/*
 * rally.
 *
 * The look is taken from superhuman.com: near black, one electric accent, thin
 * hairlines, small wide-tracked labels, and type that is tight where it is big
 * and loose where it is small. What is borrowed is the discipline rather than
 * the palette.
 *
 * The field behind the glass is a timing diagram, because that is what this
 * page is about. Hairlines every 9px with a heavier one every ninth, which is
 * the pitch that matters: fine enough that a 22px blur under a panel returns
 * flat colour, coarse enough to read as texture in the margins. Glass over a
 * flat background is just flat background, so the field has to exist first.
 *
 * It is painted on `body` and not on a fixed `::before` at `z-index: -1`. That
 * pattern creates a stacking context which then eats anything trying to glow
 * above it, and there are two glows on this page.
 *
 * Two accents, and they mean something rather than decorating. Violet is
 * predicted, teal is confirmed. The same pair is used in the readout, on the
 * tick ribbon and on the ball, so the numbers and the picture agree.
 */

:root {
  --violet: #7c5cff;
  --violet-soft: #a08cff;
  --teal: #2fd4c4;
  --amber: #ffb547;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --radius: 16px;
  --hair: 1px;
}

:root[data-theme="dark"] {
  --bg: #08080d;
  --ink: #ececf4;
  --ink-dim: #8f8fa8;
  --ink-faint: #5c5c74;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-solid: #12121b;
  --edge: rgba(255, 255, 255, 0.085);
  --edge-strong: rgba(255, 255, 255, 0.16);
  --rule: rgba(255, 255, 255, 0.035);
  --rule-strong: rgba(255, 255, 255, 0.075);
  --glow-a: rgba(124, 92, 255, 0.22);
  --glow-b: rgba(47, 212, 196, 0.1);
  --court: rgba(255, 255, 255, 0.05);
  --court-line: rgba(255, 255, 255, 0.14);
  --score: rgba(255, 255, 255, 0.3);
  --paddle: #ececf4;
  --scrim: rgba(8, 8, 13, 0.72);
  --grad-a: #a08cff;
  --grad-b: #2fd4c4;
}

:root[data-theme="light"] {
  --bg: #f5f4f9;
  --ink: #12121a;
  --ink-dim: #55556c;
  --ink-faint: #8a8aa0;
  --panel: rgba(255, 255, 255, 0.62);
  --panel-solid: #ffffff;
  --edge: rgba(16, 16, 32, 0.1);
  --edge-strong: rgba(16, 16, 32, 0.18);
  --rule: rgba(16, 16, 40, 0.045);
  --rule-strong: rgba(16, 16, 40, 0.09);
  --glow-a: rgba(124, 92, 255, 0.16);
  --glow-b: rgba(47, 212, 196, 0.12);
  --court: rgba(16, 16, 40, 0.035);
  --court-line: rgba(16, 16, 40, 0.14);
  --score: rgba(16, 16, 40, 0.28);
  --paddle: #1a1a26;
  --scrim: rgba(245, 244, 249, 0.78);
  /* Darker than the dark theme's pair, not lighter. The same violet and teal
     that read as bright on near-black read as washed out on near-white, and
     the last word of the headline was the palest thing on the page. */
  --grad-a: #6034f2;
  --grad-b: #0d9285;
}

* { box-sizing: border-box; }

/* `hidden` is a UA rule, so any author rule setting `display` beats it whatever
   the specificity. That is not a subtle failure: `.btn` is inline-flex and
   `.steps` is grid, so the online panel showed "Start over" and an empty grid
   before anything had started. The whole handshake is driven by this attribute,
   so it wins here. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  color: var(--ink);
  background-color: var(--bg);
  /* Glow first so it sits over the rules, then the two rule pitches. */
  background-image:
    radial-gradient(900px 520px at 50% -8%, var(--glow-a), transparent 70%),
    radial-gradient(680px 460px at 88% 34%, var(--glow-b), transparent 72%),
    repeating-linear-gradient(90deg, var(--rule-strong) 0 1px, transparent 1px 81px),
    repeating-linear-gradient(90deg, var(--rule) 0 1px, transparent 1px 9px);
  background-attachment: fixed;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

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

.dim { color: var(--ink-dim); }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px clamp(16px, 4vw, 44px);
  padding-left: max(clamp(16px, 4vw, 44px), env(safe-area-inset-left));
  padding-right: max(clamp(16px, 4vw, 44px), env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border-bottom: var(--hair) solid var(--edge);
}

.wordmark {
  font-weight: 700;
  font-size: 1.16rem;
  letter-spacing: -0.03em;
  text-decoration: none;
  margin-right: auto;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.topnav a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-radius: 9px;
  color: var(--ink-dim);
  font-size: 0.86rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.18s var(--ease), background 0.18s var(--ease);
}

.topnav a:hover { color: var(--ink); background: var(--panel); }

.ico { width: 15px; height: 15px; fill: currentColor; flex: none; }

.pill,
.icon-btn {
  border: var(--hair) solid var(--edge);
  background: var(--panel);
  color: var(--ink-dim);
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  transition: color 0.18s var(--ease), border-color 0.18s var(--ease);
}

