/* ==========================================================================
   Signal Lab — design tokens and control chrome.
   ========================================================================== */

:root {
  /* Panel */
  --void:      #07060d;
  --panel:     #0d0b18;
  --panel-lit: #14112a;
  --wire:      #272144;
  --wire-lit:  #3b3266;

  /* Ink */
  --ink:       #eae7fa;
  --ink-dim:   #948eb8;
  --ink-faint: #5d5680;

  /* Channel hues — one per style, never a single house accent */
  --ch1: #00f0d0;
  --ch2: #ff2e88;
  --ch3: #ffc23d;

  /* Set by the shell to the active style's hue */
  --hue: var(--ch1);

  /* DIN-family faces ship with Windows (Bahnschrift) and macOS (DIN Alternate),
     so the panel look survives with no web font and no network. */
  --font-display: "Bahnschrift", "DIN Alternate", "DIN Condensed", "Oswald",
                  "Arial Narrow", "Helvetica Neue", system-ui, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", "JetBrains Mono",
               "Roboto Mono", Consolas, "Liberation Mono", monospace;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --rail-h: 40px;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--void);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

:where(button, input, select, a):focus-visible {
  outline: 2px solid var(--hue);
  outline-offset: 2px;
}

canvas.stage {
  position: fixed;
  inset: 0;
  display: block;
}

/* The loaded video sits centred and crisp, like the screen on the wall, and
   the visualisation behind it is the light spilling out around the edges.
   `--bleed` is set from the sampled average colour, so the glow leaving the
   panel is the colour of the picture. */
.scope-video {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(.96);

  /* Fit the picture's own shape into whichever dimension runs out first, at
     `--screen` per cent of it. `--aspect` is the real ratio read off the file,
     so 4:3, 16:9 and 2.39:1 each end up as large as they can be without ever
     being letterboxed inside their own frame — the border and the glow sit on
     the picture, not on black bars beside it. */
  aspect-ratio: var(--aspect, 1.7778);
  width: min(
    calc(100vw * var(--screen, 34) / 100),
    calc(100vh * var(--screen, 34) / 100 * var(--aspect, 1.7778))
  );
  height: auto;
  object-fit: contain;
  z-index: 3;
  opacity: 0;
  background: #000;
  border: 1px solid var(--wire);
  box-shadow:
    0 0 60px 6px var(--bleed, transparent),
    0 0 160px 30px var(--bleed, transparent);
  transition: opacity .6s var(--ease), transform .6s var(--ease);
  pointer-events: none;
}

body.has-video .scope-video {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Rows that only mean something once a video is loaded, and the cut-detection
   rows which additionally need it switched on. Every rule carries a body
   prefix so it outranks the .strip__row display further down. */
body .strip__row--video,
body .strip__row--cut { display: none; }
body.has-video .strip__row--video { display: flex; }
body.has-video.cuts-on .strip__row--cut { display: flex; }

/* How much the picture just changed, against the level it has to beat. */
.cutmeter {
  position: relative;
  flex: 1 1 70px;
  height: 4px;
  background: var(--wire);
  overflow: hidden;
}
.cutmeter i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--ink-faint);
  transition: width .1s linear, background-color .15s;
}
.cutmeter i.is-hit {
  background: var(--hue);
  box-shadow: 0 0 8px var(--hue);
  transition: none;
}
.cutmeter s {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 2px;
  background: var(--ch2);
}

/* ------------------------------------------------------------------- rail */

.rail {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--rail-h);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  background: linear-gradient(180deg, rgba(7, 6, 13, .92), rgba(7, 6, 13, 0));
  transition: opacity .45s var(--ease);
}

.rail__mark { color: var(--ink); }
.rail__mark::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  margin-right: 8px;
  background: var(--hue);
  box-shadow: 0 0 8px var(--hue);
  vertical-align: middle;
  transition: background-color .3s, box-shadow .3s;
}

.rail__ch { color: var(--ink-dim); }
.rail__ch b { color: var(--hue); font-weight: 400; }

.rail__spec { margin-left: auto; }
.rail__spec b { color: var(--ink-dim); font-weight: 400; }

/* ------------------------------------------------------------------- tabs */

.tabs { display: flex; gap: 4px; }

