/* ==========================================================================
   LIQUID GLASS: ambient backdrop, top bar + profile menu, department picker
   Loaded last. Glass mode is the default; <html data-glass="lite"> swaps every
   token below for a flat solid surface, so the two modes look clearly different.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
:root {
  --glass-fill: rgba(255, 255, 255, 0.50);
  --glass-fill-strong: rgba(255, 255, 255, 0.68);
  --glass-fill-pop: rgba(255, 255, 255, 0.46);
  --glass-bar: rgba(255, 255, 255, 0.52);
  --glass-inner: rgba(255, 255, 255, 0.48);
  --glass-border: rgba(255, 255, 255, 0.78);
  --glass-inner-border: rgba(100, 116, 139, 0.26);
  --glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.95);
  --glass-shadow: 0 14px 44px rgba(30, 41, 90, 0.13);
  --glass-blur: blur(22px) saturate(170%);
  --glass-blur-pop: blur(30px) saturate(190%);
  --glass-hover: rgba(15, 23, 42, 0.06);
  --glass-lens: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.62));
  --glass-lens-border: rgba(255, 255, 255, 0.95);
  --glass-lens-shadow: inset 0 1px 0 #fff, 0 6px 18px rgba(30, 41, 90, 0.14);
  --page-base: #edf1fa;
  --page-ambient:
    radial-gradient(78vmax 78vmax at 4% -6%, rgba(56, 189, 248, 0.62), transparent 64%),
    radial-gradient(72vmax 72vmax at 104% 6%, rgba(167, 139, 250, 0.58), transparent 64%),
    radial-gradient(76vmax 76vmax at 90% 106%, rgba(52, 211, 153, 0.50), transparent 64%),
    radial-gradient(70vmax 70vmax at -6% 98%, rgba(251, 146, 190, 0.52), transparent 64%),
    radial-gradient(60vmax 44vmax at 50% 46%, rgba(129, 140, 248, 0.26), transparent 70%);
}

[data-theme="dark"] {
  --glass-fill: rgba(17, 25, 45, 0.46);
  --glass-fill-strong: rgba(13, 19, 36, 0.66);
  --glass-fill-pop: rgba(24, 32, 54, 0.48);
  --glass-bar: rgba(10, 15, 30, 0.50);
  --glass-inner: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.14);
  --glass-inner-border: rgba(255, 255, 255, 0.14);
  --glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.16);
  --glass-shadow: 0 18px 50px rgba(0, 0, 0, 0.48);
  --glass-hover: rgba(255, 255, 255, 0.08);
  --glass-lens: linear-gradient(180deg, rgba(255, 255, 255, 0.20), rgba(255, 255, 255, 0.09));
  --glass-lens-border: rgba(255, 255, 255, 0.24);
  --glass-lens-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 8px 20px rgba(0, 0, 0, 0.35);
  --page-base: #060a15;
  --page-ambient:
    radial-gradient(78vmax 78vmax at 4% -6%, rgba(14, 165, 233, 0.46), transparent 64%),
    radial-gradient(72vmax 72vmax at 104% 6%, rgba(139, 92, 246, 0.46), transparent 64%),
    radial-gradient(76vmax 76vmax at 90% 106%, rgba(16, 185, 129, 0.34), transparent 64%),
    radial-gradient(70vmax 70vmax at -6% 98%, rgba(236, 72, 153, 0.32), transparent 64%),
    radial-gradient(60vmax 44vmax at 50% 46%, rgba(99, 102, 241, 0.20), transparent 70%);
}

/* Lite mode: same components, flat solid surfaces, no blur, no ambient colour */
[data-glass="lite"] {
  --glass-fill: var(--bg-secondary);
  --glass-fill-strong: var(--bg-secondary);
  --glass-fill-pop: var(--bg-secondary);
  --glass-bar: var(--bg-secondary);
  --glass-inner: var(--bg-primary);
  --glass-border: var(--border-light);
  --glass-inner-border: var(--border-medium);
  --glass-highlight: 0 0 0 transparent;
  --glass-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  --glass-blur: none;
  --glass-blur-pop: none;
  --glass-lens: var(--bg-accent);
  --glass-lens-border: transparent;
  --glass-lens-shadow: 0 0 0 transparent;
}

