@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;500;600&display=swap');

/* ── Custom Properties ── */
:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.65);
  --bg-cell: #151d2e;
  --bg-cell-hover: #1e2a42;

  --accent-cyan: #22d3ee;
  --accent-violet: #a78bfa;
  --accent-pink: #f472b6;
  --accent-emerald: #34d399;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --glow-cyan: rgba(34, 211, 238, 0.35);
  --glow-violet: rgba(167, 139, 250, 0.35);
  --glow-pink: rgba(244, 114, 182, 0.35);
  --glow-emerald: rgba(52, 211, 153, 0.45);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --radius-full: 999px;

  --transition-fast: 0.1s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-bounce: 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Reset ── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ── Animated Background ── */
body {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 2rem 1rem;
  overflow-x: hidden;
  position: relative;
}

/* Subtle moving gradient orbs behind content */
body::before,
body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  filter: blur(100px);
  z-index: 0;
  pointer-events: none;
  animation: orbFloat 12s ease-in-out infinite alternate;
}

body::before {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.12), transparent 70%);
  top: -10%;
  left: -8%;
}

body::after {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(167, 139, 250, 0.10), transparent 70%);
  bottom: -15%;
  right: -10%;
  animation-delay: -6s;
}

@keyframes orbFloat {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(30px, -20px) scale(1.08); }
  100% { transform: translate(-15px, 15px) scale(0.95); }
}

/* ── Layout ── */
main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.5rem;
  width: 100%;
  max-width: 520px;
  position: relative;
  z-index: 1;
}

/* ── Title ── */
h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 3.2rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  user-select: none;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-violet), var(--accent-pink));
  background-size: 200% 200%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 24px var(--glow-cyan));
  animation: gradientShift 6s ease-in-out infinite;
  position: relative;
}

/* Decorative line under title */
h1::after {
  content: '';
  display: block;
  width: 60%;
  height: 3px;
  margin: 0.6rem auto 0;
  background: linear-gradient(90deg, transparent, var(--accent-cyan), var(--accent-violet), transparent);
  border-radius: var(--radius-full);
  opacity: 0.6;
}

@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50%      { background-position: 100% 50%; }
}

/* ── Shared Animations ── */
@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes subtlePulse {
  0%, 100% { opacity: 0.7; }
  50%      { opacity: 1; }
}

@keyframes popIn {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

.fade-in {
  animation: fadeSlideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ── Utility ── */
.hidden {
  display: none !important;
}

/* ═══════════════════════════════════════
   MODE SELECTION SCREEN
   ═══════════════════════════════════════ */
.mode-screen {
  width: 100%;
}

.mode-card {
  background: var(--bg-card);
  padding: 2.8rem 2.2rem;
  border-radius: var(--radius-xl);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  box-shadow:
    0 30px 60px -15px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.06);
  text-align: center;
  position: relative;
  overflow: hidden;
}

/* Decorative shimmer across the card */
.mode-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.03),
    transparent
  );
  animation: shimmer 4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes shimmer {
  0%   { left: -100%; }
  100% { left: 200%; }
}

.mode-card h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.75rem;
  margin-bottom: 0.35rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-violet));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.mode-card .subtitle {
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 400;
  margin-bottom: 2rem;
  letter-spacing: 0.02em;
}

/* ── Mode Buttons ── */
.mode-options {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.mode-btn {
  background: var(--bg-cell);
  border: 1.5px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  padding: 18px 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 18px;
  text-align: left;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-smooth),
    box-shadow var(--transition-smooth);
  box-shadow:
    inset 0 1px 2px rgba(0, 0, 0, 0.25),
    0 4px 8px rgba(0, 0, 0, 0.12);
  position: relative;
  overflow: hidden;
}

/* Glow line on hover */
.mode-btn::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: 100%;
  background: linear-gradient(180deg, var(--accent-cyan), var(--accent-violet));
  opacity: 0;
  transition: opacity var(--transition-fast);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.mode-btn:hover::after {
  opacity: 1;
}

.mode-btn:hover {
  background: var(--bg-cell-hover);
  border-color: rgba(34, 211, 238, 0.25);
  transform: translateY(-3px);
  box-shadow:
    0 12px 28px -8px rgba(34, 211, 238, 0.2),
    0 0 0 1px rgba(34, 211, 238, 0.08);
}

.mode-btn.selected {
  background: rgba(34, 211, 238, 0.08);
  border-color: var(--accent-cyan);
  box-shadow:
    0 0 20px rgba(34, 211, 238, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.mode-btn.selected::after {
  opacity: 1;
}

.mode-icon {
  font-size: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.08), rgba(167, 139, 250, 0.08));
  transition: transform var(--transition-bounce);
  flex-shrink: 0;
}

.mode-btn:hover .mode-icon {
  transform: scale(1.12) rotate(4deg);
}

.mode-btn-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mode-btn-title {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.mode-btn-desc {
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* ── Difficulty Section ── */
.difficulty-section {
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  animation: fadeSlideUp 0.35s ease both;
}

.difficulty-section h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.difficulty-options {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 1.6rem;
}

.diff-btn {
  background: var(--bg-cell);
  border: 1.5px solid rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 10px 26px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  letter-spacing: 0.03em;
}

.diff-btn:hover {
  background: var(--bg-cell-hover);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.12);
}

.diff-btn.active {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-violet));
  color: var(--bg-primary);
  font-weight: 700;
  border-color: transparent;
  box-shadow:
    0 4px 18px var(--glow-cyan),
    0 0 0 1px rgba(34, 211, 238, 0.3);
}

