/* Import more font weights for better hierarchy */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');

/* --- CSS Variables for easy theme management --- */
:root {
  --color-x: #00e0ff; /* Brighter neon blue */
  --color-o: #ff2d90; /* Brighter neon pink */
  --color-win: #2bff88; /* Vibrant neon green */
  --color-bg-start: #3a0058; /* Deeper, richer purple */
  --color-bg-end: #0a003a;   /* Deeper, richer blue */
  --glass-bg: rgba(255, 255, 255, 0.08); /* Slightly less opaque */
  --glass-bg-hover: rgba(255, 255, 255, 0.15);
  --glass-border: rgba(255, 255, 255, 0.15); /* Thicker for more presence */
  --neon-glow-primary: #00fff5; /* Main neon glow color */
  --neon-glow-secondary: #ff00c8; /* Secondary neon glow for contrast */
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Poppins', sans-serif;
  background-image: linear-gradient(135deg, var(--color-bg-start) 0%, var(--color-bg-end) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: white;
  margin: 0;
  overflow: hidden;
  position: relative; /* For background elements */
}

/* --- Background Neon Glass Elements --- */
body::before,
body::after {
  content: '';
  position: absolute;
  border-radius: 50%; /* Circular shapes */
  filter: blur(80px); /* Heavy blur for ethereal glow */
  opacity: 0.6;
  animation: backgroundGlow 15s infinite alternate ease-in-out;
  z-index: -1; /* Keep behind the content */
}

body::before {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, var(--neon-glow-primary) 0%, transparent 70%);
  top: -100px;
  left: -100px;
  animation-delay: 0s;
}

body::after {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, var(--neon-glow-secondary) 0%, transparent 70%);
  bottom: -150px;
  right: -150px;
  animation-delay: 7.5s; /* Stagger animation for more dynamic effect */
}

@keyframes backgroundGlow {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 0.6;
  }
  25% {
    transform: translate(50px, -50px) scale(1.1);
    opacity: 0.7;
  }
  50% {
    transform: translate(0, 50px) scale(1.2);
    opacity: 0.8;
  }
  75% {
    transform: translate(-50px, -50px) scale(1.1);
    opacity: 0.7;
  }
  100% {
    transform: translate(0, 0) scale(1);
    opacity: 0.6;
  }
}

.container {
  text-align: center;
  background: var(--glass-bg);
  border-radius: 20px;
  padding: clamp(20px, 5vw, 40px);
  backdrop-filter: blur(15px); /* Increased blur for more glass effect */
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), /* Stronger shadow */
              0 0 40px rgba(var(--neon-glow-primary), 0.2), /* Subtle neon container glow */
              0 0 20px rgba(var(--neon-glow-secondary), 0.1);
  border: 3px solid var(--glass-border);
  border-color: rgb(172, 172, 172);
  width: 90vw;
  max-width: 500px;
  position: relative; /* To contain any internal glows */
  overflow: hidden; /* Ensures shadows/glows are contained */
  z-index: 1; /* Bring to front */
}

.title {
  font-size: clamp(2em, 8vw, 3em);
  font-weight: 700;
  margin-bottom: 20px;
  text-shadow: 0 0 15px var(--neon-glow-primary), 0 0 25px var(--neon-glow-secondary); /* Dual color text glow */
  animation: pulseGlow 3s infinite alternate ease-in-out; /* Add subtle title pulse */
}

@keyframes pulseGlow {
  from { text-shadow: 0 0 10px var(--neon-glow-primary), 0 0 20px var(--neon-glow-secondary); }
  to { text-shadow: 0 0 20px var(--neon-glow-primary), 0 0 35px var(--neon-glow-secondary); }
}