/* --------------------------------------------------------------------------
   2. Ambient backdrop: fixed colour fields the glass has something to refract
   -------------------------------------------------------------------------- */
html:not([data-glass="lite"]) body {
  background: var(--page-base);
}

html:not([data-glass="lite"]) body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--page-ambient);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   3. Top bar: brand, XP, calculator and one profile menu
   -------------------------------------------------------------------------- */
header.app-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: transparent;
  border-bottom: none;
  box-shadow: none;
}

/* The frosted layer sits on a pseudo-element so the menu that drops out of the
   header can blur the page itself (nested backdrop-filters cannot). */
header.app-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--glass-bar);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
}

.header-container {
  flex-wrap: nowrap;
  padding: 0.55rem 1.25rem;
  gap: 0.75rem;
}

.brand-section {
  min-width: 0;
  gap: 0.6rem;
}

.brand-info {
  min-width: 0;
}

.brand-info h1 {
  font-size: 1.02rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The tagline only has room on the wide welcome screen */
.brand-info p {
  display: none;
}

@media (min-width: 1024px) {
  body[data-screen="welcome"] .brand-info p {
    display: block;
  }
}

.header-actions {
  flex-shrink: 0;
  gap: 0.5rem;
}

.header-actions .btn-icon,
.header-menu-btn,
#header-xp-badge {
  background: var(--glass-inner);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-highlight);
}

#header-xp-badge {
  height: 38px;
  padding: 0 0.75rem;
  color: #9333ea;
}

[data-theme="dark"] #header-xp-badge {
  color: #d8b4fe;
}

.header-actions .btn-icon {
  border-radius: 999px;
  color: var(--text-secondary);
}

.header-menu-wrap {
  position: relative;
}

.header-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 38px;
  padding: 0 0.6rem 0 0.3rem;
  border-radius: 999px;
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
  transition: background 0.2s ease;
}

.header-menu-btn:hover,
.header-actions .btn-icon:hover {
  background: var(--glass-fill-strong);
}

.header-menu-btn .candidate-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}

.header-menu-btn-label {
  max-width: 9rem;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-menu-chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.header-menu-btn[aria-expanded="true"] .header-menu-chevron {
  transform: rotate(180deg);
}

/* Calculator: the "FULL" tag sits as a small, still badge on the button's corner */
#btn-calc-toggle {
  width: 38px;
  height: 38px;
  padding: 0;
}

#btn-calc-toggle .calc-pro-pill {
  top: -4px;
  right: -6px;
  padding: 2px 4px;
  font-size: 0.5rem;
  letter-spacing: 0.04em;
  border-radius: 999px;
  box-shadow: 0 0 0 2px var(--bg-secondary, #fff);
  animation: none;
}

/* Submit matches the height and shape of the other header controls */
#btn-submit-header {
  height: 38px;
  padding: 0 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  background: linear-gradient(180deg, #ef4444, #dc2626);
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

#btn-submit-header:hover {
  background: linear-gradient(180deg, #dc2626, #b91c1c);
}

/* During an exam the bar holds: timer on the left, tools on the right */
body[data-screen="exam"] #header-timer {
  margin-right: auto;
}

/* Profile & settings popover */
.header-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  width: min(290px, calc(100vw - 24px));
  padding: 0.45rem;
  border-radius: 20px;
  background: var(--glass-fill-pop);
  -webkit-backdrop-filter: var(--glass-blur-pop);
  backdrop-filter: var(--glass-blur-pop);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), var(--glass-highlight);
  transform-origin: top right;
  animation: glass-pop 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.header-menu[hidden],
