:root {
  color-scheme: dark;
  --bg: #0d1222;
  --ink: #fff8ee;
  --muted: #b9c4d8;
  --line: rgba(255, 255, 255, 0.18);
  --panel: rgba(12, 21, 42, 0.94);
  --blue: #54c7ff;
  --store-blue: #1266ff;
  --yellow: #ffd166;
  --pink: #ff5ca8;
  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 16% 12%, rgba(255, 92, 168, 0.2), transparent 28%),
    radial-gradient(circle at 84% 12%, rgba(84, 199, 255, 0.24), transparent 30%),
    linear-gradient(155deg, #08122d 0%, #102b68 50%, #090f1f 100%);
  color: var(--ink);
  touch-action: none;
  user-select: none;
}

button {
  font: inherit;
}

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

@supports (height: 100dvh) {
  .shell {
    height: 100dvh;
    min-height: 100dvh;
  }
}

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

.brand-header {
  display: grid;
  place-items: center;
  min-height: clamp(30px, 5.8dvh, 50px);
  text-align: center;
}

.match-logo {
  color: transparent;
  font-size: clamp(1.25rem, min(6.1dvw, 4.8dvh), 2.55rem);
  font-weight: 1000;
  line-height: 1;
  background:
    linear-gradient(90deg, #ff5ca8 0%, #ffd166 28%, #42c96d 50%, #54c7ff 74%, #9b7cff 100%);
  background-clip: text;
  -webkit-background-clip: text;
  filter: drop-shadow(0 5px 0 rgba(5, 10, 24, 0.5)) drop-shadow(0 0 16px rgba(84, 199, 255, 0.34));
  letter-spacing: 0;
  text-transform: uppercase;
}

.site-tag {
  margin-top: 1px;
  color: rgba(255, 248, 238, 0.78);
  font-size: clamp(0.68rem, 2.2dvw, 0.88rem);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.topbar,
.bottombar {
  display: grid;
  align-items: center;
  gap: clamp(5px, 1.5dvw, 10px);
}

.topbar {
  grid-template-columns: minmax(98px, 1.25fr) minmax(124px, 1fr) minmax(56px, 0.56fr);
}

.bottombar {
  grid-template-columns: minmax(70px, 1fr) auto auto auto auto;
}

.metric {
  min-width: 0;
  padding: clamp(4px, 1dvh, 7px) clamp(6px, 1.8dvw, 10px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
}

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

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

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

.metric strong {
  display: block;
  margin-top: 1px;
  font-size: clamp(1.15rem, 4dvh, 1.7rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

#target {
  font-size: clamp(0.68rem, 2.25dvh, 0.98rem);
  line-height: 1.08;
}

#score {
  font-size: clamp(1rem, 3.5dvh, 1.55rem);
}

#moves {
  font-size: clamp(1rem, 3.35dvh, 1.45rem);
}

.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.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    rgba(4, 10, 28, 0.8);
  background-size: 34px 34px;
  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%;
}

.game-message-slot {
  display: grid;
  height: clamp(36px, 5.4dvh, 46px);
  padding: 0 6px;
  place-items: center;
  overflow: hidden;
}

.toast {
  position: static;
  width: 100%;
  max-width: 100%;
  padding: 3px 10px;
  border-radius: 8px;
  background: rgba(8, 14, 30, 0.76);
  color: var(--yellow);
  font-size: clamp(0.78rem, min(3.2dvw, 1.8dvh), 1rem);
  font-weight: 950;
  line-height: 1.1;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
  text-wrap: balance;
  transform: translateY(3px) scale(0.98);
}

.toast.pop {
  animation: gameCommentPop 760ms ease-out;
}

.small-button,
.primary-button,
.secondary-button,
.arcade-button,
.store-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 950;
  min-height: 46px;
}

.small-button {
  padding: 0 12px;
  background: var(--yellow);
  color: #121827;
}

.icon-button {
  width: 46px;
  min-width: 46px;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
}

.rules-mini {
  min-width: 52px;
  padding: 0 10px;
  font-size: 0.86rem;
}

.primary-button,
.secondary-button,
.arcade-button,
.store-button {
  width: 100%;
  margin-top: 12px;
  padding: 0 18px;
}

.primary-button {
  background: var(--blue);
  color: #081122;
}

.secondary-button {
  background: var(--yellow);
  color: #121827;
}

.arcade-button {
  background: #ffffff;
  color: #0d1222;
}

