@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap');

:root {
  --bg: #f0f4f8;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-light: #dbeafe;
  --host: #2563eb;
  --host-bg: #eff6ff;
  --guest: #dc2626;
  --guest-bg: #fef2f2;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --ok: #10b981;
  --ok-bg: #ecfdf5;
  --warn-bg: #fffbeb;
  --warn-border: #fbbf24;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-full: 999px;
  --sh-sm: 0 1px 3px rgba(0,0,0,.06);
  --sh-md: 0 4px 12px rgba(0,0,0,.07);
  --sh-lg: 0 8px 24px rgba(0,0,0,.09);
  --tr: .2s ease;
  --room-topbar-height: 58px;
  --match-panels-height: clamp(280px, calc(100vh - 390px), 430px);
  --room-stage-scale: 1;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
.hidden { display: none !important; }

.main-content.is-online-page {
  min-height: calc(100vh - var(--navbar-height));
}
@supports (height: 100dvh) {
  .main-content.is-online-page {
    min-height: calc(100dvh - var(--navbar-height));
  }
}

.main-content.is-online-page > .container {
  padding-top: calc(var(--navbar-height) + var(--page-gap)) !important;
  padding-bottom: 4px !important;
}

.online-page {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  max-width: 1240px;
  margin: 0 auto;
  padding: 2px 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.online-page .fa,
.online-page .fas,
.online-page .fa-solid,
.online-page .fa-regular {
  font-family: "Font Awesome 6 Free" !important;
  font-weight: 900;
}
.online-page .fa-brands {
  font-family: "Font Awesome 6 Brands" !important;
}

.online-page .connection-pill {
  --conn-accent: #f59e0b;
  --conn-border: #fcd34d;
  --conn-bg: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 30px;
  padding: 0;
  border-radius: var(--r-full);
  background: var(--conn-bg);
  border: 1px solid var(--conn-border);
  margin-left: auto;
  flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.85);
  transition: background var(--tr), border-color var(--tr), box-shadow var(--tr), transform var(--tr);
}
.online-page .connection-pill:hover {
  transform: translateY(-1px);
}
.online-page .pill-indicator {
  position: relative;
  width: 14px;
  height: 14px;
  display: block;
}
.online-page .pill-core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--conn-accent);
  transform: translate(-50%, -50%);
}
.online-page .pill-wave {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--conn-accent);
  transform: translate(-50%, -50%) scale(0.7);
  opacity: 0;
}

.online-page .connection-pill.is-online {
  --conn-accent: #10b981;
  --conn-border: #6ee7b7;
  --conn-bg: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
}
.online-page .connection-pill.is-connecting {
  --conn-accent: #f59e0b;
  --conn-border: #fcd34d;
  --conn-bg: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
}
.online-page .connection-pill.is-offline {
  --conn-accent: #ef4444;
  --conn-border: #fca5a5;
  --conn-bg: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
}

.online-page .connection-pill.is-connecting .pill-wave {
  animation: connWave 1.5s ease-out infinite;
}
.online-page .connection-pill.is-connecting .pill-wave.wave-2 {
  animation-delay: 0.45s;
}

.online-page .connection-pill.is-online .pill-core {
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.45);
  animation: connOnlineBeat 1.8s ease-in-out infinite;
}
.online-page .connection-pill.is-online .pill-wave {
  display: none;
}

.online-page .connection-pill.is-offline .pill-wave {
  display: none;
}
.online-page .connection-pill.is-offline .pill-core {
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.35);
  animation: connOfflineBlink 1.6s ease-in-out infinite;
}

@keyframes connWave {
  0% {
    opacity: 0.75;
    transform: translate(-50%, -50%) scale(0.7);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2);
  }
}

