:root {
  --ink: #f4f2ee;
  --void: #06060a;
  --d: #1f3bff;
  --r: #ff2b3d;
  --dim: rgba(244, 242, 238, 0.42);
  --line: rgba(244, 242, 238, 0.14);
  --mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
  --pad: clamp(14px, 2.2vw, 30px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--void);
  color: var(--ink);
  overflow: hidden;
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- chrome ---------- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: var(--pad);
  z-index: 6;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 11px;
  letter-spacing: 0.16em;
  opacity: 0.9;
}

.brand b { font-weight: 500; }

.source {
  display: flex;
  border: 1px solid var(--line);
}

.source button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--dim);
  font: inherit;
  font-size: 9px;
  letter-spacing: 0.18em;
  padding: 4px 7px;
  cursor: pointer;
}

.source button + button { border-left: 1px solid var(--line); }
.source button:hover { color: var(--ink); }
.source button[aria-busy="true"] { opacity: 0.55; cursor: progress; }

.source button[aria-selected="true"] {
  color: var(--void);
  background: var(--ink);
}

.src-note {
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--dim);
  opacity: 0.85;
}

/* Live results and market prices are single snapshots, so the night's
   transport controls make no sense for either. */
body[data-source="live"] .deck .icon,
body[data-source="live"] .scrub-wrap,
body[data-source="live"] #speed,
body[data-source="markets"] .deck .icon,
body[data-source="markets"] .scrub-wrap,
body[data-source="markets"] #speed {
  display: none;
}

/* the scrub bar normally pushes the race counter right; without it, do it here */
body[data-source="live"] .deck .pct,
body[data-source="markets"] .deck .pct { margin-left: auto; }

.modes { display: flex; gap: 6px; }

.modes button {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.14em;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.modes button i {
  font-style: normal;
  font-size: 8px;
  padding: 1px 4px;
  border: 1px solid currentColor;
  opacity: 0.7;
}

.modes button:hover { color: var(--ink); border-color: rgba(244, 242, 238, 0.4); }

.modes button[aria-selected="true"] {
  color: var(--void);
  background: var(--ink);
  border-color: var(--ink);
}

.deck {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px var(--pad) 14px;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--dim);
  background: linear-gradient(to top, rgba(6, 6, 10, 0.92), rgba(6, 6, 10, 0));
  z-index: 6;
}

.deck .icon,
.deck .speed {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  font: inherit;
  letter-spacing: 0.1em;
  padding: 6px 9px;
  cursor: pointer;
}

.deck .icon {
  height: 26px;
  width: 32px;
  padding: 0;
  font-size: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.deck .icon .ico {
  width: 14px;
  height: 14px;
  display: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.deck .icon .ico.on { display: block; }

.deck .speed { color: var(--dim); }

.deck .live {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  font: inherit;
  font-size: 9px;
  letter-spacing: 0.18em;
  padding: 0 9px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.deck .live i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  display: block;
  background: rgba(244, 242, 238, 0.3);
}

.deck .live.on { color: var(--ink); border-color: rgba(244, 242, 238, 0.45); }

.deck .live.on i {
  background: var(--r);
  box-shadow: 0 0 7px rgba(255, 43, 61, 0.9);
}
.deck button:hover { border-color: rgba(244, 242, 238, 0.45); }

.clock { color: var(--ink); min-width: 86px; }

.scrub-wrap { position: relative; flex: 1; display: flex; align-items: center; }

#scrub {
  appearance: none;
  width: 100%;
  height: 2px;
  background: rgba(244, 242, 238, 0.18);
  outline: none;
  cursor: pointer;
}

#scrub::-webkit-slider-thumb {
  appearance: none;
  width: 9px;
  height: 9px;
  background: var(--ink);
  border-radius: 0;
  cursor: pointer;
}

#scrub::-moz-range-thumb {
  width: 9px;
  height: 9px;
  border: 0;
  border-radius: 0;
  background: var(--ink);
}

.scrub-marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.pct { min-width: 92px; text-align: right; color: var(--ink); }

/* ---------- CRUT ---------- */

.scan {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.4s;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.34) 0 1px, rgba(0, 0, 0, 0) 1px 3px),
    radial-gradient(120% 100% at 50% 50%, rgba(0, 0, 0, 0) 55%, rgba(0, 0, 0, 0.55) 100%);
}

body[data-view="invaders"] .scan { opacity: 1; }

/* ---------- HUD: both ---------- */

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.25s;
}

body[data-view="seam"] .hud-seam,
body[data-view="invaders"] .hud-inv { opacity: 1; }

/* ---------- HUD: seam ---------- */

.hud-seam {
  display: grid;
  grid-template-rows: auto 1fr;
  padding: calc(var(--pad) * 2.6) var(--pad) 96px;
}

.seam-label {
  justify-self: center;
  font-size: clamp(8px, 0.9vw, 11px);
  letter-spacing: 0.34em;
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.85), 0 0 22px rgba(0, 0, 0, 0.6);
}

