/* ════════════════════════════════════════════════════════════
   TIC TAC TOE PRO  ·  style.css
   ════════════════════════════════════════════════════════════ */

/* ── 1. CSS CUSTOM PROPERTIES ──────────────────────────────── */
:root {
  /* Player palette */
  --clr-x:        #e94560;
  --clr-x-glow:   rgba(233, 69, 96, 0.35);
  --clr-x-dim:    rgba(233, 69, 96, 0.12);
  --clr-o:        #4fc3f7;
  --clr-o-glow:   rgba(79, 195, 247, 0.35);
  --clr-o-dim:    rgba(79, 195, 247, 0.12);
  --clr-win:      #f5a623;
  --clr-win-glow: rgba(245, 166, 35, 0.4);

  /* Dark theme (default) */
  --bg:           #080818;
  --glass:        rgba(255, 255, 255, 0.045);
  --glass-border: rgba(255, 255, 255, 0.09);
  --glass-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  --txt:          #f0f0ff;
  --txt-dim:      rgba(240, 240, 255, 0.45);
  --cell-bg:      rgba(255, 255, 255, 0.032);
  --cell-hover:   rgba(255, 255, 255, 0.075);
  --grid-line:    rgba(255, 255, 255, 0.07);
  --score-bg:     rgba(255, 255, 255, 0.04);

  /* Spacing & shape */
  --radius:    16px;
  --radius-sm: 10px;
  --radius-xs: 7px;
  --gap:       14px;

  /* Motion */
  --ease:   cubic-bezier(0.4, 0, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur:    0.25s;
}

[data-theme="light"] {
  --bg:           #eef0f8;
  --glass:        rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.95);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.10);
  --txt:          #12122a;
  --txt-dim:      rgba(18, 18, 42, 0.50);
  --cell-bg:      rgba(255, 255, 255, 0.60);
  --cell-hover:   rgba(255, 255, 255, 0.90);
  --grid-line:    rgba(0, 0, 0, 0.09);
  --score-bg:     rgba(0, 0, 0, 0.04);
}

/* ── 2. RESET & BASE ────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--txt);
  min-height: 100dvh;
  overflow-x: auto;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

/* Ambient glow orbs */
body::before,
body::after {
  content: '';
  position: fixed;
  width: 480px;
  height: 480px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  transition: opacity var(--dur) var(--ease);
}
body::before {
  background: radial-gradient(circle, rgba(233,69,96,0.09) 0%, transparent 70%);
  top: -140px; left: -120px;
}
body::after {
  background: radial-gradient(circle, rgba(79,195,247,0.09) 0%, transparent 70%);
  bottom: -140px; right: -120px;
}

/* ── 3. LAYOUT ──────────────────────────────────────────────── */
/* Main wrapper for 3-column layout (left ad | game | right ad) */
.game-layout-wrapper {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 12px;
  min-height: 100vh;
  align-items: flex-start;
}

.app-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 500px;
  padding: 18px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* Ad sidebars styling */
.ad-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 300px;
  flex-shrink: 0;
}

.ad-sidebar-left {
  /* Left sidebar */
}

.ad-sidebar-right {
  /* Right sidebar */
}

.ad-container {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 8px;
  min-height: 250px;
}

.adsbygoogle {
  display: block;
  min-height: 600px;
}

/* Glass card base */
.glass-card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: var(--radius);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 18px 20px;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

/* ── 4. HEADER ──────────────────────────────────────────────── */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  gap: 12px;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--txt);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all var(--dur) var(--ease);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.back-btn:hover {
  background: var(--cell-hover);
  transform: translateX(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.back-btn:active {
  transform: scale(0.95);
}

.back-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.5;
}

.game-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.5px;
  line-height: 1;
}
.title-x   { color: var(--clr-x); }
.title-sep { color: var(--txt-dim); font-weight: 400; }
.title-o   { color: var(--clr-o); }
.title-label {
  color: var(--txt);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
  margin-left: 4px;
}

.header-controls { 
  display: flex; 
  gap: 8px;
  margin-left: auto;
}

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--txt);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--spring), box-shadow var(--dur) var(--ease);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.icon-btn:hover {
  background: var(--cell-hover);
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.icon-btn:active { transform: scale(0.95); }
.icon-btn svg { width: 17px; height: 17px; pointer-events: none; }

/* ── 5. SETTINGS PANEL ──────────────────────────────────────── */
.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.settings-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--txt-dim);
}

/* Tab group */
.tab-group {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.tab-btn {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--glass-border);
  background: transparent;
  color: var(--txt-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur) var(--ease),
              color var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              transform 0.12s var(--ease);
}
.tab-btn:hover {
  background: var(--cell-hover);
  color: var(--txt);
}
.tab-btn:active { transform: scale(0.97); }
.tab-btn.active {
  background: var(--clr-x);
  border-color: var(--clr-x);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 12px var(--clr-x-glow);
}