@keyframes connOnlineBeat {
  0% {
    transform: translate(-50%, -50%) scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.45);
  }
  60% {
    transform: translate(-50%, -50%) scale(1);
    box-shadow: 0 0 0 8px rgba(16, 185, 129, 0);
  }
  100% {
    transform: translate(-50%, -50%) scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

@keyframes connOfflineBlink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.lobby-card {
  background: var(--card);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-md);
  overflow: hidden;
}
.lobby-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 24px;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 50%, #e0f2fe 100%);
  border-bottom: 1px solid var(--line);
}
.lobby-icon {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--brand);
  display: grid; place-items: center;
  font-size: 20px; color: #fbbf24;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(37,99,235,.3);
}
.lobby-heading h1,
.lobby-heading h2 { font-size: 18px; font-weight: 800; color: var(--ink); }
.lobby-heading p { font-size: 13px; color: var(--muted); margin-top: 2px; }
.lobby-actions { padding: 12px; display: grid; gap: 8px; }
.lobby-action-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--card);
  cursor: pointer;
  transition: var(--tr);
  text-align: left;
  width: 100%;
  font-family: inherit;
}
.lobby-action-btn:hover { border-color: var(--brand); background: #fafbff; transform: translateY(-1px); box-shadow: var(--sh-md); }
.action-icon { width: 40px; height: 40px; border-radius: var(--r-md); display: grid; place-items: center; font-size: 18px; flex-shrink: 0; }
.host-icon { background: var(--brand-light); color: var(--brand); }
.join-icon { background: var(--guest-bg); color: var(--guest); }
.action-text { flex: 1; min-width: 0; }
.action-text strong { display: block; font-size: 14px; font-weight: 700; color: var(--ink); }
.action-text span { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }
.action-arrow { color: #94a3b8; font-size: 12px; transition: var(--tr); }
.lobby-action-btn:hover .action-arrow { color: var(--brand); transform: translateX(2px); }

.online-page .modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 2200; padding: 16px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from{opacity:0} to{opacity:1} }
.online-page .modal-box {
  width: min(440px, 100%); max-height: 90svh;
  background: var(--card); border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  display: flex; flex-direction: column; overflow: hidden;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from{opacity:0;transform:translateY(20px) scale(.97)} to{opacity:1;transform:none} }
.online-page .modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.online-page .modal-header h2 { font-size: 16px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.online-page .modal-header h2 i { color: var(--brand); font-size: 16px; }
.online-page .modal-close {
  width: 32px; height: 32px; border: none; border-radius: 50%;
  background: #f1f5f9; color: var(--muted); font-size: 14px;
  cursor: pointer; display: grid; place-items: center; transition: var(--tr);
}
.online-page .modal-close:hover { background: #e2e8f0; color: var(--ink); }
.online-page .modal-body { padding: 14px 18px; display: grid; gap: 12px; overflow-y: auto; }
.online-page .modal-footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

.online-page .field { display: grid; gap: 5px; }
.online-page .field > span { font: 600 12px/1 inherit; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.online-page .field > span i { font-size: 11px; color: var(--brand); }
.online-page .field input, .online-page .field select {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: #f8fafc; font: 400 14px/1.4 inherit; color: var(--ink);
  transition: var(--tr); appearance: none;
}
.online-page .field input:focus, .online-page .field select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.1); background: #fff; }
.online-page .field input::placeholder { color: #94a3b8; }
.online-page .field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8.825L.175 3 1.05 2.125 6 7.075l4.95-4.95L11.825 3z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}
.online-page .time-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.online-page .time-buttons button {
  flex: 1; min-width: 70px; padding: 8px 8px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: #f8fafc; color: var(--muted);
  font: 700 12px/1 inherit; cursor: pointer; transition: var(--tr);
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.online-page .time-buttons button:hover { border-color: var(--brand); color: var(--brand); }
.online-page .time-buttons button.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.online-page .mode-buttons,
.online-page .difficulty-buttons-inline {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.online-page .mode-buttons button,
.online-page .difficulty-buttons-inline button {
  flex: 1;
  min-width: 110px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: #f8fafc;
  color: var(--muted);
  font: 700 12px/1.2 inherit;
  cursor: pointer;
  transition: var(--tr);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.online-page .mode-buttons button:hover,
.online-page .difficulty-buttons-inline button:hover {
  border-color: var(--brand);
  color: var(--brand);
}
.online-page .mode-buttons button.active,
.online-page .difficulty-buttons-inline button.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.online-page .operation-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
.online-page .operation-btn {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: #f8fafc;
  color: var(--muted);
  min-height: 44px;
  padding: 7px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  font: 700 12px/1.2 inherit;
  transition: var(--tr);
}
.online-page .operation-btn .op-symbol {
  font-size: 16px;
  line-height: 1;
}
.online-page .operation-btn .op-text {
  font-size: 11px;
  line-height: 1.2;
}
.online-page .operation-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}
.online-page .operation-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.online-page .field-hint {
  color: #94a3b8;
  font-size: 11px;
  font-weight: 500;
}

/* ── Game Modals (shared) ── */
.gm-modal { width: min(440px, 100%); }
.gm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 40%, #2563eb 100%);
  border-bottom: none;
}
.gm-header--join {
  background: linear-gradient(135deg, #1e3a5f 0%, #1e40af 40%, #2563eb 100%);
}
.gm-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.gm-header-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,.15);
  display: grid; place-items: center;
  font-size: 15px; color: #fff;
  flex-shrink: 0;
}
.gm-header h2 {
  font-size: 15px; font-weight: 700; color: #fff;
  margin: 0; line-height: 1.2;
}
.gm-header p {
  font-size: 11px; color: rgba(255,255,255,.6);
  margin: 1px 0 0; font-weight: 500;
}
.gm-header .modal-close {
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.7);
  border: none;
}
.gm-header .modal-close:hover {
  background: rgba(255,255,255,.22);
  color: #fff;
}
.gm-body {
  padding: 16px 18px !important;
  gap: 13px !important;
}
.gm-footer {
  padding: 12px 18px !important;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}
.gm-submit {
  padding: 9px 20px !important;
  font-size: 13px !important;
}

/* Mode selector row */
.gm-mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.gm-mode {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: #f8fafc;
  cursor: pointer;
  transition: all .2s ease;
  font-family: inherit;
  text-align: left;
}
.gm-mode i {
  font-size: 15px;
  color: var(--muted);
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}
.gm-mode strong {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
}
.gm-mode small {
  display: none;
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
}
.gm-mode:hover {
  border-color: #93c5fd;
  background: #f0f7ff;
}
.gm-mode.active {
  border-color: var(--brand);
  background: var(--brand-light);
  box-shadow: 0 0 0 1px var(--brand);
}
.gm-mode.active i { color: var(--brand); }
.gm-mode.active strong { color: var(--brand); }

/* Time selector row */
.gm-time-row {
  display: flex;
  gap: 6px;
}
.gm-time {
  flex: 1;
  padding: 9px 8px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: #f8fafc;
  color: var(--muted);
  font: 700 12px/1 inherit;
  cursor: pointer;
  transition: all .2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.gm-time i { font-size: 11px; }
.gm-time:hover {
  border-color: #93c5fd;
  color: var(--brand);
}
.gm-time.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 1px 4px rgba(37,99,235,.25);
}

/* Difficulty buttons */
.diff-btn {
  flex: 1;
  padding: 9px 10px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: #f8fafc;
  color: var(--muted);
  font: 700 12px/1.2 inherit;
  cursor: pointer;
  transition: all .2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.diff-btn i { font-size: 11px; }
.diff-btn:hover { border-color: var(--brand); color: var(--brand); }
.diff-btn.active { color: #fff; }
.diff-btn.active[data-level="easy"] { background: #10b981; border-color: #10b981; }
.diff-btn.active[data-level="medium"] { background: #f59e0b; border-color: #f59e0b; }
.diff-btn.active[data-level="hard"] { background: #ef4444; border-color: #ef4444; }

.online-page .btn-primary, .online-page .btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--r-md);
  font: 700 13px/1 inherit; cursor: pointer; transition: var(--tr); border: none; white-space: nowrap;
}
.online-page .btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; box-shadow: var(--sh-sm); }
.online-page .btn-primary:hover { transform: translateY(-1px); box-shadow: var(--sh-md); }
.online-page .btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.online-page .btn-secondary { background: #f1f5f9; color: var(--muted); border: 1px solid var(--line); }
.online-page .btn-secondary:hover { background: #e2e8f0; color: var(--ink); }

.online-page .alert-box { padding: 9px 12px; border-radius: var(--r-md); font: 600 12px/1.4 inherit; }
.online-page .alert-box.error { background: var(--danger-bg); border: 1px solid #fca5a5; color: #991b1b; }
.online-page .alert-box.success { background: var(--ok-bg); border: 1px solid #6ee7b7; color: #065f46; }
.online-page .auth-note {
  padding: 10px 12px; border-radius: var(--r-md);
  background: var(--warn-bg); border: 1px solid var(--warn-border);
  color: #92400e; font-size: 12px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.online-page .auth-note i { font-size: 14px; }
.online-page .auth-note a { color: var(--brand); font-weight: 700; text-decoration: none; margin-left: auto; }
.online-page .auth-note a:hover { text-decoration: underline; }

.room-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  position: relative;
}
.room-stage {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  transform: scale(var(--room-stage-scale));
  transform-origin: top center;
  will-change: transform;
  transition: transform .12s ease-out;
}

.room-topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--card); border-radius: var(--r-lg); box-shadow: var(--sh-sm);
  flex-wrap: wrap;
  min-height: var(--room-topbar-height);
}
.leave-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px;
  border: 1px solid #fca5a5; border-radius: var(--r-full);
  background: var(--danger-bg); color: var(--danger);
  font: 700 12px/1 inherit; cursor: pointer; transition: var(--tr);
}
.leave-btn:hover { background: #fee2e2; border-color: #f87171; }
.leave-btn i { font-size: 12px; }
.room-code-box {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 10px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: var(--r-full);
  font-size: 12px;
}
.room-code-label { font-weight: 600; color: var(--muted); }
.room-code-box strong { font-size: 15px; font-weight: 800; color: var(--brand); letter-spacing: 1.5px; font-family: 'Inter', monospace; }
.copy-btn {
  width: 26px; height: 26px; border: none; border-radius: 50%;
  background: var(--brand-light); color: var(--brand);
  font-size: 11px; cursor: pointer; display: grid; place-items: center; transition: var(--tr);
}
.copy-btn:hover { background: var(--brand); color: #fff; }
.copy-btn.copied { background: var(--ok); color: #fff; }
.copy-btn:disabled {
  cursor: not-allowed;
  opacity: .5;
  background: #e2e8f0;
  color: #94a3b8;
}
.copy-btn:disabled:hover {
  background: #e2e8f0;
  color: #94a3b8;
}
.online-page .field input.is-readonly {
  background: #eef2ff;
  color: #334155;
  border-color: #bfdbfe;
}
.qr-scan-tools {
  display: flex;
  justify-content: flex-start;
}
.join-scan-btn {
  width: 100%;
}
.qr-scan-panel {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: #f8fafc;
}
.qr-scan-frame {
  width: 100%;
  border-radius: var(--r-md);
  overflow: hidden;
  background: #0f172a;
  border: 1px solid #1e293b;
  min-height: 180px;
}
.qr-scan-frame video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}
.qr-scan-status {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}
.qr-scan-status.is-error {
  color: var(--danger);
}
.qr-scan-status.is-success {
  color: var(--ok);
}
.qr-scan-stop-btn {
  width: 100%;
}
.room-timer {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: var(--r-full);
  color: var(--brand); font-size: 12px; margin-left: auto;
}
.room-timer i { font-size: 12px; }
.room-timer strong { font-size: 15px; font-weight: 800; font-family: 'Inter', monospace; }
.room-status {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: var(--r-full);
  font: 700 11px/1 inherit; color: var(--muted);
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; }
.room-spectators {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--r-full);
  color: #1d4ed8;
  font: 700 11px/1 inherit;
}
.room-spectators i {
  font-size: 11px;
}

.qr-modal-box {
  width: min(460px, 100%);
}
.qr-modal-body {
  display: grid;
  gap: 12px;
}
.qr-canvas-wrap {
  width: 250px;
  max-width: 100%;
  margin: 0 auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: #fff;
}
.qr-canvas-wrap canvas {
  width: 100%;
  height: auto;
  display: block;
}
.qr-expire-text {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.invite-link-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.invite-link-row input {
  flex: 1;
}

/* ── Scoreboard ── */
.scoreboard {
  display: flex;
  align-items: stretch;
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
  border: 1px solid var(--line);
  overflow: hidden;
}
.scoreboard > .sb-side:first-child {
  border-top-left-radius: var(--r-lg);
  border-bottom-left-radius: var(--r-lg);
}
.scoreboard > .sb-side:last-child {
  border-top-right-radius: var(--r-lg);
  border-bottom-right-radius: var(--r-lg);
}

/* Player sides */
.sb-side {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}
.sb-host { background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%); }
.sb-guest { background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%); }
.team-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-size: 15px; flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
}
.host-avatar { background: var(--host); color: #fff; }
.guest-avatar { background: var(--guest); color: #fff; }
.sb-player-info { flex: 1; min-width: 0; }
.sb-role {
  display: block;
  font: 800 9px/1 inherit;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}
.sb-name {
  display: block;
  font-size: 14px; font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--ink);
}
.spectator-answer-pill {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font: 700 10px/1.3 inherit;
  border: 1px solid transparent;
  white-space: nowrap;
}
.spectator-answer-pill i {
  font-size: 10px;
}
.spectator-answer-pill.is-pending {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #475569;
}
.spectator-answer-pill.is-correct {
  background: #dcfce7;
  border-color: #22c55e;
  color: #166534;
}
.spectator-answer-pill.is-wrong {
  background: #fee2e2;
  border-color: #ef4444;
  color: #991b1b;
}
.conn-badge {
  padding: 3px 8px; border-radius: var(--r-full);
  font: 700 9px/1.4 inherit;
  background: #f1f5f9; color: #94a3b8;
  flex-shrink: 0;
}
.conn-badge.is-online { background: var(--ok-bg); color: #065f46; }

/* Center scores block */
.sb-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  flex-shrink: 0;
  padding: 6px 4px;
  background: linear-gradient(180deg, #f1f5f9 0%, #e8ecf1 100%);
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  min-width: 120px;
}
.sb-score {
  font-size: clamp(28px, 3.5vw, 40px);
  font-weight: 900;
  line-height: 1;
  min-width: 40px;
  text-align: center;
  padding: 4px 2px;
}
.sb-score-host { color: var(--host); }
.sb-score-guest { color: var(--guest); }
.sb-vs-sep {
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 900;
  line-height: 1;
  color: #94a3b8;
  flex-shrink: 0;
  padding: 0 2px;
}

.sb-side.winner { box-shadow: inset 0 0 0 2px var(--brand); }
.sb-guest.winner { box-shadow: inset 0 0 0 2px var(--guest); }
.sb-side.is-spectator-clickable {
  cursor: pointer;
  transition: box-shadow .2s ease, transform .15s ease, filter .2s ease;
}
.sb-side.is-spectator-clickable:hover {
  box-shadow: inset 0 0 0 2px #93c5fd;
  filter: saturate(1.05);
}
.sb-side.is-spectator-clickable.is-spectator-focus {
  box-shadow: inset 0 0 0 2px #2563eb;
  filter: saturate(1.12);
}
.sb-score.is-winner {
  animation: scoreGlow 1.5s ease-in-out infinite alternate;
}

/* Question card team color tint */
.question-card.is-host-side {
  border-color: #bfdbfe;
  background: linear-gradient(180deg, #f0f7ff 0%, #ffffff 30%);
}
.question-card.is-guest-side {
  border-color: #fecaca;
  background: linear-gradient(180deg, #fff5f5 0%, #ffffff 30%);
}

.play-area {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
}

.arena-card {
  background: var(--card); border-radius: var(--r-lg);
  box-shadow: var(--sh-sm); padding: 10px;
  border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 6px;
  min-height: var(--match-panels-height);
  height: var(--match-panels-height);
}
.arena-status { font: 700 12px/1 inherit; color: var(--brand); display: flex; align-items: center; gap: 5px; }
.arena-status i { font-size: 12px; }
.arena-board {
  position: relative;
  height: auto;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: #ffffff;
}
.arena-video {
  position: absolute; top: 0; left: 50%;
  width: 100%; height: 100%;
  object-fit: contain;
  filter: saturate(1.05);
  transform: translateX(-50%);
  transition: transform .4s ease;
}
.arena-center-line {
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 2px; border-left: 2px dashed rgba(100,116,139,.3);
  transform: translateX(-50%); z-index: 4;
}
.win-video-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 3;
}
.win-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.question-card {
  background: var(--card); border-radius: var(--r-lg);
  box-shadow: var(--sh-sm); padding: 14px;
  border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px;
}
.question-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  min-height: 0;
  padding: 0;
}
.spectator-follow-controls {
  position: static;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px;
  border: 1px solid #cfd8e6;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}
.spectator-follow-label {
  display: none;
}
.spectator-follow-btn {
  width: 26px;
  height: 26px;
  border: 1px solid transparent;
  background: #f8fafc;
  color: #475569;
  border-radius: 999px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font: 700 10px/1.2 inherit;
  cursor: pointer;
  transition: all .18s ease;
}
.spectator-follow-btn:hover {
  border-color: #93c5fd;
  color: #1d4ed8;
  background: #eff6ff;
}
.spectator-follow-btn.is-active {
  background: #dbeafe;
  border-color: #3b82f6;
  color: #1d4ed8;
}
.spectator-follow-btn i {
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
}
.subject-tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; background: var(--brand-light); color: var(--brand);
  border-radius: var(--r-full); font: 700 10px/1.4 inherit;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subject-tag i { font-size: 10px; }
.result-tag {
  position: static;
  font: 700 11px/1.2 inherit;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 3px 9px;
  max-width: clamp(140px, 32vw, 320px);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-tag:empty {
  display: none;
}
.spectator-feedback-row {
  margin-top: -4px;
  min-height: 0;
}
.spectator-feedback-tag {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-width: 0;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  font: 700 11px/1.2 inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-tag.is-neutral,
.spectator-feedback-tag.is-neutral {
  color: #475569;
  background: #f8fafc;
  border-color: #e2e8f0;
}
.result-tag.is-info,
.spectator-feedback-tag.is-info {
  color: #1d4ed8;
  background: #eff6ff;
  border-color: #93c5fd;
}
.result-tag.is-pending,
.spectator-feedback-tag.is-pending {
  color: #475569;
  background: #f8fafc;
  border-color: #cbd5e1;
}
.result-tag.is-correct,
.spectator-feedback-tag.is-correct {
  color: #166534;
  background: #dcfce7;
  border-color: #22c55e;
}
.result-tag.is-wrong,
.spectator-feedback-tag.is-wrong {
  color: #991b1b;
  background: #fee2e2;
  border-color: #ef4444;
}

.question-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.waiting-state {
  text-align: center;
  padding: 24px 12px;
}
.waiting-icon {
  width: 48px; height: 48px; border-radius: 50%;
  background: #f1f5f9;
  display: grid; place-items: center;
  font-size: 20px; color: var(--muted);
  margin: 0 auto 10px;
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.6;transform:scale(.95)} }
.waiting-text {
  font-size: 13px; font-weight: 600; color: var(--muted);
}

.question-text {
  font-size: clamp(15px, 1.8vw, 20px);
  font-weight: 800; line-height: 1.3; color: var(--ink);
  word-wrap: break-word; overflow-wrap: break-word;
  width: 100%;
}
.answers-grid {
  display: grid;
  gap: 6px;
  align-content: start;
}
.answers-grid.answers-grid--math {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.answer-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--card); color: var(--ink);
  font: 700 clamp(13px, 1.2vw, 16px)/1.3 inherit;
  cursor: pointer; transition: var(--tr); text-align: left; width: 100%;
}
.answer-badge {
  width: 28px; height: 28px; border-radius: 50%;
  background: #f1f5f9; color: var(--brand);
  display: grid; place-items: center;
  font: 800 12px/1 inherit; flex-shrink: 0;
}
.answer-value { line-height: 1.3; word-break: break-word; flex: 1; min-width: 0; display: block; }
.answer-btn:hover:not(:disabled) { border-color: var(--brand); background: #fafbff; transform: translateY(-1px); box-shadow: var(--sh-sm); }
.answer-btn.selected { border-color: var(--brand); background: var(--brand-light); }
.answer-btn:disabled { cursor: not-allowed; opacity: .65; }
.answer-btn.correct {
  border-color: #22c55e;
  background: #dcfce7;
  color: #14532d;
  opacity: 1;
  box-shadow: inset 0 0 0 1px #86efac;
}
.answer-btn.correct .answer-badge { background: #16a34a; color: #fff; }
.answer-btn.wrong {
  border-color: #ef4444;
  background: #fee2e2;
  color: #7f1d1d;
  opacity: 1;
  box-shadow: inset 0 0 0 1px #fca5a5;
}
.answer-btn.wrong .answer-badge { background: #dc2626; color: #fff; }

.room-actions {
  display: flex; gap: 8px; justify-content: center;
  padding: 10px 14px;
  background: var(--card); border-radius: var(--r-lg);
  box-shadow: var(--sh-sm); border: 1px solid var(--line);
}
.btn-action {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 24px; border: none; border-radius: var(--r-md);
  font: 700 13px/1 inherit; cursor: pointer; transition: var(--tr);
}
.btn-action:hover { transform: translateY(-1px); box-shadow: var(--sh-md); }
.btn-action:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-start { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; }
.btn-resume { background: #f59e0b; color: #fff; }
.voice-inline-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 2px;
}
.voice-top-btn {
  border: 1px solid #d1d5db;
  background: #fff;
  color: #64748b;
}
.voice-top-btn:hover {
  border-color: #93c5fd;
  color: #1d4ed8;
}
.voice-top-btn.is-on {
  border-color: #22c55e;
  background: #dcfce7;
  color: #166534;
}
.voice-status-text {
  display: none;
}
#voiceRemoteAudio {
  display: none;
}
#backgroundMusic {
  display: none;
}
.view-controls {
  position: fixed;
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 2250;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: var(--sh-md);
  backdrop-filter: blur(8px);
  max-width: calc(100vw - 16px);
  white-space: nowrap;
  overflow: hidden;
}
.view-controls.is-dragging {
  user-select: none;
}
.view-controls::-webkit-scrollbar { display: none; }
.view-drag-handle {
  width: 26px;
  height: 34px;
  border: 1px dashed rgba(15, 23, 42, 0.2);
  border-radius: 10px;
  background: #f3f6fa;
  color: #64748b;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  cursor: grab;
  touch-action: none;
}
.view-controls.is-dragging .view-drag-handle {
  cursor: grabbing;
  background: #e8efff;
  color: #1d4ed8;
  border-color: rgba(37, 99, 235, 0.35);
}
.view-drag-handle i {
  font-size: 12px;
  pointer-events: none;
}
.view-drag-handle:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.35);
  outline-offset: 2px;
}
.view-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.view-divider {
  width: 1px;
  height: 28px;
  background: rgba(15, 23, 42, 0.14);
}
.view-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background: #f2f5f9;
  color: #0f4fa9;
  box-shadow: var(--sh-sm);
  display: grid;
  place-items: center;
  transition: var(--tr);
}
.view-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--sh-md);
}
.view-btn:active {
  transform: translateY(0);
}
.view-btn:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.4);
  outline-offset: 2px;
}
.view-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--sh-sm);
}
.view-btn i {
  font-size: 14px;
}
.view-btn.is-active {
  background: #fee2e2;
  color: #b91c1c;
}
.view-btn-reset {
  background: linear-gradient(135deg, #e2ecff 0%, #dbeafe 100%);
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}
.view-btn-reset:hover {
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
}
.view-btn-reset i {
  font-size: 13px;
}
.view-label {
  min-width: 46px;
  text-align: center;
  font-weight: 800;
  font-size: 13px;
  color: #0f172a;
  user-select: none;
}

.question-card.is-winner-open .result-tag,
.question-card.is-winner-open .spectator-feedback-row,
.question-card.is-winner-open .question-body,
.question-card.is-winner-open .question-text,
.question-card.is-winner-open .answers-grid {
  display: none !important;
}

.winner-hud {
  position: relative;
  width: 100%;
  z-index: 2;
}
.winner-hud-card {
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.9);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 14px 44px rgba(15, 23, 42, 0.28);
  backdrop-filter: blur(8px);
  animation: winnerHudIn .35s ease;
}
@keyframes winnerHudIn {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}
.winner-hud-header {
  background: linear-gradient(135deg, #0f4fa9 0%, #2563eb 40%, #1d4ed8 100%);
  padding: 12px 14px;
  text-align: center;
  color: #fff;
}
.winner-hud-header.is-guest {
  background: linear-gradient(135deg, #991b1b 0%, #dc2626 40%, #ef4444 100%);
}
.winner-hud-header.is-draw {
  background: linear-gradient(135deg, #334155 0%, #475569 40%, #64748b 100%);
}
.winner-icon-badge {
  width: 52px;
  height: 52px;
  margin: 0 auto 8px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
}
.winner-icon-badge i {
  font-size: 24px;
}
.winner-modal-caption {
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.82);
}
.winner-hud-header h2 {
  margin: 2px 0 0;
  font-size: clamp(20px, 3.6vw, 28px);
  font-weight: 900;
  line-height: 1.15;
  word-break: break-word;
}
.winner-hud-body {
  padding: 11px 12px 12px;
  background: #fff;
  display: grid;
  gap: 10px;
}
.winner-score-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #f8fafc;
}
.winner-score-col {
  padding: 8px 8px;
  text-align: center;
  display: grid;
  gap: 2px;
}
.winner-score-col-host {
  background: linear-gradient(180deg, #eff6ff 0%, #f8fbff 100%);
}
.winner-score-col-guest {
  background: linear-gradient(180deg, #fef2f2 0%, #fff8f8 100%);
}
.winner-score-col.is-winner {
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.22);
}
.winner-score-col-guest.is-winner {
  box-shadow: inset 0 0 0 2px rgba(220, 38, 38, 0.25);
}
.winner-score-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.winner-score-value {
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
}
.winner-score-col-host .winner-score-value {
  color: var(--host);
}
.winner-score-col-guest .winner-score-value {
  color: var(--guest);
}
.winner-score-divider {
  width: 40px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  color: #94a3b8;
  background: #f1f5f9;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.winner-actions {
  display: flex;
  gap: 8px;
}
.winner-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 10px;
  border: none;
  border-radius: 10px;
  font: 700 13px/1 inherit;
  cursor: pointer;
  transition: var(--tr);
}
.winner-btn:hover {
  transform: translateY(-1px);
}
.winner-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}
.winner-btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
.winner-btn-secondary {
  background: #f1f5f9;
  color: var(--muted);
  border: 1px solid var(--line);
}

