:root {
  --bg-0: #05060d;
  --bg-1: #0a0d1f;
  --ink: #e9ecff;
  --ink-dim: #8a92c8;
  --x: #ff4d8d;
  --x-glow: #ff4d8d88;
  --o: #4df0ff;
  --o-glow: #4df0ff88;
  --tie: #c79cff;
  --line: #1a2044;
  --card: #0d1230cc;
  --card-2: #141a3f;
  --accent: #7b5bff;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
  background: radial-gradient(ellipse at top, #10143a 0%, var(--bg-0) 60%);
  color: var(--ink);
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  -webkit-font-smoothing: antialiased;
}

/* Animated background */
.bg-grid {
  position: fixed; inset: 0; z-index: 0;
  background-image:
    linear-gradient(rgba(123, 91, 255, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(123, 91, 255, 0.07) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse at center, black 40%, transparent 75%);
  animation: drift 40s linear infinite;
  pointer-events: none;
}
@keyframes drift { to { background-position: 440px 440px; } }

.glow {
  position: fixed;
  width: 520px; height: 520px;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.55;
  z-index: 0;
  pointer-events: none;
  animation: float 14s ease-in-out infinite;
}
.glow-a { background: var(--x); top: -140px; left: -140px; }
.glow-b { background: var(--o); bottom: -180px; right: -180px; animation-delay: -7s; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, 60px) scale(1.1); }
}

/* App shell */
.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 28px 26px 22px;
  background: linear-gradient(180deg, #0c1030cc, #070a1fcc);
  border: 1px solid #1f2657;
  border-radius: 24px;
  box-shadow:
    0 30px 80px -30px rgba(123, 91, 255, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  backdrop-filter: blur(14px);
}

/* Title */
.title-wrap { text-align: center; }
.title {
  font-size: 46px;
  margin: 0;
  font-weight: 900;
  letter-spacing: -1.5px;
  line-height: 1;
  background: linear-gradient(120deg, var(--x), var(--accent) 50%, var(--o));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 24px rgba(123, 91, 255, 0.5));
}
.title .t { display: inline-block; animation: bounceIn 600ms cubic-bezier(.22,1.5,.36,1) backwards; }
.title .dot {
  display: inline-block;
  color: var(--accent);
  -webkit-text-fill-color: var(--accent);
  margin: 0 6px;
  animation: pulse 1.6s ease-in-out infinite;
}
.title .t-1 { animation-delay: 40ms; }
.title .t-2 { animation-delay: 80ms; }
.title .t-3 { animation-delay: 120ms; }
.title .t-4 { animation-delay: 160ms; }
.title .t-5 { animation-delay: 200ms; }
.title .t-6 { animation-delay: 280ms; }
.title .t-7 { animation-delay: 320ms; }
.title .t-8 { animation-delay: 360ms; }
.title .t-9 { animation-delay: 400ms; }
.title .t-10 { animation-delay: 440ms; }
@keyframes bounceIn {
  from { transform: translateY(-24px) scale(0.6); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.25); opacity: 0.6; }
}
.subtitle {
  color: var(--ink-dim);
  margin: 8px 0 0;
  font-size: 13px;
  letter-spacing: 0.3px;
}

/* HUD */
.hud {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.score {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 8px;
  text-align: center;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}
.score .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--ink-dim);
  margin-bottom: 4px;
}
.score .value {
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.score-x .value { color: var(--x); text-shadow: 0 0 16px var(--x-glow); }
.score-o .value { color: var(--o); text-shadow: 0 0 16px var(--o-glow); }
.score-tie .value { color: var(--tie); }
.score.bump { transform: translateY(-4px) scale(1.04); }
.score-x.bump { border-color: var(--x); box-shadow: 0 10px 30px -10px var(--x-glow); }
.score-o.bump { border-color: var(--o); box-shadow: 0 10px 30px -10px var(--o-glow); }
.score-tie.bump { border-color: var(--tie); }

/* Controls */
.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.mode-toggle, .difficulty {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.mode-btn, .diff-btn {
  border: none;
  background: transparent;
  color: var(--ink-dim);
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: color 150ms ease, background 150ms ease, transform 120ms ease;
}
.mode-btn:hover, .diff-btn:hover { color: var(--ink); }
.mode-btn.active {
  background: linear-gradient(135deg, var(--x), var(--accent));
  color: white;
  box-shadow: 0 6px 20px -6px var(--x-glow);
}
.diff-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--o));
  color: white;
  box-shadow: 0 6px 20px -6px var(--o-glow);
}
.difficulty.hidden { display: none; }

