/* optional: giảm CLS khi font tải xong (đổi metrics ít hơn swap) */
@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700;800&family=JetBrains+Mono:wght@600;700&display=optional');

* { box-sizing: border-box; }

/* =====================================================
   THEME — Dark (mặc định)
   ===================================================== */
:root {
  --primary:        #60a5fa;
  --primary-glow:   #3b82f6;
  --primary-dark:   #2563eb;
  --accent:         #a78bfa;
  --accent-glow:    #8b5cf6;
  --cyan:           #22d3ee;

  --text:           #e2e8f0;
  --text-strong:    #f1f5f9;
  --muted:          #94a3b8;
  --border:         rgba(148, 163, 184, 0.18);

  --card:           rgba(40, 52, 82, 0.55);
  --card-border:    rgba(180, 195, 220, 0.18);

  --surface-1:      rgba(40, 52, 82, 0.55);   /* card chính */
  --surface-2:      rgba(20, 28, 50, 0.6);    /* input, nested */
  --surface-3:      rgba(15, 23, 42, 0.42);   /* contest-block, timing-opt */
  --surface-strong: rgba(30, 41, 59, 0.7);    /* progress-bar bg, btn--ghost */

  --success:        #34d399;
  --success-bg:     rgba(52, 211, 153, 0.12);
  --danger:         #f87171;
  --danger-bg:      rgba(248, 113, 113, 0.12);
  --warning:        #fbbf24;
  --warning-bg:     rgba(251, 191, 36, 0.12);

  --header-bg:
    linear-gradient(135deg, rgba(30, 41, 90, 0.7), rgba(15, 23, 42, 0.6));
  --header-overlay:
    radial-gradient(circle at 0% 0%, rgba(96, 165, 250, 0.25), transparent 50%),
    radial-gradient(circle at 100% 100%, rgba(167, 139, 250, 0.18), transparent 60%);
  --header-title-gradient: linear-gradient(135deg, #fff 0%, #c7d2fe 100%);
  --header-nav-color: #cbd5e1;

  --modal-overlay: rgba(2, 6, 23, 0.7);
  --modal-content:
    linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));

  --body-bg:
    linear-gradient(135deg, #1a2238 0%, #232b4a 50%, #2a3050 100%);
  --aurora:
    radial-gradient(50% 40% at 20% 25%, rgba(96, 165, 250, 0.42), transparent 70%),
    radial-gradient(45% 35% at 80% 20%, rgba(167, 139, 250, 0.38), transparent 70%),
    radial-gradient(55% 45% at 60% 85%, rgba(56, 189, 248, 0.28), transparent 70%),
    radial-gradient(40% 30% at 15% 90%, rgba(244, 114, 182, 0.20), transparent 70%);
  --dot-color: rgba(255, 255, 255, 0.04);
  --dot-blend: screen;

  --table-th-bg: rgba(15, 23, 42, 0.6);
  --table-row-hover: rgba(96, 165, 250, 0.06);
  --scrollbar-track: rgba(15, 23, 42, 0.4);

  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5), 0 6px 14px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* =====================================================
   THEME — Light
   ===================================================== */