@supports (height: 100dvh) {
  :root {
    --match-panels-height: clamp(280px, calc(100dvh - 390px), 430px);
  }
}

/* Pixel preset: 1920x1080 */
@media (min-width: 1900px) and (min-height: 1000px) {
  .online-page { max-width: 1440px; }
  :root {
    --room-topbar-height: 64px;
    --match-panels-height: 480px;
  }
  .room-topbar { padding: 10px 14px; gap: 10px; }
  .sb-side { padding: 14px 20px; gap: 14px; }
  .sb-center { min-width: 150px; }
  .sb-score { font-size: clamp(36px, 3.6vw, 50px); }
  .team-avatar { width: 40px; height: 40px; font-size: 17px; }
  .sb-name { font-size: 16px; }
}

/* Pixel preset: 1366x768 */
@media (min-width: 1330px) and (max-width: 1410px) and (min-height: 730px) and (max-height: 810px) {
  :root {
    --room-topbar-height: 54px;
    --match-panels-height: 290px;
  }
  .room-topbar { padding: 6px 10px; gap: 6px; }
  .sb-score { font-size: clamp(24px, 4vw, 34px); }
  .sb-center { min-width: 100px; }
}

@media (max-width: 1399.98px) {
  .online-page { max-width: 1220px; }
  :root {
    --room-topbar-height: 56px;
    --match-panels-height: clamp(270px, calc(100vh - 330px), 400px);
  }
}

