*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #111118;
  --bg2: #1a1a24;
  --surface: #1e1e2a;
  --border: rgba(255,255,255,0.08);
  --text: #eeeef2;
  --muted: #8b8b9a;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --accent: #ec4899;
  --x: #ef4444;
  --o: #06b6d4;
  --gold: #fbbf24;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.35);
  --header-h: 56px;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body.logged-in {
  padding-top: var(--header-h);
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 60% 40% at 10% 0%, rgba(99,102,241,0.08), transparent),
    radial-gradient(ellipse 50% 30% at 90% 100%, rgba(236,72,153,0.05), transparent);
}

#confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

/* ─── Global header ─── */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-h);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 1rem;
  background: rgba(17,17,24,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.app-header.hidden { display: none; }

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.brand-icon {
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.15em;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 0.9rem;
  font-weight: 700;
}

.brand-sub {
  font-size: 0.65rem;
  color: var(--muted);
  font-weight: 500;
}

.header-center {
  flex: 1;
  min-width: 0;
  text-align: center;
  overflow: hidden;
}

.header-leader {
  font-size: 0.75rem;
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.header-btn {
  position: relative;
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.header-btn:hover { background: var(--bg2); }

.badge-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: var(--danger);
  color: white;
  font-size: 0.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  max-width: 140px;
}

.header-avatar { font-size: 1.3rem; flex-shrink: 0; }

.header-user-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.header-nick {
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-stats {
  font-size: 0.65rem;
  color: var(--muted);
}

/* ─── Dropdown panels ─── */
.dropdown-panel {
  position: fixed;
  top: calc(var(--header-h) + 4px);
  right: 1rem;
  width: min(320px, calc(100vw - 2rem));
  max-height: min(420px, 70dvh);
  overflow-y: auto;
  z-index: 999;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
}

.friends-dropdown { right: 4rem; width: min(360px, calc(100vw - 2rem)); }

.friends-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.friends-tab {
  flex: 1;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.friends-tab.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.4);
  color: var(--text);
}

.friends-tab-panel.hidden { display: none; }

.users-hint {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.users-online-count {
  display: block;
  margin-bottom: 0.5rem;
}

.add-friend-search {
  flex: 1;
  position: relative;
  min-width: 0;
}

.add-friend-btn {
  width: auto;
  flex-shrink: 0;
  min-width: 2.5rem;
}

.friend-search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 10;
  max-height: 160px;
  overflow-y: auto;
}

.friend-search-results.hidden { display: none; }

.search-result-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
}

.search-result-item:last-child { border-bottom: none; }
.search-result-item span:nth-child(2) { flex: 1; min-width: 0; }
.search-tag { font-size: 0.68rem; color: var(--muted); }

.friend-badge {
  font-size: 0.62rem;
  color: var(--primary);
  font-weight: 500;
}

.user-actions {
  display: flex;
  gap: 0.25rem;
  align-items: center;
  flex-shrink: 0;
}

.user-pending {
  font-size: 0.65rem;
  color: var(--muted);
  white-space: nowrap;
}

.panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.panel-top h4 { font-size: 0.85rem; font-weight: 600; }

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.75rem;
  cursor: pointer;
  font-family: inherit;
}

.online-count { font-size: 0.7rem; color: var(--success); }

.notif-list, .friends-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.notif-item {
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.8rem;
}

.notif-item.unread { border-color: rgba(99,102,241,0.4); background: rgba(99,102,241,0.08); }
.notif-title { font-weight: 600; margin-bottom: 0.15rem; }
.notif-body { color: var(--muted); font-size: 0.75rem; }

.add-friend-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.add-friend-row input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.friend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.friend-info { flex: 1; min-width: 0; }
.friend-nick { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friend-meta { font-size: 0.7rem; color: var(--muted); }
.friend-avatar { font-size: 1.2rem; }
.friend-status { font-size: 0.6rem; }

.friend-request-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem;
  margin-bottom: 0.35rem;
  border-radius: var(--radius-sm);
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.2);
  font-size: 0.8rem;
}

