:root {
  --bg: #08090b;
  --ink: #f4f6f6;
  --dim: #6b7280;
  --line: rgba(244, 246, 246, 0.11);
  --accent: #64e3d7;
  --bad: #ff6b5e;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

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

/* A canvas is a replaced element: with width:auto its layout size comes from its
   own width/height attributes, so sizing the attributes from clientWidth feeds
   back and the canvas doubles every frame. The explicit 100% breaks the loop. */
#stage { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }

/* ---------- header ---------- */

header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3;
  display: flex; align-items: baseline; gap: 14px;
  padding: 22px clamp(18px, 4vw, 40px);
  pointer-events: none;
}
.mark {
  font-family: var(--mono); font-size: 13px; font-weight: 600;
  letter-spacing: .32em; text-transform: uppercase;
}
.sub {
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em;
  color: var(--dim);
}
@media (max-width: 620px) { .sub { display: none; } }

/* ---------- readout ---------- */

/* the graph is centred, so the readout sits on its own scrim to stay legible */
#hud::before {
  content: ''; position: fixed; z-index: -1; top: 0; bottom: 0; right: 0;
  width: min(330px, 34vw);
  background: linear-gradient(to left, rgba(8, 9, 11, .92) 30%, transparent);
}
#hud {
  position: fixed; z-index: 3;
  top: 50%; right: clamp(14px, 3vw, 34px); transform: translateY(-50%);
  display: grid; gap: 9px;
  font-family: var(--mono); font-size: 11px;
  pointer-events: none;
}
#hud .row {
  display: grid; grid-template-columns: 1fr; justify-items: end;
  line-height: 1.25;
}
#hud b {
  font-size: 17px; font-weight: 500; font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
#hud span { color: var(--dim); letter-spacing: .1em; font-size: 9.5px; text-transform: uppercase; }
#hud .cost { margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
#hud .cost b { color: var(--accent); }
/* Portrait: the readout moves under the header and the scrim comes from the top,
   so the middle of the screen belongs to the graph. */
@media (max-width: 720px) {
  #hud { top: 62px; bottom: auto; right: 14px; transform: none; gap: 5px; }
  #hud b { font-size: 14px; }
  #hud span { font-size: 8.5px; }
  #hud .cost { margin-top: 3px; padding-top: 6px; }
  #hud::before {
    top: 0; bottom: auto; left: 0; right: 0; width: auto; height: 300px;
    background: linear-gradient(to bottom, rgba(8, 9, 11, .9) 45%, transparent);
  }
}

/* ---------- hover card ---------- */

#tip {
  position: fixed; z-index: 4; display: none;
  padding: 9px 11px; max-width: 260px;
  font-family: var(--mono); font-size: 11px; line-height: 1.5;
  background: rgba(8, 9, 11, .92); border: 1px solid var(--line);
  border-radius: 8px; backdrop-filter: blur(10px);
  pointer-events: none; white-space: pre-line;
}
#tip .k { color: var(--dim); }

/* ---------- footer / transport ---------- */

footer {
  position: fixed; z-index: 3; bottom: 0; left: 0; right: 0;
  padding: 0 clamp(18px, 4vw, 40px) 20px;
  background: linear-gradient(to top, var(--bg) 42%, transparent);
}

#runs { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
@media (max-width: 720px) {
  /* one scrollable row beats two wrapped rows eating the canvas */
  #runs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -18px 12px; padding: 0 18px; }
  #runs::-webkit-scrollbar { display: none; }
  #runs button { flex: none; }
  .bar { gap: 10px; }
}
#runs button {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--dim);
  padding: 7px 12px; cursor: pointer;
  background: transparent; border: 1px solid var(--line); border-radius: 999px;
  transition: color .18s, border-color .18s;
}
#runs button:hover { color: var(--ink); border-color: rgba(244, 246, 246, .3); }
#runs button[aria-current="true"] { color: var(--bg); background: var(--accent); border-color: var(--accent); }

.bar { display: flex; align-items: center; gap: 14px; }

#play {
  flex: none; width: 40px; height: 40px; padding: 0; cursor: pointer;
  display: grid; place-items: center; color: var(--ink);
  background: transparent; border: 1px solid rgba(244, 246, 246, .25);
  border-radius: 999px; transition: border-color .18s, background .18s;
}
#play:hover { border-color: var(--accent); background: rgba(100, 227, 215, .08); }
#play svg { width: 17px; height: 17px; fill: currentColor; }
#play .i-pause, #play.paused .i-play { display: block; }
#play .i-play, #play.paused .i-pause { display: none; }

#scrub {
  flex: 1; height: 20px; margin: 0; cursor: pointer;
  appearance: none; background: transparent;
}
#scrub::-webkit-slider-runnable-track { height: 1px; background: var(--line); }
#scrub::-moz-range-track { height: 1px; background: var(--line); }
#scrub::-webkit-slider-thumb {
  appearance: none; margin-top: -5px; width: 11px; height: 11px;
  border-radius: 999px; background: var(--accent); border: none;
}
#scrub::-moz-range-thumb { width: 11px; height: 11px; border: none; border-radius: 999px; background: var(--accent); }

.clock, .speed {
  font-family: var(--mono); font-size: 11px; font-variant-numeric: tabular-nums;
  letter-spacing: .08em; color: var(--dim);
}
.speed {
  padding: 6px 9px; cursor: pointer; min-width: 48px;
  background: transparent; border: 1px solid var(--line); border-radius: 6px;
}
.speed:hover { color: var(--ink); border-color: rgba(244, 246, 246, .3); }

.note {
  max-width: 62ch; margin: 14px 0 0;
  font-family: var(--mono); font-size: 10.5px; line-height: 1.65;
  color: var(--dim);
}
@media (max-width: 720px) { .note { display: none; } }
