:root {
  color-scheme: dark;
  --bg: #0b0c0e; --panel: #15171b; --raised: #1f2228; --line: #2c3038; --fg: #e9eaee; --muted: #9298a4;
  --accent: #4c9aff; --accent-fg: #06122a; --clip: #f5b94a; --err: #ff7b72; --track: #23262d;
  --r: 8px; --h: 38px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }

input, select, button {
  font: inherit; color: var(--fg); background: var(--raised); border: 1px solid var(--line); border-radius: var(--r);
  height: var(--h); padding: 0 .8rem;
}
button { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .35rem; white-space: nowrap; }
button:hover:not(:disabled) { border-color: #4a505c; background: #262a31; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #6aaeff; border-color: #6aaeff; }
button.quiet { background: transparent; border-color: transparent; color: var(--muted); }
button.quiet:hover:not(:disabled) { color: var(--fg); background: var(--raised); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 18px; height: 18px; fill: currentColor; flex: none; }

/* Login */
#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
#loginForm { background: var(--panel); border: 1px solid var(--line); padding: 2rem; border-radius: 14px; width: min(360px, 100%); display: grid; gap: .75rem; }
#loginForm h1 { margin: 0; font-size: 1.35rem; }
#loginForm .sub { margin: 0 0 .5rem; color: var(--muted); }
#loginErr { color: var(--err); margin: 0; min-height: 1.4em; }

/* Viewer */
#viewer { display: grid; grid-template-rows: minmax(0, 1fr) auto; height: 100vh; }
#stage { min-height: 0; padding: 8px; }
#grid { height: 100%; display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 8px; }
#grid.single .cell:not(.big) { display: none; }
.cell { position: relative; background: #000; border-radius: 6px; overflow: hidden; outline: 2px solid transparent; outline-offset: -2px; cursor: pointer; }
.cell.selected { outline-color: var(--accent); }
.cell video { width: 100%; height: 100%; object-fit: contain; display: block; }
.cell .label { position: absolute; top: 8px; left: 8px; background: #000b; padding: 3px 10px; border-radius: 6px; font-size: 13px; pointer-events: none; }
.cell.selected .label { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.cell .expand { position: absolute; top: 6px; right: 6px; height: 32px; padding: 0 .6rem; background: #000b; border-color: transparent; opacity: 0; transition: opacity .15s; }
.cell:hover .expand, .cell .expand:focus-visible, #grid.single .expand { opacity: 1; }
.cell .nofootage { position: absolute; inset: 0; display: none; place-items: center; color: var(--muted); pointer-events: none; }
.cell.gap .nofootage { display: grid; }
.cell.gap video { visibility: hidden; }

/* Dock */
#dock { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 12px 12px; display: grid; gap: 10px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.group { display: flex; align-items: center; gap: 6px; }
.group.end { margin-left: auto; }
.skip span { font-size: 13px; }
button.play { width: 52px; height: 44px; border-radius: 22px; padding: 0; }
button.play svg { width: 24px; height: 24px; }
.play .i-pause, .play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }
.seg { gap: 0; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; padding: 0 .7rem; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--raised); color: var(--fg); font-weight: 600; }
.clock { min-width: 12rem; }
#clockTime { font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.15; }
#clockDate { color: var(--muted); font-size: 12.5px; }
button.round { width: var(--h); padding: 0; border-radius: 50%; font-weight: 700; }

.pop { position: relative; }
.popover {
  position: absolute; bottom: calc(100% + 8px); right: 0; z-index: 10; background: var(--raised); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; box-shadow: 0 12px 32px #0009; min-width: 260px;
}
#gotoForm { display: grid; gap: 8px; }
#gotoForm label { color: var(--muted); font-size: 13px; }
#help { width: 340px; }
#help h2 { margin: 0 0 8px; font-size: 14px; }
#help dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
#help dt { color: var(--fg); white-space: nowrap; }
#help dd { margin: 0; color: var(--muted); }
kbd { font: 12px ui-monospace, monospace; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }

/* Timeline */
#timeline { position: relative; }
#tl { display: block; width: 100%; cursor: pointer; touch-action: none; }
#tlTip { position: absolute; top: -30px; transform: translateX(-50%); background: var(--raised); border: 1px solid var(--line); border-radius: 6px; padding: 2px 8px; font-size: 12px; font-variant-numeric: tabular-nums; pointer-events: none; white-space: nowrap; }

/* Clip strip */
.clip { border-top: 1px solid var(--line); padding-top: 10px; gap: 8px 14px; }
.clip-title { font-weight: 600; }
.step { display: inline-flex; align-items: center; gap: 8px; }
.step label { color: var(--muted); }
.time { font-variant-numeric: tabular-nums; color: var(--clip); min-width: 8.5em; }
.time.unset { color: var(--muted); }
#clipCam { max-width: 18rem; }
#clipHint { color: var(--muted); }
#clipHint.bad { color: var(--err); }

@media (max-width: 800px) {
  #stage { padding: 4px; }
  #grid { gap: 4px; }
  #dock { padding: 8px; }
  .group.end { margin-left: 0; }
  .clock { min-width: 0; }
  .skip span { display: none; }
  .popover { right: auto; left: 0; }
  #help { width: min(340px, calc(100vw - 32px)); }
}
