/* ============================================
   MOUNAJ — Arcade-Modern Gaming Aesthetic
   ============================================ */

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

/* === Custom Properties === */
:root {
  --bg: #0a0a12;
  --bg-surface: #12121e;
  --bg-card: #181828;
  --bg-cell: #1e1e35;
  --bg-cell-hover: #2a2a45;
  --text: #eeeef5;
  --text-muted: #7a7a9e;
  --accent: #6c5ce7;
  --accent-glow: rgba(108, 92, 231, 0.35);
  --accent-hover: #7f70f0;
  --accent-dim: rgba(108, 92, 231, 0.15);
  --win: #00d2a0;
  --win-glow: rgba(0, 210, 160, 0.25);
  --loss: #ff6b6b;
  --loss-glow: rgba(255, 107, 107, 0.25);
  --draw: #ffd93d;
  --x-color: #6c5ce7;
  --o-color: #00d2a0;
  --radius: 14px;
  --radius-lg: 20px;
  --font: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Chakra Petch', 'Outfit', sans-serif;
}

/* === Base === */
html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  position: relative;
}

/* === Background floating shapes === */
.bg-shapes {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.shape {
  position: absolute;
  font-size: 4rem;
  opacity: 0.04;
  animation: float 20s infinite ease-in-out;
  font-weight: 800;
}

.shape-x { color: var(--x-color); }
.shape-o { color: var(--o-color); }

.shape:nth-child(1) { top: 10%; left: 5%; animation-delay: 0s; font-size: 5rem; }
.shape:nth-child(2) { top: 25%; right: 8%; animation-delay: -4s; font-size: 3.5rem; }
.shape.s2:nth-child(3) { top: 55%; left: 12%; animation-delay: -8s; font-size: 3rem; }
.shape.s2:nth-child(4) { top: 70%; right: 15%; animation-delay: -12s; font-size: 4.5rem; }
.shape.s3:nth-child(5) { top: 85%; left: 30%; animation-delay: -6s; font-size: 2.5rem; }
.shape.s3:nth-child(6) { top: 40%; right: 25%; animation-delay: -16s; font-size: 3rem; }

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-20px) rotate(5deg); }
  50% { transform: translateY(10px) rotate(-3deg); }
  75% { transform: translateY(-15px) rotate(2deg); }
}

/* === App Layout === */
.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

/* === Header === */
.header {
  text-align: center;
  padding: 16px 0 8px;
  position: relative;
}

.logo-mark {
  font-size: 1.6rem;
  margin-bottom: 2px;
  letter-spacing: 4px;
  opacity: 0.5;
}

.logo-icon {
  background: linear-gradient(135deg, var(--x-color), var(--o-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 3px;
  text-transform: uppercase;
  display: block;
  text-shadow: 0 0 30px var(--accent-glow);
}

.logo-tagline {
  font-size: 0.7rem;
  color: var(--text-muted);
  letter-spacing: 6px;
  text-transform: uppercase;
  margin-top: 4px;
}

.nav-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 14px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  transition: all 0.2s;
}

.nav-link:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* === Section Titles === */
.section-title {
  font-family: var(--font-display);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* === Lobby === */
.lobby {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding-top: 8px;
}

/* === Hero === */
.hero {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(108, 92, 231, 0.12);
  position: relative;
  overflow: hidden;
  animation: fadeSlideUp 0.6s ease-out;
}

.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 50%, var(--accent-dim), transparent 60%);
  pointer-events: none;
}

.hero-avatar {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: relative;
  z-index: 2;
  border-radius: 50%;
}

.avatar-glow {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: conic-gradient(var(--accent), var(--o-color), var(--accent));
  z-index: 1;
  animation: spin 4s linear infinite;
}

