:root {
  --bg: #0f172a;
  --card: #020617;
  --accent-x: #22c55e;
  --accent-o: #3b82f6;
  --line: #1f2937;
  --text-main: #e5e7eb;
  --text-sub: #9ca3af;
  --danger: #f97373;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, sans-serif;
  background: radial-gradient(circle at top, #1e293b 0, #020617 60%);
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 16px;
}

.wrap {
  width: 100%;
  max-width: 480px;
  background: linear-gradient(145deg, #020617, #020617ee);
  border-radius: 24px;
  padding: 24px 20px 20px;
  box-shadow:
    0 20px 50px rgba(0,0,0,0.7),
    0 0 0 1px rgba(148,163,184,0.15);
}

.title {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.subtitle {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-sub);
  margin-bottom: 12px;
}

/* mode buttons */
.mode-toggle {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}

.mode-btn {
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  background: rgba(15, 23, 42, 0.8);
  color: var(--text-sub);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.mode-btn:hover {
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.8);
}

.mode-active {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  border-color: transparent;
  box-shadow: 0 8px 20px rgba(34, 197, 94, 0.55);
}

.difficulty-row {
  display: flex;
  justify-content: flex-start;   /* was: center */
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 0.8rem;
  color: var(--text-sub);
  width: fit-content;            /* so it hugs the text/buttons */
}

.difficulty-label {
  opacity: 0.9;
}

.diff-btn {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(148,163,184,0.5);
  background: rgba(15,23,42,0.9);
  color: var(--text-sub);
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.diff-btn:hover {
  box-shadow: 0 5px 12px rgba(15,23,42,0.9);
}

.diff-active {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  border-color: transparent;
  box-shadow: 0 6px 16px rgba(34,197,94,0.55);
}

.hidden {
  display: none;
}

.status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(15,23,42,0.8);
  border: 1px solid rgba(148,163,184,0.2);
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.turn {
  font-weight: 600;
  font-size: 0.95rem;
}

.turn span {
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
}

.turn-x span {
  background: rgba(34,197,94,0.15);
  border: 1px solid rgba(34,197,94,0.5);
  color: var(--accent-x);
}

.turn-o span {
  background: rgba(59,130,246,0.15);
  border: 1px solid rgba(59,130,246,0.5);
  color: var(--accent-o);
}

.message {
  font-size: 0.85rem;
  color: var(--text-sub);
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 16px;
}

.cell {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: radial-gradient(circle at top, #111827, #020617);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.6rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease,
              border-color 0.15s ease, background 0.2s ease;
  user-select: none;
}

.cell:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(15,23,42,0.9);
  border-color: rgba(148,163,184,0.6);
}

.cell.x {
  color: var(--accent-x);
  text-shadow: 0 0 18px rgba(34,197,94,0.55);
}

.cell.o {
  color: var(--accent-o);
  text-shadow: 0 0 18px rgba(59,130,246,0.55);
}

/* Winning cells – keep glowing until board is cleared */
.cell.winning {
  position: relative;
  background: radial-gradient(circle at center,
    rgba(250, 204, 21, 0.35),
    rgba(249, 115, 22, 0.10) 65%,
    #020617 100%
  );
  border-color: #fbbf24;
  box-shadow:
    0 0 18px rgba(250, 204, 21, 0.9),
    0 0 32px rgba(249, 115, 22, 0.7);
  transform: scale(1.04);
  animation: winPulse 0.28s ease-out;   /* small pop, glow stays */
}

/* Winning cells in LIGHT mode – same idea, brighter */
body.light-mode .cell.winning {
  position: relative;
  background: radial-gradient(circle at center,
    rgba(253, 224, 71, 0.55),
    rgba(251, 146, 60, 0.25) 65%,
    #fefce8 100%
  );
  border-color: #fbbf24;
  box-shadow:
    0 0 22px rgba(249, 115, 22, 0.7),
    0 0 38px rgba(251, 191, 36, 0.8);
  transform: scale(1.04);
  animation: winPulse 0.28s ease-out;
}

@keyframes winPulse {
  0%   { transform: scale(1.0); }
  60%  { transform: scale(1.08); }
  100% { transform: scale(1.04); }
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* settings row (sound on/off/vibrate button) */
.settings-row {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 10px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.settings-btn {
  padding: 6px 10px;
  font-size: 0.75rem;
}

.btn {
  border-radius: 999px;
  padding: 8px 16px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.08s ease, box-shadow 0.08s ease,
              background 0.15s ease, filter 0.15s ease;
  white-space: nowrap;
}

.btn span.icon {
  font-size: 1.1rem;
}

.btn-primary {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  box-shadow: 0 10px 25px rgba(34,197,94,0.55);
}

.btn-primary:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-sub);
  border: 1px dashed rgba(148,163,184,0.6);
}

.btn-ghost:hover {
  background: rgba(15,23,42,0.8);
  border-style: solid;
}

.scoreboard {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px dashed rgba(148,163,184,0.4);
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-sub);
  gap: 10px;
}

.score-x {
  color: var(--accent-x);
  font-weight: 600;
}

.score-o {
  color: var(--accent-o);
  font-weight: 600;
}

.score-draw {
  color: var(--danger);
  font-weight: 500;
}

/* Light mode overrides */
body.light-mode {
  background: radial-gradient(circle at top, #e5e7eb 0, #f9fafb 60%);
  color: #020617;
}

body.light-mode .wrap {
  background: linear-gradient(145deg, #ffffff, #e5e7eb);
  box-shadow:
    0 16px 35px rgba(148,163,184,0.55),
    0 0 0 1px rgba(148,163,184,0.35);
}

body.light-mode .status {
  background: rgba(248,250,252,0.95);
  border-color: rgba(148,163,184,0.6);
}

body.light-mode .message {
  color: #6b7280;
}

body.light-mode .cell {
  background: radial-gradient(circle at top, #f9fafb, #e5e7eb);
  border-color: #e5e7eb;
  box-shadow: none;
}

body.light-mode .cell:hover {
  box-shadow: 0 8px 14px rgba(148,163,184,0.6);
  border-color: #cbd5f5;
}

body.light-mode .btn-ghost,
body.light-mode .settings-btn {
  color: #4b5563;
  border-color: rgba(148,163,184,0.9);
}

body.light-mode .subtitle,
body.light-mode .scoreboard,
body.light-mode .score-draw,
body.light-mode .score-x,
body.light-mode .score-o {
  color: #374151;
}

body.light-mode .mode-btn {
  background: #f9fafb;
  color: #4b5563;
  border-color: rgba(148, 163, 184, 0.8);
}

body.light-mode .mode-active {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  box-shadow: 0 8px 18px rgba(34, 197, 94, 0.5);
}

body.light-mode .diff-btn {
  background: #f9fafb;
  color: #4b5563;
}

body.light-mode .diff-active {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  box-shadow: 0 6px 16px rgba(34,197,94,0.5);
}

@media (max-width: 480px) {
  .wrap {
    border-radius: 18px;
    padding: 18px 14px 14px;
  }
  .title {
    font-size: 1.3rem;
  }
  .cell {
    border-radius: 16px;
    font-size: 2.2rem;
  }
}

/* ------------ WIN CROWN + CLAP ANIMATIONS ------------ */

.crown {
  text-align: center;
  font-size: 3rem;
  margin-top: 8px;
  margin-bottom: 4px;
  opacity: 0;
  transform: translateY(-16px) scale(0.9);
  transition: opacity 0.45s ease-out, transform 0.45s ease-out;
}

.crown.active {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Clap emoji burst */
.clap-container {
  position: fixed;
  top: 8px;
  left: 0;
  width: 100%;
  pointer-events: none;
  z-index: 50;
}

.clap {
  position: absolute;
  font-size: 2rem;
  animation: clap-fall 1.2s linear forwards;
}

@keyframes clap-fall {
  0% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateY(120px) scale(1.3);
    opacity: 0;
  }
}

/* ----------------------------------------------------------
   RESPONSIVE LAYOUT
   Works cleanly on:
   - All iPhones
   - All iPads & tablets
   - Desktop screens
   - Safari / Chrome / Firefox
   - PWA (Add to Home Screen)
----------------------------------------------------------- */

/* Center and control container width */
.wrap {
  max-width: 460px;
  margin: 0 auto;
  padding: 16px 12px 24px;
}

/* Top bar: modes on the left, sound/light on the right */
.top-bar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: nowrap;      /* keep everything on one line */
  gap: 8px;
  width: 100%;
}

/* Push SOUND / Light to the right */
.top-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Keep mode buttons from shrinking */
.mode-toggle {
  flex-shrink: 0;
}

/* Keep Sound/Light buttons on one line */
#avToggle,
#themeToggle {
  white-space: nowrap;
}

/* ------------------- PHONES ------------------- */
@media (max-width: 480px) {
  body {
    padding: 8px 4px;
  }

  .wrap {
    max-width: 100%;
    padding: 14px 10px 20px;
  }

  .top-bar {
    gap: 6px;
  }

  .mode-btn,
  #avToggle,
  #themeToggle {
    font-size: 0.78rem;
    padding: 5px 10px;
  }

  /* Level row text smaller */
  .difficulty-row {
    font-size: 0.8rem;
  }

  /* Slightly smaller cells on narrow screens */
  .cell {
    border-radius: 14px;
    font-size: 2rem;
  }
}

/* ------------------- TABLETS ------------------- */
@media (min-width: 481px) and (max-width: 1024px) {
  .wrap {
    max-width: 520px;
  }
  .top-bar {
    gap: 10px;
  }
}

/* Small toggle for compact Light button (if you add .small-toggle in HTML) */
.small-toggle {
  min-width: auto;
  width: auto;
  padding: 4px 10px !important;
  font-size: 0.7rem !important;
  line-height: 1.2;
  white-space: nowrap;
}

/* =========================================
   EMOJI PULSE GLOW (TITLE CONTROLLERS)
   ========================================= */

.pulse-emoji {
  display: inline-block;
  animation: emojiPulse 2.5s ease-in-out infinite;
  transform-origin: center;
}

/* Bigger pulse + soft neon glow at the peak */
@keyframes emojiPulse {
  0% {
    transform: scale(1);
    opacity: 1;
    text-shadow: 0 0 0 rgba(0, 255, 180, 0);
  }
  50% {
    transform: scale(1.22); /* was 1.15 → bigger pulse */
    opacity: 0.9;
    text-shadow:
      0 0 6px rgba(0, 255, 180, 0.8),
      0 0 12px rgba(0, 200, 255, 0.7);
  }
  100% {
    transform: scale(1);
    opacity: 1;
    text-shadow: 0 0 0 rgba(0, 255, 180, 0);
  }
}

/* =========================================
   TITLE NEON GRADIENT + SOFT FLICKER
   ========================================= */

.title {
  font-weight: 700;
  letter-spacing: 0.02em;
  /* Gradient text */
  background: linear-gradient(120deg, #7afcff, #35ff69, #fff35c);
  background-size: 220% 220%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;

  /* Slow shimmer / flicker */
  animation: titleNeon 6s ease-in-out infinite;
}

/* Slow shimmer + glow, not a crazy strobe */
@keyframes titleNeon {
  0% {
    filter: none;
    text-shadow: none;
    background-position: 0% 50%;
  }
  35% {
    filter: brightness(1.1);
    text-shadow:
      0 0 6px rgba(0, 255, 180, 0.5),
      0 0 14px rgba(0, 200, 255, 0.4);
    background-position: 40% 50%;
  }
  50% {
    filter: brightness(1.2);
    text-shadow:
      0 0 8px rgba(0, 255, 220, 0.7),
      0 0 18px rgba(0, 200, 255, 0.6);
    background-position: 60% 50%;
  }
  100% {
    filter: none;
    text-shadow: none;
    background-position: 100% 50%;
  }
}

/* prevent title neon from affecting emoji controllers */
.title .pulse-emoji {
  background: none !important;
  background-clip: border-box !important;
  -webkit-background-clip: border-box !important;

  /* this is the key: make them visible again */
  -webkit-text-fill-color: initial !important;
  color: #fff !important;

  /* force their own pulse animation, not the title's */
  animation: emojiPulse 2.5s ease-in-out infinite !important;

  /* don't inherit title's filter/glow */
  filter: none !important;
  mix-blend-mode: normal !important;
}

/* QUICK FIX: Prevent controls from wrapping or shifting */
.top-controls, .mode-buttons, .toggle-buttons {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  overflow-x: auto;       /* allow scroll instead of wrap if needed */
  scrollbar-width: none;  /* hide scrollbar (Firefox) */
}

.top-controls::-webkit-scrollbar,
.mode-buttons::-webkit-scrollbar,
.toggle-buttons::-webkit-scrollbar {
  display: none;          /* hide scrollbar (Safari/Chrome) */
}

/* Prevent buttons from stretching too tall or wide */
.top-controls button,
.mode-buttons button,
.toggle-buttons button {
  flex: 0 0 auto;
  white-space: nowrap;
}