.seam-base {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 4vw;
  min-width: 0;
  padding-bottom: 4px;
}

.seam-num {
  display: flex;
  align-items: flex-end;
  gap: 0.18em;
  line-height: 0.88;
  color: #fff;
  text-shadow: 0 2px 60px rgba(0, 0, 0, 0.25);
}

.seam-num b {
  font-weight: 700;
  font-size: clamp(64px, 13vw, 190px);
  letter-spacing: -0.055em;
  font-variant-numeric: tabular-nums;
}

.seam-num span {
  font-size: clamp(8px, 1vw, 12px);
  letter-spacing: 0.3em;
  padding-bottom: clamp(6px, 1.2vw, 18px);
  opacity: 0.7;
}

.seam-num-r { flex-direction: row-reverse; }
.seam-num-r span { padding-bottom: clamp(6px, 1.2vw, 18px); }

.seam-tally {
  position: absolute;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  font-size: 9px;
  letter-spacing: 0.28em;
  color: rgba(255, 255, 255, 0.82);
  white-space: nowrap;
  text-shadow: 0 0 14px rgba(0, 0, 0, 0.55);
}

/* ---------- HUD: invaders ---------- */

.hud-inv { padding: calc(var(--pad) * 2.9) var(--pad) 58px; }

.inv-score {
  display: flex;
  flex-direction: column;
  gap: 18px;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--dim);
}

.inv-flip { display: flex; flex-direction: column; gap: 8px; }

.inv-flip b {
  display: inline-block;
  font-size: clamp(54px, 7.4vw, 118px);
  line-height: 0.78;
  font-weight: 700;
  letter-spacing: -0.05em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  transform-origin: left bottom;
}

.inv-flip b.bump { animation: bump 0.3s cubic-bezier(0.2, 0.8, 0.3, 1); }

@keyframes bump {
  0% { transform: scale(1.16); color: #7f92ff; }
  100% { transform: scale(1); color: var(--ink); }
}

.inv-flip span { letter-spacing: 0.24em; }

.inv-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 12px;
}

.inv-label em {
  font-style: normal;
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--dim);
  opacity: 0.7;
  white-space: nowrap;
}

.inv-rows { display: flex; flex-direction: column; gap: 3px; }

.inv-row { display: flex; justify-content: space-between; gap: 18px; width: 176px; }
.inv-row b { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }

.inv-chambers {
  position: absolute;
  right: var(--pad);
  top: calc(var(--pad) * 3.1);
  display: flex;
  flex-direction: column;
  gap: 7px;
  text-align: right;
}

.chamber {
  display: grid;
  grid-template-columns: auto auto 46px;
  align-items: center;
  justify-content: end;
  gap: 14px;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--dim);
}

.ch-nums {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-variant-numeric: tabular-nums;
  font-size: clamp(20px, 1.7vw, 27px);
  letter-spacing: -0.01em;
  line-height: 1;
}

.ch-nums i { font-style: normal; opacity: 0.35; }
.ch-d { color: #7f92ff; font-weight: 500; }
.ch-r { color: #ff6272; font-weight: 500; }

.ch-ctl {
  font-size: 10px;
  letter-spacing: 0.16em;
  padding: 3px 5px;
  border: 1px solid currentColor;
  text-align: center;
  color: var(--dim);
}

.ch-ctl.d { color: #8f9dff; }
.ch-ctl.r { color: #ff7d88; }

.inv-feed {
  position: absolute;
  right: var(--pad);
  top: calc(var(--pad) * 7.6);
  width: min(340px, 42vw);
  margin: 0;
  padding: 0;
  list-style: none;
  text-align: right;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--dim);
}

.inv-feed li {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 3px 0;
  animation: slide 0.35s ease-out;
}

.inv-feed .flip { color: #7f8cff; }
.inv-feed .lost { color: #ff7d88; }

@keyframes slide {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.inv-legend {
  position: absolute;
  left: var(--pad);
  bottom: 58px;
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.lg { display: inline-flex; align-items: center; gap: 5px; }
.lg + .lg { margin-left: 14px; }

/* the legend says different things once the wall shows probabilities */
.inv-legend .lg-heat { display: none; }
.inv-legend[data-kind="heat"] .lg-call { display: none; }
.inv-legend[data-kind="heat"] .lg-heat { display: inline-flex; }

.sw { width: 8px; height: 8px; display: inline-block; }
.sw-dim { background: rgba(255, 43, 61, 0.46); }
.sw-close { background: linear-gradient(90deg, var(--r) 50%, #8f9dff 50%); }
.sw-r { background: var(--r); }
.sw-d { background: #4d68ff; }
.sw-ramp {
  width: 34px;
  background: linear-gradient(90deg, #ff2b3d 0%, #d6d0e4 50%, #4d68ff 100%);
}

@media (max-width: 720px) {
  .modes button { padding: 7px 8px; font-size: 9px; }
  .modes button i { display: none; }
  .brand b { font-size: 9px; }
  .pct, .inv-feed { display: none; }
  .seam-num b { font-size: 26vw; }
}
