/* ── CSS Variables ──────────────────────────────────────────── */
:root {
  /* Shared colours */
  --bg: #0b1220;
  --card: #111d33;
  --border: #2a5d89;
  --border-light: #3f80b2;
  --primary: #06b6d4;
  --muted: #94a3b8;
  --text: #e2e8f0;
  --cyan: #67e8f9;
  --blue-100: #bae6fd;
  --blue-300: #7dd3fc;

  /* Battle-page specific */
  --battle-text-size: 2.85rem;
  --battle-font-family: 'Courier New', monospace;
  --battle-caret-width: 3px;
  --battle-me-color: #06b6d4;
  --battle-opp-color: #f97316;
  --battle-glow: 0 0 10px;

  /* Join-page specific */
  --text-size: 3.35rem;
  --font: 'Courier New', monospace;
}

/* ── Base ───────────────────────────────────────────────────── */
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 12% -14%, #1a3a62, #0b1220 48%);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.topnav {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box;
  margin: 0 !important;
}

/* ── Shared Buttons ─────────────────────────────────────────── */
/* Primary / btn-main */
.btn-primary,
.btn-main {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--primary);
  color: #07222d;
  border: none;
  border-radius: 12px;
  font-weight: 900;
  font-size: 1rem;
  padding: 12px 24px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
.btn-primary:hover,
.btn-main:hover { filter: brightness(1.06); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary ion-icon,
.btn-main ion-icon { font-size: 1.1rem; pointer-events: none; }

/* join.ejs overrides size */
.btn-main {
  font-size: 1.18rem;
  padding: 14px 22px;
}

/* Secondary / btn-sec */
.btn-secondary,
.btn-sec {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: transparent;
  color: var(--blue-300);
  border: 1px solid #3d7aaa;
  border-radius: 12px;
  font-weight: 800;
  font-size: 0.97rem;
  padding: 11px 22px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-secondary:hover,
.btn-sec:hover { background: rgba(6,182,212,0.08); border-color: var(--border-light); }
.btn-secondary ion-icon { font-size: 1.05rem; pointer-events: none; }

/* join.ejs size tweak */
.btn-sec {
  color: #7dd3fc;
  font-size: 1.1rem;
  padding: 13px 18px;
}

/* Danger */
.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(239, 68, 68, 0.13);
  color: #fca5a5;
  padding: 10px 22px;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.26); border-color: #ef4444; color: #fff; }
.btn-danger ion-icon { font-size: 1.05rem; pointer-events: none; }

/* Icon-only button */
.icon-btn ion-icon {
  font-size: 1.05rem;
  pointer-events: none;
}

/* ── Shared Input ───────────────────────────────────────────── */
.input {
  background: #0a1628;
  color: #e2e8f0;
  border: 1px solid #315a84;
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 1.2rem;
}
.input.code {
  width: 220px;
  letter-spacing: 4px;
  text-transform: uppercase;
  text-align: center;
  font-family: monospace;
  font-weight: 800;
}

/* ── Shared layout helpers ──────────────────────────────────── */
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── Shared Caret ───────────────────────────────────────────── */
.caret {
  position: absolute;
  width: 3px;
  border-radius: 2px;
  background: #06b6d4;
  box-shadow: 0 0 10px #06b6d4;
  pointer-events: none;
  transition: top 0.08s, left 0.08s;
  z-index: 2;
}

/* ── Shared Toast ───────────────────────────────────────────── */
/* join.ejs uses .toast, battle.ejs uses .battle-toast — merged below */
.toast,
.battle-toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  background: rgba(7, 22, 37, 0.96);
  border: 1px solid #3d7aaa;
  color: var(--blue-100);
  font-weight: 800;
  font-size: 0.95rem;
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.34);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 350;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 90vw;
  text-align: center;
}
.toast.show,
.battle-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.toast.err,
.battle-toast.err { color: #fecaca; border-color: rgba(239,68,68,0.55); }
.battle-toast { bottom: 28px; font-size: 0.95rem; padding: 12px 20px; border-radius: 14px; box-shadow: 0 8px 28px rgba(0,0,0,0.42); }
.battle-toast ion-icon { font-size: 1.15rem; flex-shrink: 0; pointer-events: none; }

/* ── Shared Spinner ─────────────────────────────────────────── */
.spinner { width: 52px; height: 52px; border: 4px solid #1e3a5f; border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Shared pulse ───────────────────────────────────────────── */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ── Shared board / table ───────────────────────────────────── */
.board {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.board table { width: 100%; border-collapse: collapse; }
.board th, .board td { text-align: left; padding: 10px; border-bottom: 1px solid #1a314d; font-size: 1.02rem; }
.board .name-cell { display: flex; align-items: center; gap: 8px; }

/* ── Shared player name / role ──────────────────────────────── */
.player-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 1.1rem; font-weight: 900; }
.player-role { font-size: 0.95rem; color: #93c5fd; font-weight: 700; }

/* ── Shared live strip / chips (battle + race) ──────────────── */
.battle-live-strip,
.race-live-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  background: rgba(9, 20, 36, 0.88);
  border: 1px solid #23496d;
  border-radius: 999px;
  padding: 8px 10px;
}
.battle-live-strip { width: fit-content; margin: 0 auto; }

.battle-chip,
.race-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(16, 32, 52, 0.92);
  border: 1px solid #315a84;
  font-size: 0.78rem;
  color: #cbd5e1;
}
.battle-chip { max-width: 200px; }
.race-chip   { max-width: 180px; }

.battle-chip-dot,
.race-chip-dot {
  width: 7px;
  height: 16px;
  border-radius: 999px;
  box-shadow: 0 0 8px currentColor;
  flex: 0 0 7px;
}

.battle-chip-name,
.race-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.battle-chip-name { max-width: 132px; }
.race-chip-name  { max-width: 128px; }

.battle-chip-wpm,
.race-chip-wpm {
  color: #7dd3fc;
  font-weight: 900;
  margin-left: auto;
  font-size: 0.72rem;
}

/* ── Shared mini-caret dot ──────────────────────────────────── */
.mini-caret-dot {
  display: inline-block;
  width: 7px;
  height: 16px;
  border-radius: 999px;
  vertical-align: middle;
  margin-right: 7px;
  box-shadow: 0 0 6px currentColor;
}

/* ══════════════════════════════════════════════════════════════
   BATTLE PAGE (battle.ejs)
   ══════════════════════════════════════════════════════════════ */

/* ── Battle Page Layout ─────────────────────────────────────── */
.battle-page { max-width: 1500px; margin: 0 auto; padding: 28px 24px 80px; }
.battle-page h1 {
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 900;
  color: var(--cyan);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.battle-page h1 ion-icon { font-size: 0.85em; }
.battle-page .subtitle { color: var(--muted); margin: 0 0 36px; font-size: 1rem; }

.battle-screen { display: none; }
.battle-screen.active { display: block; }

/* ── Landing cards ──────────────────────────────────────────── */
.battle-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 28px; }
@media (max-width: 768px) { .battle-cards { grid-template-columns: 1fr; } }

.battle-card {
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: 0 10px 26px rgba(3, 14, 26, 0.5);
  transition: border-color 0.18s, transform 0.18s, box-shadow 0.18s;
}
.battle-card:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(3, 14, 26, 0.65);
}
.battle-card h3 {
  margin: 0 0 10px;
  color: var(--blue-100);
  font-size: 1.15rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  gap: 8px;
}
.battle-card h3 ion-icon { font-size: 1.2rem; color: var(--cyan); }
.battle-card p { margin: 0 0 20px; color: var(--muted); font-size: 0.88rem; line-height: 1.55; }

/* ── Room code input (battle landing) ───────────────────────── */
.room-join-row { display: flex; gap: 8px; margin-top: 8px; }
.room-code-input {
  flex: 1;
  background: rgba(10, 22, 40, 0.9);
  border: 1px solid #315a84;
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 1.1rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  font-family: monospace;
  font-weight: 800;
}
.room-code-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(6,182,212,0.15); }

