:root { color-scheme: light; }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-family: system-ui, sans-serif; color: #14213d; background: #f5f7fb; }
main { width: min(100%, 1060px); margin: 0 auto; padding: clamp(16px, 4vw, 48px); }
nav a { color: #2855a5; }
header { display: flex; justify-content: space-between; gap: 24px; align-items: end; margin: 32px 0 22px; }
.eyebrow { color: #d46543; font-size: .8rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1 { font-size: clamp(2.6rem, 6vw, 4.5rem); line-height: 1; margin: 10px 0; }
header p { color: #52627b; margin: 0; }

button { border: 0; border-radius: 12px; padding: 13px 22px; color: white; background: #2855a5; font: inherit; font-weight: 750; cursor: pointer; }
button:hover, button:focus-visible { background: #183e80; }
.overlay-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; }
.finish-button { color: #9d244a; background: #fce1e9; }
.finish-button:hover, .finish-button:focus-visible { color: #801b3b; background: #f7c8d6; }
.finish-button:focus-visible { outline: 2px solid #9d244a; outline-offset: 2px; }
.controls { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 16px; }
.control-buttons { display: flex; align-items: center; gap: 8px; }
.sound-toggle { display: grid; place-items: center; flex: 0 0 46px; width: 46px; height: 46px; padding: 0; color: #2855a5; background: #e7eefb; }
.sound-toggle:hover, .sound-toggle:focus-visible { color: #183e80; background: #d6e2f8; }
.sound-toggle:focus-visible { outline: 2px solid #183e80; outline-offset: 2px; }
.sound-toggle svg { display: block; width: 24px; height: 24px; }
.sound-toggle .sound-slash { display: none; }
.sound-toggle[aria-pressed="false"] { color: #87909e; background: #e8eaee; }
.sound-toggle[aria-pressed="false"] .sound-waves { display: none; }
.sound-toggle[aria-pressed="false"] .sound-slash { display: initial; }
.sound-toggle[aria-pressed="false"]:hover, .sound-toggle[aria-pressed="false"]:focus-visible { color: #646d7a; background: #dadee4; }
#pause:disabled { opacity: .5; cursor: not-allowed; }
.controls p { flex: 1; min-width: 240px; margin: 0; color: #52627b; }
.game-mode { display: flex; align-items: center; gap: 8px; color: #52627b; font-size: .9rem; }
.game-mode[hidden] { display: none; }
.game-mode select { max-width: 220px; padding: 8px 10px; border: 1px solid #aab7c9; border-radius: 9px; color: #14213d; background: white; font: inherit; }
.game-mode select:disabled { opacity: .6; }
.controls { flex-wrap: wrap; }
@media (max-width: 640px) {
  .overlay-actions button { padding: 13px 12px; font-size: .9rem; }
  header { display: block; }
  .scoreboard { justify-content: flex-start; margin-top: 22px; text-align: left; }
  .controls { flex-wrap: wrap; }
  .controls p { flex-basis: 100%; font-size: .85rem; }
  .game-mode { width: 100%; justify-content: space-between; }
  .game-mode select { flex: 1; }
  .control-buttons { width: 100%; }
  .control-buttons #pause { flex: 1; }
}

.score-form { display: grid; gap: 8px; width: min(100%, 350px); }
.score-form[hidden] { display: none; }
.score-form label { font-weight: 700; }
.name-row { display: flex; gap: 8px; }
.name-row input { min-width: 0; flex: 1; border: 1px solid #aab7c9; border-radius: 10px; padding: 10px 12px; font: inherit; }
.name-row button { padding: 10px 14px; }
.save-status { min-height: 1em; font-size: .85rem; }
.rotate-prompt[hidden], .game-hud { display: none; }
.rotate-prompt { position: absolute; inset: 0; z-index: 9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 20px; text-align: center; background: #fffffff5; overflow-y: auto; }
.rotate-prompt h2 { margin: 0; font-size: clamp(1.5rem, 5vw, 2.2rem); }
.rotate-prompt p { max-width: 460px; margin: 0; line-height: 1.4; }
#fullscreen { width: 46px; height: 46px; padding: 0; background: #e7eefb; color: #2855a5; font-size: 1.6rem; line-height: 1; }
#fullscreen:hover, #fullscreen:focus-visible { background: #d6e2f8; }
body.game-view-active { overflow: hidden; }
.game-layout.immersive { position: fixed; inset: 0; z-index: 1000; width: 100%; height: 100vh; height: 100dvh; margin: 0; background: #fff; overflow: hidden; }
.game-layout.immersive .game { width: 100%; height: 100%; border: 0; border-radius: 0; }
.game-layout.immersive .overlay, .game-layout.immersive .rotate-prompt { justify-content: safe center; }
.game-layout.immersive .game-hud { position: absolute; top: max(8px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); z-index: 8; display: flex; gap: 14px; padding: 5px 8px; border-radius: 8px; background: #ffffffdc; font-size: .8rem; font-weight: 700; pointer-events: none; }
.game-layout.immersive .game-hud strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.game-layout.immersive .controls { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); z-index: 8; display: block; margin: 0; }
.game-layout.immersive .controls > p { display: none; }
.game-layout.immersive .control-buttons { width: auto; }
.game-layout.immersive .control-buttons #pause { flex: none; }
.game-layout.immersive .control-buttons button { min-height: 44px; }
@media (max-width: 600px) {
  .game-layout.immersive .controls { top: auto; bottom: max(8px, env(safe-area-inset-bottom)); }
  .game-layout.immersive .control-buttons #pause { padding: 8px; font-size: .8rem; }
}
.leaderboard { margin-top: 32px; padding: 24px; border: 1px solid #dce4ef; border-radius: 20px; background: white; }
.leaderboard h2 { margin: 0 0 4px; font-size: 1.7rem; }
.leaderboard p { margin: 0 0 18px; color: #52627b; }
.leaderboard ol { margin: 0; padding-left: 2rem; }
.leaderboard li { padding: 9px 0; border-bottom: 1px solid #edf1f6; }
.leaderboard li:last-child { border-bottom: 0; }
.leaderboard li strong { float: right; font-variant-numeric: tabular-nums; }
.leaderboard .empty { list-style: none; margin-left: -2rem; color: #6a7890; }
.leaderboard .leaderboard-gap { list-style: none; margin-left: -2rem; padding: 8px 0; color: #6a7890; font-size: .9rem; text-align: center; }
.leaderboard .current-player { padding: 9px 10px; border-radius: 8px; background: #eaf4ff; font-weight: 600; }
.leaderboard .you-label { color: #175a9b; font-size: .8rem; font-weight: 600; }
@media (max-width: 640px) {
  .name-row { flex-wrap: wrap; }
  .name-row input { flex-basis: 100%; }
  .name-row button { width: 100%; }
}
@media (max-height: 359px) {
  .game-layout.immersive .ground { height: 40px; }
  .game-layout.immersive .player, .game-layout.immersive .obstacle { bottom: 40px; }
}
[hidden] { display: none; }
#audio-trim input { width: 100%; }
#audio-status { min-height: 1.4em; }
.setup-files button { justify-self: start; min-width: 0; max-width: 100%; padding: 8px 10px; white-space: normal; overflow-wrap: anywhere; }
.setup-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.setup-actions button { padding: 8px 10px; }
.setup-actions button:disabled { opacity: .5; cursor: not-allowed; }
#setup-status { min-height: 1.4em; }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 12px; padding: 24px; text-align: center; background: #fffffff0; z-index: 5; }
.overlay[hidden] { display: none; }
.overlay h2 { font-size: clamp(1.7rem, 5vw, 2.5rem); margin: 0; }
.overlay p { color: #52627b; margin: 0 0 10px; }
button { border: 0; border-radius: 12px; padding: 13px 22px; color: white; background: #2855a5; font: inherit; font-weight: 750; cursor: pointer; }
button:hover, button:focus-visible { background: #183e80; }
.controls { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 16px; }
.control-buttons { display: flex; align-items: center; gap: 8px; }
.sound-toggle { display: grid; place-items: center; flex: 0 0 46px; width: 46px; height: 46px; padding: 0; color: #2855a5; background: #e7eefb; }
.sound-toggle:hover, .sound-toggle:focus-visible { color: #183e80; background: #d6e2f8; }
.sound-toggle:focus-visible { outline: 2px solid #183e80; outline-offset: 2px; }
.sound-toggle svg { display: block; width: 24px; height: 24px; }
.sound-toggle .sound-slash { display: none; }
.sound-toggle[aria-pressed="false"] { color: #87909e; background: #e8eaee; }
.sound-toggle[aria-pressed="false"] .sound-waves { display: none; }
.sound-toggle[aria-pressed="false"] .sound-slash { display: initial; }
.sound-toggle[aria-pressed="false"]:hover, .sound-toggle[aria-pressed="false"]:focus-visible { color: #646d7a; background: #dadee4; }
#pause:disabled { opacity: .5; cursor: not-allowed; }
.controls p { flex: 1; min-width: 240px; margin: 0; color: #52627b; }
.game-mode { display: flex; align-items: center; gap: 8px; color: #52627b; font-size: .9rem; }
.game-mode[hidden] { display: none; }
.game-mode select { max-width: 220px; padding: 8px 10px; border: 1px solid #aab7c9; border-radius: 9px; color: #14213d; background: white; font: inherit; }
.game-mode select:disabled { opacity: .6; }
.controls { flex-wrap: wrap; }
@media (max-width: 640px) {
  .overlay-actions button { padding: 13px 12px; font-size: .9rem; }
  header { display: block; }
  .scoreboard { justify-content: flex-start; margin-top: 22px; text-align: left; }
  .controls { flex-wrap: wrap; }
  .controls p { flex-basis: 100%; font-size: .85rem; }
  .game-mode { width: 100%; justify-content: space-between; }
  .game-mode select { flex: 1; }
  .control-buttons { width: 100%; }
  .control-buttons #pause { flex: 1; }
}

.score-form { display: grid; gap: 8px; width: min(100%, 350px); }
.score-form[hidden] { display: none; }
.score-form label { font-weight: 700; }
.name-row { display: flex; gap: 8px; }
.name-row input { min-width: 0; flex: 1; border: 1px solid #aab7c9; border-radius: 10px; padding: 10px 12px; font: inherit; }
.name-row button { padding: 10px 14px; }
.save-status { min-height: 1em; font-size: .85rem; }
.overlay { overflow-y: auto; gap: 9px; }
.rotate-prompt[hidden], .game-hud { display: none; }
.rotate-prompt { position: absolute; inset: 0; z-index: 9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 20px; text-align: center; background: #fffffff5; overflow-y: auto; }
.rotate-prompt h2 { margin: 0; font-size: clamp(1.5rem, 5vw, 2.2rem); }
.rotate-prompt p { max-width: 460px; margin: 0; line-height: 1.4; }
#fullscreen { width: 46px; height: 46px; padding: 0; background: #e7eefb; color: #2855a5; font-size: 1.6rem; line-height: 1; }
#fullscreen:hover, #fullscreen:focus-visible { background: #d6e2f8; }
body.game-view-active { overflow: hidden; }
.game-layout.immersive { position: fixed; inset: 0; z-index: 1000; width: 100%; height: 100vh; height: 100dvh; margin: 0; background: #fff; overflow: hidden; }
.game-layout.immersive .game { width: 100%; height: 100%; border: 0; border-radius: 0; }
.game-layout.immersive .overlay, .game-layout.immersive .rotate-prompt { justify-content: safe center; }
.game-layout.immersive .game-hud { position: absolute; top: max(8px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); z-index: 8; display: flex; gap: 14px; padding: 5px 8px; border-radius: 8px; background: #ffffffdc; font-size: .8rem; font-weight: 700; pointer-events: none; }
.game-layout.immersive .game-hud strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.game-layout.immersive .controls { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); z-index: 8; display: block; margin: 0; }
.game-layout.immersive .controls > p { display: none; }
.game-layout.immersive .control-buttons { width: auto; }
.game-layout.immersive .control-buttons #pause { flex: none; }
.game-layout.immersive .control-buttons button { min-height: 44px; }
@media (max-width: 600px) {
  .game-layout.immersive .controls { top: auto; bottom: max(8px, env(safe-area-inset-bottom)); }
  .game-layout.immersive .control-buttons #pause { padding: 8px; font-size: .8rem; }
}

[hidden] { display: none !important; }
.game-layout { position: relative; }
.adapter-mount { position: relative; }
.shell-actions { position: relative; z-index: 8; display: flex; justify-content: center; gap: 10px; margin-top: 12px; pointer-events: none; }
.game-layout[data-state="running"] .shell-actions { display: none; }
.shell-actions button { pointer-events: auto; }
.shell-error { position: absolute; inset: 0; z-index: 12; padding: 24px; background: #fff; text-align: center; }
.game-layout.immersive .adapter-mount { height: 100%; }
.game-layout.immersive .shell-actions { position: absolute; top: 65%; left: 0; right: 0; margin: 0; }
.game-layout.immersive .debug-panel { display: none; }
.game-layout.immersive .scoreboard { display: none; }
.game-layout.immersive .adapter-mount > .game-hud { display: flex; }


.result-entry { padding: 16px; background: #fff; border: 1px solid #dce4ef; border-radius: 12px; }
.game-visits { margin-top: 24px; color: #52627b; font-size: .9rem; }
.game-visits p { margin: 8px 0; }
.game-visits strong { color: #2855a5; }
.result-entry .score-form { margin: auto; }
.result-entry input { display: block; width: 100%; padding: 8px; font: inherit; }
.game-layout.immersive .result-entry { position: absolute; z-index: 10; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(92%, 420px); max-height: 65%; overflow: auto; }
.game-layout.immersive:has(.result-entry:not([hidden])) .shell-actions { top: auto; bottom: 65px; }

/* Mode selection belongs to the page, outside active or fullscreen play. */
.game-layout.immersive .game-mode,
.game-layout[data-state="running"] .game-mode { display: none; }
