@import url("https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Nunito:wght@600;700;800;900&display=swap");

:root {
  color-scheme: dark;
  --navy: #102b46;
  --blue: #163b60;
  --panel: #1d4b72;
  --cream: #fff3d2;
  --yellow: #ffcc47;
  --orange: #f27b48;
  --mint: #58d5b3;
  --mono: "DM Mono", monospace;
  --round: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  padding: 28px 20px 20px;
  color: var(--cream);
  background-color: var(--navy);
  background-image: radial-gradient(#315477 1px, transparent 1px);
  background-size: 20px 20px;
  font-family: var(--round);
}
body.modal-open { overflow: hidden; }

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.page-shell { width: min(1120px, 100%); margin: 0 auto; }
.masthead { display: flex; align-items: center; gap: 15px; margin: 0 0 25px 4px; }
.brand-mark { display: grid; width: 58px; height: 58px; place-content: center; border: 3px solid var(--cream); border-radius: 17px; color: var(--navy); background: var(--yellow); font-size: 22px; font-weight: 900; line-height: 1; transform: rotate(-5deg); box-shadow: 4px 4px 0 #071b2f; }
.brand-mark span { display: inline; color: var(--orange); }
.eyebrow { margin: 0 0 3px; color: #a7c3d6; font: 10px var(--mono); letter-spacing: 1.6px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(24px, 4vw, 36px); font-weight: 900; letter-spacing: -1.5px; line-height: 1; }
h1 span { color: var(--yellow); }
.header-badge { margin-left: auto; padding: 7px 10px; border: 1px dashed #6e8da7; border-radius: 8px; color: #a7c3d6; font: 9px var(--mono); line-height: 1.45; text-align: center; transform: rotate(4deg); }
.header-badge strong { color: var(--yellow); font-size: 15px; }
.install-button { margin-left: auto; padding: 10px 13px; border: 1px solid #6c9caa; border-radius: 9px; color: #eafff6; background: #286d77; cursor: pointer; font: 700 10px var(--mono); letter-spacing: .4px; white-space: nowrap; }
.install-button:hover { background: #358b89; }
.install-button:not([hidden]) + .header-badge { display: none; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 265px; align-items: start; gap: 20px; }
.game-column { min-width: 0; }
.scorebar { display: grid; grid-template-columns: 1fr 1.15fr 1fr .75fr; min-height: 65px; padding: 10px 18px; border: 2px solid #39678c; border-bottom: 0; border-radius: 13px 13px 0 0; background: #1a4267; }
.score-block { display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.score-block + .score-block { padding-left: 18px; border-left: 1px solid #39678c; }
.score-label { color: #a8c1d2; font: 9px var(--mono); letter-spacing: 1px; }
.score-block strong { overflow: hidden; color: white; font: 700 16px var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.score-current { text-align: center; }
.score-current strong { color: var(--yellow); font-size: 21px; letter-spacing: 2px; }
.score-block:last-child { align-items: flex-end; text-align: right; }
.score-lives strong { display: flex; gap: 2px; color: #ff8872; font: 700 16px var(--round); letter-spacing: 0; }
.life-heart.lost { color: #70869a; }
.cabinet-screen { position: relative; overflow: hidden; border: 2px solid #39678c; background: #9ce0d4; aspect-ratio: 900 / 510; }
#game-canvas { display: block; width: 100%; height: 100%; }
.screen-overlay { position: fixed; z-index: 1000; inset: 0; display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); background: rgb(10 31 51 / 82%); overscroll-behavior: contain; }
.hidden { display: none; }
.dialog-card { width: min(390px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 23px 26px 19px; border: 3px solid var(--cream); border-radius: 16px; color: var(--navy); background: #fff4d9; text-align: center; box-shadow: 0 7px 0 rgb(9 29 47 / 35%); }
.dialog-icon { display: block; margin-bottom: 5px; font-size: 32px; }
.dialog-card .eyebrow { color: #648096; }
.dialog-card h2 { margin: 4px 0 8px; color: var(--blue); font-size: clamp(30px, 5vw, 43px); font-weight: 900; letter-spacing: -2px; line-height: .96; }
.dialog-copy { margin: 0 auto 15px; color: #526f83; font-size: 13px; font-weight: 700; }
.dialog-copy strong { color: var(--orange); font-size: 22px; }
.dialog-card label { display: block; margin-bottom: 5px; color: #526f83; font: 10px var(--mono); letter-spacing: 1px; text-align: left; }
.name-row { display: flex; gap: 7px; }
.name-row input { min-width: 0; flex: 1; padding: 11px 10px; border: 2px solid #c5d6d8; border-radius: 8px; outline: none; color: var(--navy); background: white; font-size: 14px; }
.name-row input:focus { border-color: #45b99b; box-shadow: 0 0 0 3px rgb(69 185 155 / 18%); }
.button { border: 0; border-radius: 9px; color: #14324b; cursor: pointer; font-family: var(--round); font-weight: 900; transition: filter .12s, transform .12s; touch-action: manipulation; }
.button:hover { filter: brightness(1.08); }
.button:active { transform: translateY(2px); }
.button:focus-visible { outline: 3px solid white; outline-offset: 3px; }
.button-start { padding: 11px 15px; background: var(--yellow); box-shadow: 0 3px 0 #d9a62f; white-space: nowrap; }
.keyboard-hint { margin: 12px 0 0; color: #7890a0; font: 9px var(--mono); }
.game-over-card { width: min(360px, 100%); }
.game-over-card h2 { color: #ed7445; font-size: clamp(30px, 5vw, 40px); }
.game-over-card .button { margin-top: 7px; }
.save-status { min-height: 16px; margin: -7px 0 2px; color: #597b8a; font-size: 11px; font-weight: 700; }
.save-status.error { color: #bd4d37; }
.toast { position: absolute; top: 14px; left: 50%; padding: 8px 14px; border: 1px solid #fff4d9; border-radius: 99px; color: #173c58; background: #fff4d9; font-size: 12px; font-weight: 900; opacity: 0; pointer-events: none; transform: translate(-50%, -8px); transition: opacity .16s, transform .16s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

.controls-row { display: flex; min-height: 145px; flex-direction: column; align-items: center; justify-content: center; gap: 13px; padding: 14px; border: 2px solid #39678c; border-top: 0; border-radius: 0 0 13px 13px; background: #1a4267; }
.control-instructions { display: grid; grid-template-columns: 10px auto; align-items: center; justify-content: center; gap: 0 8px; margin: 0; color: #f1f5e8; font: 11px var(--mono); letter-spacing: .5px; text-align: center; }
.control-instructions small { grid-column: 1 / -1; margin-top: 5px; color: #9db8cb; font: 11px var(--round); letter-spacing: 0; }
.status-light { width: 9px; height: 9px; border-radius: 50%; background: #7d9bac; box-shadow: 0 0 0 3px rgb(125 155 172 / 17%); }
.status-light.open { background: #52ecc1; box-shadow: 0 0 10px #52ecc1; }
.water-buttons { display: flex; gap: 8px; }
.water-buttons { justify-content: center; gap: 12px; width: min(100%, 440px); }
.water-buttons .button { min-width: 0; min-height: 62px; flex: 1; padding: 15px 20px; border-radius: 13px; font-size: 17px; letter-spacing: .5px; }
.button-open { background: #56dfb4; box-shadow: 0 3px 0 #249a7c; }
.button-close { color: #fff1d2; background: #d26952; box-shadow: 0 3px 0 #93473b; }
.mobile-hint { display: none; }

.leaderboard { overflow: hidden; border: 2px solid #39678c; border-radius: 13px; background: #1a4267; }
.leaderboard-heading { display: flex; align-items: center; gap: 11px; padding: 17px 17px 14px; border-bottom: 1px solid #39678c; }
.trophy { font-size: 28px; }
.leaderboard-heading .eyebrow { color: #9db8cb; }
.leaderboard-heading h2 { margin: 0; color: var(--yellow); font-size: 23px; font-weight: 900; letter-spacing: 1px; line-height: 1; }
.score-list { display: grid; gap: 0; min-height: 320px; margin: 0; padding: 7px 16px; list-style: none; }
.score-list li { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 7px; min-height: 31px; border-bottom: 1px dashed #345b7a; font-size: 12px; }
.score-list li:last-child { border-bottom: 0; }
.rank { color: #86a6bb; font: 10px var(--mono); }
.score-list li:nth-child(-n+3) .rank { color: var(--yellow); }
.score-player { overflow: hidden; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.score-value { color: #61ddba; font: 11px var(--mono); }
.empty-score { display: flex !important; grid-template-columns: none !important; justify-content: center; color: #abc0d0; font-size: 12px !important; }
.leaderboard-foot { padding: 11px 6px; border-top: 1px solid #39678c; color: #9db8cb; font: 8px var(--mono); letter-spacing: .8px; text-align: center; }
.leaderboard-foot span { color: var(--yellow); }
footer { display: flex; justify-content: space-between; padding: 17px 4px 0; color: #7794ac; font: 8px var(--mono); letter-spacing: 1px; }

@media (max-width: 760px) {
  body { padding: 18px 12px 14px; }
  .masthead { margin-bottom: 18px; }
  .brand-mark { width: 49px; height: 49px; font-size: 19px; }
  .game-layout { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .leaderboard { grid-row: 2; }
  .score-list { grid-template-columns: 1fr 1fr; column-gap: 13px; min-height: auto; }
  .leaderboard-heading { padding: 12px 15px; }
  .leaderboard-foot { padding: 9px 5px; }
  .mobile-hint { display: block; margin: 7px 0 0; color: #9db8cb; font-size: 11px; text-align: center; }
}

@media (max-width: 480px) {
  body { padding: 13px 8px 12px; }
  .masthead { gap: 10px; margin: 0 3px 13px; }
  .brand-mark { width: 42px; height: 42px; border-radius: 13px; font-size: 17px; }
  .eyebrow { font-size: 8px; letter-spacing: 1px; }
  h1 { font-size: 26px; }
  .header-badge { padding: 5px 7px; font-size: 8px; }
  .install-button { margin-left: auto; padding: 7px 8px; font-size: 8px; }
  .install-button + .header-badge { margin-left: 0; }
  .scorebar { min-height: 57px; padding: 7px 9px; }
  .score-block + .score-block { padding-left: 8px; }
  .score-label { font-size: 7px; letter-spacing: .5px; }
  .score-block strong { font-size: 12px; }
  .score-current strong { font-size: 17px; }
  .score-lives strong { gap: 0; font-size: 13px; }
  .controls-row { min-height: 130px; gap: 10px; padding: 10px 8px; }
  .control-instructions { gap: 0 6px; font-size: 9px; }
  .control-instructions small { font-size: 9px; }
  .water-buttons { width: min(100%, 390px); gap: 9px; }
  .water-buttons .button { min-height: 58px; padding: 12px 9px; font-size: 15px; }
  .dialog-card { padding: 15px 15px 13px; }
  .dialog-icon { font-size: 25px; }
  .dialog-card h2 { font-size: 31px; }
  .dialog-copy { margin-bottom: 10px; font-size: 11px; }
  .keyboard-hint { margin-top: 9px; font-size: 7px; }
  .score-list { column-gap: 8px; padding: 7px 10px; }
  .score-list li { grid-template-columns: 20px minmax(0, 1fr) auto; gap: 5px; font-size: 11px; }
  footer { font-size: 7px; letter-spacing: .4px; }
}

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