/* ── 6. BUTTONS ─────────────────────────────────────────────── */
.primary-btn {
  width: 100%;
  padding: 13px 24px;
  border-radius: var(--radius-sm);
  border: none;
  background: linear-gradient(135deg, #e94560 0%, #b5253c 100%);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: transform 0.18s var(--spring),
              box-shadow 0.18s var(--ease),
              filter 0.18s var(--ease);
}
.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px var(--clr-x-glow);
}
.primary-btn:active { transform: translateY(0); }

.secondary-btn {
  padding: 10px 20px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--txt);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: background var(--dur) var(--ease),
              transform 0.14s var(--spring),
              box-shadow var(--dur) var(--ease);
}
.secondary-btn:hover {
  background: var(--cell-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}
.secondary-btn:active { transform: translateY(0); }

/* ── 7. STATUS BAR ──────────────────────────────────────────── */
.status-bar {
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  transition: border-color var(--dur) var(--ease);
}

.turn-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
}

.player-badge {
  width: 30px; height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 900;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.player-x { background: var(--clr-x-dim); color: var(--clr-x); }
.player-o { background: var(--clr-o-dim); color: var(--clr-o); }

/* AI Thinking indicator */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--clr-o);
  font-weight: 500;
}

.thinking-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}
.thinking-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--clr-o);
  animation: dot-pulse 1.3s var(--ease) infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.75); }
  40%           { opacity: 1;    transform: scale(1.2);  }
}

/* ── 8. BOARD & CELLS ───────────────────────────────────────── */
.board-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
}

.board {
  position: absolute;
  inset: 0;
  display: grid;
  gap: 3px;
  background: var(--grid-line);
  border-radius: var(--radius);
  overflow: hidden;
  animation: board-appear 0.35s var(--ease) both;
}
.board.size-3 { grid-template-columns: repeat(3, 1fr); }
.board.size-4 { grid-template-columns: repeat(4, 1fr); }
.board.size-6 { grid-template-columns: repeat(6, 1fr); }

@keyframes board-appear {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1);    }
}

/* Individual cell */
.cell {
  position: relative;
  background: var(--cell-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: background 0.18s var(--ease);
  -webkit-tap-highlight-color: transparent;
  animation: cell-in 0.3s var(--ease) both;
}

@keyframes cell-in {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1);    }
}

.cell:hover:not(.taken) {
  background: var(--cell-hover);
}
.cell.taken { cursor: default; }

/* Winning cell highlight */
.cell.winner-cell {
  animation: winner-glow 0.9s var(--ease) infinite alternate;
}
@keyframes winner-glow {
  from { background: rgba(245, 166, 35, 0.08); }
  to   { background: rgba(245, 166, 35, 0.22); }
}

/* ── 9. MARKS (SVG ANIMATED) ────────────────────────────────── */
.mark {
  width: 58%;
  height: 58%;
  overflow: visible;
  display: block;
}

/* X lines */
.x-line1, .x-line2 {
  stroke: var(--clr-x);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 90;
  stroke-dashoffset: 90;
  filter: drop-shadow(0 0 4px var(--clr-x-glow));
}
.x-line1 { animation: draw-stroke 0.22s var(--ease) forwards; }
.x-line2 { animation: draw-stroke 0.22s var(--ease) 0.11s forwards; }

/* O circle */
.o-circle {
  fill: none;
  stroke: var(--clr-o);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 195;
  stroke-dashoffset: 195;
  filter: drop-shadow(0 0 4px var(--clr-o-glow));
  animation: draw-stroke 0.38s var(--ease) forwards;
}

/* Thinner strokes for 6×6 (cells are ~half the size) */
.board.size-6 .x-line1,
.board.size-6 .x-line2 { stroke-width: 11; }  /* viewBox is 100×100 so same units, lighter feel */
.board.size-6 .o-circle { stroke-width: 11; }

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

/* Winning mark glow boost */
.winner-cell .x-line1,
.winner-cell .x-line2 {
  filter: drop-shadow(0 0 8px var(--clr-x));
}
.winner-cell .o-circle {
  filter: drop-shadow(0 0 8px var(--clr-o));
}

/* ── 10. WIN LINE SVG ───────────────────────────────────────── */
.win-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}

#win-line {
  stroke-linecap: round;
}
#win-line.animate {
  animation: draw-win 0.45s var(--ease) forwards;
}
@keyframes draw-win {
  to { stroke-dashoffset: 0; }
}

