/* ═══════════════════════════════════════════════════════════════════════════════
   master.css — TechSillica Exam Engine
   Version 3.0  |  WCAG 2.1 AA  |  Zero Trust Security
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────────────────
   1.  CSS CUSTOM PROPERTIES — Light theme (default)
   ───────────────────────────────────────────────────────────────────────────── */

:root {
  /* ── Brand ── */
  --blue-dark:        #153d66;
  --blue-mid:         #004ea2;
  --blue-light:       #e8f0fb;
  --blue-border:      #b8cfe8;  /* border for blue-light containers */
  --blue-label-bg:    #d0dff5;  /* label bg inside blue-light containers */
  --gold:             #c78100;
  --gold-light:       #fef9ee;

  /* ── Status — WCAG AA contrast ≥ 4.5:1 on white backgrounds ── */
  --green:            #1a7a3e;
  --green-light:      #d4edda;
  --red:              #a52a1f;
  --red-light:        #fdecea;
  --orange:           #b86a11;
  --purple:           #5e35b1;

  /* ── Neutrals ── */
  --grey-bg:          #f0f2f5;
  --grey-border:      #b8bfc7;
  --grey-text:        #4a5260;
  --white:            #ffffff;
  --body-bg:          #f0f2f5;
  --body-color:       #1a1a1a;
  --card-bg:          #ffffff;
  --input-bg:         #ffffff;
  --header-bg:        #153d66;
  --sidebar-bg:       #ffffff;
  --panel-bg:         #ffffff;
  --section-bar-bg:   #ffffff;
  --timer-bg:         #153d66;
  --option-hover-bg:  #e8f0fb;
  --meta-row-bg:      #f0f2f5;

  /* ── Shadows ── */
  --shadow-sm:        0 1px 4px rgba(0,0,0,.08);
  --shadow-md:        0 3px 12px rgba(0,0,0,.12);
  --shadow-lg:        0 8px 32px rgba(0,0,0,.18);

  /* ── Radii ── */
  --radius-sm:        4px;
  --radius-md:        8px;
  --radius-lg:        12px;

  /* ── Typography — Zero Trust: no external font CDN references ── */
  /* Latin: system font stack — Roboto included as Android system font fallback */
  --font-main:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
                       'Helvetica Neue', Arial, sans-serif;
  --font-hindi:       'Noto Sans Devanagari', 'Mangal', 'Kokila', sans-serif;

  /* ── Font scale — controlled by JS font-size classes ── */
  --fs-base:          1rem;        /* ~16px browser default */
  --line-height:      1.6;         /* WCAG 1.4.8 Visual Presentation */
  --paragraph-spacing: 1.5em;

  /* ── Transitions ── */
  --trans:            0.2s ease;   /* default — kept for backward compat */
  --trans-fast:       0.12s ease;  /* palette-btn, micro-interactions     */
  --trans-ui:         0.15s ease;  /* buttons, borders, options           */
  --trans-color:      0.3s ease;   /* colour-only changes (timer, theme)  */

  /* ── Difficulty colours — WCAG AA ≥ 4.5:1 on light backgrounds ── */
  --diff-easy:        #1a7a3e;
  --diff-medium-bg:   #fdebd0;
  --diff-medium:      #9c5f00;
  --diff-hard:        #a52a1f;

  /* ── Focus ring — WCAG 2.4.7 Focus Visible ── */
  --focus-ring-color:  var(--blue-mid);
  --focus-ring-width:  3px;
  --focus-ring-offset: 2px;

  /* ── Semantic UI tokens ── */
  --timer-danger-color: #ff5252;  /* brighter than --red for dark timer-bg */
  --warning-bg:         #fff3cd;
  --warning-text:       #5c4605;
  --warning-pulse-base: #fff3cd;
  --warning-pulse-peak: #ffeba3;
} /* end :root */

/* ─────────────────────────────────────────────────────────────────────────────
   2.  DARK THEME — [data-theme="dark"] selector (matches semantic HTML)
   ───────────────────────────────────────────────────────────────────────────── */
[data-theme="dark"],
.theme-dark {
  --blue-dark:        #1e5c94;
  --blue-mid:         #4d9de0;
  --blue-light:       #1a2d45;
  --gold:             #e8a820;
  --gold-light:       #2d2410;

  --green:            #27ae60;
  --green-light:      #0d2b18;
  --red:              #e74c3c;
  --red-light:        #2b0d0d;
  --orange:           #f5a623;

  --grey-bg:          #1a1d23;
  --grey-border:      #2d3340;
  --grey-text:        #9aa3b2;
  --white:            #1e2229;
  --body-bg:          #12151a;
  --body-color:       #e2e8f0;
  --card-bg:          #1e2229;
  --input-bg:         #252b35;
  --header-bg:        #0d1520;
  --sidebar-bg:       #1e2229;
  --panel-bg:         #1e2229;
  --section-bar-bg:   #1e2229;
  --timer-bg:         #0d1520;
  --option-hover-bg:  #1a2d45;
  --meta-row-bg:      #1a1d23;

  --shadow-sm:        0 1px 4px rgba(0,0,0,.3);
  --shadow-md:        0 3px 12px rgba(0,0,0,.4);

  --diff-easy:        #27ae60;
  --diff-medium:      #f5a623;
  --diff-medium-bg:   #3d2a10;
  --diff-hard:        #e74c3c;
}

/* System-level dark mode — delegates to the [data-theme="dark"] vars above.
   No duplication needed: the selector below simply applies the same token
   overrides when the OS prefers dark and no explicit theme is set.          */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not(.theme-light) {
    --blue-dark:      #1e5c94;
    --blue-mid:       #4d9de0;
    --blue-light:     #1a2d45;
    --gold:           #e8a820;
    --gold-light:     #2d2410;
    --green:          #27ae60;
    --green-light:    #0d2b18;
    --red:            #e74c3c;
    --red-light:      #2b0d0d;
    --orange:         #f5a623;
    --grey-bg:        #1a1d23;
    --grey-border:    #2d3340;
    --grey-text:      #9aa3b2;
    --white:          #1e2229;
    --body-bg:        #12151a;
    --body-color:     #e2e8f0;
    --card-bg:        #1e2229;
    --input-bg:       #252b35;
    --header-bg:      #0d1520;
    --sidebar-bg:     #1e2229;
    --panel-bg:       #1e2229;
    --section-bar-bg: #1e2229;
    --timer-bg:       #0d1520;
    --option-hover-bg:#1a2d45;
    --meta-row-bg:    #1a1d23;
    --shadow-sm:      0 1px 4px rgba(0,0,0,.3);
    --shadow-md:      0 3px 12px rgba(0,0,0,.4);
    --diff-easy:      #27ae60;
    --diff-medium:    #f5a623;
    --diff-medium-bg: #3d2a10;
    --diff-hard:      #e74c3c;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   3.  FONT-SIZE SCALE CLASSES  (WCAG 1.4.4 Resize text up to 200%)
   ───────────────────────────────────────────────────────────────────────────── */
.fs-sm  { --fs-base: 0.75rem; }   /* 12px */
.fs-md  { --fs-base: 0.875rem; }  /* 14px — default */
.fs-lg  { --fs-base: 1rem; }      /* 16px */
.fs-xl  { --fs-base: 1.125rem; }  /* 18px */

/* ─────────────────────────────────────────────────────────────────────────────
   4.  RESET & BASE STYLES
   ───────────────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Prevent text-size-adjust issues on iOS */
html {
  height: 100%;
  -webkit-text-size-adjust: none; /* Safari: disable auto font inflation */
  -moz-text-size-adjust: none;    /* Firefox: same */
  text-size-adjust: none;         /* Standard — WCAG 1.4.4: user zoom still works */
  /* WCAG 1.4.4: Respect user's browser font size setting */
  font-size: 100%;
}

body {
  height: 100%;
  overflow: hidden;
  min-height: 100svh;                 /* Small viewport units */
  min-height: -webkit-fill-available; /* iOS Safari */
  font-family: var(--font-main);
  font-size: var(--fs-base);
  line-height: var(--line-height);    /* WCAG 1.4.8 */
  background-color: var(--body-bg);
  color: var(--body-color);
  transition: background-color var(--trans), color var(--trans);
}

/* ── Global Focus Ring — WCAG 2.4.7 Focus Visible, 2.4.11 Focus Not Obscured ── */
:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
  border-radius: var(--radius-sm);
}

