:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1e2530;
  --line: #2b3440;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #4cc9f0;
  --radius: 10px;
  --hover: rgba(255, 255, 255, .08);
  --danger: #ff6b6b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.spacer { flex: 1; }
.mono { font-family: ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}
h1 { margin: 0; font-size: 20px; letter-spacing: .2px; }
.disclaimer { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px; }

.actions { display: flex; gap: 10px; align-items: center; }
.gear-wrap { position: relative; }
#gear { display: grid; place-items: center; padding: 6px; }
#gear[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
.settings-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 10;
  width: 260px; padding: 14px;
  display: grid; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.settings-panel[hidden] { display: none; }
.settings-panel h2 { margin: 0; }
.settings-panel label { display: grid; gap: 4px; }
.settings-panel .note { margin: 0; }
label { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }

button, select, .file {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover:not(:disabled), .file:hover { border-color: #3d4a5a; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: #1f6feb; border-color: #1f6feb; color: #fff; }
.check { cursor: pointer; }

main { padding: 16px 20px 40px; display: grid; gap: 16px; max-width: 1500px; margin: 0 auto; }

/* The selected shooter's bar, under the board */
.selbar { --c: var(--accent); display: grid; gap: 8px; padding: 10px 12px; border-radius: 8px; background: var(--panel-2); border-left: 3px solid var(--c); }
.sb-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--muted); min-width: 0; }
.selbar .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.name {
  flex: 1 1 8em; min-width: 5em; max-width: 16em;
  font: inherit; font-weight: 600; color: var(--text);
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  padding: 3px 6px;
  text-overflow: ellipsis;
}
.name:hover, .name:focus { border-color: var(--line); background: var(--panel); outline: none; }
.selbar .seg button.on { background: color-mix(in srgb, var(--c) 30%, transparent); color: var(--text); }
.sb-rel output { color: var(--text); font-variant-numeric: tabular-nums; }
.status { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 0; }
.sync-btn.on { border-color: var(--c); color: var(--c); }
.save-status { color: var(--muted); }

/* Hidden players for the shooters' videos, which are drawn onto the board */
#videos { position: fixed; left: 0; top: 0; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
#videos video { width: 1px; height: 1px; }