[data-theme="light"] {
  --primary:        #2563eb;
  --primary-glow:   #3b82f6;
  --primary-dark:   #1d4ed8;
  --accent:         #7c3aed;
  --accent-glow:    #8b5cf6;
  --cyan:           #0891b2;

  --text:           #1e293b;
  --text-strong:    #0f172a;
  --muted:          #64748b;
  --border:         rgba(15, 23, 42, 0.12);

  --card:           rgba(255, 255, 255, 0.78);
  --card-border:    rgba(15, 23, 42, 0.08);

  --surface-1:      rgba(255, 255, 255, 0.78);
  --surface-2:      rgba(255, 255, 255, 0.95);
  --surface-3:      rgba(241, 245, 249, 0.75);
  --surface-strong: rgba(226, 232, 240, 0.85);

  --success:        #059669;
  --success-bg:     rgba(16, 185, 129, 0.12);
  --danger:         #dc2626;
  --danger-bg:      rgba(220, 38, 38, 0.10);
  --warning:        #d97706;
  --warning-bg:     rgba(245, 158, 11, 0.14);

  --header-bg:
    linear-gradient(135deg, rgba(37, 99, 235, 0.95), rgba(29, 78, 216, 0.95));
  --header-overlay:
    radial-gradient(circle at 80% 0%, rgba(147, 197, 253, 0.4), transparent 60%);
  --header-title-gradient: linear-gradient(135deg, #fff 0%, #e0e7ff 100%);
  --header-nav-color: rgba(255, 255, 255, 0.9);

  --modal-overlay: rgba(15, 23, 42, 0.4);
  --modal-content:
    linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.98));

  --body-bg:
    linear-gradient(135deg, #eef2ff 0%, #e0e7ff 50%, #dbeafe 100%);
  --aurora:
    radial-gradient(50% 40% at 20% 25%, rgba(96, 165, 250, 0.28), transparent 70%),
    radial-gradient(45% 35% at 80% 20%, rgba(167, 139, 250, 0.26), transparent 70%),
    radial-gradient(55% 45% at 60% 85%, rgba(56, 189, 248, 0.22), transparent 70%),
    radial-gradient(40% 30% at 15% 90%, rgba(244, 114, 182, 0.18), transparent 70%);
  --dot-color: rgba(15, 23, 42, 0.05);
  --dot-blend: multiply;

  --table-th-bg: rgba(248, 250, 252, 0.85);
  --table-row-hover: rgba(96, 165, 250, 0.08);
  --scrollbar-track: rgba(15, 23, 42, 0.08);

  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.18), 0 6px 14px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 10px 28px rgba(15, 23, 42, 0.10), 0 2px 6px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 4px 14px rgba(15, 23, 42, 0.08);
}

/* =====================================================
   BASE
   ===================================================== */
html, body {
  margin: 0; padding: 0;
  color: var(--text);
  font-family: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
  background: var(--body-bg);
  background-attachment: fixed;
  overflow-x: hidden;
  transition: background 0.4s ease, color 0.3s ease;
}

body::before {
  content: "";
  position: fixed; inset: -20%;
  background: var(--aurora);
  filter: blur(40px);
  z-index: 0;
  pointer-events: none;
  animation: auroraDrift 28s ease-in-out infinite alternate;
}
@keyframes auroraDrift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(-3%, 2%, 0) scale(1.05); }
  100% { transform: translate3d(2%, -3%, 0) scale(1.02); }
}

body::after {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  background-image: radial-gradient(var(--dot-color) 1px, transparent 1px);
  background-size: 22px 22px;
  z-index: 0;
  mix-blend-mode: var(--dot-blend);
}

body > * { position: relative; z-index: 1; }

::selection { background: rgba(96, 165, 250, 0.4); color: var(--text-strong); }

a { color: var(--primary); text-decoration: none; transition: color 0.15s, opacity 0.15s; }
a:hover { color: var(--primary-glow); text-decoration: underline; }

.container { max-width: 880px; margin: 0 auto; padding: 24px 16px; }
.container--wide { max-width: 1200px; }

/* Trang quản trị: giảm CLS khi tbody bảng được render sau fetch (ô trống → nhiều hàng) */
.container--wide .tab-panel > .card > .table-wrap {
  min-height: 220px;
}

/* Đã có mật khẩu trong session: hiện khu admin ngay từ frame đầu, tránh nhảy form đăng nhập → bảng */
html.admin-session-pending #loginSection {
  display: none !important;
}
html.admin-session-pending #adminArea {
  display: block !important;
}
html.admin-session-pending .header #logoutLink,
html.admin-session-pending .header #changePwdLink {
  display: inline !important;
}

/* =====================================================
   HEADER + Theme toggle
   ===================================================== */
.header {
  background: var(--header-bg);
  color: #fff;
  padding: 20px 26px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.10);
  transition: background 0.4s ease;
}
.header::after {
  content: "";
  position: absolute; inset: 0;
  background: var(--header-overlay);
  pointer-events: none;
}
.header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.3px;
  position: relative;
  background: var(--header-title-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.header .nav { position: relative; display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.header .nav a {
  color: var(--header-nav-color);
  margin-left: 14px;
  font-size: 14px;
  opacity: 0.92;
}
.header .nav a:hover { color: #fff; opacity: 1; }

/* Theme toggle button */
.theme-toggle {
  position: relative;
  margin-left: 10px;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  line-height: 1;
  transition: transform 0.25s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  backdrop-filter: blur(6px);
}
.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.20);
  border-color: rgba(255, 255, 255, 0.45);
  transform: rotate(20deg) scale(1.05);
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.25);
}
.theme-toggle:active { transform: rotate(0deg) scale(0.95); }