/* Ensure focus is visible even within containers */
:focus:not(:focus-visible) {
  outline: none;
}

/* Focus-within for containers (cards, options) — scoped to relevant elements only */
.option-row:focus-within,
.palette-btn:focus-within,
.fs-btn:focus-within {
  --focus-ring-color: var(--blue-mid);
}

/* ── Target Size — WCAG 2.5.8 Target Size (Minimum) 24×24px ── */
button, a, input[type="checkbox"], input[type="radio"],
.palette-btn, .hdr-icon-btn, .fs-btn, .option-row {
  min-width: 24px;
  min-height: 24px;
}

/* Larger touch targets for primary actions */
.btn, .sec-tab, .option-row, .palette-btn {
  min-height: 44px;
}

/* ── Reduced Motion — WCAG 2.3.3 Animation from Interactions ── */
/* @keyframes pulse hoisted to top-level (keyframes inside @media causes
   "Expected declaration" parse errors in older Firefox/WebKit builds).  */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* Preserve critical timer pulse — but slower, gentler */
  .timer-display.timer-danger,
  .q-timer-val.danger {
    animation: pulse 2s infinite !important;
  }
}

/* ── Print Styles — WCAG compatible (content remains accessible) ── */
@media print {
  .top-header, .section-bar, .exam-sidebar, .action-bar,
  .cheat-overlay, .fullscreen-overlay, .loading-overlay,
  .toast-container, .pwa-banner, .modal-overlay,
  .sidebar-toggle, .sidebar-backdrop, .fs-toolbar,
  .expiry-warning-banner, .section-locked-banner {
    display: none !important;
  }

  body {
    overflow: auto;
    background: #fff !important;
    color: #000 !important;
  }

  .exam-body, .question-panel, .q-top-zone, .q-bottom-zone {
    height: auto;
    overflow: visible;
    max-height: none;
    border: none;
  }

  .question-text, .option-text {
    color: #000 !important;
    font-size: 12pt;
    line-height: 1.5;
  }

  .option-row {
    border: 1px solid #999;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  img {
    max-width: 100% !important;
    display: block;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    word-break: break-all;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   5.  TOP HEADER
   ───────────────────────────────────────────────────────────────────────────── */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 58px;
  background-color: var(--header-bg);
  border-bottom: 3px solid var(--gold);
  position: relative;
  z-index: 100;
  flex-shrink: 0;
  gap: 0.75rem;
}

.header-left   { display: flex; align-items: center; flex-shrink: 0; }
.header-center { display: flex; align-items: center; justify-content: center; flex: 1; min-width: 0; }
.header-right  { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }

/* ── Exam Logo ── */
.exam-logo { display: flex; align-items: center; gap: 0.75rem; }

.logo-mark {
  background-color: var(--gold);
  color: var(--blue-dark);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.logo-divider  { width: 1px; height: 28px; background-color: rgba(255,255,255,.35); }
.logo-text     { display: flex; flex-direction: column; }
.logo-title    { color: #fff; font-size: 0.9rem; font-weight: 600; line-height: 1.2; }
.logo-subtitle { color: rgba(255,255,255,.72); font-size: 0.75rem; }

/* ── Candidate Block ── */
.candidate-block { display: flex; align-items: center; gap: 0.625rem; }

.candidate-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--gold);
  color: var(--blue-dark);
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.candidate-info { display: flex; flex-direction: column; }
.candidate-name { color: #fff; font-size: 0.88rem; font-weight: 600; line-height: 1.2; }
.candidate-id   { color: rgba(255,255,255,.68); font-size: 0.72rem; }

/* ── Header Icon Buttons ── */
.hdr-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  background-color: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.28);
  color: #fff;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1rem;
  font-family: var(--font-main);
  transition: background-color var(--trans), border-color var(--trans);
}

.hdr-icon-btn:hover {
  background-color: rgba(255,255,255,.22);
  border-color: rgba(255,255,255,.5);
}

.hdr-icon-btn:focus-visible {
  outline-color: var(--gold);
}

.hdr-icon-btn abbr {
  text-decoration: none;
  color: inherit;
}

/* ── Language Toggle ── */
.lang-toggle {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  background-color: transparent;
  border: 1px solid rgba(255,255,255,.5);
  color: #fff;
  padding: 0.375rem 0.875rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.82rem;
  font-family: var(--font-main);
  transition: background-color var(--trans), border-color var(--trans);
  white-space: nowrap;
}

.lang-toggle:hover {
  background-color: rgba(255,255,255,.15);
  border-color: rgba(255,255,255,.8);
}

.lang-toggle:focus-visible {
  outline-color: var(--gold);
}

.lang-toggle abbr { text-decoration: none; }

/* ─────────────────────────────────────────────────────────────────────────────
   6.  FONT-SIZE TOOLBAR
   ───────────────────────────────────────────────────────────────────────────── */
.fs-toolbar {
  display: none;
  align-items: center;
  gap: 0.625rem;
  padding: 0.375rem 1.5rem;
  background-color: var(--blue-dark);
  border-bottom: 1px solid rgba(255,255,255,.15);
  flex-shrink: 0;
  z-index: 91;
}

.fs-toolbar.visible { display: flex; }

.fs-label { color: rgba(255,255,255,.82); font-size: 0.75rem; margin-right: 0.25rem; }

.fs-btn {
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,.4);
  background-color: transparent;
  color: #fff;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: var(--font-main);
  min-height: 32px;
  min-width: 32px;
  transition: background-color var(--trans);
}

.fs-btn:hover {
  background-color: rgba(255,255,255,.18);
}

.fs-btn.fs-active {
  background-color: var(--gold);
  color: var(--blue-dark);
  border-color: var(--gold);
  font-weight: 700;
}

.fs-btn:focus-visible {
  outline-color: var(--gold);
}

/* ─────────────────────────────────────────────────────────────────────────────
   7.  SECTION BAR (tabs + timers)
   ───────────────────────────────────────────────────────────────────────────── */
.section-bar {
  display: flex;
  align-items: stretch;
  background-color: var(--section-bar-bg);
  border-bottom: 2px solid var(--grey-border);
  height: 52px;
  flex-shrink: 0;
  position: relative;
  z-index: 90;
  transition: background-color var(--trans), border-color var(--trans);
}

.section-tabs {
  display: flex;
  align-items: stretch;
  flex: 1;
  overflow-x: auto;
}

