:root {
  color-scheme: dark;
  --bg: #101314;
  --ink: #f7f3e8;
  --muted: #aab8b2;
  --line: rgba(247, 243, 232, 0.16);
  --panel: rgba(18, 23, 24, 0.94);
  --store-blue: #0476d9;
  --store-blue-dark: #063a79;
  --store-blue-light: #54c7ff;
  --claim: #58d68d;
  --trail: #ffd166;
  --danger: #ff5d73;
  --water: #3bb7ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 16%, rgba(84, 199, 255, 0.2), transparent 28%),
    radial-gradient(circle at 84% 14%, rgba(4, 118, 217, 0.18), transparent 30%),
    linear-gradient(150deg, #071e3a 0%, #0b315f 48%, #081624 100%);
  color: var(--ink);
  touch-action: none;
  user-select: none;
}

button {
  font: inherit;
}

.shell {
  position: relative;
  display: grid;
  width: 100vw;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  place-items: center;
}

.game {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  width: min(100%, 520px);
  height: min(100dvh - 24px, 920px);
  min-height: 560px;
}

.topbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  gap: 10px;
}

.metric {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.18);
}

.metric.center {
  text-align: center;
}

.metric.right {
  text-align: right;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 1px;
  font-size: clamp(1.12rem, 4dvh, 1.65rem);
  line-height: 1;
}

.board-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    #12191a;
  background-size: 24px 24px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 18px 45px rgba(0, 0, 0, 0.3);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.toast {
  position: absolute;
  left: 50%;
  top: 45%;
  transform: translate(-50%, -50%) scale(0.96);
  color: var(--trail);
  font-size: 1.35rem;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}

.toast.show {
  animation: toastRise 820ms ease-out;
}

.bottombar {
  display: grid;
  width: min(100%, 390px);
  margin: 0 auto;
  grid-template-columns: 40px 40px 1fr 58px 58px 58px 40px 40px 1fr;
  grid-template-rows: repeat(2, 36px);
  justify-content: center;
  align-items: stretch;
  gap: 6px;
}

.dir,
.bomb,
.sound,
.pause,
.rules,
.primary-button {
  border: 0;
  border-radius: 8px;
  color: #111314;
  cursor: pointer;
  font-weight: 900;
}

.dir {
  width: 100%;
  min-height: 36px;
  background: var(--water);
  box-shadow: 0 8px 22px rgba(59, 183, 255, 0.2);
  font-size: 1.25rem;
}

.dir-stack {
  display: grid;
  grid-column: 5;
  grid-row: 1 / span 2;
  grid-template-rows: 1fr 1fr;
  gap: 6px;
}

#rulesButton {
  grid-column: 1;
}

#soundButton {
  grid-column: 2;
}

#leftButton {
  grid-column: 4;
}

#rightButton {
  grid-column: 6;
}

#bombButton {
  grid-column: 7;
}

#pauseButton {
  grid-column: 8;
}

#leftButton,
#rightButton,
.bomb,
.sound,
.pause,
.rules {
  min-height: 78px;
}

#leftButton,
#rightButton,
.sound,
.bomb,
.pause,
.rules {
  grid-row: 1 / span 2;
}

.pause {
  background: var(--trail);
  box-shadow: 0 8px 22px rgba(255, 209, 102, 0.2);
}

.bomb {
  background: var(--danger);
  box-shadow: 0 8px 22px rgba(255, 93, 115, 0.2);
}

.sound {
  background: var(--store-blue-light);
  box-shadow: 0 8px 22px rgba(84, 199, 255, 0.2);
  font-size: 1.2rem;
}

.rules {
  background: rgba(247, 243, 232, 0.16);
  color: var(--ink);
  font-size: 0.72rem;
  box-shadow: inset 0 0 0 1px var(--line);
}

.primary-button {
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  padding: 0 18px;
  background: var(--store-blue-light);
  box-shadow: 0 10px 28px rgba(84, 199, 255, 0.24);
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(7, 9, 10, 0.64);
  backdrop-filter: blur(10px);
}

.overlay.show {
  display: flex;
}

.panel {
  width: min(100%, 365px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
}

.overlay.home-mode .panel {
  width: min(100%, 560px);
  border-color: rgba(84, 199, 255, 0.36);
  background:
    linear-gradient(180deg, rgba(4, 118, 217, 0.24), rgba(6, 58, 121, 0.12)),
    rgba(8, 24, 44, 0.96);
}

.kicker {
  margin: 0 0 6px;
  color: var(--store-blue-light);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 12dvw, 4rem);
  line-height: 0.94;
}

.panel p:not(.kicker) {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.score-form {
  margin-top: 16px;
}

.score-form label,
.home-scores h2 {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.initials-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 7px;
}

.initials-row input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: inherit;
  font-size: 1.2rem;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.city-input {
  width: 100%;
  min-height: 46px;
  margin-top: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0 12px;
}

.small-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--trail);
  color: #111314;
  cursor: pointer;
  font-weight: 900;
}

.high-score {
  min-height: 1.35em;
  font-weight: 800;
}

.rules-list {
  margin: 14px 0 0;
  padding-left: 1.1rem;
  color: var(--muted);
  line-height: 1.35;
}

.rules-list li {
  margin: 8px 0;
}

.home-scores {
  margin-top: 16px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.06);
}

.home-scores h2 {
  margin: 0 0 8px;
}

.home-scores ol {
  margin: 0;
  padding-left: 0;
  list-style-position: inside;
  font-variant-numeric: tabular-nums;
}

