:root {
  --ink: #14120f;
  --ink-3: #2a2722;
  --graphite: #4a463f;
  --fog-dark: #6e685d;
  --fog: #bdb6a6;
  --vellum: #e3decd;
  --ember: #f58a5a;
  --tangerine: #ffc94f;
  --signal: #58acef;
  --rhubarb: #ff7bb1;
  --violet: #b38ef1;
  --accent: var(--rhubarb);   /* updated live from JS as the colours cycle */
  --screen: #0d0c0b;
  --screen-edge: #25231f;
  --gutter: 16px;
  --font: 'Outfit', 'Helvetica Neue', Arial, sans-serif;
  --glow: 1; --fringe: 1; --grain: 1;   /* deck look, set live from the tweak panel */
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ink);
  color: var(--vellum);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#scene {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
body.grabbing #scene { cursor: grabbing; }

/* ─── Logo ─────────────────────────────────────────────────────────── */
.brand {
  position: fixed; top: max(18px, env(safe-area-inset-top)); left: max(var(--gutter), env(safe-area-inset-left));
  pointer-events: none;
}
.logo {
  margin: 0;
  font-family: 'Monoton', 'Arial Black', sans-serif;
  font-weight: 400;
  font-size: clamp(26px, 4.4vw, 46px);
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
  color: #fff6ef;
  text-shadow: 0 0 6px var(--accent), 0 0 18px var(--accent), 0 0 42px var(--accent);
  transition: text-shadow 1.2s;
}
.logo span { color: var(--accent); text-shadow: 0 0 8px var(--accent), 0 0 26px var(--accent); transition: color 1.2s, text-shadow 1.2s; }

/* ─── Hint + toast ─────────────────────────────────────────────────── */
.hint {
  position: fixed; left: 50%; bottom: 168px; transform: translateX(-50%);
  margin: 0; padding: 6px 14px;
  font: 300 13px/1.2 var(--font); letter-spacing: 0.04em; color: var(--fog);
  background: rgba(13,12,11,.6); border: 1px solid var(--screen-edge); border-radius: 999px;
  white-space: nowrap; pointer-events: none;
  transition: opacity .8s;
}
.hint.gone { opacity: 0; }
@media (pointer: coarse) { .hint-keys { display: none; } }

.toast {
  position: fixed; left: 50%; top: max(80px, calc(env(safe-area-inset-top) + 70px));
  transform: translate(-50%, -12px);
  width: max-content; max-width: calc(100% - 2 * var(--gutter));
  padding: 11px 18px;
  font: 300 15px/1.3 var(--font); color: var(--vellum); text-align: center;
  background: var(--screen); border: 1px solid var(--screen-edge); border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.6);
  opacity: 0; pointer-events: none;
  transition: opacity .3s, transform .3s;
}
.toast::before { content: ''; display: inline-block; width: 7px; height: 7px; margin-right: 9px; border-radius: 50%; background: var(--signal); vertical-align: 1px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ─── The deck: four little screens ────────────────────────────────── */
.deck {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(1060px, calc(100% - 2 * var(--gutter)));
  display: grid;
  grid-template-columns: 1.3fr 0.85fr 1.3fr 1.15fr;
  grid-template-areas: "tape tempo scope keys";
  gap: 10px;
}
.screen {
  position: relative;
  height: 132px;
  background: var(--screen);
  border: 1px solid var(--screen-edge);
  border-radius: 16px;
  box-shadow: 0 12px 34px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.035);
  overflow: hidden;
}
.screen canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* phosphor-screen texture: faint scanlines, grain and a vignette over each screen */
.screen::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  opacity: calc(0.9 * var(--grain));
  background:
    radial-gradient(120% 140% at 50% 45%, transparent 55%, rgba(0,0,0,.55) 100%),
    repeating-linear-gradient(0deg, rgba(0,0,0,.28) 0 1px, transparent 1px 3px),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .09 0'/></filter><rect width='120' height='120' filter='url(%23n)'/></svg>");
  animation: grain 0.5s steps(4) infinite;
}
@keyframes grain { 25% { background-position: 0 0, 0 1px, 30px 10px; } 50% { background-position: 0 0, 0 0, -20px 40px; } 75% { background-position: 0 0, 0 1px, 50px -30px; } }
/* glow + colour fringe on the HTML parts of the deck */
.scope-head, .keys-head, .key-label {
  text-shadow: 0 0 calc(7px * var(--glow)) currentColor,
    calc(-0.8px * var(--fringe)) 0 rgba(255, 47, 79, calc(0.55 * var(--fringe))),
    calc(0.8px * var(--fringe)) 0 rgba(47, 140, 255, calc(0.55 * var(--fringe)));
}
.ring { box-shadow: 0 0 calc(10px * var(--glow)) -3px currentColor, inset 0 0 calc(8px * var(--glow)) -4px currentColor; }
.ring svg { filter: drop-shadow(0 0 calc(3px * var(--glow)) currentColor)
  drop-shadow(calc(-0.8px * var(--fringe)) 0 rgba(255, 47, 79, calc(0.6 * var(--fringe))))
  drop-shadow(calc(0.8px * var(--fringe)) 0 rgba(47, 140, 255, calc(0.6 * var(--fringe)))); }
.scr-tape { grid-area: tape; }
.scr-tempo { grid-area: tempo; }
.scr-scope { grid-area: scope; }
.scr-keys { grid-area: keys; }

