/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --asphalt: #4a4a4a;
  --asphalt-dark: #3a3a3a;
  --sidewalk: #cdb892;
  --sidewalk-dark: #a89070;
  --grass: #5fa84a;
  --grass-dark: #3e7a30;
  --lane: #f2c84b;
  --crosswalk: #f0e9d8;
  --cone: #ec6a2c;
  --runner: #d44a3a;
  --runner-dark: #7a1f18;

  --bg: #1c1c1c;
  --ink: #e9e4d4;
  --ink-dim: #8c8773;
  --led: #ff5a3a;
  --led-bg: #1a0d0a;
  --paper: #f0e9d8;
  --bib-blue: #1f3a8a;
  --warn: #f0c454;
}

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  overscroll-behavior-y: none;
  overflow: hidden;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
}

/* ===== STREET CANVAS ===== */
#street {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  touch-action: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--asphalt-dark);
}

/* ===== HUD ===== */
#hud {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  z-index: 10;
  background: var(--led-bg);
  border: 2px solid #000;
  box-shadow: 2px 2px 0 #000, 0 0 0 1px #2a1815 inset;
  padding: 8px 10px;
  display: none;
  flex-direction: column;
  gap: 2px;
  min-width: 168px;
}
body[data-state="running"] #hud,
body[data-state="paused"] #hud { display: flex; }

.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}
.hud-label {
  color: var(--ink-dim);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}
.hud-row > :last-child {
  color: var(--led);
  font-size: 16px;
  text-shadow: 0 0 6px rgba(255, 90, 58, 0.5);
}

/* ===== PAUSE PILL ===== */
#pause-pill {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 10;
  background: #000;
  color: var(--led);
  font-weight: 900;
  font-size: 11px;
  letter-spacing: 0.2em;
  padding: 6px 10px;
  border: 2px solid var(--led);
  display: none;
  animation: blink 1s steps(2) infinite;
}
body[data-state="paused"] #pause-pill { display: block; }
@keyframes blink { 50% { opacity: 0.2; } }

/* ===== MILE BANNER ===== */
#banner {
  position: fixed;
  top: 38%;
  left: 0;
  right: 0;
  z-index: 20;
  pointer-events: none;
  text-align: center;
  display: none;
}
#banner.show { display: block; animation: bannerIn 3.6s ease-out forwards; }
#banner .banner-text {
  display: inline-block;
  background: #000;
  color: var(--lane);
  font-family: "Impact", "Arial Black", system-ui, sans-serif;
  font-weight: 900;
  font-size: clamp(28px, 9vw, 56px);
  letter-spacing: 0.06em;
  padding: 14px 28px;
  border: 4px solid var(--lane);
  box-shadow: 6px 6px 0 var(--asphalt-dark);
  transform: skewX(-8deg);
  white-space: nowrap;
}
#banner .banner-sub {
  display: block;
  margin-top: 8px;
  color: #fff;
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: clamp(11px, 3vw, 14px);
  letter-spacing: 0.2em;
  text-shadow: 2px 2px 0 #000;
}
@keyframes bannerIn {
  0%   { transform: translateX(-110vw); opacity: 0; }
  18%  { transform: translateX(0);      opacity: 1; }
  84%  { transform: translateX(0);      opacity: 1; }
  100% { transform: translateX(110vw);  opacity: 0; }
}

/* ===== PANELS ===== */
.panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  background: rgba(28, 28, 28, 0.86);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.panel[hidden] { display: none; }

.panel-inner {
  background: var(--asphalt-dark);
  border: 4px solid #000;
  box-shadow: 8px 8px 0 #000, 0 0 0 2px var(--lane) inset;
  padding: 28px 22px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}

