/* ============================================================
   XO (Tic-Tac-Toe) — Rave Design System
   Black & Silver aesthetic, responsive board, animated SVG marks.
   ============================================================ */

/* Reconnect banner */
.reconnect-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  padding: 10px 16px;
  background: rgba(248, 113, 113, 0.95);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  animation: fadeUp 0.3s ease;
}
.spinner-sm {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

/* Top bar extras */
.room-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--silver-200);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}
.room-badge:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
  transform: translateY(-1px);
}
.room-badge svg {
  width: 14px;
  height: 14px;
  opacity: 0.7;
}

.mute-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--fg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s var(--ease);
}
.mute-btn:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}
.mute-btn svg {
  width: 18px;
  height: 18px;
}

/* Container & layout */
.xo-container {
  height: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 10px 14px calc(var(--safe-b) + 12px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  overflow: hidden;
}

/* Mini-Lobby */
.xo-lobby {
  width: 100%;
  max-width: 440px;
  margin: auto;
  padding: 30px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 20px;
  animation: pop 0.4s var(--ease);
}
.lobby-icon {
  width: 76px;
  height: 76px;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(255,255,255,0.12), rgba(255,255,255,0.02));
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.lobby-icon svg {
  width: 44px;
  height: 44px;
}
.lobby-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--fg-3);
  font-size: 13px;
  font-weight: 700;
}
.lobby-divider::before, .lobby-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.join-code-row {
  width: 100%;
  display: flex;
  gap: 8px;
}
.join-input {
  text-align: center;
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* In-Game Header: Players & Score */
.xo-players-bar {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-lg);
  background: rgba(18, 18, 18, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  flex-shrink: 0;
}

.player-card {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  transition: all 0.25s var(--ease);
  min-width: 0;
}
.player-card.is-o {
  flex-direction: row-reverse;
  text-align: left;
}
.player-card.is-turn {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.12);
}
.player-card.is-disconnected {
  opacity: 0.6;
}

.player-avatar-wrap {
  position: relative;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
}
.player-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  background: #181818;
  border: 2px solid #2a2a2a;
  display: block;
}
.bot-avatar-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2a2a2a, #151515);
  border: 2px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--silver-300);
}
.bot-avatar-icon svg {
  width: 20px;
  height: 20px;
}
.player-sym-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 5px;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);
  z-index: 2;
}
.is-o .player-sym-badge {
  right: auto;
  left: -4px;
}
.status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  border: 2px solid #111;
  z-index: 2;
}
.is-o .status-dot {
  right: auto;
  left: -1px;
}
.status-dot.offline {
  background: var(--red);
  animation: pulse 1.6s infinite;
}

.player-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  flex: 1;
}
.player-name {
  font-size: 13px;
  font-weight: 800;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}
.sym-x {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.4);
}
.sym-o {
  background: rgba(176, 196, 222, 0.22);
  color: #d1e0f0;
  border: 1px solid rgba(176, 196, 222, 0.4);
}

.player-meta {
  font-size: 11px;
  color: var(--fg-3);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Central Scoreboard */
.xo-score-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0 4px;
  flex-shrink: 0;
}
.score-numbers {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 17px;
  font-weight: 900;
  color: #fff;
}
.score-divider {
  color: var(--fg-4);
  font-size: 14px;
}
.score-label {
  font-size: 10px;
  letter-spacing: 0.05em;
  color: var(--fg-3);
  font-weight: 700;
  text-transform: uppercase;
}

/* Turn banner */
.xo-turn-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 13px;
  font-weight: 800;
  color: var(--silver-200);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  flex-shrink: 0;
  transition: all 0.3s var(--ease);
}
.xo-turn-status.my-turn {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.4);
  color: #fff;
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.15);
  animation: glow 2s ease-in-out infinite;
}

