:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #dbe3ec;
  --accent: #0369a1;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2fe;
  --start: #0f766e;
  --start-soft: #ccfbf1;
  --end: #4338ca;
  --end-soft: #e0e7ff;
  --sel: rgba(3, 105, 161, 0.12);
  --sel-text: #bae6fd;
  --wave: #b6c2d1;
  --wave-on: #0369a1;
  --hit: #fef08a;
  --err: #b91c1c;
  --err-soft: #fee2e2;
  --ok: #15803d;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px rgba(15, 23, 42, .06);
  --radius: 18px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111a2b;
    --surface-2: #17223a;
    --ink: #e5edf7;
    --ink-2: #c3cfdf;
    --muted: #8a9ab3;
    --line: #233150;
    --accent: #38bdf8;
    --accent-ink: #062033;
    --accent-soft: #0c2a42;
    --start: #2dd4bf;
    --start-soft: #0b3a37;
    --end: #a5b4fc;
    --end-soft: #232a5c;
    --sel: rgba(56, 189, 248, 0.14);
    --sel-text: #0f3c5c;
    --wave: #34445f;
    --wave-on: #38bdf8;
    --hit: #5b5214;
    --err: #fca5a5;
    --err-soft: #3b1418;
    --ok: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.5 var(--font);
  min-height: 100vh;
}
main { position: relative; z-index: 1; max-width: 1040px; margin: 0 auto; padding: 28px 16px 64px; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; gap: 14px; margin: 4px 4px 22px; }
.logo { width: 52px; height: 52px; border-radius: 12px; }
h1 { font-size: 30px; line-height: 1.1; margin: 0; letter-spacing: -.01em; }
.sub { margin: 4px 0 0; color: var(--ink-2); }
h2 { font-size: 23px; margin: 0; letter-spacing: -.005em; }
h3 { font-size: 18px; margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px; margin-bottom: 18px;
}
.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.num {
  flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 18px;
}
.muted { color: var(--muted); }
.small { font-size: 15px; }
.lead { margin: 0 0 14px; color: var(--ink-2); }
.hint { margin: 10px 2px 0; color: var(--muted); font-size: 16px; }
.err {
  margin: 14px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--err-soft); color: var(--err);
  font-weight: 500;
}
.msg { margin: 10px 0 0; padding: 10px 14px; border-radius: 12px; background: var(--surface-2); color: var(--ink-2); }

/* inputs + buttons */
.row { display: flex; gap: 10px; flex-wrap: wrap; }
input[type=text], input[type=search], input:not([type]), .tf input {
  font: inherit; color: var(--ink); background: var(--surface); border: 2px solid var(--line);
  border-radius: 12px; padding: 12px 14px; min-height: 54px; outline: none; min-width: 0;
}
.row input { flex: 1 1 260px; }
input:focus, input:focus-visible { border-color: var(--accent); }
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 12px; min-height: 54px; padding: 0 20px;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .link:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 16px; border-radius: 10px; }
.btn.big { min-height: 60px; padding: 0 24px; font-size: 19px; }
.btn.huge { min-height: 68px; padding: 0 30px; font-size: 21px; }
.btn.huge svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.btn.start { border-color: var(--start); color: var(--start); }
.btn.start:hover { background: var(--start-soft); }
.btn.end { border-color: var(--end); color: var(--end); }
.btn.end:hover { background: var(--end-soft); }
.link {
  font: inherit; background: none; border: 0; padding: 4px 0; color: var(--accent); cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; font-weight: 500;
}

/* step 1 */
.video { display: flex; gap: 16px; margin-top: 18px; align-items: center; }
.video img { width: 168px; aspect-ratio: 16/9; object-fit: cover; border-radius: 12px; background: var(--surface-2); flex: none; }
.video-info { min-width: 0; flex: 1; }
.vtitle { font-weight: 700; font-size: 19px; line-height: 1.3; overflow-wrap: anywhere; }
.status { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); }
.bar { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; position: relative; }
.bar i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s; }
.bar.busy i { width: 35% !important; animation: slide 1.3s ease-in-out infinite; }
@keyframes slide { 0% { left: -35%; } 100% { left: 100%; } }