/* Board */
.board-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.turn-indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 16px 6px 14px;
  font-size: 12px;
  color: var(--ink-dim);
  letter-spacing: 1.2px;
  text-transform: uppercase;
}
.turn-label { font-weight: 600; }
.turn-mark {
  font-weight: 900;
  font-size: 18px;
  transition: color 200ms ease, text-shadow 200ms ease;
}
.turn-x { color: var(--x); text-shadow: 0 0 12px var(--x-glow); }
.turn-o { color: var(--o); text-shadow: 0 0 12px var(--o-glow); }

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  width: min(92vw, 420px);
  aspect-ratio: 1 / 1;
  padding: 10px;
  background: linear-gradient(135deg, #11163a, #0a0e28);
  border: 1px solid #262d66;
  border-radius: 20px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.02),
    0 20px 40px -20px rgba(0, 0, 0, 0.8);
}

.cell {
  position: relative;
  border: 1px solid #1c234f;
  background: linear-gradient(160deg, #0d1335, #0a0f2b);
  border-radius: 14px;
  color: var(--ink);
  font-size: clamp(44px, 12vw, 72px);
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}
.cell::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: 14px;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(123, 91, 255, 0.25), transparent 60%);
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
}
.cell:hover::before { opacity: 1; }
.cell:not(:disabled):hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.cell:disabled { cursor: default; }
.cell.mark-x, .cell.mark-o {
  animation: pop 280ms cubic-bezier(.22,1.5,.36,1);
}
.cell.mark-x { color: var(--x); text-shadow: 0 0 24px var(--x-glow), 0 0 60px var(--x-glow); }
.cell.mark-o { color: var(--o); text-shadow: 0 0 24px var(--o-glow), 0 0 60px var(--o-glow); }
.cell.win {
  background: linear-gradient(160deg, #1a2050, #121843);
  animation: winPulse 900ms ease-in-out infinite;
}
@keyframes pop {
  0%   { transform: scale(0.2) rotate(-10deg); opacity: 0; }
  60%  { transform: scale(1.15) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}
@keyframes winPulse {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.35); }
}

/* Strike line */
.strike {
  position: absolute;
  inset: 10px;
  pointer-events: none;
  overflow: visible;
}
.strike line {
  stroke: url(#noGrad);
  stroke-width: 6;
  stroke-linecap: round;
  filter: drop-shadow(0 0 12px currentColor);
  stroke-dasharray: 500;
  stroke-dashoffset: 500;
  transition: stroke-dashoffset 550ms cubic-bezier(.25,.8,.3,1);
}
.strike.active line { stroke-dashoffset: 0; }
.strike.x line { stroke: var(--x); color: var(--x); }
.strike.o line { stroke: var(--o); color: var(--o); }

/* Actions */
.actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn {
  border: none;
  border-radius: 12px;
  padding: 11px 22px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 150ms ease, background 150ms ease;
}
.btn-primary {
  background: linear-gradient(135deg, var(--x), var(--accent));
  color: white;
  box-shadow: 0 10px 30px -10px var(--x-glow);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 14px 36px -10px var(--x-glow); }
.btn-ghost {
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--line);
}
.btn-ghost:hover { color: var(--ink); border-color: var(--accent); }

/* Banner */
.banner {
  min-height: 28px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.4px;
  transition: opacity 280ms ease, transform 280ms ease;
  opacity: 0;
  transform: translateY(6px);
}
.banner.show { opacity: 1; transform: translateY(0); }
.banner.win-x { color: var(--x); text-shadow: 0 0 16px var(--x-glow); }
.banner.win-o { color: var(--o); text-shadow: 0 0 16px var(--o-glow); }
.banner.tie { color: var(--tie); }

/* Foot */
.foot {
  text-align: center;
  color: var(--ink-dim);
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.foot .sep { margin: 0 8px; opacity: 0.5; }

/* Confetti */
.confetti {
  position: fixed;
  width: 10px; height: 14px;
  top: -20px;
  z-index: 9;
  pointer-events: none;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0.1; }
}

@media (max-width: 420px) {
  .app { padding: 20px 16px; }
  .title { font-size: 36px; }
}
