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

:root {
  --bg: #eef2ff;
  --surface: #ffffff;
  --primary: #6366f1;
  --x-color: #ef4444;
  --o-color: #3b82f6;
  --text: #1a1a2e;
  --text-light: #6b7280;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  min-height: 100vh;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

#app {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 20px 16px 32px;
}

/* ── Screens ── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Mode Select ── */
.logo {
  text-align: center;
  padding-top: 24px;
  margin-bottom: 8px;
}
.logo-icon { font-size: 48px; line-height: 1; letter-spacing: 4px; }
.logo h1 {
  font-size: 38px;
  font-weight: 800;
  color: var(--primary);
  margin-top: 4px;
}
.subtitle {
  text-align: center;
  color: var(--text-light);
  font-size: 17px;
  margin-bottom: 28px;
}

.mode-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.mode-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 3px solid transparent;
  border-radius: 18px;
  padding: 18px 20px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: transform 0.12s, box-shadow 0.12s;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.08);
}
.mode-card:hover { transform: translateY(-3px); box-shadow: 0 8px 22px rgba(99, 102, 241, 0.16); }
.mode-card:active { transform: scale(0.98); }
.two-player-card { border-color: #a5b4fc; }
.easy-card { border-color: #6ee7b7; }
.hard-card { border-color: #fca5a5; }
.mode-emoji { font-size: 40px; line-height: 1; }
.mode-name { font-size: 20px; font-weight: 700; }
.mode-details { font-size: 14px; color: var(--text-light); margin-top: 2px; }

/* ── Top bar ── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.icon-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 22px; height: 22px; }

.scoreboard {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 10px;
}
.score-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 6px 12px;
  text-align: center;
  min-width: 56px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.score-mark { font-size: 18px; line-height: 1; }
.score-val { font-size: 20px; font-weight: 800; margin-top: 2px; }
.score-x .score-val { color: var(--x-color); }
.score-o .score-val { color: var(--o-color); }

.turn-badge {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  padding: 10px;
  margin-bottom: 18px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* ── Board ── */
#board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 420px;
  margin: 0 auto;
  aspect-ratio: 1;
}
.cell {
  background: var(--surface);
  border: none;
  border-radius: 18px;
  font-size: min(80px, 18vw);
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(99, 102, 241, 0.1);
  transition: transform 0.1s, background 0.15s;
  user-select: none;
}
.cell:active { transform: scale(0.96); }
.cell.filled { cursor: default; }
.cell.pop { animation: pop 0.25s ease; }
.cell.win {
  background: #fef08a;
  animation: winpulse 0.6s ease infinite alternate;
}
@keyframes pop {
  0% { transform: scale(0.4); }
  70% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
@keyframes winpulse {
  from { box-shadow: 0 3px 10px rgba(250, 204, 21, 0.4); }
  to { box-shadow: 0 6px 24px rgba(250, 204, 21, 0.9); }
}

/* ── Win overlay ── */
#win-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#win-screen.show { display: flex; }
.win-content {
  background: var(--surface);
  border-radius: 24px;
  padding: 36px 32px;
  text-align: center;
  max-width: 340px;
  width: 88%;
  animation: pop 0.3s ease;
}
.win-emoji { font-size: 64px; line-height: 1; }
.win-content h2 { font-size: 28px; margin: 14px 0 24px; }
.primary-btn, .secondary-btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 14px;
  padding: 14px;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  margin-top: 10px;
}
.primary-btn { background: var(--primary); color: white; }
.primary-btn:active { transform: scale(0.97); }
.secondary-btn { background: #e5e7eb; color: var(--text); }
.secondary-btn:active { transform: scale(0.97); }