.dept-dd-panel[hidden],
.dept-dd-opt[hidden],
.dept-dd-group[hidden],
.dept-dd-empty[hidden] {
  display: none !important;
}

@keyframes glass-pop {
  from { opacity: 0; transform: scale(0.94) translateY(-6px); }
  to { opacity: 1; transform: none; }
}

.header-menu-profile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.7rem 0.7rem;
}

.header-menu-profile .candidate-text strong {
  font-size: 0.95rem;
  word-break: break-word;
}

.header-menu-profile .badge-status-active {
  flex-shrink: 0;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  cursor: pointer;
}

.header-menu-profile .badge-status-active svg {
  width: 12px;
  height: 12px;
}

.header-menu-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.7rem;
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

.header-menu-row > svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.header-menu-row:hover,
.header-menu-row:focus-visible {
  background: var(--glass-hover);
  outline: none;
}

.header-menu-row-static {
  cursor: default;
}

.header-menu-row-static:hover {
  background: transparent;
}

.header-menu-row-label {
  flex: 1;
}

.header-menu-row-value {
  color: var(--text-secondary);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.header-menu-row > .header-menu-row-go {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

/* Department row once the access code is locked to a department */
.header-menu-row > .header-menu-row-lock {
  display: none;
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.header-menu-row.is-locked > .header-menu-row-go {
  display: none;
}

.header-menu-row.is-locked > .header-menu-row-lock {
  display: block;
}

.dept-dd-trigger:disabled {
  cursor: not-allowed;
  opacity: 0.8;
}

.dept-dd-trigger:disabled .dept-dd-chevron {
  display: none;
}

.header-menu-sep {
  height: 1px;
  margin: 0.35rem 0.7rem;
  background: var(--glass-hover);
}

/* iOS-style switch */
.menu-switch {
  position: relative;
  flex-shrink: 0;
  width: 42px;
  height: 25px;
  border-radius: 999px;
  background: rgba(120, 130, 150, 0.35);
  transition: background 0.22s ease;
}

.menu-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.28);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

[aria-checked="true"] > .menu-switch {
  background: #22c55e;
}

[aria-checked="true"] > .menu-switch::after {
  transform: translateX(17px);
}

@media (max-width: 640px) {
  .header-container {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }

  .brand-info h1 {
    font-size: 0.95rem;
  }

  .header-menu-btn {
    padding: 0 0.3rem;
  }

  .header-menu-btn-label,
  .header-menu-chevron,
  .submit-label-long {
    display: none;
  }

  /* During an exam the timer and Submit need the room more than the brand does */
  body[data-screen="exam"] .brand-section {
    display: none;
  }

  body[data-screen="exam"] .header-actions {
    gap: 0.45rem;
  }

  #header-timer {
    padding: 0 0.75rem 0 0.6rem;
  }

  #btn-submit-header {
    padding: 0 0.9rem;
  }

  /* Phones: less nested padding so text gets the width instead of the borders */
  .main-wrapper {
    padding: 0.85rem 0.75rem 1.5rem;
  }

  .welcome-view {
    padding: 0.5rem 0 2rem;
  }

  .welcome-hero-banner {
    margin-bottom: 1.25rem;
  }

  .welcome-main-title {
    font-size: 1.5rem;
  }

  .welcome-main-sub {
    font-size: 0.92rem;
  }

  .welcome-grid {
    gap: 1rem;
  }

  .welcome-box {
    padding: 1.15rem 1rem;
  }

  .box-title {
    font-size: 1.15rem;
  }

  .box-desc,
  .welcome-box p {
    max-width: none;
  }

  .dept-preview-card {
    padding: 0.85rem;
  }

  .mode-card {
    padding: 1rem 0.9rem;
  }

  .mode-card-header {
    gap: 0.75rem;
  }

  .mode-price-badge {
    flex-shrink: 0;
  }

  .welcome-input-row-grid {
    grid-template-columns: 1fr;
  }

  .btn-pro-submit {
    font-size: 0.9rem;
  }

  .freemium-banner {
    padding: 1.1rem 1rem !important;
    margin-bottom: 1rem !important;
  }

  .hero-card {
    padding: 1.25rem 1rem !important;
  }

  .course-cards-grid {
    grid-template-columns: 1fr;
  }

  .instructions-box {
    padding: 1rem !important;
  }
}

