:root {
  --bg-main: #090c15;
  --bg-card: rgba(18, 24, 40, 0.75);
  --bg-card-hover: rgba(26, 35, 58, 0.85);
  --bg-cell: rgba(15, 21, 37, 0.8);
  --bg-cell-hover: rgba(28, 38, 66, 0.9);
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(0, 240, 255, 0.3);
  
  --color-x: #00f0ff;
  --color-x-glow: rgba(0, 240, 255, 0.45);
  --color-x-dark: #0284c7;
  
  --color-o: #ff3366;
  --color-o-glow: rgba(255, 51, 102, 0.45);
  --color-o-dark: #e11d48;
  
  --color-draw: #f59e0b;
  --color-draw-glow: rgba(245, 158, 11, 0.4);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
  
  --shadow-card: 0 16px 40px -8px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--border-subtle);
  --shadow-neon-x: 0 0 25px var(--color-x-glow);
  --shadow-neon-o: 0 0 25px var(--color-o-glow);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  line-height: 1.5;
  selection-background-color: var(--color-x);
  selection-color: #000;
}

/* Background Atmosphere Glow */
.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  pointer-events: none;
  z-index: 0;
}
.bg-glow-1 {
  width: 450px;
  height: 450px;
  background: radial-gradient(circle, rgba(0, 240, 255, 0.15) 0%, rgba(0,0,0,0) 70%);
  top: -100px;
  left: -100px;
}
.bg-glow-2 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(255, 51, 102, 0.13) 0%, rgba(0,0,0,0) 70%);
  bottom: -100px;
  right: -100px;
}

#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

/* Floating Reactions Container */
#reactions-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 950;
  overflow: hidden;
}

.floating-reaction {
  position: absolute;
  font-size: 2.4rem;
  bottom: 60px;
  user-select: none;
  animation: floatUp 2.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5));
}

@keyframes floatUp {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.6) rotate(0deg);
  }
  15% {
    opacity: 1;
    transform: translateY(-40px) scale(1.2) rotate(-8deg);
  }
  75% {
    opacity: 1;
    transform: translateY(-260px) scale(1) rotate(12deg);
  }
  100% {
    opacity: 0;
    transform: translateY(-380px) scale(0.8) rotate(20deg);
  }
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  position: relative;
  z-index: 10;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(0,240,255,0.15), rgba(255,51,102,0.15));
  border: 1px solid rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 1.1rem;
  font-weight: 900;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.brand-icon .x-mark {
  color: var(--color-x);
  text-shadow: 0 0 10px var(--color-x-glow);
}
.brand-icon .o-mark {
  color: var(--color-o);
  text-shadow: 0 0 10px var(--color-o-glow);
}

.brand-text h1 {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  background: linear-gradient(120deg, #ffffff 40%, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-tag {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-x);
  opacity: 0.9;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.online-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.25);
  font-size: 0.82rem;
  color: #34d399;
  transition: all 0.25s ease;
}

.online-badge strong {
  display: inline-block;
  transition: transform 0.2s ease, color 0.2s ease;
}

.number-pulse {
  transform: scale(1.4);
  color: #a7f3d0 !important;
  text-shadow: 0 0 10px rgba(52, 211, 153, 0.8);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10b981;
  animation: pulseDot 2s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.6; }
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

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

.icon-btn {
  padding: 8px 10px;
}

.icon {
  width: 17px;
  height: 17px;
}

/* Layout Grid */
.main-content {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 28px;
  align-items: start;
}

/* Left: Game Section */
.game-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
}

/* Status Card */
.game-status-card {
  width: 100%;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-subtle);
  transition: border-color 0.3s ease;
}

.round-badge-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 0.78rem;
}

.round-badge {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 3px 10px;
  border-radius: 6px;
  letter-spacing: 0.05em;
}

.mode-tag {
  color: #38bdf8;
  font-weight: 600;
}

.turn-indicator-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.turn-label {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
}