/* =====================================================
   CARD (Glassmorphism)
   ===================================================== */
.card {
  background: var(--card);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border-radius: 18px;
  padding: 26px;
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-md);
  position: relative;
  transition: border-color 0.25s, box-shadow 0.25s, background 0.3s;
}
.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, rgba(255,255,255,0.20), rgba(255,255,255,0) 60%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
  pointer-events: none;
}
.card + .card { margin-top: 16px; }

h2 {
  margin: 0 0 16px;
  font-size: 20px;
  color: var(--text-strong);
  font-weight: 700;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--text);
}

/* =====================================================
   FORM CONTROLS
   ===================================================== */
input[type="text"],
input[type="tel"],
input[type="number"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text-strong);
  background: var(--surface-2);
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.7; }

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.20), 0 0 12px rgba(96, 165, 250, 0.18);
}

textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: 14px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 180px; }

/* =====================================================
   BUTTONS
   ===================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 20px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: linear-gradient(135deg, var(--primary-glow), var(--primary-dark));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.18s, filter 0.15s;
  font-family: inherit;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35), inset 0 1px 0 rgba(255,255,255,0.15);
  position: relative;
  overflow: hidden;
}
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.18) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.5s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(59, 130, 246, 0.5), inset 0 1px 0 rgba(255,255,255,0.2); }
.btn:hover::after { transform: translateX(100%); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn--ghost {
  background: var(--surface-strong);
  color: var(--text);
  border-color: var(--border);
  box-shadow: none;
}
.btn--ghost:hover { background: var(--surface-strong); filter: brightness(1.08); border-color: var(--primary); }

.btn--success { background: linear-gradient(135deg, #10b981, #059669); box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4); }
.btn--success:hover { box-shadow: 0 8px 22px rgba(16, 185, 129, 0.55); }

.btn--danger { background: linear-gradient(135deg, #ef4444, #b91c1c); box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4); }
.btn--danger:hover { box-shadow: 0 8px 22px rgba(239, 68, 68, 0.55); }

.btn--warning { background: linear-gradient(135deg, #f59e0b, #b45309); box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4); }
.btn--warning:hover { box-shadow: 0 8px 22px rgba(245, 158, 11, 0.55); }

.btn--sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }

.share-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.share-actions .btn { padding: 4px 8px; font-size: 12px; }

.btn-group { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

.muted { color: var(--muted); font-size: 14px; }

.error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid currentColor;
  padding: 12px 14px;
  border-radius: 10px;
  margin: 10px 0;
  font-size: 14px;
  backdrop-filter: blur(6px);
}

.success-box {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid currentColor;
  padding: 12px 14px;
  border-radius: 10px;
  margin: 10px 0;
  font-size: 14px;
  backdrop-filter: blur(6px);
}

/* =====================================================
   QUIZ
   ===================================================== */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

/* Timer LED — luôn giữ tông tối kể cả theme sáng (đặc trưng digital display) */
.timer {
  font-family: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #bae6fd;
  background: linear-gradient(145deg, #050816, #0c1326);
  padding: 12px 24px;
  border-radius: 14px;
  border: 1px solid rgba(96, 165, 250, 0.35);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 10px rgba(96, 165, 250, 0.7), 0 0 22px rgba(59, 130, 246, 0.5);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 -2px 8px rgba(0, 0, 0, 0.5),
    0 0 24px rgba(59, 130, 246, 0.25),
    0 8px 22px rgba(0, 0, 0, 0.3);
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.timer::before {
  content: "";
  display: inline-block;
  width: 9px; height: 9px;
  background: var(--cyan);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--cyan), 0 0 16px rgba(34, 211, 238, 0.7);
  animation: tick 1s steps(2, end) infinite;
}
@keyframes tick {
  0%, 50%   { opacity: 1; }
  51%, 100% { opacity: 0.2; }
}
.timer.timer--low {
  color: #fecaca;
  background: linear-gradient(145deg, #160708, #3c0a0e);
  border-color: rgba(248, 113, 113, 0.5);
  text-shadow: 0 0 10px rgba(248, 113, 113, 0.8), 0 0 22px rgba(239, 68, 68, 0.6);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    inset 0 -2px 8px rgba(0, 0, 0, 0.5),
    0 0 28px rgba(220, 38, 38, 0.5);
  animation: lowPulse 1.1s ease-in-out infinite;
}
.timer.timer--low::before {
  background: #f87171;
  box-shadow: 0 0 8px #f87171, 0 0 18px rgba(248, 113, 113, 0.8);
}
@keyframes lowPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.03); }
}