/* Modals cover everything, including the sticky header (1000) and floating unlock bar (998) */
.modal-overlay {
  z-index: 1200;
}

/* Results: "+50 XP earned" card (had no styles before) */
.results-xp-award {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.9rem 1.1rem;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.12), rgba(245, 158, 11, 0.1));
  border: 1px solid rgba(168, 85, 247, 0.25);
}

.results-xp-award .xp-star {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.18);
  font-size: 1.2rem;
}

.results-xp-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.results-xp-text > strong {
  font-size: 1rem;
  color: var(--text-primary);
}

/* Results upsell: perk text was near-white on a light card */
.upsell-header p {
  color: var(--text-secondary);
}

.upsell-perks-grid {
  background: var(--bg-tertiary);
}

.upsell-perk {
  position: relative;
  padding-left: 1.5rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.upsell-perk strong {
  color: var(--text-primary);
}

.upsell-perk svg {
  position: absolute;
  left: 0;
  top: 2px;
  width: 16px;
  height: 16px;
  color: #16a34a;
}

.theory-paper-short {
  display: none;
}

/* Keyboard-shortcut tips mean nothing on a touch screen */
@media (hover: none) and (pointer: coarse) {
  .instructions-list .kbd-only {
    display: none;
  }
}

@media (max-width: 640px) {
  /* Results screen */
  .results-view {
    gap: 1rem;
  }

  .score-hero-card {
    padding: 1.4rem 1rem 1.25rem !important;
    gap: 1.25rem;
  }

  .score-primary-info h2 {
    font-size: 1.4rem;
    line-height: 1.25;
  }

  .score-primary-info p {
    font-size: 0.92rem;
  }

  .score-gauge-box {
    width: 100%;
    flex-direction: column;
    gap: 1rem;
  }

  .score-circle {
    width: 120px;
    height: 120px;
  }

  .score-circle-inner {
    width: 94px;
    height: 94px;
  }

  .score-circle-inner .pct {
    font-size: 1.45rem;
  }

  .score-quick-stats {
    width: 100%;
    padding: 0.75rem 0.9rem;
    border-radius: 12px;
    background: var(--bg-tertiary);
  }

  .quick-stat-row {
    gap: 1rem;
    font-size: 0.88rem;
  }

  .quick-stat-row strong {
    text-align: right;
  }

  .weak-area-remediation-card {
    padding: 1.1rem 1rem !important;
    margin-bottom: 0 !important;
  }

  .weak-area-remediation-card h3 {
    font-size: 1.05rem;
  }

  .weak-area-remediation-card .btn {
    width: 100%;
    white-space: normal;
  }

  .topic-analytics-card {
    padding: 1.25rem 1rem !important;
  }

  .results-actions {
    flex-direction: column;
    gap: 0.6rem !important;
  }

  .results-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .freemium-upsell-card {
    padding: 1.25rem 1rem !important;
  }

  .upsell-header h3 {
    font-size: 1.2rem;
  }

  .upsell-perks-grid {
    grid-template-columns: 1fr;
    padding: 0.85rem;
  }

  #btn-open-unlock-results {
    width: 100%;
    justify-content: center;
    padding: 0.8rem 1rem !important;
    font-size: 0.95rem !important;
  }

  .review-header h3 {
    font-size: 1.2rem;
  }

  .review-question-card {
    padding: 1.15rem 1rem !important;
  }

  /* Theory screen */
  .theory-layout {
    gap: 1rem;
  }

  .theory-card {
    padding: 1.15rem 1rem !important;
    gap: 1rem;
  }

  .theory-meta-bar {
    padding-bottom: 0;
    gap: 0.5rem;
  }

  #btn-exit-theory {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
  }

  /* The pen-and-paper reminder shrinks to a single line so the question shows first */
  .theory-paper-banner {
    padding: 0.55rem 0.8rem;
    gap: 0.6rem;
  }

  .theory-paper-icon svg {
    width: 18px;
    height: 18px;
  }

  .theory-paper-text strong {
    display: none;
  }

  .theory-paper-short {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.35;
  }

  .theory-paper-text p {
    display: none;
  }

  .theory-question-text {
    font-size: 1.05rem;
    line-height: 1.65;
    padding: 0;
  }

  .marking-scheme-card,
  .lecturer-tip-card,
  .self-eval-card {
    padding: 1rem 0.85rem !important;
  }

  .final-answer-card {
    padding: 1rem 0.85rem;
  }

  .marking-step-item {
    flex-direction: column;
    gap: 0.4rem;
  }

  .marking-step-item .step-marks {
    order: -1;
    align-self: flex-start;
  }

  .self-eval-btns {
    flex-direction: column;
    gap: 0.5rem;
  }

  .btn-self-eval {
    justify-content: center;
  }

  /* Prev / Next side by side; the "Problem x of y" text is already in the badges */
  .theory-footer {
    gap: 0.6rem;
    margin-top: 0;
  }

  .theory-progress-pill {
    display: none;
  }

  .theory-footer .btn {
    flex: 1;
    white-space: nowrap;
    padding: 0.7rem 0.5rem;
    font-size: 0.88rem;
  }

  .theory-sidebar-card {
    position: static;
    padding: 1rem !important;
  }

  .theory-palette-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 0.4rem;
  }

  .theory-palette-btn {
    height: 40px;
  }
}