.title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-bottom: 18px;
  font-family: "Impact", "Arial Black", sans-serif;
  letter-spacing: 0.04em;
  line-height: 1;
}
.t-row {
  display: inline-block;
  background: var(--lane);
  color: #1a1a1a;
  font-weight: 900;
  font-size: clamp(26px, 8vw, 38px);
  padding: 6px 14px 4px;
  transform: skewX(-8deg);
  border: 3px solid #000;
  box-shadow: 4px 4px 0 #000;
}
.t-row-2 { background: var(--cone); color: #fff; }
.title.small .t-row { font-size: clamp(20px, 6vw, 28px); padding: 5px 12px 3px; }

.pitch {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  margin: 0 0 22px;
}
.pitch strong { color: var(--lane); font-weight: 900; }
.pitch .warn { color: var(--warn); font-style: italic; }
.pitch .muted { color: var(--ink-dim); font-size: 13px; }

button {
  font-family: "Impact", "Arial Black", sans-serif;
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 0.14em;
  color: #fff;
  background: var(--runner);
  border: 3px solid #000;
  box-shadow: 5px 5px 0 #000;
  padding: 14px 32px;
  cursor: pointer;
  text-transform: uppercase;
  transition: transform 60ms ease, box-shadow 60ms ease;
  -webkit-tap-highlight-color: transparent;
}
button:active {
  transform: translate(3px, 3px);
  box-shadow: 2px 2px 0 #000;
}
button.secondary {
  background: #2a2a2a;
  color: var(--ink);
  font-size: 14px;
  padding: 10px 18px;
  box-shadow: 4px 4px 0 #000;
  margin-top: 10px;
}

.legend {
  margin-top: 16px;
  font-size: 10px;
  color: var(--ink-dim);
  letter-spacing: 0.1em;
}

.resume-stats,
.quit-stats {
  font-family: "Courier New", monospace;
  font-weight: 900;
  font-size: 18px;
  color: var(--led);
}
.resume-stats .muted,
.quit-stats .muted {
  color: var(--ink-dim);
  font-weight: 400;
  font-size: 12px;
}
.resume-note {
  margin: -10px 0 14px;
  color: var(--grass);
  letter-spacing: 0.08em;
}
.quit-warn {
  font-size: 13px;
  margin-bottom: 18px;
}
.quit-warn .warn { font-style: normal; font-weight: 900; letter-spacing: 0.04em; }
.quit-warn .muted { color: var(--ink-dim); font-size: 11px; letter-spacing: 0.12em; }

/* ===== PERSISTENT QUIT BUTTON (in-race) ===== */
#btn-quit {
  position: fixed;
  bottom: max(14px, env(safe-area-inset-bottom));
  right: max(14px, env(safe-area-inset-right));
  z-index: 50;
  display: none;
  font-family: "Courier New", ui-monospace, monospace;
  font-weight: 900;
  font-size: 11px;
  letter-spacing: 0.22em;
  padding: 8px 12px;
  background: #000;
  color: var(--led);
  border: 2px solid var(--led);
  box-shadow: 3px 3px 0 #000;
  text-shadow: 0 0 6px rgba(255, 90, 58, 0.5);
  /* The button sits in the thumb's scroll zone. Without this, a flick that
     starts on the button can be captured as a tap gesture, killing both
     the scroll and any race momentum that came with it. */
  touch-action: manipulation;
}
body[data-state="running"] #btn-quit,
body[data-state="paused"] #btn-quit { display: block; }
#btn-quit:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 #000;
}

/* ===== DNF / QUITTER BIB ===== */
.bib.dnf {
  background: #d8cfb8;
  position: relative;
  overflow: hidden;
}
.bib.dnf::before, .bib.dnf::after { background: #1a1a1a; }
.bib-top.dnf-top {
  color: var(--runner-dark);
  letter-spacing: 0.28em;
}
.bib.dnf .bib-num { color: #555; text-decoration: line-through; text-decoration-thickness: 4px; }
.bib.dnf .bib-time { color: var(--runner-dark); font-size: 38px; }
.bib-stamp {
  position: absolute;
  top: 36%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-14deg);
  color: rgba(208, 50, 40, 0.62);
  font-family: "Impact", "Arial Black", sans-serif;
  font-weight: 900;
  font-size: 52px;
  letter-spacing: 0.14em;
  border: 5px solid rgba(208, 50, 40, 0.62);
  padding: 6px 14px;
  pointer-events: none;
  white-space: nowrap;
}
#btn-dnf-share { background: var(--runner-dark); }

/* ===== FINISH / BIB ===== */
.panel-inner.finish {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  max-width: 420px;
}

.bib {
  background: var(--paper);
  color: #1a1a1a;
  border: 4px solid #000;
  box-shadow: 8px 8px 0 #000;
  padding: 20px 22px 16px;
  text-align: center;
  font-family: "Impact", "Arial Black", system-ui, sans-serif;
  position: relative;
}
.bib::before, .bib::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  background: #1a1a1a;
  border-radius: 50%;
  transform: translateY(-50%);
}
.bib::before { left: -8px; }
.bib::after  { right: -8px; }