/* transcript */
.search { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; position: relative; }
.search svg { position: absolute; left: 14px; width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2.2; pointer-events: none; }
.search input { flex: 1; padding-left: 44px; min-height: 48px; }
.search .muted { font-size: 15px; white-space: nowrap; }
.tx {
  position: relative; height: 380px; overflow-y: auto; border: 2px solid var(--line); border-radius: 14px; padding: 6px 18px 18px;
  background: var(--surface-2); font-size: 19px; line-height: 1.75; scroll-behavior: smooth; outline: none;
}
.tx:focus-visible { border-color: var(--accent); }
.para { display: grid; grid-template-columns: 64px 1fr; gap: 10px; padding-top: 12px; }
.ts {
  font: 600 14px/1 var(--font); color: var(--muted); background: none; border: 0; cursor: pointer; padding: 8px 0 0;
  text-align: left; font-variant-numeric: tabular-nums; user-select: none; -webkit-user-select: none;
}
.ts:hover { color: var(--accent); text-decoration: underline; }
.para p { margin: 0; color: var(--ink); }
.w { border-radius: 4px; cursor: text; }
.w.in { background: var(--sel-text); }
.w.hit { background: var(--hit); }
.w.now { box-shadow: inset 0 -3px 0 var(--accent); }
.tx ::selection { background: var(--accent); color: var(--accent-ink); }
.tx-use {
  display: flex; align-items: center; gap: 14px; margin-top: 10px; padding: 12px 14px; border-radius: 14px;
  background: var(--accent-soft); border: 2px solid var(--accent);
}
.tx-use-text { flex: 1; min-width: 0; font-style: italic; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tx-use-text .muted { font-style: normal; }
#tx-note { margin: 8px 2px 0; }

/* player */
.player { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.player-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; gap: 10px; }
.clock { font-variant-numeric: tabular-nums; font-weight: 600; }
canvas { display: block; width: 100%; touch-action: none; }
#mini { height: 34px; border-radius: 8px; background: var(--surface-2); cursor: pointer; margin-bottom: 8px; }
.wave-wrap { position: relative; }
#wave { height: 150px; border-radius: 12px; background: var(--surface-2); cursor: pointer; }
.zoom { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-top: 8px; }
.transport { display: grid; grid-template-columns: 1fr 1fr 1.6fr 1fr 1fr; gap: 8px; margin-top: 14px; }
.transport .btn { padding: 0 8px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.controls { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.controls .btn { flex: 1 1 160px; }
#play .ico, #play-part .ico { width: 1.1em; display: inline-block; text-align: center; }
.times { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; }
.tbox { border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.tbox.start { border-color: color-mix(in srgb, var(--start) 45%, var(--line)); }
.tbox.end { border-color: color-mix(in srgb, var(--end) 45%, var(--line)); }
.tbox label { display: block; font-weight: 700; margin-bottom: 6px; }
.tbox.start label { color: var(--start); }
.tbox.end label { color: var(--end); }
.tf { display: flex; gap: 6px; align-items: center; }
.tf input { width: 100%; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; min-height: 44px; padding: 6px 8px; }
.tf .btn { flex: none; }
.tbox .link { margin-top: 6px; font-size: 16px; }

/* step 3 */
.preview { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.preview-info { flex: 1; min-width: 220px; }
.quote {
  margin-top: 6px; color: var(--ink-2); font-style: italic; border-left: 3px solid var(--accent); padding-left: 12px;
  max-height: 6.2em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
}
.save { display: flex; align-items: center; gap: 16px; margin-top: 22px; flex-wrap: wrap; }
.save-extra { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.check { display: inline-flex; gap: 10px; align-items: center; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.done { margin-top: 18px; padding: 16px 18px; border-radius: 14px; background: var(--surface-2); border: 2px solid var(--ok); }
.done-head { display: flex; gap: 10px; align-items: center; font-size: 19px; }
.tick { width: 30px; height: 30px; border-radius: 50%; background: var(--ok); color: var(--surface); display: grid; place-items: center; font-weight: 800; }
.fname { margin: 8px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.done p { margin: 8px 0 4px; }

footer { text-align: center; margin-top: 10px; }

@media (max-width: 640px) {
  body { font-size: 17px; }
  main { padding-top: 18px; }
  .card { padding: 18px 16px; }
  h1 { font-size: 26px; }
  h2 { font-size: 20px; }
  .video { gap: 12px; align-items: flex-start; }
  .video img { width: 112px; border-radius: 10px; }
  .vtitle { font-size: 17px; }
  .times { grid-template-columns: 1fr; }
  .tx { height: 300px; font-size: 18px; padding: 4px 12px 14px; }
  .para { grid-template-columns: 1fr; gap: 0; }
  .ts { padding-top: 4px; }
  .tx-use { flex-direction: column; align-items: stretch; }
  .search .muted { display: none; }
  .btn.huge { width: 100%; }
  .transport { gap: 6px; grid-template-columns: 1fr 1fr 1.4fr 1fr 1fr; }
  .transport .btn { font-size: 16px; padding: 0 4px; min-height: 56px; }
  #play .lbl { display: none; }
}

/* video + transcript side by side */
.stage { display: grid; grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr); gap: 18px; align-items: start; }
.stage.no-tx { grid-template-columns: minmax(0, 560px); justify-content: center; }
.video-box { position: relative; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: #000; position: sticky; top: 12px; }
.video-box video { width: 100%; height: 100%; display: block; object-fit: contain; cursor: pointer; background: #000; }
.video-over {
  position: absolute; inset: 0; display: grid; place-items: end start; padding: 12px;
  background: #000 center / cover no-repeat; color: #fff; font-size: 15px; font-weight: 600;
}
.video-over span { background: rgba(0, 0, 0, .65); padding: 6px 10px; border-radius: 8px; }

/* word menu */
.word-pop {
  position: absolute; z-index: 5; display: flex; gap: 6px; padding: 6px; border-radius: 12px;
  background: var(--surface); border: 2px solid var(--line); box-shadow: var(--shadow); line-height: 1.2;
}
.word-pop .btn { min-height: 44px; font-size: 16px; padding: 0 12px; white-space: nowrap; }
.w.picked { outline: 2px solid var(--accent); outline-offset: 1px; }

/* video quality */
.video-opts { margin-top: 14px; padding: 16px; border: 2px solid var(--line); border-radius: 14px; }
.q-title { font-weight: 700; margin-bottom: 10px; }
.q-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.q { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 2px solid var(--line); border-radius: 12px; cursor: pointer; }
.q:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.q input { width: 20px; height: 20px; margin-top: 3px; accent-color: var(--accent); }
.q small { display: block; color: var(--muted); font-size: 14px; margin-top: 2px; }
#save-video-go svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

@media (max-width: 820px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .video-box { position: relative; top: 0; max-width: 560px; }
}
@media (max-width: 640px) {
  .q-row { grid-template-columns: 1fr; }
  .word-pop { flex-wrap: wrap; }
}
.err-detail { display: block; margin-top: 6px; font: 500 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; opacity: .85; overflow-wrap: anywhere; }
.fade-row { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; }
.fade-opts { display: inline-flex; gap: 10px; flex-wrap: wrap; color: var(--ink-2); }
.fade-opts label { display: inline-flex; align-items: center; gap: 6px; }
.fade-opts select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--surface); border: 2px solid var(--line);
  border-radius: 10px; padding: 6px 8px; min-height: 42px;
}
.fade-opts.off { opacity: .45; }