/* ── Stats panel ────────────────────────────────────────────── */
.battle-stats-panel {
  background: linear-gradient(160deg, #0f1e33, #0b1729);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 28px;
  box-shadow: 0 8px 22px rgba(3, 14, 26, 0.4);
}
.battle-stats-panel h3 {
  margin: 0 0 16px;
  color: var(--cyan);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
}
.battle-stats-panel h3 ion-icon { font-size: 1rem; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 500px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-item { text-align: center; }
.stat-value { font-size: 1.8rem; font-weight: 900; color: var(--primary); }
.stat-label { font-size: 0.72rem; color: #64748b; margin-top: 2px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Customization panel ────────────────────────────────────── */
.customization-panel {
  background: linear-gradient(160deg, #0d1c31, #0a1628);
  border: 1px solid #285980;
  border-radius: 20px;
  padding: 22px;
  margin-bottom: 28px;
  box-shadow: 0 8px 22px rgba(3, 14, 26, 0.4);
}
.customization-title {
  margin: 0 0 16px;
  color: var(--cyan);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 7px;
}
.customization-title ion-icon { font-size: 1rem; }
.customization-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
}
@media (max-width: 980px) { .customization-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .customization-grid { grid-template-columns: 1fr; } }
.custom-field {
  background: rgba(10, 18, 32, 0.75);
  border: 1px solid #1e3a5f;
  border-radius: 12px;
  padding: 12px;
}
.custom-field label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  font-weight: 700;
}
.custom-field input[type="range"],
.custom-field select {
  width: 100%;
  background: rgba(11, 18, 32, 0.9);
  border: 1px solid #1e3a5f;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
}
.custom-field select:focus { outline: none; border-color: var(--primary); }
.custom-pill {
  margin-top: 8px;
  color: var(--cyan);
  font-size: 0.76rem;
  font-weight: 700;
}

/* ── Waiting / Queue ────────────────────────────────────────── */
.waiting-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 72px 24px;
}
.waiting-box h2 { font-size: 1.6rem; font-weight: 900; color: var(--text); margin: 0; }
.waiting-box p { color: var(--muted); margin: 0; font-size: 1rem; }

/* ── Private Room screen ────────────────────────────────────── */
#screenRoom.active {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - 66px);
}
.room-stage {
  display: flex; flex-direction: column; align-items: center; gap: 32px;
  text-align: center; position: relative; z-index: 1;
  padding: 80px 32px; width: 100%; max-width: 1120px;
}
.room-eyebrow {
  font-size: 0.7rem; letter-spacing: 8px; text-transform: uppercase;
  color: #1e6080; font-family: 'Courier New', monospace; font-weight: 700;
}
.room-headline {
  font-size: clamp(0.9rem, 2.2vw, 1.15rem); color: #475569;
  font-weight: 500; margin: 0; letter-spacing: 1px;
}
.room-code-giant {
  font-size: clamp(3.8rem, 13vw, 8rem); font-weight: 900;
  letter-spacing: 0.16em; color: #67e8f9;
  font-family: 'Courier New', monospace;
  text-shadow: 0 0 30px rgba(103,232,249,0.5);
  cursor: pointer; user-select: all; line-height: 1;
}
.room-divider {
  width: min(760px, 82vw); height: 1px;
  background: linear-gradient(90deg, transparent, #1a4060, #2a7eb3 40%, #2a7eb3 60%, #1a4060, transparent);
}
.room-action-row {
  display: flex; gap: 14px; flex-wrap: wrap; justify-content: center;
}
.room-waiting-status {
  display: flex; align-items: center; gap: 10px;
  color: #334155; font-size: 0.9rem; font-family: 'Courier New', monospace;
  letter-spacing: 1px;
}
.room-code-display {
  font-size: 2.8rem;
  font-weight: 900;
  letter-spacing: 10px;
  color: var(--primary);
  font-family: monospace;
  background: radial-gradient(circle at 20% -10%, #143154, #0a1d34 62%);
  border: 1px solid #4d8dbb;
  border-radius: 999px;
  padding: 20px 38px;
  display: inline-block;
  box-shadow: 0 10px 32px rgba(0,0,0,0.28);
  cursor: pointer;
  user-select: all;
  transition: transform 0.15s, filter 0.15s;
}
.copy-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(6, 182, 212, 0.08); border: 1px solid #2a5a7a;
  color: var(--primary); padding: 12px 24px; border-radius: 40px;
  cursor: pointer; font-size: 0.9rem; font-weight: 700;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  letter-spacing: 0.5px;
}
.copy-btn:hover { background: rgba(6, 182, 212, 0.18); border-color: var(--primary); box-shadow: 0 0 16px rgba(6,182,212,0.2); }
.copy-btn ion-icon { font-size: 1rem; pointer-events: none; }
.invite-link {
  background: rgba(10, 22, 40, 0.9);
  border: 1px solid #1e3a5f;
  border-radius: 10px;
  padding: 10px 14px;
  color: #cbd5e1;
  width: min(760px, 92vw);
  font-size: 0.85rem;
  font-family: monospace;
  box-sizing: border-box;
}

/* ── Countdown overlay ──────────────────────────────────────── */
#battleCountdownOverlay { position: fixed; inset: 0; background: rgba(5,10,20,0.93); z-index: 100; display: none; align-items: center; justify-content: center; flex-direction: column; backdrop-filter: blur(6px); }
#battleCountdownOverlay.show { display: flex; }
.countdown-num { font-size: 8rem; font-weight: 900; color: var(--cyan); animation: countPop 0.4s cubic-bezier(.36,.07,.19,.97); font-family: monospace; line-height: 1; }
.countdown-num.go { color: #22c55e; font-size: 6rem; }
@keyframes countPop { 0% { transform: scale(2); opacity: 0; } 60% { transform: scale(0.9); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }

/* ── Battle Intro Cinematic Overlay ─────────────────────────── */
#battleIntroOverlay {
  position: fixed; inset: 0; z-index: 200;
  background: radial-gradient(ellipse at 50% 45%, #091426 0%, #040810 60%, #000 100%);
  display: none; align-items: center; justify-content: center; overflow: hidden;
}
#battleIntroOverlay.bi-active { display: flex; }
#battleIntroOverlay::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 30;
  background: repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0,0,0,0.07) 3px, rgba(0,0,0,0.07) 4px);
}
.bi-bar { position: absolute; left: 0; right: 0; height: 12vh; background: #000; z-index: 20; }
.bi-bar-top { top: 0; transform: translateY(-100%); }
.bi-bar-bottom { bottom: 0; transform: translateY(100%); }
#battleIntroOverlay.bi-active .bi-bar-top { animation: biBarT 0.25s ease forwards; }
#battleIntroOverlay.bi-active .bi-bar-bottom { animation: biBarB 0.25s ease forwards; }
@keyframes biBarT { to { transform: translateY(0); } }
@keyframes biBarB { to { transform: translateY(0); } }
#battleIntroOverlay.bi-exit .bi-bar-top { animation: biBarTOut 0.3s ease 0.05s forwards; }
#battleIntroOverlay.bi-exit .bi-bar-bottom { animation: biBarBOut 0.3s ease 0.05s forwards; }
@keyframes biBarTOut { from { transform: translateY(0); } to { transform: translateY(-100%); } }
@keyframes biBarBOut { from { transform: translateY(0); } to { transform: translateY(100%); } }

.bi-player {
  position: absolute; top: 12vh; bottom: 12vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; width: 38%; z-index: 4;
}
.bi-player-left { left: 0; transform: translateX(-130vw); }
.bi-player-right { right: 0; transform: translateX(130vw); }
#battleIntroOverlay.bi-active .bi-player-left  { animation: biInLeft  0.7s cubic-bezier(0.1,0.85,0.3,1.02) 0.05s forwards; }
#battleIntroOverlay.bi-active .bi-player-right { animation: biInRight 0.7s cubic-bezier(0.1,0.85,0.3,1.02) 0.05s forwards; }
#battleIntroOverlay.bi-exit  .bi-player-left   { animation: biOutLeft  0.45s cubic-bezier(0.6,0,1,0.4) forwards; }
#battleIntroOverlay.bi-exit  .bi-player-right  { animation: biOutRight 0.45s cubic-bezier(0.6,0,1,0.4) forwards; }
@keyframes biInLeft  { 0%{transform:translateX(-130vw)} 65%{transform:translateX(5vw)} 82%{transform:translateX(-2vw)} 100%{transform:translateX(0)} }
@keyframes biInRight { 0%{transform:translateX(130vw)}  65%{transform:translateX(-5vw)} 82%{transform:translateX(2vw)}  100%{transform:translateX(0)} }
@keyframes biOutLeft  { to { transform: translateX(-150vw); } }
@keyframes biOutRight { to { transform: translateX(150vw); } }

.bi-avatar-wrap {
  width: min(160px,22vw); height: min(160px,22vw); border-radius: 50%;
  overflow: hidden; position: relative; background: #0f172a;
  border: 3px solid #67e8f9;
  box-shadow: 0 0 24px rgba(103,232,249,.75), 0 0 70px rgba(103,232,249,.25), inset 0 0 14px rgba(103,232,249,.12);
}
.bi-player-right .bi-avatar-wrap {
  border-color: #f97316;
  box-shadow: 0 0 24px rgba(249,115,22,.75), 0 0 70px rgba(249,115,22,.25), inset 0 0 14px rgba(249,115,22,.12);
}
.bi-player-name {
  font-size: clamp(1rem,2.4vw,1.75rem); font-weight: 800; color: #fff;
  letter-spacing: 2px; text-transform: uppercase; font-family: 'Courier New', monospace;
  text-shadow: 0 0 18px rgba(103,232,249,.9), 0 2px 10px rgba(0,0,0,.8);
  opacity: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw;
}
.bi-player-right .bi-player-name { text-shadow: 0 0 18px rgba(249,115,22,.9), 0 2px 10px rgba(0,0,0,.8); }
#battleIntroOverlay.bi-active  .bi-player-name { animation: biFadeUp  0.4s ease 0.88s forwards; }
#battleIntroOverlay.bi-exit    .bi-player-name { animation: biFadeOut 0.25s ease forwards; }
@keyframes biFadeUp  { from { opacity:0; transform:translateY(14px); } to { opacity:1; transform:translateY(0); } }
@keyframes biFadeOut { to   { opacity: 0; } }

.bi-center {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  display: flex; flex-direction: column; align-items: center; z-index: 5; pointer-events: none;
}
.bi-battle-word {
  font-size: clamp(3.5rem,13vw,9.5rem); font-weight: 900; line-height: 0.9;
  color: #67e8f9; letter-spacing: 10px; font-family: 'Courier New', monospace;
  -webkit-text-stroke: 2px #67e8f9;
  text-shadow: 0 0 40px rgba(103,232,249,1), 0 0 80px rgba(103,232,249,.55), 0 0 130px rgba(103,232,249,.22);
  transform: translateY(-130px) scaleX(1.4); opacity: 0;
}
#battleIntroOverlay.bi-active .bi-battle-word { animation: biBattleDrop 0.42s cubic-bezier(0.5,2.2,0.5,0.85) 0.72s forwards; }
#battleIntroOverlay.bi-exit   .bi-battle-word { animation: biBattleExit 0.5s ease-in forwards; }
@keyframes biBattleDrop {
  0%   { transform: translateY(-130px) scaleX(1.4); opacity:0; }
  55%  { transform: translateY(8px)    scaleX(0.97); opacity:1; }
  100% { transform: translateY(0)      scaleX(1);    opacity:1; }
}
@keyframes biBattleExit { to { transform: scale(4.5) translateY(-8px); opacity:0; } }

.bi-vs {
  font-size: clamp(1.8rem,5.5vw,3.8rem); font-weight: 900; letter-spacing: 6px;
  font-family: 'Courier New', monospace; color: #fff; margin-top: 6px;
  text-shadow: 0 0 28px rgba(255,255,255,.9), 0 0 56px rgba(255,255,255,.4);
  transform: scale(0); opacity: 0;
}
#battleIntroOverlay.bi-active .bi-vs { animation: biVsPop  0.5s cubic-bezier(.36,.07,.19,.97) 0.6s forwards; }
#battleIntroOverlay.bi-exit   .bi-vs { animation: biVsOut  0.28s ease-in forwards; }
@keyframes biVsPop { 0%{transform:scale(0);opacity:0} 60%{transform:scale(1.3);opacity:1} 100%{transform:scale(1);opacity:1} }
@keyframes biVsOut { to { transform: scale(0); opacity: 0; } }

.bi-flash {
  position: absolute; inset: 0; background: rgba(255,255,255,.88);
  opacity: 0; pointer-events: none; z-index: 25;
}
#battleIntroOverlay.bi-active .bi-flash { animation: biFlash 0.14s ease-out 0.71s; }
@keyframes biFlash { 40% { opacity: .88; } 100% { opacity: 0; } }

.bi-bg-pulse {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(ellipse at center, rgba(103,232,249,.12) 0%, transparent 65%);
  opacity: 0;
}
#battleIntroOverlay.bi-active .bi-bg-pulse { animation: biBgPulse 0.35s ease 0.7s; }
@keyframes biBgPulse { 45% { opacity: 1; } 100% { opacity: 0; } }

.bi-energy-line {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 0; height: 3px; opacity: 0; z-index: 6;
  background: linear-gradient(90deg, transparent 0%, #67e8f9 25%, #fff 50%, #f97316 75%, transparent 100%);
}
#battleIntroOverlay.bi-active .bi-energy-line { animation: biEnergyLine 0.45s cubic-bezier(.19,1,.22,1) 0.72s forwards; }
@keyframes biEnergyLine { 0%{width:0;opacity:1} 55%{width:82vw;opacity:.9} 100%{width:82vw;opacity:0} }

.bi-spark { position: absolute; border-radius: 50%; pointer-events: none; z-index: 15; }
@keyframes biSparkFly {
  0%   { transform: translate(-50%,-50%) translate(0,0); opacity: 1; }
  100% { transform: translate(-50%,-50%) translate(var(--stx),var(--sty)); opacity: 0; }
}

/* ── Battle arena ───────────────────────────────────────────── */
.battle-arena { display: flex; flex-direction: column; gap: 16px; align-items: center; }
.battle-arena > .battle-header,
.battle-arena > .progress-bars,
.battle-arena > #canvasContainer,
.battle-arena > .battle-finish-banner,
.battle-arena > .battle-hud,
.battle-arena > .battle-timer,
.battle-arena > .forfeit-row {
  width: min(1320px, 96vw);
  margin-left: auto;
  margin-right: auto;
}
.battle-header { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center; }
.player-info {
  background: linear-gradient(160deg, #0f1e33, #0b1729);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 18px;
  box-shadow: 0 8px 20px rgba(3, 14, 26, 0.4);
}
.player-info.me { border-color: var(--battle-me-color); box-shadow: 0 0 0 1px rgba(6,182,212,0.18), 0 8px 20px rgba(3,14,26,0.4); }
.player-info.opp { border-color: var(--battle-opp-color); box-shadow: 0 0 0 1px rgba(249,115,22,0.18), 0 8px 20px rgba(3,14,26,0.4); }
.player-name.me { color: var(--battle-me-color); }
.player-name.opp { color: var(--battle-opp-color); }
.player-wpm { font-size: 1.5rem; font-weight: 900; }
.player-wpm .wpm-unit { font-size: 0.68rem; color: #64748b; font-weight: 400; }
.vs-badge {
  font-size: 0.85rem;
  font-weight: 900;
  color: #475569;
  text-align: center;
  background: linear-gradient(160deg, #0f1e33, #0b1729);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.progress-bars { display: flex; flex-direction: column; gap: 8px; }
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-label { width: 110px; font-size: 0.78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: right; flex-shrink: 0; }
.progress-label.opp { text-align: left; order: 2; }
.progress-track { flex: 1; height: 10px; background: #1e293b; border-radius: 5px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 5px; transition: width 0.15s ease-out; }
.progress-fill.me { background: linear-gradient(90deg, #06b6d4, #0891b2); box-shadow: 0 0 8px rgba(6,182,212,0.45); }
.progress-fill.opp { background: linear-gradient(90deg, #f97316, #ea580c); box-shadow: 0 0 8px rgba(249,115,22,0.35); }

/* ── Typing area (battle) ───────────────────────────────────── */
#canvasContainer {
  background: linear-gradient(160deg, #0f1e33, #0b1729);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px;
  position: relative;
  min-height: clamp(260px, 38vh, 430px);
  overflow-x: hidden;
  overflow-y: auto;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 10px 28px rgba(0,0,0,0.22);
  cursor: text;
}
#typingContent { font-size: var(--battle-text-size); line-height: 1.9; font-family: var(--battle-font-family); user-select: none; min-height: 120px; position: relative; font-weight: 700; letter-spacing: 0.5px; }
#canvasContainer::-webkit-scrollbar { display: none; }
#typingContent .word { display: inline-block; white-space: nowrap; }
#typingContent .char { display: inline; white-space: pre; color: #64748b; }
#typingContent .char.correct { color: #4ade80; }
#typingContent .char.incorrect { color: #f87171; text-decoration: underline; }
#typingContent .word-overflow {
  display: inline;
  color: #f97316;
  opacity: 0.92;
  font-weight: 800;
  text-decoration: underline;
  margin-left: 1px;
}
#hiddenInput { position: absolute; opacity: 0; pointer-events: none; top: 0; left: 0; width: 1px; height: 1px; }
.caret-battle { position: absolute; width: var(--battle-caret-width); height: 1.4em; border-radius: 2px; pointer-events: none; transition: top 0.08s, left 0.08s; z-index: 2; }
.caret-me { background: var(--battle-me-color); box-shadow: var(--battle-glow) var(--battle-me-color); animation: blink-me 1s step-end infinite; }
body.typing-active .caret-me { animation: none; opacity: 1; }
.caret-opp { background: var(--battle-opp-color); box-shadow: var(--battle-glow) var(--battle-opp-color); opacity: 0.8; transition: top 0.2s ease-out, left 0.2s ease-out; }
@keyframes blink-me { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
.typing-click-hint {
  position: absolute;
  inset: 0;
  background: rgba(5,10,20,0.75);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
  backdrop-filter: blur(2px);
  gap: 8px;
}
.typing-click-hint ion-icon { font-size: 1.4rem; color: var(--primary); pointer-events: none; }
.battle-timer { text-align: center; font-size: 0.85rem; color: #64748b; }
.battle-timer span { color: var(--primary); font-weight: 700; }
.forfeit-row { text-align: center; }

/* ── HUD ────────────────────────────────────────────────────── */
.battle-hud {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
@media (max-width: 700px) { .battle-hud { grid-template-columns: 1fr; gap: 8px; } }
.hud-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(40,89,128,0.5);
  border-radius: 14px;
  padding: 12px 16px;
  text-align: center;
}
.hud-label {
  color: #64748b;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.hud-label ion-icon { font-size: 0.9rem; pointer-events: none; }
.hud-value { color: var(--text); font-size: 1.1rem; font-weight: 900; margin-top: 6px; }
.hud-value.leading { color: #4ade80; }
.hud-value.trailing { color: #f87171; }
.momentum-track { height: 10px; background: #1e293b; border-radius: 6px; overflow: hidden; margin-top: 9px; }
.momentum-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #f59e0b, #22c55e); transition: width 0.2s ease; }

.battle-finish-banner {
  display: none;
  text-align: center;
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.28);
  color: var(--blue-100);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.9rem;
  font-weight: 700;
}
.battle-finish-banner.show { display: block; }

/* ── Result screen (battle) ─────────────────────────────────── */
.result-screen {
  width: min(1120px, 100%);
  margin: 0 auto;
  text-align: center;
  padding: 48px 24px;
}
.result-icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  font-size: 3.5rem;
  margin-bottom: 20px;
  animation: resultPop 0.5s cubic-bezier(.36,.07,.19,.97);
}
.result-icon-wrap.win { background: radial-gradient(circle, rgba(34,197,94,0.18), transparent 70%); color: #22c55e; filter: drop-shadow(0 0 18px rgba(34,197,94,0.45)); }
.result-icon-wrap.lose { background: radial-gradient(circle, rgba(239,68,68,0.18), transparent 70%); color: #ef4444; filter: drop-shadow(0 0 14px rgba(239,68,68,0.35)); }
.result-icon-wrap.draw { background: radial-gradient(circle, rgba(245,158,11,0.18), transparent 70%); color: #f59e0b; }
@keyframes resultPop { 0% { transform: scale(0); opacity: 0; } 80% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
.result-title { font-size: 2.5rem; font-weight: 900; margin: 0 0 8px; }
.result-title.win { color: #22c55e; text-shadow: 0 0 20px rgba(34,197,94,0.5); }
.result-title.lose { color: #ef4444; }
.result-title.draw { color: #f59e0b; }
.result-subtitle { color: var(--muted); margin: 0 0 16px; font-size: 1rem; }
.result-roast {
  max-width: 980px;
  margin: 0 auto 24px;
  padding: 14px 18px;
  border-radius: 12px;
  background: rgba(239, 68, 68, 0.10);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: #fecaca;
  font-weight: 700;
  line-height: 1.4;
  font-size: 1rem;
  display: none;
}
.result-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px 40px;
  background: linear-gradient(160deg, #0f1e33, #0b1729);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 36px;
  margin-bottom: 28px;
  text-align: left;
  box-shadow: 0 10px 26px rgba(3,14,26,0.4);
  width: min(980px, 100%);
  margin-left: auto;
  margin-right: auto;
}
@media (max-width: 900px) { .result-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .result-stats { grid-template-columns: 1fr; padding: 20px 22px; gap: 12px; } }
.result-stat-label { font-size: 0.75rem; color: #64748b; text-transform: uppercase; letter-spacing: 1px; }
.result-stat-value { font-size: 1.6rem; font-weight: 900; color: var(--text); }
.result-stat-value.highlight { color: #22c55e; }
.coins-banner {
  background: linear-gradient(135deg, #1c2f1a, #1a2d0f);
  border: 1px solid #22c55e;
  border-radius: 14px;
  padding: 16px 28px;
  margin: 0 auto 28px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #4ade80;
  font-size: 1.1rem;
  font-weight: 800;
}
.coins-banner.animate { animation: coinPop 900ms ease; }
.coins-icon {
  width: 26px;
  height: 26px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(34, 197, 94, 0.45));
  animation: coinSpin 1.2s ease;
}
.coins-amount { font-size: 2rem; font-weight: 900; color: #22c55e; }
@keyframes coinPop {
  0% { transform: scale(0.9); opacity: 0.7; }
  55% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes coinSpin {
  0% { transform: rotateY(0deg) scale(0.8); }
  55% { transform: rotateY(180deg) scale(1.08); }
  100% { transform: rotateY(360deg) scale(1); }
}
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.rematch-pending { color: #f59e0b; font-size: 0.9rem; margin-top: 12px; animation: pulse 1s ease-in-out infinite; }
.opponent-forfeit { color: #f59e0b; font-size: 0.85rem; margin-top: 8px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.opponent-forfeit ion-icon { font-size: 1rem; }

/* ── Battle history ─────────────────────────────────────────── */
.history-section { margin-top: 36px; }
.history-section h3 {
  color: var(--cyan);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin: 0 0 14px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 7px;
}
.history-section h3 ion-icon { font-size: 1rem; }
.history-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.history-table th { text-align: left; padding: 10px 14px; color: #475569; font-weight: 700; border-bottom: 1px solid #1e3a5f; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
.history-table td { padding: 12px 14px; border-bottom: 1px solid rgba(30,58,95,0.5); }
.history-table tr:hover td { background: rgba(15,30,51,0.6); }
.badge-win {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(34,197,94,0.15);
  color: #4ade80;
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 800;
}
.badge-lose {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(239,68,68,0.15);
  color: #f87171;
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 800;
}

/* ── FX canvas ──────────────────────────────────────────────── */
#battleFxCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 120;
  pointer-events: none;
  display: none;
}

/* ── Win/lose shake ─────────────────────────────────────────── */
body.win-shake .result-screen { animation: winPulse 700ms ease-in-out 2; }
body.lose-shake .result-screen { animation: loseTilt 520ms ease-in-out 2; }
@keyframes winPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}
@keyframes loseTilt {
  0% { transform: rotate(0deg); }
  25% { transform: rotate(-0.8deg); }
  75% { transform: rotate(0.8deg); }
  100% { transform: rotate(0deg); }
}

/* ── Rematch modal ──────────────────────────────────────────── */
.rematch-modal {
  position: fixed;
  inset: 0;
  z-index: 420;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(4, 10, 18, 0.82);
  backdrop-filter: blur(3px);
  padding: 16px;
}
.rematch-modal.show { display: flex; }
.rematch-card {
  width: min(520px, 100%);
  background: linear-gradient(160deg, #0f1e33, #0b1729);
  border: 1px solid #2a5d89;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.46);
  text-align: center;
}
.rematch-card h3 {
  margin: 0 0 8px;
  color: #67e8f9;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.rematch-card p { margin: 0 0 16px; color: #cbd5e1; }
.rematch-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ── Battle mobile ──────────────────────────────────────────── */
@media (max-width: 600px) {
  .battle-page { padding: 16px 12px 60px; }
  .battle-page h1 { font-size: 1.65rem; }
  #canvasContainer { padding: 18px 14px; }
  :root { --battle-text-size: 1.85rem; }
  .progress-label { width: 72px; font-size: 0.72rem; }
  .player-wpm { font-size: 1.2rem; }
  .result-stats { padding: 18px 16px; }
  .waiting-box { padding: 48px 16px; }
  .room-code-display { font-size: 2.1rem; letter-spacing: 6px; padding: 16px 26px; }
}
@media (max-width: 400px) {
  :root { --battle-text-size: 1.55rem; }
  .battle-header { gap: 6px; }
  .player-info { padding: 10px 12px; }
}

/* ══════════════════════════════════════════════════════════════
   JOIN / GROUP ROOM PAGE (join.ejs)
   ══════════════════════════════════════════════════════════════ */

/* ── Join page layout ───────────────────────────────────────── */
.page { max-width: 100%; margin: 0 auto; padding: 42px 5vw 96px; }
.screen { display: none; }
.screen.active { display: block; }
.title { font-size: clamp(2.6rem, 5.2vw, 3.6rem); color: #67e8f9; margin: 0; }
.subtitle { color: var(--muted); margin: 10px 0 20px; font-size: 1.2rem; }

.card {
  background: linear-gradient(160deg, #0f1e33, #0b1729);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px;
  box-shadow: 0 10px 26px rgba(3, 14, 26, 0.5);
}

.lobby-stack {
  display: grid;
  gap: 22px;
  width: min(1320px, 100%);
  margin: 0 auto;
}
.lobby-controls { display: grid; gap: 18px; justify-items: center; }
#screenLobby { max-width: 100% !important; }
#screenLobby .card { max-width: 100% !important; }

/* ── Entry card ─────────────────────────────────────────────── */
.entry-card {
  width: min(980px, 100%);
  display: grid;
  gap: 16px;
  border-radius: 26px;
  border-color: #3f80b2;
  background: linear-gradient(165deg, rgba(12, 28, 47, 0.96), rgba(8, 18, 33, 0.96));
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.36);
}
.entry-help {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid rgba(103, 232, 249, 0.35);
  color: #bae6fd;
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 700;
}
.entry-help ion-icon { font-size: 1.15rem; color: #67e8f9; }
.entry-code-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  align-items: center;
}
.entry-code-row .input.code {
  flex: 1 1 320px;
  min-width: 190px;
  width: auto;
  font-size: 1.42rem;
  letter-spacing: 6px;
}
.entry-code-row .btn-main,
.entry-code-row .btn-sec {
  flex: 0 0 auto;
  min-width: 150px;
  white-space: nowrap;
}
.entry-tip {
  margin: 0;
  color: #94a3b8;
  font-size: 0.94rem;
  text-align: center;
}

/* ── Code pill ──────────────────────────────────────────────── */
.code-pill {
  display: inline-block;
  text-align: center;
  background: radial-gradient(circle at 20% -10%, #143154, #0a1d34 62%);
  border: 1px solid #4d8dbb;
  color: #a5f3fc;
  font-family: monospace;
  letter-spacing: 8px;
  font-size: clamp(2.8rem, 7.8vw, 4.2rem);
  font-weight: 900;
  border-radius: 999px;
  padding: 18px 34px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.16s ease, filter 0.16s ease;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.28);
}
.code-pill:hover { transform: translateY(-1px); filter: brightness(1.08); }

body.viewer-lobby .code-pill {
  font-size: clamp(1rem, 3vw, 1.5rem);
  letter-spacing: 3px;
  padding: 6px 10px;
  border-style: solid;
  opacity: 0.75;
  margin-left: auto;
  transform: translateY(-6px);
}

/* ── Players list ───────────────────────────────────────────── */
.players-wrap {
  margin-top: 4px;
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(42,91,132,0.3);
  border-radius: 16px;
  padding: 16px;
}
.players-title-row { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.players-title { margin: 0; color: #bae6fd; font-size: 1.2rem; font-weight: 900; text-transform: uppercase; letter-spacing: 1px; }
.player-count-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(125,211,252,0.1);
  border: 1px solid rgba(125,211,252,0.25);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #7dd3fc;
  transition: background 0.25s, transform 0.25s;
}
.player-count-badge.bump {
  background: rgba(125,211,252,0.22);
  transform: scale(1.08);
}
/* Odometer overrides — keep it inline with the badge */
.player-count-badge .odometer {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  line-height: 1;
}
.player-count-badge .odometer.odometer-animating-up .odometer-ribbon-inner,
.player-count-badge .odometer.odometer-animating-down .odometer-ribbon-inner {
  transition-duration: 0.55s;
  transition-timing-function: cubic-bezier(0.25, 1, 0.5, 1);
}
.player-count-label { color: #94a3b8; font-weight: 500; }
@keyframes player-join-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}
.player-join-anim { animation: player-join-in 0.22s cubic-bezier(0.22,1,0.36,1) both; }
.players { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.players li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 13px;
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(46,98,142,0.4);
}
.player-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.player-right { display: flex; align-items: center; gap: 8px; }
.avatar-mini { width: 36px; height: 46px; border-radius: 7px; border: 1px solid #375f86; background: #0b1220; overflow: hidden; position: relative; flex: 0 0 36px; }

.players li.kickable-user {
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}
.players li.kickable-user:hover {
  transform: translateY(-1px);
  border-color: #ef4444;
  box-shadow: 0 10px 22px rgba(127, 29, 29, 0.32);
}
.players li.kickable-user:hover .player-name {
  color: #fecaca;
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.player-audio-mini {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid #3d7aaa;
  background: rgba(8, 22, 38, 0.92);
  color: #a5f3fc;
  cursor: pointer;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* ── Ready overlay ──────────────────────────────────────────── */
.ready-overlay {
  position: fixed;
  inset: 0;
  z-index: 160;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: rgba(3,7,18,0.97);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease, transform 0.45s ease;
  transform: scale(1);
}
.ready-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, transparent, transparent 3px, rgba(0,0,0,0.1) 3px, rgba(0,0,0,0.1) 4px);
  pointer-events: none;
  z-index: 0;
}
.ready-overlay.show { opacity: 1; pointer-events: all; }
.ready-overlay.fade-out { opacity: 0; transform: scale(1.06); pointer-events: none; }
.ready-text {
  font-size: clamp(3rem, 12vw, 7rem);
  font-weight: 900;
  color: #67e8f9;
  letter-spacing: 4px;
  text-shadow: 0 0 60px rgba(103,232,249,0.9), 0 0 120px rgba(103,232,249,0.4);
  text-align: center;
  transform: scale(0.4);
  opacity: 0;
  position: relative;
  z-index: 1;
}
.ready-overlay.show .ready-text {
  animation: readyPop 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) forwards, readyGlow 0.9s 0.7s ease-in-out infinite alternate;
}
.ready-sub {
  font-size: clamp(0.9rem, 2.5vw, 1.3rem);
  color: #94a3b8;
  font-weight: 700;
  letter-spacing: 4px;
  text-align: center;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(12px);
  position: relative;
  z-index: 1;
}
.ready-overlay.show .ready-sub { animation: readySubSlide 0.4s 0.35s ease forwards; }
.ready-timer-bar {
  position: absolute;
  bottom: 0; left: 0;
  height: 4px; width: 100%;
  background: linear-gradient(90deg, #67e8f9, #818cf8, #f472b6);
  transform-origin: left;
  transform: scaleX(1);
  opacity: 0;
  z-index: 2;
}
.ready-overlay.show .ready-timer-bar { animation: readyTimerDrain 2s linear forwards; }
.ready-bars { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 1; }
.ready-bar { position: absolute; left: 0; right: 0; height: 3px; background: linear-gradient(90deg, transparent, #67e8f9, transparent); opacity: 0; }
.ready-overlay.show .ready-bar-top { top: 0; animation: readyBarSweep 0.7s 0.1s ease forwards; }
.ready-overlay.show .ready-bar-bottom { bottom: 0; animation: readyBarSweep 0.7s 0.2s ease forwards; }
@keyframes readyPop {
  0%   { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.13); opacity: 1; }
  80%  { transform: scale(0.97); }
  100% { transform: scale(1);    opacity: 1; }
}
@keyframes readyGlow {
  from { text-shadow: 0 0 40px rgba(103,232,249,0.8), 0 0 80px rgba(103,232,249,0.3); }
  to   { text-shadow: 0 0 90px rgba(103,232,249,1), 0 0 160px rgba(103,232,249,0.7), 0 0 220px rgba(129,140,248,0.5); }
}
@keyframes readySubSlide {
  0%   { transform: translateY(12px); opacity: 0; }
  100% { transform: translateY(0);    opacity: 1; }
}
@keyframes readyBarSweep {
  0%   { opacity: 0; transform: scaleX(0); }
  40%  { opacity: 1; }
  100% { opacity: 0; transform: scaleX(1); }
}
@keyframes readyTimerDrain {
  0%   { transform: scaleX(1); opacity: 1; }
  95%  { opacity: 1; }
  100% { transform: scaleX(0); opacity: 0.4; }
}

/* ── Countdown (join) ───────────────────────────────────────── */
.countdown {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 10, 20, 0.93);
  font-size: 7rem;
  font-weight: 900;
  color: #67e8f9;
}
.countdown.show { display: flex; }

/* ── Arena / board / typing (join) ─────────────────────────── */
.arena { display: grid; gap: 20px; }

.typing-wrap {
  background: #131f35;
  border: 1px solid #1e3a5f;
  border-radius: 12px;
  padding: 30px;
  position: relative;
  min-height: clamp(320px, 44vh, 520px);
  overflow-x: hidden;
  overflow-y: auto;
}
.typing-wrap::-webkit-scrollbar { display: none; }
.typing {
  font-size: var(--text-size);
  line-height: 1.9;
  font-family: var(--font);
  user-select: none;
  min-height: 120px;
  position: relative;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.typing .word { display: inline; }
.typing .char { display: inline; white-space: pre; color: #64748b; }
.typing .word-overflow { display: inline; }
.typing .overflow-char { color: #ef4444; text-decoration: underline; }
.typing .char.correct { color: #4ade80; }
.typing .char.incorrect { color: #f87171; text-decoration: underline; }
.remote-carets { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.remote-caret {
  position: absolute;
  width: 7px;
  height: 26px;
  border-radius: 999px;
  box-shadow: 0 0 10px currentColor;
  opacity: 0;
  transition: top 0.08s, left 0.08s, opacity 0.12s;
}
.remote-caret.show { opacity: 0.92; }

/* ── Monitor grid ───────────────────────────────────────────── */
.monitor-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 980px) { .monitor-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .monitor-grid { grid-template-columns: 1fr; } }
@media (max-width: 620px) {
  .entry-code-row { flex-wrap: wrap; }
  .entry-code-row .input.code { flex-basis: 100%; width: 100%; }
  .entry-code-row .btn-main,
  .entry-code-row .btn-sec { width: 100%; }
}
.monitor-kpi {
  background: linear-gradient(165deg, #0d1c31, #0a1628);
  border: 1px solid #285980;
  border-radius: 14px;
  padding: 16px 18px;
}
.monitor-kpi-label { color: #93c5fd; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 1px; }
.monitor-kpi-value { color: #e2e8f0; font-size: 1.54rem; font-weight: 900; margin-top: 6px; }
.monitor-live-view {
  background: linear-gradient(165deg, #0c1a2e, #091525);
  border: 1px solid #2b597f;
  border-radius: 22px;
  padding: 28px 34px;
  min-height: 360px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 10px 28px rgba(0,0,0,0.3);
}
.monitor-live-head {
  color: #93c5fd;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.monitor-track {
  position: relative;
  height: 270px;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid #2f638f;
  background: radial-gradient(circle at 15% -20%, rgba(24, 70, 110, 0.3), rgba(10, 20, 36, 0.95) 50%);
}
.monitor-world {
  position: absolute;
  inset: 0 auto 0 0;
  height: 100%;
  will-change: transform;
  transition: transform 0.16s linear;
}
.monitor-line {
  position: absolute;
  left: 0; right: auto; bottom: 34px;
  white-space: nowrap;
  font-family: var(--font);
  font-size: clamp(2.15rem, 3.9vw, 3.2rem);
  line-height: 1.45;
  font-weight: 900;
  color: #6b8dae;
  user-select: none;
  padding: 0 28px;
}
.monitor-char { display: inline-block; white-space: pre; min-width: 0.62ch; }
.monitor-carets { position: absolute; inset: 0; pointer-events: none; }
.monitor-caret {
  position: absolute;
  bottom: 32px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: left 0.16s ease, bottom 0.16s ease;
}
.monitor-caret-stick {
  width: 4px; height: 22px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
}
.monitor-caret-avatar {
  width: 28px; height: 36px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(6, 16, 28, 0.9);
  overflow: hidden;
}
.monitor-caret-name {
  max-width: 86px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.66rem;
  font-weight: 900;
  color: #dbeafe;
  text-shadow: 0 1px 4px rgba(0,0,0,0.65);
  margin-bottom: 1px;
}
.monitor-offboard {
  position: absolute;
  left: 8px; bottom: 6px;
  color: #fca5a5;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.4px;
  opacity: 0.86;
}

/* ── Host actions / lobby controls ─────────────────────────── */
.host-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.lobby-controls .host-actions { justify-content: center; }
.room-audio-btn { min-width: 160px; text-align: center; font-weight: 900; }
.audio-toggle {
  position: static;
  width: 38px; height: 38px;
  border-radius: 999px;
  border: 1px solid #3d7aaa;
  background: rgba(8, 22, 38, 0.92);
  color: #a5f3fc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  z-index: 2;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
}
.audio-toggle:hover { filter: brightness(1.08); }

.lobby-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

/* ── Jointool (host-only) ───────────────────────────────────── */
.jointool {
  margin: 0;
  color: #94a3b8;
  font-size: 2.02rem;
  font-weight: 700;
  text-align: right;
  background-color: rgba(103, 232, 249, 0.04);
  border-radius: 20px;
  padding: 10px;
}
body.viewer-lobby .jointool { display: none; }

/* ── Name modal ─────────────────────────────────────────────── */
.name-modal {
  position: fixed;
  inset: 0;
  z-index: 220;
  background: rgba(2, 5, 11, 0.995);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.name-modal-card {
  width: min(90vw, 1720px);
  min-height: min(74vh, 720px);
  background: #091325;
  border: 1px solid #35658f;
  border-radius: 22px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 10px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.45);
  animation: modalRise 0.42s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.name-modal-title { margin: 0 0 14px; color: #67e8f9; font-size: clamp(2.2rem, 5vw, 3.2rem); }
.name-modal-subtitle { margin: 0 0 20px; color: #94a3b8; font-size: 1.22rem; }
.host-setting-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 6px 0 14px;
  justify-content: center;
}
.host-mode-btn {
  background: #0a1628;
  color: #cbd5e1;
  border: 1px solid #315a84;
  border-radius: 10px;
  padding: 20px 24px;
  font-weight: 800;
  font-size: 1.3rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 260px;
  justify-content: center;
}
.host-mode-btn.active {
  border-color: #06b6d4;
  color: #a5f3fc;
  box-shadow: 0 0 0 1px rgba(6, 182, 212, 0.35) inset;
}
.name-modal .row .input { min-height: 58px; }
.name-modal .row .btn-main { min-height: 58px; min-width: 180px; }
.name-modal .row { justify-content: center; width: 100%; }
@keyframes modalRise {
  0% { transform: translateY(26px) scale(0.98); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

#screenEntry.active {
  min-height: calc(100vh - 140px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#screenEntry .card { width: min(980px, 100%); }

/* ── Result / podium (join) ─────────────────────────────────── */
#screenResult.active {
  width: min(1700px, 100%);
  margin: 0 auto;
  display: grid;
  justify-items: center;
  gap: 14px;
  padding-top: 14px;
}
#screenResult .title {
  text-align: center;
  font-size: clamp(3rem, 5.8vw, 4.8rem);
  letter-spacing: 1px;
  text-shadow: 0 10px 34px rgba(103, 232, 249, 0.18);
}

#screenHostMonitor.active {
  display: grid;
  gap: 14px;
  width: 100%;
  margin: 0 auto;
}
#screenHostMonitor .arena { width: 100%; }
#screenHostMonitor .monitor-live-view { width: 100%; margin: 0 auto; }
@media (min-width: 1280px) {
  #screenHostMonitor.active {
    width: min(1880px, calc(100vw - 24px));
    margin-left: calc(50% - 50vw + 12px);
    margin-right: calc(50% - 50vw + 12px);
  }
  #screenHostMonitor .monitor-live-view { width: min(100%, 1820px); }
}

.podium {
  width: min(1440px, calc(100vw - 36px));
  background: linear-gradient(160deg, #0d1d35, #091525);
  border: 1px solid #1e4060;
  border-radius: 24px;
  padding: 30px 24px 24px;
  margin: 0 auto;
  position: relative;
  box-shadow: 0 22px 52px rgba(2, 8, 18, 0.54);
}
.podium::before {
  content: '';
  position: absolute;
  inset: -40px 10% auto;
  height: 160px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(103, 232, 249, 0.18), transparent 70%);
  filter: blur(22px);
  pointer-events: none;
}
.podium-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.28fr) minmax(0, 1fr);
  gap: 16px;
  align-items: end;
  min-height: clamp(390px, 52vh, 620px);
  margin-bottom: 16px;
}
.podium-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  opacity: 0;
  transform: translateY(30px) scale(0.94);
  transition: opacity 0.8s cubic-bezier(0.2,0.8,0.2,1), transform 0.8s cubic-bezier(0.2,0.8,0.2,1);
}
.podium-slot.show { opacity: 1; transform: translateY(0) scale(1); }
.podium-reveal {
  position: absolute;
  top: 14px; left: 6px; right: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  pointer-events: none;
}
.podium-rank {
  font-size: 1.7rem;
  font-weight: 900;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0,0,0,0.6);
  line-height: 1;
}
.podium-avatar {
  width: 72px; height: 94px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(7, 19, 34, 0.6);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.podium-slot#slot1 .podium-avatar {
  width: 92px;
  height: 118px;
}
.podium-slot#slot2 .podium-avatar {
  width: 80px;
  height: 104px;
}
.podium-slot#slot3 .podium-avatar {
  width: 70px;
  height: 90px;
}
.podium-name {
  font-size: 1rem;
  font-weight: 900;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.97);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
  background: rgba(0,0,0,0.3);
  padding: 4px 10px;
  border-radius: 6px;
}
.podium-slot#slot1 .podium-name { font-size: 1.08rem; }
.podium-slot#slot2 .podium-name { font-size: 1rem; }
.podium-slot#slot3 .podium-name { font-size: 0.92rem; }
.podium-column {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border-radius: 18px 18px 0 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-bottom: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-weight: 900;
  font-size: 2.55rem;
  color: rgba(255,255,255,0.25);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
  padding-bottom: 12px;
  padding-top: 124px;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.15), 0 14px 28px rgba(0,0,0,0.22);
}
.podium-col-1 { height: clamp(270px, 36vh, 420px); font-size: 3rem; background: linear-gradient(180deg, #16a34a, #14532d); }
.podium-col-2 { height: clamp(210px, 30vh, 330px); font-size: 2.4rem; background: linear-gradient(180deg, #94a3b8, #475569); }
.podium-col-3 { height: clamp(170px, 24vh, 260px); font-size: 2rem; background: linear-gradient(180deg, #d97706, #92400e); }
.podium-suspense {
  display: none;
  color: #fef08a;
  font-weight: 900;
  font-size: 1.3rem;
  letter-spacing: 3px;
  text-align: center;
  margin-top: 12px;
  text-shadow: 0 0 20px rgba(254,240,138,0.5);
  animation: pulseText 0.8s ease infinite;
}
.podium-suspense.show { display: block; }

.emoji-banner {
  font-size: clamp(4rem, 18vw, 10rem);
  text-align: center;
  line-height: 1.2;
  animation: emojiBounce 0.6s cubic-bezier(0.2,1.4,0.4,1) forwards;
  transform: scale(0);
  filter: drop-shadow(0 8px 24px rgba(0,0,0,0.6));
}
@keyframes emojiBounce {
  0% { transform: scale(0) rotate(-10deg); }
  70% { transform: scale(1.15) rotate(3deg); }
  100% { transform: scale(1) rotate(0deg); }
}
.board-blurred { filter: blur(6px); transition: filter 0.6s ease; }
.snark-line {
  margin-top: 12px;
  color: #fdba74;
  font-weight: 800;
  text-align: center;
  min-height: 30px;
  font-size: 1.08rem;
}

#screenResult .board {
  width: min(1200px, 100%);
  margin: 18px auto 0;
}
#screenResult .board th,
#screenResult .board td { padding: 14px 16px; font-size: 1.08rem; }

/* ── Join result responsive ─────────────────────────────────── */
@media (max-width: 980px) {
  #screenResult.active { width: 100%; gap: 12px; }
  #screenResult .title { font-size: clamp(2.3rem, 7vw, 3.3rem); }
  .podium { width: min(100%, calc(100vw - 24px)); padding: 22px 14px 18px; }
  .podium-stage { gap: 10px; min-height: clamp(260px, 38vh, 420px); grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, 1fr); }
  .podium-column { width: 100%; max-width: 100%; font-size: 2rem; padding-top: 96px; }
  .podium-avatar { width: 72px; height: 92px; }
  .podium-slot#slot1 .podium-avatar { width: 82px; height: 106px; }
  .podium-slot#slot2 .podium-avatar { width: 72px; height: 94px; }
  .podium-slot#slot3 .podium-avatar { width: 64px; height: 84px; }
  .podium-name { font-size: 0.92rem; }
  .podium-slot#slot1 .podium-name { font-size: 1rem; }
  .podium-slot#slot2 .podium-name { font-size: 0.92rem; }
  .podium-slot#slot3 .podium-name { font-size: 0.86rem; }
  .podium-rank { font-size: 1.3rem; }
  #screenResult .board { width: 100%; }
  #screenResult .board th,
  #screenResult .board td { padding: 12px 10px; font-size: 0.96rem; }
}
@media (max-width: 620px) {
  .monitor-live-view { padding: 22px 18px; }
  .podium { padding: 18px 10px 14px; }
  .podium-stage { gap: 6px; min-height: 220px; grid-template-columns: 1fr; }
  .podium-column { width: 100%; border-radius: 14px 14px 0 0; font-size: 1.4rem; padding-top: 72px; padding-bottom: 8px; }
  .podium-avatar { width: 42px; height: 56px; border-radius: 8px; }
  .podium-slot#slot1 .podium-avatar { width: 52px; height: 70px; }
  .podium-slot#slot2 .podium-avatar { width: 46px; height: 60px; }
  .podium-slot#slot3 .podium-avatar { width: 42px; height: 52px; }
  .podium-name { font-size: 0.74rem; padding: 2px 6px; }
  .podium-slot#slot1 .podium-name { font-size: 0.82rem; }
  .podium-slot#slot2 .podium-name { font-size: 0.74rem; }
  .podium-slot#slot3 .podium-name { font-size: 0.7rem; }
  .podium-rank { font-size: 1.05rem; }
  .snark-line { font-size: 0.94rem; }
  #screenResult .board { overflow-x: auto; }
  #screenResult .board table { min-width: 540px; }
  #screenResult .board th,
  #screenResult .board td { padding: 10px 8px; font-size: 0.88rem; }
}
@media (max-width: 620px) {
  .monitor-live-view { padding: 22px 18px; }
  .podium { padding: 18px 10px 14px; }
  .podium-stage { gap: 6px; min-height: 220px; }
  .podium-column { width: min(150px, 100%); border-radius: 14px 14px 0 0; font-size: 1.5rem; padding-top: 72px; padding-bottom: 8px; }
  .podium-avatar { width: 42px; height: 56px; border-radius: 8px; }
  .podium-name { font-size: 0.74rem; padding: 2px 6px; }
  .podium-rank { font-size: 1.05rem; }
  .podium-col-1 { height: 180px; }
  .podium-col-2 { height: 138px; }
  .podium-col-3 { height: 110px; }
  .snark-line { font-size: 0.94rem; }
  #screenResult .board { overflow-x: auto; }
  #screenResult .board table { min-width: 540px; }
  #screenResult .board th,
  #screenResult .board td { padding: 10px 8px; font-size: 0.88rem; }
}

/* ── Misc animations ────────────────────────────────────────── */
@keyframes pulseText {
  0%, 100% { opacity: 0.5; transform: scale(0.98); }
  50% { opacity: 1; transform: scale(1.02); }
}
@keyframes pop { 0% { transform: scale(0.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
