/* All colours and sizes come from the design tokens (src/tokens.js) as CSS variables.
   The values here are only the fallback before the script runs.
   Look: screen "Fragments" (Joel, 29.11.2026). */
:root {
  --bg: #000; --ink: #fff; --line: #fff; --dim: #8a8984; --rec: #ff0000; --control: #d9d9d9; --surface: #1f1f1f; --accent: #fff;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --titleSize: 38px; --tabSize: 24px; --textSize: 16px; --smallSize: 11px;
  --pad: 12px; --ruleWidth: 8px; --lineWidth: 1px; --sessionHeight: 50px; --cellAspect: 1.08; --radius: 14px;
  --dockMid: 135px; --dockRec: 100px; --dockSide: 110px; --dockSpread: 86px; --dockBottom: 28px;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --dockSpace: calc(var(--dockMid) + var(--dockBottom) + env(safe-area-inset-bottom));
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: var(--textSize)/1.25 var(--font); -webkit-font-smoothing: antialiased; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid color-mix(in srgb, var(--ink) 14%, transparent); border-radius: calc(var(--radius) * .6); padding: 7px 12px; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
button.txt { background: none; border: 0; border-radius: 0; padding: 4px 0; color: var(--ink); }
button.txt.dim { color: var(--dim); }
button.txt.danger, button.txt.arm { color: var(--rec); }
.grow { flex: 1; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 6; background: var(--bg); padding-top: env(safe-area-inset-top); }
.tabs { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 22px var(--pad) 0; }
.tab { margin: 0; font-weight: 500; letter-spacing: -.01em; white-space: nowrap; }
.tab.on { font-size: var(--titleSize); text-decoration: underline; text-decoration-thickness: max(2px, calc(var(--titleSize) * .05)); text-underline-offset: calc(var(--titleSize) * .14); }
.tab.later { font-size: var(--tabSize); cursor: default; }
.subbar { display: flex; align-items: center; gap: 16px; padding: 18px var(--pad) 12px; font-weight: 500; }
.subbar button.txt { font-weight: 500; }
.rule { height: var(--ruleWidth); background: var(--line); margin-top: 6px; }

/* ---------- grid ---------- */
main { padding-bottom: calc(var(--dockSpace) + 24px); }
.session-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; height: var(--sessionHeight); padding: 0 var(--pad);
  border: 0; border-bottom: var(--lineWidth) solid var(--line); border-radius: 0; background: var(--bg); color: var(--ink); font: 500 var(--textSize) var(--font); text-align: left; }
.session + .session .session-head, #binLink { border-top: var(--lineWidth) solid var(--line); }
.cells { display: grid; grid-template-columns: repeat(var(--cols, 2), 1fr); gap: var(--lineWidth); background: var(--line); }
.cell { position: relative; aspect-ratio: 1 / var(--cellAspect); background: var(--bg); cursor: pointer; overflow: hidden; }
.cell.blank { cursor: default; }
.cell canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.cell-name { position: absolute; left: var(--pad); right: 56px; bottom: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-time { position: absolute; right: var(--pad); bottom: 16px; font-size: var(--smallSize); font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 5px; }
.sync-dot { display: none; width: 5px; height: 5px; border-radius: 50%; background: var(--dim); }
.cell.pending .sync-dot { display: inline-block; }
.pick { display: none; position: absolute; top: 12px; right: 12px; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--ink); }
.selecting .cell:not(.blank) .pick { display: block; }
.cell.picked .pick { background: var(--ink); box-shadow: inset 0 0 0 4px var(--bg); }
.grid-empty { color: var(--dim); text-align: center; padding: 80px 24px; margin: 0; }
.bin-link { color: var(--dim); cursor: pointer; }

/* ---------- record control ---------- */
.dock { position: fixed; z-index: 8; left: 50%; bottom: calc(var(--dockBottom) + env(safe-area-inset-bottom)); width: 0; height: var(--dockMid); pointer-events: none; }
.dock-side, .dock-mid { position: absolute; border-radius: 50%; background: var(--control); }
.dock-side { width: var(--dockSide); height: var(--dockSide); top: calc((var(--dockMid) - var(--dockSide)) / 2); }
.dock-left { left: calc(-1 * var(--dockSpread) - var(--dockSide) / 2); }
.dock-right { left: calc(var(--dockSpread) - var(--dockSide) / 2); }
.dock-mid { width: var(--dockMid); height: var(--dockMid); left: calc(var(--dockMid) / -2); top: 0; display: grid; place-items: center; }
.rec { pointer-events: auto; width: var(--dockRec); height: var(--dockRec); padding: 0; border: 0; border-radius: 50%; background: var(--rec); transition: border-radius .18s, transform .18s; }
.rec.on { border-radius: 18%; transform: scale(.6); }
.selecting .dock { display: none; }