.request-actions { display: flex; gap: 0.25rem; }
.section-label { font-size: 0.7rem; color: var(--muted); margin-bottom: 0.35rem; font-weight: 600; }

.invite-friends-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.invite-chip { font-size: 0.75rem !important; }

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
  min-height: calc(100dvh - var(--header-h));
}

.screen { display: none; }
.screen.active { display: block; }

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-inner {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.glass-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.glass-card-inner {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ─── LOGIN ─── */
#login-screen.active .login-layout {
  display: grid;
  grid-template-columns: 1fr 1.2fr 260px;
  gap: 1rem;
  align-items: start;
}

body:not(:has(.app-header:not(.hidden))) .app-shell {
  min-height: 100dvh;
}

.login-hero { padding: 1rem 0.5rem; }

.login-hero h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 700;
  margin-bottom: 0.5rem;
  line-height: 1.2;
}

.hero-desc {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.hero-features {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.hero-features span {
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.hero-leader {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  background: rgba(251,191,36,0.08);
  border: 1px solid rgba(251,191,36,0.2);
  font-size: 0.85rem;
}

.leader-badge strong { color: var(--gold); }

.login-panel { padding: 1.25rem; }
.sidebar-panel { padding: 1rem; }

.auth-tabs, .lobby-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  background: var(--bg2);
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.auth-tab, .lobby-tab {
  flex: 1;
  padding: 0.55rem 0.4rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.auth-tab.active, .lobby-tab.active {
  background: var(--primary);
  color: white;
}

.auth-form { display: none; }
.auth-form.active { display: block; }

.input-group { margin-bottom: 0.75rem; }

.input-group label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.input-group input, .select-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.input-group input:focus, .select-input:focus {
  border-color: var(--primary);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.85rem;
  cursor: pointer;
}

.customize-section { margin-bottom: 0.75rem; }
.customize-section > label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.customize-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.avatar-picker { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.avatar-option {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 8px;
  border: 2px solid transparent;
  background: var(--bg2);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-option.selected {
  border-color: var(--primary);
  background: rgba(99,102,241,0.15);
}

.color-picker { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.color-option {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-option.selected { border-color: white; }

.btn {
  padding: 0.65rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-gradient {
  width: 100%;
  background: var(--primary);
  color: white;
}

.btn-ghost {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: var(--surface); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.78rem; }
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.7rem; width: auto; }

.lobby-panel { display: none; }
.lobby-panel.active { display: block; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.panel-header h3 { font-size: 0.9rem; font-weight: 600; }

.leaderboard-list { display: flex; flex-direction: column; gap: 0.35rem; }

.lb-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.lb-item.top {
  border-color: rgba(251,191,36,0.3);
  background: rgba(251,191,36,0.06);
}

.lb-rank { width: 1.2rem; color: var(--muted); font-weight: 600; font-size: 0.7rem; }
.lb-avatar { font-size: 1.1rem; }
.lb-nick { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-pts { color: var(--gold); font-weight: 700; font-size: 0.8rem; }

.crown { display: inline-flex; font-size: 0.8rem; }

.rooms-list {
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 0.65rem;
}

.room-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border);
  margin-bottom: 0.4rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.room-item:hover { border-color: var(--primary); }

.room-avatars { display: flex; font-size: 1.1rem; flex-shrink: 0; }
.room-info { flex: 1; min-width: 0; }
.room-name { font-weight: 600; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-meta { font-size: 0.72rem; color: var(--muted); }
.room-code {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--primary);
  flex-shrink: 0;
}

.empty-msg {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 1.25rem;
}

.hint { color: var(--muted); font-size: 0.78rem; margin-top: 0.5rem; }

/* ─── WAITING ─── */
.waiting-layout {
  max-width: 460px;
  margin: 1.5rem auto;
  padding: 1.5rem;
  text-align: center;
}

.waiting-header h2 { font-size: 1.25rem; margin: 0.4rem 0 0.75rem; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
}

.badge-wait {
  background: rgba(251,191,36,0.12);
  color: var(--gold);
  border: 1px solid rgba(251,191,36,0.25);
}

.code-box {
  padding: 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border);
}

.code-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; display: block; margin-bottom: 0.35rem; }

.code-box strong {
  font-size: 1.75rem;
  letter-spacing: 0.25em;
  font-weight: 800;
  color: var(--primary);
  display: block;
  margin-bottom: 0.75rem;
}

.code-actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }

.invite-friends-section {
  text-align: left;
  margin-bottom: 1rem;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border);
}

.invite-friends-section label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
}

.waiting-text { font-weight: 600; font-size: 0.9rem; margin-bottom: 0.2rem; }
.waiting-chat { margin: 1rem 0; padding: 0.75rem; text-align: left; }

/* ─── GAME ─── */
.game-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex-wrap: wrap;
}

.game-top-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}

.room-tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: var(--bg2);
  border: 1px solid var(--border);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.turn-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: rgba(99,102,241,0.12);
  border: 1px solid rgba(99,102,241,0.25);
  color: #a5b4fc;
}

.turn-pill.my-turn {
  background: rgba(34,197,94,0.12);
  border-color: rgba(34,197,94,0.3);
  color: var(--success);
}

.turn-timer {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  background: rgba(6,182,212,0.1);
  border: 1px solid rgba(6,182,212,0.25);
  color: var(--o);
  font-variant-numeric: tabular-nums;
}

.turn-timer.hidden { display: none; }
.turn-timer.urgent {
  background: rgba(239,68,68,0.12);
  border-color: rgba(239,68,68,0.3);
  color: var(--danger);
}

.opponent-status {
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.2);
  color: var(--success);
}

