:root {
  color-scheme: dark;
  --ink: #f8f4e8;
  --muted: #b5bdb8;
  --line: rgba(248, 244, 232, 0.16);
  --panel: rgba(19, 22, 25, 0.95);
  --store-blue: #0476d9;
  --store-blue-dark: #063a79;
  --store-blue-light: #54c7ff;
  --blue: #38bdf8;
  --green: #58d68d;
  --yellow: #ffd166;
  --pink: #f472b6;
  --orange: #fb923c;
  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% 12%, rgba(84, 199, 255, 0.2), transparent 30%),
    radial-gradient(circle at 84% 18%, rgba(4, 118, 217, 0.18), transparent 30%),
    linear-gradient(150deg, #071e3a 0%, #0b315f 50%, #081624 100%);
  color: var(--ink);
  touch-action: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

.shell {
  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 auto;
  gap: 10px;
  width: min(100%, 520px);
  height: min(100dvh - 24px, 920px);
  min-height: 570px;
}

.topbar {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.72);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
}

.game-title {
  margin: 0;
  overflow: hidden;
  color: var(--store-blue-light);
  font-family: "Arial Black", Impact, Haettenschweiler, "Franklin Gothic Heavy", sans-serif;
  font-size: clamp(1.35rem, 6vw, 2.25rem);
  font-weight: 900;
  letter-spacing: 1px;
  line-height: 1;
  text-align: center;
  text-shadow:
    0 2px 0 rgba(255, 255, 255, 0.2),
    0 5px 14px rgba(84, 199, 255, 0.28);
  text-transform: uppercase;
  white-space: nowrap;
}

.hud-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  align-items: stretch;
  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: 900;
  text-transform: uppercase;
}

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

.exit-button {
  min-width: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.store-tag {
  min-height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.72);
  color: rgba(255, 255, 255, 0.92);
  font-size: clamp(0.92rem, 3.2vw, 1.15rem);
  font-weight: 900;
  letter-spacing: 0.3px;
  text-align: center;
  text-shadow: 0 2px 10px rgba(84, 199, 255, 0.28);
}

.board-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12171a;
  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%);
  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);
}

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

.piece-tray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.piece-slot {
  display: grid;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  place-items: center;
  touch-action: none;
}

.piece-slot.used {
  opacity: 0.28;
}

.piece-preview {
  display: grid;
  gap: 4px;
}

.piece-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.piece-cell {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--blue);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.36), 0 4px 10px rgba(0, 0, 0, 0.25);
}

.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%, 370px);
  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,
.score-form label,
.home-scores h2 {
  margin: 0 0 6px;
  color: var(--store-blue-light);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.35rem, 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;
}

.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: 900;
  padding: 0 12px;
}

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

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

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

.small-button,
.primary-button {
  border: 0;
  background: var(--store-blue-light);
  color: #111416;
}

.primary-button,
.secondary-button,
.arcade-button,
.store-button {
  width: 100%;
  margin-top: 16px;
}

.secondary-button,
.arcade-button,
.store-button {
  border: 1px solid var(--line);
  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 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 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: 640px) {
  .game {
    min-height: 0;
  }

  .piece-slot {
    min-height: 74px;
  }
}