/* Game Board */
.xo-board-wrap {
  position: relative;
  width: min(84vw, 45dvh, 390px);
  height: min(84vw, 45dvh, 390px);
  aspect-ratio: 1 / 1;
  margin: auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.xo-board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  padding: 12px;
  background: rgba(14, 14, 14, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), inset 0 0 20px rgba(255, 255, 255, 0.02);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.xo-cell {
  position: relative;
  background: rgba(24, 24, 24, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: all 0.2s var(--ease);
}
.xo-cell:hover:not(.disabled) {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.08);
  transform: scale(1.02);
}
.xo-cell:active:not(.disabled) {
  transform: scale(0.96);
}
.xo-cell.disabled {
  cursor: default;
}
.xo-cell.winning-cell {
  background: rgba(255, 255, 255, 0.16) !important;
  border-color: rgba(255, 255, 255, 0.6) !important;
  box-shadow: 0 0 30px rgba(255, 255, 255, 0.3) !important;
  animation: winPulse 1.2s ease-in-out infinite alternate;
  z-index: 2;
}
@keyframes winPulse {
  0% { transform: scale(1); box-shadow: 0 0 15px rgba(255, 255, 255, 0.2); }
  100% { transform: scale(1.04); box-shadow: 0 0 35px rgba(255, 255, 255, 0.45); }
}

/* SVG Marks */
.mark-svg {
  width: 60%;
  height: 60%;
  pointer-events: none;
}

.mark-x {
  stroke: #ffffff;
  stroke-width: 6.5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.4));
}
.mark-x .x1 {
  stroke-dasharray: 50;
  stroke-dashoffset: 0;
  animation: drawLine 0.2s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.mark-x .x2 {
  stroke-dasharray: 50;
  stroke-dashoffset: 0;
  animation: drawLine 0.2s cubic-bezier(0.2, 0.8, 0.2, 1) 0.08s both;
}

.mark-o {
  stroke: #c8d8ea;
  stroke-width: 6.5;
  stroke-linecap: round;
  fill: none;
  filter: drop-shadow(0 0 8px rgba(180, 205, 235, 0.4));
}
.mark-o .o-circle {
  stroke-dasharray: 130;
  stroke-dashoffset: 0;
  transform-origin: center;
  transform: rotate(-90deg);
  animation: drawCircle 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.no-anim .x1, .no-anim .x2, .no-anim .o-circle {
  animation: none !important;
  stroke-dashoffset: 0 !important;
}

@keyframes drawLine {
  0% { stroke-dashoffset: 50; }
  100% { stroke-dashoffset: 0; }
}
@keyframes drawCircle {
  0% { stroke-dashoffset: 130; }
  100% { stroke-dashoffset: 0; }
}

/* Waiting / Spectator footer controls */
.xo-footer-ctrls {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Waiting Card */
.waiting-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.14);
  text-align: center;
  animation: fadeUp 0.3s ease;
}

/* Floating overlay trigger button */
.reopen-overlay-btn {
  position: fixed;
  bottom: calc(var(--safe-b) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 700;
  animation: pop 0.3s var(--ease);
}

/* Result Card Customizations */
.result-card-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.result-rewards-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.4);
  color: var(--amber);
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 0 20px rgba(251, 191, 36, 0.2);
}
.result-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.result-close-x {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--fg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.result-close-x:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

/* Spectator pill */
.spectator-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(96, 165, 250, 0.12);
  border: 1px solid rgba(96, 165, 250, 0.3);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}

/* Responsive tweaks for very small / landscape screens */
@media (max-height: 600px) {
  .xo-container {
    padding-top: 4px;
    padding-bottom: 4px;
    gap: 6px;
  }
  .xo-board-wrap {
    width: min(65vw, 55dvh, 260px);
    height: min(65vw, 55dvh, 260px);
  }
  .player-avatar {
    width: 30px;
    height: 30px;
  }
  .bot-avatar-icon {
    width: 30px;
    height: 30px;
  }
  .xo-players-bar {
    padding: 4px 8px;
  }
}