.turn-player-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  border-radius: 999px;
  font-size: 1.25rem;
  font-weight: 800;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.turn-player-badge.turn-x {
  background: rgba(0, 240, 255, 0.12);
  border: 1px solid var(--color-x);
  color: var(--color-x);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.25);
}

.turn-player-badge.turn-o {
  background: rgba(255, 51, 102, 0.12);
  border: 1px solid var(--color-o);
  color: var(--color-o);
  box-shadow: 0 0 20px rgba(255, 51, 102, 0.25);
}

.turn-hint {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Game Over Banner */
.game-over-banner {
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fadeInPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes fadeInPop {
  0% { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.winner-title-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.winner-icon {
  font-size: 2.2rem;
  line-height: 1;
  animation: bounceTrophy 1s infinite alternate ease-in-out;
}

@keyframes bounceTrophy {
  from { transform: translateY(0); }
  to { transform: translateY(-6px); }
}

.winner-info h2 {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.2;
}

.winner-info p {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.restart-timer-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0, 0, 0, 0.3);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.restart-progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.restart-progress-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--color-x), var(--color-o));
  border-radius: 999px;
  transition: width 0.1s linear;
}

.restart-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.restart-countdown {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.restart-countdown strong {
  color: #fff;
  font-family: var(--font-mono);
}

.btn-primary-small {
  padding: 6px 14px;
  border-radius: 8px;
  background: linear-gradient(135deg, #0284c7, #2563eb);
  border: none;
  color: #fff;
  font-family: var(--font-main);
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary-small:hover {
  transform: translateY(-1px);
  filter: brightness(1.15);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

/* 3x3 Board Arena */
.board-wrapper {
  position: relative;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 1 / 1;
  margin: 4px auto;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.03);
  padding: 10px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card), inset 0 0 30px rgba(0,0,0,0.5);
}

.grid-cell {
  background: var(--bg-cell);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.grid-cell:hover:not(.taken) {
  background: var(--bg-cell-hover);
  border-color: rgba(255, 255, 255, 0.25);
  transform: scale(1.02);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.grid-cell:active:not(.taken) {
  transform: scale(0.96);
}

.grid-cell.taken {
  cursor: default;
}

/* SVG Symbols inside Cell */
.cell-symbol-svg {
  width: 65%;
  height: 65%;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4));
}

.symbol-x-path {
  stroke: var(--color-x);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  animation: drawStroke 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  filter: drop-shadow(0 0 8px var(--color-x-glow));
}

.symbol-o-path {
  stroke: var(--color-o);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 250;
  stroke-dashoffset: 250;
  animation: drawStroke 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  filter: drop-shadow(0 0 8px var(--color-o-glow));
}

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

/* Winning highlight on cells */
.grid-cell.winning-cell {
  background: rgba(255, 255, 255, 0.12);
  border-color: #fff;
  animation: pulseWinCell 1.2s infinite alternate ease-in-out;
}

@keyframes pulseWinCell {
  0% { transform: scale(1); box-shadow: 0 0 10px rgba(255,255,255,0.2); }
  100% { transform: scale(1.04); box-shadow: 0 0 25px rgba(255,255,255,0.6); }
}

/* Winning Strike SVG */
.win-line-svg {
  position: absolute;
  top: 10px;
  left: 10px;
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 5;
}
.win-line-svg.visible {
  opacity: 1;
}

/* Live Reactions Bar */
.reactions-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  gap: 12px;
  flex-wrap: wrap;
}

.reactions-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.reactions-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
}

.reaction-btn {
  font-size: 1.25rem;
  line-height: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 6px 9px;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.reaction-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-3px) scale(1.18);
}
.reaction-btn:active {
  transform: scale(0.9);
}

/* Info Card */
.info-card {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: rgba(14, 165, 233, 0.06);
  border: 1px solid rgba(14, 165, 233, 0.2);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 0.82rem;
  color: #93c5fd;
  line-height: 1.4;
}
.info-icon {
  font-size: 1.1rem;
}