.pill { padding: 6px 12px; }
.pill:hover, .icon-btn:hover { color: var(--ink); border-color: var(--edge-strong); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 33px;
  padding: 0;
}

.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.7; }
:root[data-theme="dark"] .sun { display: none; }
:root[data-theme="light"] .moon { display: none; }

/* -------------------------------------------------------------------- hero */

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 44px) 96px;
  padding-left: max(clamp(16px, 4vw, 44px), env(safe-area-inset-left));
  padding-right: max(clamp(16px, 4vw, 44px), env(safe-area-inset-right));
}

/* Deliberately short. The board is the argument, so it has to be on screen
   without scrolling; a hero that fills the fold turns a playable page into a
   landing page with a game somewhere below it. */
.hero { padding: clamp(30px, 4.5vw, 52px) 0 clamp(20px, 2.6vw, 30px); }

.kicker,
.eyebrow {
  margin: 0 0 14px;
  font-size: 0.735rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.hero-title {
  margin: 0 0 14px;
  font-size: clamp(2rem, 4.6vw, 3.3rem);
  font-weight: 600;
  line-height: 1.04;
  letter-spacing: -0.042em;
}

.hero-title em {
  font-style: normal;
  background: linear-gradient(96deg, var(--grad-a), var(--grad-b));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lede {
  margin: 0;
  max-width: 56ch;
  font-size: clamp(1.02rem, 1.6vw, 1.16rem);
  color: var(--ink-dim);
}

/* ------------------------------------------------------------------- glass */

.glass {
  background: var(--panel);
  border: var(--hair) solid var(--edge);
  border-radius: var(--radius);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
}

/* ------------------------------------------------------------------- arena */

.arena { scroll-margin-top: 74px; }

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 268px;
  gap: 14px;
  align-items: start;
  /* Board panel, gap, readout. Written out rather than left to `auto` columns,
     because the panel's own width uses a percentage and an auto track sized
     from a percentage child is circular. */
  max-width: calc(62svh * 5 / 3 + 28px + 14px + 268px);
  margin-inline: auto;
}

/* The panel wraps the board rather than the column.
 *
 * Sized from the same expression as the canvas plus its padding, because the
 * ribbon underneath is 100% of the panel: let the panel run wider than the
 * board and the ribbon runs wider than the board too, and the one strip whose
 * whole job is to line up tick for tick with the game stops lining up with it. */
.board-panel {
  width: min(100%, calc(62svh * 5 / 3 + 28px));
  margin-inline: auto;
  padding: 14px;
  overflow: hidden;
}

/* Height first, width second.
 *
 * A board sized purely by its column is as tall as the column is wide, which on
 * a laptop pushes the mode tabs and the whole readout below the fold. Capping
 * the height and deriving the width from the aspect ratio keeps the game and
 * its controls on one screen, which is the only reason any of this is here. */
#board {
  display: block;
  width: 100%;
  aspect-ratio: 5 / 3;
  border-radius: 9px;
  background: var(--court);
  touch-action: none;
  cursor: crosshair;
}

.ribbon-wrap { margin-top: 11px; }

#ribbon {
  display: block;
  width: 100%;
  height: 30px;
  border-radius: 6px;
}

.ribbon-key {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 9px;
  font-size: 0.715rem;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.ribbon-key > span { display: inline-flex; align-items: center; gap: 6px; }

.swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--ink-faint);
}

.swatch.is-confirmed { background: var(--teal); }
.swatch.is-predicted { background: var(--violet); }
.swatch.is-rewritten { background: var(--amber); }

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

.readout { padding: 18px 18px 16px; }

.figures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 10px;
  margin: 0;
}

.figures > div { min-width: 0; }

.figures dt,
.hash-row dt {
  margin: 0 0 2px;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.figures dd,
.hash-row dd {
  margin: 0;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 1.28rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.figures dd.is-confirmed { color: var(--teal); }
.figures dd.is-predicted { color: var(--violet-soft); }
.figures dd.is-bad { color: var(--amber); }

.hash-row {
  margin-top: 15px;
  padding-top: 13px;
  border-top: var(--hair) solid var(--edge);
}

.hash-row dd { font-size: 1.02rem; color: var(--ink-dim); }

.readout-note {
  margin: 13px 0 0;
  font-size: 0.775rem;
  line-height: 1.5;
  color: var(--ink-faint);
}

/* ------------------------------------------------------------------- modes */

.modes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 16px 0 12px;
}

.tab {
  padding: 9px 17px;
  border: var(--hair) solid var(--edge);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-dim);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s var(--ease);
}

.tab:hover { color: var(--ink); border-color: var(--edge-strong); }

.tab.is-on {
  color: #fff;
  background: var(--violet);
  border-color: transparent;
  box-shadow: 0 5px 22px -6px var(--violet);
}

.panel { padding: 18px 20px 20px; }

.panel-lede {
  margin: 0 0 16px;
  max-width: 62ch;
  font-size: 0.925rem;
  color: var(--ink-dim);
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: 16px 22px;
}

.control label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 0.715rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.control output {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink-dim);
}

