:root {
  --bg: #08090c;
  --panel: #111318;
  --panel-2: #161922;
  --line: #232734;
  --line-soft: #1b1e28;
  --text: #eceef4;
  --muted: #8a90a2;
  --faint: #5b6172;
  --accent: #a78bfa;
  --accent-2: #f472b6;
  --grad: linear-gradient(135deg, var(--accent), var(--accent-2));
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(167, 139, 250, .10), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(244, 114, 182, .07), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 12px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 12px; flex: none; color: inherit; text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--grad);
  display: grid; place-items: center; box-shadow: 0 6px 24px rgba(167, 139, 250, .35);
}
.brand-mark span { width: 10px; height: 18px; border-radius: 3px; border: 2px solid rgba(255, 255, 255, .9); }
.brand-name { font-weight: 700; letter-spacing: -.01em; font-size: 16px; }
.brand-sub { color: var(--muted); font-size: 13px; }
.topbar h1 {
  margin: 0 0 0 auto; font-size: 15px; font-weight: 600; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}

main { padding: 24px 28px 48px; max-width: 1600px; margin: 0 auto; }

/* ---------- stage ---------- */
/* Both panes are 1080 px tall in the pack, so columns sized in proportion to their pack
   widths come out the same height. --lw / --rw are set from the clip's demo.json. */
.stage { --lw: 1920; --rw: 608; --bezel: 10px; }
.panes {
  position: relative;
  display: grid; gap: 28px; align-items: start;
  grid-template-columns: var(--cols, minmax(0, 1920fr) minmax(0, 608fr));  /* --cols set per clip by demo.js */
  /* keep the pair inside the window height */
  max-width: calc((100vh - 230px) * (var(--lw) + var(--rw)) / 1080 + 28px + 2 * var(--bezel));
  margin: 0 auto;
}
.pane { margin: 0; min-width: 0; }
.pane canvas { display: block; width: 100%; height: auto; background: #000; }
.pane.wide canvas { border-radius: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.pane.phone .screen {
  padding: var(--bezel); border-radius: 30px; background: #000;
  border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0, 0, 0, .55), inset 0 0 0 1px #000;
}
.pane.phone canvas { border-radius: 21px; }
.pane figcaption { text-align: center; color: var(--muted); font-size: 12px; margin-top: 10px; }

.busy {
  position: absolute; left: 0; right: 0; top: 0; bottom: 34px;
  display: grid; place-items: center; pointer-events: none;
}
.busy[hidden] { display: none; }
.busy i {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .15); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- transport ---------- */
.transport {
  display: flex; align-items: center; gap: 14px;
  margin: 22px auto 0; max-width: 1100px;
  padding: 10px 14px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line);
}
.icon-btn {
  flex: none; display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: var(--text);
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn.play { width: 42px; height: 42px; background: var(--grad); color: #fff; border-radius: 50%; }
.icon-btn.play:hover { filter: brightness(1.08); background: var(--grad); }
.icon-btn .i-pause, .icon-btn .i-muted { display: none; }
.playing .icon-btn .i-play { display: none; }
.playing .icon-btn .i-pause { display: block; }
.muted .icon-btn .i-vol { display: none; }
.muted .icon-btn .i-muted { display: block; }
.time { flex: none; min-width: 58px; font-variant-numeric: tabular-nums; }
.time.dim { color: var(--muted); text-align: right; min-width: 40px; }

.scrub { position: relative; flex: 1; height: 28px; cursor: pointer; touch-action: none; outline: none; }
.scrub .track {
  position: absolute; left: 0; right: 0; top: 50%; height: 5px; margin-top: -2.5px;
  border-radius: 3px; background: var(--line); overflow: hidden;
}
.scrub .buffered, .scrub .played { position: absolute; left: 0; top: 0; bottom: 0; width: 0; }
.scrub .buffered { background: #343a4c; }
.scrub .played { background: var(--grad); }
.scrub .handle {
  position: absolute; top: 50%; left: 0; width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border-radius: 50%; background: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
  transform: scale(.85); transition: transform .1s;
}
.scrub:hover .handle, .scrub.dragging .handle, .scrub:focus-visible .handle { transform: scale(1.1); }
.hover-tip {
  position: absolute; bottom: 30px; transform: translateX(-50%);
  padding: 3px 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line);
  pointer-events: none; white-space: nowrap;
}

.speed { flex: none; display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.speed button { border: 0; background: transparent; padding: 5px 10px; color: var(--muted); font-size: 13px; }
.speed button.on { background: var(--panel-2); color: var(--text); }

.keys { text-align: center; color: var(--faint); font-size: 12px; margin: 10px 0 0; }

/* ---------- full screen ---------- */
.stage:fullscreen { background: var(--bg); padding: 28px; display: flex; flex-direction: column; justify-content: center; }
.stage:fullscreen .panes { max-width: calc((100vh - 170px) * (var(--lw) + var(--rw)) / 1080 + 28px + 2 * var(--bezel)); width: 100%; }
.stage:fullscreen .keys { display: none; }

/* ---------- clip list ---------- */
.clips { margin-top: 44px; }
.clips h2 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 14px; }
.clip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.clip {
  display: block; text-align: left; padding: 0; overflow: hidden;
  border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  transition: border-color .15s, transform .1s;
}
.clip:hover { border-color: #3a4052; }
.clip.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.clip img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: #000; }
.clip .meta { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; }
.clip .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clip .dur { color: var(--muted); flex: none; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }

#v { position: fixed; left: 0; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; }

@media (max-width: 760px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
  .topbar h1 { margin: 0; width: 100%; }
  .brand-sub { display: none; }
  main { padding: 16px 16px 40px; }
  .panes { grid-template-columns: minmax(0, 1fr); max-width: none; gap: 20px; }
  .pane.phone { width: min(52%, 240px); margin: 0 auto; }
  .busy { bottom: auto; height: 56vw; }
  .transport { gap: 6px; padding: 8px 10px; flex-wrap: wrap; }
  .time { min-width: 0; }
  .time.dim { margin-right: auto; }
  .scrub { order: 10; flex-basis: 100%; }
  .keys { display: none; }
}