/* Wide maths (e.g. long fractions) scrolls inside its option instead of widening the page */
.option-content {
  min-width: 0;
  overflow-x: auto;
}

.main-wrapper {
  overflow-x: clip;
}

/* On small phones the logo alone stands for the brand once the student is inside */
@media (max-width: 420px) {
  body:not([data-screen="welcome"]) .brand-info {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   4. Page surfaces become glass (glass mode only; lite keeps the solid cards)
   -------------------------------------------------------------------------- */
html:not([data-glass="lite"]) .welcome-box,
html:not([data-glass="lite"]) .hero-card,
html:not([data-glass="lite"]) .palette-sidebar,
html:not([data-glass="lite"]) .score-hero-card,
html:not([data-glass="lite"]) .topic-analytics-card,
html:not([data-glass="lite"]) .fc-toolbar,
html:not([data-glass="lite"]) .fc-generator-panel {
  background: var(--glass-fill) !important;
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border) !important;
  box-shadow: var(--glass-shadow), var(--glass-highlight) !important;
}

/* Reading surfaces stay a little more solid so questions are easy on the eye */
html:not([data-glass="lite"]) .question-card,
html:not([data-glass="lite"]) .question-footer,
html:not([data-glass="lite"]) .theory-card {
  background: var(--glass-fill-strong) !important;
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border) !important;
  box-shadow: var(--glass-shadow), var(--glass-highlight) !important;
}

/* Panels nested inside a glass card: a lighter pane, no second blur */
html:not([data-glass="lite"]) .dept-preview-card,
html:not([data-glass="lite"]) .mode-free,
html:not([data-glass="lite"]) .welcome-input,
html:not([data-glass="lite"]) .mode-price-badge,
html:not([data-glass="lite"]) .mastery-map-card,
html:not([data-glass="lite"]) .instructions-box {
  background: var(--glass-inner) !important;
  border-color: var(--glass-inner-border) !important;
  box-shadow: var(--glass-highlight);
}

/* The department card must stack above the card after it on phones */
.welcome-dept-box {
  z-index: 2;
}

/* --------------------------------------------------------------------------
   5. Department picker
   -------------------------------------------------------------------------- */
.welcome-select-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  border: 0 !important;
  opacity: 0;
  pointer-events: none;
}