/* Scrollbar styling for section tabs */
.section-tabs::-webkit-scrollbar { height: 4px; }
.section-tabs::-webkit-scrollbar-track { background: transparent; }
.section-tabs::-webkit-scrollbar-thumb { background: var(--grey-border); border-radius: 2px; }

/* ── Section Tab Button ── */
.sec-tab {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 0 1.25rem;
  border: none;
  background-color: transparent;
  border-right: 1px solid var(--grey-border);
  cursor: pointer;
  font-family: var(--font-main);
  transition: background-color var(--trans);
  position: relative;
  white-space: nowrap;
  min-width: 160px;
  min-height: 44px;
}

.sec-tab:hover:not(.locked):not(.active) {
  background-color: var(--blue-light);
}

.sec-tab:focus-visible {
  outline-offset: -3px;
}

.sec-tab.active {
  background-color: var(--blue-light);
  border-bottom: 3px solid var(--blue-mid);
  margin-bottom: -2px;
}

.sec-tab.completed {
  background-color: var(--green-light);
}

.sec-tab.locked {
  background-color: var(--meta-row-bg);
  opacity: 0.6;
  cursor: not-allowed;
}

/* Lock icon using CSS — no emoji dependency for accessibility */
.sec-tab.locked::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 8px;
  width: 12px;
  height: 12px;
  background-color: var(--grey-text);
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z'/%3E%3C/svg%3E");
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z'/%3E%3C/svg%3E");
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
}

.sec-name { font-size: 0.82rem; font-weight: 600; color: var(--blue-dark); line-height: 1.2; }
.sec-tab.active    .sec-name { color: var(--blue-mid); }
.sec-tab.locked    .sec-name { color: var(--grey-text); }
.sec-tab.completed .sec-name { color: var(--green); }

.sec-meta { font-size: 0.68rem; color: var(--grey-text); margin-top: 2px; }

/* ─────────────────────────────────────────────────────────────────────────────
   8.  TIMER PANEL
   ───────────────────────────────────────────────────────────────────────────── */
.timer-panel {
  display: flex;
  align-items: center;
  padding: 0 1.125rem;
  gap: 0.25rem;
  background-color: var(--timer-bg);
  flex-shrink: 0;
}

.timer-block   { display: flex; flex-direction: column; align-items: center; min-width: 72px; }
.timer-label   { font-size: 0.62rem; color: rgba(255,255,255,.7); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 1px; }
.timer-display {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  transition: color var(--trans-color);
}

.timer-display.timer-warning { color: var(--gold); }
.timer-display.timer-danger  { color: var(--timer-danger-color); animation: pulse 1s infinite; }

.timer-divider { width: 1px; height: 28px; background-color: rgba(255,255,255,.22); margin: 0 0.625rem; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes spin  { to { transform: rotate(360deg); } }

/* ─────────────────────────────────────────────────────────────────────────────
   9.  EXPIRY WARNING BANNER
   ───────────────────────────────────────────────────────────────────────────── */
.expiry-warning-banner {
  display: none;
  align-items: center;
  gap: 0.625rem;
  background-color: var(--warning-bg);
  border-bottom: 2px solid var(--gold);
  padding: 0.5rem 1.5rem;
  font-size: 0.82rem;
  color: var(--warning-text);
  flex-shrink: 0;
  animation: warningPulse 1.5s ease-in-out infinite;
}

.expiry-warning-banner.visible  { display: flex; }

/* warningPulse reads --warning-pulse-* tokens; theme overrides live in :root/[data-theme] */
@keyframes warningPulse {
  0%, 100% { background-color: var(--warning-pulse-base); }
  50%       { background-color: var(--warning-pulse-peak); }
}

/* ─────────────────────────────────────────────────────────────────────────────
   10. SECTION LOCKED BANNER
   ───────────────────────────────────────────────────────────────────────────── */
.section-locked-banner {
  display: none;
  align-items: center;
  gap: 0.625rem;
  background-color: var(--red-light);
  border-bottom: 2px solid var(--red);
  padding: 0.5rem 1.5rem;
  font-size: 0.82rem;
  color: var(--red);
  flex-shrink: 0;
}

.section-locked-banner.visible { display: flex; }

/* ─────────────────────────────────────────────────────────────────────────────
   11. EXAM BODY
   ───────────────────────────────────────────────────────────────────────────── */
.exam-body {
  --gold:       var(--gold-600);
  --navy:       var(--navy-800);
  --navy-light: var(--navy-050);;
  --green:      var(--green-600);
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100svh - 58px - 52px);
}

/* Adjust height when banners/toolbars are visible */
body.has-locked-banner .exam-body                { height: calc(100svh - 58px - 52px - 38px); }
body.has-expiry-banner .exam-body                { height: calc(100svh - 58px - 52px - 38px); }
body.has-locked-banner.has-expiry-banner .exam-body { height: calc(100svh - 58px - 52px - 76px); }
body.has-fs-toolbar .exam-body                   { height: calc(100svh - 58px - 52px - 38px); }
body.has-fs-toolbar.has-locked-banner .exam-body,
body.has-fs-toolbar.has-expiry-banner .exam-body   { height: calc(100svh - 58px - 52px - 76px); }
body.has-fs-toolbar.has-locked-banner.has-expiry-banner .exam-body {
  height: calc(100svh - 58px - 52px - 114px);
}

/* ─────────────────────────────────────────────────────────────────────────────
   12. QUESTION PANEL (MAIN)
   ───────────────────────────────────────────────────────────────────────────── */
.question-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--panel-bg);
  border-right: 1px solid var(--grey-border);
  overflow-y: hidden;
  transition: background-color var(--trans), border-color var(--trans);
}

/* ── Question Metadata Row ── */
.question-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1.5rem;
  background-color: var(--meta-row-bg);
  border-bottom: 1px solid var(--grey-border);
  flex-shrink: 0;
  gap: 0.625rem;
  flex-wrap: wrap;
}

.question-id-tag { display: flex; align-items: center; gap: 0.625rem; flex-wrap: wrap; }

.q-section-tag {
  background-color: var(--blue-dark);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
}

.q-number-label { font-size: 0.85rem; font-weight: 600; color: var(--grey-text); }

/* ── Difficulty Badge — not relying on color alone (WCAG 1.4.1) ── */
.difficulty-badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 0.125rem 0.5rem;
  border-radius: 20px;
  text-transform: uppercase;
  border: 1.5px solid;
}

.diff-easy   { background-color: var(--green-light); color: var(--diff-easy); border-color: var(--diff-easy); }
.diff-medium { background-color: var(--diff-medium-bg); color: var(--diff-medium); border-color: var(--diff-medium); }
.diff-hard   { background-color: var(--red-light); color: var(--diff-hard); border-color: var(--diff-hard); }

/* ── Question-level Timer ── */
.q-timer-block {
  display: none;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--grey-text);
}

.q-timer-block.visible { display: flex; }
.q-timer-val  { font-variant-numeric: tabular-nums; min-width: 36px; text-align: right; }
.q-timer-val.warning { color: var(--orange); }
.q-timer-val.danger  { color: var(--red); animation: pulse 1s infinite; }

.question-marks-badge {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.78rem;
  font-weight: 600;
  background-color: var(--card-bg);
  border: 1px solid var(--grey-border);
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  flex-shrink: 0;
}

.marks-positive { color: var(--green); font-weight: 700; }
.marks-sep      { color: var(--grey-border); }
.marks-negative { color: var(--red); font-weight: 700; }

