/* ========================================================================
   Neon Tic-Tac-Toe — Tres en Raya futurista
   Paleta: cian #00f0ff para X, magenta #ff2bd6 para O, fondo violeta oscuro
   ======================================================================== */

:root {
  --bg-0: #06010d;
  --bg-1: #0d0220;
  --bg-2: #1a0438;

  --cyan: #00f0ff;
  --cyan-soft: rgba(0, 240, 255, 0.6);
  --cyan-glow: rgba(0, 240, 255, 0.35);

  --magenta: #ff2bd6;
  --magenta-soft: rgba(255, 43, 214, 0.6);
  --magenta-glow: rgba(255, 43, 214, 0.35);

  --violet: #b14bff;
  --gold: #ffd166;
  --danger: #ff5577;

  --fg-1: #f5e9ff;
  --fg-2: #c8b8e6;
  --fg-3: #7d6e9c;

  --border: rgba(177, 75, 255, 0.25);
  --border-strong: rgba(177, 75, 255, 0.5);

  --font-display: 'Orbitron', 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
}

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

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--fg-1);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: clamp(16px, 4vw, 48px) 16px;
  position: relative;
}

/* Fondo: cuadrícula neón animada + scanlines CRT */
.grid-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%),
    radial-gradient(circle at 20% 10%, rgba(0, 240, 255, 0.08), transparent 50%),
    radial-gradient(circle at 80% 90%, rgba(255, 43, 214, 0.10), transparent 50%);
  background-blend-mode: normal;
}
.grid-bg::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(177, 75, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(177, 75, 255, 0.06) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, black 30%, transparent 90%);
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, black 30%, transparent 90%);
  animation: grid-drift 18s linear infinite;
}
@keyframes grid-drift {
  0%   { background-position: 0 0, 0 0; }
  100% { background-position: 40px 40px, 40px 40px; }
}

.scanlines {
  position: fixed; inset: 0;
  z-index: -1;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 240, 255, 0.015) 0,
    rgba(0, 240, 255, 0.015) 1px,
    transparent 1px,
    transparent 3px
  );
  pointer-events: none;
  mix-blend-mode: overlay;
}

/* Layout */
.shell {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  align-items: center;
}

/* Header */
.hdr { text-align: center; padding-top: 4px; }
.badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg-2);
  margin-bottom: 8px;
}
.title {
  font-family: var(--font-display);
  font-size: clamp(40px, 9vw, 56px);
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1;
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
}
.title-x {
  color: var(--cyan);
  text-shadow:
    0 0 8px var(--cyan-glow),
    0 0 18px var(--cyan-soft),
    0 0 38px var(--cyan-glow);
  animation: pulse-cyan 3.2s ease-in-out infinite;
}
.title-amp {
  color: var(--fg-3);
  font-size: 0.55em;
  font-weight: 500;
  vertical-align: middle;
}
.title-o {
  color: var(--magenta);
  text-shadow:
    0 0 8px var(--magenta-glow),
    0 0 18px var(--magenta-soft),
    0 0 38px var(--magenta-glow);
  animation: pulse-magenta 3.2s ease-in-out infinite 1.6s;
}
.tagline {
  margin-top: 6px;
  font-size: 13px;
  color: var(--fg-3);
  letter-spacing: 0.06em;
  font-family: var(--font-mono);
}

@keyframes pulse-cyan {
  0%, 100% { text-shadow: 0 0 8px var(--cyan-glow), 0 0 18px var(--cyan-soft), 0 0 38px var(--cyan-glow); }
  50%      { text-shadow: 0 0 14px var(--cyan-soft), 0 0 32px var(--cyan-glow), 0 0 60px var(--cyan-glow); }
}
@keyframes pulse-magenta {
  0%, 100% { text-shadow: 0 0 8px var(--magenta-glow), 0 0 18px var(--magenta-soft), 0 0 38px var(--magenta-glow); }
  50%      { text-shadow: 0 0 14px var(--magenta-soft), 0 0 32px var(--magenta-glow), 0 0 60px var(--magenta-glow); }
}

/* Scoreboard */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  width: 100%;
}
.score {
  text-align: center;
  padding: 12px 8px;
  background: rgba(13, 2, 32, 0.6);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}
