:root {
  --bg-dark: #0b0f19;
  --bg-card: #131b2e;
  --bg-card-hover: #1c2742;
  --border-color: #24324f;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-glow: rgba(59, 130, 246, 0.35);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.35);
  --success: #10b981;
  --warning: #f59e0b;
}

[data-theme="light"] {
  --bg-dark: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --border-color: #cbd5e1;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-glow: rgba(37, 99, 235, 0.25);
  --danger: #dc2626;
  --danger-glow: rgba(220, 38, 38, 0.2);
  --success: #059669;
  --warning: #d97706;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

input, select, textarea {
  user-select: text !important;
  -webkit-user-select: text !important;
}

/* Screens Management */
.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

/* =======================================================
   1. LOBBY SCREEN
   ======================================================= */
#screenLobby {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 20%, #1e293b 0%, #0b0f19 70%);
}

.lobby-container {
  width: 100%;
  max-width: 520px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.logo-header {
  text-align: center;
  margin-bottom: 24px;
}

.logo-badge {
  display: inline-block;
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.logo-header h1 {
  font-size: 1.6rem;
  font-weight: 800;
  background: linear-gradient(135deg, #60a5fa, #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}

.logo-header p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: #cbd5e1;
}

.avatar-selector {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.avatar-opt {
  font-size: 1.5rem;
  padding: 8px 12px;
  background: var(--bg-dark);
  border: 2px solid var(--border-color);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

.avatar-opt:hover, .avatar-opt.selected {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.15);
  transform: translateY(-2px);
}

input[type="text"], select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: #fff;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.tabs-header {
  display: flex;
  background: var(--bg-dark);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 10px var(--primary-glow);
}

.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  border: none;
  border-radius: 10px;
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.btn-solo-practice {
  flex: 1;
  padding: 14px 16px;
  background: linear-gradient(135deg, #d97706, #f59e0b);
  border: none;
  border-radius: 10px;
  color: white;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn-solo-practice:hover {
  transform: translateY(-1px);
  filter: brightness(1.1);
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.45);
}

/* =======================================================
   2. WAITING ROOM SCREEN
   ======================================================= */
#screenWaiting {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.waiting-box {
  width: 100%;
  max-width: 600px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 30px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.room-code-badge {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: #0f172a;
  border: 2px dashed var(--primary);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 4px;
  color: #60a5fa;
  margin: 12px 0 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.room-code-badge:hover {
  background: rgba(59, 130, 246, 0.1);
}

.room-code-badge span.copy-hint {
  font-size: 0.75rem;
  letter-spacing: 0;
  color: var(--text-muted);
  font-weight: normal;
}

.players-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 20px 0 24px;
  text-align: left;
}

.player-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 10px;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.player-avatar {
  font-size: 1.4rem;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
}

.player-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.player-tag {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  margin-left: 6px;
}

.status-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
}

.status-badge.ready {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.status-badge.waiting {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

/* =======================================================
   3. GAME ARENA SCREEN
   ======================================================= */
#screenGame {
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Top Live Header */
.game-header {
  background: rgba(19, 27, 46, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 10;
}

.opponents-bar {
  display: flex;
  gap: 12px;
  flex: 1;
  max-width: 650px;
  overflow-x: auto;
}

.opponent-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(11, 15, 25, 0.7);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 12px;
  min-width: 160px;
  transition: all 0.2s;
}

.opponent-card.me {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.1);
}

.op-avatar {
  font-size: 1.1rem;
}

.op-meta {
  flex: 1;
  min-width: 0;
}

.op-name {
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.op-color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.op-progress-txt {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.op-progress-bar {
  width: 100%;
  height: 4px;
  background: #1e293b;
  border-radius: 2px;
  margin-top: 2px;
  overflow: hidden;
}

.op-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.3s;
}

.timer-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #0f172a;
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: 8px;
  font-family: monospace;
  font-size: 1.15rem;
  font-weight: 700;
  color: #38bdf8;
}

.btn-submit-exam {
  background: linear-gradient(135deg, #059669, #10b981);
  color: white;
  border: none;
  padding: 8px 18px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-submit-exam:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

/* Arena Body */
.arena-container {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* Remote Cursors Overlay */
#cursorOverlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
}

.remote-cursor {
  position: absolute;
  pointer-events: none;
  transition: left 0.05s linear, top 0.05s linear;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  z-index: 100;
  transform: translate(-2px, -2px);
}

.cursor-pointer {
  width: 18px;
  height: 18px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

.cursor-tag {
  background: rgba(15, 23, 42, 0.9);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  margin-top: 2px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  border-left: 3px solid;
  pointer-events: none;
}

.cursor-tag.live-spectate {
  background: rgba(15, 23, 42, 0.95) !important;
  border: 1.5px solid #ef4444 !important;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.6) !important;
  color: #f8fafc !important;
  font-weight: 800 !important;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.live-pulse-dot {
  font-size: 0.7rem;
  animation: pulseLive 1.2s infinite;
}

/* Question Section */
.question-pane {
  flex: 1;
  padding: 24px 32px;
  overflow-y: auto;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.q-badge-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.q-index-pill {
  background: var(--primary);
  color: white;
  font-weight: 800;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 6px;
}

.q-chapter-pill {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 6px;
}

.q-critical-pill {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
}

.btn-flag-q {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
  user-select: none;
}
.btn-flag-q:hover {
  background: rgba(245, 158, 11, 0.15);
  border-color: #f59e0b;
  color: #fbbf24;
}
.btn-flag-q.active {
  background: rgba(245, 158, 11, 0.2);
  border-color: #f59e0b;
  color: #fbbf24;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.3);
}

.pallet-flag-icon {
  font-size: 0.65rem;
  position: absolute;
  top: 2px;
  right: 2px;
  line-height: 1;
}

.q-pallet-btn.flagged {
  border-color: #f59e0b !important;
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.35) !important;
}

/* Rung màn hình khi phạm câu điểm liệt */
@keyframes shakeEffect {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
.shake-screen {
  animation: shakeEffect 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.q-text-content {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 16px;
  color: #f8fafc;
}

.q-image-box {
  background: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 16px;
  text-align: center;
}

.q-image-box img {
  max-width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 6px;
}

.options-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.option-card {
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 14px 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: all 0.15s;
  position: relative;
}

.option-card:hover {
  background: var(--bg-card-hover);
  border-color: #3b82f6;
}

.option-card.selected {
  background: rgba(59, 130, 246, 0.12);
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.opt-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
  color: #cbd5e1;
}

.option-card.selected .opt-num {
  background: var(--primary);
  color: white;
}

.opt-text {
  flex: 1;
  font-size: 0.98rem;
  line-height: 1.45;
}

/* Opponent chosen badges inside option */
.opt-opponents-tag {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.op-choice-badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  animation: popIn 0.2s ease-out;
}

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Palette Sidebar */
.palette-pane {
  width: 280px;
  background: var(--bg-card);
  border-left: 1px solid var(--border-color);
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.palette-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  overflow-y: auto;
  max-height: calc(100vh - 220px);
  padding-right: 4px;
}

.q-pallet-btn {
  aspect-ratio: 1;
  border: 1px solid var(--border-color);
  background: var(--bg-dark);
  border-radius: 8px;
  color: #94a3b8;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.15s;
}

.q-pallet-btn:hover {
  background: var(--bg-card-hover);
  color: #fff;
}

.q-pallet-btn.current {
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.4);
}

.q-pallet-btn.my-answered {
  background: rgba(16, 185, 129, 0.15);
  border-color: #10b981;
  color: #34d399;
}

/* Palette styles in Review Mode */
.q-pallet-btn.rev-correct {
  background: rgba(16, 185, 129, 0.25) !important;
  border-color: #10b981 !important;
  color: #34d399 !important;
  font-weight: 800;
}
.q-pallet-btn.rev-wrong {
  background: rgba(239, 68, 68, 0.25) !important;
  border-color: #ef4444 !important;
  color: #f87171 !important;
  font-weight: 800;
}
.q-pallet-btn.rev-critical-wrong {
  background: rgba(239, 68, 68, 0.4) !important;
  border: 2px dashed #f59e0b !important;
  color: #fca5a5 !important;
  font-weight: 800;
  animation: pulseCrit 1.5s infinite;
}
.q-pallet-btn.rev-unanswered {
  background: rgba(100, 116, 139, 0.15) !important;
  border-color: #475569 !important;
  color: #94a3b8 !important;
}

@keyframes pulseCrit {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
  50% { box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.2); }
}

/* =======================================================
   BANNER THEO DÕI GÓC NHÌN NGƯỜI CHƠI (FOLLOW MODE / SPECTATOR)
   ======================================================= */
.follow-mode-banner {
  background: linear-gradient(135deg, rgba(30, 27, 75, 0.95), rgba(15, 23, 42, 0.95));
  border-bottom: 2px solid #6366f1;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  z-index: 25;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.25);
  animation: slideDownBanner 0.25s ease-out;
}

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

.fmb-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.fmb-live-dot {
  width: 10px;
  height: 10px;
  background: #ef4444;
  border-radius: 50%;
  box-shadow: 0 0 10px #ef4444;
  animation: pulseLive 1.2s infinite;
  flex-shrink: 0;
}

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

.fmb-avatar {
  font-size: 1.5rem;
}

.fmb-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: #e0e7ff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.fmb-name {
  color: #a5b4fc;
}

.fmb-badge {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1px;
  background: rgba(99, 102, 241, 0.25);
  color: #c7d2fe;
  border: 1px solid rgba(99, 102, 241, 0.6);
  padding: 2px 7px;
  border-radius: 4px;
}

.fmb-sub {
  font-size: 0.78rem;
  color: #94a3b8;
  margin-top: 2px;
}

.btn-stop-follow {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-stop-follow:hover {
  background: #dc2626;
  color: white;
  border-color: #dc2626;
  transform: translateY(-1px);
}

.btn-follow-toggle {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.4);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  margin-left: auto;
  white-space: nowrap;
}

.btn-follow-toggle:hover {
  background: #6366f1;
  color: white;
  border-color: #6366f1;
}

.btn-follow-toggle.active {
  background: #6366f1;
  color: white;
  border-color: #818cf8;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.5);
}

.opponent-card.following {
  border-color: #6366f1 !important;
  box-shadow: 0 0 14px rgba(99, 102, 241, 0.45) !important;
  background: rgba(99, 102, 241, 0.08) !important;
}

.follow-choice-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  animation: popBadge 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popBadge {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.option-card.followed-picked {
  border-width: 2px !important;
  transition: all 0.25s ease;
}

.fmb-live-ticker {
  color: #38bdf8;
  font-weight: 600;
}

.fmb-live-ticker.live-act {
  color: #fbbf24;
  animation: tickerHighlight 1s ease-out;
}

@keyframes tickerHighlight {
  0% { background: rgba(245, 158, 11, 0.35); border-radius: 4px; padding: 2px 6px; }
  100% { background: transparent; }
}

/* =======================================================
   BANNER KẾT QUẢ TRỰC TIẾP TRÊN PHẦN CÂU HỎI
   ======================================================= */
.game-result-banner {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.95));
  border-bottom: 2px solid #3b82f6;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  z-index: 20;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.grb-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.grb-badge {
  font-size: 1.4rem;
  font-weight: 900;
  padding: 6px 14px;
  border-radius: 8px;
  letter-spacing: 1px;
}
.grb-badge.pass {
  background: #059669;
  color: white;
  box-shadow: 0 0 14px rgba(16, 185, 129, 0.4);
}
.grb-badge.fail {
  background: #dc2626;
  color: white;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.4);
}

.grb-text .grb-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: #f8fafc;
}

.grb-text .grb-sub {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 2px;
}

.grb-filters {
  display: flex;
  gap: 6px;
  background: rgba(15, 23, 42, 0.6);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.grb-filter-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.grb-filter-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: white;
}
.grb-filter-btn.active {
  background: var(--primary);
  color: white;
}
.grb-filter-btn.danger.active {
  background: var(--danger);
  color: white;
}
.grb-filter-btn.warning.active {
  background: #d97706;
  color: white;
}

.grb-actions {
  display: flex;
  gap: 8px;
}

.btn-sm-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: white;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-sm-primary:hover {
  filter: brightness(1.15);
}

.btn-sm-nav {
  background: rgba(30, 41, 59, 0.9);
  color: #cbd5e1;
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-sm-nav:hover {
  background: rgba(51, 65, 85, 0.9);
  color: white;
}

/* Thẻ đáp án trong chế độ Review trực tiếp trên câu hỏi */
.q-result-pill {
  font-size: 0.8rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.q-result-pill.pass {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.5);
}
.q-result-pill.fail {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.5);
}
.q-result-pill.unanswered {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.option-card.review-correct {
  background: rgba(16, 185, 129, 0.12) !important;
  border-color: #10b981 !important;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.25) !important;
}

.option-card.review-correct .opt-num {
  background: #10b981 !important;
  color: white !important;
}

.option-card.review-wrong {
  background: rgba(239, 68, 68, 0.12) !important;
  border-color: #ef4444 !important;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.2) !important;
}

.option-card.review-wrong .opt-num {
  background: #ef4444 !important;
  color: white !important;
}

.my-choice-tag {
  font-size: 0.75rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  margin-left: auto;
  white-space: nowrap;
}
.my-choice-tag.pass {
  background: rgba(16, 185, 129, 0.25);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.5);
}
.my-choice-tag.fail {
  background: rgba(239, 68, 68, 0.25);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.5);
}

/* Hộp giải thích chi tiết & Căn cứ pháp lý */
.explanation-box {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-left: 4px solid #38bdf8;
  border-radius: 10px;
  padding: 14px 18px;
  margin-top: 14px;
  animation: fadeIn 0.25s ease-out;
}

.explanation-title {
  color: #38bdf8;
  font-weight: 800;
  font-size: 0.9rem;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.explanation-text {
  font-size: 0.92rem;
  line-height: 1.6;
  color: #cbd5e1;
}

.pallet-dots-wrap {
  position: absolute;
  bottom: 2px;
  display: flex;
  gap: 2px;
}

.pallet-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.nav-controls {
  margin-top: auto;
  padding: 16px 32px;
  background: rgba(19, 27, 46, 0.8);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
}

.btn-nav {
  padding: 10px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: #cbd5e1;
  font-weight: 600;
  cursor: pointer;
}

.btn-nav:hover:not(:disabled) {
  background: var(--bg-card-hover);
  color: white;
}

.btn-nav:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* =======================================================
   4. RESULT SCREEN
   ======================================================= */
#screenResult {
  padding: 30px 20px;
  overflow-y: auto;
}

.result-container {
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.podium-box {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 16px;
  margin: 30px 0 40px;
}

.podium-slot {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px 16px;
  text-align: center;
  width: 220px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.4);
}

.podium-slot.rank-1 {
  order: 2;
  border-color: #fbbf24;
  transform: translateY(-20px);
}

.podium-slot.rank-2 {
  order: 1;
  border-color: #94a3b8;
}

.podium-slot.rank-3 {
  order: 3;
  border-color: #d97706;
}

.podium-crown {
  font-size: 2rem;
  margin-bottom: 6px;
}

.podium-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.podium-score {
  font-size: 1.5rem;
  font-weight: 800;
  color: #38bdf8;
}

/* =======================================================
   4. REVIEW CARDS SECTION (THẺ CÂU HỎI TRỰC QUAN)
   ======================================================= */
.review-section {
  margin-bottom: 30px;
}

.review-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 16px 20px;
  margin-bottom: 16px;
}

.review-filters {
  display: flex;
  gap: 8px;
}

.rf-btn {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.rf-btn:hover {
  background: var(--bg-card-hover);
  color: #fff;
}

.rf-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 0 12px var(--primary-glow);
}

.rf-btn.danger.active {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
  box-shadow: 0 0 12px var(--danger-glow);
}

.rf-btn.warning.active {
  background: #d97706;
  color: white;
  border-color: #d97706;
  box-shadow: 0 0 12px rgba(217, 119, 6, 0.4);
}

/* Quick Jump Palette in Review */
.review-palette-wrap {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 24px;
}

@media (max-width: 768px) {
  .review-palette-wrap {
    grid-template-columns: repeat(10, 1fr);
  }
}

.rf-pal-btn {
  padding: 6px 0;
  font-size: 0.8rem;
  font-weight: 800;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-dark);
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.rf-pal-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.2);
}

