:root {
  --bg-color: #080c18;
  --panel-bg: rgba(16, 24, 44, 0.84);
  --border-color: rgba(255, 255, 255, 0.12);
  --border-glow: rgba(56, 189, 248, 0.35);

  --color-x: #38bdf8;
  --color-x-glow: rgba(56, 189, 248, 0.6);
  --color-o: #fbbf24;
  --color-o-glow: rgba(251, 191, 36, 0.6);
  --color-win: #10b981;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-logo: 'Bungee', cursive, sans-serif;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-full: 9999px;

  --shadow-lg: 0 16px 36px rgba(0, 0, 0, 0.7), 0 0 24px rgba(56, 189, 248, 0.15);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);

  /* Board Variables (Default Neon) */
  --board-bg: #0f172a;
  --board-grid-line: rgba(255, 255, 255, 0.14);
  --board-cell-bg: #141e33;
  --board-cell-hover: rgba(56, 189, 248, 0.25);
  --star-point-color: rgba(255, 255, 255, 0.35);
}

/* ========================================================
   THEME: TRADITIONAL WOOD (KAYA / WALNUT GOMOKU)
   ======================================================== */
body.theme-wood {
  --bg-color: #17110c;
  --panel-bg: rgba(38, 26, 18, 0.9);
  --border-color: rgba(245, 158, 11, 0.22);
  --border-glow: rgba(245, 158, 11, 0.3);

  --board-bg: #c99355;
  --board-grid-line: #5c3811;
  --board-cell-bg: #dfa868;
  --board-cell-hover: rgba(255, 255, 255, 0.35);
  --star-point-color: #5c3811;

  --color-x: #18181b; /* Ink Stone X */
  --color-x-glow: rgba(0, 0, 0, 0.5);
  --color-o: #f8fafc; /* White Jade Stone O */
  --color-o-glow: rgba(255, 255, 255, 0.7);
}

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

html, body {
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(circle at 12% 12%, rgba(56, 189, 248, 0.12) 0%, transparent 45%),
    radial-gradient(circle at 88% 88%, rgba(245, 158, 11, 0.1) 0%, transparent 45%),
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 30px 30px, 30px 30px;
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right)) max(0.8rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
  user-select: none;
  -webkit-user-select: none;
  position: relative;
}

/* Ambient Glow */
.ambient-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
  z-index: 0;
  opacity: 0.6;
}

.glow-1 {
  width: 320px;
  height: 320px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.35), transparent 70%);
  top: -80px;
  left: -80px;
  animation: floatOrb 12s ease-in-out infinite alternate;
}

.glow-2 {
  width: 340px;
  height: 340px;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.25), transparent 70%);
  bottom: -90px;
  right: -90px;
  animation: floatOrb 15s ease-in-out infinite alternate-reverse;
}

.glow-3 {
  width: 240px;
  height: 240px;
  background: radial-gradient(circle, rgba(168, 85, 247, 0.2), transparent 70%);
  top: 40%;
  left: 60%;
  animation: floatOrb 10s ease-in-out infinite alternate;
}

@keyframes floatOrb {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, 20px) scale(1.1); }
  100% { transform: translate(-20px, 35px) scale(0.95); }
}

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

.caro-app-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 630px;
  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.15rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin: 0 auto;
}

/* Portal Nav */
.portal-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  background: rgba(8, 12, 24, 0.7);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.portal-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.6rem;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.78rem;
  transition: var(--transition);
  position: relative;
  white-space: nowrap;
}

.portal-tab:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

.portal-tab.active {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.35), rgba(99, 102, 241, 0.25));
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.3);
}

.active-dot {
  width: 6px;
  height: 6px;
  background: #38bdf8;
  border-radius: 50%;
  box-shadow: 0 0 8px #38bdf8;
  display: inline-block;
}

/* App Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 0.65rem;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.badge-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.badge {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 1.2px;
  color: var(--color-x);
  background: rgba(56, 189, 248, 0.15);
  padding: 2px 7px;
  border-radius: var(--radius-full);
  display: inline-block;
  width: fit-content;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.badge-sub {
  font-size: 0.62rem;
  font-weight: 700;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.12);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(251, 191, 36, 0.25);
}

.logo-title {
  font-family: var(--font-logo);
  font-size: clamp(1.2rem, 4.2vw, 1.65rem);
  background: linear-gradient(135deg, #ffffff 30%, #38bdf8 70%, #818cf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.5px;
  line-height: 1.2;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tool-btn {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.tool-btn.active {
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.5);
  color: var(--text-main);
}

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

/* ========================================================
   LOBBY SCREEN
   ======================================================== */