.progress-bar {
  background: var(--surface-strong);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
  margin-top: 8px;
  border: 1px solid var(--border);
}
.progress-bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent), var(--cyan));
  background-size: 200% 100%;
  animation: progressShine 3s linear infinite;
  transition: width 0.3s ease;
  box-shadow: 0 0 12px rgba(96, 165, 250, 0.5);
}
@keyframes progressShine {
  0%   { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

.q-number { font-size: 14px; color: var(--muted); margin-bottom: 8px; }

.q-text {
  font-size: 19px;
  font-weight: 600;
  margin: 8px 0 18px;
  line-height: 1.5;
  color: var(--text-strong);
}

.answers { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }

.answer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-3);
  cursor: pointer;
  transition: all 0.18s ease;
  position: relative;
  overflow: hidden;
  color: var(--text);
}
.answer:hover {
  border-color: var(--primary);
  transform: translateX(3px);
  filter: brightness(1.05);
}
.answer.selected {
  border-color: var(--primary);
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.22), rgba(139, 92, 246, 0.18));
  box-shadow: 0 0 0 1px var(--primary), 0 6px 18px rgba(96, 165, 250, 0.25);
}
.answer input[type="radio"] {
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
  width: 18px; height: 18px;
}
.answer .answer-letter {
  font-weight: 700;
  color: var(--primary);
  min-width: 22px;
}

.skipped-banner {
  background: var(--warning-bg);
  color: var(--warning);
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 14px;
  border: 1px solid currentColor;
  backdrop-filter: blur(6px);
}
.skipped-banner b { color: inherit; filter: brightness(1.15); }

.chip-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--warning);
  background: var(--warning-bg);
  color: var(--warning);
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.chip:hover { filter: brightness(1.12); transform: translateY(-1px); }
.chip.chip--current {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border-color: #f59e0b;
  color: #fff;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.45);
}

/* =====================================================
   RESULT
   ===================================================== */