.dept-dd-trigger {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.65rem 0.85rem;
  border-radius: 14px;
  border: 1.5px solid var(--glass-inner-border);
  background: var(--glass-inner);
  box-shadow: var(--glass-highlight), 0 2px 10px rgba(15, 23, 42, 0.06);
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: box-shadow 0.2s ease, background 0.2s ease;
}

[data-glass="lite"] .dept-dd-trigger {
  box-shadow: none;
}

.dept-dd-trigger:hover {
  background: var(--glass-fill-strong);
}

.dept-dd-trigger:focus-visible,
.dept-dd-trigger[aria-expanded="true"] {
  outline: none;
  box-shadow: var(--glass-highlight), 0 0 0 3px rgba(59, 130, 246, 0.28);
}

.dept-dd-icon {
  flex-shrink: 0;
  width: 1.6rem;
  font-size: 1.2rem;
  line-height: 1;
  text-align: center;
}

.dept-dd-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}

.dept-dd-name {
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dept-dd-meta {
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-muted);
}

.dept-dd-chevron {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}

.dept-dd-trigger[aria-expanded="true"] .dept-dd-chevron {
  transform: rotate(180deg);
}

.dept-dd-panel {
  position: absolute;
  z-index: 900;
  padding: 0.45rem;
  border-radius: 20px;
  background: var(--glass-fill-pop);
  -webkit-backdrop-filter: var(--glass-blur-pop);
  backdrop-filter: var(--glass-blur-pop);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow), var(--glass-highlight);
  transform-origin: top center;
  animation: glass-pop 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.dept-dd-search {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.35rem;
  padding: 0.5rem 0.7rem;
  border-radius: 13px;
  background: var(--glass-hover);
}

.dept-dd-search svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.dept-dd-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 0.92rem;
}

.dept-dd-search input::placeholder {
  color: var(--text-muted);
}

.dept-dd-list {
  position: relative;
  max-height: min(340px, 52vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.dept-dd-group {
  position: relative;
  z-index: 1;
  padding: 0.65rem 0.7rem 0.25rem;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.dept-dd-opt {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 44px;
  padding: 0.5rem 0.7rem;
  border-radius: 13px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.dept-dd-opt-name {
  flex: 1;
  min-width: 0;
}

.dept-dd-code {
  padding: 0.12rem 0.42rem;
  border-radius: 6px;
  background: var(--glass-hover);
  color: var(--text-secondary);
  font-family: var(--font-mono, monospace);
  font-size: 0.7rem;
  font-weight: 700;
}

.dept-dd-check {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--primary-500, #3b82f6);
  stroke-width: 3;
  visibility: hidden;
}

.dept-dd-opt[aria-selected="true"] .dept-dd-check {
  visibility: visible;
}

/* The glass lens that glides to whichever row is hovered or focused */
.dept-dd-hl {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  border-radius: 13px;
  background: var(--glass-lens);
  border: 1px solid var(--glass-lens-border);
  box-shadow: var(--glass-lens-shadow);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.26s cubic-bezier(0.22, 1, 0.36, 1),
    height 0.2s ease,
    opacity 0.15s ease;
}

.dept-dd-empty {
  padding: 1rem 0.7rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 640px) {
  /* 16px stops iOS Safari zooming the page when the search box is focused */
  .dept-dd-search input {
    font-size: 16px;
  }
}

/* --------------------------------------------------------------------------
   6. Setup screen: test setup sheet, Daily 5, mastery map, small fixes
   -------------------------------------------------------------------------- */

/* Icon-only buttons: the shared .btn rule adds a right margin meant for a text
   label, which pushed the calculator icon off-centre */
.btn-icon .icon-svg-stroke {
  width: 18px;
  height: 18px;
  margin-right: 0;
}

/* Above the sticky header (1000), under the app's modals (1200) so the unlock dialog can open over it */
.setup-sheet {
  position: fixed;
  inset: 0;
  z-index: 1150;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.setup-sheet[hidden] {
  display: none;
}

body.sheet-open {
  overflow: hidden;
}

body.sheet-open .floating-unlock-bar {
  display: none !important;
}

.setup-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 24, 0.45);
  animation: sheet-fade 0.2s ease-out;
}

.setup-sheet-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 600px;
  /* leaves the top bar visible above the sheet */
  max-height: calc(100vh - 68px);
  max-height: calc(100dvh - 68px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  border-radius: 26px 26px 0 0;
  background: var(--glass-fill-strong);
  -webkit-backdrop-filter: var(--glass-blur-pop);
  backdrop-filter: var(--glass-blur-pop);
  border: 1px solid var(--glass-border);
  border-bottom: 0;
  box-shadow: 0 -12px 48px rgba(8, 12, 24, 0.28), var(--glass-highlight);
  outline: none;
  animation: sheet-up 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to { transform: none; }
}

@keyframes sheet-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.setup-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.1rem 0.75rem;
}

.setup-sheet-heading {
  min-width: 0;
}

.setup-sheet-code {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  color: var(--primary-500, #3b82f6);
}

.setup-sheet-heading h3 {
  margin: 0.1rem 0 0;
  font-size: 1.12rem;
  font-weight: 800;
  line-height: 1.25;
  color: var(--text-primary);
}

.setup-sheet-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--glass-hover);
  color: var(--text-secondary);
  cursor: pointer;
}

.setup-sheet-close svg {
  width: 18px;
  height: 18px;
}

.setup-sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.25rem 1.1rem 0.5rem;
}

