:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --panel-2: #f0efe9;
  --text: #1d1d1d;
  --muted: #5c5c5c;
  --accent: #f25f5c;
  --accent-2: #247ba0;
  --danger: #ff3b30;
  --shadow: rgba(0, 0, 0, 0.18);
  --grid: rgba(0, 0, 0, 0.08);
  --font-title: "Impact", "Arial Black", sans-serif;
  --font-body: "Trebuchet MS", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at 10% 20%, #fff0db, var(--bg));
  font-family: var(--font-body);
  overflow: hidden;
}

.menu-screen,
.game-screen {
  min-height: 100vh;
  display: none;
  align-items: center;
  justify-content: center;
  width: 100vw;
}

.menu-screen {
  display: grid;
  padding: 24px;
}

.game-screen {
  display: none;
  padding: 24px;
}

body.in-game .menu-screen {
  display: none;
}

body.in-game .game-screen {
  display: grid;
  padding: 60px 24px;
}

.menu-card {
  width: min(540px, 90vw);
  background: var(--panel);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 24px 50px var(--shadow);
  display: grid;
  gap: 20px;
  position: relative;
  overflow: hidden;
}

.menu-card::before {
  content: "";
  position: absolute;
  inset: -60px auto auto -80px;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, var(--accent), transparent 70%);
  opacity: 0.25;
}

.menu-title {
  font-size: 38px;
  letter-spacing: 2px;
  font-family: var(--font-title);
}

.menu-subtitle {
  color: var(--muted);
  font-size: 14px;
}

.menu-buttons {
  display: grid;
  gap: 12px;
}

.menu-btn {
  padding: 14px 18px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.menu-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 20px var(--shadow);
}

.menu-btn.primary {
  background: var(--accent);
  color: white;
}

.menu-btn.danger {
  background: var(--danger);
  color: white;
}

.menu-btn.small {
  padding: 10px 12px;
  font-size: 12px;
  text-transform: none;
}

.menu-btn.ghost {
  background: transparent;
  border: 1px solid var(--grid);
}

.menu-panels {
  display: grid;
  gap: 12px;
}

.panel {
  display: none;
  background: var(--panel-2);
  border-radius: 16px;
  padding: 16px;
  gap: 12px;
}

.panel.active {
  display: grid;
}

.panel-title {
  font-weight: 700;
}

.panel-text {
  font-size: 12px;
  color: var(--muted);
}

.panel-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  text-align: center;
}

.panel-stats span {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.panel-stats strong {
  font-size: 18px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.field select {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--grid);
  background: #fff;
  font-weight: 600;
}

.field.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.menu-message {
  min-height: 16px;
  color: var(--danger);
  font-size: 12px;
}

.game-frame {
  background: var(--panel);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 18px 40px var(--shadow);
  position: relative;
}

.game-frame.solo {
  padding: 20px;
}

#board {
  --board-cols: 10;
  --board-rows: 20;
  height: min(78vh, 860px);
  width: auto;
  max-width: 96vw;
  aspect-ratio: var(--board-cols) / var(--board-rows);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(220, 220, 220, 0.6));
  border-radius: 12px;
  border: 2px solid var(--grid);
}

.hud {
  position: fixed;
  top: 18px;
  left: 18px;
  display: none;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.85);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  box-shadow: 0 10px 20px var(--shadow);
  pointer-events: none;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  border-radius: 18px;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: var(--panel);
  padding: 24px 28px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.3);
  display: grid;
  gap: 14px;
}

.overlay-title {
  font-size: 22px;
  font-weight: 700;
}

.overlay-sub {
  color: var(--muted);
}

.overlay-score {
  font-weight: 700;
}

.overlay-actions {
  display: grid;
  gap: 10px;
}

.history {
  display: grid;
  gap: 8px;
  max-height: 200px;
  overflow: auto;
  font-size: 12px;
}

.history-item {
  padding: 10px;
  border-radius: 10px;
  background: #fff;
  display: grid;
  gap: 4px;
}

.theme-dark {
  --bg: #101217;
  --panel: #1b1f28;
  --panel-2: #252b36;
  --text: #f5f6f8;
  --muted: #9aa0aa;
  --accent: #ffb703;
  --accent-2: #219ebc;
  --grid: rgba(255, 255, 255, 0.12);
  background: radial-gradient(circle at 20% 20%, #1b1f28, #0d0f14);
}

.theme-anime {
  --bg: #fff1f6;
  --panel: #ffffff;
  --panel-2: #ffe3f1;
  --text: #2a1b2f;
  --muted: #7b4e67;
  --accent: #ff6fb1;
  --accent-2: #8f5bff;
  --grid: rgba(255, 105, 180, 0.2);
  font-family: "Georgia", "Times New Roman", serif;
  background: radial-gradient(circle at 20% 20%, #ffe3f1, #fff1f6);
}

.theme-cartoon {
  --bg: #fef9c3;
  --panel: #fff7e0;
  --panel-2: #ffe7a3;
  --text: #352b1a;
  --muted: #6b5a3a;
  --accent: #ff7f11;
  --accent-2: #00a6fb;
  --grid: rgba(53, 43, 26, 0.2);
  font-family: "Comic Sans MS", "Trebuchet MS", sans-serif;
  background: radial-gradient(circle at 20% 20%, #ffe7a3, #fef9c3);
}

.theme-whiteboard {
  --bg: #f7f7f7;
  --panel: #ffffff;
  --panel-2: #f0f0f0;
  --text: #121212;
  --muted: #444;
  --accent: #2d6cdf;
  --accent-2: #ef476f;
  --grid: rgba(0, 0, 0, 0.12);
  font-family: "Courier New", monospace;
  background: repeating-linear-gradient(0deg, #f7f7f7, #f7f7f7 24px, #e6e6e6 25px);
}

.theme-normal {
  font-family: var(--font-body);
}

@media (max-width: 720px) {
  .menu-title {
    font-size: 30px;
  }
  #board {
    height: min(82vh, 760px);
    max-width: 94vw;
  }
}

@media (min-width: 1024px) {
  .hud {
    display: grid;
  }
}