.lobby-screen {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.lobby-screen.hidden {
  display: none;
}

.lobby-card {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.lobby-hero {
  text-align: center;
  padding: 0.4rem 0;
}

.section-title {
  font-family: var(--font-logo);
  font-size: clamp(1.15rem, 3.8vw, 1.4rem);
  color: #fff;
  letter-spacing: 0.5px;
}

.section-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.modes-grid {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.mode-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.mode-card:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.online-card {
  border-color: rgba(56, 189, 248, 0.4);
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.12), rgba(99, 102, 241, 0.08));
}

.online-card:hover {
  border-color: #38bdf8;
  box-shadow: 0 8px 28px rgba(56, 189, 248, 0.25);
}

.mode-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  background: linear-gradient(135deg, #ef4444, #f59e0b);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.mode-header-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.mode-icon {
  font-size: 1.8rem;
  background: rgba(255, 255, 255, 0.06);
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
}

.mode-info h3 {
  font-size: 0.95rem;
  font-weight: 800;
  color: #ffffff;
}

.mode-info p {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.35;
  margin-top: 2px;
}

.ai-difficulty-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px;
  border-radius: var(--radius-sm);
}

.diff-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.diff-btn.active {
  background: rgba(245, 158, 11, 0.3);
  color: #fcd34d;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.3);
}

.btn-mode-select {
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.82rem;
  border: none;
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3);
  transition: var(--transition);
}

.btn-mode-select:hover {
  filter: brightness(1.1);
}

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

/* Online Setup Dialog */
.online-setup-box {
  background: #111827;
  border: 1.5px solid rgba(56, 189, 248, 0.4);
  border-radius: var(--radius-md);
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.7), 0 0 24px rgba(56, 189, 248, 0.2);
  animation: modal-enter 0.25s ease-out;
}

.online-setup-box.hidden {
  display: none;
}

.setup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 0.5rem;
}

.setup-header h3 {
  font-size: 0.95rem;
  font-weight: 800;
  color: #38bdf8;
}

.close-x {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
}

.setup-actions {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.action-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.action-box h4 {
  font-size: 0.85rem;
  color: #ffffff;
}

.action-box p {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.btn-primary-action {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
}

.action-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.7rem;
  font-weight: 800;
}

.action-divider::before,
.action-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.action-divider span {
  padding: 0 0.5rem;
}

.join-input-group {
  display: flex;
  gap: 0.4rem;
}

.join-input-group input {
  flex: 1;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  color: #ffffff;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  outline: none;
  text-transform: uppercase;
}

.join-input-group input:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
}

