/* Stopping Distance — everything outside the canvas.
 *
 * The road, the bike and the two distance bars all live in Phaser. This file
 * keeps the canvas centred, stops the page scrolling under a braking thumb,
 * and dresses the three cards: the guess, the debrief, the end.
 *
 * The debrief repeats the two bars in the DOM. That is deliberate duplication:
 * the canvas version is the dramatic one that grows under the bike, the DOM
 * version is selectable, survives a dead canvas, and is the one a screen
 * reader and a zoomed-in phone can actually use.
 */

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#stage {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

#stage canvas {
  display: block;
  /* The whole game is one control, and that control is a hold. Without this a
     hold-and-brake reads as a page drag on Android and the brake never fires. */
  touch-action: none;
}

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

.nojs {
  position: fixed;
  inset: auto 20px 20px;
  z-index: 60;
  margin: 0;
  padding: 16px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 14px;
  line-height: 1.5;
}

/* ================================================================
 * Cards. One shell for all three.
 * ================================================================ */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(18, 9, 31, 0.84);
  backdrop-filter: blur(10px);
  animation: sheet-in 0.18s var(--ease-out) both;
  /* A tall debrief (bars + open "why?") must not trap its own bottom on a
     small phone. The sheet scrolls; the road behind it does not. */
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet[hidden] { display: none; }

@keyframes sheet-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.card {
  width: 100%;
  max-width: 348px;
  /* Vertically centred by the flex parent, but margin:auto keeps a card taller
     than the viewport from having its top cut off and unreachable. */
  margin: auto;
  padding: 24px 22px 20px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: card-in 0.26s var(--ease-snap) both;
}

@keyframes card-in {
  from { transform: translateY(14px) scale(0.96); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.kick {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}

/* ---------- the guess ---------- */

.guess-h {
  margin: 0;
  font-size: clamp(19px, 5.6vw, 23px);
  font-weight: 500;
  line-height: 1.4;
  color: var(--paper);
}

.guess-h b {
  font-weight: 700;
  color: var(--gold);
}

.guess-art {
  display: block;
  width: 100%;
  height: auto;
  margin: 18px 0 4px;
}

.guess-q {
  margin: 8px 0 16px;
  font-size: 17px;
  font-weight: 700;
  color: var(--paper);
}

.guess-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ---------- verdict ---------- */

.verdict {
  margin: 0;
  font-size: clamp(28px, 8.4vw, 36px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--volt);
}

.verdict.hit { color: var(--hot); }

.line {
  margin: 10px 0 0;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--dim);
}

.line b {
  font-weight: 700;
  color: var(--paper);
}

/* ---------- the bars: the hero visual ----------
 *
 * Fixed metre scale across all six rounds, so round 3's bar is visibly, and
 * honestly, four times round 1's. Rescaling per round would flatter the fast
 * rounds and quietly delete the entire lesson. */

.bars {
  margin: 20px 0 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
  text-align: left;
}

.bar-row {
  display: grid;
  grid-template-columns: 62px 1fr 56px;
  align-items: center;
  gap: 9px;
}

.bar-lab {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
}

.bar-track {
  position: relative;
  height: 16px;
  border-radius: 8px;
  background: var(--void);
  border: 1px solid var(--line);
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 7px;
  transition: width 0.5s var(--ease-out);
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}

.bar-gold  { background: var(--gold); }
.bar-hot   { background: var(--hot); }
.bar-paper { background: var(--paper); }

.bar-num {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 13px;
  font-weight: 700;
  text-align: right;
  color: var(--paper);
}

.bar-total {
  margin-top: 5px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

/* Where the hazard was. If the paper bar runs past this line, you hit it —
   the picture says so before any of the words do. */
.hazard-mark {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 3px;
  background: var(--volt);
  border-radius: 2px;
  box-shadow: 0 0 0 2px rgba(18, 9, 31, 0.9);
  transition: left 0.5s var(--ease-out);
}

.gap {
  margin: 14px 0 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--dim);
}

.gap b { color: var(--paper); }
.gap b.over { color: var(--hot); }
.gap b.under { color: var(--volt); }

/* ---------- numbers on the end card ---------- */

.nums {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 20px 0 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.nums > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.num {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  color: var(--volt);
}

.nums > div:nth-child(2) .num { color: var(--gold); }
.nums > div:nth-child(3) .num { color: var(--paper); }

.num-lab {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

/* ---------- buttons ---------- */

.big {
  width: 100%;
  min-height: var(--thumb);
  border-radius: 16px;
  font-size: 17px;
  font-weight: 700;
  transition: transform 0.12s var(--ease-snap);
}

.big:active { transform: scale(0.97); }

.big-volt { background: var(--volt); color: var(--void); }
.big-hot  { background: var(--hot);  color: var(--paper); }

#again { margin-top: 18px; }

/* ---------- the opt-in explanation ---------- */

.why {
  margin-top: 12px;
  text-align: left;
}

/* 44px: the arcade's floor for anything a thumb has to find. */
.why summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 2px;
  font-size: 14px;
  font-weight: 600;
  color: var(--dim);
}

.why summary::-webkit-details-marker { display: none; }
.why summary::after { content: " \203A"; }
.why[open] summary::after { content: " \2039"; }
.why summary:hover { color: var(--paper); }

.why-body p {
  margin: 0 0 10px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--dim);
}

.why-body p:last-child { margin-bottom: 4px; }

.why-body b {
  font-weight: 700;
  color: var(--paper);
}

/* The actual sum, shown to anyone who asks. Monospace so the numbers line up
   and it reads as working, not as prose.
   pre-wrap, not pre-line: pre-line collapses runs of spaces, which silently
   destroyed the column alignment the labels are padded to produce. */
.maths {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11.5px;
  line-height: 1.7;
  color: var(--gold);
  white-space: pre-wrap;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--void);
  border: 1px solid var(--line);
}

.stat-head {
  font-weight: 700;
  color: var(--paper) !important;
  margin-bottom: 6px !important;
}

.stats {
  margin: 0 0 10px;
  padding-left: 18px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--dim);
}

.stats b {
  font-weight: 700;
  color: var(--hot);
}

.fine {
  font-size: 12px !important;
  color: var(--dim);
  opacity: 0.8;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