.store-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
}

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

.overlay.show {
  display: flex;
}

.panel {
  width: min(100%, 380px);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background:
    linear-gradient(180deg, rgba(18, 102, 255, 0.22), rgba(255, 92, 168, 0.08)),
    var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.4);
}

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

h1 {
  margin: 0;
  font-size: clamp(2rem, 8dvw, 3.25rem);
  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,
.level-map h2 {
  display: block;
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 950;
  text-transform: uppercase;
}

.level-map {
  margin-top: 16px;
}

.level-map[hidden] {
  display: none;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.level-button {
  display: grid;
  min-height: 52px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  place-items: center;
  background: linear-gradient(155deg, rgba(84, 199, 255, 0.24), rgba(255, 92, 168, 0.16));
  color: var(--ink);
  cursor: pointer;
  font-weight: 1000;
}

.level-button.locked {
  cursor: default;
  opacity: 0.42;
  filter: grayscale(0.85);
}

.level-stars {
  color: var(--yellow);
  font-size: 0.72rem;
  letter-spacing: 0;
}

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

.initials-row input,
.city-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-weight: 800;
  padding: 0 12px;
}

.initials-row input {
  text-align: center;
  text-transform: uppercase;
}

.city-input {
  margin-top: 7px;
}

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

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

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

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

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

@keyframes toastPop {
  0% {
    opacity: 0;
    transform: translate(-50%, -40%) scale(0.9);
  }
  18% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -72%) scale(1.12);
  }
}

@keyframes gameCommentPop {
  0% { opacity: 0; transform: translateY(3px) scale(0.98); }
  12%, 78% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-2px) scale(1); }
}

@media (max-height: 640px) {
  .shell {
    padding: max(5px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
      max(5px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .game {
    min-height: 0;
    gap: 5px;
  }

  .brand-header {
    min-height: 28px;
  }

  .match-logo {
    font-size: clamp(1rem, 5.8dvw, 1.42rem);
    line-height: 1;
  }

  .site-tag {
    margin-top: 1px;
    font-size: 0.62rem;
  }

  .metric {
    min-width: 0;
    padding: 5px 7px;
  }

  .metric-label {
    font-size: 0.58rem;
  }

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

  .topbar {
    grid-template-columns: minmax(88px, 1.28fr) minmax(104px, 1fr) minmax(50px, 0.52fr);
    gap: 5px;
  }

  #target {
    max-width: 104px;
    font-size: 0.64rem;
  }

  .small-button {
    min-height: 38px;
    padding: 0 9px;
    font-size: 0.82rem;
  }

  .icon-button {
    width: 38px;
    min-width: 38px;
    padding: 0;
  }

  .overlay {
    align-items: flex-start;
    padding: 10px;
  }

  .panel {
    width: min(100%, 390px);
    max-height: calc(100dvh - 20px);
    padding: 14px;
  }

  h1 {
    font-size: clamp(1.65rem, 7dvw, 2.35rem);
  }

  .panel p:not(.kicker) {
    margin-top: 8px;
    line-height: 1.32;
  }

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

  .initials-row {
    margin-bottom: 8px;
  }

  .primary-button,
  .secondary-button,
  .arcade-button,
  .store-button {
    margin-top: 8px;
    min-height: 42px;
  }

  .home-scores {
    max-height: 26dvh;
  }
}

.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;
}

.orientation-guard {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  place-items: center;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 209, 102, 0.22), transparent 32%),
    radial-gradient(circle at 80% 16%, rgba(84, 199, 255, 0.24), transparent 34%),
    linear-gradient(155deg, #08122d 0%, #102b68 54%, #090f1f 100%);
  color: var(--ink);
  text-align: center;
}

.orientation-guard div {
  display: grid;
  gap: 10px;
  width: min(92vw, 420px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 21, 42, 0.94);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

.orientation-guard strong {
  color: var(--yellow);
  font-size: clamp(1.45rem, 7vw, 2.25rem);
  line-height: 1.05;
}

.orientation-guard span {
  color: var(--ink);
  font-size: clamp(0.96rem, 3.6vw, 1.15rem);
  font-weight: 800;
  line-height: 1.35;
}

@media (orientation: landscape) and (pointer: coarse) and (max-height: 560px) {
  .shell {
    visibility: hidden;
  }

  .orientation-guard {
    display: grid;
  }
}
.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;
}
