/* Shell styles. Colors come from palette.css (day/night token pairs) and
   are mixed live by --night, which the visualizer drives from 0 (white
   grid page) to 1 (black). */

:root {
  --night: 0;
  --n: calc(var(--night) * 100%);
  --paper: color-mix(in oklab, var(--night-paper) var(--n), var(--day-paper));
  --ink: color-mix(in oklab, var(--night-ink) var(--n), var(--day-ink));
  --ghost: color-mix(in oklab, var(--night-ink-ghost) var(--n), var(--day-ink-ghost));
  --grid-lin: color-mix(in oklab, var(--night-grid) var(--n), var(--day-grid));
  /* UI chrome does not fade linearly with the page: ink and paper would
     cross at mid-grey and the text would vanish. It snaps at night 0.5 and
     the snap is eased by color transitions on the elements. */
  --ui: clamp(0, (var(--night) - 0.5) * 1000, 1);
  --u: calc(var(--ui) * 100%);
  --ui-paper: color-mix(in oklab, var(--night-paper) var(--u), var(--day-paper));
  --ui-ink: color-mix(in oklab, var(--night-ink) var(--u), var(--day-ink));
  --ui-ghost: color-mix(in oklab, var(--night-ink-ghost) var(--u), var(--day-ink-ghost));
  /* Paper and its grid converge mid-fade; pull the rule toward the UI ink so
     the sheet stays a sheet while it dims. */
  --grid: color-mix(in oklab, var(--grid-lin) 84%, var(--ui-ink));
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --cell: 16px;
  --line: 1px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  min-height: 100dvh;
  overflow: hidden;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    linear-gradient(color-mix(in oklab, var(--grid) 45%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in oklab, var(--grid) 45%, transparent) 1px, transparent 1px);
  background-size: calc(var(--cell) * 5) calc(var(--cell) * 5), calc(var(--cell) * 5) calc(var(--cell) * 5), var(--cell) var(--cell), var(--cell) var(--cell);
  background-position: -1px -1px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#viz {
  position: fixed; inset: 0;
  width: 100vw; height: 100dvh;
  display: block;
  pointer-events: none;
  z-index: 0;
}
/* Paper tooth: a faint SVG noise so the page reads as stock, not screen. */
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  opacity: calc(0.22 - var(--night) * 0.14);
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .45 0 0 0 0 .4 0 0 0 .35 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 1px dashed var(--accent); outline-offset: 3px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- wireframe primitives ---------- */
.tree, .deck { --paper: var(--ui-paper); --ink: var(--ui-ink); --ghost: var(--ui-ghost); color: var(--ink); }
.tree *, .deck, .deck *, .tree, .tree::before, .tree::after {
  transition-property: color, background-color, border-color, box-shadow, fill, stroke;
  transition-duration: 600ms;
  transition-timing-function: ease;
}
/* A node is a hairline box with corner registration ticks and a ghost
   offset outline, like a drafting overlay that didn't quite align. */
.node, .panel, .deck {
  position: relative;
  border: var(--line) solid var(--ink);
  background: color-mix(in oklab, var(--paper) 94%, transparent);
  box-shadow: 4px 4px 0 -1px var(--paper), 4px 4px 0 0 var(--ghost);
  backdrop-filter: blur(1.5px);
}
.node::before, .panel::before, .deck::before,
.node::after, .panel::after, .deck::after {
  content: ""; position: absolute; width: 7px; height: 7px; pointer-events: none;
  border-color: var(--ink); border-style: solid;
}
.node::before, .panel::before, .deck::before { top: -4px; left: -4px; border-width: 1px 0 0 1px; }
.node::after, .panel::after, .deck::after { bottom: -4px; right: -4px; border-width: 0 1px 1px 0; }
.panel::after { bottom: 2px; right: 2px; }