/* The course is already chosen by the card that opened the sheet */
.setup-sheet .config-field-subject {
  display: none;
}

.setup-sheet .config-grid {
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 0 0 0.9rem;
}

/* Topic spans the row; question count and duration share the next one */
.setup-sheet .config-grid .config-field:nth-child(2) {
  grid-column: 1 / -1;
}

.setup-sheet .config-field {
  gap: 0.3rem;
  min-width: 0;
  margin-bottom: 0 !important;
}

.setup-sheet .config-field label {
  font-size: 0.78rem;
}

.setup-sheet .config-select {
  padding: 0.6rem 0.7rem;
  font-size: 0.9rem;
  text-overflow: ellipsis;
}

/* Multi-select topic picker (tick one or more topics) */
.topic-picker-hint {
  font-weight: 500;
  color: var(--text-muted);
}

.topic-picker-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  text-align: left;
  cursor: pointer;
}

.topic-picker-label {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.topic-picker-chevron {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.topic-picker-trigger[aria-expanded="true"] .topic-picker-chevron {
  transform: rotate(180deg);
}

.topic-picker-list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-height: 260px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.35rem;
  background: var(--bg-tertiary);
  border: 1.5px solid var(--border-medium);
  border-radius: var(--radius-md);
}

.topic-picker-list[hidden] {
  display: none;
}

.topic-opt {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  font-size: 0.86rem;
  line-height: 1.3;
  color: var(--text-primary);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}

.topic-opt:hover {
  background: rgba(59, 130, 246, 0.08);
}

.topic-opt input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.topic-opt-box {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-medium);
  border-radius: 5px;
  background: var(--bg-secondary);
  display: grid;
  place-items: center;
}

.topic-opt input:checked + .topic-opt-box {
  background: var(--primary-500);
  border-color: var(--primary-500);
}

.topic-opt input:checked + .topic-opt-box::after {
  content: "";
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}