.btn-secondary-action {
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: #38bdf8;
  font-weight: 800;
  font-size: 0.8rem;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* ========================================================
   GAMEPLAY SCREEN
   ======================================================== */
.game-screen {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.game-screen.hidden {
  display: none;
}

.game-status-bar {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.room-tag-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
}

.btn-back {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.room-info-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(0, 0, 0, 0.4);
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-full);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.75rem;
}

.room-info-badge b {
  color: #38bdf8;
  letter-spacing: 0.5px;
}

.btn-copy-mini {
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #bae6fd;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
}

.board-mini-tools {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-tool-mini {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.ping-status {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  color: #10b981;
}

.ping-dot {
  width: 6px;
  height: 6px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 6px #10b981;
  animation: pulse 1.5s infinite;
}

/* Players VS Card */
.players-card {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: rgba(10, 16, 32, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.85rem;
  gap: 0.5rem;
}

.player-slot {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.player-slot.active-turn {
  background: rgba(255, 255, 255, 0.06);
}

.player-o {
  flex-direction: row-reverse;
  text-align: right;
}

.player-avatar-wrap {
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.player-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-logo);
  font-size: 1.25rem;
  background: #1e293b;
  border: 2px solid rgba(255, 255, 255, 0.15);
  position: relative;
  z-index: 2;
}

.player-x .player-avatar {
  color: var(--color-x);
  border-color: var(--color-x);
}

.player-o .player-avatar {
  color: var(--color-o);
  border-color: var(--color-o);
}

.avatar-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px dashed transparent;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.player-slot.active-turn .avatar-ring {
  opacity: 1;
  border-color: #38bdf8;
  animation: spin 6s linear infinite;
}

.player-o.active-turn .avatar-ring {
  border-color: #fbbf24;
}

.player-meta {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.player-name {
  font-size: 0.82rem;
  font-weight: 800;
  color: #ffffff;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

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

.vs-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
}

.vs-badge .vs-text {
  font-family: 'Bungee', cursive, sans-serif;
  font-size: 0.95rem;
  letter-spacing: 1.5px;
  color: var(--accent-gold, #f59e0b);
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  text-shadow: 0 0 12px rgba(245, 158, 11, 0.4);
}

.vs-badge small {
  font-size: 0.65rem;
  font-weight: 900;
  color: var(--text-dim);
}

/* Turn Banner */
.game-turn-banner {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  color: #e2e8f0;
}

/* ========================================================
   CARO 15X15 BOARD
   ======================================================== */
.caro-board-container {
  display: flex;
  justify-content: center;
  width: 100%;
}

.caro-board-wrapper {
  position: relative;
  width: 100%;
  max-width: 590px;
  aspect-ratio: 1;
  background: var(--board-bg);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  box-shadow: inset 0 2px 14px rgba(0, 0, 0, 0.7), 0 14px 34px rgba(0, 0, 0, 0.6);
  padding: 4px;
  overflow: hidden;
  touch-action: none;
}

body.theme-wood .caro-board-wrapper {
  border-color: #5c3811;
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.5), 0 14px 34px rgba(0, 0, 0, 0.7);
}

.caro-grid-15x15 {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: 1px;
  width: 100%;
  height: 100%;
  background: var(--board-grid-line);
}

.caro-cell {
  background: var(--board-cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background-color 0.12s ease;
}

.caro-cell:hover:not(.taken) {
  background: var(--board-cell-hover);
}

/* Star Points (Hoshi dots) */
.caro-cell.star-point::after {
  content: '';
  position: absolute;
  width: 5px;
  height: 5px;
  background: var(--star-point-color);
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
}

.caro-cell.taken.star-point::after {
  display: none;
}

/* Pieces (Stones) */
.caro-piece {
  width: 88%;
  height: 88%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 3;
  animation: drop-stone 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes drop-stone {
  0% { transform: scale(0.3); opacity: 0; }
  75% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

/* Neon Theme Pieces */
.piece-x {
  background: radial-gradient(circle at 35% 35%, #7dd3fc 0%, #0284c7 60%, #0369a1 100%);
  box-shadow: 0 0 10px var(--color-x-glow), 0 3px 6px rgba(0, 0, 0, 0.6);
  border: 1px solid #bae6fd;
}

.piece-x::before {
  content: '✕';
  font-size: clamp(0.85rem, 3.2vw, 1.25rem);
  font-weight: 900;
  color: #ffffff;
  line-height: 1;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
}

.piece-o {
  background: radial-gradient(circle at 35% 35%, #fef08a 0%, #d97706 60%, #b45309 100%);
  box-shadow: 0 0 10px var(--color-o-glow), 0 3px 6px rgba(0, 0, 0, 0.6);
  border: 1px solid #fef9c3;
}

.piece-o::before {
  content: '◯';
  font-size: clamp(0.9rem, 3.6vw, 1.35rem);
  font-weight: 900;
  color: #ffffff;
  line-height: 1;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
}

/* Traditional Wood Theme Pieces */
body.theme-wood .piece-x {
  background: radial-gradient(circle at 30% 30%, #475569 0%, #1e293b 50%, #090d16 100%);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.8), inset 0 1px 2px rgba(255, 255, 255, 0.3);
  border: none;
}
body.theme-wood .piece-x::before {
  content: '';
}

body.theme-wood .piece-o {
  background: radial-gradient(circle at 30% 30%, #ffffff 0%, #f1f5f9 60%, #cbd5e1 100%);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5), inset 0 -1px 2px rgba(0, 0, 0, 0.2);
  border: none;
}
body.theme-wood .piece-o::before {
  content: '';
}

/* Last Move Indicator */
.caro-cell.last-move .caro-piece::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  background: #ef4444;
  border-radius: 50%;
  box-shadow: 0 0 8px #ef4444;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
}

/* Move Numbers on Pieces */
.piece-num {
  position: absolute;
  font-size: 0.55rem;
  font-weight: 800;
  color: #fff;
  z-index: 4;
}
body.theme-wood .piece-o .piece-num {
  color: #1e293b;
}

/* SVG Line Overlay */
.caro-svg-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.caro-win-line {
  stroke: #10b981;
  stroke-width: 6;
  stroke-linecap: round;
  filter: drop-shadow(0 0 10px #10b981);
  stroke-dasharray: 600;
  stroke-dashoffset: 600;
  animation: draw-line 0.35s ease-out forwards;
}

/* ========================================================
   CONTROLS & CHAT / EMOJI
   ======================================================== */
.game-controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.quick-chat-scroller {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  padding-bottom: 3px;
  scrollbar-width: none;
}
.quick-chat-scroller::-webkit-scrollbar {
  display: none;
}

.chat-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 0.32rem 0.65rem;
  border-radius: var(--radius-full);
  white-space: nowrap;
  cursor: pointer;
  transition: var(--transition);
}

.chat-chip:hover {
  background: rgba(56, 189, 248, 0.2);
  color: #fff;
  border-color: rgba(56, 189, 248, 0.4);
}

.quick-emojis-bar {
  display: flex;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 4px;
}

.emoji-btn {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem 0.45rem;
  border-radius: 6px;
  transition: var(--transition);
}

.emoji-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.2);
}

.game-action-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.btn-game-act {
  font-size: 0.78rem;
  font-weight: 800;
  padding: 0.55rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
}

.btn-game-act.restart {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
}

.btn-game-act.undo {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #e2e8f0;
}

.btn-game-act.surrender {
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

/* Floating Emoji Container */
.emoji-floating-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1002;
}

.floating-bubble {
  position: absolute;
  bottom: 120px;
  font-size: 2.2rem;
  animation: floatUp 2.2s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes floatUp {
  0% { transform: translateY(0) scale(0.6); opacity: 0; }
  15% { transform: translateY(-20px) scale(1.2); opacity: 1; }
  80% { opacity: 0.9; }
  100% { transform: translateY(-220px) scale(0.9); opacity: 0; }
}

/* Toast Notify */
.toast-notify {
  position: fixed;
  top: -80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: #ffffff;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.6);
  z-index: 1005;
  transition: top 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast-notify.active {
  top: 20px;
}

/* Win Banner */
.win-banner {
  position: fixed;
  bottom: -160px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #1e1b4b, #312e81);
  border: 2px solid #38bdf8;
  border-radius: var(--radius-lg);
  padding: 1rem 1.5rem;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.8), 0 0 30px rgba(56, 189, 248, 0.6);
  z-index: 1001;
  transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  width: min(92%, 440px);
}

.win-banner.active {
  bottom: 24px;
}

.win-content {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.win-icon {
  font-size: 2.2rem;
  animation: bounce 0.8s infinite alternate ease-in-out;
}

.win-text h3 {
  font-size: 1.1rem;
  font-weight: 900;
  color: #fcd34d;
}

.win-text p {
  font-size: 0.78rem;
  color: #c7d2fe;
}

.btn-win {
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  color: #ffffff;
  font-weight: 900;
  font-size: 0.78rem;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  margin-left: auto;
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

@keyframes modal-enter {
  0% { transform: scale(0.92) translateY(20px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

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

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

/* Modal Backdrop & Dialog */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 16, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1010;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  padding: 1rem;
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: #0f172a;
  border: 1.5px solid rgba(56, 189, 248, 0.4);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(56, 189, 248, 0.2);
  transform: scale(0.9);
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  width: 100%;
}

.modal-backdrop.active .modal-dialog {
  transform: scale(1);
}

@media (max-width: 600px) {
  body {
    padding: max(0.35rem, env(safe-area-inset-top)) max(0.35rem, env(safe-area-inset-right)) max(0.5rem, env(safe-area-inset-bottom)) max(0.35rem, env(safe-area-inset-left));
  }

  .caro-app-container {
    padding: 0.75rem 0.5rem;
    gap: 0.65rem;
    border-radius: var(--radius-md);
  }

  .caro-board-wrapper {
    padding: 2px;
    border-width: 1.5px;
  }
}

/* ========================================================
   LIVE ACTIVE ROOMS SECTION
   ======================================================== */
.live-rooms-container {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
}

.live-rooms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.live-rooms-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.75rem;
  font-weight: 800;
  color: #38bdf8;
  letter-spacing: 0.5px;
}

.pulse-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
  animation: pulse-dot 1.4s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.5; }
}

.live-count-badge {
  background: rgba(56, 189, 248, 0.2);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  font-size: 0.68rem;
  font-weight: 900;
  padding: 1px 6px;
  border-radius: var(--radius-full);
}

.btn-refresh-mini {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.btn-refresh-mini:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.live-rooms-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.45rem;
}

.empty-rooms-msg {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 0.74rem;
  color: var(--text-dim);
  padding: 0.65rem 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  border: 1px dashed rgba(255, 255, 255, 0.08);
}

.live-room-card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}

.live-room-card:hover {
  background: rgba(56, 189, 248, 0.15);
  border-color: #38bdf8;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.25);
}

.live-room-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.live-room-code {
  font-size: 0.8rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: 0.5px;
}

.live-room-join-tag {
  font-size: 0.65rem;
  font-weight: 800;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.15);
  padding: 1px 5px;
  border-radius: 4px;
}

.live-room-status {
  font-size: 0.68rem;
  font-weight: 700;
}

.live-room-status.waiting {
  color: #4ade80;
}

.live-room-status.playing {
  color: #fbbf24;
}