.tab {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  font: inherit;
  letter-spacing: .1em;
  color: var(--ink-faint);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: color .18s, border-color .18s, background-color .18s;
}
.tab i {
  font-style: normal;
  color: var(--tab);
  opacity: .5;
  transition: opacity .18s;
}
.tab:hover { color: var(--ink); border-color: var(--wire); }
.tab:hover i { opacity: 1; }
.tab.is-on {
  color: var(--tab);
  border-color: color-mix(in srgb, var(--tab) 50%, transparent);
  background: color-mix(in srgb, var(--tab) 12%, transparent);
}
.tab.is-on i { opacity: 1; }

/* --------------------------------------------------------- source strip */

.strip {
  position: fixed;
  left: 14px;
  top: calc(var(--rail-h) + 8px);
  z-index: 10;
  width: min(420px, calc(100vw - 28px));
  max-height: calc(100vh - var(--rail-h) - 24px);
  overflow-y: auto;
  padding: 13px 15px 11px;
  background: rgba(13, 11, 24, .82);
  backdrop-filter: blur(14px);
  border: 1px solid var(--wire);
  border-left: 2px solid var(--hue);
  transition: opacity .45s var(--ease);
}

.strip__row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.strip__row + .strip__row { margin-top: 9px; }

.lbl {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  width: 42px;
  flex: none;
}

.btn {
  appearance: none;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: transparent;
  border: 1px solid var(--wire);
  padding: 6px 10px;
  cursor: pointer;
  transition: color .18s, border-color .18s, background-color .18s;
}
.btn:hover { color: var(--ink); border-color: var(--wire-lit); }
.btn.is-on {
  color: var(--hue);
  border-color: color-mix(in srgb, var(--hue) 55%, transparent);
  background: color-mix(in srgb, var(--hue) 11%, transparent);
}
.btn--mini { padding: 4px 8px; font-size: 9.5px; }

input[type="range"] {
  appearance: none;
  height: 2px;
  background: var(--wire);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--hue);
}
input[type="range"]::-moz-range-thumb {
  width: 11px; height: 11px;
  border: 0;
  border-radius: 50%;
  background: var(--hue);
}

.strip input[type="range"] { flex: 1 1 90px; }

.val {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-dim);
  width: 44px;
  text-align: right;
  flex: none;
  font-variant-numeric: tabular-nums;
}

.meter {
  height: 2px;
  margin-top: 11px;
  background: var(--wire);
  overflow: hidden;
}
.meter i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--hue);
  box-shadow: 0 0 10px var(--hue);
}

/* ---------------------------------------------------------------- transport

   Bottom centre, between the source strip and the style panel. Only present
   once there is something to play. */

.transport {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 6;
  width: min(440px, calc(100vw - 32px));
  padding: 10px 12px;
  display: none;
  flex-direction: column;
  gap: 8px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--wire);
  border-radius: 6px;
  backdrop-filter: blur(12px);
}
body.has-track .transport { display: flex; }

.transport__head,
.transport__foot {
  display: flex;
  align-items: center;
  gap: 8px;
}

.transport__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: .04em;
  color: var(--ink);
}

