.maze-shell { width: min(1080px, calc(100% - 32px)); }

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

.game-heading {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 32px;
  align-items: end;
  padding: 30px 34px;
  border-bottom: 3px solid var(--ink);
}

.game-heading .eyebrow { margin-bottom: 10px; }
.game-heading h1 { max-width: 820px; font-size: clamp(2.35rem, 6.7vw, 4.9rem); line-height: 0.94; }
.lede { max-width: 730px; margin: 18px 0 0; color: var(--muted); font-size: 1rem; line-height: 1.6; }

.progress-box { min-width: 160px; padding: 16px; border: 2px solid var(--line); background: #171220; text-align: center; }
.progress-box > span,
.stat > span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.1em; }
.progress-box strong { color: var(--gold); font-size: 1.55rem; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 3px solid var(--ink); }
.stat { min-width: 0; padding: 18px 12px; border-right: 2px solid var(--line); text-align: center; }
.stat:last-child { border-right: 0; }
.stat strong { font-size: clamp(1.05rem, 3vw, 1.65rem); }

.game-stage {
  --round-window: 1800ms;
  min-height: 755px;
  padding: 30px;
  background:
    linear-gradient(rgba(88, 199, 215, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(88, 199, 215, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 50% 28%, #29203a 0, transparent 57%);
  background-size: 24px 24px, 24px 24px, auto;
}

.prompt-panel { display: flex; min-height: 538px; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.stage-kicker { margin: 0 0 10px; color: var(--gold); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.14em; }
.prompt-panel h2 { margin: 0; font-size: clamp(1.45rem, 4vw, 2.5rem); letter-spacing: -0.04em; }
.prompt-panel > p:not(.stage-kicker, .sr-only) { max-width: 700px; min-height: 46px; margin: 10px 0 8px; color: var(--muted); font-size: 0.95rem; line-height: 1.55; }

.maze-viewport {
  position: relative;
  width: min(700px, 100%);
  height: 310px;
  margin: 0 auto 18px;
  overflow: hidden;
  border: 3px solid var(--ink);
  background:
    linear-gradient(90deg, #261d31 0 17%, transparent 17% 83%, #261d31 83%),
    linear-gradient(180deg, #171220 0 9%, #20313a 9% 100%);
  box-shadow: 7px 7px 0 var(--shadow);
  isolation: isolate;
}

.maze-viewport::before,
.maze-viewport::after { position: absolute; z-index: 1; inset-block: 0; width: 17%; content: ""; background: repeating-linear-gradient(180deg, #3a3047 0 18px, #211a2e 18px 36px); }
.maze-viewport::before { left: 0; border-right: 4px solid #0b0910; }
.maze-viewport::after { right: 0; border-left: 4px solid #0b0910; }

.speed-lines { position: absolute; z-index: 0; inset: 0 17%; overflow: hidden; }
.speed-lines i { position: absolute; left: calc(50% - 2px); width: 4px; height: 42px; background: rgba(248, 241, 223, 0.2); transform: perspective(80px) rotateX(35deg); }
.speed-lines i:nth-child(1) { top: -30px; }
.speed-lines i:nth-child(2) { top: 50px; }
.speed-lines i:nth-child(3) { top: 135px; }
.speed-lines i:nth-child(4) { top: 225px; }
.game-stage[data-state="approach"] .speed-lines i,
.game-stage[data-state="active"] .speed-lines i { animation: floor-run 440ms linear infinite; }

.junction {
  position: absolute;
  z-index: 2;
  top: -48px;
  left: 50%;
  width: 330px;
  height: 228px;
  transform: translateX(-50%) scale(0.58);
  transform-origin: 50% 20%;
}

.road { position: absolute; display: block; border: 4px solid #0b0910; background: #35515a; box-shadow: inset 0 0 0 4px rgba(88, 199, 215, 0.1); }
.road-in { top: 101px; left: 119px; width: 92px; height: 128px; border-top: 0; }
.road-left { top: 70px; left: -2px; width: 147px; height: 72px; border-right: 0; }
.road-straight { top: -2px; left: 119px; width: 92px; height: 105px; border-bottom: 0; }
.road-right { top: 70px; right: -2px; width: 147px; height: 72px; border-left: 0; }
.junction-center { position: absolute; z-index: 2; top: 70px; left: 119px; width: 92px; height: 72px; background: #35515a; }

.star { position: absolute; z-index: 5; display: none; color: var(--gold); font-size: 2.35rem; font-style: normal; line-height: 1; text-align: center; text-shadow: 3px 3px 0 #7a4d10; animation: star-pulse 300ms steps(2, end) infinite; }
.star i { display: block; margin-top: -3px; color: var(--ink); font-size: 1rem; font-style: normal; text-shadow: none; }
.road-left .star { top: 11px; left: 35px; }
.road-straight .star { top: 13px; left: 24px; }
.road-right .star { top: 11px; right: 35px; }
.junction[data-target="left"] .road-left .star,
.junction[data-target="straight"] .road-straight .star,
.junction[data-target="right"] .road-right .star { display: block; }

.wall { position: absolute; z-index: 6; display: grid; place-items: center; border: 4px solid #0b0910; background: repeating-linear-gradient(45deg, #5a405d 0 12px, #32243b 12px 24px); color: #f8f1df; font-size: 2rem; font-weight: 900; }
.wall-left { top: 70px; left: -2px; width: 147px; height: 72px; }
.wall-straight { top: -2px; left: 119px; width: 92px; height: 105px; }
.wall-right { top: 70px; right: -2px; width: 147px; height: 72px; }
.junction[data-open-left="true"] .wall-left,
.junction[data-open-straight="true"] .wall-straight,
.junction[data-open-right="true"] .wall-right { display: none; }

.game-stage[data-state="approach"] .junction { animation: first-approach 620ms linear forwards; }
.game-stage[data-state="active"] .junction { animation: junction-approach var(--round-window) linear forwards; }

.runner { position: absolute; z-index: 8; bottom: 18px; left: 50%; width: 42px; height: 76px; transform: translateX(-50%); }
.runner span { position: absolute; display: block; border: 3px solid #0b0910; }
.runner-head { top: 0; left: 10px; width: 23px; height: 23px; background: var(--gold); box-shadow: inset -4px -4px 0 #c99325; }
.runner-body { top: 23px; left: 3px; width: 36px; height: 31px; background: var(--blue); box-shadow: inset -5px -4px 0 #2a8394; }
.runner-legs { top: 53px; left: 6px; width: 30px; height: 23px; border-top: 0 !important; background: linear-gradient(90deg, var(--red) 0 37%, transparent 37% 63%, var(--red) 63%); }
.game-stage[data-state="approach"] .runner,
.game-stage[data-state="active"] .runner { animation: runner-bob 180ms steps(2, end) infinite; }

.floor-message { position: absolute; z-index: 9; bottom: 10px; left: 14px; padding: 4px 6px; background: #120f1dcc; color: var(--muted); font-size: 0.66rem; font-weight: 900; letter-spacing: 0.09em; }

.timing-wrap { width: min(500px, 94%); margin: 1px auto 11px; }
.timing-wrap[hidden] { display: none; }
.timing-labels { display: flex; justify-content: space-between; margin-bottom: 5px; color: var(--muted); font-size: 0.66rem; font-weight: 900; letter-spacing: 0.08em; }
.timing-wrap .deadline-track { width: 100%; height: 17px; margin: 0; border-width: 3px; }
.timing-wrap .deadline-fill { background: linear-gradient(90deg, var(--green) 0 38%, var(--gold) 67%, var(--red) 100%); transform-origin: left center; }

.result-flash { display: flex; min-height: 40px; margin: 0 0 11px; flex-direction: column; align-items: center; justify-content: center; }
.result-flash[hidden] { display: none; }
.result-flash strong { color: var(--green); font-size: 1.4rem; }
.result-flash[data-kind="wrong"] strong { color: var(--red); }
.result-flash span { color: var(--muted); font-size: 0.8rem; }

.turn-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; max-width: 880px; margin: 15px auto 0; }
.turn-controls button { display: grid; min-width: 0; min-height: 116px; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 14px; border: 3px solid var(--ink); border-radius: 0; background: #231b30; box-shadow: 5px 5px 0 var(--shadow); color: var(--ink); cursor: pointer; touch-action: manipulation; transition: transform 80ms ease, box-shadow 80ms ease, background 100ms ease; }
.turn-controls button:disabled { cursor: default; opacity: 0.5; }
.turn-controls button:not(:disabled):hover { background: #302540; }
.turn-controls button:not(:disabled):active,
.turn-controls button.is-pressed { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--shadow); }
.turn-controls button:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; }
.turn-controls button > span { color: var(--blue); font-size: 2.9rem; font-weight: 900; line-height: 1; }
.turn-controls strong { min-width: 0; font-size: 0.82rem; letter-spacing: 0.06em; overflow-wrap: anywhere; }
.turn-controls small { display: flex; gap: 4px; }
.turn-controls kbd { width: 29px; height: 29px; border-color: var(--line); font-size: 0.7rem; }
.control-note { margin: 18px 0 0; color: var(--muted); font-size: 0.84rem; line-height: 1.5; text-align: center; }

.game-stage[data-state="approach"] .primary-button,
.game-stage[data-state="active"] .primary-button,
.game-stage[data-state="feedback"] .primary-button { visibility: hidden; }
.game-stage[data-state="game-over"] { background-color: #351521; }
.game-stage[data-state="complete"] { background-color: #2d2515; }
.game-stage[data-state="cancelled"] { background-color: #241a31; }

.content-section { display: grid; grid-template-columns: 0.85fr 1.6fr; gap: 64px; padding: 76px 18px 58px; }
.content-section h2,
.info-panel h2,
.faq-section h2,
.related-section h2 { margin: 0; font-size: clamp(1.8rem, 4vw, 3rem); line-height: 1.08; letter-spacing: -0.05em; }
.steps-list { margin: 0; padding: 0; border-top: 2px solid var(--line); list-style: none; }
.steps-list li { display: grid; grid-template-columns: 54px 1fr; gap: 18px; padding: 20px 0; border-bottom: 2px solid var(--line); }
.steps-list span { color: var(--gold); font-weight: 800; }
.steps-list p,
.info-panel p,
.faq-list p { margin: 0; color: var(--muted); font-size: 1rem; line-height: 1.7; }
.reading-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.info-panel { padding: 30px; border: 2px solid var(--line); background: var(--panel); }
.info-panel h2 { margin-bottom: 22px; }
.info-panel > p:not(.section-kicker) + p { margin-top: 16px; }
.faq-section,
.related-section { padding: 72px 18px 0; }
.faq-list { margin-top: 28px; border-top: 2px solid var(--line); }
.faq-list details { border-bottom: 2px solid var(--line); }
.faq-list summary { padding: 22px 44px 22px 0; color: var(--ink); cursor: pointer; font-size: 1.05rem; font-weight: 800; line-height: 1.4; }
.faq-list details p { max-width: 850px; padding: 0 0 24px; }
.related-links { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-top: 28px; }
.related-links a { display: flex; min-width: 0; min-height: 118px; flex-direction: column; justify-content: space-between; padding: 18px; border: 2px solid var(--line); background: var(--panel); color: var(--ink); font-weight: 800; line-height: 1.35; text-decoration: none; overflow-wrap: anywhere; }
.related-links a:hover,
.related-links a:focus-visible { border-color: var(--gold); outline: 0; }
.related-links small { color: var(--muted); font-size: 0.76rem; font-weight: 400; }

@keyframes floor-run { from { transform: translateY(-70px); } to { transform: translateY(70px); } }
@keyframes first-approach { from { transform: translateX(-50%) scale(0.36); } to { transform: translateX(-50%) scale(0.58); } }
@keyframes junction-approach { from { transform: translateX(-50%) scale(0.58); } to { transform: translateX(-50%) translateY(74px) scale(1.12); } }
@keyframes runner-bob { 0%, 49% { transform: translateX(-50%) translateY(0); } 50%, 100% { transform: translateX(-50%) translateY(-4px); } }
@keyframes star-pulse { 0%, 49% { opacity: 0.55; } 50%, 100% { opacity: 1; } }

@media (max-width: 900px) {
  .game-heading { grid-template-columns: 1fr; }
  .progress-box { display: flex; align-items: center; justify-content: space-between; }
  .progress-box > span { margin: 0; }
  .turn-controls button { grid-template-columns: 1fr; gap: 5px; justify-items: center; }
  .turn-controls small { display: none; }
  .related-links { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 650px) {
  .maze-shell { width: min(100% - 18px, 620px); padding-top: 10px; }
  .topbar { align-items: flex-start; gap: 10px; }
  .topbar-meta { max-width: 66%; flex-wrap: wrap; justify-content: flex-end; gap: 6px 9px; }
  .language-chip { margin-left: 0; }
  .best-label,
  #saved-best { display: none; }
  .game-card { box-shadow: 6px 6px 0 var(--shadow); }
  .game-heading { gap: 20px; padding: 24px 18px; }
  .game-heading h1 { font-size: clamp(2.05rem, 11vw, 3.7rem); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(2) { border-right: 0; }
  .stat:nth-child(-n + 2) { border-bottom: 2px solid var(--line); }
  .game-stage { min-height: 740px; padding: 25px 10px 22px; }
  .prompt-panel { min-height: 545px; }
  .maze-viewport { height: 292px; }
  .junction { width: 300px; }
  .road-in { left: 109px; width: 82px; }
  .road-left { width: 135px; }
  .road-straight { left: 109px; width: 82px; }
  .road-right { width: 135px; }
  .junction-center { left: 109px; width: 82px; }
  .wall-left,
  .wall-right { width: 135px; }
  .wall-straight { left: 109px; width: 82px; }
  .turn-controls { gap: 7px; }
  .turn-controls button { min-height: 105px; padding: 10px 6px; }
  .turn-controls button > span { font-size: 2.35rem; }
  .turn-controls strong { font-size: 0.67rem; }
  .content-section,
  .reading-grid { grid-template-columns: 1fr; }
  .content-section { gap: 30px; padding: 58px 8px 44px; }
  .info-panel { padding: 24px 20px; }
  .faq-section,
  .related-section { padding: 58px 8px 0; }
  .related-links { grid-template-columns: 1fr; }
  .related-links a { min-height: 92px; }
}

@media (max-width: 390px) {
  .brand { font-size: 0.8rem; }
  .topbar-meta { max-width: 68%; }
  .topbar-link { font-size: 0.61rem; }
  .maze-viewport { height: 278px; }
  .game-stage { min-height: 720px; }
}

@media (prefers-reduced-motion: reduce) {
  .speed-lines i,
  .junction,
  .runner,
  .star { animation: none !important; }
  .game-stage[data-state="active"] .junction { transform: translateX(-50%) translateY(35px) scale(0.82); }
  .turn-controls button,
  .deadline-fill { transition: none !important; }
}
