/* =============================================================================
   OnlineExam -- Design System
   - CSS variables (light + dark)
   - Typography, color, spacing, radius, shadows, motion
   - Reusable component classes (.btn, .input, .card, .badge, .field, etc.)
   - Exam-engine specific styles
   ============================================================================= */

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

/* -- Design tokens -------------------------------------------------------- */
:root {
  /* Brand */
  --brand-50:  #eef2ff;
  --brand-100: #e0e7ff;
  --brand-200: #c7d2fe;
  --brand-400: #818cf8;
  --brand-500: #6366f1;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;
  --brand-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
  --brand-grad-soft: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 50%, #faf5ff 100%);

  /* Surfaces */
  --bg:        #f8fafc;
  --bg-soft:   #f1f5f9;
  --surface:   #ffffff;
  --surface-2: #f8fafc;
  --border:    #e5e7eb;
  --border-strong: #cbd5e1;

  /* Text */
  --text:      #0f172a;
  --text-muted:#64748b;
  --text-dim:  #94a3b8;

  /* Semantic */
  --success:   #10b981;
  --success-bg:#ecfdf5;
  --warn:      #f59e0b;
  --warn-bg:   #fffbeb;
  --danger:    #ef4444;
  --danger-bg: #fef2f2;
  --info:      #0ea5e9;
  --info-bg:   #f0f9ff;

  /* Radii */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-2xl: 28px;
  --r-pill: 999px;

  /* Shadows (layered, modern) */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-sm: 0 2px 4px rgba(15, 23, 42, .05), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 4px 10px -2px rgba(15, 23, 42, .06), 0 2px 4px -1px rgba(15, 23, 42, .04);
  --shadow-lg: 0 20px 40px -12px rgba(15, 23, 42, .15), 0 8px 16px -8px rgba(15, 23, 42, .08);
  --shadow-glow: 0 0 0 4px rgba(99, 102, 241, .12);
  --shadow-glow-danger: 0 0 0 4px rgba(239, 68, 68, .12);

  /* Spacing */
  --s-1: .25rem; --s-2: .5rem; --s-3: .75rem; --s-4: 1rem;
  --s-5: 1.25rem; --s-6: 1.5rem; --s-8: 2rem; --s-10: 2.5rem;

  /* Motion */
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --t-fast: 140ms;
  --t-mid: 220ms;

  /* Sizes */
  --header-h: 64px;
  --nav-h: 72px;
}

/* -- Dark mode ------------------------------------------------------------ */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0b1020;
    --bg-soft:   #0f172a;
    --surface:   #111827;
    --surface-2: #0f172a;
    --border:    #1f2937;
    --border-strong: #334155;
    --text:      #e2e8f0;
    --text-muted:#94a3b8;
    --text-dim:  #64748b;
    --brand-grad-soft: linear-gradient(135deg, #1e1b4b 0%, #2e1065 50%, #3b0764 100%);
    --shadow-md: 0 4px 10px -2px rgba(0, 0, 0, .35), 0 2px 4px -1px rgba(0, 0, 0, .25);
    --shadow-lg: 0 20px 40px -12px rgba(0, 0, 0, .55), 0 8px 16px -8px rgba(0, 0, 0, .35);
    --success-bg:#053024;
    --warn-bg:   #422006;
    --danger-bg: #450a0a;
    --info-bg:   #082f49;
  }
  .opt-row:hover { background: #1a2235 !important; }
}

/* Manual dark toggle support */
html[data-theme="dark"] {
  color-scheme: dark;
}

/* -- Reset --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  font-size: 15px; line-height: 1.55;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1,h2,h3,h4 { margin: 0; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0; }
a { color: var(--brand-600); text-decoration: none; transition: color var(--t-fast) var(--ease-out); }
a:hover { color: var(--brand-700); }
small { font-size: .82rem; color: var(--text-muted); }
.mono, code, kbd, pre { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }

::selection { background: var(--brand-200); color: var(--brand-700); }

button { font-family: inherit; cursor: pointer; }

input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* Focus rings */
:focus-visible { outline: none; box-shadow: var(--shadow-glow); border-radius: var(--r-sm); }

.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: .875rem; }
.dim { color: var(--text-dim); }
.center { text-align: center; }
.gap-1 { gap: var(--s-1); } .gap-2 { gap: var(--s-2); }
.gap-3 { gap: var(--s-3); } .gap-4 { gap: var(--s-4); }
.row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--s-3); }

