:root {
  color-scheme: light;
  --acid: #d8ff3e;
  --acid-soft: #e8ff9b;
  --paper: #f5f8f0;
  --grass: #e1f2c5;
  --ink: #20271c;
  --muted: #68705f;
  --line: color-mix(in oklch, var(--ink) 18%, transparent);
  --coral: #ef7656;
  --blue: #526fd6;
  --pink: #d84c9b;
  --sky: #d9ebc8;
  --track: #f0eee2;
  --track-side: #c8c4ad;
  --display: "Avenir Next Condensed", "Franklin Gothic Condensed", "Trebuchet MS", sans-serif;
  --body: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--acid); }

body {
  margin: 0;
  min-height: 100svh;
  color: var(--ink);
  background: var(--acid);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

.site-header {
  width: min(1440px, calc(100% - clamp(32px, 6vw, 96px)));
  height: 78px;
  margin: 0 auto;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.wordmark, .sound-toggle, .language-toggle, .text-button, .borrow-button {
  border: 0;
  background: transparent;
}

.header-actions { display: flex; align-items: center; gap: 22px; }
.language-toggle {
  padding: 5px 0 3px;
  border-bottom: 1px solid var(--line);
  font-size: .7rem;
  font-weight: 720;
}
.language-toggle:hover { border-color: var(--ink); }

.wordmark {
  padding: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: -.045em;
}

.wordmark span { color: var(--coral); }

.sound-toggle {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 0;
  font-size: .72rem;
  font-weight: 650;
}

.sound-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 0 color-mix(in oklch, var(--ink) 25%, transparent);
  animation: pulse 2s ease-out infinite;
}

.sound-toggle[aria-pressed="false"] .sound-dot { background: var(--muted); animation: none; }

main {
  width: min(1440px, calc(100% - clamp(32px, 6vw, 96px)));
  margin: 0 auto;
}

.draw-screen { padding: clamp(36px, 5vw, 72px) 0 24px; }

.intro-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 30px;
  align-items: end;
  margin-bottom: 30px;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: .71rem;
  font-weight: 650;
  letter-spacing: .01em;
}

h1, h2 {
  font-family: var(--display);
  margin: 0;
  font-weight: 500;
  letter-spacing: -.075em;
  line-height: .82;
}

h1 { font-size: clamp(3.5rem, 7.3vw, 7.6rem); }
h1::first-line { font-weight: 850; }
h1 span { font-weight: 450; }

.side-note {
  margin: 0 2vw 6px 0;
  max-width: 150px;
  font-size: clamp(.74rem, 1vw, .9rem);
  line-height: 1.35;
}

.drawing-board {
  position: relative;
  overflow: hidden;
  border: 1px solid color-mix(in oklch, var(--ink) 20%, transparent);
  border-radius: 3px;
  background: var(--paper);
  box-shadow: 0 5px 0 color-mix(in oklch, var(--ink) 13%, transparent);
}

#drawing-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1000 / 520;
  touch-action: none;
  cursor: crosshair;
}

.canvas-note {
  position: absolute;
  top: 18px;
  z-index: 2;
  pointer-events: none;
  color: var(--muted);
  font-size: .69rem;
}

.canvas-note-left { left: 18px; }
.canvas-note-right { right: 18px; }

.empty-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  pointer-events: none;
  text-align: center;
  color: color-mix(in oklch, var(--ink) 28%, transparent);
  transform: rotate(-2deg);
}

.empty-hint strong { font-size: clamp(.9rem, 1.3vw, 1.1rem); line-height: 1.2; }
.empty-hint span { font-size: 1.4rem; transform: translate(-42px, 2px); }

.drawing-toolbar {
  position: absolute;
  z-index: 3;
  inset: auto 15px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.drawing-toolbar button { pointer-events: auto; }

.palette { display: flex; gap: 8px; align-items: center; }
.color-button {
  width: 17px;
  height: 17px;
  padding: 0;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 1px color-mix(in oklch, var(--ink) 12%, transparent);
}
.color-button[data-color="#20271c"] { --swatch: var(--ink); }
.color-button[data-color="#ef7656"] { --swatch: var(--coral); }
.color-button[data-color="#526fd6"] { --swatch: var(--blue); }
.color-button[data-color="#d84c9b"] { --swatch: var(--pink); }
.color-button.is-active { box-shadow: 0 0 0 2px var(--ink); }

.canvas-actions { display: flex; gap: 16px; }
.canvas-actions button {
  padding: 6px 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: .69rem;
}
.canvas-actions button:hover { color: var(--ink); }

.entry-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 28%);
  gap: clamp(28px, 6vw, 90px);
  align-items: end;
  margin-top: 24px;
}

