:root {
  color-scheme: dark;
  --bg: #050816;
  --panel: rgba(15, 23, 42, 0.86);
  --panel-strong: rgba(29, 41, 69, 0.95);
  --text: #f8fbff;
  --muted: #97a8c9;
  --accent: #5ee7ff;
  --accent-2: #b96cff;
  --success: #31d6a6;
  --warning: #ffb84d;
  --danger: #ff5d7a;
  --border: rgba(255, 255, 255, 0.12);
}

body.theme-dark {
  --bg: #05070f;
  --panel: rgba(16, 18, 31, 0.9);
  --panel-strong: rgba(20, 24, 42, 0.96);
  --accent: #6fa8ff;
  --accent-2: #5f7cff;
}

body.theme-neon {
  --bg: #050816;
  --panel: rgba(15, 23, 42, 0.86);
  --panel-strong: rgba(29, 41, 69, 0.95);
  --accent: #5ee7ff;
  --accent-2: #b96cff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Tajawal', system-ui, sans-serif;
  background: radial-gradient(circle at top, rgba(94, 231, 255, 0.15), transparent 35%), var(--bg);
  color: var(--text);
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 100%;
  padding: 20px;
  position: relative;
  overflow-x: clip;
  overflow-y: visible;
}
.ambient { position: absolute; inset: auto; width: 320px; height: 320px; filter: blur(60px); opacity: 0.2; border-radius: 50%; pointer-events: none; }
.ambient-one { background: var(--accent); top: -60px; right: -80px; }
.ambient-two { background: var(--accent-2); bottom: -50px; left: -60px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 24px; position: relative; z-index: 2; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 16px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 10px 30px rgba(94, 231, 255, 0.24); font-size: 24px; }
.brand h1 { margin: 0; font-size: 1.25rem; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 0.95rem; }
.topbar-actions { display: flex; gap: 10px; }
.pill-btn { border: 1px solid var(--border); background: rgba(255,255,255,0.06); color: var(--text); padding: 10px 14px; border-radius: 999px; backdrop-filter: blur(12px); }
.pill-btn, .btn, .emoji-btn { touch-action: manipulation; }

.audio-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 20, 0.6);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 16px;
}

.audio-modal {
  width: min(92vw, 460px);
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.45);
  padding: 18px;
  display: grid;
  gap: 12px;
}

.audio-modal h3 {
  margin: 0;
}