/* ---------- select bar ---------- */
.selbar { position: fixed; z-index: 8; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 24px; padding: 18px calc(var(--pad) * 2) calc(18px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: var(--lineWidth) solid var(--line); font-weight: 500; }

/* ---------- live recording ---------- */
.rec-layer { position: fixed; z-index: 7; inset: 0; background: var(--bg); }
#stage { position: absolute; left: 0; right: 0; top: 0; bottom: var(--dockSpace); width: 100%; height: calc(100% - var(--dockSpace)); display: block; }
.rec-meta { position: absolute; left: 0; right: 0; bottom: calc(var(--dockSpace) + 8px); text-align: center; font-variant-numeric: tabular-nums; font-weight: 500; }
#recCancel { position: absolute; top: calc(18px + env(safe-area-inset-top)); left: calc(var(--pad) * 2); font-weight: 500; }

/* ---------- map ---------- */
.map-view { position: fixed; left: 0; right: 0; bottom: 0; top: var(--headH, 160px); z-index: 1; background: var(--bg); }
#map { width: 100%; height: 100%; display: block; touch-action: none; }
#map.dragging { cursor: grabbing; }
.map-tools { position: absolute; top: 10px; right: var(--pad); display: flex; gap: 4px; }
.map-tools button { padding: 4px 10px; font-size: 13px; }
.map-tip { position: absolute; transform: translate(-50%, -100%); pointer-events: none; background: var(--surface); color: var(--ink); padding: 4px 8px; border-radius: 6px; font-size: 13px; white-space: nowrap; }
.map-tip small { display: block; color: var(--dim); font-size: var(--smallSize); }
.tray { position: absolute; left: var(--pad); right: var(--pad); bottom: calc(var(--dockSpace) + 14px); max-width: 520px; margin: 0 auto;
  background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid color-mix(in srgb, var(--ink) 16%, transparent); border-radius: var(--radius); padding: 8px 10px 10px; backdrop-filter: blur(8px); font-size: 13px; }
.tray.over { border-color: var(--ink); }
.tray-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.tray-head button.txt { font-size: 13px; padding: 2px 0; }
#trayCount { color: var(--dim); font-size: var(--smallSize); }
.tray-items { display: flex; gap: 6px; overflow-x: auto; min-height: 0; }
.titem { position: relative; flex: 0 0 64px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 2px; border-radius: 8px; cursor: grab; touch-action: none; user-select: none; }
.titem canvas { width: 56px; height: 56px; }
.titem span { font-size: 10px; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.titem.playing { background: color-mix(in srgb, var(--ink) 12%, transparent); }
.titem.ghosted { opacity: .25; }
.titem .tx { position: absolute; top: 0; right: 0; padding: 0 5px; font-size: 11px; border-radius: 99px; line-height: 16px; }
.tslot { flex: 0 0 3px; align-self: stretch; background: var(--ink); border-radius: 2px; }
.tray-empty { color: var(--dim); font-size: 12px; padding: 12px 4px; text-align: center; border: 1px dashed color-mix(in srgb, var(--ink) 25%, transparent); border-radius: 8px; }
#dragGhost { position: fixed; z-index: 30; width: 64px; height: 64px; transform: translate(-50%, -50%); pointer-events: none; }
#dragGhost.out { opacity: .4; }
.mapping main { display: none; }
/* Map View: no record control, the box sits at the bottom */
.mapping .dock { display: none; }
.mapping .tray { bottom: calc(var(--pad) + env(safe-area-inset-bottom)); }

/* ---------- tweak panel ----------
   Own fixed colours, so the panel stays readable whatever you do to the tokens. */
.tweak { --ink: #f3f2ee; --dim: #9a9993; --bg: #101010; --surface: #232323; --accent: #f3f2ee; color: var(--ink); position: fixed; z-index: 20; top: 0; right: 0; bottom: 0; width: min(340px, 92vw); overflow-y: auto; background: rgba(28,28,28,.97);
  border-left: 1px solid color-mix(in srgb, var(--ink) 14%, transparent); padding: calc(10px + env(safe-area-inset-top)) 14px 40px; backdrop-filter: blur(14px); font-size: 12.5px; }
/* peek: holding a slider hides the panel (still there, so the finger keeps moving the slider) */
.tweak { transition: opacity .12s; }
.tweak.peek { opacity: 0; }
.tw-head { display: flex; align-items: center; gap: 6px; position: sticky; top: -10px; padding: 6px 0 10px; background: inherit; }
.tw-head b { flex: 1; font-size: 14px; }
.tw-head { flex-wrap: wrap; }
.tw-head button { padding: 4px 8px; font-size: 12px; white-space: nowrap; }
#twNames[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.tweak details { border-top: 1px solid color-mix(in srgb, var(--ink) 10%, transparent); padding: 4px 0; }
.tweak summary { cursor: pointer; padding: 8px 0; font-weight: 600; color: var(--dim); text-transform: uppercase; letter-spacing: .07em; font-size: 11px; }
.tw-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; padding: 5px 0; }
.tw-row output, .tw-row code { font: 11px var(--mono); color: var(--dim); }
.tw-range input { grid-column: 1 / -1; width: 100%; }
.tw-color { grid-template-columns: 1fr auto auto; }
.tw-color input { width: 34px; height: 24px; padding: 0; border: 0; background: none; }
.tw-select select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid color-mix(in srgb, var(--ink) 16%, transparent); border-radius: 6px; padding: 3px 6px; }

/* names / inspect */
.inspect [data-ref] { outline: 1px dashed color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; }
.inspect #tweak, .inspect #tweak [data-ref] { outline: none; }
.ref-tip { position: fixed; z-index: 30; pointer-events: none; background: var(--accent); color: var(--bg); font: 11px var(--mono); padding: 2px 6px; border-radius: 4px; }

.toast { position: fixed; z-index: 40; left: 50%; bottom: calc(var(--dockSpace) + 16px); transform: translateX(-50%); max-width: 90vw;
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 99px; font-size: 13px; }

