@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Share+Tech+Mono&display=swap');

:root {
  --neon-x: #ff2d55;
  --neon-o: #00f5ff;
  --neon-green: #39ff14;
  --bg-dark: #050a0e;
  --bg-panel: #0a1520;
  --grid-line: #1a3a4a;
  --text-dim: #4a7a8a;
  --text-bright: #c8f0ff;
  --glow-x: 0 0 8px #ff2d55, 0 0 20px #ff2d55, 0 0 40px #ff2d5588;
  --glow-o: 0 0 8px #00f5ff, 0 0 20px #00f5ff, 0 0 40px #00f5ff88;
  --glow-green: 0 0 8px #39ff14, 0 0 20px #39ff14;
  --cell-size: 110px;
  --gap: 4px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Press Start 2P', monospace;
  background-color: var(--bg-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-bright);
  overflow-x: hidden;
  position: relative;
}

.scanlines {
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 3px,
    rgba(0, 0, 0, 0.18) 3px,
    rgba(0, 0, 0, 0.18) 4px
  );
  pointer-events: none;
  z-index: 100;
}

.crt-flicker {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0, 0, 0, 0.55) 100%);
  pointer-events: none;
  z-index: 99;
  animation: flicker 8s infinite;
}

@keyframes flicker {
  0%, 95%, 100% { opacity: 1; }
  96% { opacity: 0.92; }
  97% { opacity: 1; }
  98% { opacity: 0.88; }
  99% { opacity: 1; }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  clip: rect(0, 0, 0, 0);
  overflow: hidden;
  white-space: nowrap;
}

header {
  margin-bottom: 28px;
  text-align: center;
}

.title-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.title-insert {
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.65rem;
  color: var(--neon-green);
  letter-spacing: 0.4em;
  text-shadow: var(--glow-green);
  animation: blink 1.2s step-start infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

h1 {
  font-size: 2.4rem;
  color: var(--text-bright);
  letter-spacing: 0.1em;
  text-shadow: 0 0 10px var(--neon-o), 0 0 30px var(--neon-o), 0 0 60px #00f5ff44;
  animation: titlePulse 3s ease-in-out infinite;
}

@keyframes titlePulse {
  0%, 100% { text-shadow: 0 0 10px var(--neon-o), 0 0 30px var(--neon-o); }
  50% { text-shadow: 0 0 16px var(--neon-o), 0 0 50px var(--neon-o), 0 0 80px var(--neon-o); }
}

.title-sub {
  font-size: 0.55rem;
  color: var(--text-dim);
  letter-spacing: 0.5em;
}

.mode-selection {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.mode-badge {
  display: block;
  text-align: center;
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.7rem;
  color: var(--neon-green);
  letter-spacing: 0.15em;
  text-shadow: var(--glow-green);
  margin-bottom: 16px;
}

#difficulty-selection {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 0.55rem;
}

#difficulty-selection label {
  color: var(--neon-o);
}

#difficulty {
  background: var(--bg-panel);
  border: 1px solid var(--neon-o);
  color: var(--neon-o);
  font-family: 'Press Start 2P', monospace;
  font-size: 0.5rem;
  padding: 6px 10px;
  cursor: pointer;
  box-shadow: 0 0 6px var(--neon-o);
}

#difficulty:focus {
  outline: 2px solid var(--neon-o);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.game-status {
  font-family: 'Share Tech Mono', monospace;
  font-size: 1rem;
  color: var(--neon-green);
  text-shadow: var(--glow-green);
  margin-bottom: 20px;
  min-height: 1.6em;
  letter-spacing: 0.08em;
}

.status-arrow {
  animation: blink 0.8s step-start infinite;
}

.board-wrapper {
  position: relative;
  padding: 18px;
  margin-bottom: 24px;
}

.corner {
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: var(--neon-o);
  border-style: solid;
  box-shadow: var(--glow-o);
}
.corner.tl { top: 0; left: 0; border-width: 2px 0 0 2px; }
.corner.tr { top: 0; right: 0; border-width: 2px 2px 0 0; }
.corner.bl { bottom: 0; left: 0; border-width: 0 0 2px 2px; }
.corner.br { bottom: 0; right: 0; border-width: 0 2px 2px 0; }