.rf-pal-btn.is-correct {
  background: rgba(16, 185, 129, 0.18);
  border-color: #10b981;
  color: #34d399;
}

.rf-pal-btn.is-wrong {
  background: rgba(239, 68, 68, 0.18);
  border-color: #ef4444;
  color: #f87171;
}

.rf-pal-btn.is-critical {
  box-shadow: 0 0 0 1px #f59e0b;
}

/* Review Cards List */
.review-cards-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.review-q-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  transition: border-color 0.2s;
  scroll-margin-top: 20px;
}

.review-q-card.critical {
  border-left: 5px solid var(--danger);
}

.review-q-card.user-correct {
  border-color: rgba(16, 185, 129, 0.4);
}

.review-q-card.user-wrong {
  border-color: rgba(239, 68, 68, 0.4);
}

/* Option in Review Card */
.option-card.review {
  cursor: default;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--bg-dark);
  border: 1.5px solid var(--border-color);
  margin-bottom: 8px;
  transition: all 0.2s;
}

.option-card.review.correct-answer {
  background: rgba(16, 185, 129, 0.12);
  border-color: #10b981;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

.correct-badge-pill {
  background: #059669;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 6px;
  margin-left: auto;
  white-space: nowrap;
}

.opt-opponents-tag {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}

.op-choice-badge {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 8px;
  font-weight: 700;
  color: white;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.op-choice-badge.wrong-pick {
  border: 1px solid rgba(239, 68, 68, 0.8);
}

.badge-tag {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge-tag.pass { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.badge-tag.fail { background: rgba(239, 68, 68, 0.2); color: #f87171; }

/* =======================================================
   5. LOCALSTORAGE MODAL & HISTORY UI
   ======================================================= */
.btn-history-trigger {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-history-trigger:hover {
  background: var(--primary);
  color: white;
}

.test-quick-bar {
  background: rgba(59, 130, 246, 0.08);
  border: 1px dashed rgba(59, 130, 246, 0.3);
  border-radius: 8px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: #93c5fd;
}

.btn-quick-tab {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-quick-tab:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.active {
  display: flex;
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
  margin-bottom: 16px;
}
.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #f8fafc;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.stats-overview {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
}

.stat-num {
  font-size: 1.3rem;
  font-weight: 800;
  color: #38bdf8;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding-right: 4px;
}

.history-item {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
}

.history-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.wrong-questions-box {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 140px;
  overflow-y: auto;
}

.wrong-q-pill {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
}

.modal-footer {
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

.btn-clear-history {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 600;
}
.btn-clear-history:hover {
  background: var(--danger);
  color: white;
}

/* =======================================================
   6. QUICK REACTIONS & SOUND FX UI
   ======================================================= */
.btn-sound-toggle {
  background: #0f172a;
  border: 1px solid var(--border-color);
  color: #fff;
  font-size: 1.1rem;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-sound-toggle:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
}

.quick-reactions-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: 20px;
}

.qr-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 2px;
}

.qr-btn {
  background: none;
  border: none;
  font-size: 1.15rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
  transition: transform 0.15s;
}
.qr-btn:hover {
  transform: scale(1.35);
}
.qr-btn:active {
  transform: scale(0.9);
}

/* Floating Emoji Animation */
.floating-emoji {
  position: absolute;
  pointer-events: none;
  z-index: 999;
  font-size: 2.2rem;
  animation: floatUpFade 1.6s ease-out forwards;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.6));
}

@keyframes floatUpFade {
  0% {
    opacity: 1;
    transform: translate(-50%, 0) scale(0.6) rotate(0deg);
  }
  30% {
    transform: translate(-50%, -40px) scale(1.3) rotate(-10deg);
  }
  60% {
    transform: translate(-50%, -90px) scale(1.1) rotate(10deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -150px) scale(0.9) rotate(0deg);
  }
}

/* =======================================================
   RESPONSIVE: màn hình thi đấu trên tablet / điện thoại
   ======================================================= */
@media (max-width: 900px) {
  .game-header {
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 8px;
    position: sticky;
    top: 0;
  }
  .timer-box { order: 1; padding: 5px 10px; font-size: 1rem; }
  .btn-sound-toggle { order: 2; }
  .btn-submit-exam { order: 3; margin-left: auto; padding: 8px 14px; }
  .opponents-bar {
    order: 4;
    flex: 1 0 100%;
    max-width: none;
    gap: 8px;
    padding-bottom: 2px;
  }
  .opponent-card { min-width: 140px; padding: 5px 8px; }

  .arena-container {
    flex-direction: column;
    overflow: visible;
  }
  .question-pane {
    width: 100%;
    max-width: none;
    padding: 16px 14px 12px;
    overflow: visible;
  }
  .q-text-content { font-size: 1.05rem; line-height: 1.5; }
  .option-card { padding: 14px 12px; }

  /* Danh sách câu: dải cuộn ngang ngay dưới thanh trên */
  .palette-pane {
    order: -1;
    width: 100%;
    border-left: none;
    border-bottom: 1px solid var(--border-color);
    padding: 8px 12px;
  }
  .palette-title { display: none; }
  .palette-grid {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
    padding: 2px 0 6px;
    scroll-snap-type: x proximity;
  }
  .q-pallet-btn {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    aspect-ratio: auto;
    scroll-snap-align: center;
  }

  /* Điều hướng cố định ở đáy để bấm bằng ngón cái */
  .nav-controls {
    position: sticky;
    bottom: 0;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 0;
    background: var(--bg-dark);
    z-index: 5;
  }
  .nav-controls .btn-nav { flex: 1; min-width: 0; padding: 12px 10px; }
  .quick-reactions-bar { order: 3; flex: 1 0 100%; justify-content: center; }
  .qr-label { display: none; }
}

@media (max-width: 480px) {
  #screenLobby { padding: 12px; align-items: flex-start; }
  .lobby-container { padding: 20px 16px; border-radius: 14px; }
  .avatar-selector { gap: 6px; }
  .avatar-opt { padding: 8px 0; flex: 1; font-size: 1.35rem; }
  .logo-header > div { flex-wrap: wrap; gap: 8px; }
  .q-badge-bar { flex-wrap: wrap; }
}

/* =======================================================
   NÚT CHUYỂN ĐỔI GIAO DIỆN SÁNG / TỐI (LIGHT / DARK THEME)
   ======================================================= */
.btn-theme-toggle {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}
.btn-theme-toggle:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
  transform: translateY(-1px);
}
.btn-theme-toggle:active {
  transform: translateY(0);
}

/* Giao diện Sáng (Light Theme Overrides) */
[data-theme="light"] body {
  background-color: var(--bg-dark);
  color: var(--text-main);
}
[data-theme="light"] #screenLobby,
[data-theme="light"] #screenWaiting {
  background: radial-gradient(circle at 50% 20%, #e2e8f0 0%, #f1f5f9 70%);
}
[data-theme="light"] .lobby-container,
[data-theme="light"] .waiting-box,
[data-theme="light"] .waiting-container {
  background: #ffffff;
  border-color: #e2e8f0;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
}
[data-theme="light"] .room-code-badge {
  background: #f1f5f9;
  border-color: var(--primary);
  color: #1d4ed8;
}
[data-theme="light"] .test-quick-bar {
  background: rgba(37, 99, 235, 0.06);
  border-color: rgba(37, 99, 235, 0.25);
  color: #1e40af;
}
[data-theme="light"] .btn-theme-toggle {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #1e293b;
}
[data-theme="light"] .btn-theme-toggle:hover {
  background: #e2e8f0;
  border-color: #94a3b8;
}
[data-theme="light"] .btn-history-trigger {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  border-color: rgba(37, 99, 235, 0.3);
}
[data-theme="light"] .btn-history-trigger:hover {
  background: #2563eb;
  color: #ffffff;
}
[data-theme="light"] .form-group label {
  color: #334155;
}
[data-theme="light"] input[type="text"],
[data-theme="light"] select {
  background: #ffffff !important;
  color: #0f172a !important;
  border-color: #cbd5e1 !important;
}
[data-theme="light"] input[type="text"]:focus,
[data-theme="light"] select:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px var(--primary-glow) !important;
}
[data-theme="light"] .tab-btn {
  color: #64748b;
  border-bottom-color: transparent;
}
[data-theme="light"] .tab-btn.active {
  color: #2563eb;
  border-bottom-color: #2563eb;
}
[data-theme="light"] .game-header {
  background: #ffffff;
  border-bottom-color: #e2e8f0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
[data-theme="light"] .timer-box {
  background: #f8fafc;
  border-color: #cbd5e1;
}
[data-theme="light"] .timer-box #timerText {
  color: #0f172a;
}
[data-theme="light"] .btn-sound-toggle {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #1e293b;
}
[data-theme="light"] .opponent-card {
  background: #f8fafc;
  border-color: #e2e8f0;
}
[data-theme="light"] .opponent-card .op-name span:last-child {
  color: #0f172a;
}
[data-theme="light"] .opponent-card .op-sub {
  color: #64748b;
}
[data-theme="light"] .question-pane {
  background: #ffffff;
}
[data-theme="light"] .q-badge-bar {
  border-bottom-color: #f1f5f9;
}
[data-theme="light"] .q-index-pill {
  background: #f1f5f9;
  color: #1e293b;
  border-color: #cbd5e1;
}
[data-theme="light"] .q-chapter-pill {
  color: #475569;
}
[data-theme="light"] .q-text-content {
  color: #0f172a;
}
[data-theme="light"] .q-image-box {
  background: #f8fafc;
  border-color: #e2e8f0;
}
[data-theme="light"] .option-card {
  background: #ffffff;
  border-color: #e2e8f0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .option-card:hover {
  background: #f8fafc;
  border-color: #3b82f6;
}
[data-theme="light"] .option-card.selected {
  background: rgba(37, 99, 235, 0.08);
  border-color: #2563eb;
}
[data-theme="light"] .opt-num {
  background: #e2e8f0;
  color: #334155;
}
[data-theme="light"] .opt-text {
  color: #1e293b;
}
[data-theme="light"] .palette-pane {
  background: #f8fafc;
  border-left-color: #e2e8f0;
}
[data-theme="light"] .palette-title {
  color: #64748b;
}
[data-theme="light"] .q-pallet-btn {
  background: #ffffff;
  border-color: #e2e8f0;
  color: #334155;
}
[data-theme="light"] .q-pallet-btn:hover {
  background: #f1f5f9;
  color: #0f172a;
}
[data-theme="light"] .nav-controls {
  background: #ffffff;
  border-top-color: #e2e8f0;
}
[data-theme="light"] .btn-nav {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #1e293b;
}
[data-theme="light"] .btn-nav:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}
[data-theme="light"] .quick-reactions-bar {
  background: #f1f5f9;
  border-color: #e2e8f0;
}
[data-theme="light"] .game-result-banner {
  background: #ffffff;
  border-bottom-color: #2563eb;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .grb-text .grb-title {
  color: #0f172a;
}
[data-theme="light"] .grb-text .grb-sub {
  color: #64748b;
}
[data-theme="light"] .grb-filters {
  background: #f1f5f9;
  border-color: #e2e8f0;
}
[data-theme="light"] .grb-filter-btn {
  color: #475569;
}
[data-theme="light"] .explanation-box {
  background: #f0f9ff;
  border-color: #bae6fd;
  border-left-color: #0284c7;
}
[data-theme="light"] .explanation-title {
  color: #0369a1;
}
[data-theme="light"] .explanation-text {
  color: #1e293b;
}
[data-theme="light"] .modal-content {
  background: #ffffff;
  color: #0f172a;
  border-color: #e2e8f0;
}
[data-theme="light"] .stat-card {
  background: #f8fafc;
  border-color: #e2e8f0;
}
[data-theme="light"] .stat-num {
  color: #0f172a;
}
[data-theme="light"] .stat-label {
  color: #64748b;
}
[data-theme="light"] .history-item {
  background: #f8fafc;
  border-color: #e2e8f0;
}
[data-theme="light"] .history-name {
  color: #0f172a;
}
[data-theme="light"] .follow-mode-banner {
  background: linear-gradient(135deg, #eef2ff, #f8fafc);
  border-bottom-color: #6366f1;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.1);
}
[data-theme="light"] .fmb-title {
  color: #1e1b4b;
}
[data-theme="light"] .fmb-name {
  color: #4338ca;
}
[data-theme="light"] .fmb-sub {
  color: #475569;
}
[data-theme="light"] .btn-follow-toggle {
  background: #eef2ff;
  color: #4338ca;
  border-color: #c7d2fe;
}
[data-theme="light"] .btn-follow-toggle:hover {
  background: #4338ca;
  color: white;
}
[data-theme="light"] .btn-follow-toggle.active {
  background: #4338ca;
  color: white;
}
[data-theme="light"] .btn-solo-practice {
  background: linear-gradient(135deg, #d97706, #f59e0b);
  color: white;
}
[data-theme="light"] .btn-flag-q {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #475569;
}
[data-theme="light"] .btn-flag-q:hover,
[data-theme="light"] .btn-flag-q.active {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #b45309;
}
[data-theme="light"] .cursor-tag.live-spectate {
  background: #ffffff !important;
  border-color: #ef4444 !important;
  color: #0f172a !important;
  box-shadow: 0 2px 10px rgba(239, 68, 68, 0.4) !important;
}

/* =======================================================
   TRẢI NGHIỆM NHIỀU NGƯỜI CHƠI: toast, đếm ngược, chat,
   đường đua, chế độ Đồng bộ
   ======================================================= */
.toast-stack {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: min(92vw, 460px);
}
.toast {
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: toastIn 0.28s ease-out;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.toast.out { opacity: 0; transform: translateY(-8px); transition: all 0.3s; }
.toast-ok, .toast-join, .toast-up { border-left-color: var(--success); }
.toast-warn, .toast-lead { border-left-color: var(--warning); }
.toast-danger, .toast-down, .toast-leave { border-left-color: var(--danger); }
.toast-chat { border-left-color: #8b5cf6; }
.toast-chat-self { border-left-color: #64748b; opacity: 0.9; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.net-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10001;
  background: var(--danger);
  color: #fff;
  text-align: center;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 6px 10px;
}

/* Đếm ngược */
.countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 9990;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 23, 0.82);
  backdrop-filter: blur(6px);
}
.countdown-overlay.show { display: flex; }
.countdown-box { text-align: center; }
.countdown-label {
  color: #cbd5e1;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  font-size: 0.95rem;
}
.countdown-num {
  font-size: clamp(6rem, 28vw, 11rem);
  font-weight: 900;
  line-height: 1.1;
  color: #fbbf24;
  text-shadow: 0 0 40px rgba(251, 191, 36, 0.6);
}
.countdown-num.pop { animation: cdPop 0.9s ease-out; }
@keyframes cdPop {
  0% { transform: scale(2.2); opacity: 0; }
  35% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.85; }
}

/* Phòng chờ: chế độ, sẵn sàng, chat */
.waiting-mode-line {
  text-align: center;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.85rem;
  margin: 4px 0 10px;
}
.btn-ready {
  width: 100%;
  margin-top: 14px;
  padding: 12px;
  border-radius: 10px;
  border: 2px solid var(--success);
  background: transparent;
  color: var(--success);
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-ready.on { background: var(--success); color: #fff; }
.btn-ready:active { transform: scale(0.98); }

.waiting-chat {
  margin-top: 16px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-dark);
  overflow: hidden;
}
.chat-log {
  height: 110px;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
}
.chat-line .chat-who { font-weight: 800; margin-right: 6px; }
.chat-line.self .chat-txt { opacity: 0.85; }
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--border-color);
}
.chat-input-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 0.9rem;
}

