: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; }
.scoreboard { display: flex; gap: 24px; text-align: right; font-variant-numeric: tabular-nums; }
.scoreboard span { display: block; color: #6a7890; font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.scoreboard strong { display: block; font-size: 1.6rem; }
.game { position: relative; height: clamp(320px, 42vw, 410px); overflow: hidden; border: 2px solid #dce4ef; border-radius: 22px; background: linear-gradient(#fff 0%, #fdf7ed 100%); touch-action: manipulation; user-select: none; }
.sun { position: absolute; width: 86px; height: 86px; top: 48px; right: 12%; border-radius: 50%; background: #ffe2a7; }
.hills { position: absolute; inset: auto 0 61px; height: 100px; opacity: .5; background: radial-gradient(ellipse 180px 90px at 13% 100%, #d8e9e1 99%, transparent 100%), radial-gradient(ellipse 250px 92px at 72% 100%, #d8e9e1 99%, transparent 100%); }
.ground { position: absolute; inset: auto 0 0; height: 64px; border-top: 4px solid #304d51; background: repeating-linear-gradient(90deg, #e3ebe2 0 24px, #edf1e8 24px 48px); }
.game.custom-background { background-image: var(--custom-background); background-position: center; background-size: contain; background-repeat: no-repeat; background-color: #fdf7ed; }
.game.custom-background.crop-background { background-size: cover; }
.game.custom-background .sun, .game.custom-background .hills { display: none; }
.player.custom-player { mix-blend-mode: normal; }
.player.custom-player img { inset: 0; width: 100%; height: 100%; object-fit: contain; }
.player.custom-player.crop-player img { object-fit: cover; }
.obstacle.custom-obstacle { border: 0; border-radius: 0; background: var(--custom-obstacle) center / 100% 100% no-repeat; }
.game.crop-obstacle .obstacle.custom-obstacle { background-size: cover; }
.obstacle.custom-obstacle::after { display: none; }
.ground.custom-ground { border-top: 0; background: none; overflow: hidden; }
.ground-track { display: flex; width: max-content; height: 100%; transform: translate3d(var(--ground-shift, 0px), 0, 0); }
.ground-tile { flex: 0 0 256px; height: 64px; background: var(--custom-ground) center / 100% 100% no-repeat; }
.ground.crop-ground .ground-tile { background-size: cover; }
.player { position: absolute; left: 80px; bottom: 64px; width: 90px; height: 135px; overflow: hidden; mix-blend-mode: multiply; z-index: 2; will-change: transform; }
.player img { position: absolute; width: 243px; max-width: none; height: auto; left: -70px; top: -9px; pointer-events: none; }
.obstacle { position: absolute; left: 0; bottom: 64px; border: 3px solid #9f4e39; border-bottom: 0; border-radius: 11px 11px 2px 2px; background: linear-gradient(90deg, #e88a64, #c96b4d); z-index: 3; will-change: transform; }
.obstacle::after { content: ""; position: absolute; top: 11px; left: 7px; width: 4px; height: 4px; border-radius: 50%; background: #9f4e39; box-shadow: 10px 12px 0 #9f4e39; }
.game-layout.debug-active { display: block; }
.game-layout .game { min-width: 0; }
.debug-panel { margin-top: 16px; padding: 18px; border: 1px solid #bfd0e3; border-radius: 18px; background: #eaf1fa; font-size: .82rem; font-variant-numeric: tabular-nums; }
.debug-panel[hidden] { display: none; }
.debug-heading { display: flex; align-items: center; gap: 10px; cursor: pointer; list-style: none; }
.debug-heading::-webkit-details-marker { display: none; }
.debug-heading::before { content: ""; width: 8px; height: 8px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); }
.debug-panel[open] .debug-heading::before { transform: rotate(45deg); }
.debug-heading:focus-visible { outline: 2px solid #2855a5; outline-offset: 4px; border-radius: 4px; }
.debug-title { font-size: 1.1rem; font-weight: 700; }
.debug-collapse-label, .debug-expand-label { margin-left: auto; font-size: .75rem; color: #52627b; }
.debug-expand-label, .debug-panel:not([open]) .debug-collapse-label { display: none; }
.debug-panel:not([open]) .debug-expand-label { display: inline; }
.debug-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.debug-actions button { padding: 6px 9px; font-size: .75rem; }
.debug-panel pre { margin: 0; padding: 10px; border-radius: 9px; color: #f8fafc; background: #14213d; font: 11px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; }
.debug-panel fieldset { margin: 10px 0 0; padding: 9px; border: 1px solid #c7d5e5; border-radius: 9px; }
.debug-columns { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(260px, .85fr); gap: 20px; align-items: start; margin-top: 12px; }
.debug-live { position: sticky; top: 16px; }
.debug-live h3 { margin: 0 0 10px; font-size: .95rem; }
@media (max-width: 760px) {
  .debug-columns { grid-template-columns: 1fr; }
  .debug-live { position: static; }
}
.debug-panel legend { padding: 0 4px; font-weight: 700; }
.debug-field { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 7px 0; }
.debug-field span { flex: 1; }
.debug-field input, .debug-field select { width: 88px; min-width: 0; padding: 4px 5px; border: 1px solid #aab7c9; border-radius: 6px; background: white; font: inherit; }
.debug-field select { width: 130px; }
.debug-field #debug-music { width: 170px; }
.debug-field input[type="checkbox"] { width: 18px; height: 18px; accent-color: #2855a5; }
.debug-field input:disabled { opacity: .55; }
.debug-note { margin: 12px 0 0; color: #52627b; line-height: 1.4; }
.setup-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 8px 12px; align-items: center; }
.setup-editor p, .setup-editor .setup-files, .setup-editor .setup-actions { grid-column: 1 / -1; }
.setup-editor p { margin: 2px 0; line-height: 1.4; }
.setup-editor input[type="text"], .setup-editor select { min-width: 0; width: 100%; padding: 7px; }
.setup-files { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 8px; }
.setup-file-card { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; gap: 4px; padding: 8px; border: 1px solid #c7d5e5; border-radius: 8px; background: #fff; overflow-wrap: anywhere; }
.setup-file-card > label:first-child { display: grid; gap: 4px; }
.setup-files small { color: #52627b; }
.setup-files input { width: 100%; min-width: 0; }
.setup-files .setup-fit-choice { display: flex; align-items: flex-start; gap: 5px; line-height: 1.3; }
.setup-fit-choice input { flex: 0 0 auto; width: auto; margin: 2px 0 0; }
.setup-file-name { min-width: 0; overflow-wrap: anywhere; }
.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; }
.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; }
  .game { height: 330px; }
  .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; }
.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; }
@media (max-width: 640px) {
  .name-row { flex-wrap: wrap; }
  .name-row input { flex-basis: 100%; }
  .name-row button { width: 100%; }
}