/* scope screen: title row on top, graph below */
.scr-scope canvas { top: 36px; height: calc(100% - 36px); }
.scope-head {
  position: absolute; left: 12px; right: 12px; top: 10px;
  display: flex; align-items: center; gap: 10px;
  font: 300 17px/1 var(--font);
}
.tag { flex: none; font: 600 10px/1 var(--font); letter-spacing: .12em; color: var(--accent); transition: color 1.2s; }
.marquee { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; color: var(--vellum); }
#title { display: inline-block; }
#title.scroll { animation: marquee var(--dur, 8s) ease-in-out infinite alternate; }
@keyframes marquee { 0%, 15% { transform: translateX(0); } 85%, 100% { transform: translateX(var(--shift)); } }
.arrow { flex: none; font: 300 15px/1 var(--font); color: var(--rhubarb); letter-spacing: -.05em; }

/* keys screen */
.keys-head {
  position: absolute; left: 12px; right: 12px; top: 10px;
  display: flex; justify-content: space-between; align-items: center;
}
.dot-toggle, .dot-label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0; background: none; border: 0;
  font: 600 10px/1 var(--font); letter-spacing: .12em; color: var(--fog-dark);
}
.dot-toggle { cursor: pointer; }
.dot { width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid currentColor; }
.dot-toggle:hover { color: var(--vellum); }
.dot-toggle[aria-pressed="true"] { color: var(--signal); }
.dot-toggle[aria-pressed="true"] .dot { background: var(--signal); }
.dot-label.on { color: var(--rhubarb); }
.dot-label.on .dot { background: var(--rhubarb); box-shadow: 0 0 8px var(--rhubarb); }

.keys {
  position: absolute; left: 8px; right: 8px; bottom: 10px; top: 30px;
  display: flex; justify-content: space-around; align-items: center;
}
.key {
  display: grid; justify-items: center; gap: 7px;
  padding: 0; background: none; border: 0; cursor: pointer;
  color: var(--vellum);
  -webkit-tap-highlight-color: transparent;
}
.ring {
  position: relative;
  display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1.5px solid var(--vellum);
  transition: transform .08s, border-color .2s, box-shadow .2s;
}
.ring svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.key-label { font: 600 9.5px/1 var(--font); letter-spacing: .14em; white-space: nowrap; }
.key:hover .ring { border-color: #fff; }
.key:active .ring { transform: scale(.93); }
.key:focus-visible { outline: none; }
.key:focus-visible .ring, .dot-toggle:focus-visible { outline: 2px solid var(--signal); outline-offset: 3px; }

.k-prev .key-label, .k-next .key-label { color: var(--signal); }
.k-prev .ring, .k-next .ring { color: var(--vellum); }
.k-play .key-label { color: var(--rhubarb); }
.k-byov .key-label { color: var(--violet); }

.k-play { gap: 13px; }
.k-play .ring { width: 54px; height: 54px; border-color: var(--rhubarb); }
.k-play .ring svg { width: 24px; height: 24px; stroke: var(--rhubarb); }
.k-play .ring::after { /* tick ring that spins while playing, like a dial */
  content: ''; position: absolute; inset: -7px; border-radius: 50%;
  border: 1.5px dashed var(--rhubarb); opacity: .25;
}
.k-play.is-playing .ring::after { opacity: .9; animation: spin 7s linear infinite; }
.k-play .i-pause { display: none; }
.k-play.is-playing .i-play { display: none; }
.k-play.is-playing .i-pause { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.k-byov .ring { border-color: var(--violet); color: var(--violet); }
.k-byov.is-live .ring { background: var(--violet); color: var(--screen); box-shadow: 0 0 18px rgba(179,142,241,.6); animation: live 1.4s ease-in-out infinite; }
@keyframes live { 50% { box-shadow: 0 0 30px rgba(179,142,241,.95); } }

/* ─── No WebGL fallback ────────────────────────────────────────────── */
.no-webgl-msg { display: none; }
body.no-webgl .no-webgl-msg {
  display: block; position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 2 * var(--gutter)));
  text-align: center; color: var(--fog); font-size: 15px; font-weight: 300;
}
body.no-webgl .hint { display: none; }

/* ─── Medium screens: drop the tempo screen into a 3-up row ────────── */
@media (max-width: 980px) {
  .deck { grid-template-columns: 1.2fr 1.2fr 1fr; grid-template-areas: "tape scope keys"; }
  .scr-tempo { display: none; }
}

/* ─── Phones: title strip, tape + tempo, then the keys ─────────────── */
@media (max-width: 700px) {
  .deck {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "scope scope" "tape tempo" "keys keys";
    gap: 8px;
    bottom: max(12px, env(safe-area-inset-bottom));
  }
  .scr-tempo { display: block; }
  .screen { height: 104px; }
  .scr-scope { height: 40px; }
  .scr-scope canvas { display: none; }
  .scope-head { top: 11px; font-size: 16px; }
  .scr-keys { height: 92px; }
  .keys { top: 26px; bottom: 6px; }
  .ring { width: 40px; height: 40px; }
  .k-play .ring { width: 46px; height: 46px; }
  .key { gap: 5px; }
  .k-play { gap: 11px; }
  .hint { bottom: 270px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .screen::after { animation: none; }
  #title.scroll, .k-byov.is-live .ring, .k-play.is-playing .ring::after { animation: none; }
}