/* Layout helpers */
.container { max-width: 1120px; margin: 0 auto; padding: 0 var(--s-4); }
.container-sm { max-width: 720px; margin: 0 auto; padding: 0 var(--s-4); }
.section { padding: var(--s-8) 0; }

/* =============================================================================
   COMPONENTS
   ============================================================================= */

/* -- App shell / chrome -------------------------------------------------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  height: var(--header-h);
  padding: 0 var(--s-5);
  background: color-mix(in oklab, var(--surface) 80%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.app-brand {
  display: flex; align-items: center; gap: var(--s-3);
  font-weight: 700; letter-spacing: -.02em; font-size: 1rem;
  color: var(--text);
}
.app-brand .logo-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 14px;
  box-shadow: 0 4px 10px -3px rgba(99, 102, 241, .4);
}
.app-brand .wordmark { background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.app-header-actions { display: flex; align-items: center; gap: var(--s-4); }

/* -- Auth screen --------------------------------------------------------- */
.auth-shell {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: var(--s-6);
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(139, 92, 246, .18), transparent 60%),
    radial-gradient(700px 400px at -10% 110%, rgba(99, 102, 241, .15), transparent 60%),
    var(--bg);
}
.auth-card {
  position: relative; overflow: hidden;
  width: 100%; max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  padding: var(--s-8);
  box-shadow: var(--shadow-lg);
  animation: rise var(--t-mid) var(--ease-out) both;
}
.auth-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--brand-grad);
}
.auth-brand { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-6); }
.auth-brand .logo-mark { width: 40px; height: 40px; border-radius: 11px; font-size: 16px; }
.auth-title { font-size: 1.5rem; font-weight: 700; margin: var(--s-2) 0 var(--s-1); }
.auth-sub   { color: var(--text-muted); margin-bottom: var(--s-6); font-size: .95rem; }
.auth-footer { margin-top: var(--s-6); display: flex; justify-content: space-between; font-size: .85rem; color: var(--text-muted); }
.auth-footer a { color: var(--text-muted); }
.auth-footer a:hover { color: var(--brand-600); }

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

/* -- Cards ---------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out);
}
.card.elevated { box-shadow: var(--shadow-md); }
.card.interactive { cursor: pointer; }
.card.interactive:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); border-color: var(--border-strong); }
.card-title { font-weight: 600; margin-bottom: var(--s-1); }
.card-meta  { font-size: .8rem; color: var(--text-muted); }

/* Stat card */
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-5);
}
.stat-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.85rem; font-weight: 700; letter-spacing: -.02em; margin-top: var(--s-1); font-variant-numeric: tabular-nums; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s-3); }

/* -- Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: 11px 18px; min-height: 44px;
  border: 1px solid transparent; border-radius: var(--r-md);
  font-weight: 600; font-size: .9375rem; line-height: 1;
  white-space: nowrap; user-select: none;
  background: var(--surface); color: var(--text);
  transition: background var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out), box-shadow var(--t-fast) var(--ease-out);
}
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 7px 12px; font-size: .8125rem; border-radius: var(--r-sm); }
.btn.lg { min-height: 52px; padding: 14px 22px; font-size: 1rem; border-radius: var(--r-lg); }

.btn-primary {
  color: #fff; background: var(--brand-grad);
  box-shadow: 0 4px 14px -4px rgba(99, 102, 241, .55);
}
.btn-primary:hover { box-shadow: 0 8px 22px -6px rgba(99, 102, 241, .55), 0 0 0 1px rgba(255,255,255,.05) inset; filter: brightness(1.05); }
.btn-primary:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; filter: none; box-shadow: none; }

.btn-outline {
  background: transparent; color: var(--brand-600);
  border-color: var(--brand-200);
}
.btn-outline:hover { background: var(--brand-50); border-color: var(--brand-400); }

.btn-secondary {
  background: var(--surface-2); color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-soft); border-color: var(--border-strong); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-soft); color: var(--text); }

.btn-success { color: #fff; background: linear-gradient(135deg, #059669, #10b981); }
.btn-success:hover { filter: brightness(1.05); }
.btn-danger  { color: #fff; background: linear-gradient(135deg, #dc2626, #ef4444); }
.btn-danger:hover  { filter: brightness(1.05); }
.btn-warning { color: #78350f; background: var(--warn-bg); border-color: #fbbf24; }
.btn-warning:hover { background: #fef3c7; }

/* Icon button */
.btn-icon { width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: var(--r-md); }