main { position: relative; z-index: 2; }
.panel { background: var(--panel); border: 1px solid var(--border); backdrop-filter: blur(18px); box-shadow: 0 20px 60px rgba(5, 8, 22, 0.4); border-radius: 24px; padding: 24px; margin-bottom: 20px; }
.grid { display: grid; gap: 20px; }
.grid > * { min-width: 0; }
.grid.two { grid-template-columns: 1.1fr 0.9fr; }
.card-list { display: grid; gap: 12px; }
.hero { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 24px; align-items: center; }
.hero h2 { font-size: 2rem; margin: 0 0 10px; }
.hero p { color: var(--muted); line-height: 1.7; margin: 0 0 18px; }
.hero .stats { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.stat-chip { background: rgba(255,255,255,0.06); border: 1px solid var(--border); padding: 8px 12px; border-radius: 999px; color: var(--muted); font-size: 0.95rem; }
.form-stack { display: grid; gap: 12px; }
.field input, .field textarea { width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border); background: rgba(255,255,255,0.05); color: var(--text); outline: none; }
.field select { width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border); background: rgba(255,255,255,0.05); color: var(--text); outline: none; }
.field select,
.field select option {
  font-family: 'Tajawal', system-ui, sans-serif;
  font-size: 1.08rem;
  font-weight: 600;
}
.field select option {
  background: #162039;
  color: #e9f2ff;
}
.field input::placeholder, .field textarea::placeholder { color: #7687a8; }
.btn { border: none; border-radius: 14px; padding: 12px 16px; color: white; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 10px 24px rgba(94, 231, 255, 0.2); transition: transform 160ms ease, opacity 160ms ease; }
.btn.secondary { background: rgba(255,255,255,0.07); border: 1px solid var(--border); color: var(--text); box-shadow: none; }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-3d { transform: translateY(-3px); box-shadow: 0 7px 0 rgba(7, 10, 20, 0.28), 0 13px 24px rgba(5, 8, 22, 0.28); transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease; }
.btn-3d:hover { transform: translateY(-5px); }
.btn-3d:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(7, 10, 20, 0.28), 0 6px 14px rgba(5, 8, 22, 0.2); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: white; border: 2px solid rgba(255,255,255,0.16); }
.avatar.avatar-image { overflow: hidden; }
.avatar.avatar-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.player-card, .chat-item, .leader-card, .rule-card { background: rgba(255,255,255,0.05); border: 1px solid var(--border); padding: 12px 14px; border-radius: 16px; }
.player-card { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.badge { display: inline-block; border-radius: 999px; padding: 4px 10px; font-size: 0.78rem; color: white; background: rgba(94,231,255,0.18); border: 1px solid rgba(94,231,255,0.25); }
.badge.host { background: rgba(185,108,255,0.2); border-color: rgba(185,108,255,0.35); }
.badge.ready { background: rgba(49,214,166,0.2); border-color: rgba(49,214,166,0.3); }
.badge.turn { background: rgba(255,184,77,0.2); border-color: rgba(255,184,77,0.3); }
.card-surface { min-height: 280px; border-radius: 24px; background: linear-gradient(135deg, rgba(94,231,255,0.15), rgba(185,108,255,0.25)); border: 1px solid rgba(255,255,255,0.18); padding: 20px; display: grid; align-content: space-between; position: relative; overflow: hidden; }
.card-surface::after { content: ''; position: absolute; inset: 0; background: radial-gradient(circle at top, rgba(255,255,255,.18), transparent 40%); pointer-events: none; }
.card-wheel { width: 144px; height: 144px; border-radius: 50%; border: 10px solid rgba(255,255,255,0.16); margin: 0 auto; background: conic-gradient(from 180deg, var(--accent), var(--accent-2), #ffef7d, var(--accent)); transition: transform 4s cubic-bezier(0.2,0.85,0.2,1); position: relative; }
.card-wheel::before { content: '▶'; position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 32px; color: white; }
.chat-box { display: grid; gap: 10px; max-height: 260px; overflow: auto; padding-inline-end: 6px; }
.chat-input { display: flex; gap: 8px; margin-top: 10px; }
.chat-input input { flex: 1; }
.emoji-row { display: flex; flex-wrap: wrap; gap: 8px; }
.emoji-btn { padding: 8px 10px; border: 1px solid var(--border); background: rgba(255,255,255,0.05); border-radius: 999px; color: var(--text); }
.mobile-quick-panel { display: none; }
.mobile-room-actions { margin-top: 10px; }
.mobile-room-actions .btn { flex: 1 1 140px; }
.confetti-piece { position: fixed; width: 10px; height: 20px; top: -20px; border-radius: 999px; animation: confetti 2.5s ease-out forwards; }
@keyframes confetti { 0% { transform: translate3d(0,0,0) rotate(0deg); opacity: 1; } 100% { transform: translate3d(var(--drift), 110vh, 0) rotate(720deg); opacity: 0; } }
.hidden { display: none !important; }
.panel-inset { background: rgba(255,255,255,0.035); }
.full-span { grid-column: 1 / -1; }
.split-row { justify-content: space-between; align-items: center; }
.status-banner { margin: 14px 0 18px; padding: 12px 14px; border-radius: 16px; border: 1px solid var(--border); }
.status-good { background: rgba(49,214,166,0.12); color: #b8ffe8; }
.status-warn { background: rgba(255,184,77,0.12); color: #ffe0a6; }
.settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; }
.game-layout { grid-template-columns: 1.2fr 0.8fr; align-items: start; }
.game-layout > * { min-width: 0; }
.game-main { position: relative; overflow: hidden; }
.emoji-popups {
  position: fixed;
  inset: 0;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 8px;
  pointer-events: none;
  z-index: 20;
}
.emoji-popup {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 16px 22px;
  max-width: min(90vw, 560px);
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(4, 8, 24, 0.76);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  animation: emojiPopFade 3s ease-out forwards;
}
.emoji-popup-icon { font-size: 4.2rem; line-height: 1; }
.emoji-popup-name { font-size: 1.5rem; color: var(--text); font-weight: 700; }
.round-card { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: center; background: linear-gradient(135deg, rgba(94,231,255,0.12), rgba(185,108,255,0.14)); border: 1px solid rgba(255,255,255,0.12); border-radius: 22px; padding: 20px; margin: 18px 0; }
.category-line { display: flex; gap: 16px; align-items: center; }
.category-emoji { font-size: 2rem; filter: drop-shadow(0 0 18px rgba(94,231,255,0.45)); }
.timer-shell { display: grid; gap: 10px; justify-items: center; }
.timer-circle { --timer-progress: 100%; width: 128px; height: 128px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--accent) var(--timer-progress), rgba(255,255,255,0.08) 0); padding: 10px; box-shadow: 0 0 0 1px rgba(255,255,255,0.1), 0 0 35px rgba(94,231,255,0.18); }
.timer-circle::before { content: ''; width: 100%; height: 100%; border-radius: 50%; background: rgba(5, 8, 22, 0.92); border: 1px solid rgba(255,255,255,0.08); grid-area: 1 / 1; }
.timer-value { grid-area: 1 / 1; position: relative; z-index: 1; font-size: 2rem; font-weight: 800; }
.answer-panel { display: grid; gap: 14px; }
.category-popup { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 8, 22, 0.35); backdrop-filter: blur(12px); z-index: 4; animation: popupFadeIn 260ms ease-out both; pointer-events: none; }
.category-popup.is-static { animation: none; }
.category-popup-card { min-width: min(90vw, 360px); border-radius: 24px; border: 1px solid rgba(255,255,255,0.16); background: rgba(255,255,255,0.08); padding: 28px 24px; text-align: center; box-shadow: 0 0 40px rgba(94,231,255,0.22), 0 0 70px rgba(185,108,255,0.18); animation: popupScaleIn 320ms ease-out both; }
.category-popup.is-static .category-popup-card { animation: none; }
.popup-title { color: var(--muted); margin-bottom: 12px; letter-spacing: 0.04em; }
.popup-category { font-size: clamp(1.4rem, 4vw, 2.2rem); font-weight: 800; }
.letter-popup-card { min-width: min(92vw, 420px); }
.letter-strip { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 14px; }
.letter-tick { opacity: 0; transform: translateY(8px); animation: tickPop 0.45s ease forwards; animation-delay: var(--d); color: var(--muted); }
.category-popup.is-static .letter-tick { animation: none; opacity: 1; transform: translateY(0) scale(1); }
.selected-letter-glow { font-size: clamp(2.2rem, 8vw, 4.4rem); font-weight: 900; text-shadow: 0 0 16px rgba(94,231,255,0.6), 0 0 34px rgba(185,108,255,0.45); }
.leaderboard-list { max-height: 70vh; overflow: auto; }
.leader-highlight { box-shadow: 0 0 0 1px rgba(94,231,255,0.2), 0 0 22px rgba(94,231,255,0.18); }
.score-flash { animation: scoreFlash 900ms ease; }
.result-row { border-radius: 16px; border: 1px solid var(--border); padding: 12px 14px; background: rgba(255,255,255,0.04); }
.result-valid { border-color: rgba(49,214,166,0.35); }
.result-invalid { border-color: rgba(255,93,122,0.25); }
.result-meta { display: grid; justify-items: end; gap: 4px; }
.winner-panel { margin-top: 18px; padding: 20px; border-radius: 24px; text-align: center; background: linear-gradient(180deg, rgba(185,108,255,0.18), rgba(94,231,255,0.12)); border: 1px solid rgba(255,255,255,0.12); }
.winner-panel .avatar { margin: 12px auto; width: 72px; height: 72px; font-size: 1.5rem; }
.trophy { font-size: 2.5rem; text-shadow: 0 0 24px rgba(255, 215, 0, 0.45); }
.winner-score { font-size: 1.3rem; font-weight: 700; color: #ffe7a8; }
.postgame-settings-panel { margin-top: 16px; }
.postgame-settings-panel .muted { margin-top: 0; margin-bottom: 10px; }
.room-exit-zone {
  margin-top: 28px;
  display: grid;
  gap: 10px;
  justify-items: center;
  border: 1px dashed rgba(255, 93, 122, 0.45);
  background: rgba(255, 93, 122, 0.08);
  padding: 14px;
}
.room-exit-zone .btn {
  min-width: min(360px, 100%);
}

@media (max-width: 900px) {
  .room-exit-zone {
    margin-top: 34px;
    margin-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}
.final-table-panel { margin-top: 16px; }
.final-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border-radius: 14px;
  border: 1px solid var(--border);
}
.final-table { width: 100%; border-collapse: collapse; min-width: 640px; background: rgba(255,255,255,0.03); }
.final-table th,
.final-table td { padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,0.08); vertical-align: top; text-align: start; }
.final-table thead th { background: rgba(255,255,255,0.05); position: sticky; top: 0; z-index: 1; }
.final-answer-word { font-weight: 700; margin-bottom: 4px; }
.final-answer-meta { display: flex; gap: 6px; align-items: center; font-size: 0.9rem; }
@keyframes popupScaleIn { 0% { transform: scale(0.92); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes popupFadeIn { 0% { opacity: 0; } 100% { opacity: 1; } }
@keyframes scoreFlash { 0% { transform: translateY(0); } 50% { transform: translateY(-3px); box-shadow: 0 0 28px rgba(94,231,255,0.22); } 100% { transform: translateY(0); } }
@keyframes tickPop { from { opacity: 0; transform: translateY(8px) scale(0.9); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes emojiPopFade {
  0% { opacity: 0; transform: translateY(8px) scale(0.96); }
  12% { opacity: 1; transform: translateY(0) scale(1); }
  82% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-4px) scale(0.98); }
}

@media (max-width: 640px) {
  .emoji-popup-icon { font-size: 3.4rem; }
  .emoji-popup-name { font-size: 1.2rem; }
}
@media (max-width: 900px) { .hero, .grid.two { grid-template-columns: 1fr; } .topbar { flex-direction: column; align-items: flex-start; } }
@media (max-width: 900px) { .game-layout, .settings-grid { grid-template-columns: 1fr; } .round-card { grid-template-columns: 1fr; justify-items: center; text-align: center; } }
@media (max-width: 900px) {
  .app-shell {
    overflow: visible;
  }

  .ambient {
    display: none;
  }

  .panel {
    backdrop-filter: none;
    box-shadow: 0 10px 24px rgba(5, 8, 22, 0.3);
  }

  .pill-btn {
    backdrop-filter: none;
  }

  .game-main {
    overflow: visible;
  }

  .mobile-quick-panel {
    display: grid;
    gap: 12px;
    margin-bottom: 16px;
  }

  .emoji-chat-panel {
    display: none;
  }

  .emoji-row {
    gap: 6px;
  }

  .emoji-btn {
    padding: 9px 11px;
    min-height: 40px;
  }

  .chat-box {
    max-height: 160px;
  }
}

/* Auth layout */
.auth-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; max-width: 860px; margin: 0 auto; }
.auth-card { display: grid; gap: 18px; }
.auth-brand { text-align: center; }
.auth-brand h2 { margin: 8px 0 0; font-size: 1.5rem; }
.brand-mark-lg { width: 64px; height: 64px; font-size: 32px; margin: 0 auto; border-radius: 20px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 0 30px rgba(94,231,255,0.3); }
.auth-tabs { display: flex; gap: 10px; }
.auth-info { height: fit-content; }
.rule-icon { font-size: 1.1rem; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 0.85rem; cursor: pointer; padding: 0; text-decoration: underline; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 14px; font-size: 0.95rem; }
.alert-success { background: rgba(49,214,166,0.15); border: 1px solid rgba(49,214,166,0.35); color: #b8ffe8; }
.alert-error { background: rgba(255,93,122,0.12); border: 1px solid rgba(255,93,122,0.3); color: #ffa5b5; }

/* Home layout */
.home-layout { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 24px; align-items: start; }
.home-hero { display: grid; gap: 20px; }
.home-user-bar { display: flex; gap: 14px; align-items: center; background: rgba(255,255,255,0.04); border-radius: 20px; padding: 14px 18px; border: 1px solid var(--border); }
.home-user-bar .pill-btn { margin-inline-start: auto; }
.home-username { font-size: 1.1rem; font-weight: 700; }
.home-actions { gap: 14px; }
.btn-large { padding: 14px 24px; font-size: 1rem; border-radius: 18px; }
.btn-sm { padding: 8px 14px; font-size: 0.88rem; }
.scoring-table { display: grid; gap: 10px; }
.score-row { display: flex; justify-content: space-between; align-items: center; background: rgba(255,255,255,0.04); padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border); }
.home-rules { height: fit-content; }

/* Profile */
.profile-layout { max-width: 540px; margin: 0 auto; }
.avatar-lg { width: 72px; height: 72px; font-size: 1.6rem; border-radius: 50%; border: 3px solid rgba(255,255,255,0.2); }
.profile-avatar-section { display: flex; gap: 18px; align-items: flex-start; padding: 16px; border-radius: 16px; background: rgba(255,255,255,0.04); border: 1px solid var(--border); }
.profile-image-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.color-swatches { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.color-swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; transition: transform 140ms; }
.color-swatch:hover { transform: scale(1.18); }
.swatch-active { border-color: white; box-shadow: 0 0 0 2px rgba(255,255,255,0.5); }
.color-picker { width: 40px; height: 28px; border-radius: 8px; border: 1px solid var(--border); background: transparent; cursor: pointer; padding: 2px; }
.field-static { padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border); background: rgba(255,255,255,0.03); color: var(--muted); }
.divider { border: none; border-top: 1px solid var(--border); margin: 22px 0; }
.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
}
.checkbox-field input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}
@media (max-width: 1100px) {
  .grid.two,
  .game-layout,
  .home-layout,
  .auth-layout {
    grid-template-columns: 1fr;
  }

  .game-main {
    order: 1 !important;
  }

  .scoreboard-panel {
    order: 2 !important;
  }
}

