:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --sunken: #e9ecf2;
  --ink: #171a21;
  --muted: #5b6474;
  --line: #d9dee7;
  --action: #0b7285;
  --action-ink: #ffffff;
  --action-soft: #d8eff4;
  --before: #aab2c0;
  --after: #0e9fb8;
  --after-ink: #0b7285;
  --logo-s: #12303a;
  --ok: #1d7a4c;
  --bad: #b3261e;
  --ui: "Segoe UI Variable Text", "Segoe UI", system-ui, "Nirmala UI", "Microsoft YaHei UI", "Yu Gothic UI", "Noto Sans", sans-serif;
  --mono: "Cascadia Mono", Consolas, ui-monospace, "DejaVu Sans Mono", monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #15171c;
  --surface: #1d2027;
  --sunken: #101216;
  --ink: #eceef3;
  --muted: #9aa3b3;
  --line: #2d323d;
  --action: #22d3ee;
  --action-ink: #06222a;
  --action-soft: #123640;
  --before: #596273;
  --after: #22d3ee;
  --after-ink: #22d3ee;
  --logo-s: #d9eef2;
  --ok: #6fd39d;
  --bad: #ff8f86;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 14px/1.45 var(--ui);
  -webkit-user-select: none; user-select: none; cursor: default;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--action); outline-offset: 2px; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 24px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark { width: 38px; height: 38px; flex: none; stroke-width: 10; }
.mark-s { stroke: var(--logo-s); }
.mark-c { stroke: var(--after); }
h1 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.prefs { display: flex; align-items: center; gap: 10px; flex: none; }

.ghost { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.ghost svg { width: 17px; height: 17px; color: var(--muted); }
.ghost .chev { width: 11px; height: 11px; }
.ghost:hover { border-color: var(--muted); }

.lang { position: relative; }
.menu {
  position: absolute; inset-block-start: 40px; inset-inline-end: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(2, minmax(150px, 1fr)); gap: 2px;
  padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 32px rgb(10 14 30 / 0.18);
}
.menu button { text-align: start; padding: 7px 10px; border: 0; border-radius: 6px; background: none; white-space: nowrap; }
.menu button:hover { background: var(--sunken); }
.menu button[aria-current="true"] { background: var(--action-soft); color: var(--action); font-weight: 600; }

.seg { display: flex; padding: 3px; gap: 2px; border-radius: 9px; background: var(--sunken); }
.seg button { display: grid; place-items: center; width: 34px; height: 28px; border: 0; border-radius: 6px; background: none; color: var(--muted); }
.seg svg { width: 17px; height: 17px; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(10 14 30 / 0.16); }

/* ---------- layout ---------- */
main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 348px; gap: 20px; padding: 4px 24px 24px; }
.work { display: flex; flex-direction: column; gap: 18px; min-height: 0; min-width: 0; }
.panel { min-width: 0; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow-y: auto; }

/* ---------- files ---------- */
.drop { flex: 1 1 0; min-height: 150px; display: flex; flex-direction: column; border: 1.5px dashed var(--line); border-radius: 12px; overflow: hidden; }
.drop.has-files { border-style: solid; border-width: 1px; background: var(--surface); }
.drop-empty { margin: auto; padding: 20px; text-align: center; display: grid; justify-items: center; gap: 10px; }
.drop-empty svg { width: 46px; height: 46px; color: var(--before); }
.drop-title { margin: 0; font-size: 16px; font-weight: 600; }
.exts { margin: 2px 0 0; color: var(--muted); font-size: 12px; max-width: 34em; }