.game-board {
  display: inline-flex;
  flex-direction: column;
  gap: var(--gap);
  background: var(--grid-line);
  border: 1px solid var(--grid-line);
}

.row {
  display: flex;
  gap: var(--gap);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  cursor: pointer;
  transition: background 0.15s ease;
  position: relative;
  user-select: none;
}

.cell:hover {
  background: #0f2030;
}

.cell:focus {
  outline: 2px solid var(--neon-o);
  outline-offset: -2px;
}

.cell::after {
  content: attr(data-player);
  position: absolute;
  font-family: 'Press Start 2P', monospace;
  font-size: 2rem;
  transition: transform 0.15s ease, opacity 0.15s ease;
  transform: scale(0.6);
  opacity: 0;
}

.cell[data-player]::after {
  transform: scale(1);
  opacity: 1;
}

.cell[data-player="X"]::after {
  color: var(--neon-x);
  text-shadow: var(--glow-x);
}

.cell[data-player="O"]::after {
  color: var(--neon-o);
  text-shadow: var(--glow-o);
}

.cell.winning {
  background: rgba(57, 255, 20, 0.06);
  animation: winPulse 0.9s ease-in-out infinite;
}

@keyframes winPulse {
  0%, 100% { background: rgba(57, 255, 20, 0.04); }
  50% { background: rgba(57, 255, 20, 0.14); }
}

.score-board {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border: 1px solid var(--grid-line);
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 28px;
  gap: 8px;
  border-right: 1px solid var(--grid-line);
}

.score-item:last-child {
  border-right: none;
}

.score-label {
  font-size: 0.5rem;
  color: var(--text-dim);
  letter-spacing: 0.2em;
}

.score-value {
  font-size: 1.5rem;
}

.score-x .score-value { color: var(--neon-x); text-shadow: var(--glow-x); }
.score-o .score-value { color: var(--neon-o); text-shadow: var(--glow-o); }
.score-tie .score-value { color: var(--neon-green); text-shadow: var(--glow-green); }

button {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.6rem;
  padding: 10px 18px;
  cursor: pointer;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--grid-line);
  letter-spacing: 0.1em;
  transition: all 0.2s ease;
  position: relative;
}

button:hover {
  color: var(--neon-o);
  border-color: var(--neon-o);
  box-shadow: 0 0 10px var(--neon-o), inset 0 0 10px rgba(0, 245, 255, 0.05);
}

button:focus {
  outline: 2px solid var(--neon-o);
  outline-offset: 2px;
}

button[aria-pressed="true"] {
  color: var(--neon-o);
  border-color: var(--neon-o);
  box-shadow: 0 0 12px var(--neon-o), inset 0 0 10px rgba(0, 245, 255, 0.08);
}

.restart-btn {
  display: block;
  margin: 0 auto;
  color: var(--neon-x);
  border-color: var(--neon-x);
  box-shadow: 0 0 8px rgba(255, 45, 85, 0.4);
}

.restart-btn:hover {
  color: var(--neon-x);
  border-color: var(--neon-x);
  box-shadow: 0 0 16px var(--neon-x), inset 0 0 10px rgba(255, 45, 85, 0.08);
}

footer {
  margin-top: 32px;
  padding-bottom: 16px;
}

.footer-text {
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.5rem;
  color: var(--text-dim);
  letter-spacing: 0.2em;
}

.ai-thinking .cell {
  cursor: progress;
  opacity: 0.7;
}

#notification {
  font-family: 'Share Tech Mono', monospace;
  font-size: 0.65rem;
  color: var(--neon-green);
  text-align: center;
  margin-top: 10px;
  min-height: 1.2em;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 768px) {
  :root { --cell-size: 85px; }
  h1 { font-size: 1.6rem; }
}

@media (max-width: 480px) {
  :root { --cell-size: 72px; }
  h1 { font-size: 1.1rem; }
  .score-item { padding: 10px 16px; }
}