.opponent-status.offline {
  background: rgba(239,68,68,0.1);
  border-color: rgba(239,68,68,0.2);
  color: var(--danger);
}

.hidden { display: none !important; }

.game-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1rem;
  align-items: start;
}

.game-main { position: relative; }

.players-duel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  flex: 1;
  min-width: 130px;
  max-width: 180px;
  transition: border-color 0.2s;
}

.player-card.active { border-color: var(--primary); }
.player-card.x.active { border-color: rgba(239,68,68,0.4); }
.player-card.o.active { border-color: rgba(6,182,212,0.4); }

.player-avatar-wrap { position: relative; flex-shrink: 0; }
.player-avatar { font-size: 1.75rem; display: block; }

.player-symbol {
  position: absolute;
  bottom: -3px;
  right: -5px;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  font-size: 0.6rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-card.x .player-symbol { background: var(--x); color: white; }
.player-card.o .player-symbol { background: var(--o); color: white; }

.player-name {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 90px;
}

.player-role { font-size: 0.68rem; color: var(--muted); }

.duel-divider span {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  background: var(--bg2);
}

.board-wrapper {
  position: relative;
  width: min(360px, 92vw);
  margin: 0 auto 1rem;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  aspect-ratio: 1;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  cursor: pointer;
  transition: background 0.15s;
}

.cell:hover:not(:disabled) { background: rgba(99,102,241,0.1); }
.cell:disabled { cursor: default; }

.cell span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: clamp(2rem, 9vw, 3rem);
  font-weight: 800;
}

.cell.x span { color: var(--x); }
.cell.o span { color: var(--o); }

.cell.winning { background: rgba(99,102,241,0.15) !important; }

.win-line {
  position: absolute;
  height: 4px;
  background: var(--primary);
  border-radius: 999px;
  transform-origin: left center;
  z-index: 10;
  pointer-events: none;
}

.win-line.hidden { display: none; }

.stats-row {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
}

.stats-row strong { color: var(--text); }

.winner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  border-radius: var(--radius);
  z-index: 20;
}

.winner-overlay.hidden { display: none; }

.winner-card {
  text-align: center;
  padding: 1.5rem;
  max-width: 320px;
  width: 90%;
}

.winner-crown { font-size: 2rem; }
.winner-crown.hidden { display: none; }
.winner-emoji { font-size: 3rem; margin: 0.5rem 0; }