/* ─────────────────────────────────────────────────────────────────────────────
   13. SPLIT-ZONE LAYOUT (top-zone / bottom-zone)
   ───────────────────────────────────────────────────────────────────────────── */
.q-top-zone {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: 42%;
  overflow-y: auto;
  border-bottom: 2px solid var(--grey-border);
  background-color: var(--panel-bg);
  position: relative;
}

.q-top-zone:empty,
.q-top-zone.q-top-empty { display: none; }

.q-bottom-zone {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ─────────────────────────────────────────────────────────────────────────────
   14. PASSAGE BLOCK
   ───────────────────────────────────────────────────────────────────────────── */
.passage-block {
  margin: 1rem 1.5rem 0;
  border: 1px solid var(--blue-border);
  border-radius: var(--radius-md);
  background-color: var(--blue-light);
  overflow: hidden;
  flex-shrink: 0;
}

[data-theme="dark"] .passage-block,
.theme-dark .passage-block {
  background-color: var(--blue-light);  /* resolves to #1a2d45 in dark theme */
  border-color: var(--grey-border);
}

.passage-label {
  background-color: var(--blue-label-bg);
  color: var(--blue-dark);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--blue-border);
}

[data-theme="dark"] .passage-label,
.theme-dark .passage-label {
  background-color: var(--header-bg);   /* resolves to #0d1520 in dark theme */
  border-color: var(--grey-border);
}

.passage-text {
  padding: 0.875rem 1rem;
  font-size: 0.88rem;
  line-height: 1.75;
  color: var(--body-color);
  max-height: 160px;
  overflow-y: auto;
}

/* Zoom button */
.zoom-btn {
  position: absolute;
  top: 6px;
  right: 10px;
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  background-color: var(--blue-dark);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  opacity: 0.75;
  transition: opacity var(--trans);
}

.zoom-btn:hover  { opacity: 1; }
.zoom-btn:focus-visible { outline-color: var(--gold); }

/* ─────────────────────────────────────────────────────────────────────────────
   15. QUESTION IMAGE
   ───────────────────────────────────────────────────────────────────────────── */
.question-image-wrap {
  margin: 1rem 1.5rem 0;
  text-align: center;
  flex-shrink: 0;
  position: relative;
}

.question-image-wrap img {
  max-width: 100%;
  max-height: 220px;
  border: 1px solid var(--grey-border);
  border-radius: var(--radius-md);
  object-fit: contain;
  cursor: zoom-in;
  transition: transform var(--trans);
}

.question-image-wrap img:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: 4px;
}

.question-image-wrap img:hover {
  transform: scale(1.02);
}

/* ─────────────────────────────────────────────────────────────────────────────
   16. QUESTION TEXT
   ───────────────────────────────────────────────────────────────────────────── */
.question-text-box { padding: 1.25rem 1.5rem 0; flex-shrink: 0; }

.question-text,
.question-text-hi {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--body-color);
}

.question-text-hi { font-family: var(--font-hindi); line-height: 1.9; }

/* ─────────────────────────────────────────────────────────────────────────────
   17. OPTIONS LIST (FIELDSET)
   ───────────────────────────────────────────────────────────────────────────── */
.options-list {
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  flex: 1;
  border: none;
}

.option-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  min-height: 44px;
  border: 2px solid var(--grey-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--trans-ui), background-color var(--trans-ui);
  background-color: var(--card-bg);
  user-select: none;
  position: relative;
}

.option-row:hover {
  background-color: var(--option-hover-bg);
  border-color: var(--blue-mid);
}

.option-row:focus-within {
  border-color: var(--blue-mid);
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: 2px;
}

.option-row.selected {
  background-color: var(--blue-light);
  border-color: var(--blue-mid);
  /* WCAG 1.4.1 — pattern in addition to color */
  background-image: linear-gradient(135deg, transparent 95%, rgba(0,78,162,0.08) 95%);
}

.option-row input[type="radio"] {
  margin-top: 3px;
  transform: scale(1.25);
  cursor: pointer;
  flex-shrink: 0;
  accent-color: var(--blue-mid);
  min-width: 18px;
  min-height: 18px;
}

.option-row input[type="radio"]:disabled { cursor: not-allowed; }

.option-row input[type="radio"]:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: 2px;
}

.option-alpha {
  font-weight: 700;
  color: var(--blue-mid);
  font-size: 0.9rem;
  min-width: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.option-text {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--body-color);
}

/* ─────────────────────────────────────────────────────────────────────────────
   18. ACTION BAR
   ───────────────────────────────────────────────────────────────────────────── */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-top: 2px solid var(--grey-border);
  background-color: var(--meta-row-bg);
  flex-shrink: 0;
  gap: 0.625rem;
  flex-wrap: wrap;
}

.action-left, .action-right { display: flex; gap: 0.625rem; flex-wrap: wrap; }

/* ─────────────────────────────────────────────────────────────────────────────
   19. BUTTONS
   ───────────────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.625rem 1.125rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  min-height: 44px;
  min-width: 44px;  /* WCAG 2.5.8 Target Size */
  transition: opacity var(--trans-ui), transform var(--trans-fast), box-shadow var(--trans-ui), background-color var(--trans-ui);
  white-space: nowrap;
  line-height: 1.2;
}

.btn:hover:not(:disabled):not([aria-disabled="true"]) {
  opacity: 0.88;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0,0,0,.18);
}

.btn:active:not(:disabled):not([aria-disabled="true"]) {
  transform: translateY(0);
  box-shadow: none;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn:focus-visible {
  outline-color: var(--gold);
  outline-offset: 3px;
}

.btn-review { background-color: var(--orange); }
.btn-clear  { background-color: var(--grey-text); }
.btn-prev   { background-color: var(--grey-text); }
.btn-save   { background-color: var(--blue-mid); }
.btn-submit {
  background-color: var(--red);
  width: 100%;
  justify-content: center;
  font-size: 0.9rem;
  padding: 0.75rem;
}

/* ─────────────────────────────────────────────────────────────────────────────
   20. SIDEBAR
   ───────────────────────────────────────────────────────────────────────────── */
.exam-sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background-color: var(--sidebar-bg);
  border-left: 1px solid var(--grey-border);
  overflow-y: auto;
  transition: background-color var(--trans), border-color var(--trans), transform 0.3s ease;
}

/* ── Palette Legend — using <ul> structure for semantics ── */
.palette-legend {
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid var(--grey-border);
  background-color: var(--meta-row-bg);
  flex-shrink: 0;
}

.palette-legend ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.palette-legend li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.74rem;
  color: var(--grey-text);
}

.legend-dot {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
  display: inline-block;
  border: 1px solid rgba(0,0,0,.15);
}

[data-theme="dark"] .legend-dot,
.theme-dark .legend-dot { border-color: rgba(255,255,255,.15); }

.dot-answered        { background-color: var(--green); }
.dot-not-answered    { background-color: var(--red); }
.dot-review          { background-color: var(--orange); }
.dot-answered-review { background-color: var(--purple); }
.dot-not-visited     { background-color: var(--grey-border); }

/* ── Section Summary — using <dl> structure ── */
.section-summary {
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid var(--grey-border);
  flex-shrink: 0;
}

.summary-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--blue-dark);
  margin-bottom: 0.5rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.375rem;
}