/* ---------- the noodle tree ---------- */
.tree {
  position: fixed; z-index: 4; top: max(20px, env(safe-area-inset-top)); left: max(20px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: auto auto auto;
  grid-template-rows: auto;
  column-gap: 56px;
  align-items: start;
  max-width: calc(100vw - 40px);
}
.noodles {
  position: absolute; inset: 0; width: 100%; height: 100%;
  overflow: visible; pointer-events: none;
}
.noodles path {
  fill: none; stroke: var(--ink); stroke-width: 1.1;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.noodles path.ghost { stroke: var(--ghost); stroke-width: 1; stroke-dasharray: 2 4; }
.noodles circle { fill: var(--paper); stroke: var(--ink); stroke-width: 1; }
.noodles circle.live { fill: var(--accent); stroke: var(--accent); }

.node {
  display: block; text-align: left;
  padding: 7px 11px 6px;
  letter-spacing: 0.02em;
}
.node:hover { background: color-mix(in oklab, var(--paper) 70%, var(--ghost)); }
.root { grid-column: 1; padding: 10px 14px 9px; }
.root .node-label { display: block; font-size: 15px; letter-spacing: 0.01em; }
.root .node-meta { display: block; font-size: 10.5px; opacity: 0.62; letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; }

.branches {
  grid-column: 2;
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 12px;
  transform-origin: left center;
  transition: opacity 280ms ease, transform 380ms cubic-bezier(.2,.9,.2,1.15), visibility 0s;
}
.leaf { min-width: 104px; font-size: 12.5px; }
.leaf::marker { content: none; }
.leaf[aria-expanded="true"] {
  background: var(--ink); color: var(--paper);
  box-shadow: 4px 4px 0 -1px var(--paper), 4px 4px 0 0 var(--accent);
}
.tree.collapsed .branches { opacity: 0; transform: translateX(-24px) scaleX(0.6); pointer-events: none; visibility: hidden;
  transition: opacity 280ms ease, transform 380ms cubic-bezier(.2,.9,.2,1.15), visibility 0s linear 380ms; }
.tree.collapsed .panel { display: none; }

.panel {
  grid-column: 3; grid-row: 1;
  width: min(380px, calc(100vw - 340px));
  padding: 14px 16px 16px;
  max-height: max(240px, calc(100dvh - 220px));
  overflow: auto;
  animation: unfurl 360ms cubic-bezier(.2,.9,.2,1.1);
}
@keyframes unfurl { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.panel-h {
  margin: 0 0 10px; font-weight: 500; font-size: 10.5px;
  letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.7;
  border-bottom: 1px dashed var(--ghost); padding-bottom: 6px;
}
.prose p { margin: 0 0 10px; max-width: 58ch; }
.small { font-size: 12px; }
.pending { opacity: 0.66; font-style: italic; }
.credits { margin: 0 0 10px; display: grid; gap: 6px; }
.credits div { display: grid; grid-template-columns: 110px 1fr; gap: 10px; border-top: 1px dotted var(--ghost); padding-top: 5px; }
.credits dt { opacity: 0.62; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; padding-top: 1px; }
.credits dd { margin: 0; }

.pay { display: grid; gap: 12px; }
.amounts { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.amounts label { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.amounts input[type="radio"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.amounts label > span {
  display: inline-block; min-width: 46px; text-align: center;
  border: 1px solid var(--ink); padding: 5px 8px;
}
.amounts input[type="radio"]:checked + span { background: var(--ink); color: var(--paper); }
.amounts input[type="radio"]:focus-visible + span { outline: 1px dashed var(--accent); outline-offset: 3px; }
.amounts .custom > span { min-width: 0; border-right: 0; }
.amounts .custom input[type="number"] {
  width: 74px; border: 1px solid var(--ink); background: transparent; padding: 5px 6px;
  -moz-appearance: textfield;
}
.amounts .custom input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
.go {
  display: inline-block; justify-self: start;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  padding: 7px 12px; text-decoration: none; letter-spacing: 0.04em;
}
.go:hover { filter: brightness(1.06); }
.go[disabled] { opacity: 0.5; cursor: progress; }
.status { margin: 0; min-height: 1.5em; }

/* ---------- the deck (bottom left) ---------- */
.deck {
  position: fixed; z-index: 3;
  left: max(20px, env(safe-area-inset-left)); bottom: max(20px, env(safe-area-inset-bottom));
  width: 300px;
  padding: 8px 10px 9px;
  display: grid; gap: 7px;
  user-select: none;
}
.deck-top { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; font-size: 10.5px; letter-spacing: 0.08em; }
.deck-id { border: 1px solid var(--ink); padding: 0 4px; opacity: 0.8; }
.marquee { overflow: hidden; white-space: nowrap; mask-image: linear-gradient(90deg, transparent, #000 10%, #000 90%, transparent); }
.marquee span { display: inline-block; animation: marq 22s linear infinite; animation-play-state: paused; }
.deck.playing .marquee span { animation-play-state: running; }
@keyframes marq { to { transform: translateX(-50%); } }
.deck-time { font-variant-numeric: tabular-nums; font-size: 15px; letter-spacing: 0.02em; color: var(--accent); }
.deck-row { display: grid; grid-template-columns: auto auto 1fr auto; gap: 7px; align-items: center; }
.deck-row.lo { grid-template-columns: auto 90px 1fr; }
.deck-dur { font-size: 10.5px; opacity: 0.66; font-variant-numeric: tabular-nums; }
.deck-led { justify-self: end; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.66; }
.deck.playing .deck-led { color: var(--accent); opacity: 1; }

.key {
  width: 30px; height: 24px; padding: 0;
  display: grid; place-items: center;
  border: 1px solid var(--ink); background: transparent;
}
.key.small { width: 24px; height: 20px; }
.key svg { width: 13px; height: 13px; fill: var(--ink); stroke: var(--ink); stroke-width: 1.3; }
.key .i-pause { display: none; }
.deck.playing .key .i-play { display: none; }
.deck.playing .key .i-pause { display: inline; }
.key .i-wave { fill: none; }
#mute[aria-pressed="true"] .i-wave { display: none; }
.key:hover, .key:active { background: var(--ink); }
.key:hover svg, .key:active svg { fill: var(--paper); stroke: var(--paper); }
.play { width: 38px; }

/* Hairline sliders. */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 16px; margin: 0; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 1px;
  background: linear-gradient(90deg, var(--accent) 0 var(--fill, 0%), var(--ink) var(--fill, 0%));
}
input[type="range"]::-moz-range-track { height: 1px; background: var(--ink); }
input[type="range"]::-moz-range-progress { height: 1px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 9px; height: 9px; margin-top: -4px;
  background: var(--paper); border: 1px solid var(--ink); transform: rotate(45deg);
}
input[type="range"]::-moz-range-thumb {
  width: 8px; height: 8px; border-radius: 0;
  background: var(--paper); border: 1px solid var(--ink); transform: rotate(45deg);
}
/* Seek bar ticks every 30 s, drawn as a ghost ruler under the track. */
.seek { background-image: repeating-linear-gradient(90deg, var(--ghost) 0 1px, transparent 1px calc(100% / 9)); background-size: 100% 4px; background-repeat: no-repeat; background-position: 0 100%; }

.colophon {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
  margin: 0; z-index: 2;
  font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; opacity: calc(0.45 * (1 - var(--night)));
  writing-mode: vertical-rl; transform: rotate(180deg);
}

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .tree { grid-template-columns: auto auto; column-gap: 34px; row-gap: 14px; }
  .panel { grid-column: 1 / -1; grid-row: 2; width: calc(100vw - 40px); max-height: max(260px, calc(100dvh - 330px)); }
  .deck { width: calc(100vw - 40px); }
  .colophon { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .marquee span { animation: none; }
  .panel { animation: none; }
  .branches { transition: none; }
}
