/* Same tokens as /logistic, /qr-generator and /split-bill, so the tools read as one family.
   The one dark thing on the page is the picture itself. */

/* The only bundled font: Atkinson Hyperlegible, offered for subtitles because it is made to be read at a glance. It is
   loaded from this folder, never from a font service, so the page opens with no connection. The Latin-extended files are
   only read when a line needs them. */
@font-face{font-family:"Atkinson Hyperlegible";font-style:normal;font-weight:400;font-display:swap;
  src:url(../fonts/atkinson-hyperlegible-latin-400-normal.woff2) format("woff2");
  unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}
@font-face{font-family:"Atkinson Hyperlegible";font-style:normal;font-weight:700;font-display:swap;
  src:url(../fonts/atkinson-hyperlegible-latin-700-normal.woff2) format("woff2");
  unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD}
@font-face{font-family:"Atkinson Hyperlegible";font-style:normal;font-weight:400;font-display:swap;
  src:url(../fonts/atkinson-hyperlegible-latin-ext-400-normal.woff2) format("woff2");
  unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}
@font-face{font-family:"Atkinson Hyperlegible";font-style:normal;font-weight:700;font-display:swap;
  src:url(../fonts/atkinson-hyperlegible-latin-ext-700-normal.woff2) format("woff2");
  unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF}

:root {
    --bg: #f4f5f7;
    --card-bg: #ffffff;
    --text: #1f2430;
    --muted: #6b7280;
    --border: #e2e4e9;
    --soft: #eef0f5;
    --primary: #3b5bdb;
    --primary-dark: #2f47ad;
    --danger: #d64545;
    --ok: #1f7a34;
    --warn: #b7791f;
    --radius: 8px;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px; }

/* ------------------------------------------------------------------ top bar */

.topbar { background: var(--card-bg); border-bottom: 1px solid var(--border); }

.topbar-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 12px 20px;
    padding-left: max(20px, env(safe-area-inset-left, 0px));
    padding-right: max(20px, env(safe-area-inset-right, 0px));
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }

.topnav { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; }