@media (max-height: 760px) and (min-width: 992px) {
  :root {
    --room-topbar-height: 50px;
    --match-panels-height: clamp(240px, calc(100vh - 300px), 320px);
  }
  .online-page { gap: 6px; }
  .room-shell, .room-stage, .play-area { gap: 8px; }
}

@media (max-width: 1199.98px) {
  .online-page { max-width: 1100px; padding: 2px 6px 8px; }
  :root {
    --room-topbar-height: 52px;
    --match-panels-height: clamp(250px, calc(100vh - 320px), 360px);
  }
}

@media (max-width: 991.98px) {
  :root {
    --room-topbar-height: 50px;
  }
  .play-area { grid-template-columns: 1fr; }
  .arena-card,
  .question-card {
    min-height: auto;
    height: auto;
    max-height: none;
  }
  .arena-board {
    flex: none;
    min-height: 220px;
    height: 220px;
  }
  .question-card { overflow: visible; }
  .answers-grid {
    overflow: visible;
    padding-right: 0;
    max-height: none;
  }
}

@media (max-width: 767.98px) {
  :root {
    --room-topbar-height: 48px;
  }
  .online-page { padding: 2px 6px 8px; gap: 6px; }
  .online-page .connection-pill { width: 40px; height: 28px; }
  .online-page .pill-indicator { width: 12px; height: 12px; }
  .online-page .pill-core { width: 7px; height: 7px; }
  .online-page .pill-wave { width: 9px; height: 9px; }

  .lobby-header { padding: 14px 16px; gap: 10px; }
  .lobby-icon { width: 40px; height: 40px; font-size: 17px; }
  .lobby-heading h1,
  .lobby-heading h2 { font-size: 15px; }
  .lobby-heading p { font-size: 11px; }
  .lobby-actions { padding: 8px; gap: 6px; }
  .lobby-action-btn { padding: 10px; gap: 10px; }
  .action-icon { width: 34px; height: 34px; font-size: 15px; }
  .action-text strong { font-size: 13px; }
  .action-text span { font-size: 10px; }

  .online-page .modal-box { border-radius: var(--r-lg); }
  .online-page .modal-header { padding: 10px 14px; }
  .online-page .modal-header h2 { font-size: 14px; }
  .online-page .modal-body { padding: 10px 14px; gap: 10px; }
  .online-page .modal-footer { padding: 10px 14px; }
  .online-page .btn-primary, .online-page .btn-secondary { font-size: 12px; padding: 8px 12px; }
  .online-page .field input, .online-page .field select { font-size: 14px; padding: 8px 10px; }
  .online-page .time-buttons button { font-size: 11px; padding: 7px 6px; min-width: 0; }
  .online-page .mode-buttons button,
  .online-page .difficulty-buttons-inline button {
    font-size: 11px;
    padding: 7px 6px;
    min-width: 0;
  }

  /* Game modals responsive */
  .gm-header { padding: 12px 14px; }
  .gm-header-icon { width: 32px; height: 32px; font-size: 13px; border-radius: 8px; }
  .gm-header h2 { font-size: 14px; }
  .gm-header p { font-size: 10px; }
  .gm-body { padding: 12px 14px !important; gap: 11px !important; }
  .gm-mode { padding: 8px 10px; gap: 6px; }
  .gm-mode i { font-size: 13px; }
  .gm-mode strong { font-size: 12px; }
  .gm-time { font-size: 11px; padding: 8px 6px; }
  .diff-btn { font-size: 11px; padding: 7px 8px; }
  .gm-footer { padding: 10px 14px !important; }
  .gm-submit { padding: 8px 16px !important; font-size: 12px !important; }
  .online-page .operation-btn {
    min-height: 40px;
    padding: 6px 7px;
  }
  .online-page .operation-btn .op-symbol { font-size: 14px; }
  .online-page .operation-btn .op-text { font-size: 10px; }

  .room-topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 6px;
    padding: 6px 8px;
    align-items: center;
  }
  .leave-btn { grid-column: 1; justify-self: start; }
  .room-code-box { grid-column: 2; justify-self: center; min-width: 0; max-width: 100%; overflow: hidden; }
  .room-timer { grid-column: 3; justify-self: end; margin-left: 0; }
  .room-status { display: none; }
  .room-spectators { display: none; }
  .leave-btn { font-size: 10px; padding: 5px 7px; gap: 0; }
  .leave-btn span { display: none; }
  .room-code-label { display: none; }
  .room-code-box { padding: 3px 4px 3px 6px; font-size: 11px; gap: 4px; }
  .room-code-box strong { font-size: 13px; letter-spacing: 1px; }
  .copy-btn { width: 22px; height: 22px; font-size: 10px; }
  .room-timer { padding: 4px 8px; font-size: 11px; }
  .room-timer i { display: none; }
  .room-timer strong { font-size: 13px; }

  .sb-side { padding: 8px 10px; gap: 6px; }
  .team-avatar { width: 28px; height: 28px; font-size: 12px; }
  .sb-role { font-size: 8px; }
  .sb-name { font-size: 12px; }
  .spectator-answer-pill { font-size: 9px; padding: 2px 6px; gap: 4px; }
  .conn-badge { font-size: 8px; padding: 2px 5px; }
  .sb-center { padding: 4px 2px; min-width: 90px; }
  .sb-score { font-size: clamp(20px, 5.5vw, 28px); min-width: 30px; }
  .sb-vs-sep { font-size: clamp(16px, 2.5vw, 22px); }

  .arena-card { padding: 8px; gap: 4px; }
  .arena-status { font-size: 11px; }
  .arena-board { min-height: 170px; height: 170px; }

  .question-card { padding: 10px; gap: 8px; }
  .question-head {
    gap: 5px;
    min-height: 0;
    padding: 0;
    grid-template-columns: minmax(0, 1fr) auto auto;
  }
  .spectator-follow-controls {
    width: auto;
    overflow: visible;
    padding: 2px;
    gap: 3px;
  }
  .spectator-follow-btn {
    width: 24px;
    height: 24px;
    font-size: 9px;
  }
  .subject-tag { font-size: 9px; padding: 2px 8px; }
  .result-tag {
    font-size: 10px;
    padding: 3px 8px;
    max-width: clamp(110px, 38vw, 220px);
  }
  .spectator-feedback-tag {
    font-size: 10px;
    padding: 3px 8px;
    max-width: 100%;
  }
  .question-text { font-size: clamp(14px, 4vw, 18px); }
  .answer-btn { font-size: 12px; padding: 8px 10px; gap: 8px; }
  .answer-badge { width: 24px; height: 24px; font-size: 10px; }
  .waiting-icon { width: 40px; height: 40px; font-size: 16px; }
  .waiting-text { font-size: 12px; }

  .room-actions { padding: 8px 10px; }
  .btn-action { font-size: 12px; padding: 8px 16px; }
  .voice-inline-controls { gap: 4px; margin-left: 0; }
  .voice-top-btn { width: 22px; height: 22px; font-size: 10px; }
  .voice-status-text { display: none; }

  .view-controls {
    gap: 6px;
    padding: 6px 8px;
    border-radius: 14px;
    max-width: calc(100vw - 12px);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
  .view-group { gap: 4px; }
  .view-drag-handle { width: 24px; height: 30px; border-radius: 9px; }
  .view-btn { width: 30px; height: 30px; border-radius: 9px; }
  .view-btn i { font-size: 12px; }
  .view-label { min-width: 42px; font-size: 12px; }
  .view-divider { height: 24px; }

  .winner-hud { width: 100%; }
  .winner-hud-card { border-radius: 14px; }
  .winner-hud-header { padding: 10px 12px; }
  .winner-icon-badge { width: 48px; height: 48px; margin-bottom: 6px; }
  .winner-icon-badge i { font-size: 22px; }
  .winner-modal-caption { font-size: 11px; }
  .winner-hud-header h2 { font-size: 24px; }
  .winner-hud-body { padding: 10px; gap: 8px; }
  .winner-score-col { padding: 9px 7px; }
  .winner-score-name { font-size: 10px; }
  .winner-score-value { font-size: 30px; }
  .winner-score-divider { width: 38px; font-size: 10px; }
  .winner-btn { font-size: 13px; padding: 11px 10px; border-radius: 10px; }
  .winner-actions { gap: 8px; }
}

