:root {
  --bg: #0c0e11;
  --panel: rgba(20, 23, 28, 0.88);
  --panel-solid: #15181d;
  --line: rgba(255, 255, 255, 0.08);
  --hover: rgba(255, 255, 255, 0.1);
  --text: #e8ecf1;
  --muted: #8a94a3;
  --accent: #4cc9f0;
  --danger: #ff6b6b;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.mono { font-family: ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
.spacer { flex: 1; }

#board { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.icon { width: 36px; padding: 0; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: transparent; color: #06121a; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--hover); }
.btn.big { height: 46px; padding: 0 24px; font-size: 16px; border-radius: 12px; }
.btn.on { color: var(--c, var(--accent)); border-color: color-mix(in srgb, var(--c, var(--accent)) 50%, transparent); }
.btn.danger:hover { color: var(--danger); }
.btn svg { flex: none; }

.seg { display: inline-flex; padding: 2px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); }
.seg button {
  height: 28px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font: inherit; font-size: 13px; cursor: pointer;
}
.seg button.on { background: rgba(255, 255, 255, 0.12); color: var(--text); }
.seg button:disabled { opacity: 0.35; cursor: default; }

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

.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px; pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand { font-weight: 700; letter-spacing: -0.01em; font-size: 16px; }
.actions { display: flex; gap: 6px; }
.actions .btn:not(.primary) { background: var(--panel); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }

/* ---------- empty state ---------- */

.empty {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; text-align: center; pointer-events: none;
}
.empty > * { pointer-events: auto; }
.empty h1 { margin: 0; font-size: clamp(24px, 5vw, 34px); letter-spacing: -0.02em; }
.empty p { margin: 0 0 8px; color: var(--muted); max-width: 380px; }
.empty .fine { font-size: 12px; margin-top: 8px; }
.empty-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- dock: selected bar, transport, timeline ---------- */

.dock {
  position: fixed; z-index: 2; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  width: min(980px, calc(100% - 24px));
  background: var(--panel); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line); border-radius: 16px; padding: 8px;
  display: flex; flex-direction: column; gap: 6px;
}

.selbar { display: flex; align-items: center; gap: 4px; padding-bottom: 6px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.selbar::-webkit-scrollbar { display: none; }
.selbar .btn { flex: none; background: transparent; border-color: transparent; }
.selbar .btn:hover { background: var(--hover); }
.selbar .btn.on { color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.swatch span { width: 16px; height: 16px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent); }
.name {
  flex: 0 1 180px; min-width: 80px; height: 32px; padding: 0 8px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--text); font: inherit; font-weight: 600;
}
.name:hover { border-color: var(--line); }
.name:focus { outline: none; border-color: var(--c); background: rgba(0, 0, 0, 0.25); }
.grp { display: flex; align-items: center; flex: none; padding: 0 4px; margin: 0 4px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.slip { min-width: 70px; height: 30px; border: 0; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; border-radius: 6px; }
.slip:hover { color: var(--text); background: var(--hover); }

.transport { display: flex; align-items: center; gap: 8px; }
.transport #play { background: rgba(255, 255, 255, 0.1); }
#time { color: var(--muted); min-width: 56px; font-size: 13px; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; bottom: calc(100% + 8px); z-index: 3; width: 250px; padding: 4px;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.menu button {
  display: block; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: transparent;
  color: var(--text); font: inherit; font-weight: 500; text-align: left; cursor: pointer;
}
.menu button:hover { background: var(--hover); }
.menu small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }

/* Scrub ruler, lined up with the timeline tracks. */
.ruler { display: grid; grid-template-columns: 28px 96px 1fr; gap: 6px; height: 24px; margin-top: 2px; }
.ruler .scrub { grid-column: 3; position: relative; cursor: ew-resize; touch-action: none; border-radius: 6px; }
.ruler .scrub:hover { background: rgba(255, 255, 255, 0.03); }
.ruler .ticks i { position: absolute; bottom: 0; width: 1px; height: 5px; background: rgba(255, 255, 255, 0.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;
}
.timeline { display: flex; flex-direction: column; gap: 3px; max-height: 32vh; overflow-y: auto; }
.timeline .row { display: grid; grid-template-columns: 28px 96px 1fr; align-items: center; gap: 6px; height: 30px; border-radius: 8px; }
.timeline .row.sel { background: rgba(255, 255, 255, 0.04); }
.timeline .pp {
  width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--c);
  display: grid; place-items: center; cursor: pointer;
}
.timeline .pp:hover { background: var(--hover); }
.timeline .pp svg { width: 14px; height: 14px; }
.timeline .nm { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timeline .row.sel .nm { color: var(--text); }
.track { position: relative; height: 100%; border-radius: 6px; background: rgba(255, 255, 255, 0.025); cursor: pointer; touch-action: none; overflow: hidden; }
/* The untrimmed animation, behind its bar: the cut parts show as faint stripes. */
.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);
}
.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);
}
.row.sel .bar { background: color-mix(in srgb, var(--c) 42%, transparent); border-color: var(--c); }
.row.paused .bar { background: repeating-linear-gradient(-45deg, color-mix(in srgb, var(--c) 22%, transparent) 0 5px, transparent 5px 10px); }
.bar:active { cursor: grabbing; }
.edge { position: absolute; top: -5px; bottom: -5px; width: 14px; cursor: ew-resize; }
.edge.l { left: -7px; }
.edge.r { right: -7px; }
.edge::after { content: ""; position: absolute; top: 9px; bottom: 9px; left: 6px; width: 2px; border-radius: 1px; background: var(--c); opacity: 0; }
.row.sel .edge::after, .edge:hover::after { opacity: 1; }
.sync { position: absolute; top: 50%; width: 9px; height: 9px; background: #fff; transform: translate(-50%, -50%) rotate(45deg); border-radius: 1px; pointer-events: none; }
.ph { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: rgba(255, 255, 255, 0.85); pointer-events: none; }

.renamer {
  position: fixed; z-index: 5; padding: 0 8px; border-radius: 7px; text-align: center;
  border: 1.5px solid var(--c); background: var(--panel-solid); color: var(--text);
  font: 600 13px system-ui, -apple-system, sans-serif; outline: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}
.timeline .nm { cursor: text; }

/* ---------- toast, drop ---------- */

.toast {
  position: fixed; z-index: 10; top: calc(64px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  padding: 8px 14px; border-radius: 10px; background: var(--panel-solid); border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); max-width: calc(100% - 32px); text-align: center;
}
.drop {
  position: fixed; inset: 10px; z-index: 20; border: 2px dashed var(--accent); border-radius: 18px;
  background: rgba(76, 201, 240, 0.06); display: grid; place-items: center; pointer-events: none;
  font-size: 18px; font-weight: 600; color: var(--accent);
}

/* ---------- dialogs ---------- */

dialog { color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

.sheet {
  width: min(440px, calc(100% - 32px)); padding: 20px; border-radius: 16px;
  background: var(--panel-solid); border: 1px solid var(--line);
}
.sheet h2 { margin: 0 0 16px; font-size: 18px; }
.sheet p { color: var(--muted); margin: 0 0 16px; }
.sheet .field { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.sheet .field > span { color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; margin: 10px 0; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.sheet-foot { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.ex-result { margin-top: 14px; }
.ex-result video { width: 100%; max-height: 46vh; border-radius: 10px; background: #000; display: block; }
.ex-result .ex-info { margin: 8px 0 0; font-size: 12px; }

/* ---------- import wizard ---------- */

.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;
  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 .fill { position: absolute; top: 15px; height: 10px; left: var(--a); width: calc(var(--b) - var(--a)); border-radius: 5px; background: var(--accent); opacity: 0.85; }
.trimbar .handle {
  position: absolute; top: 6px; width: 14px; height: 28px; margin-left: -7px; border-radius: 5px;
  background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); cursor: ew-resize;
}
.trimbar .handle.in { left: var(--a); }
.trimbar .handle.out { left: var(--b); }
.trimbar .ph { position: absolute; top: 2px; bottom: 2px; left: var(--p); width: 2px; margin-left: -1px; background: #fff; opacity: 0.7; pointer-events: none; }
.wizard:not([data-step="trim"], [data-step="pick"]) .trimbar .handle { display: none; }
.wizard:not([data-step="trim"], [data-step="pick"]) .trimbar .fill { opacity: 0.35; }
.trimbar .strip { display: none; }

/* Picking a part of an unplayable video: a filmstrip with the chosen part outlined. */
.wizard[data-step="pick"] .wz-play { display: none; }
.wizard[data-step="pick"] .trimbar { height: 56px; }
.wizard[data-step="pick"] .trimbar::before { 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.45;
}
.trimbar .strip img { flex: 1; min-width: 0; height: 100%; object-fit: cover; }
.trimbar .strip img:not([src]) { visibility: hidden; }
.wizard[data-step="pick"] .trimbar .fill {
  top: 2px; height: 52px; border-radius: 8px; opacity: 1;
  background: rgba(76, 201, 240, 0.14); border: 2px solid var(--accent);
}
.wizard[data-step="pick"] .trimbar .handle { top: 2px; height: 52px; width: 12px; margin-left: -6px; background: var(--accent); }
.wizard[data-step="extract"] :is(.wz-play, .trimbar), .wizard[data-step="convert"] :is(.wz-play, .trimbar) { display: none; }
.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-solid); 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-foot { display: flex; align-items: center; gap: 8px; width: min(820px, 100%); justify-self: center; }

/* ---------- 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-solid); 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; }

/* ---------- phones ---------- */

@media (max-width: 640px) {
  .lbl { display: none; }
  #add { width: 36px; padding: 0; }
  .timeline .row, .ruler { grid-template-columns: 28px 56px 1fr; }
  /* Two rows: name and file actions, then timing tools. */
  .selbar { flex-wrap: wrap; overflow: visible; row-gap: 2px; }
  .selbar::before { content: ""; flex-basis: 100%; order: 2; }
  .selbar .name { flex: 1 1 0; }
  .selbar .spacer { display: none; }
  .selbar .grp, #sb-sync, #sb-mirror { order: 3; }
  .selbar .grp { margin-left: 0; padding-left: 0; border-left: 0; }
  /* The bar gets the full width; its readout goes underneath. */
  .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; }
  .rc-delay button { padding: 0 7px; }
}