.result-card { text-align: center; padding: 48px 24px; }
.result-card .score {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 84px;
  font-weight: 800;
  line-height: 1;
  margin: 16px 0 8px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 50%, var(--cyan) 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 24px rgba(96, 165, 250, 0.45));
  animation: scoreShine 4s ease-in-out infinite alternate;
}
@keyframes scoreShine {
  0%   { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}
.result-card .score-text { font-size: 16px; color: var(--muted); }

/* =====================================================
   TABLE
   ===================================================== */
.table-wrap { overflow-x: auto; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
th {
  background: var(--table-th-bg);
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
tr { transition: background 0.15s; }
tr:hover td { background: var(--table-row-hover); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.rank {
  display: inline-block;
  width: 28px; height: 28px;
  line-height: 28px;
  text-align: center;
  border-radius: 50%;
  background: var(--surface-strong);
  font-weight: 700;
  font-size: 12px;
  color: var(--text);
}
.rank--1 { background: linear-gradient(135deg, #fbbf24, #d97706); color: #fff; box-shadow: 0 0 12px rgba(251, 191, 36, 0.4); }
.rank--2 { background: linear-gradient(135deg, #cbd5e1, #64748b); color: #fff; }
.rank--3 { background: linear-gradient(135deg, #f59e0b, #b45309); color: #fff; }

/* =====================================================
   TABS
   ===================================================== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab {
  padding: 11px 20px;
  cursor: pointer;
  border: none;
  background: transparent;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--text-strong); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  text-shadow: 0 0 12px rgba(96, 165, 250, 0.4);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================
   QUESTION ITEM (admin)
   ===================================================== */
.q-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--surface-3);
  transition: border-color 0.15s, background 0.15s;
}
.q-item:hover { border-color: var(--primary); filter: brightness(1.05); }
.q-item-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.q-item-title { font-weight: 600; flex: 1; color: var(--text-strong); }
.q-item-answers { margin: 6px 0 0; padding-left: 22px; font-size: 14px; }
.q-item-answers li.correct { color: var(--success); font-weight: 600; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 12px;
  backdrop-filter: blur(8px);
  transition: transform 0.15s, border-color 0.15s;
}
.stat:hover { transform: translateY(-2px); border-color: var(--primary); }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-strong);
  margin-top: 4px;
}

.bulk-help {
  background: var(--surface-3);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--muted);
  margin: 8px 0 12px;
  white-space: pre-wrap;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  border: 1px solid var(--border);
}

@media (max-width: 600px) {
  .container { padding: 16px 10px; }
  .card { padding: 18px 14px; }
  .q-text { font-size: 16px; }
  .timer { font-size: 24px; padding: 8px 16px; letter-spacing: 1px; }
  .header h1 { font-size: 17px; }
  .result-card .score { font-size: 64px; }
}

/* =====================================================
   CONTEST LIST
   ===================================================== */
.contest-list {
  display: grid;
  gap: 14px;
  grid-template-columns: 1fr;
  margin-top: 8px;
}
@media (min-width: 640px) { .contest-list { grid-template-columns: repeat(2, 1fr); } }

.contest-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  background: var(--surface-3);
  backdrop-filter: blur(10px);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.contest-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.10), transparent 50%);
  pointer-events: none;
  opacity: 0; transition: opacity 0.2s;
}
.contest-card:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 24px rgba(96, 165, 250, 0.2);
  transform: translateY(-3px);
}
.contest-card:hover::before { opacity: 1; }
.contest-card--disabled { opacity: .5; cursor: not-allowed; }
.contest-card--disabled:hover { transform: none; box-shadow: none; border-color: var(--border); }
.contest-card-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--primary);
}
.contest-card-meta {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  font-size: 13px; color: var(--muted); margin-bottom: 14px;
}
.contest-card-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; }

.contest-block {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-3);
}
.contest-block > summary {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 700;
  color: var(--primary);
  user-select: none;
  list-style: none;
}
.contest-block > summary::after {
  content: "▸";
  float: right; transition: transform 0.2s;
  color: var(--muted);
}
.contest-block[open] > summary::after { transform: rotate(90deg); }
.contest-block .contest-text {
  padding: 0 16px 14px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
}

/* BADGE */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge--ok  { background: var(--success-bg); color: var(--success); border: 1px solid currentColor; }
.badge--off { background: var(--danger-bg); color: var(--danger); border: 1px solid currentColor; }

/* BANK SUBTABS */
.bank-subtabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 12px 0 16px;
  overflow-x: auto;
}
.bank-subtab {
  padding: 8px 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color 0.15s;
}
.bank-subtab:hover { color: var(--text-strong); }
.bank-subtab.active { color: var(--primary); border-bottom-color: var(--primary); }
.bank-sub-panel { display: none; }
.bank-sub-panel.active { display: block; }

/* FORM GRID */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 500px) { .grid-2 { grid-template-columns: 1fr; } }

/* TIMING MODE PICKER (legacy) */
.timing-mode-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 500px) { .timing-mode-pick { grid-template-columns: 1fr; } }
.timing-opt {
  display: flex; gap: 10px; align-items: flex-start;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  transition: all .15s;
  margin: 0;
  font-weight: normal;
  background: var(--surface-3);
}
.timing-opt:has(input:checked) {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.15);
  box-shadow: 0 4px 14px rgba(96, 165, 250, 0.2);
}
.timing-opt input { margin: 4px 0 0; accent-color: var(--primary); }
.timing-opt b { color: var(--primary); }

/* =====================================================
   MODAL
   ===================================================== */