.files { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.files ul { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.files li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; }
.files li:hover { background: var(--sunken); }
.files li[aria-selected="true"] { background: var(--action-soft); }
.files .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.files .meta { display: flex; gap: 10px; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.files li.bad .meta { color: var(--bad); }
.files .meta .done { color: var(--ok); font-weight: 600; }
.files .x { width: 24px; height: 24px; display: grid; place-items: center; border: 0; border-radius: 6px; background: none; color: var(--muted); }
.files .x:hover { background: var(--line); color: var(--ink); }
.files .x svg { width: 12px; height: 12px; }
.files-actions { display: flex; gap: 18px; padding: 9px 16px; border-block-start: 1px solid var(--line); }

/* ---------- preview ---------- */
.preview { flex: none; min-height: 236px; }
.empty { margin: 0; padding-block-start: 6px; color: var(--muted); }
.timeline { display: grid; gap: 5px; }
.lane { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 10px; }
.lane-name { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lane.after .lane-name { color: var(--after-ink); font-weight: 600; }
.track { position: relative; height: 22px; border-radius: 6px; background: var(--sunken); overflow: hidden; }
.track i { position: absolute; inset-block: 4px; min-width: 3px; border-radius: 4px; background: var(--before); transition: left .18s ease, width .18s ease; }
.lane.after .track i { background: var(--after); }
.lane.after .track i.still { background: var(--before); }
.ticks .track { height: 16px; background: none; overflow: visible; }
.ticks .track span { position: absolute; top: 0; font: 11px var(--mono); color: var(--muted); padding-left: 5px; border-left: 1px solid var(--line); line-height: 14px; }

.cues { width: 100%; margin-block-start: 12px; border-collapse: collapse; table-layout: fixed; }
.cues th { text-align: start; font-size: 12.5px; font-weight: 500; color: var(--muted); padding: 0 0 4px; }
.cues th:nth-child(1), .cues th:nth-child(2) { width: 118px; }
.cues td { padding: 4px 0; border-block-start: 1px solid var(--line); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cues td.t { font: 12.5px var(--mono); color: var(--muted); direction: ltr; text-align: start; }
.cues td.t.new { color: var(--after-ink); font-weight: 600; }
.cues td.txt { -webkit-user-select: text; user-select: text; }

/* ---------- controls ---------- */
.group { padding: 18px 20px; border-block-end: 1px solid var(--line); display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.title { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }

.offset { display: flex; align-items: baseline; gap: 8px; border-block-end: 2px solid var(--line); padding-block-end: 4px; direction: ltr; }
.offset:focus-within { border-color: var(--action); }
.offset input { flex: 1; min-width: 0; border: 0; background: none; outline: 0; padding: 0; font: 600 40px/1.1 var(--ui); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.offset .unit { color: var(--muted); font-size: 13px; }

.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.chips button { height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 7px; background: none; font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chips button:hover { border-color: var(--muted); background: var(--sunken); }
.chips button:active { background: var(--line); }
.readout { margin: 0; min-height: 2.9em; font-size: 13px; color: var(--muted); }
.readout.on { color: var(--after-ink); font-weight: 600; }

.check { display: flex; align-items: flex-start; gap: 9px; }
.check input { margin: 3px 0 0; width: 15px; height: 15px; accent-color: var(--action); flex: none; }
.range { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.range label, .fps, .suffix { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.panel input[type="text"]:not(#offset) { height: 34px; width: 100%; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--ink); font: 13px var(--mono); -webkit-user-select: text; user-select: text; }
.panel input[type="text"]:not(#offset):focus { outline: 0; border-color: var(--action); }
.panel input.invalid:not(#offset) { border-color: var(--bad); }
.sub { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding-inline-start: 24px; }
.sub.off { opacity: .45; pointer-events: none; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-weight: 600; }
.btn:hover { border-color: var(--muted); }
.btn.small { height: 34px; justify-content: flex-start; padding: 0 10px; font-weight: 500; min-width: 0; }
.btn.small svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
.btn.small span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.primary { width: 100%; height: 44px; border-color: transparent; background: var(--action); color: var(--action-ink); font-size: 15px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { background: var(--sunken); color: var(--muted); cursor: default; filter: none; }
.link { border: 0; background: none; padding: 0; color: var(--action); font-weight: 600; }
.link:hover { text-decoration: underline; }
.link.quiet { color: var(--muted); font-weight: 500; }

.go { margin-block-start: auto; position: sticky; bottom: 0; background: var(--surface); padding: 18px 20px 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.status { margin: 0; min-height: 1.45em; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.status.ok { color: var(--ok); font-weight: 600; }
.status.bad { color: var(--bad); }

.veil { position: fixed; inset: 10px; z-index: 30; display: grid; place-items: center; border: 2px dashed var(--action); border-radius: 14px; background: color-mix(in srgb, var(--bg) 88%, transparent); pointer-events: none; }
.veil p { font-size: 20px; font-weight: 600; color: var(--action); }

@media (max-width: 760px) {
  main { grid-template-columns: 1fr; overflow-y: auto; }
  .drop { flex: none; }
  .panel { overflow: visible; }
}
@media (prefers-reduced-motion: reduce) { .track i { transition: none; } }

/* ---------- web version ---------- */
a { color: inherit; }
.donate svg { color: var(--after); }
.menu a { display: block; padding: 7px 10px; border-radius: 6px; text-decoration: none; white-space: nowrap; text-align: start; }
.menu a:hover { background: var(--sunken); }
.menu a[aria-current="true"] { background: var(--action-soft); color: var(--after-ink); font-weight: 600; }
.note { margin: 0; font-size: 12.5px; color: var(--muted); }

.foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 24px 14px; font-size: 12.5px; color: var(--muted); }
.foot-local { display: inline-flex; align-items: center; gap: 7px; min-width: 0; }
.foot-local svg { width: 15px; height: 15px; flex: none; }
.foot .link { font-size: 12.5px; white-space: nowrap; text-decoration: underline; text-underline-offset: 2px; }
main { padding-block-end: 14px; }

.dlg { width: min(360px, calc(100vw - 32px)); padding: 26px 24px 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgb(5 15 20 / 0.35); text-align: center; -webkit-user-select: text; user-select: text; }
.dlg.wide { width: min(560px, calc(100vw - 32px)); text-align: start; }
.dlg::backdrop { background: rgb(8 14 18 / 0.55); }
.dlg h2 { margin: 0 0 10px; font-size: 18px; font-weight: 650; letter-spacing: -0.01em; padding-inline-end: 28px; }
.dlg:not(.wide) h2 { padding-inline: 28px; }
.dlg p { margin: 0 0 12px; line-height: 1.55; }
.dlg p:last-child { margin-block-end: 0; }
.dlg .small { font-size: 12.5px; color: var(--muted); }
.dlg img { display: block; width: 220px; height: 220px; max-width: 100%; margin: 16px auto 12px; padding: 4px; border-radius: 12px; background: #fff; }
.dlg .x { position: absolute; inset-block-start: 14px; inset-inline-end: 14px; width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 7px; background: none; color: var(--muted); }
.dlg .x:hover { background: var(--sunken); color: var(--ink); }
.dlg .x svg { width: 12px; height: 12px; }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-block-start: 14px; }
.dlg-actions .btn { text-decoration: none; font-weight: 500; }

@media (max-width: 760px) {
  html, body { height: auto; }
  body { min-height: 100%; }
  .top { padding: 12px 16px; flex-wrap: wrap; row-gap: 10px; }
  main { padding: 4px 16px 16px; overflow: visible; gap: 16px; }
  .drop { min-height: 190px; }
  .panel { overflow: visible; }
  .go { position: static; }
  .work { display: contents; }
  .drop { order: 1; }
  .panel { order: 2; }
  .preview { order: 3; min-height: 0; }
  .donate span { display: none; }
  .donate { padding: 0 9px; }
  .menu { grid-template-columns: repeat(2, minmax(0, 1fr)); width: min(320px, calc(100vw - 32px)); }
  .cues th:nth-child(1), .cues th:nth-child(2) { width: 96px; }
  .foot { padding: 0 16px 16px; flex-direction: column; align-items: flex-start; gap: 8px; }
  .panel input[type="text"]:not(#offset) { font-size: 16px; } /* stops iOS zooming on focus */
}
@media (max-width: 460px) {
  .brand p { display: none; }
  #langBtn > span { max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .lane { grid-template-columns: 52px minmax(0, 1fr); }
}