/* compare */
.compare {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
}
.compare-stage, .panel, .chart {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.compare-stage { position: relative; padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; min-width: 0; }
.board-wrap { position: relative; }
#board { width: 100%; height: 560px; display: block; border-radius: 8px; background: #0b0e12; touch-action: none; }
.board-wrap.over #board { outline: 2px dashed var(--accent); outline-offset: -2px; }
.empty {
  position: absolute; inset: 0; padding: 24px;
  display: grid; place-items: center; text-align: center;
  color: var(--muted); margin: 0; pointer-events: none;
}
.empty span { max-width: 34em; }
.file.primary { background: #1f6feb; border-color: #1f6feb; color: #fff; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--panel-2); color: var(--text); }
.hint { color: var(--muted); margin-left: auto; }

.panel { padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.nums { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin-bottom: 14px; }
.nums th, .nums td { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--line); }
.nums th:first-child, .nums td:first-child { text-align: left; color: var(--muted); font-weight: 400; }
.nums thead th { font-size: 12px; font-weight: 600; }
.nums thead th span { display: inline-block; max-width: 6.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.nums .d { color: var(--muted); }
.note { color: var(--muted); font-size: 12px; margin: auto 0 0; }

/* Transport, scrub ruler and one timeline row per clip (ported from MagicXray). */
.transport { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
#play { width: 42px; }
#tlabel { width: 70px; text-align: right; font-variant-numeric: tabular-nums; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 5; width: 270px; padding: 4px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
}
.menu button {
  display: block; width: 100%; padding: 8px 10px; border: 0; border-radius: 7px; background: transparent;
  color: var(--text); font-weight: 500; text-align: left;
}
.menu button:hover { background: var(--hover); }
.menu button.on::after { content: " ✓"; color: var(--accent); }
.menu small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }

.ruler, .tracks .row { display: grid; grid-template-columns: 28px 120px 1fr; gap: 6px; }
.ruler { height: 24px; }
.ruler .scrub { grid-column: 3; position: relative; cursor: ew-resize; touch-action: none; border-radius: 6px; }
.ruler .scrub:hover { background: rgba(255, 255, 255, .03); }
.ruler .ticks i { position: absolute; bottom: 0; width: 1px; height: 5px; background: rgba(255, 255, 255, .2); }
.ruler .ticks b {
  position: absolute; bottom: 7px; left: 0; transform: translateX(-50%);
  font: 500 10px ui-monospace, Menlo, monospace; color: var(--muted); white-space: nowrap; pointer-events: none;
}
.ruler .knob { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: #fff; pointer-events: none; }
.ruler .knob::before {
  content: ""; position: absolute; top: 0; left: 50%; width: 12px; height: 9px; transform: translateX(-50%);
  border-radius: 3px 3px 6px 6px; background: #fff;
}
.tracks { display: flex; flex-direction: column; gap: 3px; }
.tracks .row { align-items: center; height: 30px; border-radius: 7px; }
.tracks .row.sel { background: rgba(255, 255, 255, .04); }
.tracks .pp {
  width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--c);
  display: grid; place-items: center;
}
.tracks .pp:hover:not(:disabled) { background: var(--hover); }
.tracks .pp svg { width: 14px; height: 14px; }
.tracks .nm { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.tracks .nm b { color: var(--c); }
.tracks .row.sel .nm { color: var(--text); }
.tracks .track { position: relative; height: 100%; border-radius: 6px; background: rgba(255, 255, 255, .025); cursor: pointer; touch-action: none; overflow: hidden; }
/* The untrimmed clip, behind its bar: the cut parts show as faint stripes. */
.tracks .ghost {
  position: absolute; top: 5px; bottom: 5px; border-radius: 5px; cursor: grab;
  border: 1px dashed color-mix(in srgb, var(--c) 35%, transparent);
  background: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--c) 10%, transparent) 0 4px, transparent 4px 8px);
}
.tracks .bar {
  position: absolute; top: 5px; bottom: 5px; min-width: 6px; border-radius: 5px; cursor: grab;
  background: color-mix(in srgb, var(--c) 28%, transparent); border: 1px solid color-mix(in srgb, var(--c) 70%, transparent);
}
.tracks .row.sel .bar { background: color-mix(in srgb, var(--c) 42%, transparent); border-color: var(--c); }
.tracks .row.paused .bar { background: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--c) 22%, transparent) 0 5px, transparent 5px 10px); }
.tracks .bar:active { cursor: grabbing; }
.tracks .edge { position: absolute; top: -5px; bottom: -5px; width: 14px; cursor: ew-resize; }
.tracks .edge.l { left: -7px; }
.tracks .edge.r { right: -7px; }
.tracks .edge::after { content: ""; position: absolute; top: 9px; bottom: 9px; left: 6px; width: 2px; border-radius: 1px; background: var(--c); opacity: 0; }
.tracks .row.sel .edge::after, .edge:hover::after { opacity: 1; }
/* ◆ the sync point; an outlined ◇ at the release when none is marked (release is the default). */
.tracks .sync { position: absolute; top: 50%; width: 9px; height: 9px; background: #fff; transform: translate(-50%, -50%) rotate(45deg); border-radius: 1px; pointer-events: none; }
.tracks .sync.rel { background: transparent; border: 1.5px solid #fff; opacity: .8; }
.tracks .ph { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: rgba(255, 255, 255, .85); pointer-events: none; }

.keys { margin: 0; color: var(--muted); font-size: 12px; }
kbd {
  font: inherit; font-size: 11px;
  padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  background: var(--panel-2); color: var(--text);
}
@media (hover: none) { .keys { display: none; } }

.chart { grid-column: 1 / -1; padding: 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; min-width: 0; }
#metric { max-width: 100%; overflow-x: auto; }
#metric button { white-space: nowrap; }
#chart { width: 100%; height: 220px; display: block; }

@media (max-width: 1000px) {
  .compare { grid-template-columns: minmax(0, 1fr); }
  #board { height: 440px; }
}
@media (max-width: 760px) {
  main { padding: 12px 16px 32px; }
  #board { height: 380px; }
  .hint { margin-left: 0; }
  .ruler, .tracks .row { grid-template-columns: 28px 64px 1fr; }
}

/* export */
#export-dialog, #admin-dialog {
  max-width: min(420px, calc(100vw - 32px));
  padding: 16px;
  color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
}
#export-dialog::backdrop, #admin-dialog::backdrop { background: rgba(0, 0, 0, .6); }
#export-dialog h2, #admin-dialog h2 { margin: 0 0 10px; font-size: 16px; }
#admin-form { display: grid; gap: 10px; min-width: min(300px, calc(100vw - 64px)); }
#admin-form label { display: grid; gap: 4px; }
#admin-key { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; }
.admin-error { margin: 0; color: #f0883e; }

/* Featured-shot controls show only in a browser unlocked with the admin key. */
body:not(.admin) .admin-only { display: none; }
.admin-tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 4px 2px 10px; border-radius: 7px;
  background: #3a2a10; color: #f0b44c; font-size: 12px; font-weight: 700;
}
.admin-tag[hidden] { display: none; }
.admin-tag button { padding: 2px 8px; font-size: 12px; }
#export-preview { width: 100%; aspect-ratio: 1; display: block; border-radius: 8px; background: #0b0e12; }
.export-info { color: var(--muted); margin: 10px 0 4px; }
.export-link-row { margin: 0 0 12px; overflow-wrap: anywhere; }
#export-link { color: var(--accent); }
.export-actions { display: flex; flex-wrap: wrap; gap: 8px; }
#export-close { margin-left: auto; }

/* ---------- import guide and recorder (ported from MagicXray) ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 9px;
  font-weight: 500; white-space: nowrap; user-select: none; -webkit-tap-highlight-color: transparent;
}
.btn.icon { width: 36px; padding: 0; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--text); background: var(--hover); }
.btn svg { flex: none; }
.wizard .seg button { height: 34px; white-space: nowrap; }
dialog.wizard, dialog.recorder { color: var(--text); }
dialog.wizard::backdrop, dialog.recorder::backdrop { background: rgba(0, 0, 0, .6); }


.wizard {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: var(--bg);
}
.wizard[open] {
  display: grid; grid-template-rows: auto auto 1fr auto auto; grid-template-columns: minmax(0, 1fr);
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(14px + env(safe-area-inset-bottom));
  gap: 10px;
}
.wz-head { display: flex; align-items: center; justify-content: space-between; }
.steps { display: flex; gap: 6px; margin: 0; padding: 0; list-style: none; overflow-x: auto; }
.steps li { display: flex; align-items: center; gap: 6px; padding: 6px 10px 6px 6px; border-radius: 999px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.steps b { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; background: rgba(255, 255, 255, 0.08); }
.steps li.on { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.steps li.on b { background: var(--accent); color: #06121a; }
.steps li.done b { background: rgba(76, 201, 240, 0.25); color: var(--accent); }
.wz-hint { margin: 0; color: var(--muted); text-align: center; }
.wz-hint.error { color: var(--danger); }
.wz-stage { position: relative; min-height: 0; border-radius: 14px; overflow: hidden; background: #000; }
.wz-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.wz-overlay { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.wz-frame { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.wizard[data-step="crop"] .wz-overlay { cursor: crosshair; }
.wz-bar { display: flex; align-items: center; gap: 12px; width: min(820px, 100%); justify-self: center; }
.wz-info { color: var(--muted); font-size: 12px; min-width: 150px; text-align: right; }

.trimbar { --a: 0%; --b: 100%; --p: 0%; position: relative; flex: 1; height: 40px; cursor: pointer; touch-action: none; }
.trimbar::before { content: ""; position: absolute; left: 0; right: 0; top: 17px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); }
.trimbar .ph { position: absolute; top: 2px; bottom: 2px; left: var(--p); width: 3px; margin-left: -1.5px; border-radius: 2px; background: #fff; pointer-events: none; }
.trimbar .strip { display: none; }

/* Finding the shot in an unplayable video: a filmstrip of the original to scrub along. */
.wizard[data-step="pick"] .trimbar { height: 56px; }
.wizard[data-step="pick"] .trimbar::before { display: none; }
.trimbar .marks { position: absolute; left: 0; right: 0; top: 4px; height: 5px; pointer-events: none; }
.trimbar .marks i { position: absolute; top: 0; height: 4px; min-width: 3px; border-radius: 2px; opacity: 0.9; }
.wizard[data-step="pick"] .trimbar .marks { display: none; }
.wizard[data-step="pick"] .trimbar .strip {
  position: absolute; inset: 4px 0; display: flex; gap: 2px; border-radius: 8px; overflow: hidden;
  background: rgba(255, 255, 255, 0.06); opacity: 0.8;
}
.trimbar .strip img { flex: 1; min-width: 0; height: 100%; object-fit: cover; }
.trimbar .strip img:not([src]) { visibility: hidden; }
.wizard[data-step="extract"] :is(.wz-play, .trimbar), .wizard[data-step="convert"] :is(.wz-play, .trimbar) { display: none; }
/* The box and rim go on the shot's first frame: nothing to scrub. */
.wizard[data-step="crop"] :is(.wz-play, .trimbar) { visibility: hidden; }
.wz-fallback {
  position: absolute; inset: 0; margin: auto; width: min(560px, calc(100% - 32px)); height: fit-content;
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.wz-fallback p { margin: 0; color: var(--muted); }
.wz-fallback code {
  display: block; width: 100%; padding: 10px 12px; border-radius: 8px; background: rgba(0, 0, 0, 0.4);
  font: 12px/1.5 ui-monospace, Menlo, monospace; color: var(--text); word-break: break-all; user-select: all;
}
.wz-progress { flex: 1; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.wz-progress div { height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
.wz-keys { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.wz-keys kbd {
  display: inline-block; min-width: 18px; padding: 1px 5px; margin: 0 1px; border-radius: 4px; text-align: center;
  border: 1px solid var(--line); border-bottom-width: 2px; background: rgba(255, 255, 255, 0.04);
  font: 500 11px ui-monospace, Menlo, monospace; color: var(--text);
}
/* Shortcut hints only where there's a keyboard. */
@media (pointer: coarse), (max-width: 900px) { .wz-keys { display: none; } }
.wz-foot { display: flex; align-items: center; gap: 8px; width: min(820px, 100%); justify-self: center; }
.wz-foot > :not(.wz-keys, .spacer) { flex: none; } /* only the shortcut hints give way */

/* ---------- recorder ---------- */

.recorder {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: var(--bg);
}
.recorder[open] {
  display: grid; grid-template-rows: auto 1fr auto; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}
.rc-head { display: flex; align-items: center; gap: 12px; }
.rc-title { font-weight: 700; font-size: 16px; }
.rc-info { color: var(--muted); font-size: 12px; }
.rc-stage { position: relative; min-height: 0; border-radius: 14px; overflow: hidden; background: #000; }
.rc-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.rc-stage video.mirror { transform: scaleX(-1); }
.rc-count {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: min(40vw, 220px); font-weight: 800; color: #fff; text-shadow: 0 4px 30px rgba(0, 0, 0, 0.6);
}
.rc-msg {
  position: absolute; inset: 0; margin: auto; width: min(420px, calc(100% - 32px)); height: fit-content;
  padding: 16px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); text-align: center;
}
.rc-foot { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.rc-delay { justify-self: start; white-space: nowrap; }
.rc-side { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.rc-time { color: var(--muted); font-size: 13px; }
.recorder[data-state="rec"] .rc-time { color: #ff4d4d; }
.recorder:not([data-state="idle"]) :is(.rc-delay, .rc-flip) { visibility: hidden; }
.rc-btn {
  width: 72px; height: 72px; border-radius: 50%; border: 4px solid #fff; background: transparent;
  display: grid; place-items: center; cursor: pointer; padding: 0; -webkit-tap-highlight-color: transparent;
}
.rc-btn span { width: 54px; height: 54px; border-radius: 50%; background: #ff3b30; transition: all 0.15s; }
.recorder[data-state="rec"] .rc-btn span, .recorder[data-state="saving"] .rc-btn span { width: 28px; height: 28px; border-radius: 6px; }
.recorder[data-state="count"] .rc-btn span { opacity: 0.5; }


@media (max-width: 640px) {
  .wz-bar { flex-wrap: wrap; row-gap: 4px; }
  .wz-bar .trimbar, .wz-bar .wz-progress { flex: 1 1 0; min-width: 0; }
  .wz-info { min-width: 0; width: 100%; text-align: center; order: 3; }
  .wz-foot .seg button { padding: 0 8px; }
  .wz-foot { flex-wrap: wrap; justify-content: flex-end; row-gap: 6px; }
  .rc-delay button { padding: 0 7px; }
}
