:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2128;
  --muted: #656d76;
  --border: #d8dee4;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #cf222e;
  --ok: #1a7f37;
  --warn: #9a6700;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #161b22;
    --text: #e6edf3;
    --muted: #8d96a0;
    --border: #30363d;
    --accent: #4493f8;
    --danger: #f85149;
    --ok: #3fb950;
    --warn: #d29922;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --surface: #161b22; --text: #e6edf3; --muted: #8d96a0; --border: #30363d;
  --accent: #4493f8; --danger: #f85149; --ok: #3fb950; --warn: #d29922; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); min-height: 1.5em; margin: 0; }
.center-text { text-align: center; }
.spacer { flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.view.center { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; display: grid; gap: 14px; text-align: center; }
.login img { margin: 0 auto; }
label { display: grid; gap: 4px; text-align: left; font-size: .9rem; }
input, textarea {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button, .button {
  font: inherit;
  font-size: .95rem;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.danger { color: var(--danger); }
.icon-btn { min-width: 44px; padding: 0; font-size: 1.3rem; border: none; background: none; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--text); text-decoration: none; }

.page { max-width: 920px; margin: 0 auto; padding: 16px; display: grid; gap: 20px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }

.dropzone { text-align: center; display: grid; gap: 12px; justify-items: center; border-style: dashed; border-width: 2px; }
.dropzone p { margin: 0; }
.dropzone.drag { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
#recorder { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; font-variant-numeric: tabular-nums; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
#upload-progress { display: flex; gap: 8px; align-items: center; width: 100%; max-width: 400px; }
#upload-progress progress { flex: 1; }

.list-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.list-head input { max-width: 240px; padding: 6px 10px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.list a {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
}
.list a:hover { border-color: var(--accent); }
.list .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { grid-column: 1; font-size: .85rem; color: var(--muted); }
.badge { grid-row: 1 / span 2; grid-column: 2; font-size: .8rem; padding: 2px 10px; border-radius: 99px; border: 1px solid currentColor; }
.badge.done { color: var(--ok); }
.badge.error { color: var(--danger); }
.badge.queued, .badge.processing { color: var(--warn); }

.edit-head { display: flex; gap: 8px; align-items: center; }
.title-input { font-size: 1.2rem; font-weight: 600; }
.status-line { font-size: .9rem; color: var(--muted); }
.status-line.error { color: var(--danger); }
audio { width: 100%; }
.tabs { display: flex; gap: 4px; align-items: center; border-bottom: 1px solid var(--border); }
.tab { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; min-height: 40px; }
.tab.active { border-bottom-color: var(--accent); color: var(--accent); }
#edit-md {
  min-height: 55dvh;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .95rem;
  line-height: 1.6;
}
.markdown { min-height: 55dvh; overflow-wrap: anywhere; }
.markdown h1 { font-size: 1.5rem; margin-bottom: .5em; }
.markdown hr { border: none; border-top: 1px solid var(--border); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  width: min(420px, calc(100vw - 32px)); padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
.settings { display: grid; gap: 14px; }
.settings p { margin: 0; overflow-wrap: anywhere; }
label.check { display: flex; gap: 8px; align-items: center; font-size: 1rem; }
label.check input { width: auto; }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; }

@media (max-width: 600px) {
  .card { padding: 16px; }
  .list-head { flex-wrap: wrap; }
  .list-head input { max-width: none; }
  .actions .button, .actions button { flex: 1 1 auto; }
  .actions .spacer { display: none; }
}