.score::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent, currentColor);
  opacity: 0.04;
  pointer-events: none;
}
.score-x    { color: var(--cyan); }
.score-o    { color: var(--magenta); }
.score-draw { color: var(--gold); }
.score-label {
  display: block;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: inherit;
  margin-bottom: 2px;
  opacity: 0.8;
}
.score-value {
  display: block;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 900;
  color: var(--fg-1);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.score-value.bump { transform: scale(1.25); }

/* Status bar */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: rgba(13, 2, 32, 0.55);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 13px;
  flex-wrap: wrap;
}
.status-text {
  font-weight: 600;
  color: var(--fg-2);
}
.status-text .turn-x,
.status-text .turn-o {
  font-family: var(--font-display);
  font-weight: 900;
  margin-left: 2px;
}
.status-text .turn-x { color: var(--cyan); text-shadow: 0 0 8px var(--cyan-glow); }
.status-text .turn-o { color: var(--magenta); text-shadow: 0 0 8px var(--magenta-glow); }
.status-text .turn-x::before { content: '⚡'; margin-right: 6px; }
.status-text .turn-o::before { content: '✦'; margin-right: 6px; }

.status-text.is-win-x,
.status-text.is-win-o {
  animation: winner-flash 1.1s ease-in-out infinite;
}
.status-text.is-win-x { color: var(--cyan); }
.status-text.is-win-o { color: var(--magenta); }
.status-text.is-draw  { color: var(--gold); }
@keyframes winner-flash {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

.mode-pill {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--violet);
  padding: 4px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

/* Board */
.board {
  --cell: minmax(0, 1fr);
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, var(--cell));
  grid-template-rows: repeat(3, var(--cell));
  gap: 8px;
  padding: 12px;
  background: rgba(13, 2, 32, 0.6);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow:
    inset 0 0 24px rgba(177, 75, 255, 0.12),
    0 8px 32px rgba(0, 0, 0, 0.5);
}

.cell {
  position: relative;
  background: rgba(6, 1, 13, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: clamp(40px, 12vw, 64px);
  font-weight: 900;
  color: transparent;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.cell:hover:not(.locked) {
  border-color: var(--border-strong);
  background: rgba(13, 2, 32, 0.85);
  transform: scale(1.02);
}
.cell:active:not(.locked) { transform: scale(0.97); }
.cell.locked { cursor: default; }
.cell.is-x {
  color: var(--cyan);
  text-shadow:
    0 0 8px var(--cyan-glow),
    0 0 24px var(--cyan-soft);
  animation: pop-x 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.cell.is-o {
  color: var(--magenta);
  text-shadow:
    0 0 8px var(--magenta-glow),
    0 0 24px var(--magenta-soft);
  animation: pop-o 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.cell.is-winning {
  background: rgba(0, 240, 255, 0.08);
  border-color: currentColor;
  animation: win-pulse 1.1s ease-in-out infinite;
}
.cell.is-winning.is-x { box-shadow: 0 0 18px var(--cyan-glow); }
.cell.is-winning.is-o { box-shadow: 0 0 18px var(--magenta-glow); }

@keyframes pop-x {
  0%   { opacity: 0; transform: scale(0.4) rotate(-12deg); }
  60%  { opacity: 1; transform: scale(1.15) rotate(4deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes pop-o {
  0%   { opacity: 0; transform: scale(0.4) rotate(12deg); }
  60%  { opacity: 1; transform: scale(1.15) rotate(-4deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes win-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

.win-line {
  position: absolute;
  inset: 12px;
  width: calc(100% - 24px);
  height: calc(100% - 24px);
  pointer-events: none;
  color: var(--cyan);
  filter: drop-shadow(0 0 8px currentColor);
  opacity: 0;
  transition: opacity 0.4s ease;
}
.win-line.is-active { opacity: 1; }
.win-line.o-wins { color: var(--magenta); }

/* Controls */
.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 12px 18px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--fg-2);
  cursor: pointer;
  transition: all 0.18s ease;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover {
  color: var(--fg-1);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(0); }

.btn-secondary {
  color: var(--violet);
}
.btn-secondary:hover {
  color: var(--fg-1);
  box-shadow: 0 0 12px rgba(177, 75, 255, 0.3);
}

.btn-primary {
  color: var(--cyan);
  border-color: var(--cyan);
  background: rgba(0, 240, 255, 0.04);
  box-shadow: 0 0 0 transparent, inset 0 0 12px rgba(0, 240, 255, 0.05);
}
.btn-primary:hover {
  color: white;
  background: var(--cyan);
  border-color: var(--cyan);
  box-shadow:
    0 0 16px var(--cyan-glow),
    0 0 32px var(--cyan-glow),
    inset 0 0 8px rgba(255, 255, 255, 0.2);
}

/* Footer */
.ftr {
  margin-top: auto;
  padding-top: 12px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
  letter-spacing: 0.06em;
}

/* Responsive */
@media (max-width: 380px) {
  .title { font-size: 44px; }
  .cell  { font-size: 40px; }
  .btn   { font-size: 11px; padding: 10px 12px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .grid-bg::before { animation: none; }
}