.start-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-violet));
  color: var(--bg-primary);
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: none;
  padding: 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-smooth);
  box-shadow: 0 6px 20px -4px var(--glow-cyan);
  position: relative;
  overflow: hidden;
}

.start-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.start-btn:hover::before {
  opacity: 1;
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px -4px var(--glow-cyan);
}

.start-btn:active {
  transform: translateY(0);
}

/* ═══════════════════════════════════════
   GAME BOARD
   ═══════════════════════════════════════ */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  width: 100%;
}

.game-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.1), rgba(167, 139, 250, 0.1));
  color: var(--accent-cyan);
  padding: 6px 16px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(34, 211, 238, 0.15);
  backdrop-filter: blur(8px);
}

.status {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  background: var(--bg-card);
  padding: 12px 28px;
  border-radius: var(--radius-full);
  backdrop-filter: blur(12px);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.04);
  transition: all 0.35s ease;
  min-width: 220px;
  text-align: center;
}

/* ── Grid ── */
.boxes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  background: var(--bg-card);
  padding: 20px;
  border-radius: var(--radius-lg);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  box-shadow:
    0 30px 60px -15px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.05);
  position: relative;
}

/* Subtle corner glow accents */
.boxes::before,
.boxes::after {
  content: '';
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.3;
  pointer-events: none;
  z-index: 0;
}

.boxes::before {
  top: -20px;
  left: -20px;
  background: var(--accent-cyan);
}

.boxes::after {
  bottom: -20px;
  right: -20px;
  background: var(--accent-violet);
}

.box {
  width: 100px;
  height: 100px;
  background: var(--bg-cell);
  border: 1.5px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 3rem;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.2),
    0 2px 4px rgba(0, 0, 0, 0.1);
  line-height: 1;
  position: relative;
  z-index: 1;
}

.box:hover {
  background: var(--bg-cell-hover);
  border-color: rgba(255, 255, 255, 0.08);
  transform: translateY(-2px) scale(1.03);
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.2),
    0 8px 20px -6px rgba(0, 0, 0, 0.3);
}

.box:active {
  transform: translateY(0) scale(0.97);
  box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.35);
}

.box.x {
  color: var(--accent-cyan);
  text-shadow: 0 0 18px var(--glow-cyan);
  border-color: rgba(34, 211, 238, 0.15);
  animation: popIn 0.18s var(--transition-bounce) both;
}

.box.o {
  color: var(--accent-pink);
  text-shadow: 0 0 18px var(--glow-pink);
  border-color: rgba(244, 114, 182, 0.15);
  animation: popIn 0.18s var(--transition-bounce) both;
}

.win-highlight {
  background: rgba(52, 211, 153, 0.15) !important;
  border-color: rgba(52, 211, 153, 0.35) !important;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.2),
    0 0 24px var(--glow-emerald),
    0 0 0 2px rgba(52, 211, 153, 0.2) !important;
  transform: scale(1.08);
  z-index: 2;
  animation: winPulse 1.2s ease-in-out infinite;
}

@keyframes winPulse {
  0%, 100% {
    box-shadow:
      inset 0 2px 4px rgba(0, 0, 0, 0.2),
      0 0 20px var(--glow-emerald),
      0 0 0 2px rgba(52, 211, 153, 0.2);
  }
  50% {
    box-shadow:
      inset 0 2px 4px rgba(0, 0, 0, 0.2),
      0 0 32px var(--glow-emerald),
      0 0 0 4px rgba(52, 211, 153, 0.12);
  }
}

/* ── Controls ── */
.controls {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.reset-btn {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-violet));
  color: var(--bg-primary);
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: none;
  padding: 12px 28px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-smooth);
  box-shadow: 0 4px 16px -4px var(--glow-cyan);
  position: relative;
  overflow: hidden;
}

.reset-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.reset-btn:hover::before {
  opacity: 1;
}

.reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px -4px var(--glow-cyan);
}

.reset-btn:active {
  transform: translateY(0);
}

.change-mode-btn {
  background: transparent;
  color: var(--accent-cyan);
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  border: 1.5px solid rgba(34, 211, 238, 0.3);
  padding: 12px 28px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-smooth);
}

.change-mode-btn:hover {
  background: rgba(34, 211, 238, 0.06);
  border-color: var(--accent-cyan);
  transform: translateY(-2px);
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.15);
}

.change-mode-btn:active {
  transform: translateY(0);
}

/* ── Responsive ── */
@media (max-width: 480px) {
  body {
    padding: 1.5rem 0.8rem;
  }

  h1 {
    font-size: 2.4rem;
    letter-spacing: 0.1em;
  }

  h1::after {
    width: 50%;
  }

  .mode-card {
    padding: 2rem 1.4rem;
    border-radius: var(--radius-lg);
  }

  .mode-card h2 {
    font-size: 1.4rem;
  }

  .box {
    width: 82px;
    height: 82px;
    font-size: 2.4rem;
  }

  .boxes {
    gap: 10px;
    padding: 14px;
    border-radius: var(--radius-md);
  }

  .controls {
    flex-direction: column;
    width: 100%;
    padding: 0 0.8rem;
  }

  .reset-btn,
  .change-mode-btn {
    width: 100%;
    text-align: center;
    justify-content: center;
  }
}

/* ── Selection / Focus ── */
button:focus-visible {
  outline: 2px solid var(--accent-cyan);
  outline-offset: 2px;
}

::selection {
  background: rgba(34, 211, 238, 0.3);
  color: var(--text-primary);
}