.topic-opt input:focus-visible + .topic-opt-box {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

.topic-opt-name {
  flex: 1;
  min-width: 0;
}

.topic-opt-count {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.topic-opt.is-locked .topic-opt-name {
  color: var(--text-muted);
}

.setup-sheet .mode-cards {
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-top: 0.2rem;
}

.setup-sheet .mode-card {
  min-width: 0;
  padding: 0.65rem 0.75rem;
}

.setup-sheet .mode-card h4 {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.25;
}

/* One line of help per mode on phones would double the sheet's height */
.setup-sheet .mode-card p {
  display: none;
}

.setup-sheet-foot {
  padding: 0.75rem 1.1rem 0.9rem;
}

.setup-sheet-foot #btn-start-exam {
  width: 100%;
  min-height: 50px;
  padding: 0.75rem 1rem;
}

@media (min-width: 720px) {
  .setup-sheet {
    align-items: center;
    padding: 1.5rem;
  }

  .setup-sheet-panel {
    max-width: 660px;
    max-height: calc(100vh - 120px);
    border-radius: 26px;
    border-bottom: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow), var(--glass-highlight);
    animation: glass-pop 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .setup-sheet .mode-card p {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.76rem;
    line-height: 1.4;
  }
}

/* Mastery map: collapsible on phones, always open on larger screens */
.mastery-toggle {
  display: none;
}

@media (max-width: 640px) {
  .daily5-banner {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    margin-top: 1.1rem;
    margin-bottom: 1.4rem;
  }

  /* Flow the icon, title and PRO tag as one line of text so they wrap together */
  .daily5-text h4 {
    display: block;
    line-height: 1.35;
  }

  .daily5-text h4 > svg {
    margin-right: 0.3rem;
    vertical-align: -0.2em;
  }

  .daily5-text h4 .badge-pro-tag {
    margin-left: 0.3rem;
    vertical-align: 0.1em;
  }

  /* A shorter hero keeps the course list near the top of the phone screen */
  #setup-hero-title {
    font-size: 1.5rem;
    line-height: 1.2;
  }

  #setup-hero-desc {
    font-size: 0.9rem;
    line-height: 1.5;
  }

  .daily5-text p {
    margin-top: 0.35rem;
    font-size: 0.8rem;
    line-height: 1.45;
  }

  .btn-daily5 {
    width: 100%;
    min-height: 44px;
    white-space: normal;
  }

  .mastery-map-card {
    padding: 0.85rem 1rem;
  }

  .mastery-map-header {
    flex-wrap: nowrap;
    margin-bottom: 0;
  }

  .mastery-map-card.is-open .mastery-map-header {
    flex-wrap: wrap;
    margin-bottom: 0.85rem;
  }

  .mastery-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-left: auto;
    min-height: 36px;
    padding: 0 0.7rem;
    border: 1px solid var(--glass-inner-border);
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
  }

  .mastery-toggle svg {
    width: 14px;
    height: 14px;
    transition: transform 0.2s ease;
  }

  .mastery-toggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
  }

  .mastery-map-card:not(.is-open) .mastery-legend,
  .mastery-map-card:not(.is-open) #btn-drill-weak-topics,
  .mastery-map-card:not(.is-open) .mastery-tiles-grid {
    display: none;
  }

  .mastery-map-card.is-open .mastery-legend {
    flex-wrap: wrap;
    order: 3;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .header-menu,
  .dept-dd-panel,
  .setup-sheet-panel,
  .setup-sheet-backdrop {
    animation: none;
  }

  .dept-dd-hl,
  .menu-switch,
  .menu-switch::after {
    transition: none;
  }
}

/* Browsers without backdrop-filter get a near-solid pane instead of see-through text */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  :root {
    --glass-fill: rgba(255, 255, 255, 0.94);
    --glass-fill-strong: rgba(255, 255, 255, 0.97);
    --glass-fill-pop: rgba(255, 255, 255, 0.97);
    --glass-bar: rgba(255, 255, 255, 0.95);
  }

  [data-theme="dark"] {
    --glass-fill: rgba(17, 25, 45, 0.94);
    --glass-fill-strong: rgba(13, 19, 36, 0.97);
    --glass-fill-pop: rgba(24, 32, 54, 0.97);
    --glass-bar: rgba(10, 15, 30, 0.95);
  }
}

/* Second line under an option name in the shared glass picker (flashcard deck preferences) */
.glass-dd-opt-meta {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-muted);
}
