:root {
  color-scheme: dark;
  --ink: #211c28;
  --paper: #ffecd5;
  --signal: #d2e998;
  --line: #625368;
  font: 16px/1.5 system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--ink); color: var(--paper); }
a { color: inherit; }
button { font: inherit; cursor: pointer; color: inherit; }
:focus-visible { outline: 3px solid #fff2a1; outline-offset: 3px; }
.quarry, .field-guide, footer { width: min(1760px, calc(100% - 64px)); margin-inline: auto; }
.home { background: #2b222e; }
.quarry {
  --rail: clamp(172px, 15vw, 244px);
  --quarry-gap: clamp(14px, 1.65vw, 28px);
  display: grid; grid-template-columns: var(--rail) minmax(0, 1fr);
  grid-template-areas: "mast mast" "rail field";
  column-gap: var(--quarry-gap); padding-bottom: 36px;
}
.masthead {
  grid-area: mast; display: grid; grid-template-columns: var(--rail) minmax(0, 1fr);
  column-gap: var(--quarry-gap); align-items: end; min-height: 82px;
}
h1, .site-mark { margin: 0; font: 950 clamp(1.7rem, 3.5vw, 3rem)/.95 system-ui, sans-serif; letter-spacing: -.065em; }
.masthead .site-mark {
  grid-area: 1 / 2; justify-self: start; z-index: 2; position: relative; margin-bottom: -10px;
  margin-left: -10px; padding: 8px 18px 10px 12px; display: flex; align-items: center; gap: 10px;
  background: #453244; color: var(--paper); border-left: 4px solid var(--signal); box-shadow: 4px 4px 0 #1b1522b8;
}
.site-mark svg { flex: none; width: clamp(24px, 2.2vw, 36px); height: auto; color: var(--signal); }
.site-mark small { display: block; font-size: .875rem; line-height: 1; letter-spacing: .045em; margin-top: 5px; color: #f0ccd1; }
.manual-link {
  grid-area: 1 / 1; justify-self: start; margin-bottom: 5px; text-underline-offset: .28em;
  color: var(--signal); font-weight: 750; font-size: .9rem; white-space: nowrap; min-height: 44px;
  display: inline-flex; align-items: center;
}
.run-rail { grid-area: rail; display: flex; flex-direction: column; min-width: 0; }
.rail-record, .rail-target { padding: 15px 13px 15px 0; border-top: 1px solid #826879; }
.rail-target { border-top: 2px solid #aebf7e; }
.run-rail h2 { margin: 0 0 5px; font-size: .875rem; font-weight: 750; color: #f2cdbd; }
.run-rail p { margin: 0; }
#record-kind { color: #ecd4e4; font-size: .875rem; }
#record-value { font-size: clamp(1.3rem, 1.9vw, 1.9rem); line-height: 1.2; font-weight: 850; letter-spacing: -.05em; }
#next-goal { color: var(--signal); font-weight: 760; }
.rail-map { margin-top: auto; border-bottom: 1px solid #826879; color: #f2cdbd; font-size: .875rem; }
.rail-map svg { display: block; width: 100%; }
.rail-map span { display: block; padding-block: 4px 7px; }
.map-rock { fill: #583d50; }
.map-road { fill: none; stroke: #c6938b; stroke-width: 2; }
.map-gate { fill: none; stroke: var(--signal); stroke-width: 2; }
.game-slot { grid-area: field; min-width: 0; height: clamp(410px, 79dvh, 930px); }

#game {
  --field-inset: 18px;
  --field-top: max(var(--field-inset), env(safe-area-inset-top));
  --field-left: max(var(--field-inset), env(safe-area-inset-left));
  --field-right: max(var(--field-inset), env(safe-area-inset-right));
  --field-button: 46px;
  position: relative; isolation: isolate; overflow: hidden; width: 100%; height: 100%;
  border: 1px solid #746279; background: #e4c4d9; box-shadow: 0 8px 0 #16121b;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#game:focus-visible { outline-offset: -3px; }
#game:fullscreen { position: fixed; inset: 0; width: 100%; height: 100%; border: 0; box-shadow: none; }
#game.fullscreen-fallback { position: fixed; inset: 0; width: 100%; height: 100dvh; border: 0; box-shadow: none; z-index: 10; }
html.fullscreen-lock { overflow: hidden; overscroll-behavior: none; }
#game canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hud { position: absolute; inset: var(--field-top) calc(var(--field-right) + var(--field-button) + 6px) auto var(--field-left); display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.route-meter { width: min(270px, 100%); background: #26202e; color: var(--paper); padding: 9px 11px 10px; border-left: 3px solid #d5eaa5; box-shadow: 0 3px 0 #251e3040; }
.route-readout { display: flex; justify-content: space-between; gap: 7px; align-items: center; font-size: .85rem; font-weight: 740; }
.route-readout output { font: 800 1rem/1 ui-monospace, monospace; color: var(--signal); }
#clock { margin-left: auto; font-size: .78rem; color: #f4dce6; white-space: nowrap; }
.route-readout output:empty { display: none; }
.route-bar { height: 5px; background: #6a5a70; margin-top: 6px; position: relative; }
.route-bar i { display: block; height: 100%; width: 0%; background: var(--signal); transition: width 150ms linear; }
.route-bar b { position: absolute; top: -1px; bottom: -1px; width: 2px; background: #26202e; left: 29.6%; }
.route-bar b:last-child { left: 63.5%; }
#game[data-mode="tutorial"] .route-bar { display: none; }
#game[data-mode="tutorial"] .route-meter { width: auto; }
#hud-target { display: none; margin: 6px 0 0; color: var(--signal); font-size: .875rem; font-weight: 740; }
#game[data-fullscreen="true"] #hud-target { display: block; }
.field-button {
  height: var(--field-button); min-width: var(--field-button); padding: 0 10px; display: flex; gap: 8px;
  align-items: center; justify-content: center; background: #26202e; color: var(--paper);
  border: 1px solid #6c5a73; font-weight: 750;
}
.field-button:hover { background: #44354b; }
.pause-button > :first-child { color: var(--signal); font-size: 1.05rem; }
.fullscreen-button { position: absolute; top: var(--field-top); right: var(--field-right); z-index: 1; color: var(--signal); }
.fullscreen-button svg { width: 23px; height: 23px; flex: none; }
.collapse-icon, #game[data-fullscreen="true"] .expand-icon { display: none; }
#game[data-fullscreen="true"] .collapse-icon { display: inline; }

#pedals {
  position: absolute; right: var(--field-right); bottom: max(20px, env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(2, minmax(100px, 126px)); gap: 8px;
}
#pedals button {
  min-height: 63px; display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid #a491a6; box-shadow: 0 5px 0 #191520; background: #312738; font-weight: 830;
  -webkit-tap-highlight-color: transparent; transition: box-shadow 110ms, filter 110ms;
}
#pedals button[data-pedal="1"] { background: var(--signal); color: #24261b; border-color: #e6f4bf; }
#pedals button.pressed { box-shadow: inset 0 3px 0 #191520, 0 2px 0 #191520; filter: brightness(.81); }
#pedals button[data-pedal="-1"].pressed { background: #834639; border-color: #fac1a5; }
.pedal-icon { font: 700 1.8rem/.7 system-ui, sans-serif; }
#key-guide { position: absolute; left: 24px; bottom: 25px; display: flex; align-items: center; gap: 5px; color: #fff1de; font-size: .875rem; }
kbd { display: inline-grid; min-width: 25px; height: 25px; place-content: center; background: #372b42; color: #fff1de; border: 1px solid #ab91ab; font: 700 .78rem/1 ui-monospace, monospace; }
#key-guide span { margin-left: 5px; }
#lesson { position: absolute; top: calc(var(--field-top) + 61px); left: var(--field-left); display: flex; align-items: center; gap: 9px; max-width: min(320px, calc(100% - var(--field-left) - var(--field-right))); color: var(--paper); background: #363043; padding: 8px 11px; }
#lesson p { margin: 0; font-weight: 650; font-size: .92rem; }
.lesson-mark { flex: 0 0 20px; text-align: center; color: #292131; background: #f6d69f; font: 900 1rem/1.25 system-ui, sans-serif; }

#overlay { position: absolute; inset: 0; display: flex; justify-content: flex-end; align-items: flex-start; padding: max(6.7vh, var(--field-top)) max(7%, calc(var(--field-right) + 52px)) max(18px, env(safe-area-inset-bottom)) var(--field-left); pointer-events: none; }
.board {
  position: relative; width: min(360px, 100%); pointer-events: auto; background: #292232; color: var(--paper);
  padding: 19px 22px 22px; border: 1px solid #7d677d; box-shadow: 7px 8px 0 #31223650;
}
.board-rim { height: 6px; position: absolute; top: -1px; left: -1px; right: -1px; background: repeating-linear-gradient(128deg, #d2e998 0 11px, #2a2730 11px 22px); }
#board-label { margin-top: 4px; color: var(--signal); font: 800 .78rem/1.2 ui-monospace, monospace; letter-spacing: .12em; text-transform: uppercase; }
.board h2 { margin: 12px 0 8px; font: 950 clamp(2.4rem, 5vw, 4.7rem)/.9 system-ui, sans-serif; letter-spacing: -.054em; }
.board p { margin: 0 0 16px; font-size: .95rem; color: #f6e0d1; font-weight: 570; }
#game #result-note { margin: 12px 0 0; color: var(--signal); font-size: .875rem; }
.board-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.board button, #replay-ui button { min-height: 44px; min-width: 44px; padding: 7px 13px; font-weight: 800; border: 1px solid #a58ba4; background: #3a2f43; }
.board button:hover, #replay-ui button:hover { filter: brightness(1.15); }
.board .primary { display: inline-flex; gap: 12px; align-items: center; justify-content: center; min-width: 124px; min-height: 49px; background: var(--signal); color: #26291b; border: 1px solid #e8f4c9; box-shadow: 0 3px 0 #17141e; }
.board button:active, #replay-ui button:active { transform: translateY(2px); }
#game:not([data-mode="menu"]) #overlay { padding-top: max(5vh, var(--field-top)); }
#game:not([data-mode="menu"]) .board h2 { font-size: clamp(2rem, 4.8vw, 3.15rem); }
#options { margin-top: 13px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
#options button { display: grid; gap: 2px; justify-items: start; align-content: center; padding: 5px 6px; font-size: .875rem; line-height: 1.1; color: #fdf2e8; }
#options .option-state { font: 750 .72rem/1 ui-monospace, monospace; color: #e5c7d7; }
#options button[aria-pressed="true"] .option-state { color: var(--signal); }
#options button, .board h2, .replay-caption strong, #route { overflow-wrap: anywhere; hyphens: auto; }

#game[data-replay="true"] { display: grid; grid-template-rows: minmax(0, 1fr) auto; }
#game[data-replay="true"] canvas { position: relative; min-height: 0; }
#replay-ui {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: clamp(8px, 2vw, 22px); align-items: center;
  padding: 7px max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: #292232; border-top: 2px solid var(--signal);
}
.replay-readout { width: min(660px, 100%); }
.replay-caption { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; }
#replay-time { font: 700 .85rem/1.5 ui-monospace, monospace; }
#pedal-trace { position: relative; display: flex; height: 24px; margin: 3px 0 4px; border-block: 1px solid #7b667e; background: #42364b; }
#pedal-trace i { position: relative; flex-basis: 0; }
#pedal-trace i::after { content: ''; position: absolute; inset: 48% 0; background: #baa3b6; }
#pedal-trace i[data-pedal="1"]::after { inset: 10% 0 53%; background: var(--signal); }
#pedal-trace i[data-pedal="-1"]::after { inset: 53% 0 10%; background: #f3b4a1; }
#pedal-trace::after { content: ''; position: absolute; inset-block: -2px; left: clamp(0px, var(--playhead, 0%), calc(100% - 2px)); width: 2px; background: #fff5dc; }
.trace-legend { display: flex; flex-wrap: wrap; gap: 0 9px; font-size: .75rem; }
.trace-legend span::before { content: ''; display: inline-block; margin-right: 4px; width: 7px; height: 7px; background: var(--signal); }
.trace-legend span:nth-child(2)::before { background: #baa3b6; }
.trace-legend span:nth-child(3)::before { background: #f3b4a1; }
#replay-ui button { max-width: 115px; padding-inline: 8px; font-size: .85rem; }

.guide-ground { background: #f2dfc5; color: #382736; }
.field-guide { padding: 31px 0 34px; max-width: 1220px; }
.field-guide h1, .field-guide h2, .legal h1 { font-weight: 900; letter-spacing: -.045em; font-size: clamp(1.8rem, 4vw, 3.3rem); line-height: 1; }
.field-guide p, .field-guide li, .legal p { max-width: 69ch; }
.legal p { color: #f0dfeb; }
.field-guide li + li { margin-top: 10px; }
.field-guide li::marker { color: #70463b; font-weight: 750; }
.guide-lead { border-top: 1px solid #967360; padding-top: 12px; }
.guide-back { display: inline-flex; align-items: center; min-height: 44px; color: #443d25; font-weight: 720; text-underline-offset: .25em; }
.guide-ground :focus-visible, .guide-ground :focus { outline-color: #543445; }
.guide-lead h1 { margin: 12px 0; }
.guide-columns { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: clamp(32px, 7vw, 108px); padding-top: 12px; }
.guide-columns h2 { font-size: clamp(1.55rem, 2.5vw, 2.25rem); }
.guide-columns section + section { margin-top: 28px; }
.guide-columns h3 { font-size: 1rem; margin-bottom: 2px; }
.guide-columns h3 + p { margin-top: 0; }
.legal { width: min(70ch, calc(100% - 36px)); margin: 25px auto 55px; }
.legal h1 { margin: 24px 0 20px; }
.legal h2 { margin: 24px 0 6px; font-size: 1.2rem; }
.legal a, footer a { text-underline-offset: .25em; }
footer { border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; justify-content: space-between; padding: 12px 0 22px; color: #ddcbdb; font-size: .88rem; }
footer nav { display: flex; flex-wrap: wrap; gap: 17px; }
footer a { display: inline-flex; min-height: 44px; min-width: 44px; align-items: center; }
.quarry-footer {
  width: 100%; display: block; border: 0; padding: 0; background: #f2dfc5; color: #2b222e;
}
.quarry-silhouette { display: block; width: 100%; height: clamp(70px, 10vw, 138px); }
.footer-inner {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 24px;
  padding: 12px max(16px, calc((100% - 1220px) / 2)) 25px; background: #2b222e; color: #f2dfc5;
}
.footer-inner > span { font-weight: 760; }
.footer-inner summary { padding-block: 11px; min-height: 44px; color: var(--signal); cursor: pointer; }
.footer-inner ul { margin: 0; padding-left: 17px; }
.footer-inner a span { margin-inline-start: .35em; }

@media (max-width: 760px), (max-width: 920px) and (max-height: 525px) {
  .quarry, .field-guide, footer:not(.quarry-footer) { width: calc(100% - 20px); }
  .quarry { grid-template-columns: minmax(0, 1fr); grid-template-areas: "mast" "field" "rail"; padding-bottom: 16px; }
  .masthead { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; min-height: 64px; }
  .masthead .site-mark { grid-area: 1 / 1; margin-left: 0; font-size: 1.72rem; gap: 7px; padding: 6px 12px 8px 8px; }
  .site-mark small { font-size: .875rem; letter-spacing: 0; margin-top: 4px; }
  .manual-link { grid-area: 1 / 2; justify-self: end; margin-bottom: 0; padding-inline: 5px; }
  .game-slot { height: max(360px, 77dvh); }
  #game { --field-inset: 12px; }
  #hud-target { display: block; }
  .pause-label { display: none; }
  #pedals { bottom: max(14px, env(safe-area-inset-bottom)); grid-template-columns: repeat(2, minmax(91px, 101px)); }
  #pedals button { min-height: 66px; padding: 0 5px; font-size: .92rem; }
  #overlay, #game:not([data-mode="menu"]) #overlay { padding: calc(var(--field-top) + var(--field-button) + 5px) var(--field-right) max(12px, env(safe-area-inset-bottom)) var(--field-left); }
  .board { width: min(275px, 100%); padding: 15px 16px 15px; }
  .board h2 { margin-top: 10px; font-size: clamp(2.45rem, 10vw, 3.5rem); }
  #game:not([data-mode="menu"]) .board h2 { font-size: clamp(1.95rem, 8vw, 2.55rem); }
  #game .board p { margin-bottom: 12px; }
  #options button { padding-inline: 4px; font-size: .8125rem; }
  #key-guide { display: none; }
  .run-rail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); gap: 14px; margin: 19px 3px 0; }
  .rail-record, .rail-target { padding-block: 8px; }
  .rail-map { display: none; }
  .field-guide { padding-inline: 7px; }
  .guide-columns { grid-template-columns: 1fr; gap: 5px; }
}

@media (max-height: 525px) and (orientation: landscape) {
  .masthead { min-height: 49px; }
  .masthead .site-mark { font-size: 1.65rem; padding-block: 5px 7px; }
  .game-slot { height: max(230px, 81dvh); }
  #game { --field-inset: 12px; }
  #overlay, #game:not([data-mode="menu"]) #overlay { padding-top: var(--field-top); padding-right: calc(var(--field-right) + 52px); }
  .board { padding: 11px 13px; width: min(345px, 70%); }
  #game .board h2 { font-size: 2rem; margin: 5px 0; }
  #game .board h2 br { display: none; }
  .board p { margin-bottom: 7px; }
  #options { margin-top: 6px; }
  #lesson { top: calc(var(--field-top) + 51px); }
  #pedals { bottom: max(11px, env(safe-area-inset-bottom)); }
  #pedals button { min-height: 50px; }
}

@media (pointer: coarse) { #key-guide { display: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0ms !important; } }
#game[data-reduced="true"] * { transition-duration: 0ms !important; }