.avatar-ring {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: conic-gradient(var(--accent), transparent, var(--o-color), transparent, var(--accent));
  z-index: 0;
  opacity: 0.3;
  animation: spin 6s linear infinite reverse;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.hero-speech {
  flex: 1;
  position: relative;
  z-index: 1;
}

.hero-speech p {
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.hero-speech strong {
  color: var(--text);
  font-weight: 700;
  font-size: 1.3rem;
}

.speech-arrow {
  display: none;
}

/* === How It Works === */
.how-it-works {
  animation: fadeSlideUp 0.6s ease-out 0.1s both;
}

.steps-track {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid rgba(255,255,255,0.04);
  position: relative;
  animation: fadeSlideUp 0.5s ease-out calc(var(--i) * 0.1s + 0.2s) both;
}

.step:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.step:last-child { border-radius: 0 0 var(--radius) var(--radius); }

.step-connector {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-dim), transparent);
}

.step-icon {
  font-size: 1.2rem;
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}

.step-number {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 1px solid var(--accent);
}

.step-text {
  font-size: 0.88rem;
  color: var(--text);
  font-weight: 500;
}

/* === Play Section === */
.play-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: fadeSlideUp 0.6s ease-out 0.3s both;
}

.name-input-section label,
.game-select label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 500;
}

/* === Handle Input === */
.handle-input-wrapper {
  display: flex;
  align-items: center;
  border: 2px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  background: var(--bg-surface);
  transition: border-color 0.3s, box-shadow 0.3s;
}

.handle-input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow), inset 0 0 20px rgba(108,92,231,0.05);
}

.handle-prefix {
  padding: 15px 0 15px 16px;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 700;
  user-select: none;
}

.handle-input-wrapper input {
  flex: 1;
  padding: 15px 16px 15px 6px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  font-weight: 500;
}

.handle-input-wrapper input::placeholder {
  color: var(--text-muted);
  opacity: 0.5;
}

.handle-input-wrapper input.error {
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* === Game Cards === */
.game-cards {
  display: flex;
  gap: 12px;
}

.game-card {
  flex: 1;
  padding: 22px 16px;
  border: 2px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: border-color 0.3s, box-shadow 0.3s, transform 0.15s;
  position: relative;
  font-family: var(--font);
  overflow: hidden;
}

.game-card-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 80%, var(--accent-dim), transparent 70%);
  pointer-events: none;
}

.game-card.active {
  border-color: var(--accent);
  box-shadow: 0 4px 24px var(--accent-glow);
}

.game-card.active:active {
  transform: scale(0.97);
}

.game-card.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.game-icon {
  font-size: 1.8rem;
  position: relative;
  z-index: 1;
}

.game-name {
  font-size: 0.9rem;
  font-weight: 600;
  position: relative;
  z-index: 1;
}

.game-players {
  font-size: 0.7rem;
  color: var(--text-muted);
  position: relative;
  z-index: 1;
}

.game-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.6rem;
  background: linear-gradient(135deg, var(--accent), #9b59b6);
  color: white;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* === Buttons === */
.btn {
  padding: 16px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #5a4bd4);
  color: white;
  width: 100%;
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), #6c5ce7);
}

.btn-glow {
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-glow:hover {
  box-shadow: 0 6px 30px rgba(108, 92, 231, 0.5);
}

.btn-text {
  font-weight: 700;
}

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

.btn-share {
  background: transparent;
  border: 2px solid rgba(108, 92, 231, 0.3);
  color: var(--accent);
  width: 100%;
}

.btn-share:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.btn-small {
  padding: 12px 18px;
  font-size: 0.85rem;
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === Trust Section === */
.trust-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: fadeSlideUp 0.6s ease-out 0.4s both;
}

.trust-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid rgba(255,255,255,0.03);
}

.trust-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.trust-item:last-child { border-radius: 0 0 var(--radius) var(--radius); }

.trust-icon-wrap {
  font-size: 1.3rem;
  width: 36px;
  text-align: center;
  flex-shrink: 0;
}

.trust-content {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.trust-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.trust-text {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* === Ad Slots === */
.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed rgba(255,255,255,0.08);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.02);
  position: relative;
}

