* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f4fbff;
  --text: #0f172a;
  --muted: #6b7280;
  --accent: #ff4d4d;
  --accent-2: #2ab3e6;
  --tile: #ffffff;
  --empty: #d9eef3;
  --shadow: 0 18px 36px rgba(15, 23, 42, 0.12);
}

html, body {
  width: 100%;
  height: 100%;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  overflow: hidden;
}

.app {
  height: 100%;
  padding: 16px;
}

.menu-screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  z-index: 20;
}

body.menu-visible .menu-screen {
  display: flex;
}

body.menu-visible .game-screen {
  filter: blur(6px);
  pointer-events: none;
  user-select: none;
}

.menu-card {
  background: linear-gradient(160deg, #ffffff 20%, #f2fbff 100%);
  border-radius: 28px;
  padding: 30px 28px 32px;
  width: min(480px, 92vw);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: center;
  border: 1px solid rgba(42, 179, 230, 0.15);
}

.menu-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.menu-badge {
  align-self: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(42, 179, 230, 0.15);
  color: #1f3b5c;
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 0.7rem;
}

.menu-title {
  font-size: 2.2rem;
  font-weight: 800;
  color: #1f2937;
  letter-spacing: 1px;
}

.menu-subtitle {
  color: var(--muted);
  font-size: 0.95rem;
}

.menu-grid {
  display: grid;
  gap: 16px;
}

.menu-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.menu-label {
  font-size: 0.9rem;
  color: #3f4a5c;
  font-weight: 700;
}

.menu-toggle {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.menu-btn {
  border: 2px solid #d7e7ec;
  background: #ffffff;
  color: #3f4a5c;
  padding: 8px 14px;
  border-radius: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.menu-btn.active {
  background: linear-gradient(135deg, #2ab3e6, #58d4f4);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(42, 179, 230, 0.3);
}

.menu-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 6px;
}

.menu-action-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: #ffffff;
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.15);
  cursor: pointer;
  font-size: 1.1rem;
}

.menu-action-btn.is-off {
  opacity: 0.6;
}

.menu-play {
  margin-top: 4px;
  padding: 14px 18px;
  border-radius: 18px;
  border: none;
  background: var(--accent);
  color: #ffffff;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 2px;
  box-shadow: 0 14px 0 rgba(255, 77, 77, 0.35);
  cursor: pointer;
}

.menu-play:active {
  transform: translateY(2px);
  box-shadow: 0 10px 0 rgba(255, 77, 77, 0.35);
}

.game-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.hud-item {
  background: #ffffff;
  border: 1px solid #cfe8ee;
  border-radius: 14px;
  padding: 10px 14px;
  min-width: 96px;
  text-align: center;
}

.hud-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.hud-value {
  font-size: 1rem;
  font-weight: 700;
  color: #1f2937;
}

.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.board {
  position: relative;
  border-radius: 24px;
  padding: 12px;
  background: #ffffff;
  box-shadow: var(--shadow);
  border: 1px solid #e2e8f0;
  touch-action: manipulation;
}

.tile,
.empty-cell {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.tile {
  background: var(--tile);
  border: 2px solid rgba(42, 179, 230, 0.2);
  box-shadow: 0 10px 18px rgba(42, 179, 230, 0.18);
  font-weight: 800;
  font-size: 1.2rem;
  color: #1f2937;
}

.tile.inactive {
  opacity: 0.55;
  box-shadow: none;
}

.empty-cell {
  background: var(--empty);
  border: 2px dashed rgba(31, 41, 55, 0.12);
}

.board.shake {
  animation: shake 0.2s ease;
}

.board.win {
  animation: winPulse 0.6s ease;
}

.game-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding-bottom: 6px;
  flex-wrap: wrap;
}

.action-btn {
  padding: 10px 16px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #2ab3e6, #58d4f4);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.action-btn.ghost {
  background: #ffffff;
  color: #2ab3e6;
  border: 2px solid #cfe8ee;
}

.action-icon-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: #ffffff;
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.12);
  cursor: pointer;
  font-size: 1.05rem;
}

.action-icon-btn.is-off {
  opacity: 0.6;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.overlay-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  max-width: 320px;
  width: 90%;
  box-shadow: var(--shadow);
}

.overlay-title {
  font-size: 1.4rem;
  margin-bottom: 10px;
}

.overlay-text {
  font-weight: 600;
  margin-bottom: 10px;
}

.overlay-meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.hidden {
  display: none !important;
}

@keyframes shake {
  0% { transform: translateX(0); }
  50% { transform: translateX(4px); }
  100% { transform: translateX(0); }
}

@keyframes winPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}

@media (max-width: 720px) {
  .menu-card {
    padding: 22px 20px 26px;
  }

  .menu-title {
    font-size: 1.7rem;
    letter-spacing: 1px;
  }

  .menu-grid {
    gap: 12px;
  }

  .game-actions {
    flex-wrap: nowrap;
    gap: 8px;
  }

  .action-btn {
    padding: 8px 10px;
    font-size: 0.82rem;
    border-radius: 12px;
  }

  .action-icon-btn {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }
}