.home-scores li {
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 800;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-scores[hidden],
.arcade-button[hidden],
.store-button[hidden] {
  display: none;
}

.secondary-button,
.primary-button,
.arcade-button,
.store-button {
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.secondary-button[hidden] {
  display: none;
}

.primary-button {
  border: 0;
  background: var(--store-blue-light);
  color: #111314;
  box-shadow: 0 10px 28px rgba(84, 199, 255, 0.24);
}

.arcade-button {
  margin-top: 10px;
  border-color: rgba(84, 199, 255, 0.48);
  background: rgba(84, 199, 255, 0.34);
}

.store-button {
  margin-top: 10px;
  border-color: rgba(84, 199, 255, 0.42);
  background: rgba(84, 199, 255, 0.14);
}

@keyframes toastRise {
  0% {
    opacity: 0;
    transform: translate(-50%, -20%) scale(0.9);
  }
  22% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -86%) scale(1.1);
  }
}

@media (max-height: 620px) {
  .game {
    min-height: 0;
    gap: 8px;
  }

  .metric {
    padding: 7px 8px;
  }

  .metric strong {
    font-size: 1.04rem;
  }
}

.pause-action-row {
  display: contents;
}

.pause-action-row:has(> button:not([hidden]) + button:not([hidden])) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.pause-action-row:has(> button:not([hidden]) + button:not([hidden])) > button {
  width: 100% !important;
  min-width: 0;
  margin-top: 0 !important;
  margin-right: 0 !important;
}
.arcade-store-arcade-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.22em;
  width: 100%;
  margin: 0 0 14px;
  border: 2px solid #1266ff;
  background: #ffffff;
  color: #071225;
  box-shadow: 0 0 0 2px rgba(18, 102, 255, 0.16), 0 8px 20px rgba(18, 102, 255, 0.2);
  text-transform: none;
}

.arcade-store-arcade-button span:nth-child(2) {
  color: #1266ff;
  text-transform: uppercase;
}

.arcade-store-arcade-button:hover,
.arcade-store-arcade-button:focus-visible {
  background: #ffffff;
  color: #071225;
  outline: 3px solid rgba(84, 199, 255, 0.55);
  outline-offset: 3px;
}
/* Shared 3D arcade button polish. */
.arcade-store-arcade-button {
  gap: 0;
  border: 2px solid #1266ff;
  background: linear-gradient(180deg, #ffffff 0%, #f2f8ff 44%, #d4e8ff 100%);
  color: #071225;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.95), inset 0 -4px 0 rgba(18,102,255,.2), 0 8px 20px rgba(18,102,255,.22);
  text-shadow: 0 1px 0 rgba(255,255,255,.8);
}

.arcade-store-arcade-button .bleep-blue,
.arcade-store-arcade-button span:nth-child(2) {
  color: #1266ff;
  text-transform: uppercase;
}

.arcade-store-arcade-button:hover,
.arcade-store-arcade-button:focus-visible {
  background: linear-gradient(180deg, #ffffff 0%, #eaf4ff 42%, #bfdcff 100%);
  color: #071225;
  outline: 3px solid rgba(84,199,255,.58);
  outline-offset: 3px;
}

.primary-button {
  background: linear-gradient(180deg, color-mix(in srgb, var(--blue, #54c7ff) 34%, #fff) 0%, var(--blue, #54c7ff) 52%, color-mix(in srgb, var(--blue, #54c7ff) 72%, #071225) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.42), inset 0 -4px 0 rgba(5,10,24,.22), 0 8px 18px rgba(0,0,0,.26);
}

.secondary-button,
.small-button {
  background: linear-gradient(180deg, color-mix(in srgb, var(--yellow, #ffd166) 34%, #fff) 0%, var(--yellow, #ffd166) 54%, color-mix(in srgb, var(--yellow, #ffd166) 72%, #8a5a00) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.48), inset 0 -4px 0 rgba(89,51,0,.22), 0 7px 16px rgba(0,0,0,.24);
}

.store-button,
.buy-button {
  background: linear-gradient(180deg, rgba(255,255,255,.2) 0%, rgba(255,255,255,.1) 50%, rgba(5,10,24,.22) 100%);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.2), inset 0 -4px 0 rgba(5,10,24,.22), 0 7px 16px rgba(0,0,0,.22);
}
/* Compact high-score entry row: Initials, City, Save. */
.score-form {
  display: grid;
  grid-template-columns: minmax(4.2rem, 4.9rem) minmax(0, 1fr) auto;
  gap: 6px 8px;
  align-items: end;
}

.score-form label[for="initialsInput"] {
  grid-column: 1;
  grid-row: 1;
}

.score-form label[for="cityInput"] {
  grid-column: 2;
  grid-row: 1;
}

.initials-row {
  display: contents;
}

.initials-row input,
#initialsInput {
  grid-column: 1;
  grid-row: 2;
  width: 4.8rem;
  min-width: 0;
  text-align: center;
}

.city-input,
#cityInput {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
}

.initials-row button,
.score-form button[type="submit"] {
  grid-column: 3;
  grid-row: 2;
  min-width: 4.1rem;
  padding-inline: 10px;
}

.score-form datalist {
  display: none;
}

.score-form .high-score,
#highScoreText {
  grid-column: 1 / -1;
}
/* Keep the Arcade return button visible on initials/end-game overlays. */
.overlay {
  align-items: flex-start !important;
  overflow: auto !important;
  padding-top: max(10px, env(safe-area-inset-top)) !important;
  padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
}

.panel {
  max-height: calc(100dvh - 20px) !important;
}

.arcade-store-arcade-button {
  position: sticky;
  top: 0;
  z-index: 5;
}
