:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f0ede6;
  --ink: #1d1c1a;
  --muted: #5f5a52;
  --faint: #8a847a;
  --line: #e2ddd3;
  --line-strong: #cfc8bb;
  --accent: #1d5c63;
  --accent-hover: #164a50;
  --accent-soft: #dcecec;
  --on-accent: #ffffff;
  --danger: #b42318;
  --focus: #2f6fdb;
  --now: #ffe58f;
  --now-ink: #1d1c1a;
  --match: #c9e3ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.06);
  --ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --read: 'Literata', Georgia, 'Times New Roman', serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151514;
    --surface: #1e1d1b;
    --surface-2: #262522;
    --ink: #ecebe6;
    --muted: #b0aa9f;
    --faint: #8d877c;
    --line: #34322e;
    --line-strong: #4a4741;
    --accent: #5fb8b0;
    --accent-hover: #7ccac3;
    --accent-soft: #1d3a3a;
    --on-accent: #0e1f1f;
    --danger: #ff7b6e;
    --focus: #7aa7ff;
    --now: #6b5a12;
    --now-ink: #fff8dc;
    --match: #23466e;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 20px rgb(0 0 0 / 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 var(--ui);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2 { line-height: 1.2; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

/* Buttons and fields */
button, .button {
  font: 500 14px/1 var(--ui);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  text-decoration: none;
}
button:hover, .button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover, .button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
button.small, .button.small { padding: 5px 10px; min-height: 28px; font-size: 13px; }
button.link { background: none; border: 0; color: var(--accent); padding: 0 4px; min-height: 0; text-decoration: underline; }
.icon-btn { padding: 6px; min-width: 36px; justify-content: center; }
input[type='text'], input[type='search'], input[type='password'], input[type='number'], select, textarea {
  font: 14px/1.4 var(--ui);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 36px;
}
textarea { font-family: var(--read); font-size: 17px; line-height: 1.6; width: 100%; resize: vertical; }
label.stack { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 14px; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
fieldset { border: 0; padding: 0; margin: 0 0 18px; min-width: 0; }
legend { font-weight: 600; font-size: 14px; padding: 0; margin-bottom: 8px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font: 700 19px/1 var(--ui); color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.topnav { display: flex; gap: 6px; align-items: center; }

main { flex: 1; width: 100%; }
.view { max-width: 1100px; margin: 0 auto; padding: 32px 20px 48px; }

/* Home */
.hero h1 { font: 700 clamp(26px, 4vw, 38px)/1.15 var(--ui); letter-spacing: -0.02em; margin: 8px 0 12px; max-width: 22ch; }
.lede { font-size: 17px; color: var(--muted); max-width: 62ch; margin: 0 0 28px; }
.start-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .start-grid { grid-template-columns: 1fr; } }
.dropzone {
  border: 2px dashed var(--line-strong); border-radius: 14px; background: var(--surface);
  padding: 36px 24px; text-align: center; color: var(--muted); transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-title { font: 600 18px/1.3 var(--ui); color: var(--ink); margin: 8px 0 4px; }
.drop-sub { margin: 0 0 18px; font-size: 13px; }
.drop-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.file-pick { position: relative; }
.file-pick:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #d23a2a; display: inline-block; }
.rec-dot.live { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .rec-dot.live { animation: none; } }
.recorder { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 18px; flex-wrap: wrap; color: var(--ink); font-variant-numeric: tabular-nums; }
.recorder meter { width: 120px; }

.options { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.quality { display: grid; gap: 8px; }
.q-card { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.q-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.q-card:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.q-card input { margin: 0; grid-row: span 2; accent-color: var(--accent); }
.q-name { font-weight: 600; }
.q-size { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.q-note { grid-column: 2 / 4; font-size: 13px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.history { margin-top: 40px; }
.history h2 { font-size: 18px; margin: 0 0 4px; }
.history-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.history-item { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.history-item .open { flex: 1; justify-content: flex-start; border: 0; background: none; padding: 4px; text-align: left; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.history-item .open:hover .h-title { text-decoration: underline; }
.h-title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.h-meta { color: var(--muted); font-size: 13px; font-weight: 400; }

/* Working */
#working { max-width: 760px; }
#working h1 { font-size: 26px; margin: 8px 0 2px; overflow-wrap: anywhere; }
.stages { list-style: none; padding: 0; margin: 20px 0; display: grid; gap: 8px; }
.stages li { display: flex; gap: 10px; align-items: baseline; color: var(--faint); padding-left: 26px; position: relative; }
.stages li::before { content: ''; position: absolute; left: 4px; top: 5px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line-strong); }
.stages li.active { color: var(--ink); font-weight: 600; }
.stages li.active::before { border-color: var(--accent); background: var(--accent-soft); }
.stages li.done { color: var(--muted); }
.stages li.done::before { background: var(--accent); border-color: var(--accent); }
.stages li.skipped { text-decoration: line-through; }
.stage-detail { font-weight: 400; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
progress { width: 100%; height: 10px; accent-color: var(--accent); }
.work-status { min-height: 1.5em; color: var(--muted); font-variant-numeric: tabular-nums; }
.live-text { margin-top: 24px; font: 17px/1.65 var(--read); color: var(--muted); max-height: 40vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; white-space: pre-wrap; }
.live-text:empty { display: none; }

/* Editor */
#editor { max-width: none; padding: 0; display: flex; flex-direction: column; min-height: calc(100vh - 57px); }
.editor-bar { display: flex; gap: 12px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.title-input { flex: 1; min-width: 200px; font: 600 19px/1.2 var(--ui); border-color: transparent; background: transparent; padding: 6px 8px; }
.title-input:hover { border-color: var(--line); }
.editor-tools { display: flex; gap: 6px; align-items: center; }
.find-bar { display: flex; gap: 8px; align-items: center; padding: 8px 20px; background: var(--surface-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.find-bar input[type='search'], .find-bar input[type='text'] { width: 200px; }
.find-count { color: var(--muted); font-size: 13px; min-width: 70px; font-variant-numeric: tabular-nums; }
.editor-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 0; }
@media (max-width: 960px) { .editor-body { grid-template-columns: 1fr; } .side { border-left: 0; border-top: 1px solid var(--line); } }
.transcript { padding: 28px clamp(16px, 5vw, 64px) 120px; max-width: 860px; width: 100%; margin: 0 auto; }
.side { border-left: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 14px; background: var(--bg); }
@media (min-width: 961px) { .side { position: sticky; top: 57px; height: calc(100vh - 57px - 64px); overflow: auto; } }

.para { position: relative; margin: 0 0 22px; padding-left: 14px; border-left: 3px solid color-mix(in srgb, var(--spk) 70%, transparent); }
.para.active { border-left-color: var(--spk); }
.para-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.spk-chip { font: 600 13px/1 var(--ui); color: var(--spk); background: color-mix(in srgb, var(--spk) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--spk) 35%, transparent); border-radius: 999px; padding: 5px 10px; min-height: 26px; }
.spk-chip:hover { border-color: var(--spk); }
.ts { font: 500 12px/1 var(--ui); color: var(--muted); background: none; border: 0; padding: 4px; min-height: 24px; font-variant-numeric: tabular-nums; }
.ts:hover { color: var(--accent); text-decoration: underline; }
.para-edit { opacity: 0; padding: 3px 6px; min-height: 24px; font-size: 12px; color: var(--muted); }
.para:hover .para-edit, .para:focus-within .para-edit { opacity: 1; }
@media (hover: none) { .para-edit { opacity: 1; } }
.para-text { font: 18px/1.75 var(--read); margin: 0; overflow-wrap: break-word; }
.w { border-radius: 3px; cursor: pointer; transition: background .1s; }
.w:hover { background: var(--surface-2); }
.w.now { background: var(--now); color: var(--now-ink); }
.w.match { background: var(--match); }
.w.match.current { outline: 2px solid var(--focus); }
.para-editing textarea { margin-top: 4px; }
.edit-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.empty-transcript { color: var(--muted); font: 18px/1.6 var(--read); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.panel h2 { font-size: 15px; margin: 0 0 10px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { margin: 0; }
.speaker-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 8px; }
.speaker-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.speaker-row .swatch-btn { width: 22px; height: 22px; border-radius: 50%; padding: 0; min-height: 0; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line-strong); }
.speaker-row input[type='text'] { width: 100%; padding: 6px 8px; min-height: 32px; }
.speaker-row .spk-meta { grid-column: 2 / 4; font-size: 12px; color: var(--muted); margin-top: -4px; }
.talkbar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; grid-column: 2 / 4; }
.talkbar span { display: block; height: 100%; }
.redetect { margin-top: 12px; font-size: 14px; }
.redetect summary { cursor: pointer; color: var(--muted); }
.redetect-body { display: grid; gap: 8px; margin-top: 8px; }
.video-box video { width: 100%; border-radius: 10px; background: #000; display: block; }
.info dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; overflow-wrap: anywhere; }

.claude-actions { display: grid; gap: 8px; }
.claude-actions textarea { font: 13px/1.4 var(--ui); min-height: 52px; }
.suggestion { border-top: 1px solid var(--line); padding: 10px 0 0; margin-top: 10px; display: grid; gap: 4px; font-size: 14px; }
.suggestion .sug-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.suggestion .quote { color: var(--muted); font: italic 13px/1.4 var(--read); }
.suggestion .conf { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }
.fix-row { display: grid; grid-template-columns: auto 1fr; gap: 6px; align-items: start; font-size: 14px; padding: 6px 0; border-top: 1px solid var(--line); }
.fix-row del { color: var(--danger); }
.fix-row ins { text-decoration: none; color: var(--accent); font-weight: 600; }
.fix-row .why { color: var(--muted); font-size: 12px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-text { color: var(--danger); font-size: 14px; }

/* Player */
.player {
  position: sticky; bottom: 0; z-index: 15; display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgb(0 0 0 / 0.04);
}
.play { width: 44px; height: 44px; border-radius: 50%; justify-content: center; padding: 0; background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.play:hover { background: var(--accent-hover); }
.play .i-pause { display: none; }
.play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }
.time { font: 500 13px/1 var(--ui); color: var(--muted); font-variant-numeric: tabular-nums; min-width: 44px; text-align: center; }
.timeline { flex: 1; height: 36px; position: relative; cursor: pointer; border-radius: 6px; }
.timeline canvas { width: 100%; height: 100%; display: block; }
.speed { min-height: 32px; padding: 4px 6px; }
.follow { font-size: 13px; color: var(--muted); }
@media (max-width: 640px) { .player label.follow, #back5, #fwd5 { display: none; } .player { gap: 6px; padding: 8px 10px; } }

/* Menus, selection bar, toast */
.menu { position: fixed; z-index: 60; min-width: 200px; max-height: 70vh; overflow: auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; }
.menu-item { width: 100%; border: 0; background: none; justify-content: flex-start; padding: 8px 10px; border-radius: 6px; font-weight: 400; }
.menu-item:hover, .menu-item:focus { background: var(--surface-2); outline: none; }
.menu-item:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.menu-item .check { margin-left: auto; color: var(--accent); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 0; }
.menu-heading { font-size: 12px; color: var(--muted); padding: 6px 10px 2px; }
.swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.sel-bar { position: fixed; z-index: 40; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; max-width: min(560px, 94vw); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; font-size: 13px; }
.sel-bar .label { color: var(--muted); padding: 0 6px; }
.sel-bar button { min-height: 28px; padding: 4px 9px; font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 70; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: center; max-width: 92vw; }
.toast .link { color: var(--bg); }

/* Dialogs */
dialog { border: 1px solid var(--line-strong); border-radius: 14px; padding: 20px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); width: min(520px, 94vw); max-height: 90vh; }
dialog.wide { width: min(980px, 96vw); }
dialog::backdrop { background: rgb(20 20 20 / 0.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.dialog-head h2 { margin: 0; font-size: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
dialog.confirm p { margin: 0 0 8px; }
dialog.confirm input { width: 100%; }
.key-row { display: flex; gap: 6px; }
.key-advice { font-size: 13px; margin: 8px 0 12px; }
.key-advice summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.key-advice ul { margin: 6px 0 0; padding-left: 20px; color: var(--muted); display: grid; gap: 4px; }
.key-row input { flex: 1; font-family: ui-monospace, monospace; }

.export-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; }
@media (max-width: 700px) { .export-grid { grid-template-columns: 1fr; } }
.formats { display: grid; gap: 2px; align-content: start; }
.format-group { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 10px 0 4px; }
.format-group:first-of-type { margin-top: 0; }
.format-opt { display: flex; gap: 8px; align-items: center; padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.format-opt:has(input:checked) { background: var(--accent-soft); font-weight: 600; }
.format-opt input { accent-color: var(--accent); margin: 0; }
.format-opt .ext { margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 400; }
.export-options { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: flex-end; margin-bottom: 14px; min-height: 40px; }
.export-options label.stack { font-size: 13px; }
.export-options input[type='number'] { width: 80px; }
.preview-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.preview { margin: 0; height: 340px; overflow: auto; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font: 13px/1.5 ui-monospace, 'Cascadia Code', Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.site-footer { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 14px 20px; font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); }
body.editing .site-footer { display: none; }

/* Credits page */
.doc { max-width: 760px; margin: 0 auto; padding: 32px 20px 56px; }
.doc h1 { font: 700 clamp(26px, 4vw, 34px)/1.15 var(--ui); letter-spacing: -0.02em; margin: 8px 0 12px; }
.doc h2 { font-size: 20px; margin: 36px 0 12px; }
.doc p { max-width: 68ch; }
.credit { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin: 0 0 12px; }
.credit h3 { margin: 0; font-size: 17px; }
.credit .by { margin: 2px 0 8px; color: var(--muted); font-size: 14px; }
.credit p { margin: 0 0 8px; }
.credit dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 10px 0 0; font-size: 14px; }
.credit dt { color: var(--muted); font-weight: 500; }
.credit dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 520px) { .credit dl { grid-template-columns: 1fr; } .credit dd { margin-bottom: 6px; } }
