:root {
  --ink: #17253a;
  --paper: #fff9df;
  --track: #d75b3f;
  --track-dark: #9e382c;
  --yellow: #ffd83d;
  --blue: #1769aa;
  --sky: #9adcf0;
  --grass: #3f9b5f;
  --white: #fffdf3;
  --shadow: #0f2638;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: #17354b; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.035) 0 2px, transparent 2px 28px),
    #17354b;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", system-ui, sans-serif;
  overflow-x: hidden;
}

button { font: inherit; }
button:focus-visible { outline: 4px solid #101010; outline-offset: 3px; }

.stadium-shell {
  width: min(1100px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--paper);
  border-inline: 5px solid var(--ink);
  position: relative;
  overflow: hidden;
}

.scoreboard {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 9px 16px;
  color: var(--white);
  background: var(--ink);
  border-bottom: 6px solid var(--yellow);
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 900; letter-spacing: .02em; }
.brand-mark {
  display: grid; place-items: center;
  width: 36px; height: 36px;
  color: var(--ink); background: var(--yellow);
  border: 3px solid var(--white);
  transform: rotate(-4deg);
  font: 900 22px/1 Georgia, serif;
}
.scoreboard-values { display: flex; justify-content: center; gap: 18px; margin-left: auto; }
.scoreboard-values span { white-space: nowrap; font-size: .9rem; }
.scoreboard-values b { color: var(--yellow); font-size: 1.12rem; }
.sound-button {
  min-height: 42px;
  border: 2px solid var(--white);
  color: var(--white); background: transparent;
  padding: 6px 11px;
  cursor: pointer;
  font-weight: 800;
}

.screen { display: none; }
.screen.active { display: block; }

.start-screen {
  min-height: calc(100vh - 70px);
  background:
    linear-gradient(#fff8d5 0 54%, transparent 54%),
    repeating-linear-gradient(0deg, #cb563d 0 46px, #f5e8c0 46px 49px);
  position: relative;
  padding: clamp(28px, 6vw, 72px);
}
.start-screen::before {
  content: ""; position: absolute; inset: 0 0 auto; height: 48%;
  background: repeating-linear-gradient(100deg, transparent 0 100px, rgba(23,37,58,.06) 100px 103px);
  pointer-events: none;
}
.start-track { height: 200px; position: relative; max-width: 760px; margin: 0 auto 22px; }
.finish-post { position: absolute; top: 0; width: 15px; height: 170px; background: var(--ink); }
.finish-post.left { left: 7%; transform: rotate(-3deg); }
.finish-post.right { right: 7%; transform: rotate(3deg); }
.finish-post::before {
  content: ""; position: absolute; top: 8px; left: 12px; width: 72px; height: 52px;
  background: conic-gradient(#fff 25%, #17253a 0 50%, #fff 0 75%, #17253a 0) 0/26px 26px;
  border: 3px solid var(--ink);
}
.finish-post.right::before { left: auto; right: 12px; }
.start-ruler {
  position: absolute; left: 18%; right: 18%; bottom: 38px; height: 70px;
  display: flex; justify-content: space-between; align-items: flex-end;
  padding: 0 5px 5px;
  background: var(--yellow); border: 5px solid var(--ink);
  box-shadow: 9px 9px 0 rgba(23,37,58,.18);
  transform: rotate(-1deg);
}
.start-ruler i { width: 3px; height: 24px; background: var(--ink); }
.start-ruler span, .start-ruler b { font-weight: 900; }
.start-runner { left: 46%; bottom: 105px; animation: runner-bob .45s infinite alternate ease-in-out; }
.start-copy { position: relative; max-width: 760px; margin: 0 auto; text-align: center; }
.eyebrow { margin: 0 0 8px; color: var(--track-dark); font-weight: 900; letter-spacing: .13em; }
.start-copy h1 { margin: 0; font-size: clamp(2.3rem, 8vw, 5.2rem); line-height: 1; letter-spacing: -.07em; }
.start-copy h1 span { display: inline-block; color: var(--track-dark); transform: rotate(-3deg); border-bottom: 10px solid var(--yellow); }
.start-copy > p:not(.eyebrow) { font-size: clamp(1rem, 2.5vw, 1.35rem); font-weight: 700; }
.quick-guide { max-width: 640px; margin: 18px auto 0; line-height: 1.7; }

.main-button {
  min-width: min(360px, 90%);
  min-height: 58px;
  padding: 13px 22px;
  color: var(--white); background: var(--blue);
  border: 4px solid var(--ink);
  box-shadow: 7px 7px 0 var(--ink);
  font-weight: 900; font-size: 1.1rem;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.main-button:hover { transform: translate(3px,3px); box-shadow: 4px 4px 0 var(--ink); }

.race-world { position: relative; min-height: 380px; background: var(--sky); overflow: hidden; }
.race-world::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 53%;
  background: var(--grass); border-top: 6px solid var(--ink);
}
.crowd { height: 95px; display: flex; justify-content: space-around; align-items: end; padding: 0 4%; }
.crowd i { width: 34px; height: 52px; background: #ee8a4b; border: 3px solid var(--ink); border-radius: 50% 50% 8px 8px; transform: rotate(5deg); }
.crowd i:nth-child(3n) { height: 65px; background: #7868b7; transform: rotate(-7deg); }
.crowd i:nth-child(2n) { background: #f5c34f; }
.course-caption {
  position: absolute; z-index: 4; top: 12px; left: 50%; transform: translateX(-50%);
  display: grid; justify-items: center; gap: 1px;
  width: min(560px, calc(100% - 32px));
  padding: 8px 16px;
  color: var(--white); background: var(--ink);
  border: 4px solid var(--white);
  box-shadow: 5px 5px 0 rgba(23,37,58,.25);
}
.course-caption strong { font-size: clamp(1.05rem, 3vw, 1.55rem); }
.course-caption em { color: var(--yellow); font-style: normal; font-size: 1.15em; }
.course-caption > span { font-size: .8rem; font-weight: 800; }
.track-scene {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: 36px; height: 175px;
  background: var(--track); border-block: 5px solid var(--ink);
}
.track-lanes { position: absolute; inset: 0; background: repeating-linear-gradient(0deg, transparent 0 52px, #f5e8c0 52px 57px); }
.finish-line { position: absolute; right: 4%; top: 0; bottom: 0; width: 35px; background: conic-gradient(#fff 25%, #17253a 0 50%, #fff 0 75%, #17253a 0) 0/28px 28px; border-inline: 3px solid var(--ink); }
.gap-zone {
  position: absolute; left: 58%; top: -2px; width: 19%; height: 178px;
  background: #17354b; border-inline: 5px dashed var(--yellow);
  display: grid; place-items: center; color: var(--white);
}
.gap-zone b { z-index: 2; padding: 4px 7px; color: var(--yellow); background: var(--ink); font-size: clamp(.8rem, 2vw, 1.05rem); }
.gap-arrow { position: absolute; left: 8px; right: 8px; top: 28px; border-top: 4px solid var(--white); }
.gap-arrow::before, .gap-arrow::after { content: ""; position: absolute; top: -8px; width: 12px; height: 12px; border-top: 4px solid var(--white); }
.gap-arrow::before { left: 0; border-left: 4px solid var(--white); transform: rotate(-45deg); }
.gap-arrow::after { right: 0; border-right: 4px solid var(--white); transform: rotate(45deg); }
.placed-bridge { display: none; position: absolute; z-index: 4; left: 57.4%; top: 72px; height: 42px; width: 20%; background: var(--yellow); border: 5px solid var(--ink); transform-origin: left; }
.placed-bridge.show { display: block; animation: bridge-drop .35s cubic-bezier(.2,.9,.25,1.25); }

.runner { position: absolute; z-index: 5; width: 52px; height: 83px; left: 8%; bottom: 48px; transition: left .65s cubic-bezier(.2,.75,.25,1); }
.runner .head { position: absolute; left: 12px; top: 0; width: 31px; height: 31px; border: 4px solid var(--ink); border-radius: 50%; background: #f4b184; }
.runner .head::before { content: ""; position: absolute; left: -8px; top: -5px; width: 38px; height: 15px; background: var(--blue); border: 4px solid var(--ink); border-radius: 70% 20% 0 0; transform: rotate(-7deg); }
.runner .body { position: absolute; left: 12px; top: 29px; width: 32px; height: 34px; background: var(--yellow); border: 4px solid var(--ink); transform: skew(-8deg); }
.runner .leg { position: absolute; top: 58px; left: 13px; width: 8px; height: 25px; background: var(--ink); transform-origin: top; }
.runner .leg.two { left: 35px; transform: rotate(-25deg); }
.runner.running .leg.one { animation: leg-run .22s infinite alternate; }
.runner.running .leg.two { animation: leg-run .22s infinite alternate-reverse; }
.runner.success { left: 88%; animation: runner-bob .25s 2 alternate; }
.runner.stumble { animation: stumble .45s; }

.burst { display: none; position: absolute; z-index: 6; left: 76%; top: 65px; width: 10px; height: 10px; }
.burst.show { display: block; }
.burst i { position: absolute; width: 12px; height: 45px; background: var(--yellow); border: 2px solid var(--ink); transform-origin: 6px 5px; animation: burst .55s ease-out forwards; }
.burst i:nth-child(1) { --r: 0deg; }.burst i:nth-child(2) { --r: 60deg; }.burst i:nth-child(3) { --r: 120deg; }
.burst i:nth-child(4) { --r: 180deg; }.burst i:nth-child(5) { --r: 240deg; }.burst i:nth-child(6) { --r: 300deg; }
.pace-meter { position: absolute; z-index: 5; left: 5%; right: 5%; bottom: 10px; height: 13px; background: #fff; border: 3px solid var(--ink); }
.pace-meter span { display: block; width: 100%; height: 100%; background: var(--yellow); transform-origin: left; }

.measurement-bench { padding: 22px clamp(12px, 4vw, 42px) 34px; background: var(--paper); }
.bench-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; }
.bench-heading h2 { margin: 0; font-size: clamp(1.25rem, 3vw, 1.8rem); }
.bench-heading p { margin: 0; font-size: .9rem; }
.bridge-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 18px; }
.bridge-choice {
  position: relative; min-width: 0; min-height: 130px; padding: 44px 8px 10px;
  color: var(--ink); background: #e8f4f0;
  border: 4px solid var(--ink); cursor: pointer; overflow: hidden;
  box-shadow: 5px 5px 0 rgba(23,37,58,.16);
}
.bridge-choice:hover { background: #fff3aa; }
.bridge-choice[disabled] { cursor: default; opacity: .58; }
.bridge-choice.wrong { background: #ffe2df; }
.bridge-choice.correct { background: #dcf6c9; }
.choice-number { position: absolute; left: 8px; top: 6px; font-weight: 900; font-size: 1.05rem; }
.mini-ruler {
  position: relative; width: calc(100% - 8px); height: 54px; margin: 0 4px;
  background: #fffdf3; border: 3px solid var(--ink); overflow: hidden;
}
.mini-ruler .ticks { position: absolute; inset: 0; }
.mini-ruler .ticks i { position: absolute; top: 0; width: 1px; height: 10px; background: var(--ink); transform: translateX(-.5px); }
.mini-ruler .ticks .half-tick { width: 2px; height: 16px; }
.mini-ruler .ticks .cm-tick { width: 3px; height: 23px; }
.mini-ruler .bridge-bar { position: absolute; left: 0; bottom: 0; height: 24px; background: var(--yellow); border: 3px solid var(--ink); border-left: 0; }
.mini-ruler .cm-labels { position: absolute; inset: 3px 4px auto; display: flex; justify-content: space-between; font: 800 .65rem/1 monospace; }
.bridge-choice small { display: block; margin-top: 7px; font-weight: 800; }
.feedback { min-height: 2em; margin: 18px 0 0; text-align: center; font-weight: 800; line-height: 1.5; }
.feedback.good { color: #14602d; }.feedback.bad { color: #9c251f; }

.quiz-screen, .result-screen { min-height: calc(100vh - 70px); padding: clamp(28px, 6vw, 72px) clamp(18px, 8vw, 100px); text-align: center; background: var(--paper); }
.quiz-screen { background: repeating-linear-gradient(-4deg, #fff9df 0 42px, #f4edcf 42px 44px); }
.quiz-screen h2, .result-screen h2 { margin: 5px 0 22px; font-size: clamp(1.8rem, 5vw, 3rem); }
.quiz-flag { display: grid; grid-template-columns: repeat(4, 46px); width: max-content; margin: 0 auto 22px; border: 4px solid var(--ink); transform: rotate(-2deg); }
.quiz-flag span { width: 46px; height: 32px; background: var(--ink); }
.quiz-flag span:nth-child(even) { background: var(--white); }
.quiz-question { max-width: 760px; margin: 0 auto 20px; font-size: clamp(1.15rem, 3vw, 1.5rem); font-weight: 900; line-height: 1.55; }
.quiz-choices { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; max-width: 760px; margin: 0 auto; }
.quiz-choice { min-height: 58px; padding: 10px; border: 3px solid var(--ink); background: var(--white); color: var(--ink); font-weight: 800; cursor: pointer; }
.quiz-choice.correct { background: #d8f6c6; }.quiz-choice.wrong { background: #ffd9d5; }
.quiz-feedback { min-height: 4.5em; max-width: 760px; margin: 18px auto; font-weight: 700; line-height: 1.6; }

.result-screen { background: radial-gradient(circle at 50% 18%, #fff 0 5%, transparent 5.4%), var(--paper); }
.result-ribbon { width: min(620px, 96%); margin: 0 auto 28px; padding: 9px; color: var(--white); background: var(--track); border: 5px solid var(--ink); font: 900 clamp(1.7rem, 5vw, 3.2rem)/1 Georgia, serif; letter-spacing: .25em; transform: rotate(-2deg); }
.result-score { display: flex; justify-content: center; align-items: baseline; gap: 8px; margin: 10px 0; }
.result-score span { font-weight: 900; }.result-score strong { color: var(--track-dark); font-size: clamp(3rem, 10vw, 6rem); line-height: 1; }.result-score small { font-weight: 900; }
.result-stats { display: grid; grid-template-columns: repeat(4,1fr); max-width: 820px; margin: 25px auto 30px; border: 4px solid var(--ink); }
.result-stats div { padding: 12px 8px; border-right: 3px solid var(--ink); }
.result-stats div:last-child { border-right: 0; }
.result-stats dt { font-size: .82rem; font-weight: 700; }.result-stats dd { margin: 4px 0 0; font-size: 1.25rem; font-weight: 900; }
.leaderboard-panel { max-width: 760px; margin: 35px auto 0; text-align: left; border-top: 5px solid var(--ink); padding-top: 10px; }

@keyframes runner-bob { to { transform: translateY(-7px) rotate(-2deg); } }
@keyframes leg-run { from { transform: rotate(32deg); } to { transform: rotate(-32deg); } }
@keyframes bridge-drop { from { transform: translateY(-80px) rotate(-15deg); opacity: 0; } to { transform: translateY(0) rotate(0); opacity: 1; } }
@keyframes stumble { 25% { transform: rotate(18deg) translateY(8px); } 55% { transform: rotate(-8deg); } }
@keyframes burst { to { transform: rotate(var(--r, 0deg)) translateY(-75px) scale(.2); opacity: 0; } }

@media (max-width: 700px) {
  .stadium-shell { border-inline: 0; }
  .scoreboard { gap: 8px; padding: 7px 8px; flex-wrap: wrap; }
  .brand { font-size: .9rem; }.brand-mark { width: 31px; height: 31px; }
  .scoreboard-values { order: 3; width: 100%; justify-content: space-between; gap: 5px; }
  .sound-button { margin-left: auto; min-height: 38px; font-size: .8rem; }
  .start-screen { min-height: calc(100vh - 105px); padding-inline: 18px; }
  .start-track { height: 170px; }.start-ruler { left: 10%; right: 10%; }.finish-post.left { left: 2%; }.finish-post.right { right: 2%; }
  .race-world { min-height: 335px; }.crowd { height: 80px; }.crowd i { width: 24px; height: 40px; }
  .track-scene { bottom: 34px; height: 150px; }.gap-zone { height: 153px; }.runner { bottom: 38px; transform: scale(.86); transform-origin: bottom left; }
  .placed-bridge { top: 60px; }.burst { top: 55px; }
  .bench-heading { display: block; }.bench-heading p { margin-top: 5px; }
  .bridge-choices { gap: 7px; }.bridge-choice { min-height: 115px; padding-inline: 3px; border-width: 3px; box-shadow: 3px 3px 0 rgba(23,37,58,.16); }
  .mini-ruler { margin-inline: 1px; width: calc(100% - 2px); }.cm-labels { font-size: .55rem !important; }
  .quiz-choices { grid-template-columns: 1fr; }
  .result-stats { grid-template-columns: repeat(2,1fr); }.result-stats div:nth-child(2) { border-right: 0; }.result-stats div:nth-child(-n+2) { border-bottom: 3px solid var(--ink); }
}

@media (max-width: 390px) {
  .brand > span:last-child { max-width: 145px; line-height: 1.1; }
  .course-caption { top: 7px; }.crowd { opacity: .7; }
  .bridge-choice small { font-size: .67rem; }
}

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