/* Chat nhanh trong trận */
.quick-chat-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}
.qc-btn {
  background: var(--bg-dark);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 4px 11px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.qc-btn:hover { border-color: var(--primary); transform: translateY(-1px); }
.qc-btn:active { transform: scale(0.95); }

/* Đường đua xếp hạng sống */
.race-track {
  flex-direction: column;
  gap: 4px;
  padding: 8px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
}
.race-lane {
  display: grid;
  grid-template-columns: 26px 110px 1fr 74px;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 6px;
}
.race-lane.me { background: var(--primary-glow); }
.rl-rank { text-align: center; }
.rl-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rl-road {
  position: relative;
  height: 22px;
  border-radius: 11px;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  overflow: hidden;
}
.rl-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  opacity: 0.35;
  transition: width 0.6s ease;
}
.rl-car {
  position: absolute;
  top: 50%;
  margin-top: -11px;
  width: 26px;
  text-align: center;
  font-size: 1.05rem;
  line-height: 22px;
  transition: left 0.6s ease;
}
.rl-flag { position: absolute; right: 4px; top: 50%; margin-top: -9px; font-size: 0.85rem; line-height: 18px; opacity: 0.8; }
.rl-score { text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Chế độ Đồng bộ */
.live-bar {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
}
.live-bar-top {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 0.9rem;
}
.live-msg { flex: 1; text-align: center; color: var(--text-muted); font-size: 0.82rem; font-weight: 700; }
.live-time { font-variant-numeric: tabular-nums; color: #fbbf24; font-size: 1.1rem; }
.live-track { height: 8px; border-radius: 4px; background: var(--border-color); margin-top: 8px; overflow: hidden; }
.live-fill { height: 100%; background: linear-gradient(90deg, #10b981, #fbbf24); transition: width 0.1s linear; }
.live-bar.reveal .live-fill { background: linear-gradient(90deg, #3b82f6, #8b5cf6); }
.live-bar.reveal .live-msg { color: var(--text-main); }

body.live-mode #btnPrevQ,
body.live-mode #btnNextQ,
body.live-mode #btnSubmitExam,
body.live-mode #btnFlagQuestion { display: none; }
body.live-mode .palette-grid .q-pallet-btn { pointer-events: none; }
body.live-game .palette-grid .q-pallet-btn:nth-child(n+16) { display: none; }
body.live-game[data-live-total="20"] .palette-grid .q-pallet-btn:nth-child(n+16):nth-child(-n+20) { display: flex; }
body.live-game[data-live-total="20"] .palette-grid .q-pallet-btn:nth-child(n+21) { display: none; }

@media (max-width: 900px) {
  .race-track { padding: 6px 10px; gap: 2px; }
  .race-lane { grid-template-columns: 20px 104px 1fr 58px; gap: 5px; font-size: 0.72rem; }
  .rl-road { height: 18px; }
  .rl-car { margin-top: -9px; line-height: 18px; font-size: 0.95rem; }
  body.has-race:not(.spectator) .opponents-bar { display: none; }
  .live-msg { font-size: 0.72rem; }
  .live-bar-top { flex-wrap: wrap; }
}

/* Đồng đội, sinh tồn, chọc đối thủ */
.team-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 2px 4px 6px;
}
.tr-bar { height: 10px; border-radius: 5px; background: #ef4444; overflow: hidden; }
.tr-fill { height: 100%; background: #3b82f6; transition: width 0.5s ease; }
.race-lane { cursor: pointer; }
.race-lane.me { cursor: default; }
.race-lane:not(.me):hover { background: var(--bg-card-hover); }
.race-lane.out { opacity: 0.5; }
.race-lane.out .rl-name { text-decoration: line-through; }

/* Khán giả */
body.spectator #btnFlagQuestion,
body.spectator #btnPrevQ,
body.spectator #btnNextQ,
body.spectator .quick-reactions-bar { display: none; }

/* Tiến độ ở sảnh */
.progress-chip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}
.pc-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 700;
}
.pc-due { border-color: var(--warning); color: var(--warning); }
.progress-goal { height: 4px; border-radius: 2px; background: var(--border-color); margin-top: 8px; overflow: hidden; }
.progress-goal-fill { height: 100%; width: 0; background: linear-gradient(90deg, #10b981, #3b82f6); transition: width 0.4s; }

/* Modal ôn tập */
.study-modal { max-width: 860px; width: 96vw; max-height: 90vh; overflow-y: auto; }
.study-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.study-tab {
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-dark);
  color: var(--text-main);
  font-weight: 700;
  cursor: pointer;
}
.study-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.study-pane { display: none; }
.study-pane.active { display: block; }
.study-suggest {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: var(--bg-dark);
  border: 1px solid var(--success);
  font-size: 0.88rem;
}
.study-suggest.warn { border-color: var(--warning); }
.study-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.study-chapter {
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sc-name { font-size: 0.82rem; color: var(--text-muted); min-height: 2.4em; }
.sc-acc { font-size: 0.82rem; font-weight: 700; color: var(--text-muted); }
.sc-acc.good { color: var(--success); }
.sc-acc.mid { color: var(--warning); }
.sc-acc.bad { color: var(--danger); }
.sc-bar { height: 6px; border-radius: 3px; background: var(--border-color); overflow: hidden; }
.sc-fill { height: 100%; background: var(--text-muted); }
.sc-fill.good { background: var(--success); }
.sc-fill.mid { background: var(--warning); }
.sc-fill.bad { background: var(--danger); }
.sc-actions { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.study-search-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; flex-wrap: wrap; }
.study-search-row input, .study-search-row select {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-dark);
  color: var(--text-main);
  font-size: 0.9rem;
}
.study-search-row input { flex: 1; min-width: 160px; }
.study-search-row select { max-width: 100%; }
.study-count { color: var(--text-muted); font-size: 0.8rem; font-weight: 700; }
.study-empty { text-align: center; color: var(--text-muted); padding: 20px; }
.study-q {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-dark);
  margin-bottom: 8px;
  padding: 8px 12px;
}
.study-q summary { cursor: pointer; font-size: 0.9rem; line-height: 1.5; }
.sq-id { font-weight: 800; margin-right: 6px; }
.sq-ch, .sq-crit {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 6px;
  margin-right: 6px;
  background: var(--border-color);
}
.sq-crit { background: var(--danger); color: #fff; }
.sq-opts { margin: 10px 0 8px 22px; display: flex; flex-direction: column; gap: 4px; font-size: 0.88rem; }
.sq-opts .sq-correct { color: var(--success); font-weight: 700; }
.sq-exp { font-size: 0.84rem; color: var(--text-muted); border-left: 3px solid var(--primary); padding-left: 10px; margin-top: 6px; }
.sq-img { max-width: 100%; max-height: 220px; border-radius: 8px; margin-top: 8px; }
.sq-more { width: 100%; margin-top: 6px; }
.study-level { text-align: center; padding: 10px 0 14px; display: flex; flex-direction: column; gap: 6px; }
.sl-big { font-size: 1.6rem; font-weight: 900; }
.sl-sub { color: var(--text-muted); font-size: 0.85rem; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.badge-item {
  text-align: center;
  padding: 12px 8px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-dark);
  opacity: 0.6;
}
.badge-item.on { opacity: 1; border-color: var(--success); }
.bi-icon { font-size: 1.8rem; }
.bi-name { font-weight: 800; font-size: 0.9rem; }
.bi-desc { font-size: 0.75rem; color: var(--text-muted); margin: 2px 0 4px; }
.bi-state { font-size: 0.75rem; font-weight: 700; }

@media (max-width: 600px) {
  /* Huy hiệu người chọn nằm dưới chữ đáp án để chữ không bị bóp hẹp */
  .option-card { flex-wrap: wrap; }
  .option-card .opt-text { flex: 1 1 55%; min-width: 0; }
  .option-card .opt-opponents-tag { flex-basis: 100%; justify-content: flex-start; }
}

/* Tinh chỉnh trải nghiệm */
.waiting-mode-rules {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.5;
  margin: -4px 0 12px;
  padding: 0 8px;
}
.live-bar.urgent { border-color: var(--danger); animation: urgentPulse 0.6s ease-in-out infinite alternate; }
.live-bar.urgent .live-time { color: var(--danger); }
.live-bar.urgent .live-fill { background: var(--danger); }
@keyframes urgentPulse {
  from { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
  to { box-shadow: 0 0 14px 2px rgba(239, 68, 68, 0.55); }
}
@media (prefers-reduced-motion: reduce) {
  .live-bar.urgent { animation: none; }
  .countdown-num.pop, .toast { animation: none; }
}

/* ---- Sinh tồn: lớp phủ, theo dõi người sống, danh sách câu ---- */
.live-flash {
  position: fixed; inset: 0; z-index: 9000; display: flex; align-items: center; justify-content: center;
  background: rgba(2, 6, 23, 0.72); backdrop-filter: blur(3px); animation: lfIn 0.25s ease-out;
}
.live-flash .lf-card {
  max-width: min(440px, 90vw); text-align: center; padding: 26px 24px; border-radius: 18px;
  background: var(--bg-card); border: 1px solid var(--border-color); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}
.live-flash.out .lf-card { border-color: #ef4444; }
.live-flash.win .lf-card { border-color: #fbbf24; }
.live-flash .lf-icon { font-size: 3.4rem; line-height: 1; margin-bottom: 8px; }
.live-flash .lf-text { font-size: 1.15rem; font-weight: 800; color: var(--text-main); }
.live-flash .lf-alive { margin-top: 12px; font-size: 0.9rem; color: var(--text-muted); }
.live-flash .lf-hint { margin-top: 10px; font-size: 0.8rem; color: var(--text-muted); }
@keyframes lfIn { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: scale(1); } }

.live-watch {
  margin-top: 8px; padding: 6px 10px; border-radius: 8px; font-size: 0.78rem; line-height: 1.6;
  background: rgba(139, 92, 246, 0.12); border: 1px dashed rgba(139, 92, 246, 0.5); color: var(--text-main);
}
.live-watch .lw-p { display: inline-block; margin-right: 10px; white-space: nowrap; }

.race-lane.offline { opacity: 0.6; }
.q-pallet-btn.skipped { opacity: 0.35; }
body.live-mode.eliminated .palette-grid .q-pallet-btn { pointer-events: auto; }

@media (max-width: 600px) {
  .live-bar-top { flex-wrap: wrap; row-gap: 4px; }
  .live-bar-top .live-msg { order: 3; flex: 1 1 100%; text-align: left; }
}
