: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;
  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,
.bottombar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.metric {
  min-width: 84px;
  padding: 8px 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;
}

#target {
  font-size: clamp(0.78rem, 2.6dvh, 1.08rem);
  line-height: 1.08;
}

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

.toast {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  color: var(--yellow);
  font-size: 1.35rem;
  font-weight: 950;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  text-shadow: 0 4px 14px rgba(0, 0, 0, 0.55);
}

.toast.pop {
  animation: toastPop 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 14px;
  background: var(--yellow);
  color: #121827;
}

.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;
  background: rgba(4, 7, 14, 0.68);
  backdrop-filter: blur(10px);
}

.overlay.show {
  display: flex;
}

.panel {
  width: min(100%, 380px);
  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 {
  display: block;
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 950;
  text-transform: uppercase;
}

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

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

  .metric {
    padding: 6px 8px;
  }
}