.modal {
  position: fixed; inset: 0;
  background: var(--modal-overlay);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto;
  padding: 30px 12px;
  animation: modalFade 0.2s ease;
}
@keyframes modalFade { from { opacity: 0; } to { opacity: 1; } }
.modal-content {
  background: var(--modal-content);
  backdrop-filter: blur(20px) saturate(140%);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  max-width: 820px;
  width: 100%;
  padding: 26px;
  box-shadow: var(--shadow-lg);
  color: var(--text);
  animation: modalSlide 0.25s ease;
}
@keyframes modalSlide { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; color: var(--primary); font-size: 20px; }

.detail-meta {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 18px;
  font-size: 14px;
}
.detail-meta b { color: var(--primary); font-weight: 600; }
.big-score { color: var(--primary); font-weight: 700; font-size: 18px; }
.detail-body { display: flex; flex-direction: column; gap: 12px; }

.d-q {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 12px;
  padding: 14px 16px;
  background: var(--surface-3);
}
.d-q--ok    { border-left-color: var(--success); background: var(--success-bg); }
.d-q--bad   { border-left-color: var(--danger);  background: var(--danger-bg); }
.d-q--blank { border-left-color: var(--muted);   background: var(--surface-strong); }
.d-q-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.d-q-num { font-weight: 700; color: var(--primary); font-size: 14px; }
.d-q-text { font-weight: 600; margin-bottom: 10px; line-height: 1.5; color: var(--text-strong); }
.d-q-ans { display: flex; flex-direction: column; gap: 6px; }
.d-ans {
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 14px;
  color: var(--text);
}
.d-ans--correct { background: var(--success-bg); border-color: var(--success); color: var(--success); font-weight: 600; }
.d-ans--wrong   { background: var(--danger-bg);  border-color: var(--danger);  color: var(--danger); }
.d-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.d-badge--ok    { background: var(--success-bg); color: var(--success); border: 1px solid currentColor; }
.d-badge--bad   { background: var(--danger-bg);  color: var(--danger);  border: 1px solid currentColor; }
.d-badge--blank { background: var(--surface-strong); color: var(--muted); border: 1px solid var(--border); }

@media (max-width: 600px) {
  .detail-meta { grid-template-columns: 1fr; }
  .modal-content { padding: 18px; }
  .modal-header h2 { font-size: 17px; }
}

/* =====================================================
   ANTI-CHEAT
   ===================================================== */
.ac-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid currentColor;
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(6px);
}
.ac-status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor, 0 0 12px currentColor;
  animation: livePulse 1.2s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.85); }
}
.ac-status--alert {
  background: var(--danger-bg);
  color: var(--danger);
  animation: alertPulse 0.8s ease-in-out 3;
}
@keyframes alertPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.04); }
}

.modal-content.ac-warn {
  max-width: 520px;
  text-align: center;
  border: 2px solid rgba(251, 191, 36, 0.5);
  box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.3), var(--shadow-lg), 0 0 40px rgba(251, 191, 36, 0.25);
}
.ac-warn-icon {
  font-size: 60px;
  line-height: 1;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 16px rgba(251, 191, 36, 0.6));
  animation: warnBounce 0.6s ease;
}
@keyframes warnBounce {
  0%   { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}
.ac-warn h2 {
  text-align: center;
  color: var(--warning);
  margin: 4px 0 8px;
}
.ac-warn-msg {
  font-size: 15px;
  line-height: 1.55;
  margin: 6px 0 14px;
  color: var(--text);
}

/* User-select bị khoá khi đang giám sát */
body.ac-locked {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
body.ac-locked input,
body.ac-locked textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: linear-gradient(180deg, rgba(96, 165, 250, 0.45), rgba(139, 92, 246, 0.45)); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, rgba(96, 165, 250, 0.7), rgba(139, 92, 246, 0.7)); }

/* PRINT */
@media print {
  body * { visibility: hidden; }
  .modal, .modal-content, .modal-content * { visibility: visible; }
  .modal { position: static; background: #fff; padding: 0; }
  .modal-content { box-shadow: none; max-width: none; background: #fff; color: #000; }
  .modal-content * { color: #000 !important; background: #fff !important; }
  .modal-header button, #closeDetail, #printDetail, #closeDetailBottom { display: none !important; }
}