/* -- Fields --------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--s-2); margin-bottom: var(--s-4); }
.field label { font-size: .8125rem; color: var(--text-muted); font-weight: 500; }
.input, input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=search], select, textarea {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  font-size: .9375rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  outline: none;
  transition: border-color var(--t-fast) var(--ease-out), box-shadow var(--t-fast) var(--ease-out), background var(--t-fast) var(--ease-out);
}
textarea { height: auto; min-height: 140px; padding: 12px 14px; resize: vertical; }
.input:hover, input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
.input:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--brand-500); box-shadow: var(--shadow-glow);
}
.input.with-icon { padding-left: 42px; }
.field-icon-wrap { position: relative; }
.field-icon-wrap > svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-dim); pointer-events: none; }

/* -- OTP boxes ----------------------------------------------------------- */
.otp-boxes { display: flex; gap: var(--s-2); justify-content: center; }
.otp-boxes input {
  width: 48px; height: 56px; padding: 0; text-align: center;
  font-family: 'JetBrains Mono', monospace; font-size: 1.5rem; font-weight: 600;
  border: 1.5px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
}
.otp-boxes input:focus { border-color: var(--brand-500); box-shadow: var(--shadow-glow); transform: translateY(-1px); }
.otp-boxes input.filled { border-color: var(--brand-400); background: var(--brand-50); }
@media (max-width: 420px) {
  .otp-boxes input { width: 42px; height: 52px; font-size: 1.25rem; }
}