.ad-banner {
  height: 60px;
}

.ad-rect {
  height: 120px;
}

.ad-sticky {
  position: sticky;
  bottom: 0;
  height: 50px;
  border-radius: var(--radius) var(--radius) 0 0;
  margin: 0 -16px;
  z-index: 10;
  background: rgba(10, 10, 18, 0.9);
  backdrop-filter: blur(10px);
}

.ad-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  opacity: 0.5;
}

/* === Game Page === */

/* === Game Container === */
.game-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding-top: 8px;
}

/* === Game Status === */
.game-status {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  min-height: 28px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.game-status.your-turn {
  color: var(--win);
  text-shadow: 0 0 20px var(--win-glow);
}

.game-status.their-turn {
  color: var(--text-muted);
}

/* === Player Cards (game info) === */
.game-info {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.player-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  background: var(--bg-surface);
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.04);
}

.player-x-card { border-color: rgba(108, 92, 231, 0.2); }
.player-o-card { border-color: rgba(0, 210, 160, 0.2); }

.player-symbol {
  font-size: 1.2rem;
  font-weight: 800;
}

.player-x-card .player-symbol { color: var(--x-color); }
.player-o-card .player-symbol { color: var(--o-color); }

.player-handle {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 4px;
}

.vs-badge {
  font-family: var(--font-display);
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 2px;
  font-weight: 700;
}

/* === Scoreboard === */
.scoreboard {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

.score-you {
  color: var(--x-color);
  min-width: 16px;
  text-align: center;
}

.score-opponent {
  color: var(--o-color);
  min-width: 16px;
  text-align: center;
}

.score-draws {
  color: var(--draw);
  min-width: 16px;
  text-align: center;
}

.score-separator {
  color: var(--text-muted);
  font-weight: 400;
  opacity: 0.4;
}

/* === Board === */
.board-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(85vw, 340px);
  aspect-ratio: 1;
}

.cell {
  background: var(--bg-cell);
  border: 2px solid rgba(255,255,255,0.04);
  border-radius: var(--radius);
  font-size: clamp(2rem, 12vw, 3.8rem);
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s, border-color 0.2s, box-shadow 0.2s;
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}

.cell:not(.disabled):not(:empty):hover,
.cell:not(.disabled):active {
  background: var(--bg-cell-hover);
}

.cell:active {
  transform: scale(0.93);
}

.cell.x {
  color: var(--x-color);
  text-shadow: 0 0 15px var(--accent-glow);
  border-color: rgba(108, 92, 231, 0.15);
}

.cell.o {
  color: var(--o-color);
  text-shadow: 0 0 15px var(--win-glow);
  border-color: rgba(0, 210, 160, 0.15);
}

.cell.win {
  background: var(--win-glow);
  border-color: rgba(0, 210, 160, 0.3);
  animation: winPulse 0.8s ease-in-out infinite alternate;
}

@keyframes winPulse {
  from { box-shadow: 0 0 10px var(--win-glow); }
  to { box-shadow: 0 0 25px var(--win-glow); }
}

.cell.disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