@media (max-width: 420px) {
  .online-page .connection-pill {
    width: 36px;
    height: 26px;
  }
  .view-controls {
    gap: 3px;
    padding: 5px 6px;
  }
  .view-drag-handle { width: 22px; height: 28px; }
  .view-group { gap: 3px; }
  .view-btn { width: 28px; height: 28px; }
  .view-label { min-width: 30px; font-size: 11px; }
}

@media (max-width: 575.98px) {
  :root {
    --room-topbar-height: 46px;
  }
  .room-topbar {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "leave timer"
      "code code";
    row-gap: 5px;
    gap: 4px;
    padding: 5px 6px;
  }
  .leave-btn { grid-area: leave; }
  .room-timer { grid-area: timer; justify-self: end; }
  .room-code-box {
    grid-area: code;
    width: 100%;
    justify-self: stretch;
    justify-content: center;
  }
  .room-code-box strong { font-size: 12px; letter-spacing: .8px; }
  .copy-btn { width: 20px; height: 20px; font-size: 9px; }
  .room-code-box { gap: 3px; }
  .room-timer { padding: 3px 6px; }
  .room-timer strong { font-size: 12px; }
  .arena-board { min-height: 150px; height: 150px; }
  .view-controls {
    gap: 4px;
    padding: 6px 7px;
  }
  .view-drag-handle { width: 22px; height: 28px; }
  .view-group { gap: 3px; }
  .view-label { min-width: 34px; }
  #volumeLabel { display: none; }
  .winner-actions {
    flex-direction: column;
  }
  .winner-btn {
    width: 100%;
  }
  .winner-hud {
    width: 100%;
  }
  .scoreboard {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "center center"
      "host guest";
  }
  .sb-center {
    grid-area: center;
    min-width: 0;
    width: 100%;
    border-left: none;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: 6px 4px;
  }
  .sb-host {
    grid-area: host;
    border-right: 1px solid var(--line);
  }
  .sb-guest { grid-area: guest; }
  .scoreboard > .sb-side:first-child {
    border-top-left-radius: 0;
    border-bottom-left-radius: var(--r-lg);
  }
  .scoreboard > .sb-side:last-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: var(--r-lg);
  }
  .sb-score { font-size: clamp(18px, 5vw, 24px); }
  .sb-side { padding: 6px 8px; gap: 5px; }
}