/* -- Badges --------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  background: var(--bg-soft); color: var(--text-muted);
}
.badge.success { background: var(--success-bg); color: #047857; }
.badge.warn    { background: var(--warn-bg);    color: #92400e; }
.badge.danger  { background: var(--danger-bg);  color: #b91c1c; }
.badge.info    { background: var(--info-bg);    color: #0369a1; }
.badge.brand   { background: var(--brand-50);   color: var(--brand-700); }
.badge .dot    { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }

/* -- Alerts --------------------------------------------------------------- */
.alert {
  display: flex; align-items: flex-start; gap: var(--s-3);
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md);
  font-size: .9rem; line-height: 1.45;
  border: 1px solid transparent;
  margin-bottom: var(--s-4);
}
.alert svg { flex-shrink: 0; width: 18px; height: 18px; margin-top: 2px; }
.alert.error    { background: var(--danger-bg);  color: #991b1b; border-color: rgba(239, 68, 68, .25); }
.alert.success  { background: var(--success-bg); color: #065f46; border-color: rgba(16, 185, 129, .25); }
.alert.info     { background: var(--info-bg);    color: #075985; border-color: rgba(14, 165, 233, .25); }
.alert.warn     { background: var(--warn-bg);    color: #92400e; border-color: rgba(245, 158, 11, .25); }

/* -- Tables --------------------------------------------------------------- */
.tbl-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow-x: auto; overflow-y: hidden; box-shadow: var(--shadow-sm); -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; min-width: 640px; border-collapse: collapse; font-size: .9rem; }
.tbl thead { background: var(--bg-soft); }
.tbl th { text-align: left; font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); padding: 12px 14px; }
.tbl td { padding: 12px 14px; border-top: 1px solid var(--border); }
.tbl tbody tr { transition: background var(--t-fast) var(--ease-out); }
.tbl tbody tr:hover { background: var(--bg-soft); }
.tbl tbody tr.row-warn  { background: color-mix(in oklab, var(--warn-bg) 60%, transparent); }
.tbl tbody tr.row-error { background: color-mix(in oklab, var(--danger-bg) 60%, transparent); }

/* -- Skeleton loader ---------------------------------------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-soft) 25%, var(--border) 37%, var(--bg-soft) 63%);
  background-size: 400% 100%; border-radius: var(--r-sm);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0 } 100% { background-position: -100% 0 } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* -- Toast --------------------------------------------------------------- */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px 16px; min-width: 260px; max-width: 420px; box-shadow: var(--shadow-lg); font-size: .9rem; animation: toast-in var(--t-mid) var(--ease-out) both; }
.toast.success { border-color: rgba(16, 185, 129, .35); }
.toast.error   { border-color: rgba(239, 68, 68, .35); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* =============================================================================
   EXAM ENGINE -- Mobile-first exam taking surface
   ============================================================================= */

#exam-root { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; background: var(--bg); }

/* Top bar */
.exam-top {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--s-3);
  padding: 10px 14px;
  background: color-mix(in oklab, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.exam-name { font-weight: 600; font-size: .95rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exam-meta { display: flex; align-items: center; gap: var(--s-2); font-size: .78rem; }

.exam-timer {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 700; font-variant-numeric: tabular-nums;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: .95rem;
  padding: 6px 10px; border-radius: var(--r-pill);
  background: var(--success-bg); color: #047857;
  border: 1px solid color-mix(in oklab, var(--success) 25%, transparent);
}
.exam-timer-warn     { background: var(--warn-bg);   color: #b45309; border-color: color-mix(in oklab, var(--warn) 30%, transparent); }
.exam-timer-critical { background: var(--danger-bg); color: #b91c1c; border-color: color-mix(in oklab, var(--danger) 30%, transparent); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .65 } }

.exam-net, .exam-save {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px; border-radius: var(--r-pill);
  font-size: .75rem; font-weight: 500;
  background: var(--bg-soft); color: var(--text-muted);
  border: 1px solid var(--border);
}
.exam-net::before, .exam-save::before {
  content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor;
}
.exam-net.status-online    { background: var(--success-bg); color: #047857; border-color: color-mix(in oklab, var(--success) 25%, transparent); }
.exam-net.status-weak      { background: var(--warn-bg);    color: #b45309; border-color: color-mix(in oklab, var(--warn) 30%, transparent); }
.exam-net.status-offline   { background: var(--danger-bg);  color: #b91c1c; border-color: color-mix(in oklab, var(--danger) 30%, transparent); }
.exam-save.status-saving,
.exam-save.status-syncing  { background: var(--info-bg);    color: #075985; border-color: color-mix(in oklab, var(--info) 25%, transparent); }
.exam-save.status-saved    { background: var(--success-bg); color: #047857; border-color: color-mix(in oklab, var(--success) 25%, transparent); }
.exam-save.status-queued   { background: var(--warn-bg);    color: #b45309; border-color: color-mix(in oklab, var(--warn) 30%, transparent); }
.exam-save.status-offline  { background: var(--danger-bg);  color: #b91c1c; border-color: color-mix(in oklab, var(--danger) 30%, transparent); }

/* Body */
.exam-body {
  flex: 1; padding: var(--s-5);
  padding-bottom: calc(var(--nav-h) + var(--s-5));
  max-width: 880px; width: 100%; margin: 0 auto;
}
.exam-question-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: .78rem; color: var(--text-muted); margin-bottom: var(--s-3);
}
.exam-question-meta .qnum {
  font-weight: 700; color: var(--brand-600); font-variant-numeric: tabular-nums;
  background: var(--brand-50); padding: 2px 9px; border-radius: var(--r-pill);
}
.exam-question-html {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: var(--s-5);
  font-size: 1rem; line-height: 1.65;
  box-shadow: var(--shadow-xs);
}
.exam-question-html img { max-width: 100%; height: auto; border-radius: var(--r-sm); }
.exam-question-html p { margin: 0 0 .75em; }
.exam-question-html p:last-child { margin-bottom: 0; }

/* Options */
.exam-options { margin-top: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); }
.opt-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--r-md);
  transition: background var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out);
  position: relative;
}
.opt-row:hover { background: var(--bg-soft); border-color: var(--border-strong); }
.opt-row:active { transform: scale(.995); }
.opt-row.opt-selected { background: var(--brand-50); border-color: var(--brand-500); box-shadow: var(--shadow-glow); }
.opt-row input { flex-shrink: 0; margin-top: 3px; width: 18px; height: 18px; accent-color: var(--brand-500); }
.opt-row .opt-body { flex: 1; font-size: .95rem; line-height: 1.5; min-width: 0; }
.opt-row .opt-body img { max-width: 100%; border-radius: var(--r-sm); margin-top: 8px; }
.opt-row .opt-letter {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--bg-soft); color: var(--text-muted);
  font-weight: 600; font-size: .8rem;
}
.opt-row.opt-selected .opt-letter { background: var(--brand-500); color: #fff; }

/* Descriptive answer area */
.exam-text-answer textarea {
  width: 100%; min-height: 180px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 14px; font-size: .95rem; line-height: 1.55;
}

/* Bottom navigation */
.exam-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px;
  padding: 10px 12px;
  background: color-mix(in oklab, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px -8px rgba(15, 23, 42, .08);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.exam-nav button {
  border: 1px solid transparent; padding: 11px 6px; border-radius: var(--r-md);
  font-weight: 600; font-size: .82rem; line-height: 1;
  background: var(--surface-2); color: var(--text); cursor: pointer;
  min-height: 44px;
  transition: background var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out);
}
.exam-nav button:active { transform: scale(.97); }
.exam-nav .btn-primary    { background: var(--brand-grad); color: #fff; border: none; box-shadow: 0 4px 10px -3px rgba(99, 102, 241, .5); }
.exam-nav .btn-secondary  { background: var(--bg-soft); color: var(--text); border-color: var(--border); }
.exam-nav .btn-mark       { background: var(--warn-bg); color: #92400e; border-color: rgba(245, 158, 11, .25); }
.exam-nav .btn-clear      { background: var(--danger-bg); color: #991b1b; border-color: rgba(239, 68, 68, .2); }
.exam-nav .btn-palette    { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-200); font-variant-numeric: tabular-nums; }
.exam-nav .btn-submit     { background: linear-gradient(135deg, #059669, #10b981); color: #fff; border: none; box-shadow: 0 4px 10px -3px rgba(16, 185, 129, .5); }

/* Question palette sheet */
.exam-palette-sheet {
  position: fixed; left: 0; right: 0; bottom: var(--nav-h); z-index: 50;
  background: var(--surface); border-top-left-radius: var(--r-2xl); border-top-right-radius: var(--r-2xl);
  box-shadow: 0 -16px 40px -8px rgba(15, 23, 42, .18); max-height: 65vh; overflow: auto;
  padding: var(--s-5); animation: slide-up var(--t-mid) var(--ease-out);
}
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.exam-palette-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: var(--s-3); }
.exam-palette-head button { border: none; background: var(--bg-soft); font-size: 18px; cursor: pointer; width: 32px; height: 32px; border-radius: 8px; }
.exam-palette-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: var(--s-4); font-size: .75rem; color: var(--text-muted); }
.exam-palette-legend .leg { padding: 3px 10px; border-radius: var(--r-pill); display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.leg.leg-answered    { background: var(--success-bg); color: #047857; }
.leg.leg-notanswered { background: var(--bg-soft); color: var(--text-muted); }
.leg.leg-marked      { background: var(--warn-bg); color: #92400e; }
.leg.leg-current     { background: var(--brand-50); color: var(--brand-700); }

.exam-palette-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.pal-cell {
  border: 1.5px solid var(--border); background: var(--surface);
  border-radius: var(--r-md); padding: 10px 0;
  font-weight: 600; font-size: .9rem; cursor: pointer;
  transition: transform var(--t-fast) var(--ease-out), box-shadow var(--t-fast) var(--ease-out);
}
.pal-cell:hover { box-shadow: var(--shadow-sm); }
.pal-cell.pal-answered    { background: var(--success-bg); border-color: var(--success); color: #047857; }
.pal-cell.pal-marked      { background: var(--warn-bg);    border-color: var(--warn);    color: #92400e; }
.pal-cell.pal-current     { outline: 3px solid color-mix(in oklab, var(--brand-500) 40%, transparent); outline-offset: 2px; }

/* Tablet+ */
@media (min-width: 768px) {
  .exam-nav { grid-template-columns: repeat(6, auto); justify-content: flex-end; }
  .exam-nav button { min-width: 100px; padding: 12px 18px; font-size: .875rem; }
  .exam-palette-grid { grid-template-columns: repeat(10, 1fr); }
  .exam-palette-sheet { left: auto; right: 16px; bottom: calc(var(--nav-h) + 8px); width: 460px; border-radius: var(--r-2xl); }
}

.exam-fatal {
  padding: var(--s-8); text-align: center;
  color: #991b1b; font-weight: 600; font-size: 1rem;
}

/* =============================================================================
   Exam list / dashboard cards
   ============================================================================= */
.exam-card {
  display: flex; flex-direction: column; gap: var(--s-3);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--s-5);
  transition: box-shadow var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out);
}
.exam-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); transform: translateY(-1px); }
.exam-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); }
.exam-card-title { font-weight: 600; font-size: 1rem; line-height: 1.35; }
.exam-card-code  { font-size: .72rem; color: var(--text-dim); font-family: 'JetBrains Mono', monospace; margin-top: 2px; }
.exam-card-desc  { color: var(--text-muted); font-size: .875rem; line-height: 1.5; }
.exam-card-grid  { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-2); font-size: .78rem; color: var(--text-muted); }
.exam-card-grid .kv strong { display: block; color: var(--text); font-weight: 600; font-size: .85rem; margin-top: 1px; }
.exam-card-actions { display: flex; gap: var(--s-2); margin-top: var(--s-2); align-items: center; }

/* Empty state */
.empty {
  text-align: center; padding: var(--s-10) var(--s-5);
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--r-lg);
  color: var(--text-muted);
}
.empty .empty-icon {
  width: 56px; height: 56px; margin: 0 auto var(--s-3);
  border-radius: 16px; background: var(--brand-grad-soft);
  display: grid; place-items: center; color: var(--brand-600);
}
.empty .empty-title { font-weight: 600; color: var(--text); margin-bottom: var(--s-1); }

/* Tile grid (admin dashboard) */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s-3); }
.tile {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: var(--s-3);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--s-5);
  text-decoration: none; color: inherit;
  transition: box-shadow var(--t-fast) var(--ease-out), transform var(--t-fast) var(--ease-out), border-color var(--t-fast) var(--ease-out);
}
.tile:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); transform: translateY(-2px); }
.tile-icon {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--brand-grad-soft); color: var(--brand-600);
  display: grid; place-items: center;
}
.tile-icon svg { width: 22px; height: 22px; }
.tile-title { font-weight: 600; }
.tile-sub   { font-size: .82rem; color: var(--text-muted); }
.tile .arrow { position: absolute; top: var(--s-4); right: var(--s-4); color: var(--text-dim); transition: transform var(--t-fast) var(--ease-out); }
.tile:hover .arrow { color: var(--brand-600); transform: translateX(2px); }

/* Page header */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--s-3); margin: var(--s-6) 0 var(--s-4); flex-wrap: wrap; }
.page-title { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; }
.page-sub { color: var(--text-muted); font-size: .9rem; }