.bib-top {
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--bib-blue);
  font-weight: 900;
}
.bib-num {
  font-size: 64px;
  line-height: 1;
  margin: 4px 0 4px;
  color: var(--runner);
  letter-spacing: 0.06em;
}
.bib-event {
  font-size: 18px;
  letter-spacing: 0.14em;
  font-weight: 900;
}
.bib-distance {
  font-family: "Courier New", monospace;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: #555;
  margin-top: 2px;
}
.bib-rule {
  height: 3px;
  background: #1a1a1a;
  margin: 12px 0;
}
.bib-time-label {
  font-size: 10px;
  letter-spacing: 0.3em;
  color: #555;
}
.bib-time {
  font-family: "Courier New", monospace;
  font-weight: 900;
  font-size: 44px;
  letter-spacing: 0.04em;
  color: #1a1a1a;
  line-height: 1;
  margin-top: 2px;
}
.bib-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
  font-family: "Courier New", monospace;
  font-size: 13px;
  font-weight: 900;
  color: #1a1a1a;
}
.bib-stats .muted {
  font-family: "Impact", sans-serif;
  font-weight: 400;
  font-size: 9px;
  letter-spacing: 0.22em;
  color: #777;
}
.bib-sus {
  margin-top: 12px;
  padding: 6px 8px;
  background: #1a1a1a;
  color: var(--warn);
  font-family: ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.18em;
  font-weight: 900;
  border: 2px dashed var(--warn);
}
.bib-footer {
  margin-top: 12px;
  font-family: "Courier New", monospace;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: #888;
}

.finish-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 18px;
}
#btn-share {
  background: var(--grass);
}

/* ===== Scoreboard — bib-stub results sheet ===== */
.scoreboard {
  background: var(--paper);
  color: #1a1a1a;
  border: 4px solid #000;
  box-shadow: 8px 8px 0 #000;
  margin-top: 16px;
  padding: 14px 18px 16px;
  font-family: "Courier New", monospace;
  text-align: left;
}
.scoreboard__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-family: "Impact", "Arial Black", sans-serif;
  font-size: 12px;
  letter-spacing: 0.22em;
  color: var(--bib-blue);
  border-bottom: 2px dashed #1a1a1a;
  padding-bottom: 8px;
}
.scoreboard__status {
  color: var(--runner);
  font-size: 10px;
  letter-spacing: 0.18em;
}
.scoreboard__list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 2px;
}
.scoreboard__row,
.scoreboard__empty {
  display: grid;
  grid-template-columns: 2.4rem 1fr 6rem;
  gap: 8px;
  align-items: baseline;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.06em;
  padding: 3px 2px;
  border-bottom: 1px dotted #c8bfa6;
}
.scoreboard__row span:first-child { color: #888; font-size: 11px; }
.scoreboard__row span:last-child { text-align: right; font-family: "Courier New", monospace; }
.scoreboard__row.is-current {
  background: var(--warn);
  border-bottom-color: #1a1a1a;
}
.scoreboard__empty {
  grid-template-columns: 1fr;
  text-align: center;
  color: #888;
  border-bottom: none;
  font-style: italic;
}
.initials-form {
  margin-top: 10px;
  border-top: 2px dashed #1a1a1a;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.initials-form[hidden] { display: none; }
.initials-form label {
  font-family: "Impact", "Arial Black", sans-serif;
  font-size: 11px;
  letter-spacing: 0.22em;
  color: var(--bib-blue);
  text-align: center;
}
.initials-form__row {
  display: flex;
  gap: 8px;
}
.initials-form input {
  flex: 1;
  background: #fff;
  border: 2px solid #1a1a1a;
  padding: 8px 12px;
  font-family: "Courier New", monospace;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
  color: #1a1a1a;
  min-width: 0;
}
.initials-form input:focus { outline: 2px solid var(--runner); outline-offset: 1px; }
.initials-form__save {
  margin-top: 0;
  padding: 8px 14px;
  font-size: 13px;
}
.initials-form__skip {
  align-self: center;
  margin-top: 6px;
  background: none;
  border: none;
  padding: 4px 8px;
  font-family: "Courier New", monospace;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
  text-decoration: underline;
  cursor: pointer;
  min-height: 0;
}
.initials-form__skip:hover {
  background: none;
  color: var(--ink);
}

/* ===== CONFETTI ===== */
#confetti {
  position: fixed;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  display: none;
}
#confetti.active { display: block; }

#bloff-back { z-index: 200 !important; }

@media (prefers-reduced-motion: reduce) {
  #banner.show { animation-duration: 1.2s; }
  #pause-pill { animation: none; }
}