/* Right: Stats & History Section */
.stats-history-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 14px;
}

.heading-icon {
  width: 18px;
  height: 18px;
  color: var(--color-x);
}

/* Stats Overview Card */
.stats-overview-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
}

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

.score-pill {
  border-radius: var(--radius-md);
  padding: 12px 10px;
  text-align: center;
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.x-pill {
  background: rgba(0, 240, 255, 0.05);
  border-color: rgba(0, 240, 255, 0.2);
}
.draw-pill {
  background: rgba(245, 158, 11, 0.05);
  border-color: rgba(245, 158, 11, 0.2);
}
.o-pill {
  background: rgba(255, 51, 102, 0.05);
  border-color: rgba(255, 51, 102, 0.2);
}

.pill-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
}
.x-pill .pill-top { color: var(--color-x); }
.draw-pill .pill-top { color: var(--color-draw); }
.o-pill .pill-top { color: var(--color-o); }

.pill-score {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.1;
  color: #fff;
}

.pill-percent {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-weight: 600;
}

/* Ratio Bar */
.ratio-bar-wrapper {
  margin-bottom: 14px;
}
.ratio-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  display: flex;
}
.ratio-segment {
  height: 100%;
  transition: width 0.4s ease;
}
.ratio-segment.x-seg { background: var(--color-x); }
.ratio-segment.draw-seg { background: var(--color-draw); }
.ratio-segment.o-seg { background: var(--color-o); }

.ratio-legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.74rem;
  font-family: var(--font-mono);
}
.leg-item.x-leg { color: var(--color-x); }
.leg-item.draw-leg { color: var(--color-draw); }
.leg-item.o-leg { color: var(--color-o); }

.total-matches-counter {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border-subtle);
  padding-top: 12px;
}
.total-matches-counter strong {
  color: #fff;
}

.streak-badge {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}

/* History Card */
.history-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
}

.history-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.history-card-header .section-heading {
  margin-bottom: 0;
}

.live-dot-tag {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
  color: #10b981;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.25);
  padding: 2px 8px;
  border-radius: 999px;
}

/* History Table */
.table-container {
  overflow-x: auto;
  max-height: 380px;
  overflow-y: auto;
  border-radius: var(--radius-sm);
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.table-container::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.table-container::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 999px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  text-align: left;
}

.history-table th {
  position: sticky;
  top: 0;
  background: #111728;
  color: var(--text-dim);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  z-index: 2;
}

.history-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
}

.history-table tbody tr {
  transition: background-color 0.15s ease;
}
.history-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.03);
}

.history-table .empty-row td {
  text-align: center;
  padding: 30px 10px;
  color: var(--text-dim);
  font-style: italic;
}

.match-round-col {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #cbd5e1;
}

.winner-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.76rem;
}
.winner-tag.winner-x {
  background: rgba(0, 240, 255, 0.12);
  color: var(--color-x);
  border: 1px solid rgba(0, 240, 255, 0.25);
}
.winner-tag.winner-o {
  background: rgba(255, 51, 102, 0.12);
  color: var(--color-o);
  border: 1px solid rgba(255, 51, 102, 0.25);
}
.winner-tag.winner-draw {
  background: rgba(245, 158, 11, 0.12);
  color: var(--color-draw);
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.time-ago-col {
  font-size: 0.74rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #f8fafc;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  font-size: 0.85rem;
  font-weight: 600;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 1000;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr;
    gap: 24px;
  }
  
  .board-wrapper {
    max-width: 320px;
  }
  
  .app-header {
    margin-bottom: 20px;
  }
}

@media (max-width: 480px) {
  .app-container {
    padding: 16px 12px 36px;
  }
  
  .brand-text h1 {
    font-size: 1.25rem;
  }
  
  .score-counters {
    gap: 6px;
  }
  
  .pill-score {
    font-size: 1.3rem;
  }
  
  .history-table th, .history-table td {
    padding: 8px 6px;
    font-size: 0.75rem;
  }
}
