:root {
  --x-neon: #ff4d4d;
  --o-neon: #4db8ff;

  --win-neon: #fff46b;
  --grid-neon: rgba(255, 255, 255, 0.6);
  /* .button defaults */
  --btn-neon: #4db8ff;
  --btn-neon-soft: rgba(77, 184, 255, 0.45);
}

* {
  box-sizing: border-box;
  font-family: "Inter", sans-serif;
}

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background 0.6s ease;
  overflow: hidden;
}

body.turn-x {
  background: radial-gradient(circle at top, #b31d1d 0%, #6d0000 55%, #2b0000 100%);
}

.turn-x .button {
  --btn-neon: #ff6464;
  --btn-neon-soft: rgba(255, 77, 77, 0.45);
}

body.turn-o {
  background: radial-gradient(circle at top, #1ea1ff 0%, #003b7a 55%, #00162b 100%);
}

.turn-o .button {
  --btn-neon: #4db8ff;
  --btn-neon-soft: rgba(77, 184, 255, 0.45);
}

body.turn-x::before,
body.turn-o::before {
  content: "";
  position: fixed;
  inset: -50%;
  background: conic-gradient(from 0deg, transparent, rgba(255, 255, 255, 0.05), transparent);
  animation: bgSpin 18s linear infinite;
  pointer-events: none;
}

.app {
  color: white;
  text-align: center;
}

.board-wrapper {
  width: min(90vw, 320px);
  margin: 20px auto;
  animation: float 4s ease-in-out infinite;
}

.board-wrapper.win {
  animation: winShake 0.6s ease-in-out;
}

svg {
  width: 100%;
  height: auto;
}

/* Grid */
.grid-line {
  stroke: white;
  stroke-width: 4;
  opacity: 0.5;
}

/* Click area */
.cell {
  fill: transparent;
  cursor: pointer;
}

.cell:hover {
  fill: rgba(255, 255, 255, 0.03);
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.4));
}

/* X animation */
.x-line {
  stroke: var(--x-neon);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 70;
  stroke-dashoffset: 70;
  animation: draw 0.4s forwards;
  animation:
    draw 0.35s ease-out forwards,
    neonPulseX 1.8s ease-in-out infinite 0.4s;
  filter: drop-shadow(0 0 6px var(--x-neon)) drop-shadow(0 0 14px var(--x-neon));
}

/* O animation */
.o-circle {
  fill: none;
  stroke: var(--o-neon);
  stroke-width: 6;
  stroke-dasharray: 176;
  stroke-dashoffset: 176;
  animation:
    draw 0.45s ease-out forwards,
    neonPulseO 2s ease-in-out infinite 0.5s;
  filter: drop-shadow(0 0 6px var(--o-neon)) drop-shadow(0 0 16px var(--o-neon));
}

/* Win line */
.win-line {
  stroke: var(--win-neon);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 300;
  stroke-dashoffset: 300;
  animation:
    draw 0.6s ease-out forwards,
    winGlow 1.4s ease-in-out infinite 0.6s;
  filter: drop-shadow(0 0 10px var(--win-neon)) drop-shadow(0 0 26px var(--win-neon));
}

.grid-line {
  stroke: var(--grid-neon);
  filter: drop-shadow(0 0 6px white);
  animation: gridPulse 3s ease-in-out infinite;
}

.button {
  appearance: none;
  border: 2px solid var(--btn-neon);
  background: transparent;
  color: white;
  padding: 14px 28px;
  margin: 12px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 14px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  letter-spacing: 0.6px;
  box-shadow:
    0 0 12px var(--btn-neon-soft),
    inset 0 0 12px rgba(255, 255, 255, 0.05);
  transition:
    transform 0.15s ease,
    box-shadow 0.25s ease,
    background 0.25s ease,
    border-color 0.25s ease;
  animation: idleGlow 3.5s ease-in-out infinite;
}

/* Neon glow pulse */
.button::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, 0.25), transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.button:hover {
  background: rgba(0, 234, 255, 0.081);
  box-shadow:
    0 0 25px var(--btn-neon),
    0 0 60px var(--btn-neon-soft),
    inset 0 0 18px rgba(255, 255, 255, 0.1);
  transform: translateY(-2px) scale(1.03);
}

.button:hover::before {
  transform: translateX(100%);
}

.button:active {
  transform: scale(0.97);
  box-shadow:
    0 0 18px var(--btn-neon),
    inset 0 0 25px rgba(0, 0, 0, 0.4);
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.hidden {
  display: none;
}

.history {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.history .switch {
  width: 100%;
  display: flex;
  margin-bottom: 1rem;
}

.history .switch button {
  flex: 1;
  background-color: transparent;
  color: white;
  font-size: 1rem;
  font-weight: 600;
  padding: 8px;
  outline: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.25s ease;
}

.history .switch button:hover {
  border-color: var(--btn-neon-soft);
}
.history .switch button.active {
  border-color: var(--btn-neon);
}

.history-table-wrapper {
  width: 100%;
  max-height: 30vh;
  overflow-y: auto;

  /* scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--btn-neon) transparent;
}

.history-table-wrapper table {
  width: 100%;
  border-collapse: collapse;
}
.history-table-wrapper thead {
  position: sticky;
  top: 0;
  z-index: 1;
  backdrop-filter: blur(10px);
}

.history-table-wrapper td {
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

/* scrollbar - WebKit-based browsers */
.history-table-wrapper::-webkit-scrollbar {
  width: 4px;
}
.history-table-wrapper::-webkit-scrollbar-track {
  background: transparent;
}
.history-table-wrapper::-webkit-scrollbar-thumb {
  background-color: var(--btn-neon);
  border-radius: 9999px;
}
.history-table-wrapper::-webkit-scrollbar-thumb:hover {
  background-color: var(--btn-neon-soft);
}

/* Animations */

@keyframes draw {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes bgSpin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes gridPulse {
  0%,
  100% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.8;
  }
}

@keyframes neonPulseX {
  0%,
  100% {
    filter: drop-shadow(0 0 6px var(--x-neon)) drop-shadow(0 0 12px var(--x-neon));
  }
  50% {
    filter: drop-shadow(0 0 12px var(--x-neon)) drop-shadow(0 0 22px var(--x-neon));
  }
}

@keyframes neonPulseO {
  0%,
  100% {
    filter: drop-shadow(0 0 8px var(--o-neon)) drop-shadow(0 0 16px var(--o-neon));
  }
  50% {
    filter: drop-shadow(0 0 16px var(--o-neon)) drop-shadow(0 0 28px var(--o-neon));
  }
}

@keyframes winGlow {
  0%,
  100% {
    stroke-width: 8;
    opacity: 0.8;
  }
  50% {
    stroke-width: 10;
    opacity: 1;
  }
}

@keyframes winShake {
  0% {
    transform: scale(1);
  }
  25% {
    transform: scale(1.02) rotate(0.6deg);
  }
  50% {
    transform: scale(1.03) rotate(-0.6deg);
  }
  75% {
    transform: scale(1.02) rotate(0.4deg);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes idleGlow {
  0%,
  100% {
    box-shadow:
      0 0 12px var(--btn-neon-soft),
      inset 0 0 12px rgba(255, 255, 255, 0.05);
  }
  50% {
    box-shadow:
      0 0 22px var(--btn-neon),
      inset 0 0 18px rgba(255, 255, 255, 0.08);
  }
}
