: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;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

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

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

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

.primary-button {
  width: 100%;
  margin-top: 16px;
  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;
}

.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,
.arcade-button,
.store-button {
  width: 100%;
  min-height: 48px;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

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