.name-field { display: grid; gap: 8px; max-width: 390px; }
.name-field span { color: var(--muted); font-size: .68rem; }
.name-field input {
  width: 100%;
  padding: 1px 0 8px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  font-family: var(--display);
  font-size: clamp(1.2rem, 2vw, 1.65rem);
  font-weight: 700;
}

.race-button {
  min-height: 62px;
  padding: 0 22px;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ink);
  color: var(--acid);
  font-weight: 750;
  transition: transform 180ms ease, background 180ms ease, opacity 180ms ease;
}
.race-button:not(:disabled):hover { transform: translateY(-3px); }
.race-button:disabled { opacity: .22; cursor: not-allowed; }
.race-button span { font-size: 1.35rem; }

.borrow-button {
  display: block;
  margin: 26px auto 0;
  padding: 8px 2px 4px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: .69rem;
}
.borrow-button:hover { color: var(--ink); border-color: var(--ink); }

.race-screen { padding: 30px 0 16px; }
.race-heading {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.race-heading .eyebrow { margin-bottom: 4px; }
.race-heading h2 { font-size: clamp(1.8rem, 3vw, 2.7rem); font-weight: 730; line-height: 1; }
.text-button { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .72rem; }

.race-stage {
  position: relative;
  width: 100%;
  height: clamp(500px, calc(100svh - 190px), 720px);
  overflow: hidden;
  border: 1px solid color-mix(in oklch, var(--ink) 16%, transparent);
  background: var(--sky);
  box-shadow:
    0 5px 0 color-mix(in oklch, var(--ink) 14%, transparent),
    0 18px 42px color-mix(in oklch, var(--ink) 8%, transparent);
}

#race-canvas { display: block; width: 100%; height: 100%; }

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-family: var(--display);
  font-size: clamp(9rem, 24vw, 22rem);
  font-weight: 850;
  letter-spacing: -.1em;
  line-height: 1;
  transform: translateY(-2%);
  color: var(--ink);
}
.countdown.is-pop { animation: countPop 720ms cubic-bezier(.2,.8,.2,1) both; }

.leaderboard {
  position: absolute;
  z-index: 4;
  top: 28px;
  right: 28px;
  width: min(195px, 26vw);
  margin: 0;
  padding: 0;
  list-style: none;
}
.leaderboard li {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 32px;
  padding: 5px 8px;
  border-bottom: 1px solid color-mix(in oklch, var(--ink) 9%, transparent);
  background: color-mix(in oklch, var(--paper) 78%, transparent);
  font-size: clamp(.62rem, .9vw, .76rem);
}
.leaderboard li.is-player { background: var(--ink); color: var(--paper); }
.leaderboard .lane-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.leaderboard .rank-distance { font-variant-numeric: tabular-nums; opacity: .65; }

.race-controls {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 18px;
  width: min(340px, calc(100% - 34px));
  transform: translateX(-50%);
}
.progress-copy { display: flex; justify-content: space-between; font-size: .65rem; margin-bottom: 7px; }
.progress-track { height: 2px; background: color-mix(in oklch, var(--ink) 20%, transparent); overflow: hidden; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--ink); transform-origin: left; }
.race-status {
  min-height: 32px;
  margin-top: 8px;
  padding: 0 9px;
  display: grid;
  grid-template-columns: 20px 1fr auto;
  gap: 7px;
  align-items: center;
  border: 1px solid color-mix(in oklch, var(--ink) 19%, transparent);
  background: color-mix(in oklch, var(--paper) 84%, transparent);
  font-size: .65rem;
  font-weight: 680;
  transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}