/* === Waiting Section === */
.waiting-section {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.waiting-anim {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.waiting-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.4s infinite ease-in-out;
}

.waiting-dot:nth-child(2) { animation-delay: 0.16s; }
.waiting-dot:nth-child(3) { animation-delay: 0.32s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

.waiting-text {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.challenge-link-box {
  display: flex;
  gap: 8px;
  width: 100%;
}

.challenge-link-box input {
  flex: 1;
  padding: 12px 14px;
  border: 2px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 0.8rem;
  font-family: var(--font);
  outline: none;
}

/* === Join Section === */
.join-section {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 30px 0;
  animation: fadeSlideUp 0.5s ease-out;
}

.join-badge {
  font-size: 2.5rem;
  animation: pulse-scale 2s infinite ease-in-out;
}

@keyframes pulse-scale {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.join-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.join-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.join-section .name-input-section {
  text-align: left;
  width: 100%;
}

/* === Game Over === */
.game-over {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
  animation: fadeSlideUp 0.4s ease-out;
}

.game-result-wrap {
  padding: 16px;
  background: var(--bg-surface);
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.04);
}

.game-result {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.game-result.win {
  color: var(--win);
  text-shadow: 0 0 30px var(--win-glow);
}
.game-result.loss {
  color: var(--loss);
  text-shadow: 0 0 30px var(--loss-glow);
}
.game-result.draw {
  color: var(--draw);
}

.game-over-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* === Footer === */
.footer {
  text-align: center;
  padding: 24px 0 16px;
  margin-top: 20px;
}

.footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.75rem;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--accent);
}

.footer-dot {
  color: var(--text-muted);
  opacity: 0.3;
}

.footer-copy {
  color: var(--text-muted);
  font-size: 0.7rem;
  opacity: 0.5;
}

/* === Legal Pages === */
.legal-page {
  flex: 1;
  padding: 10px 0 40px;
}

.legal-page h1 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.legal-updated {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-bottom: 24px;
}

.legal-page h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  margin-top: 24px;
  margin-bottom: 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.legal-page p {
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.legal-page ul {
  padding-left: 20px;
  margin-bottom: 8px;
}

.legal-page li {
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.legal-page a {
  color: var(--accent);
}

/* === Leaderboard === */
.leaderboard-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lb-header {
  text-align: center;
  padding: 10px 0;
  animation: fadeSlideUp 0.5s ease-out;
}

.lb-trophy {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 4px;
}

.lb-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  text-transform: uppercase;
  letter-spacing: 3px;
}

.lb-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 4px;
}

/* Podium */
.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  padding: 10px 0;
  animation: fadeSlideUp 0.5s ease-out 0.1s both;
}

.podium-spot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
  max-width: 120px;
}

.podium-avatar {
  font-size: 2rem;
}

