:root {
  color-scheme: dark;
  --bg: #111416;
  --ink: #f7f4ec;
  --muted: #b7c2bb;
  --line: rgba(247, 244, 236, 0.16);
  --panel: rgba(22, 26, 28, 0.92);
  --store-blue: #0476d9;
  --store-blue-dark: #063a79;
  --store-blue-light: #54c7ff;
  --green: #4dd689;
  --yellow: #ffd166;
  --pink: #ef6f9f;
  --blue: #4cc9f0;
  --red: #ff715b;
  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 22% 18%, rgba(84, 199, 255, 0.2), transparent 30%),
    radial-gradient(circle at 78% 8%, rgba(4, 118, 217, 0.2), transparent 28%),
    linear-gradient(155deg, #071e3a 0%, #0b315f 50%, #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,
.bottombar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
}

.metric,
.combo {
  min-width: 84px;
  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: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.metric strong,
.combo strong {
  display: block;
  margin-top: 1px;
  font-size: clamp(1.15rem, 4dvh, 1.7rem);
  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.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    #151a1c;
  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%;
}

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

.floating-text.pop {
  animation: floatScore 780ms ease-out;
}

.combo {
  width: 96px;
}

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

.icon-button {
  width: 52px;
  background: var(--yellow);
  box-shadow: 0 8px 24px rgba(255, 209, 102, 0.22);
}

.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(8, 10, 11, 0.64);
  backdrop-filter: blur(10px);
}

.overlay.show {
  display: flex;
}

.panel {
  width: min(100%, 360px);
  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(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(--store-blue-light);
  font-size: 0.72rem;
  font-weight: 900;
  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 rgba(84, 199, 255, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.09);
  color: var(--ink);
  font: inherit;
  font-weight: 900;
  padding: 0 12px;
}

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

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

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

.small-button {
  border: 0;
  padding: 0 16px;
  background: var(--store-blue-light);
  color: #071624;
}

.secondary-button,
.arcade-button,
.store-button {
  width: 100%;
  margin-top: 16px;
  border: 1px solid rgba(84, 199, 255, 0.32);
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
}

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

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

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

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

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

@keyframes floatScore {
  0% {
    opacity: 0;
    transform: translate(-50%, -28%) scale(0.88);
  }
  22% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -92%) scale(1.12);
  }
}

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

  .metric,
  .combo {
    padding: 7px 8px;
  }

  .metric strong,
  .combo strong {
    font-size: 1.05rem;
  }
}