/* ── 11. RESULT OVERLAY ─────────────────────────────────────── */
.result-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: rgba(8, 8, 24, 0.68);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in 0.28s var(--ease);
}
[data-theme="light"] .result-overlay {
  background: rgba(238, 240, 248, 0.75);
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.result-card {
  text-align: center;
  padding: 28px 22px;
  width: min(92%, 280px);
  animation: pop-in 0.38s var(--spring) both;
}
@keyframes pop-in {
  from { transform: scale(0.75) translateY(10px); opacity: 0; }
  to   { transform: scale(1)    translateY(0);    opacity: 1; }
}

.result-emoji {
  font-size: 52px;
  line-height: 1;
  margin-bottom: 12px;
  animation: emoji-bounce 0.55s var(--spring) 0.1s both;
}
@keyframes emoji-bounce {
  from { transform: scale(0.4) rotate(-12deg); opacity: 0; }
  to   { transform: scale(1)   rotate(0);      opacity: 1; }
}

.result-title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 5px;
  letter-spacing: -0.3px;
}
.result-sub {
  font-size: 13px;
  color: var(--txt-dim);
  margin-bottom: 22px;
  line-height: 1.5;
}
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-actions .primary-btn  { padding: 11px; font-size: 14px; }
.result-actions .secondary-btn { padding: 9px 16px; font-size: 13px; width: 100%; text-align: center; }

/* ── 12. SCOREBOARD ─────────────────────────────────────────── */
.scoreboard-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--txt-dim);
  text-align: center;
  margin-bottom: 14px;
}

.score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.score-card {
  text-align: center;
  padding: 12px 8px;
  border-radius: var(--radius-xs);
  background: var(--score-bg);
  border-top: 2px solid transparent;
}
.score-x    { border-top-color: var(--clr-x); }
.score-draw { border-top-color: var(--txt-dim); }
.score-o    { border-top-color: var(--clr-o); }

.score-name {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--txt-dim);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-val {
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -1px;
  transition: transform 0.3s var(--spring), color var(--dur) var(--ease);
}
.score-x .score-val    { color: var(--clr-x); }
.score-draw .score-val { color: var(--txt-dim); }
.score-o .score-val    { color: var(--clr-o); }

.score-val.pop {
  animation: score-pop 0.4s var(--spring);
}
@keyframes score-pop {
  0%   { transform: scale(1);   }
  50%  { transform: scale(1.5); }
  100% { transform: scale(1);   }
}

/* ── 13. CONTROLS ───────────────────────────────────────────── */
.game-controls {
  display: flex;
  justify-content: center;
}
.game-controls .secondary-btn {
  padding: 11px 32px;
  font-size: 14px;
}

/* ── 14. CONFETTI PARTICLES ─────────────────────────────────── */
#particles-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}

.confetti {
  position: absolute;
  top: -16px;
  pointer-events: none;
  animation: confetti-fall linear forwards;
  border-radius: 2px;
}
@keyframes confetti-fall {
  0%   { transform: translateY(0)     rotate(0deg)   scaleX(1);   opacity: 1; }
  70%  { opacity: 1; }
  100% { transform: translateY(110vh) rotate(600deg) scaleX(0.5); opacity: 0; }
}

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

.cell:focus-visible {
  outline: 2px solid var(--clr-x);
  outline-offset: -2px;
  z-index: 1;
}
.tab-btn:focus-visible,
.primary-btn:focus-visible,
.secondary-btn:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid var(--clr-x);
  outline-offset: 2px;
}

/* ── 16. RESPONSIVE ─────────────────────────────────────────── */

/* Tablets & below: hide side ads, stack vertically */
@media (max-width: 1024px) {
  .game-layout-wrapper {
    flex-direction: column;
    gap: 16px;
    align-items: center;
  }

  .ad-sidebar {
    width: 100%;
    max-width: 500px;
    flex-direction: row;
    gap: 12px;
    flex-wrap: wrap;
  }

  .ad-sidebar-left,
  .ad-sidebar-right {
    width: 100%;
  }

  .ad-container {
    min-height: auto;
    max-height: 120px;
  }

  .adsbygoogle {
    min-height: auto;
  }
}

/* Mobile: hide ads completely and adjust title */
@media (max-width: 768px) {
  .game-layout-wrapper {
    padding: 8px;
  }

  .ad-sidebar {
    display: none;
  }

  .game-header {
    flex-wrap: wrap;
  }

  .back-btn {
    padding: 6px 10px;
    font-size: 12px;
    gap: 4px;
    min-width: auto;
  }

  .back-btn svg {
    width: 14px;
    height: 14px;
  }

  .game-title {
    flex: 1;
  }

  .header-controls {
    gap: 6px;
    margin-left: 0;
  }
}

@media (max-width: 420px) {
  .app-container    { padding: 12px 12px 24px; gap: 11px; }
  .game-title       { font-size: 19px; }
  .title-label      { font-size: 14px; }
  .glass-card       { padding: 14px 15px; }
  .tab-btn          { font-size: 12px; padding: 7px 8px; }
  .result-emoji     { font-size: 44px; }
  .result-title     { font-size: 20px; }
  .score-val        { font-size: 26px; }
  .icon-btn         { width: 36px; height: 36px; }

  .game-header {
    padding: 2px 0;
  }

  .game-title {
    flex: 1;
  }

  .back-btn {
    padding: 6px 8px;
    font-size: 11px;
    gap: 3px;
    border-radius: 6px;
  }

  .back-btn span {
    display: none;
  }

  .back-btn svg {
    width: 12px;
    height: 12px;
  }

  .header-controls {
    gap: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