.winner-card h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.result-sub { color: var(--muted); margin-bottom: 1rem; font-size: 0.85rem; }
.winner-actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.winner-actions .btn { width: auto; min-width: 130px; }

.chat-panel {
  display: flex;
  flex-direction: column;
  height: min(480px, 65dvh);
  padding: 0.85rem;
  overflow: hidden;
}

.chat-room-code {
  font-size: 0.68rem;
  font-family: ui-monospace, monospace;
  color: var(--muted);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.4rem 0;
  min-height: 100px;
}

.chat-msg {
  display: flex;
  gap: 0.4rem;
  align-items: flex-start;
  font-size: 0.82rem;
}

.chat-msg-avatar { font-size: 1.2rem; flex-shrink: 0; }
.chat-msg-body { flex: 1; min-width: 0; }
.chat-msg-nick { font-size: 0.68rem; font-weight: 600; margin-bottom: 0.1rem; opacity: 0.85; }

.chat-msg-text {
  font-size: 0.82rem;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  background: var(--bg2);
  word-break: break-word;
  line-height: 1.35;
}

.chat-msg.mine { flex-direction: row-reverse; }
.chat-msg.mine .chat-msg-body { text-align: right; }
.chat-msg.font-serif .chat-msg-text { font-family: Georgia, serif; }
.chat-msg.font-mono .chat-msg-text { font-family: ui-monospace, monospace; }
.chat-msg.font-rounded .chat-msg-text { font-family: 'Comic Sans MS', cursive; }

.chat-input-bar {
  display: flex;
  gap: 0.35rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.chat-input-bar input {
  flex: 1;
  min-width: 0;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  min-height: 2.5rem;
}

.chat-input-bar input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.chat-input-bar .btn-primary {
  width: auto;
  flex-shrink: 0;
  min-width: 2.75rem;
  padding: 0.55rem 0.9rem;
}

.emoji-toggle {
  width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg2);
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.emoji-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  padding: 0.5rem;
  margin-bottom: 0.4rem;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  max-height: 120px;
  overflow-y: auto;
}

.emoji-panel.hidden { display: none; }

.emoji-panel button {
  width: 1.85rem;
  height: 1.85rem;
  border: none;
  border-radius: 4px;
  background: transparent;
  font-size: 1rem;
  cursor: pointer;
}

.emoji-panel button:hover { background: rgba(255,255,255,0.08); }

.history-panel {
  margin-top: 1rem;
  padding: 1rem;
}

.history-panel h3 { font-size: 0.88rem; margin-bottom: 0.65rem; font-weight: 600; }

.history-list {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
}

.history-item {
  flex-shrink: 0;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  min-width: 110px;
}

.history-item .opp { display: block; color: var(--muted); font-size: 0.68rem; }
.history-item .result-win { color: var(--success); font-weight: 600; }
.history-item .result-loss { color: var(--danger); font-weight: 600; }
.history-item .result-draw { color: var(--gold); font-weight: 600; }

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  z-index: 10001;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 2rem);
  text-align: center;
}

.toast.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(12px);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}

.confetti-piece {
  position: absolute;
  width: 8px;
  height: 8px;
  top: -10px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ─── RESPONSIVE ─── */
@media (max-width: 960px) {
  #login-screen.active .login-layout { grid-template-columns: 1fr; }
  .login-hero { text-align: center; }
  .hero-features { justify-content: center; }
  .hero-leader { max-width: 400px; margin: 0 auto; }
  .game-grid { grid-template-columns: 1fr; }
  .chat-panel { height: 300px; }
  .header-leader { display: none; }
  .header-user { max-width: 100px; }
  .friends-dropdown { right: 1rem; }
}

@media (max-width: 480px) {
  body { padding-top: 52px; --header-h: 52px; }
  .app-shell { padding: 0.65rem; }
  .customize-row { grid-template-columns: 1fr; }
  .duel-divider { display: none; }
  .players-duel { flex-direction: column; }
  .player-card { max-width: 100%; width: 100%; }
  .header-user-info { display: none; }
  .brand-sub { display: none; }
}
