/* Layout: editor shell — preview + timeline on the left, tool panel on the right; stacks on phones.
   Accent comes from classic subtitle yellow; neutrals lean slightly toward slate blue. */
:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --line: #d9dde4;
  --fg: #171b22;
  --muted: #5b6372;
  --accent: #e0a800;
  --accent-ink: #1a1400;
  --accent-soft: #fff3c4;
  --danger: #c2362b;
  --stage: #0d1014;
  --tl-bg: #e6e9ee;
  --tl-wave: #9aa3b2;
  --tl-cue: #f2c230;
  --tl-cue-active: #ffb300;
  --tl-text: #1a1400;
  --font-ui: "Anuphan", "Noto Sans Thai", system-ui, sans-serif;
  --font-display: "Bai Jamjuree", "Anuphan", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1f242c; --line: #2c333d;
    --fg: #e8ebf0; --muted: #98a1b0; --accent: #ffc928; --accent-ink: #1a1400; --accent-soft: #3a3214;
    --danger: #ff6b5e; --stage: #07090b; --tl-bg: #12161b; --tl-wave: #4a5464;
    --tl-cue: #d9aa1c; --tl-cue-active: #ffc928; --tl-text: #1a1400; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --surface-2: #1f242c; --line: #2c333d;
  --fg: #e8ebf0; --muted: #98a1b0; --accent: #ffc928; --accent-ink: #1a1400; --accent-soft: #3a3214;
  --danger: #ff6b5e; --stage: #07090b; --tl-bg: #12161b; --tl-wave: #4a5464;
  --tl-cue: #d9aa1c; --tl-cue-active: #ffc928; --tl-text: #1a1400; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.55 var(--font-ui);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