/* Says in words whether the page can open with no connection. */
.net {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 3px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--card-bg);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: help;
}
.net::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.net[data-state="ready"], .net[data-state="disk"] { color: var(--ok); border-color: #c3e6cb; background: #eaf7ec; }
.net[data-state="ready"]::before, .net[data-state="disk"]::before { background: var(--ok); }
.net[data-state="saving"] { color: var(--warn); border-color: #eadaa8; background: #fdf6e3; }
.net[data-state="saving"]::before { background: var(--warn); }
.net[data-state="none"] { color: #a12a2a; border-color: #f3c3c3; background: #fdecec; }
.net[data-state="none"]::before { background: var(--danger); }

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px;
    padding-left: max(20px, env(safe-area-inset-left, 0px));
    padding-right: max(20px, env(safe-area-inset-right, 0px));
}

/* ------------------------------------------------------------------ buttons */

.btn, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    line-height: 1.3;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover, button:hover { background: var(--soft); text-decoration: none; }
.btn.sm { padding: 4px 9px; font-size: 0.8rem; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f3c3c3; }
.btn.danger:hover { background: #fdecec; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button:disabled:hover { background: #fff; }
.btn-primary:disabled:hover { background: var(--primary); }
.btn[aria-pressed="false"] { color: var(--muted); }
.btn svg { flex: none; }

/* ------------------------------------------------------------------ layout */

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 400px);
    gap: 20px;
    align-items: start;
}

/* The picture stays in view while the long list of settings scrolls past it. */
.stage-col { min-width: 0; position: sticky; top: 20px; }

.controls { min-width: 0; }

@media (max-width: 980px) {
    .layout { grid-template-columns: minmax(0, 1fr); }
    .stage-col { position: static; }
}

/* On a window wide and tall enough, the page is exactly as tall as the window and never scrolls: the picture takes the left, the
   tabs the right, and what does not fit in a tab scrolls inside the tab (the trim list, the longer settings). Only when the script
   has made the tabs, so a page that lost its script stays a page that scrolls. Shorter windows scroll like any page. */
@media (min-width: 981px) and (min-height: 560px) {
    .tabbed, .tabbed body { height: 100%; }
    .tabbed body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
    .tabbed .topbar { flex: none; }
    .tabbed .container { flex: 1 1 auto; min-height: 0; width: 100%; display: flex; flex-direction: column; }
    .tabbed .layout { flex: 1 1 auto; min-height: 0; grid-template-rows: minmax(0, 1fr); align-items: stretch; }
    .tabbed .stage-col { position: static; min-height: 0; overflow-y: auto; }
    .tabbed .controls { display: flex; flex-direction: column; min-height: 0; }
    .tabbed .panes { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 20px;
}
.stage-card { padding: 14px; margin-bottom: 0; }

@media (max-width: 600px) {
    .card { padding: 16px; }
    .stage-card { padding: 10px; }
    .topbar-inner { flex-direction: column; align-items: flex-start; }
}

h2 { font-size: 1.1rem; margin: 0 0 12px; }

/* The tools column is a set of tabs (panels.js): each card's own heading, made clickable, is its tab, and one card shows at a
   time. Without the script the cards simply stack, as plain cards. */
.tabbed .controls { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tabbed .controls .card { margin: 0; padding-top: 16px; padding-bottom: 16px; border: 0; border-radius: 0; background: transparent; }
.tabbed .controls .card:not(.active) { display: none; }
.tabs { display: flex; flex-wrap: wrap; padding: 0 4px; border-bottom: 1px solid var(--border); }
.tabs .tab { flex: 1 1 auto; margin: 0 0 -1px; padding: 10px 5px 8px; border-bottom: 2px solid transparent; font-size: 0.82rem; font-weight: 600; line-height: 1.2; text-align: center; white-space: nowrap; color: var(--muted); cursor: pointer; user-select: none; }
.tabs .tab:hover { color: var(--text); }
.tabs .tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.panes { display: flex; flex-direction: column; }
.tabbed .controls .card.active { flex: 0 1 auto; min-height: 0; }

h3 { font-size: 0.95rem; margin: 20px 0 10px; padding-top: 16px; border-top: 1px solid var(--border); }

label { display: block; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.field { margin-top: 14px; }
.field-label { margin-bottom: 4px; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.card > .field-label { margin-top: 16px; }
.soft { color: var(--muted); font-weight: 400; font-size: 0.82rem; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.row label { margin: 0; }
output { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; font-size: 0.88rem; }

.hint { color: var(--muted); font-size: 0.85rem; margin: 10px 0 0; }
.hint.first { margin-top: 0; }
.hint strong { color: var(--text); font-weight: 600; }
code {
    background: var(--soft);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: var(--mono);
    font-size: 0.82rem;
    color: var(--text);
    overflow-wrap: anywhere;
    user-select: all;
}
kbd {
    display: inline-block;
    min-width: 18px;
    padding: 0 5px;
    border: 1px solid var(--border);
    border-bottom-width: 2px;
    border-radius: 4px;
    background: #fff;
    font: inherit;
    font-size: 0.78rem;
    text-align: center;
    color: var(--text);
}

input[type=range] { display: block; width: 100%; margin: 8px 0 0; accent-color: var(--primary); }

select, textarea {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text);
    background: #fff;
}
textarea { resize: vertical; font-family: var(--mono); font-size: 0.88rem; line-height: 1.5; }
select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }

.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 0.9rem; color: var(--text); margin-top: 12px; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }

.two { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: end; }
.hint + .two { margin-top: 12px; }
.two > .checkbox { margin: 0 0 9px; }
.two > .field { margin-top: 0; }

.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* Segmented choices, as in the QR generator. */
.seg { display: flex; margin-top: 4px; }
.seg-btn { flex: 1; background: #fff; color: var(--muted); border: 1px solid var(--border); border-radius: 0; margin: 0; }
.seg-btn:first-child { border-radius: 6px 0 0 6px; }
.seg-btn:last-child { border-radius: 0 6px 6px 0; }
.seg-btn + .seg-btn { border-left: none; }
.seg-btn:hover { background: var(--soft); }
.seg-btn[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }
.seg-btn[aria-pressed="true"]:hover { background: var(--primary-dark); }
.seg-btn[aria-pressed="true"] + .seg-btn { border-left: 1px solid var(--primary); }

.swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 4px; }
.sw { width: 30px; height: 30px; padding: 0; border-radius: 50%; background: var(--c); border: 2px solid var(--border); box-shadow: inset 0 0 0 2px #fff; }
.sw:hover { background: var(--c); border-color: var(--muted); }
.sw[aria-pressed="true"] { border-color: var(--primary); }
input[type="color"] { width: 54px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; }
.swatches input[type="color"] { width: 30px; height: 30px; padding: 0; border: 2px solid var(--border); border-radius: 50%; overflow: hidden; background: transparent; }
.swatches input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.swatches input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 50%; }
.swatches input[type="color"]::-moz-color-swatch { border: 0; border-radius: 50%; }
input[type="color"].active { border-color: var(--primary); }
input[type="color"]:disabled { opacity: .45; cursor: not-allowed; }
.is-off { opacity: .5; }

.offset { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.offset .val { font: 700 1.4rem/1 var(--mono); font-variant-numeric: tabular-nums; }
.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }

.file-row { display: grid; grid-template-columns: 78px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.file-row:first-of-type { border-top: 0; padding-top: 0; }
.file-label { font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.file-name { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-name.empty { color: var(--muted); }
.file-btns { display: flex; gap: 6px; }

.fix { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.fix summary { cursor: pointer; font-size: 0.9rem; font-weight: 600; }

.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; font-size: 0.88rem; align-items: center; }
.keys dt { margin: 0; white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }

/* ------------------------------------------------------------------ the picture */

.stage { position: relative; isolation: isolate; width: 100%; aspect-ratio: 16 / 9; max-height: calc(100vh - 250px); min-height: 200px; background: #000; border-radius: 6px; overflow: hidden; }
.stage:fullscreen { width: 100%; height: 100%; max-height: none; min-height: 0; aspect-ratio: auto; border-radius: 0; }
.stage:-webkit-full-screen { width: 100%; height: 100%; max-height: none; min-height: 0; aspect-ratio: auto; border-radius: 0; }
body.dragging .stage { outline: 3px dashed var(--primary); outline-offset: -8px; }
video { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }

.preview { position: absolute; inset: 0; z-index: 1;
  background: radial-gradient(55% 45% at 72% 36%, rgba(255,255,255,.10), transparent 70%),
              linear-gradient(180deg, #2c3e50, #46515a 58%, #6b5d4a); }
.pv-burned { position: absolute; left: 4%; right: 4%; bottom: 7%; text-align: center; color: #fff;
  font: 500 calc(var(--stage-h, 400px) * .046)/1.3 "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 .06em .2em #000; }

.subs { position: absolute; inset: 0; z-index: 3; width: 100%; height: 100%; pointer-events: none; }

.pv-card { position: absolute; z-index: 5; left: 50%; top: 6%; transform: translateX(-50%); width: min(470px, 90%); display: flex; flex-direction: column; gap: 8px; padding: 16px 18px; background: rgba(255,255,255,.97); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.pv-title { margin: 0; font-size: 1rem; font-weight: 700; line-height: 1.3; text-wrap: balance; }
.pv-text { margin: 0; color: var(--muted); font-size: 0.85rem; }
.pv-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
@media (max-width: 760px) { .pv-text { display: none; } .pv-card { top: 4%; padding: 10px 12px; gap: 6px; } .pv-title { font-size: 0.9rem; } }
.has-video .preview, .has-video .pv-card { display: none; }

.osd { position: absolute; z-index: 6; top: 12px; left: 50%; transform: translateX(-50%); max-width: 90%; padding: 7px 12px; border-radius: 6px; background: rgba(20,24,32,.88); color: #fff; font-size: 0.85rem; font-weight: 600; line-height: 1.35; text-align: center; opacity: 0; transition: opacity .18s; pointer-events: none; }
.osd.show { opacity: 1; }

.rec-badge { position: absolute; z-index: 6; left: 12px; top: 12px; display: inline-flex; align-items: center; gap: 8px; padding: 5px 11px; border-radius: 999px; background: rgba(20,24,32,.88); color: #fff; font-size: 0.82rem; font-weight: 600; }
.rec-badge .dot { width: 9px; height: 9px; border-radius: 50%; background: #ff4d4d; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* The map of which parts play: the bar is the whole video, the blue is what is kept. */
.timeline { position: relative; height: 22px; margin-top: 12px; border-radius: 6px; background: repeating-linear-gradient(135deg, var(--soft) 0 6px, #e3e6ee 6px 12px); border: 1px solid var(--border); cursor: pointer; overflow: hidden; }
.tl-track { position: absolute; inset: 0; }
.tl-keep { position: absolute; top: 0; bottom: 0; background: var(--primary); opacity: .88; }
.tl-head { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--danger); pointer-events: none; z-index: 1; }

.status { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin-top: 12px; font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.status .now { min-width: 0; overflow-wrap: anywhere; }
.status .right { display: flex; align-items: center; gap: 10px; }
.status .clock { color: var(--text); font-family: var(--mono); font-weight: 600; }

/* ------------------------------------------------------------------ trim and render */

/* The list of parts: Start on the left, Finish on the right, one row each. */
/* The parts list takes the room the tab has, up to ten parts in full, and scrolls beyond that (player.js sets the limits in pixels:
   a note under a part makes it taller, so rows are measured, not counted). The heading keeps room for the scroll bar too, so Start
   and Finish stay over their columns. */
#cardTrim.active { display: flex; flex-direction: column; }
.trim-list, .audit { display: flex; flex-direction: column; flex: 0 1 auto; min-height: 0; }
#trimRows, .audit-list { position: relative; min-height: 0; overflow-y: auto; }
#trimRows { scrollbar-gutter: stable; }
.trim-head { flex: none; overflow-y: hidden; scrollbar-gutter: stable; }
.cap-note { margin: 6px 0 0; font-size: 0.78rem; color: var(--muted); }

.trim-head, .trim-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 48px 28px; column-gap: 8px; align-items: center; }
.trim-head span { text-align: center; }
.trim-head { margin-top: 14px; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.trim-row { margin-top: 8px; }
.trim-row .tr-len { font: 500 0.78rem var(--mono); color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.trim-row .tr-rm { width: 28px; height: 28px; padding: 0; font-size: 1.1rem; line-height: 1; color: var(--muted); }
.trim-row .tr-rm:hover { color: var(--danger); border-color: #f3c3c3; background: #fdecec; }
.trim-row .tr-note { grid-column: 1 / -1; margin: 3px 0 0; font-size: 0.8rem; color: var(--warn); }
.trim-row .tr-note:empty { display: none; }
.trim-row.err .tr-note { color: #a12a2a; }
.trim-row.err .tf { border-color: #e9a4a4; background: #fff7f7; }
.trim-row .tf { transition: background .6s, border-color .6s; }
.trim-row.flash .tf { border-color: var(--primary); background: #f0f4ff; }

/* A time field: hours, minutes and seconds in one box with one part selected. The block that shows which part is selected
   stands in for a cursor, so the cursor is hidden. */
.tf { width: 100%; min-width: 0; padding: 8px 4px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text);
      font: 600 1rem var(--mono); letter-spacing: 0.04em; text-align: center; font-variant-numeric: tabular-nums; caret-color: transparent; cursor: text; }
.tf::selection { background: var(--primary); color: #fff; }
.tf:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }

.trim-sum { margin: 8px 0 0; font-size: 0.85rem; font-weight: 600; }
.trim-sum:empty { display: none; }

/* Audit: the stretches the list leaves out, each with Review (play just that) and Include (add it to the list). */
#trimAudit[aria-expanded="true"] { background: var(--soft); }
.audit { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.audit-sum { margin: 0; font-size: 0.85rem; font-weight: 600; }
.au-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; padding: 6px 8px 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.au-row.reviewing { border-color: var(--primary); background: #f0f4ff; }
.au-when { display: flex; flex-direction: column; min-width: 0; }
.au-range { font: 600 0.85rem var(--mono); font-variant-numeric: tabular-nums; }
.au-len { font-size: 0.78rem; color: var(--muted); }
.au-btns { display: flex; flex: none; gap: 6px; }

.progress { height: 10px; margin-top: 12px; border-radius: 999px; background: var(--soft); overflow: hidden; border: 1px solid var(--border); }
.progress-fill { height: 100%; width: 0; background: var(--primary); transition: width .3s linear; }
.rd-status { margin: 8px 0 0; font-size: 0.88rem; min-height: 1.3em; }
.rd-status.err { color: #a12a2a; }
.rd-status.ok { color: var(--ok); font-weight: 600; }

@media (prefers-reduced-motion: reduce) { *, .rec-badge .dot { transition: none !important; animation: none !important; } }