/* ===== Modal (used by admin-ui.js) ===== */
.admin-modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: color-mix(in oklab, #0f172a 55%, transparent);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px;
  opacity: 0; transition: opacity var(--t-mid) var(--ease-out);
}
.admin-modal-overlay.is-open { opacity: 1; }
.admin-modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 480px; max-height: 90vh;
  display: flex; flex-direction: column;
  transform: translateY(12px); transition: transform var(--t-mid) var(--ease-out);
}
.admin-modal-overlay.is-open .admin-modal { transform: translateY(0); }
.admin-modal-lg { max-width: 640px; }
.admin-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.admin-modal-head h3 { font-size: 1rem; font-weight: 600; margin: 0; }
.admin-modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.admin-modal-body .field:last-child { margin-bottom: 0; }
.admin-modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 20px; border-top: 1px solid var(--border);
  background: var(--bg-soft);
  border-bottom-left-radius: var(--r-lg); border-bottom-right-radius: var(--r-lg);
}

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab-btn { border: none; background: transparent; padding: 10px 16px; font: inherit; font-weight: 500; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--brand-600); border-bottom-color: var(--brand-500); }

/* Filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filter-bar .input, .filter-bar select { height: 40px; flex: 1 1 180px; min-width: 0; }

/* Pagination */
.pager { display: flex; gap: 6px; justify-content: center; padding: 16px 0; }
.pager button { min-width: 36px; height: 36px; padding: 0 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: var(--r-sm); cursor: pointer; }
.pager button:hover { background: var(--bg-soft); }
.pager button.active { background: var(--brand-500); color: #fff; border-color: var(--brand-500); }
.pager button:disabled { opacity: .5; cursor: not-allowed; }

/* Small-screen tuning */
@media (max-width: 640px) {
  .app-header { padding: 0 12px; }
  .app-header-actions { gap: 8px; }
  .app-header-actions .muted { display: none; } /* hide long usernames on small screens */
  .app-brand .wordmark { display: inline; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .section { padding: var(--s-6) 0; }
  .container, .container-sm { padding: 0 12px; }
  .tile-grid { grid-template-columns: 1fr !important; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: 1.4rem; }
  .card { padding: var(--s-4); }
  .auth-card { padding: 24px; }
}
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
}
