/* GRʷAVE Player: the stage shell, "Hard Telemetry".
   The page is the stage: one canvas fills the area above a slim control rail; the core draws
   the whole show on it and the painter letterboxes the 960x540 stage. The rail fades when idle
   (src/ui/rail.js sets data-idle). The playlist drawer is the only DOM over the stage.
   Flat: 1px hairlines, right angles, no shadows, no gradients except hard-stop slider fills.
   Palette comes from CSS variables published by src/render/palettes.js (defaults match LAB);
   --accent* follow the CURRENT archetype. Text colours keep >= 4.5:1 on --bg. */

:root {
  --bg: #050608;
  --panel: #0b0e13;
  --bezel: #1a212b;
  --ink: #dbe4ee;
  --ink-dim: #5b6675;
  --primary: #8fe8ff;
  --warn: #ff3b4a;
  --glow: #bff3ff;
  --grid: #141a22;
  --screen: #020304;
  --hud: #c8d4e0;
  --hud-dim: #8d99a8;
  --accent: #ff7a1a;
  --accent-rgb: 255 122 26;
  --line: #2a3441;
  --key: 34px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, Menlo, "DejaVu Sans Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
}

body {
  color: var(--hud);
  font: 12px/1.25 var(--mono);
  letter-spacing: 0.06em;
  -webkit-text-size-adjust: 100%;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

::selection { background: var(--primary); color: var(--bg); }

:focus-visible {
  outline: 2px solid var(--glow);
  outline-offset: 1px;
}

.noscript { color: var(--warn); text-align: center; }

/* ------------------------------------------------------------------- layout */

.chassis {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.stage {
  grid-row: 1;
  grid-column: 1;
  position: relative;
  min-height: 0;
  background: var(--bg);
}
.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.stage canvas[data-hit="true"] { cursor: pointer; }
.stage canvas:focus-visible { outline: 1px solid var(--accent); outline-offset: -3px; }
.chassis[data-idle="true"] .stage,
.chassis[data-idle="true"] .stage canvas[data-hit="true"] { cursor: none; }

/* --------------------------------------------------------------------- rail */

.rail {
  grid-row: 2;
  grid-column: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 6px max(10px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: var(--bg);
  text-transform: uppercase;
  transition: opacity 0.35s linear;
}
.rail-row { display: contents; }
.chassis[data-idle="true"] .rail { opacity: 0; }

.grp { display: flex; align-items: center; gap: 4px; }
.grp-tape { flex: 1 1 140px; min-width: 140px; gap: 10px; }
.tape-row { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.grp-modes { gap: 4px; }

.readout, .tag {
  color: var(--hud-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tag { padding-right: 2px; }
.readout#vol-readout { min-width: 3ch; }

/* keys: flat, square, 1px hairline */
.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: var(--key);
  height: var(--key);
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--hud);
  font: inherit;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}
.key.icon { padding: 0; width: var(--key); }
.key .ico { width: 16px; height: 16px; fill: currentColor; }
.key:hover { border-color: var(--hud-dim); }
.key:active { background: var(--panel); }
.key:disabled { color: var(--hud-dim); border-color: var(--bezel); cursor: default; }
.key[aria-pressed="true"], .key[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.key.quiet { color: var(--hud-dim); }
.chassis[data-play="playing"] .key-play,
.chassis[data-play="paused"] .key-pause { color: var(--accent); border-color: var(--accent); }
.chassis[data-play="loading"] .key-play { color: var(--primary); border-color: var(--primary); }
.count { color: var(--hud-dim); }

/* archetype segment */
.seg { display: flex; }
.opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--key);
  padding: 0 8px;
  border: 1px solid var(--line);
  margin-left: -1px;
  border-radius: 0;
  background: transparent;
  color: var(--hud-dim);
  font: inherit;
  letter-spacing: 0.1em;
  cursor: pointer;
}
.opt:first-child { margin-left: 0; }
.opt .nm { display: none; }
.opt:hover { color: var(--hud); }
.opt[aria-pressed="true"] {
  position: relative;
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.opt:focus-visible { position: relative; z-index: 1; }

/* scene select */
.select {
  height: var(--key);
  max-width: 16rem;
  padding: 0 24px 0 8px;
  border: 1px solid var(--line);
  border-radius: 0;
  background:
    linear-gradient(45deg, transparent 50%, var(--hud) 50%) right 12px center / 5px 5px no-repeat,
    linear-gradient(-45deg, transparent 50%, var(--hud) 50%) right 7px center / 5px 5px no-repeat,
    var(--bg);
  color: var(--hud);
  font: inherit;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  appearance: none;
  cursor: pointer;
}
.select option { background: var(--bg); color: var(--hud); }

/* sliders: 2px track, square thumb, hard-stop fill to --p */
.slider {
  --p: 0%;
  appearance: none;
  -webkit-appearance: none;
  height: var(--key);
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.slider.seek { flex: 1; min-width: 80px; }
.slider.fader { width: 72px; }
.slider::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(90deg, var(--accent) var(--p), var(--line) var(--p));
}
.slider::-moz-range-track { height: 2px; background: var(--line); }
.slider::-moz-range-progress { height: 2px; background: var(--accent); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 8px; height: 16px;
  margin-top: -7px;
  border: 0; border-radius: 0;
  background: var(--hud);
}
.slider::-moz-range-thumb { width: 8px; height: 16px; border: 0; border-radius: 0; background: var(--hud); }
.slider:disabled { cursor: default; }
.slider:disabled::-webkit-slider-thumb { background: var(--hud-dim); }
.slider:disabled::-moz-range-thumb { background: var(--hud-dim); }
.slider:focus-visible { outline-offset: -6px; }

/* status + messages */
.status { margin: 0; color: var(--hud-dim); }
.messages { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.messages:empty { display: none; }
.msg { margin: 0; color: var(--hud); cursor: pointer; text-transform: none; }
.msg.error { color: var(--warn); }
.msg::before { content: "› "; color: var(--hud-dim); }

/* ------------------------------------------------------------------- drawer */

.drawer {
  grid-row: 1;
  grid-column: 1;
  justify-self: end;
  align-self: stretch;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(26rem, 100%);
  min-height: 0;
  padding: 12px 12px 10px;
  border-left: 1px solid var(--line);
  background: var(--bg);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.drawer-title {
  margin: 0;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--hud);
}
.drawer-title::before { content: "CH-05 "; color: var(--hud-dim); }
.drawer-tools { display: flex; gap: 6px; }
.drawer-tools .key { flex: 1; }

.list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.list li { display: flex; border-bottom: 1px solid var(--grid); }
.list li:last-child { border-bottom: 0; }
.trk {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 3ch minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--hud);
  font: inherit;
  letter-spacing: 0.04em;
  text-align: left;
  cursor: pointer;
}
.trk:hover { background: var(--panel); }
.trk[aria-current="true"] { color: var(--accent); box-shadow: inset 2px 0 0 var(--accent); }
.trk[aria-disabled="true"] { color: var(--hud-dim); cursor: progress; }
.trk .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trk .no, .trk .dur { color: var(--hud-dim); font-variant-numeric: tabular-nums; }
.trk:focus-visible, .rm:focus-visible { outline-offset: -2px; }
.rm {
  width: 32px;
  border: 0;
  border-left: 1px solid var(--grid);
  background: transparent;
  color: var(--hud-dim);
  font: inherit;
  cursor: pointer;
}
.rm:hover { color: var(--warn); }

.entity { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.entity dt { color: var(--hud-dim); text-transform: uppercase; letter-spacing: 0.16em; }
.entity dd { margin: 0; color: var(--hud); }
#state-name { color: var(--accent); letter-spacing: 0.16em; }

.hint { margin: 0; color: var(--hud-dim); line-height: 1.7; }
kbd {
  display: inline-block;
  min-width: 2ch;
  padding: 0 4px;
  border: 1px solid var(--line);
  color: var(--hud);
  font: inherit;
  text-align: center;
}

/* --------------------------------------------------------------- drop overlay */

/* The whole page becomes one input plate: dark screen with a faint scan raster, a hairline frame with
   heavy corner brackets, a centred readout and a tick scale. Hard edges, no blur, no rounded corners. */
.drop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: stretch;
  padding: clamp(10px, 3vmin, 28px);
  background:
    repeating-linear-gradient(0deg, rgb(255 255 255 / 0.025) 0 1px, transparent 1px 3px),
    rgb(2 3 4 / 0.9);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  font-family: var(--mono);
}
body.is-dragging .drop { opacity: 1; visibility: visible; }
.drop-frame {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vmin, 16px);
  border: 1px solid var(--line);
  outline: 1px solid rgb(var(--accent-rgb) / 0.35);
  outline-offset: -6px;
  text-align: center;
  text-transform: uppercase;
}
.drop-corner { position: absolute; width: clamp(18px, 5vmin, 44px); height: clamp(18px, 5vmin, 44px); border: 0 solid var(--accent); }
.drop-corner.tl { left: -1px; top: -1px; border-left-width: 3px; border-top-width: 3px; }
.drop-corner.tr { right: -1px; top: -1px; border-right-width: 3px; border-top-width: 3px; }
.drop-corner.bl { left: -1px; bottom: -1px; border-left-width: 3px; border-bottom-width: 3px; }
.drop-corner.br { right: -1px; bottom: -1px; border-right-width: 3px; border-bottom-width: 3px; }
.drop-code { margin: 0; color: var(--hud-dim); letter-spacing: 0.3em; font-size: clamp(10px, 1.6vmin, 13px); }
.drop-title {
  margin: 0;
  color: var(--ink);
  font-size: clamp(20px, 5.2vmin, 52px);
  font-weight: 700;
  letter-spacing: 0.18em;
  white-space: nowrap;
}
.drop-plus {
  display: inline-grid;
  place-items: center;
  width: 1.15em;
  height: 1.15em;
  margin-right: 0.45em;
  border: 2px solid var(--accent);
  color: var(--accent);
  line-height: 1;
}
.drop-sep { color: var(--accent); }
.drop-scale {
  width: min(70%, 640px);
  height: 10px;
  border-bottom: 1px solid var(--ink-dim);
  background: repeating-linear-gradient(90deg, var(--ink-dim) 0 1px, transparent 1px 10%) bottom / 100% 10px no-repeat,
    repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px 2%) bottom / 100% 5px no-repeat;
}
.drop-sub { margin: 0; color: var(--hud-dim); letter-spacing: 0.15em; font-size: clamp(10px, 1.6vmin, 13px); }
@media (max-width: 600px) {
  .drop-title { font-size: 6.2vw; letter-spacing: 0.08em; }
}

.key-add { border-color: rgb(var(--accent-rgb) / 0.6); }
.key-add .ico { color: var(--accent); }

/* ------------------------------------------------------------------- sizes */

@media (min-width: 1500px) {
  .opt .nm { display: inline; color: var(--hud-dim); }
  .opt[aria-pressed="true"] .nm { color: var(--accent); }
}
@media (min-width: 2400px) {
  body { font-size: 14px; }
  :root { --key: 40px; }
}
@media (pointer: coarse) {
  :root { --key: 44px; }
  .rail { gap: 8px 10px; }
}
@media (max-width: 600px) {
  .grp-transport { flex: 1 1 100%; justify-content: space-between; }
  .grp-tape { flex-basis: 100%; }
  .seg { flex: 1 1 auto; }
  .opt { flex: 1; justify-content: center; padding: 0 4px; }
  .grp-scene { flex: 1 1 auto; }
  .select { flex: 1; max-width: none; }
  .drawer { width: 100%; border-left: 0; }
}

/* A phone held upright (the core's stacked portrait face: narrower than 600 px, height >= 1.2 x width):
   the face takes the whole screen and the rail sits over its lower end (the telemetry bay and the last
   list rows) while it is shown. Idle, the rail is gone and lets taps through to the track list. */
@media (max-width: 599px) and (max-aspect-ratio: 5/6) {
  .stage { grid-row: 1 / -1; }
  .rail { position: relative; z-index: 2; }
  .chassis[data-idle="true"] .rail { pointer-events: none; }
}

@media (prefers-reduced-motion: reduce) {
  .rail { transition: none; }
}
@media (forced-colors: active) {
  .key[aria-pressed="true"], .opt[aria-pressed="true"] { outline: 2px solid Highlight; }
}