.transport__time {
  flex: none;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

.tbtn {
  flex: none;
  width: 30px; height: 26px;
  display: grid;
  place-items: center;
  font-size: 10px;
  color: var(--ink);
  background: var(--panel-lit);
  border: 1px solid var(--wire);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.tbtn:hover:not(:disabled) { border-color: var(--hue); color: var(--hue); }
.tbtn:disabled { opacity: .3; cursor: default; }

.tbtn--play {
  width: 38px;
  color: var(--hue);
  border-color: color-mix(in srgb, var(--hue) 45%, var(--wire));
}

.tlbl {
  flex: none;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.transport .scrub { flex: 1 1 auto; min-width: 0; }
.transport .vol { flex: 0 0 70px; }

/* Tempo readout — deliberately quiet. It is a reading, not a control, and it
   is wrong often enough on anything that is not four-to-the-floor that it
   should not be the loudest thing in the strip. */
.tempo {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .08em;
  color: var(--ink-faint);
}

.tempo b {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  transition: color .4s var(--ease);
}

.tempo__unit { font-size: 9px; opacity: .7; }

/* The dot flashes on each detected beat. No transition on the way in — a beat
   marker that eases up reads as late even when it is not. */
.tempo__pulse {
  width: 6px; height: 6px;
  flex: none;
  border-radius: 50%;
  background: var(--wire-lit);
  transition: background .18s linear, box-shadow .18s linear;
}
.tempo__pulse.is-hit {
  background: var(--hue);
  box-shadow: 0 0 7px var(--hue);
  transition: none;
}

/* How much the measured gaps agree with each other. */
.tempo__lock {
  width: 38px; height: 2px;
  margin-left: auto;
  background: var(--wire);
  overflow: hidden;
}
.tempo__lock i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--hue);
  transition: width .35s var(--ease);
}

.tempo.is-searching b { color: var(--ink-faint); }
/* Locked means beats are coming from the grid, not from raw onsets. */
.tempo.is-locked b { color: var(--ink); }

/* The library row only means anything once tracks.json lists playable paths. */
body .strip__row--library { display: none; }
body.has-library .strip__row--library { display: flex; }

.tracks {
  flex: 1 1 180px;
  min-width: 0;
  padding: 4px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
  background: var(--panel-lit);
  border: 1px solid var(--wire);
  border-radius: 3px;
}
.tracks:focus { border-color: var(--hue); outline: none; }

.hintbox {
  width: 62px;
  flex: none;
  padding: 4px 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
  background: var(--panel-lit);
  border: 1px solid var(--wire);
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
}
.hintbox::placeholder { color: var(--ink-faint); }
.hintbox:focus { border-color: var(--hue); outline: none; }

.hint {
  margin: 8px 0 0;
  font-family: var(--font-mono);
  font-size: 9.5px;
  line-height: 1.6;
  letter-spacing: .04em;
  color: var(--ink-faint);
  min-height: 1.6em;
}
.hint.is-alert { color: var(--ch2); }

/* ----------------------------------------------------- parameter panel */

.panel {
  position: fixed;
  right: 14px;
  top: calc(var(--rail-h) + 8px);
  z-index: 10;
  width: 274px;
  max-height: calc(100vh - var(--rail-h) - 24px);
  display: flex;
  flex-direction: column;
  background: rgba(13, 11, 24, .84);
  backdrop-filter: blur(14px);
  border: 1px solid var(--wire);
  border-right: 2px solid var(--hue);
  transition: opacity .45s var(--ease);
}

.panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--wire);
}

.panel__title {
  margin: 0;
  flex: 1;
  font-family: var(--font-display);
  font-variation-settings: "wght" 600, "wdth" 87.5;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--ink);
}

.panel__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 12px 10px;
}

.panel__foot {
  display: flex;
  gap: 6px;
  padding: 9px 12px;
  border-top: 1px solid var(--wire);
}

body:not(.panel-open) .panel__body,
body:not(.panel-open) .panel__foot { display: none; }

.pgroup { padding-top: 10px; }

.pgroup__name {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 400;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--wire);
  padding-bottom: 5px;
}

.prow {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 26px;
}

.prow__label {
  flex: 0 0 78px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-dim);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prow__range { flex: 1 1 auto; min-width: 0; }

.prow__value {
  flex: 0 0 52px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.prow__select {
  flex: 1 1 auto;
  min-width: 0;
  appearance: none;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--hue);
  background: transparent;
  border: 1px solid var(--wire);
  padding: 4px 6px;
  cursor: pointer;
}
.prow__select option { background: var(--panel); color: var(--ink); }

.prow__toggle {
  flex: 1 1 auto;
  appearance: none;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  background: transparent;
  border: 1px solid var(--wire);
  padding: 4px 6px;
  cursor: pointer;
  transition: color .18s, border-color .18s, background-color .18s;
}
.prow__toggle.is-on {
  color: var(--hue);
  border-color: color-mix(in srgb, var(--hue) 50%, transparent);
  background: color-mix(in srgb, var(--hue) 11%, transparent);
}

/* Get out of the way once the user stops touching anything. */
body.idle .strip,
body.idle .rail,
body.idle .transport,
body.idle .panel { opacity: 0; pointer-events: none; }
body.idle { cursor: none; }

body.chrome-off .strip,
body.chrome-off .rail,
body.chrome-off .transport,
body.chrome-off .panel { opacity: 0; pointer-events: none; }

body.dropping::after {
  content: "";
  position: fixed;
  inset: 10px;
  z-index: 20;
  border: 1px dashed var(--hue);
  pointer-events: none;
}

@media (max-width: 940px) {
  .tab span, .rail__ch { display: none; }
  .tab { font-size: 0; padding: 5px 8px; }
  .tab i { font-size: 10.5px; opacity: 1; }
  .panel { width: 232px; }
  .prow__label { flex-basis: 62px; }
}

@media (max-width: 620px) {
  .strip { left: 10px; right: 10px; bottom: 10px; width: auto; }
  .lbl { width: 100%; }
  .panel { right: 10px; left: 10px; width: auto; max-height: 46vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}