@media (max-width: 900px) {
  .app-shell {
    padding: 14px;
  }

  .panel {
    border-radius: 18px;
    padding: 16px;
    margin-bottom: 14px;
  }

  .topbar {
    margin-bottom: 14px;
    flex-wrap: wrap;
  }

  .brand h1 {
    font-size: 1.08rem;
  }

  .brand p {
    font-size: 0.82rem;
  }

  .settings-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .row {
    gap: 8px;
  }

  .btn,
  .pill-btn,
  .btn-large {
    min-height: 44px;
  }

  .round-card {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 12px;
    padding: 14px;
    margin: 12px 0;
  }

  .timer-circle {
    width: 104px;
    height: 104px;
  }

  .timer-value {
    font-size: 1.55rem;
  }

  .leaderboard-list {
    max-height: 40vh;
  }

  .postgame-settings-grid {
    grid-template-columns: 1fr;
  }

  .game-main {
    order: 1 !important;
  }

  .scoreboard-panel {
    order: 2 !important;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .ambient {
    width: 220px;
    height: 220px;
    filter: blur(46px);
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 20px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .home-actions,
  .auth-tabs,
  .row {
    width: 100%;
  }

  .home-actions .btn,
  .auth-tabs .btn {
    flex: 1;
  }

  .home-user-bar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .home-user-bar .pill-btn {
    margin-inline-start: 0;
    width: 100%;
  }

  .profile-image-actions .btn {
    flex: 1 1 140px;
  }

  .home-username,
  .home-user-bar .muted {
    overflow-wrap: anywhere;
  }

  .home-actions .btn-large {
    font-size: 0.95rem;
    padding-inline: 12px;
    white-space: normal;
    text-wrap: balance;
  }

  .player-card,
  .leader-card,
  .result-row {
    padding: 10px 11px;
    border-radius: 12px;
  }

  .field input,
  .field select,
  .field textarea {
    font-size: 16px;
    padding: 11px 12px;
  }

  .category-popup-card {
    min-width: min(94vw, 340px);
    padding: 18px 14px;
    border-radius: 16px;
  }

  .selected-letter-glow {
    font-size: clamp(1.9rem, 11vw, 3rem);
  }

  .winner-panel {
    padding: 14px;
    border-radius: 16px;
  }

  .audio-modal-backdrop {
    align-items: end;
    justify-items: stretch;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    backdrop-filter: blur(2px);
  }

  .audio-modal {
    width: 100%;
    border-radius: 18px 18px 12px 12px;
    padding: 14px;
    max-height: min(72dvh, 520px);
    overflow-y: auto;
    box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.45);
    animation: audioSheetIn 220ms ease-out;
  }

  .audio-modal .btn,
  .audio-modal input,
  .audio-modal select {
    min-height: 44px;
  }
}

@keyframes audioSheetIn {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .app-shell {
    padding: 8px 10px;
    overflow: visible;
  }

  .ambient {
    display: none;
  }

  .topbar {
    margin-bottom: 8px;
    gap: 8px;
  }

  .brand p {
    display: none;
  }

  .panel {
    padding: 12px;
    border-radius: 14px;
    margin-bottom: 10px;
  }

  .grid.two,
  .game-layout {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .card-list {
    gap: 8px;
  }

  .btn,
  .pill-btn,
  .btn-large {
    min-height: 40px;
    padding: 9px 12px;
  }

  .round-card {
    padding: 10px;
    margin: 8px 0;
    grid-template-columns: 1fr auto;
    text-align: start;
  }

  .timer-circle {
    width: 84px;
    height: 84px;
  }

  .timer-value {
    font-size: 1.25rem;
  }

  .leaderboard-list {
    max-height: 46vh;
  }

  .field input,
  .field select,
  .field textarea {
    padding: 9px 10px;
  }

  .category-popup-card {
    min-width: min(80vw, 320px);
    padding: 12px;
  }
}

body.keyboard-open .ambient {
  display: none;
}

body.keyboard-open .topbar {
  margin-bottom: 8px;
}

body.keyboard-open .panel {
  margin-bottom: 10px;
}

body.keyboard-open .leaderboard-list {
  max-height: 34vh;
}

/* Mobile-first round layout: intentionally scoped to active gameplay. */
.mobile-scores-toggle { display: none; }
.game-header-actions { display: flex; align-items: center; gap: 8px; }
@media (max-width: 900px) {
  .game-layout { display: flex; flex-direction: column; gap: 10px; }
  .game-layout > .game-main { order: 0; width: 100%; }
  .game-layout > .scoreboard-panel { order: 1; width: 100%; display: none; }
  .game-layout.scores-open > .scoreboard-panel { display: block; }
  .mobile-scores-toggle { display: inline-flex; align-items: center; min-height: 44px; font-size: .83rem; padding: 8px 10px; }
  .game-main > .split-row { align-items: center; gap: 8px; }
  .game-main > .split-row h3 { margin: 0; font-size: 1.05rem; }
  .game-main > .split-row .muted { margin: 3px 0 0; font-size: .82rem; }
  .game-main > .split-row .badge.turn { display: none; }
  .game-main .round-card { grid-template-columns: minmax(0, 1fr) auto; text-align: start; justify-items: stretch; gap: 12px; margin: 12px 0; padding: 14px; }
  .game-main .timer-circle { width: 76px; height: 76px; padding: 7px; }
  .game-main .timer-value { font-size: 1.35rem; }
  .game-main .timer-shell .muted { font-size: .72rem; }
  .game-main .category-line { min-width: 0; overflow-wrap: anywhere; }
  .game-main .answer-panel { gap: 8px; }
  .game-main .answer-panel input { min-height: 52px; font-size: 16px; }
  .game-main .answer-panel #submitBtn { min-height: 52px; flex: 1; font-weight: 800; }
  .game-main .answer-panel > .row { display: flex; flex-direction: column; align-items: stretch; gap: 5px; }
  .game-main .answer-panel > .row .muted { text-align: center; font-size: .8rem; }
  .game-main .mobile-quick-panel { padding: 10px 12px; margin: 8px 0; }
  .game-main .mobile-quick-panel h4 { margin: 0; font-size: .9rem; }
  .game-main .mobile-quick-panel .emoji-row { display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 6px; scrollbar-width: none; }
  .game-main .mobile-quick-panel .emoji-btn { flex: 0 0 42px; min-width: 42px; min-height: 44px; }
  .game-main .emoji-chat-panel { display: none; }
  body.keyboard-open .game-main .mobile-quick-panel { display: none; }
  body.keyboard-open .game-main .round-card { padding: 8px 12px; margin: 6px 0; }
  body.keyboard-open .game-main .timer-circle { width: 58px; height: 58px; }
  body.keyboard-open .game-main .timer-value { font-size: 1rem; }
  body.keyboard-open .game-main > .split-row .muted { display: none; }
}
@media (max-width: 640px) {
  .app-shell { padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); }
  .topbar { flex-direction: row; align-items: center; gap: 8px; margin-bottom: 12px; }
  .topbar .brand { gap: 7px; min-width: 0; }
  .topbar .brand h1 { font-size: 1rem; }
  .topbar .brand p { font-size: .72rem; }
  .topbar-actions { width: auto; flex: 0 0 auto; gap: 5px; }
  .topbar-actions .pill-btn { min-height: 44px; padding: 8px 10px; }
  .game-main.panel { padding: 12px; border-radius: 18px; }
  .game-main .round-card .category-emoji { font-size: 1.5rem; }
  .game-main .round-card strong { font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .game-layout *, .game-layout *::before, .game-layout *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* Phase 2: round-by-round final results designed for phone screens. */
.final-results-heading { display:flex; align-items:center; gap:12px; margin-bottom:16px; }
.final-results-heading h4 { margin:0 0 3px; }
.results-heading-icon { display:grid; place-items:center; width:44px; height:44px; border-radius:14px; background:rgba(94,231,255,.11); font-size:1.35rem; }
.final-mobile-results { display:none; }
@media (max-width:900px) {
  .final-table-panel { padding:14px 12px; overflow:hidden; }
  .final-table-wrap { display:none; }
  .final-mobile-results { display:grid; gap:16px; }
  .answer-round-block { border:1px solid rgba(255,255,255,.10); border-radius:18px; background:rgba(255,255,255,.035); overflow:hidden; min-width:0; }
  .answer-round-heading { display:flex; align-items:center; flex-wrap:wrap; gap:6px 10px; padding:13px 12px; background:linear-gradient(105deg,rgba(94,231,255,.12),rgba(185,108,255,.09)); }
  .answer-round-heading strong { flex:1; min-width:75px; font-size:1rem; overflow-wrap:anywhere; }
  .round-index { color:#77e7fa; font-size:.82rem; font-weight:800; white-space:nowrap; }
  .round-counter { font-size:.72rem; opacity:.65; }
  .answer-round-players { display:grid; gap:8px; padding:10px; }
  .answer-result-card { display:grid; gap:10px; padding:12px; border-radius:14px; border:1px solid rgba(255,255,255,.1); background:rgba(9,17,37,.5); min-width:0; }
  .answer-result-card.result-valid { border-inline-start:3px solid #49d5aa; }
  .answer-result-card.result-invalid { border-inline-start:3px solid #f17e94; }
  .answer-result-top,.answer-result-bottom { display:flex; align-items:center; justify-content:space-between; gap:10px; min-width:0; }
  .answer-player { display:flex; align-items:center; gap:8px; min-width:0; }
  .answer-player .avatar { width:30px; height:30px; flex:0 0 30px; font-size:.8rem; }
  .answer-player strong { font-size:.9rem; overflow-wrap:anywhere; }
  .answer-points { font-size:.83rem; font-weight:800; white-space:nowrap; color:#c7cedb; }
  .answer-points.has-points { color:#f8d986; }
  .answer-result-word { font-size:1.2rem; font-weight:800; min-width:0; overflow-wrap:anywhere; }
  .answer-status { flex:0 0 auto; max-width:55%; text-align:center; border-radius:999px; padding:5px 9px; font-size:.72rem; line-height:1.35; }
  .answer-status.result-valid { background:rgba(49,214,166,.14); color:#85edca; border:1px solid rgba(49,214,166,.25); }
  .answer-status.result-invalid { background:rgba(255,93,122,.12); color:#ffadbd; border:1px solid rgba(255,93,122,.2); }
  .winner-panel { position:relative; overflow:hidden; padding:24px 14px; border:1px solid rgba(255,213,116,.4); background:radial-gradient(ellipse at 50% 0%,rgba(255,209,102,.18),transparent 60%),linear-gradient(150deg,#2b2449,#122c42); }
  .winner-panel .trophy { font-size:3rem; animation:autobis-trophy-arrive .65s cubic-bezier(.2,1.4,.5,1) both; }
  .winner-panel .avatar { width:76px; height:76px; box-shadow:0 0 0 5px rgba(94,231,255,.13); }
  .winner-panel h3 { font-size:1.15rem; overflow-wrap:anywhere; }
  .winner-panel .winner-score { color:#ffdf8d; font-size:1.6rem; font-weight:900; }
}
@keyframes autobis-trophy-arrive { from { opacity:0; transform:translateY(-15px) scale(.65) rotate(-12deg); } to { opacity:1; transform:none; } }
@media (prefers-reduced-motion:reduce) { .winner-panel .trophy { animation:none !important; } }

/* Phase 2 refinement: compact expandable round summaries for mobile. */
@media (max-width:900px) {
  .final-mobile-results { gap:7px; }
  .answer-round-compact { min-width:0; border:1px solid rgba(255,255,255,.12); border-radius:12px; overflow:hidden; background:rgba(255,255,255,.035); }
  .answer-round-summary { display:flex; align-items:center; gap:8px; min-height:51px; padding:10px 12px; cursor:pointer; list-style:none; background:linear-gradient(105deg,rgba(94,231,255,.09),rgba(185,108,255,.055)); }
  .answer-round-summary::-webkit-details-marker { display:none; }
  .answer-round-summary strong { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:.95rem; }
  .answer-round-summary .round-counter { font-size:.7rem; }
  .answer-chevron { font-size:1.25rem; opacity:.8; transition:transform .2s; }
  .answer-round-compact[open] .answer-chevron { transform:rotate(180deg); }
  .answer-compact-list { padding:4px 9px 9px; }
  .answer-compact-row { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1.2fr) 22px 35px; align-items:center; gap:7px; padding:10px 3px; border-bottom:1px solid rgba(255,255,255,.08); font-size:.83rem; }
  .answer-compact-row:last-child { border-bottom:0; }
  .answer-compact-name,.answer-compact-word { min-width:0; overflow-wrap:anywhere; }
  .answer-compact-name { font-weight:700; }
  .answer-compact-word { font-weight:600; }
  .answer-compact-status { text-align:center; font-size:1.05rem; font-weight:900; }
  .answer-compact-status.result-valid { color:#85edca; }
  .answer-compact-status.result-invalid { color:#ffadbd; }
  .answer-compact-score { text-align:end; color:#c7cedb; font-variant-numeric:tabular-nums; }
  .answer-compact-score.has-points { color:#f8d986; }
}
@media (prefers-reduced-motion:reduce) { .answer-chevron { transition:none; } }