.menu {
  margin-bottom: 25px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

input {
  padding: 12px 18px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  outline: none;
  background: rgba(0, 0, 0, 0.2); /* Darker transparent */
  color: white;
  font-family: 'Poppins', sans-serif;
  font-size: 1em;
  font-weight: 400;
  transition: all 0.3s ease;
  flex-grow: 1;
  max-width: 200px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}

input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

input:focus {
  background: rgba(0, 0, 0, 0.3);
  box-shadow: 0 0 20px var(--neon-glow-primary); /* Stronger focus glow */
  border-color: var(--neon-glow-primary);
}

button {
  padding: 12px 25px;
  border: none;
  background: linear-gradient(45deg, var(--color-x), #00aaff); /* Gradient button */
  color: white;
  border-radius: 10px;
  font-weight: 600;
  font-size: 1em;
  font-family: 'Poppins', sans-serif;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: all 0.3s ease;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

button:hover {
  background: linear-gradient(45deg, #00aaff, var(--color-x)); /* Reverse gradient on hover */
  box-shadow: 0 0 25px var(--color-x), 0 0 10px rgba(255,255,255,0.4);
  transform: translateY(-3px);
}

button:active {
  transform: translateY(0) scale(0.96);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

/* --- Responsive Game Board --- */
.board {
  display: grid;
  grid-template-columns: repeat(3, 12vmin);
  grid-template-rows: repeat(3, 12vmin);
  max-width: 330px;
  max-height: 330px;
  gap: 10px;
  justify-content: center;
  margin: 20px auto;
  
}

.cell {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2em, 8vmin, 5em);
  font-weight: 700;
  border-radius: 10px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  cursor: pointer;
  transition: all 0.2s ease;
  transform: scale(0);
  animation: popIn 0.3s ease forwards;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3); /* Add subtle cell shadow */
  position: relative; /* For inner glow effect */
  overflow: hidden;
}

/* Add an internal subtle glow for cells */
.cell::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 10px;
  box-shadow: inset 0 0 15px rgba(var(--neon-glow-primary), 0.05),
              inset 0 0 10px rgba(var(--neon-glow-secondary), 0.05);
  transition: all 0.2s ease;
}

/* Stagger the cell pop-in for a nice effect */
.cell:nth-child(1) { animation-delay: 0.1s; }
.cell:nth-child(2) { animation-delay: 0.15s; }
.cell:nth-child(3) { animation-delay: 0.2s; }
.cell:nth-child(4) { animation-delay: 0.15s; }
.cell:nth-child(5) { animation-delay: 0.2s; }
.cell:nth-child(6) { animation-delay: 0.25s; }
.cell:nth-child(7) { animation-delay: 0.2s; }
.cell:nth-child(8) { animation-delay: 0.25s; }
.cell:nth-child(9) { animation-delay: 0.3s; }

@keyframes popIn {
  to { transform: scale(1); }
}

.cell:hover {
  background: var(--glass-bg-hover);
  transform: scale(1.05);
  border-color: var(--neon-glow-primary); /* Border glows on hover */
}
.cell:hover::before {
    box-shadow: inset 0 0 20px rgba(var(--neon-glow-primary), 0.15),
                inset 0 0 15px rgba(var(--neon-glow-secondary), 0.1);
}


.cell:active {
  transform: scale(0.95);
}

/* --- Player-specific styling with stronger glow --- */
.cell.x {
  color: var(--color-x);
  text-shadow: 0 0 10px var(--color-x), 0 0 20px var(--color-x), 0 0 30px var(--color-x);
}

.cell.o {
  color: var(--color-o);
  text-shadow: 0 0 10px var(--color-o), 0 0 20px var(--color-o), 0 0 30px var(--color-o);
}

/* --- Status Message --- */
.status {
  font-size: 1.2em;
  font-weight: 300;
  margin-top: 20px;
  height: 1.5em;
  transition: color 0.3s ease;
  text-shadow: 0 0 5px rgba(255,255,255,0.5); /* Subtle status text glow */
}

/* --- Refined Win Animation --- */
.win-glow {
  background: linear-gradient(45deg, rgba(var(--color-win), 0.1), rgba(var(--color-win), 0.2)); /* Fading background */
  color: var(--color-win);
  text-shadow: 0 0 15px var(--color-win), 0 0 25px var(--color-win), 0 0 50px var(--color-win);
  border-color: var(--color-win); /* Winning cells' border glows */
  animation: neonGlow 0.8s infinite alternate ease-in-out,
             winPulse 1.2s infinite alternate ease-in-out; /* Add a background pulse */
}

.win-glow::before { /* Make the inner glow more prominent on win */
    box-shadow: inset 0 0 30px rgba(var(--color-win), 0.3),
                inset 0 0 20px rgba(var(--color-win), 0.2);
}


@keyframes neonGlow {
  from {
    box-shadow: 0 0 15px var(--color-win), inset 0 0 15px var(--color-win);
    transform: scale(1);
  }
  to {
    box-shadow: 0 0 30px var(--color-win), inset 0 0 30px var(--color-win);
    transform: scale(1.07);
  }
}

@keyframes winPulse {
  0% { background-color: rgba(var(--color-win), 0.1); }
  100% { background-color: rgba(var(--color-win), 0.25); }
}