.control select {
  width: 100%;
  padding: 9px 11px;
  border: var(--hair) solid var(--edge);
  border-radius: 9px;
  background: var(--panel-solid);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: var(--edge-strong);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 17px;
  height: 17px;
  margin-top: -7px;
  border: none;
  border-radius: 50%;
  background: var(--violet);
  box-shadow: 0 2px 9px -2px var(--violet);
}

input[type="range"]::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: var(--edge-strong);
}

input[type="range"]::-moz-range-thumb {
  width: 17px;
  height: 17px;
  border: none;
  border-radius: 50%;
  background: var(--violet);
}

.keys {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 0.86rem;
  color: var(--ink-dim);
}

.keys .gap { width: 20px; }

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 27px;
  height: 27px;
  padding: 0 7px;
  border: var(--hair) solid var(--edge-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--panel-solid);
  color: var(--ink);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.78rem;
}

/* ------------------------------------------------------------------ online */

.online-start { display: flex; flex-wrap: wrap; gap: 9px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 19px;
  border: var(--hair) solid var(--edge-strong);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.885rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.18s var(--ease);
}

.btn:hover { border-color: var(--ink-faint); }

.btn-primary {
  background: var(--violet);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 24px -8px var(--violet);
}

.btn-primary:hover { filter: brightness(1.08); border-color: transparent; }

.btn-quiet {
  margin-top: 12px;
  padding: 6px 12px;
  border-color: transparent;
  color: var(--ink-faint);
  font-size: 0.8rem;
}

.btn-quiet:hover { color: var(--ink); border-color: var(--edge); }

.steps { display: grid; gap: 18px; margin-top: 4px; }

.step-label {
  margin: 0 0 8px;
  font-size: 0.715rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.step textarea {
  display: block;
  width: 100%;
  margin-bottom: 9px;
  padding: 11px 13px;
  border: var(--hair) solid var(--edge);
  border-radius: 10px;
  background: var(--panel-solid);
  color: var(--ink-dim);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.735rem;
  line-height: 1.5;
  resize: vertical;
  /* A handshake code is one very long line. Breaking it anywhere is right,
     because none of it is meant to be read as words. */
  word-break: break-all;
}

.step textarea:focus {
  outline: none;
  border-color: var(--violet);
}

/* The QR is always dark on white with a white quiet zone, in both themes.
   A camera reads contrast, and inverting it to suit a dark page is the
   fastest way to make a code that half the phones in the room refuse. */
.qr-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
}

.qr {
  flex: none;
  width: min(290px, 100%);
  height: auto;
  padding: 0;
  border-radius: 10px;
  background: #fff;
  image-rendering: pixelated;
}

.qr-side {
  flex: 1 1 260px;
  min-width: 0;
}

.qr-hint {
  margin: 0 0 9px;
  font-size: 0.815rem;
  line-height: 1.5;
  color: var(--ink-dim);
}

.scan {
  display: block;
  width: min(320px, 100%);
  margin-bottom: 10px;
  border: var(--hair) solid var(--edge);
  border-radius: 10px;
  background: #000;
  transform: scaleX(-1);
}

.status {
  margin: 14px 0 0;
  font-size: 0.86rem;
  color: var(--ink-dim);
  min-height: 1.4em;
}

.status.is-bad { color: var(--amber); }
.status.is-good { color: var(--teal); }

/* ------------------------------------------------------------------- bands */

.band {
  padding-top: clamp(56px, 8vw, 96px);
  scroll-margin-top: 74px;
}

.band h2 {
  margin: 0 0 16px;
  font-size: clamp(1.6rem, 3.2vw, 2.3rem);
  font-weight: 600;
  line-height: 1.14;
  letter-spacing: -0.032em;
  max-width: 22ch;
}

.body {
  margin: 0 0 28px;
  max-width: 62ch;
  color: var(--ink-dim);
}

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(258px, 1fr));
  gap: 12px;
}

.card {
  padding: 20px 21px 22px;
  border: var(--hair) solid var(--edge);
  border-radius: 13px;
  background: var(--panel);
  backdrop-filter: blur(22px) saturate(160%);
  -webkit-backdrop-filter: blur(22px) saturate(160%);
}

.card h3 {
  margin: 0 0 9px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.012em;
}

.card p {
  margin: 0;
  font-size: 0.895rem;
  line-height: 1.6;
  color: var(--ink-dim);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 11px;
  align-items: center;
  margin-top: 28px;
}

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

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  padding: 30px 20px calc(30px + env(safe-area-inset-bottom));
  border-top: var(--hair) solid var(--edge);
  font-size: 0.83rem;
  color: var(--ink-faint);
}

.foot a { text-decoration: none; transition: color 0.18s var(--ease); }
.foot a:hover { color: var(--ink); }
.sep { opacity: 0.45; }

/* ------------------------------------------------------------- narrow view */

@media (max-width: 900px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .figures { grid-template-columns: repeat(3, 1fr); }
  .hero-title { max-width: none; }
}

@media (max-width: 560px) {
  .topnav a span:not(.ico) { display: none; }
  .topnav a { padding: 7px 8px; }
  .figures dd, .hash-row dd { font-size: 1.1rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