.summary-cell {
  background-color: var(--meta-row-bg);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.summary-count {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--blue-dark);
}

.summary-label {
  font-size: 0.65rem;
  color: var(--grey-text);
  margin-top: 1px;
  text-align: center;
}

/* ── Question Palette — using <ol> structure ── */
.palette-section { flex: 1; padding: 0.625rem 0.875rem; overflow-y: auto; }
.palette-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--blue-dark);
  margin-bottom: 0.5rem;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 0.5rem;
  list-style: none;
}

.palette-btn {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--font-main);
  cursor: pointer;
  transition: transform var(--trans-fast), box-shadow var(--trans-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  min-width: 38px;
}

.palette-btn:hover { transform: scale(1.08); box-shadow: var(--shadow-sm); }
.palette-btn:focus-visible { outline-offset: 2px; }

.palette-btn.not-visited     { background-color: var(--grey-border); color: var(--body-color); border-color: var(--grey-border); }

[data-theme="dark"] .palette-btn.not-visited,
.theme-dark .palette-btn.not-visited { background-color: #2d3340; color: #9aa3b2; border-color: #3d4455; }
.palette-btn.answered        { background-color: var(--green);  color: #fff; border-color: var(--green); }
.palette-btn.not-answered    { background-color: var(--red);    color: #fff; border-color: var(--red); }
.palette-btn.marked          { background-color: var(--orange); color: #fff; border-color: var(--orange); }
.palette-btn.answered-marked { background-color: var(--purple); color: #fff; border-color: var(--purple); }
.palette-btn.active-question {
  outline: 3px solid var(--blue-mid);
  outline-offset: 1px;
  transform: scale(1.1);
  box-shadow: 0 0 8px rgba(0,78,162,.35);
}

/* ── Submit Section Wrap ── */
.submit-section-wrap {
  display: flex;
  align-items: center;
  padding: 0 1rem;
  border-right: 1px solid var(--grey-border);
}

.btn-submit-section {
  background-color: var(--blue-mid);
  color: #fff;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background-color var(--trans);
}

.btn-submit-section:hover {
  background-color: var(--blue-dark);
}

/* ── Submit Area ── */
.submit-area {
  padding: 0.75rem 0.875rem;
  border-top: 1px solid var(--grey-border);
  flex-shrink: 0;
  background-color: var(--meta-row-bg);
}

.submit-note {
  font-size: 0.68rem;
  color: var(--grey-text);
  text-align: center;
  margin-top: 0.375rem;
  line-height: 1.4;
}

/* ── Sidebar Toggle (mobile) ── */
.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 200;
  width: 52px;
  height: 52px;
  min-width: 52px;
  min-height: 52px;
  border-radius: 50%;
  background-color: var(--blue-mid);
  color: #fff;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  align-items: center;
  justify-content: center;
}

.sidebar-toggle:focus-visible { outline-color: var(--gold); outline-offset: 4px; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0,0,0,.45);
  z-index: 299;
}

.sidebar-backdrop.visible { display: block; }

/* ─────────────────────────────────────────────────────────────────────────────
   21. DIALOG / MODALS (native <dialog> element styles)
   ───────────────────────────────────────────────────────────────────────────── */
.modal-overlay,
.engine-error,
.zoom-lightbox,
.cheat-overlay,
.fullscreen-overlay {
  /* Reset native dialog positioning — we use flex center */
  position: fixed;
  inset: 0;
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  margin: 0;
  padding: 0;
  border: none;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* Native dialog ::backdrop styling */
.modal-overlay::backdrop,
.engine-error::backdrop,
.zoom-lightbox::backdrop,
.cheat-overlay::backdrop,
.fullscreen-overlay::backdrop {
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
}

/* Closed state for non-modal dialogs */
.modal-overlay:not([open]),
.engine-error:not([open]),
.zoom-lightbox:not([open]),
.cheat-overlay:not([open]),
.fullscreen-overlay:not([open]) {
  display: none;
}

/* Engine error specific — white background */
.engine-error {
  background: #fff;
  flex-direction: column;
  z-index: 9999;
  gap: 1rem;
  padding: 2rem;
  text-align: center;
  font-family: var(--font-main);
}

[data-theme="dark"] .engine-error,
.theme-dark .engine-error { background: var(--card-bg); }

.engine-error[open] { display: flex; }
.engine-error-icon  { font-size: 3rem; }
.engine-error-title { font-size: 1.3rem; font-weight: 700; color: var(--red); }
.engine-error-msg   { font-size: 0.9rem; color: var(--grey-text); max-width: 480px; line-height: 1.6; }
.engine-error-btn {
  padding: 0.625rem 1.5rem;
  background-color: var(--blue-dark);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-main);
  min-height: 44px;
  min-width: 44px;
}

.engine-error-btn:hover  { background-color: var(--blue-mid); }
.engine-error-btn:focus-visible { outline-color: var(--gold); }

.engine-error article { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.engine-error header   { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.engine-error footer   { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; }
.engine-error .back-link {
  font-size: 0.8rem;
  color: var(--grey-text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

[data-theme="dark"] .engine-error-title,
.theme-dark .engine-error-title { color: var(--timer-danger-color); }

/* ── Modal Box ── */
.modal-box {
  background-color: var(--card-bg);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 40px rgba(0,0,0,.25);
  max-width: 520px;
  width: 92%;
  overflow: hidden;
  color: var(--body-color);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.375rem;
  background-color: var(--blue-dark);
  color: #fff;
}

.modal-header h2 { font-size: 1rem; font-weight: 600; line-height: 1.3; }
.modal-icon      { font-size: 1.3rem; flex-shrink: 0; }
.modal-body      { padding: 1.25rem 1.375rem; font-size: 0.88rem; line-height: 1.65; }

/* Modal stats using <dl> */
.modal-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.625rem;
  margin-top: 1rem;
}

.mstat {
  background-color: var(--meta-row-bg);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.375rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.mstat dd {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--blue-dark);
  margin: 0;
}

.mstat dt {
  font-size: 0.68rem;
  color: var(--grey-text);
  font-weight: 400;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0.875rem 1.375rem;
  border-top: 1px solid var(--grey-border);
  background-color: var(--meta-row-bg);
  flex-wrap: wrap;
}

.btn-modal-cancel  { background-color: var(--grey-text); }
.btn-modal-confirm { background-color: var(--blue-mid); }

.modal-timeup .modal-header { background-color: var(--red); }

/* ── Instructions Modal ── */
.modal-instructions { max-width: 700px; }

.inst-logo {
  background-color: var(--gold);
  color: var(--blue-dark);
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.inst-body     { max-height: 55vh; overflow-y: auto; }
.inst-list     { padding-left: 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; font-size: 0.85rem; line-height: 1.65; }
.inst-list li  { padding-left: 0.25rem; }
.inst-list ul  { margin-top: 0.375rem; padding-left: 1.125rem; display: flex; flex-direction: column; gap: 0.25rem; }

.inst-marking {
  margin-top: 1.125rem;
  border: 1px solid var(--grey-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* Table wrapper for horizontal scroll on small screens */
.table-wrap {
  overflow-x: auto;
  max-width: 100%;
}

.marking-title {
  background-color: var(--blue-dark);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.5rem 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.marking-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.marking-table caption { text-align: left; }

.marking-table th,
.marking-table td {
  padding: 0.625rem 0.875rem;
  text-align: left;
  border-bottom: 1px solid var(--grey-border);
  color: var(--body-color);
}

.marking-table thead th {
  background-color: var(--blue-light);
  color: var(--blue-dark);
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

.marking-table tr:last-child td { border-bottom: none; }
.marking-table .total-row td { background-color: var(--meta-row-bg); font-weight: 700; }

.inst-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--body-color);
  cursor: pointer;
  line-height: 1.4;
}

.inst-checkbox-label input[type="checkbox"] {
  transform: scale(1.2);
  cursor: pointer;
  accent-color: var(--blue-mid);
  min-width: 18px;
  min-height: 18px;
  flex-shrink: 0;
}

.inst-checkbox-label input[type="checkbox"]:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: 2px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   22. LOADING OVERLAY
   ───────────────────────────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(21,61,102,.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  color: #fff;
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(255,255,255,.22);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

.loading-text { font-size: 0.9rem; color: rgba(255,255,255,.85); }

/* ─────────────────────────────────────────────────────────────────────────────
   23. ERROR STATE
   ───────────────────────────────────────────────────────────────────────────── */
body.is-error .section-bar,
body.is-error .exam-sidebar,
body.is-error .timer-panel,
body.is-error .section-locked-banner,
body.is-error .expiry-warning-banner,
body.is-error .fs-toolbar { display: none !important; }

body.is-error .exam-body { height: calc(100svh - 58px); }

.error-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 2.5rem;
  text-align: center;
  background-color: var(--card-bg);
}

.error-icon  { font-size: 3rem; }
.error-title { font-size: 1.2rem; font-weight: 700; color: var(--red); }
.error-msg   { font-size: 0.85rem; color: var(--grey-text); line-height: 1.6; max-width: 520px; }
.error-code  { font-family: monospace; background-color: var(--meta-row-bg); padding: 0.5rem 0.75rem; border-radius: 4px; color: var(--grey-text); font-size: 0.78rem; }
.error-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; justify-content: center; margin-top: 0.5rem; }
.btn-error-retry { background-color: var(--blue-mid); color: #fff; }
.btn-error-back  { background-color: var(--grey-text); color: #fff; }

/* ─────────────────────────────────────────────────────────────────────────────
   24. INLINE CHART
   ───────────────────────────────────────────────────────────────────────────── */
.chart-wrap     { padding: 1rem 1.5rem; background-color: var(--panel-bg); flex-shrink: 0; }
.chart-title    { font-size: 0.8rem; font-weight: 700; color: var(--blue-dark); text-align: center; margin-bottom: 0.25rem; }
.chart-subtitle { font-size: 0.7rem; color: var(--grey-text); text-align: center; margin-bottom: 0.75rem; }
.chart-svg-wrap { display: flex; justify-content: center; align-items: flex-start; gap: 1.25rem; flex-wrap: wrap; }
.chart-svg-wrap svg { flex-shrink: 0; }
.chart-legend   { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; justify-content: center; margin-top: 0.75rem; }
.legend-entry   { display: flex; align-items: center; gap: 0.375rem; font-size: 0.72rem; color: var(--body-color); }
.legend-swatch  { width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0; }
.chart-series-legend { display: flex; gap: 1rem; justify-content: center; margin-top: 0.625rem; }
.series-entry   { display: flex; align-items: center; gap: 0.375rem; font-size: 0.72rem; color: var(--body-color); }

/* ─────────────────────────────────────────────────────────────────────────────
   25. MIO TWO-PANEL LAYOUT
   ───────────────────────────────────────────────────────────────────────────── */
.mio-wrap       { padding: 0.875rem 1.5rem 0; display: flex; flex-direction: column; gap: 0.625rem; }
.mio-example    { background-color: var(--blue-light); border: 1px solid var(--blue-border); border-radius: var(--radius-md); overflow: hidden; }
[data-theme="dark"] .mio-example,
.theme-dark .mio-example { background-color: #1a2d45; border-color: #2d4a6e; }

.mio-label      { background-color: var(--blue-label-bg); color: var(--blue-dark); font-size: 0.72rem; font-weight: 700; padding: 0.5rem 0.875rem; letter-spacing: 0.4px; text-transform: uppercase; }
[data-theme="dark"] .mio-label,
.theme-dark .mio-label { background-color: #1e3a5f; }

.mio-steps      { padding: 0.625rem 0.875rem; font-family: 'Courier New', Courier, monospace; font-size: 0.82rem; line-height: 1.8; color: var(--body-color); overflow-x: auto; white-space: pre; }
.mio-new-input  { background-color: var(--gold-light); border: 2px solid var(--gold); border-radius: var(--radius-md); overflow: hidden; }
[data-theme="dark"] .mio-new-input,
.theme-dark .mio-new-input { background-color: #2d2410; }

.mio-new-input .mio-label { background-color: var(--gold); color: var(--blue-dark); }
.mio-new-input .mio-steps { font-weight: 700; color: var(--body-color); font-size: 0.88rem; }

/* ─────────────────────────────────────────────────────────────────────────────
   26. CHEATING PREVENTION OVERLAY
   ───────────────────────────────────────────────────────────────────────────── */
.cheat-overlay {
  background: rgba(15,15,15,.97);
  z-index: 9999;
  color: #fff;
  text-align: center;
  padding: 2.5rem;
  flex-direction: column;
}

.cheat-overlay[open]    { display: flex; }
.cheat-overlay-icon     { font-size: 3rem; margin-bottom: 1rem; }
.cheat-title            { font-size: 1.3rem; font-weight: 800; color: var(--timer-danger-color); margin-bottom: 0.625rem; }
.cheat-msg              { font-size: 0.9rem; color: rgba(255,255,255,.85); line-height: 1.7; max-width: 500px; }
.cheat-count            { font-size: 0.82rem; color: var(--gold); margin-top: 0.75rem; font-weight: 700; }

.cheat-btn {
  margin-top: 1.5rem;
  padding: 0.75rem 2rem;
  background-color: var(--blue-mid);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-main);
  min-height: 44px;
  min-width: 44px;
}

.cheat-btn:hover       { background-color: var(--blue-dark); }
.cheat-btn:focus-visible { outline-color: var(--gold); outline-offset: 3px; }

/* ─────────────────────────────────────────────────────────────────────────────
   27. FULLSCREEN ENFORCEMENT OVERLAY
   ───────────────────────────────────────────────────────────────────────────── */
.fullscreen-overlay {
  background: rgba(8,16,32,.97);
  z-index: 9998;
  color: #fff;
  text-align: center;
  padding: 2.5rem;
  flex-direction: column;
}

.fullscreen-overlay[open] { display: flex; }
.fs-overlay-icon  { font-size: 3.5rem; margin-bottom: 1.25rem; }
.fs-overlay-title { font-size: 1.4rem; font-weight: 800; color: var(--gold); margin-bottom: 0.75rem; line-height: 1.3; }
.fs-overlay-msg   { font-size: 0.9rem; color: rgba(255,255,255,.85); max-width: 480px; line-height: 1.7; margin-bottom: 1.5rem; }
.fs-overlay-btn   {
  padding: 0.75rem 2rem;
  background-color: var(--gold);
  color: var(--blue-dark);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-main);
  min-height: 44px;
  min-width: 44px;
}

.fs-overlay-btn:hover  { background-color: var(--gold-dark, #b07200); }
.fs-overlay-btn:focus-visible { outline-color: #fff; outline-offset: 3px; }

/* ─────────────────────────────────────────────────────────────────────────────
   28. DIRECTION HEADER BAR
   ───────────────────────────────────────────────────────────────────────────── */
.direction-bar { 
    display: flex; align-items: center; gap: 0.625rem; background-color: var(--blue-dark); padding: 0.5rem 1.5rem; flex-shrink: 0; }

.direction-label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; 
    color: var(--gold); white-space: nowrap; flex-shrink: 0; }

.direction-text { font-size: 0.82rem; font-weight: 600; color: #fff; line-height: 1.35; }

/* ─────────────────────────────────────────────────────────────────────────────
   29. PARTS LIST (vertical stacked parts in question text)
   ───────────────────────────────────────────────────────────────────────────── */
.parts-intro { font-size: 1rem; line-height: 1.75; color: var(--body-color); margin-bottom: 0.75rem; }
.parts-list  { display: flex; flex-direction: column; gap: 0.5rem; margin: 0; padding: 0; list-style: none; }

.parts-list-item {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.625rem 0.875rem;
  background-color: var(--blue-light);
  border: 1px solid var(--blue-border);
  border-left: 3px solid var(--blue-mid);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--body-color);
}

[data-theme="dark"] .parts-list-item,
.theme-dark .parts-list-item { background-color: #1a2d45; border-color: #2d4a6e; }

.parts-list-item .part-label { font-weight: 700; color: var(--blue-mid); min-width: 28px; flex-shrink: 0; margin-top: 1px; }

.question-text-hi .parts-list-item { font-family: var(--font-hindi); font-size: 0.95rem; line-height: 1.9; }

/* ─────────────────────────────────────────────────────────────────────────────
   30. ZOOM LIGHTBOX
   ───────────────────────────────────────────────────────────────────────────── */
.zoom-lightbox {
  background: rgba(0,0,0,.92);
  z-index: 5000;
  cursor: zoom-out;
  padding: 1.25rem;
}

.zoom-lightbox[open] { display: flex; }

.zoom-lightbox img,
.zoom-lightbox svg {
  max-width: 94vw;
  max-height: 90vh;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 60px rgba(0,0,0,.6);
  background-color: #fff;
  padding: 0.75rem;
}

.zoom-lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  background-color: rgba(255,255,255,.18);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.zoom-lightbox-close:hover  { background-color: rgba(255,255,255,.35); }
.zoom-lightbox-close:focus-visible { outline-color: var(--gold); outline-offset: 3px; }

.zoom-lightbox figure {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  margin: 0;
}

/* ─────────────────────────────────────────────────────────────────────────────
   31. TOAST NOTIFICATIONS
   ───────────────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 4000;
  pointer-events: none;
  align-items: center;
}

/* Scoped under .toast-container so these rules only apply to master.css's
   own toast system (mains.html), not to core-ui.css's .toast class. */
.toast-container .toast {
  background-color: var(--blue-dark);
  color: #fff;
  padding: 0.625rem 1.25rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  max-width: 340px;
  text-align: center;
  line-height: 1.4;
  animation: toastIn 0.25s ease both;
}

.toast-container .toast.toast-success { background-color: var(--green); }
.toast-container .toast.toast-warn    { background-color: var(--orange); }
.toast-container .toast.toast-error   { background-color: var(--red); }

@keyframes toastIn  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
/* toastOut applied by JS classList before removal: toast.classList.add('toast-out') */
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-8px); } }

/* ─────────────────────────────────────────────────────────────────────────────
   32. PWA INSTALL BANNER
   ───────────────────────────────────────────────────────────────────────────── */
.pwa-banner {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 0.625rem;
  background-color: var(--blue-dark);
  color: #fff;
  padding: 0.5rem 1.25rem;
  font-size: 0.82rem;
  flex-shrink: 0;
  z-index: 95;
}

.pwa-banner.visible { display: flex; }
.pwa-banner-msg      { flex: 1; }
.pwa-banner-actions  { display: flex; gap: 0.5rem; }

.pwa-install-btn {
  padding: 0.375rem 0.875rem;
  background-color: var(--gold);
  color: var(--blue-dark);
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: var(--font-main);
  min-height: 32px;
  min-width: 32px;
}

.pwa-dismiss-btn {
  padding: 0.375rem 0.625rem;
  background-color: transparent;
  color: rgba(255,255,255,.72);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.78rem;
  font-family: var(--font-main);
  min-height: 32px;
  min-width: 32px;
}

.pwa-install-btn:hover  { background-color: var(--gold-dark, #b07200); }
.pwa-dismiss-btn:hover  { background-color: rgba(255,255,255,.1); color: #fff; }
.pwa-install-btn:focus-visible,
.pwa-dismiss-btn:focus-visible { outline-color: var(--gold); }

/* ─────────────────────────────────────────────────────────────────────────────
   33. SCROLLBAR STYLES (Firefox + WebKit)
   ───────────────────────────────────────────────────────────────────────────── */
/* Firefox — uses the same tokens defined in the @supports block below */
* {
  scrollbar-width: thin;
  scrollbar-color: #b0b8c4 transparent;
}

[data-theme="dark"] *,
.theme-dark * { scrollbar-color: #3d4455 transparent; }

/* Standard scrollbar — Firefox 64+ (scrollbar-color / scrollbar-width).
   These properties are ignored by Chrome/Safari which use the ::-webkit- API. */
:root {
  scrollbar-color: #b0b8c4 transparent;
  scrollbar-width: thin;
}
[data-theme="dark"],
.theme-dark {
  scrollbar-color: #3d4455 transparent;
}

/* WebKit scrollbar — Chrome/Safari/Edge only.
   Wrapped in @supports selector() so Firefox never attempts to parse
   ::-webkit-scrollbar-thumb:hover (which it logged as "Unknown property"). */
@supports selector(::-webkit-scrollbar) {
  :root {
    --scrollbar-thumb:       #b0b8c4;
    --scrollbar-thumb-hover: #8a95a3;
  }
  [data-theme="dark"],
  .theme-dark {
    --scrollbar-thumb:       #3d4455;
    --scrollbar-thumb-hover: #4f5869;
  }

  ::-webkit-scrollbar       { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb {
    background:    var(--scrollbar-thumb);
    border-radius: 10px;
    /* ::-webkit-scrollbar-thumb:hover is intentionally omitted.
       Firefox rejects it as a bad selector even inside
       @supports selector(::-webkit-scrollbar), because the browser
       validates selectors before evaluating the @supports condition.
       Chrome/Safari show native OS-level hover feedback without a
       CSS rule; Firefox uses scrollbar-color defined above.         */
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   34. HIGH CONTRAST / FORCED COLORS MODE  (WCAG 1.4.11, 1.4.3)
   ───────────────────────────────────────────────────────────────────────────── */
@media (prefers-contrast: more) {
  :root {
    --blue-mid:    #003380;
    --green:       #0d5c28;
    --red:         #8b0000;
    --orange:      #8b4513;
    --grey-text:   #222;
    --grey-border: #555;
    --focus-ring-width: 4px;
  }

  .option-row,
  .btn,
  .palette-btn,
  .hdr-icon-btn,
  .fs-btn,
  .sec-tab,
  .modal-box,
  .engine-error,
  .passage-block {
    border-width: 2px !important;
    border-style: solid !important;
  }

  .option-row:focus-within,
  .palette-btn:focus-visible,
  .btn:focus-visible {
    outline-width: 4px;
  }

  .difficulty-badge { border-width: 2px; }
  .legend-dot       { border-width: 2px; border-color: #000; }
}

/* Windows High Contrast Mode (forced-colors) — WCAG 1.4.11 */
@media (forced-colors: active) {
  .option-row,
  .palette-btn,
  .btn,
  .sec-tab,
  .modal-box {
    forced-color-adjust: none;
    border: 2px solid CanvasText;
  }

  .option-row.selected { border-style: dashed; }
  .option-row:hover    { outline: 2px solid Highlight; }

  .palette-btn.answered        { border-color: CanvasText; background: Canvas; }
  .palette-btn.not-answered    { border: 3px solid CanvasText; }
  .palette-btn.marked          { border-style: double; }
  .palette-btn.active-question { outline: 3px solid Highlight; }

  .btn:focus-visible,
  .palette-btn:focus-visible,
  .sec-tab:focus-visible {
    outline: 3px solid Highlight;
    outline-offset: 2px;
  }

  .timer-display.timer-danger { color: Mark; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   35. RESPONSIVE — TABLET (≤900 px)
   ───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .exam-sidebar { width: 220px; }
  .sec-tab      { min-width: 120px; padding: 0 0.75rem; }
  .candidate-info { display: none; }
  .logo-subtitle  { display: none; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   36. RESPONSIVE — MOBILE (≤768 px)  (WCAG 1.4.10 Reflow at 320px equivalent)
   ───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .top-header      { padding: 0 0.75rem; height: 52px; gap: 0.5rem; }
  .logo-text       { display: none; }
  .logo-divider    { display: none; }
  .candidate-block { display: none; }

  .section-bar     { height: auto; flex-wrap: wrap; }
  .section-tabs    { height: 44px; }
  .sec-tab         { min-width: 90px; padding: 0 0.625rem; }
  .sec-name        { font-size: 0.72rem; }
  .sec-meta        { display: none; }

  .timer-panel     { padding: 0 0.625rem; }
  .timer-block     { min-width: 52px; }
  .timer-display   { font-size: 0.95rem; }
  .timer-label     { font-size: 0.55rem; }

  .exam-body       { position: relative; }
  .question-panel  { border-right: none; }

  .exam-sidebar {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    z-index: 300;
    transform: translateX(100%);
    box-shadow: var(--shadow-lg);
  }

  .exam-sidebar.sidebar-open { transform: translateX(0); }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0,0,0,.45);
    z-index: 299;
  }

  .sidebar-backdrop.visible { display: block; }
  .sidebar-toggle           { display: flex; }

  .question-meta-row        { padding: 0.5rem 0.875rem; flex-wrap: wrap; gap: 0.375rem; }
  .question-marks-badge     { padding: 0.25rem 0.625rem; font-size: 0.72rem; }

  .passage-block            { margin: 0.625rem 0.875rem 0; }
  .passage-text             { font-size: 0.82rem; max-height: 120px; }

  .question-text-box        { padding: 0.875rem 0.875rem 0; }
  .question-text,
  .question-text-hi         { font-size: 0.95rem; }

  .options-list             { padding: 0.75rem 0.875rem; gap: 0.5rem; }
  .option-row               { padding: 0.875rem 0.75rem; min-height: 52px; }

  .action-bar               { flex-direction: column; padding: 0.625rem 0.875rem; gap: 0.5rem; }
  .action-left,
  .action-right             { width: 100%; justify-content: stretch; }
  .action-left .btn,
  .action-right .btn        { flex: 1; justify-content: center; min-height: 48px; }

  .modal-stats              { grid-template-columns: repeat(2, 1fr); }
  .modal-footer             { flex-direction: column-reverse; gap: 0.5rem; }
  .modal-footer .btn        { width: 100%; justify-content: center; }

  .error-state              { padding: 1.5rem 1rem; }
  .q-top-zone               { max-height: 38%; }
  .fs-overlay-title         { font-size: 1.1rem; }
  .fs-overlay-msg           { font-size: 0.82rem; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   37. RESPONSIVE — SMALL MOBILE (≤480 px)
   ───────────────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .top-header    { height: 48px; }
  .logo-mark     { font-size: 0.85rem; padding: 0.2rem 0.5rem; }
  .section-bar   { height: 40px; }
  .section-tabs  { height: 40px; }
  .sec-tab       { min-width: 80px; padding: 0 0.5rem; }
  .btn           { font-size: 0.78rem; padding: 0.5rem 0.75rem; min-height: 48px; }
  .option-row    { min-height: 50px; padding: 0.75rem 0.625rem; }
  .modal-stats   { grid-template-columns: repeat(2, 1fr); }
  .palette-grid  { grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 0.375rem; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   38. SHARED / UTILITY COMPONENTS
   ───────────────────────────────────────────────────────────────────────────── */

/* ── Screen-reader only utility — WCAG compatible hiding ── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Show on focus for skip links — WCAG 2.4.1 Bypass Blocks */
.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  background: var(--blue-dark);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: top 0.2s;
}

.skip-link:focus {
  top: 0;
  outline: var(--focus-ring-width) solid var(--gold);
  outline-offset: 0;
}

/* ── Start button hint ── */
.start-btn-hint {
  font-size: 0.72rem;
  color: var(--grey-text);
  text-align: center;
  margin-top: 0.5rem;
  display: block;
  line-height: 1.4;
}

/* ── Visually hidden but accessible ── */
[hidden] { display: none !important; }

/* ── Reduced motion for banner animations ── */
@media (prefers-reduced-motion: reduce) {
  .expiry-warning-banner { animation: none; }
  .loading-spinner       { animation: none; border: 4px solid var(--gold); }
}

/* ─────────────────────────────────────────────────────────────────────────────
   39. MAINS MODE OVERRIDES
   ───────────────────────────────────────────────────────────────────────────── */
body.mains-mode .sec-tab.completed {
  background-color: var(--meta-row-bg);
  opacity: 0.55;
  cursor: not-allowed;
}

body.mains-mode .sec-tab.completed .sec-name {
  color: var(--grey-text);
  text-decoration: line-through;
  text-decoration-color: var(--grey-border);
}

body.mains-mode .sec-tab.completed::after {
  content: '\2713';
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 0.7rem;
  color: var(--green);
  font-weight: 800;
}

body.mains-mode .sec-tab:not(.active):not(.completed):not(.locked) {
  opacity: 0.6;
  cursor: not-allowed;
}

body.mains-mode .sec-tab:not(.active):not(.completed):not(.locked)::after {
  content: '\2192';
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 0.7rem;
  color: var(--grey-text);
}

body.mains-mode .timer-label {
  font-size: 0.58rem;
  max-width: 80px;
  text-align: center;
  line-height: 1.3;
  word-break: break-word;
}

body.mains-mode[data-theme="dark"] .sec-tab.completed,
body.mains-mode.theme-dark .sec-tab.completed { background-color: var(--grey-bg); }

/* ── Marks per question indicator ── */
.sec-marksq { font-size: 0.62rem; color: var(--gold); font-weight: 700; margin-top: 1px; }
.marking-table .marksq-cell { color: var(--green); font-weight: 700; }
.expiry-warning-banner[hidden] { display: none !important; }
.section-locked-banner[hidden] { display: none !important; }

/* ═══════════════════════════════════════════════════════════════════════════════
   END OF FILE
   ═══════════════════════════════════════════════════════════════════════════════ */