.race-status[data-kind="buff"] { background: var(--acid); transform: translateY(-1px); }
.race-status[data-kind="debuff"] { background: var(--coral); color: var(--paper); transform: translateY(-1px); }
.status-symbol { font-size: 1rem; text-align: center; }
.race-status b { min-width: 30px; text-align: right; font-variant-numeric: tabular-nums; }
.cheer-button {
  width: 100%;
  min-height: 62px;
  margin-top: 8px;
  padding: 0 18px;
  border: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  color: var(--acid);
  font-family: var(--display);
  font-size: 1.16rem;
  font-weight: 800;
  letter-spacing: -.02em;
}
.cheer-button:disabled { opacity: .55; cursor: default; }
.cheer-button:not(:disabled):active { transform: translateY(2px) scale(.99); }
.cheer-arrow { font-size: 1.4rem; transform: translateY(-1px); }
.cheer-arrow.kick { animation: arrowKick 240ms ease-out; }
.race-controls > p { margin: 8px 0 0; text-align: center; font-size: .62rem; color: var(--muted); }

.result-panel {
  position: absolute;
  z-index: 8;
  top: 50%;
  right: clamp(20px, 7vw, 110px);
  width: min(330px, calc(100% - 40px));
  padding: 26px;
  background: var(--acid);
  box-shadow:
    7px 8px 0 color-mix(in oklch, var(--ink) 26%, transparent),
    17px 20px 34px color-mix(in oklch, var(--ink) 13%, transparent);
  transform: translateY(-48%) rotate(-.4deg);
  animation: panelIn 560ms cubic-bezier(.16,1,.3,1) both;
}
.result-panel > p:first-child { margin: 0 0 5px; font-size: .68rem; font-weight: 650; }
.result-panel > strong {
  display: block;
  font-family: var(--display);
  font-size: clamp(3.4rem, 6vw, 5.2rem);
  letter-spacing: -.08em;
  line-height: .95;
  white-space: nowrap;
}
#result-copy { margin: 8px 0 18px; font-size: .78rem; line-height: 1.45; }
.result-actions { display: grid; }
.result-actions button {
  min-height: 44px;
  padding: 0;
  border: 0;
  border-top: 1px solid color-mix(in oklch, var(--ink) 18%, transparent);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: .76rem;
  font-weight: 650;
}
.result-actions .result-primary { padding: 0 12px; border: 0; background: var(--ink); color: var(--acid); }
.result-actions button:hover span { transform: translateX(3px); }
.result-actions span { transition: transform 150ms ease; }

footer {
  width: min(1440px, calc(100% - clamp(32px, 6vw, 96px)));
  min-height: 68px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: color-mix(in oklch, var(--ink) 58%, transparent);
  font-size: .62rem;
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 24px;
  padding: 11px 16px;
  background: var(--ink);
  color: var(--paper);
  font-size: .75rem;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

[hidden] { display: none !important; }

@keyframes pulse { 60%,100% { box-shadow: 0 0 0 8px transparent; } }
@keyframes countPop { 0% { opacity: 0; transform: scale(.7); } 18% { opacity: 1; transform: scale(1); } 78% { opacity: 1; } 100% { opacity: 0; transform: scale(1.08); } }
@keyframes arrowKick { 50% { transform: translateY(-8px); } }
@keyframes panelIn { from { opacity: 0; transform: translateY(-42%) translateX(45px) rotate(2deg); } to { opacity: 1; transform: translateY(-48%) rotate(-.4deg); } }

@media (max-width: 720px) {
  .site-header { height: 60px; }
  .draw-screen { padding-top: 28px; }
  .intro-row { position: relative; display: block; margin-bottom: 22px; }
  .side-note { position: absolute; top: 0; right: 0; margin: 0; }
  h1 { font-size: clamp(3rem, 13vw, 4rem); }
  .drawing-board { margin-inline: calc((100vw - 100%) / -2); border-left: 0; border-right: 0; }
  .entry-row { grid-template-columns: 1fr; gap: 18px; }
  .race-button { min-height: 58px; }
  .race-screen { padding-top: 12px; }
  .race-heading { min-height: 70px; }
  .race-stage { margin-inline: calc((100vw - 100%) / -2); width: 100vw; height: calc(100svh - 142px); min-height: 530px; }
  .leaderboard { top: 14px; right: 10px; width: 152px; }
  .leaderboard li { min-height: 27px; padding: 3px 6px; }
  .result-panel { top: auto; right: 20px; bottom: 105px; transform: none; }
  .race-controls { bottom: max(13px, env(safe-area-inset-bottom)); }
  .race-status { min-height: 29px; }
  .cheer-button { min-height: 56px; }
  footer { min-height: 56px; }
  .race-screen + footer { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