[hidden] { display: none !important; }
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 3px; }
h2 { font: 600 1.05rem/1.3 var(--font-display); margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding-block: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  font: 700 15px/1 var(--font-display); background: var(--accent); color: var(--accent-ink);
  padding: 7px 8px 6px; border-radius: 6px; letter-spacing: .02em;
}
.brand-name { font: 700 1.2rem/1 var(--font-display); }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface); text-decoration: none; font-weight: 500;
}
.btn:hover { border-color: var(--muted); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: .9rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.05); border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  display: inline-grid; place-items: center; cursor: pointer; font-size: 1.1rem;
}
.icon-btn.small { width: 32px; height: 32px; border-radius: 8px; }

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 440px); gap: 16px;
  padding-bottom: 24px; align-items: start;
}
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.workspace { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.stage-wrap {
  background: var(--stage); border-radius: var(--r); padding: 12px; display: grid; place-items: center;
  min-height: 240px;
}
.stage-wrap.drag { outline: 3px dashed var(--accent); outline-offset: -6px; }
.stage { position: relative; width: 100%; max-height: 62vh; aspect-ratio: 16 / 9; }
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage video { object-fit: fill; background: #000; }
.stage-hint {
  position: absolute; left: 12px; top: 12px; right: 12px; color: #c9d0da; font-size: .85rem;
  background: rgba(0,0,0,.45); padding: 6px 10px; border-radius: 6px; width: fit-content; max-width: calc(100% - 24px);
}
.stage-hint strong { color: #ffc928; margin-right: 6px; }
.stage-wrap:fullscreen { border-radius: 0; padding: 12px; background: #000; }
.stage-wrap:fullscreen .stage { width: min(calc(100vw - 24px), calc((100vh - 24px) * var(--ratio, 1.7778))) !important; max-height: none; }
.stage-wrap:fullscreen .stage-hint { display: none; }
.full-span { grid-column: 1 / -1; }
.own-key { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.own-key summary { cursor: pointer; font-size: .9rem; }
.own-key[open] { display: flex; flex-direction: column; gap: 8px; }
.capcut { border-color: var(--accent); }

.transport { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.timecode { font: 500 .95rem var(--font-mono); font-variant-numeric: tabular-nums; }
.file-name { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.zoom { display: flex; gap: 6px; }

.timeline-wrap { background: var(--tl-bg); border-radius: var(--r); border: 1px solid var(--line); overflow: hidden; }
#timeline { width: 100%; height: 150px; display: block; cursor: pointer; touch-action: none; }
.tip { margin: 0; color: var(--muted); font-size: .82rem; }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  display: flex; flex-direction: column; min-width: 0; max-height: calc(100vh - 90px); position: sticky; top: 12px;
}
@media (max-width: 900px) { .panel { position: static; max-height: none; } }
.tabs { display: flex; flex-shrink: 0; border-bottom: 1px solid var(--line); padding: 0 6px; overflow-x: auto; }
.tab {
  background: none; border: 0; padding: 12px 12px 10px; cursor: pointer; color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab.active { color: var(--fg); border-bottom-color: var(--accent); }
.tab-body { padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; min-height: 0; }

.card { border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--surface); }
.transcribe-card { background: var(--surface-2); border-color: transparent; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.chip { font-size: .78rem; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--fg); white-space: nowrap; }
.muted { color: var(--muted); margin: 0; font-size: .9rem; }
.note { font-size: .82rem; color: var(--muted); margin: 0; border-left: 3px solid var(--accent); padding-left: 8px; }
.status { margin: 0; font-size: .88rem; min-height: 1.2em; }
.status.err { color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; min-width: 0; }
.field > span { color: var(--muted); }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
textarea { resize: vertical; }
input[type="color"] { width: 100%; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 2px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.progress { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.progress-bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.find-bar { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; }
.cue-meta { font-size: .82rem; color: var(--muted); }

.cue-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cue {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: grid; gap: 6px;
  grid-template-columns: auto minmax(0, 1fr); background: var(--surface);
}
.cue.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.cue-num { font: 600 .8rem var(--font-mono); color: var(--muted); padding-top: 4px; min-width: 2ch; text-align: right; cursor: pointer; }
.cue-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cue-times { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.cue-times input { width: 92px; font: .85rem var(--font-mono); padding: 4px 6px; font-variant-numeric: tabular-nums; }
.cue-times .arrow { color: var(--muted); }
.cue textarea { font-size: 1rem; padding: 6px 8px; min-height: 2.4em; }
.cue-foot { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.wc { font-size: .75rem; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.wc.off { background: var(--accent-soft); color: var(--fg); }
.mini { border: 0; background: none; color: var(--muted); font-size: .8rem; padding: 3px 6px; border-radius: 6px; cursor: pointer; }
.mini:hover { background: var(--surface-2); color: var(--fg); }
.mini.danger:hover { color: var(--danger); }
.empty { color: var(--muted); font-size: .9rem; text-align: center; padding: 18px 8px; border: 1px dashed var(--line); border-radius: 8px; }

.section-label { font: 600 .78rem var(--font-ui); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 0 0; }
.preset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.preset { border: 1px solid var(--line); border-radius: 8px; padding: 0; overflow: hidden; cursor: pointer; background: #1b2028; display: flex; flex-direction: column; }
.preset canvas { width: 100%; aspect-ratio: 16 / 6; display: block; }
.preset span { font-size: .8rem; padding: 4px 8px; background: var(--surface); text-align: left; }
.preset.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

.font-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.font-item {
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer;
  padding: 6px 4px; text-align: center; font-size: 1.05rem; line-height: 1.3; min-width: 0;
}
.font-item small { display: block; font: .68rem var(--font-ui); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-item.active { border-color: var(--accent); background: var(--accent-soft); }

.controls { display: flex; flex-direction: column; gap: 10px; }
.group { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.group > h4 { grid-column: 1 / -1; margin: 0; font: 600 .92rem var(--font-display); display: flex; align-items: center; justify-content: space-between; }
.group .full { grid-column: 1 / -1; }
.range-field output { font: .78rem var(--font-mono); color: var(--fg); float: right; }
.switch { display: inline-flex; align-items: center; gap: 6px; font: 400 .85rem var(--font-ui); cursor: pointer; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: .85rem; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--fg); padding: 0; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.5); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 12px; }

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

.audio-only { display: none; }
body.is-audio .audio-only, body.no-media .audio-only { display: flex; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