@media (max-width: 399.98px) {
  :root {
    --room-topbar-height: 44px;
  }
  .room-topbar { gap: 3px; padding: 4px 5px; }
  .room-code-box strong { font-size: 11px; letter-spacing: .5px; }
  .sb-score { font-size: clamp(16px, 5vw, 20px); min-width: 24px; }
  .sb-center { min-width: 64px; }
  .team-avatar { width: 22px; height: 22px; font-size: 10px; }
  .sb-name { font-size: 11px; }
  .sb-vs-sep { font-size: clamp(14px, 2vw, 18px); }
  .conn-badge { display: none; }
  .arena-board { min-height: 132px; height: 132px; }
  .view-drag-handle { width: 21px; height: 28px; }
  .view-btn { width: 28px; height: 28px; }
  .view-label { min-width: 30px; font-size: 11px; }
  .winner-hud { width: 100%; }
}

/* ── Polished enhancements ── */
.lobby-action-btn {
  transition: all .25s cubic-bezier(.4,0,.2,1);
}
.lobby-action-btn:hover .action-icon {
  transform: scale(1.08);
  transition: transform .2s ease;
}

.sb-score {
  transition: all .3s cubic-bezier(.4,0,.2,1);
}
@keyframes scoreGlow {
  from { filter: drop-shadow(0 0 0 transparent); }
  to { filter: drop-shadow(0 0 8px currentColor); }
}