.podium-handle {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.podium-wins {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.podium-bar {
  width: 100%;
  border-radius: 8px 8px 0 0;
  background: var(--bg-surface);
  border: 1px solid rgba(255,255,255,0.04);
  border-bottom: none;
}

.first .podium-bar {
  height: 80px;
  background: linear-gradient(180deg, rgba(108,92,231,0.2), var(--bg-surface));
  border-color: rgba(108,92,231,0.15);
}

.second .podium-bar {
  height: 56px;
}

.third .podium-bar {
  height: 40px;
}

/* Rankings table */
.rankings {
  background: var(--bg-surface);
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.04);
  overflow: hidden;
  animation: fadeSlideUp 0.5s ease-out 0.2s both;
}

.rankings-header {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.rh-rank {
  width: 30px;
  text-align: center;
}

.rh-player {
  flex: 1;
}

.rh-stat {
  width: 32px;
  text-align: center;
}

.rh-rate {
  width: 48px;
  text-align: right;
}

.ranking-row {
  display: flex;
  align-items: center;
  padding: 11px 14px;
  font-size: 0.85rem;
  border-bottom: 1px solid rgba(255,255,255,0.02);
  animation: fadeSlideUp 0.3s ease-out calc(var(--i) * 0.05s) both;
  transition: background 0.2s;
}

.ranking-row:last-child {
  border-bottom: none;
}

.ranking-row:hover {
  background: rgba(255,255,255,0.02);
}

.ranking-row.top-three {
  background: rgba(108,92,231,0.05);
}

.row-rank {
  width: 30px;
  text-align: center;
  font-weight: 700;
  color: var(--text-muted);
  font-family: var(--font-display);
}

.ranking-row.top-three .row-rank {
  color: var(--accent);
}

.row-player {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-stat {
  width: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.row-stat.wins {
  color: var(--win);
}

.row-stat.losses {
  color: var(--loss);
}

.row-stat.draws {
  color: var(--draw);
}

.row-rate {
  width: 48px;
  text-align: right;
  font-weight: 600;
  font-family: var(--font-display);
  color: var(--text);
}

.rankings-empty,
.rankings-loading {
  padding: 30px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.lb-cta {
  padding: 8px 0;
}

.lb-cta a {
  text-decoration: none;
}

/* === Replay === */
.replay-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.replay-player.x { color: var(--x-color); }
.replay-player.o { color: var(--o-color); }

#replayCanvas {
  border-radius: var(--radius);
  max-width: 100%;
}

.replay-result {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  min-height: 32px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.replay-result.win { color: var(--win); text-shadow: 0 0 20px var(--win-glow); }
.replay-result.draw { color: var(--draw); }

.replay-controls, .replay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/* === Spectator Options === */
.spectator-options {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 0;
  animation: fadeSlideUp 0.5s ease-out;
}

.spec-badge {
  font-size: 2.5rem;
  animation: pulse-scale 2s infinite ease-in-out;
}

.spec-info {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 500;
}

.spec-queue-info {
  font-size: 0.8rem;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 4px 12px;
  border-radius: 12px;
}

.spec-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 8px;
}

/* === Watcher Info (shown to players) === */
.watcher-info {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  padding: 6px 12px;
  background: var(--bg-surface);
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.04);
}

/* === Watch Request Toast === */
.watch-request-toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  width: 100%;
  animation: fadeSlideUp 0.3s ease-out;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.wrt-text {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  flex: 1;
}

.wrt-buttons {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.wrt-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}

.wrt-btn:active {
  transform: scale(0.9);
}

.wrt-approve {
  background: var(--win);
  color: white;
}

.wrt-deny {
  background: var(--loss);
  color: white;
}

/* === Spectator Chat === */
.spectator-chat {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  overflow: hidden;
  max-height: 250px;
  display: flex;
  flex-direction: column;
}

.spectator-chat .chat-messages {
  min-height: 100px;
  max-height: 150px;
}

/* === Chat === */
.chat-container {
  position: fixed;
  bottom: 70px;
  right: 16px;
  z-index: 20;
}

.chat-toggle {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #5a4bd4);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px var(--accent-glow);
  transition: transform 0.2s;
  position: absolute;
  bottom: 0;
  right: 0;
}

.chat-toggle:active {
  transform: scale(0.93);
}

.chat-toggle-icon {
  font-size: 1.3rem;
}

.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--loss);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
}

.chat-panel {
  position: absolute;
  bottom: 60px;
  right: 0;
  width: 280px;
  max-height: 350px;
  background: var(--bg-surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: fadeSlideUp 0.2s ease-out;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.chat-status {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 400;
}

.chat-status.online {
  color: var(--win);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 150px;
  max-height: 220px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-width: 85%;
}

.chat-msg.me {
  align-self: flex-end;
}

.chat-msg.them {
  align-self: flex-start;
}

.chat-handle {
  font-size: 0.6rem;
  color: var(--text-muted);
  padding: 0 4px;
}

.chat-text {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.82rem;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg.me .chat-text {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-msg.them .chat-text {
  background: var(--bg-card);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-input-row {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.chat-input-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.82rem;
  font-family: var(--font);
  outline: none;
}

.chat-input-row input:focus {
  border-color: var(--accent);
}

.chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
  flex-shrink: 0;
}

.chat-send:active {
  transform: scale(0.9);
}

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

/* === Animations === */
@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

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

.cell.placed {
  animation: pop 0.25s ease-out;
}

/* === Desktop layout with side ad columns === */
@media (min-width: 768px) {
  .app {
    max-width: 520px;
  }

  body::before,
  body::after {
    content: '';
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 160px;
    height: 600px;
    border: 2px dashed rgba(255,255,255,0.06);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 0;
  }

  body::before {
    left: 20px;
  }

  body::after {
    right: 20px;
  }
}

/* Ensure game ad shows when board is visible */
.game-ad { display: none; }
.board-wrapper:not(.hidden) ~ .game-ad { display: flex; }
