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

:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --grid: #1e1e2e;
  --accent-x: #ff4d6d;
  --accent-o: #00d4ff;
  --accent-x-glow: rgba(255, 77, 109, 0.35);
  --accent-o-glow: rgba(0, 212, 255, 0.35);
  --text: #e8e8f0;
  --muted: #555570;
  --win-line: #ffd166;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

/* Animated background grid */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  animation: gridMove 20s linear infinite;
  pointer-events: none;
}

@keyframes gridMove {
  0% { transform: translate(0, 0); }
  100% { transform: translate(40px, 40px); }
}

/* Glow orbs */
.orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.15;
  pointer-events: none;
  animation: float 8s ease-in-out infinite;
}
.orb-1 { width: 400px; height: 400px; background: var(--accent-x); top: -100px; left: -100px; animation-delay: 0s; }
.orb-2 { width: 350px; height: 350px; background: var(--accent-o); bottom: -100px; right: -100px; animation-delay: -4s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(30px, 30px); }
}

.container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* Header */
.header {
  text-align: center;
}
.title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(3rem, 8vw, 5.5rem);
  letter-spacing: 0.08em;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent-x) 0%, #ff9a3c 50%, var(--accent-o) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.subtitle {
  font-size: 0.7rem;
  letter-spacing: 0.25em;
  color: var(--muted);
  margin-top: 4px;
  text-transform: uppercase;
}

/* Score board */
.scoreboard {
  display: flex;
  gap: 0;
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}
.score-item {
  padding: 12px 28px;
  text-align: center;
  position: relative;
}
.score-item + .score-item {
  border-left: 1px solid rgba(255,255,255,0.07);
}
.score-label {
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}
.score-val {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2rem;
  line-height: 1;
}
.score-item.you .score-val { color: var(--accent-x); }
.score-item.draws .score-val { color: var(--muted); }
.score-item.ai .score-val { color: var(--accent-o); }

/* Status */
.status {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  color: var(--muted);
  transition: all 0.3s;
}
.status .pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 100px;
  border: 1px solid currentColor;
  transition: all 0.4s;
}
.status.your-turn .pill { color: var(--accent-x); border-color: var(--accent-x); background: var(--accent-x-glow); }
.status.ai-turn .pill { color: var(--accent-o); border-color: var(--accent-o); background: var(--accent-o-glow); }
.status.win-x .pill { color: var(--accent-x); border-color: var(--accent-x); background: var(--accent-x-glow); }
.status.win-o .pill { color: var(--accent-o); border-color: var(--accent-o); background: var(--accent-o-glow); }
.status.draw .pill { color: var(--win-line); border-color: var(--win-line); background: rgba(255,209,102,0.15); }

.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1);} 50%{opacity:0.4;transform:scale(0.6);} }

/* Board */
.board-wrapper {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px;
  background: var(--grid);
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.06);
  box-shadow: 0 0 60px rgba(0,0,0,0.5);
}

.cell {
  width: clamp(90px, 20vw, 130px);
  height: clamp(90px, 20vw, 130px);
  background: var(--surface);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background 0.2s, transform 0.15s;
  border: 1px solid rgba(255,255,255,0.04);
}

.cell:hover:not(.taken) {
  background: #1a1a28;
  transform: scale(1.03);
}
.cell.taken { cursor: default; }

.cell::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.04), transparent 70%);
  opacity: 0;
  transition: opacity 0.2s;
}
.cell:hover:not(.taken)::after { opacity: 1; }

/* X and O marks */
.mark {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 3.5rem;
  line-height: 1;
  opacity: 0;
  transform: scale(0.3) rotate(-15deg);
  transition: opacity 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  user-select: none;
}
.mark.show {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}
.mark.x { color: var(--accent-x); text-shadow: 0 0 20px var(--accent-x-glow); }
.mark.o { color: var(--accent-o); text-shadow: 0 0 20px var(--accent-o-glow); }

/* Win highlight */
.cell.winner {
  animation: winPulse 0.8s ease forwards;
}
@keyframes winPulse {
  0% { background: var(--surface); }
  50% { background: rgba(255,209,102,0.15); }
  100% { background: rgba(255,209,102,0.08); border-color: rgba(255,209,102,0.3); }
}

/* Controls */
.controls {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn {
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 10px 24px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.1);
  opacity: 0;
  transition: opacity 0.2s;
}
.btn:hover::before { opacity: 1; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-x), #ff7a45);
  color: white;
  box-shadow: 0 4px 20px var(--accent-x-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 28px var(--accent-x-glow); }

.btn-secondary {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid rgba(255,255,255,0.08);
}
.btn-secondary:hover { color: var(--text); border-color: rgba(255,255,255,0.18); }

/* Difficulty selector */
.difficulty {
  display: flex;
  gap: 6px;
  align-items: center;
}
.diff-label {
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  color: var(--muted);
  text-transform: uppercase;
  margin-right: 4px;
}
.diff-btn {
  font-family: 'DM Mono', monospace;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
}
.diff-btn.active { background: var(--grid); color: var(--text); border-color: rgba(255,255,255,0.2); }
.diff-btn:hover:not(.active) { color: var(--text); }

/* Thinking overlay */
.thinking {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,10,15,0.6);
  border-radius: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  backdrop-filter: blur(2px);
}
.thinking.active { opacity: 1; pointer-events: all; }
.thinking-dots {
  display: flex; gap: 8px;
}
.thinking-dots span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent-o);
  animation: bounce 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,100%{transform:translateY(0);opacity:0.5;} 50%{transform:translateY(-10px);opacity:1;} }

/* First move selector */
.first-move {
  display: flex;
  gap: 8px;
  align-items: center;
}
.fm-label {
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  color: var(--muted);
  text-transform: uppercase;
}
.fm-btn {
  font-family: 'DM Mono', monospace;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  padding: 5px 14px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.08);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
}
.fm-btn.active-x { background: var(--accent-x-glow); color: var(--accent-x); border-color: var(--accent-x); }
.fm-btn.active-o { background: var(--accent-o-glow); color: var(--accent-o); border-color: var(--accent-o); }
.fm-btn:hover:not(.active-x):not(.active-o) { color: var(--text); }