.answer-btn {
  transition: all .2s cubic-bezier(.4,0,.2,1);
}
.answer-btn.correct {
  animation: correctPulse .4s ease;
}
@keyframes correctPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); }
}
.answer-btn.wrong {
  animation: wrongShake .4s ease;
}
@keyframes wrongShake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.btn-start {
  position: relative; overflow: hidden;
}
.btn-start::after {
  content: ""; position: absolute;
  top: 0; left: -100%; width: 50%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.2), transparent);
  animation: btnShimmer 2.5s ease-in-out infinite;
}
@keyframes btnShimmer { 0%{left:-100%} 50%,100%{left:150%} }

.room-timer.is-urgent {
  background: #fef2f2; border-color: #fca5a5; color: var(--danger);
}
.room-timer.is-urgent strong { color: var(--danger); }

@media (monochrome) {
  .lobby-header,
  .sb-host,
  .sb-guest,
  .subject-tag {
    background: #fff !important;
  }
  .host-avatar,
  .guest-avatar,
  .online-page .btn-primary,
  .btn-start {
    background: #000 !important;
    color: #fff !important;
  }
  .online-page .connection-pill.online,
  .online-page .connection-pill.is-online,
  .conn-badge.is-online {
    border-color: #000 !important;
    color: #000 !important;
    background: #fff !important;
  }
}

@media (hover: none) and (pointer: coarse) {
  .online-page .btn-primary:hover, .online-page .btn-secondary:hover,
  .online-page .btn-action:hover, .online-page .lobby-action-btn:hover,
  .online-page .answer-btn:hover:not(:disabled), .online-page .leave-btn:hover, .online-page .copy-btn:hover,
  .gm-mode:hover, .gm-time:hover, .diff-btn:hover, .view-btn:hover, .winner-btn:hover {
    transform: none; box-shadow: none;
  }
  .online-page .btn-primary:active, .online-page .btn-secondary:active,
  .online-page .btn-action:active, .online-page .lobby-action-btn:active,
  .online-page .answer-btn:active, .online-page .leave-btn:active,
  .gm-mode:active, .gm-time:active, .diff-btn:active, .view-btn:active, .winner-btn:active { transform: scale(.98); }
}
