/* WhiteDevil question bank. One stylesheet, no framework.
   Tokens and rules are documented in Design.md (Linear-derived system,
   WhiteDevil red as the single accent). Dark is the default canvas. */

@font-face {
  font-family: "Deltarune";
  src: url("/fonts/deltarune.ttf") format("truetype");
  font-display: swap;
}

/* ---------- tokens ---------- */

:root {
  color-scheme: light;
  --canvas: #ffffff;
  --surface-1: #f6f6f7;
  --surface-2: #efeff1;
  --surface-3: #e7e7ea;
  --hairline: #e4e4e7;
  --hairline-strong: #d1d1d6;
  --ink: #111113;
  --ink-muted: #3f3f46;
  --ink-subtle: #686872;
  --ink-tertiary: #9a9aa3;

  --accent: #e8091a;
  --accent-hover: #cf0817;
  --accent-press: #b00716;
  --accent-ink: #c00615;
  --accent-soft: rgba(232, 9, 26, 0.07);
  --accent-line: rgba(232, 9, 26, 0.38);

  --ok: #16753a;
  --ok-soft: rgba(22, 117, 58, 0.08);
  --ok-line: rgba(22, 117, 58, 0.42);
  --bad: #c00615;
  --bad-soft: rgba(232, 9, 26, 0.07);
  --bad-line: rgba(232, 9, 26, 0.42);

  --focus: rgba(232, 9, 26, 0.5);
  --scrim: rgba(9, 9, 11, 0.48);
  --pop-shadow: 0 18px 48px -16px rgba(9, 9, 11, 0.28), 0 2px 6px rgba(9, 9, 11, 0.06);
  --bar-bg: rgba(255, 255, 255, 0.86);

  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-pill: 999px;

  --gutter: 16px;
  --topbar-h: 56px;
  --stepper-h: 64px;
  --reading: 42rem;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);      /* entrances: quick start, long settle */
  --ease-in: cubic-bezier(0.4, 0, 1, 1);          /* exits: gather speed and leave */
  --ease-sheet: cubic-bezier(0.32, 0.72, 0, 1);   /* sheets and drawers */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1); /* a small overshoot for answer keys */

  --z-bar: 20;
  --z-menu: 30;
  --z-gate: 40;
  --z-toast: 50;
}

html.dark {
  color-scheme: dark;
  --canvas: #09090b;
  --surface-1: #111114;
  --surface-2: #18181c;
  --surface-3: #202025;
  --hairline: #232328;
  --hairline-strong: #33333b;
  --ink: #f2f2f4;
  --ink-muted: #c9c9d1;
  --ink-subtle: #8d8d98;
  --ink-tertiary: #63636d;

  --accent: #e8091a;
  --accent-hover: #f5212f;
  --accent-press: #c8081a;
  --accent-ink: #ff5c68;
  --accent-soft: rgba(232, 9, 26, 0.13);
  --accent-line: rgba(255, 92, 104, 0.45);

  --ok: #4fc473;
  --ok-soft: rgba(79, 196, 115, 0.1);
  --ok-line: rgba(79, 196, 115, 0.42);
  --bad: #ff5c68;
  --bad-soft: rgba(232, 9, 26, 0.12);
  --bad-line: rgba(255, 92, 104, 0.45);

  --scrim: rgba(0, 0, 0, 0.62);
  --pop-shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --bar-bg: rgba(9, 9, 11, 0.82);
}

@media (min-width: 768px) {
  :root { --gutter: 24px; }
}

/* ---------- base ---------- */

*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--topbar-h) + env(safe-area-inset-top) + 8px);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  font-feature-settings: "ss01" 0;
}

h1, h2, h3, h4, p, dl, dd, figure { margin: 0; }

img, video { max-width: 100%; height: auto; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }
button:disabled { cursor: default; }

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hidden { display: none !important; }

.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;
}

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 1px 6px;
  border: 1px solid var(--hairline-strong);
  border-bottom-width: 2px;
  border-radius: var(--r-xs);
  background: var(--surface-1);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--hairline-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease),
    color 0.15s var(--ease), transform 0.1s var(--ease);
  user-select: none;
  -webkit-user-select: none;
}

.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: var(--accent-press); }

.btn-secondary {
  background: var(--surface-1);
  border-color: var(--hairline);
  color: var(--ink);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--hairline-strong); }

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-1); color: var(--ink); }

.btn-block { width: 100%; }
.btn-square { width: 48px; padding: 0; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  padding: 0;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--ink-muted);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { background: var(--surface-3); }

/* ---------- app shell ---------- */

.view { min-height: 100dvh; overflow-x: clip; }

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-bar);
  padding-top: env(safe-area-inset-top);
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--hairline);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 60rem;
  height: var(--topbar-h);
  margin: 0 auto;
  padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
}

.brand {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: var(--r-md);
}
.brand img { border-radius: 7px; }

.topbar-title {
  flex: 1;
  min-width: 0;
  padding: 0 4px;
}

.topbar-title h1 {
  overflow: hidden;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.2px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Main screen title only. Pixel font: normal weight, since a faux bold smears it. */
#dashboard-title.brand-title {
  font-family: "Deltarune", var(--font-sans);
  font-size: 26px;
  font-weight: 400;
  letter-spacing: 0;
}

.crumb {
  overflow: hidden;
  color: var(--ink-subtle);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.crumb:empty { display: none; }

.page {
  width: 100%;
  max-width: 48rem;
  margin: 0 auto;
  padding: 12px var(--gutter) calc(32px + env(safe-area-inset-bottom));
}

.page.reading { max-width: var(--reading); }

/* The member line only shows when there is something to act on. */
.member-summary { display: none; }
.member-summary.member-summary-warn {
  display: block;
  padding: 10px var(--gutter);
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent-line);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

/* ---------- account menu ---------- */

.account { position: relative; }

.avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin: 0 2px;
  padding: 0;
  border: 1px solid var(--hairline-strong);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink-muted);
}
.avatar { overflow: hidden; }
.avatar .icon { width: 19px; height: 19px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar img:not([hidden]) + .icon { display: none; }
.avatar:hover { color: var(--ink); border-color: var(--ink-tertiary); }
.avatar[aria-expanded="true"] { border-color: var(--accent); }

.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: var(--z-menu);
  display: none;
  width: min(272px, calc(100vw - 16px));
  padding: 6px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  box-shadow: var(--pop-shadow);
}
.menu {
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
  transform-origin: top right;
  transition: opacity 0.14s var(--ease-in), transform 0.14s var(--ease-in), display 0.14s allow-discrete;
}
.menu.open {
  display: grid;
  opacity: 1;
  transform: none;
  animation: pop-in 0.2s var(--ease-out);
}

.menu-heading {
  display: grid;
  gap: 2px;
  padding: 10px 10px 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--hairline);
}
.menu-heading strong { font-size: 14px; font-weight: 600; }
.menu-heading span { color: var(--ink-subtle); font-size: 13px; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item .icon { width: 18px; height: 18px; color: var(--ink-subtle); }
.menu-item span:not(.switch) { flex: 1; }

.switch {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--hairline-strong);
  transition: background-color 0.18s var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.18s var(--ease);
}
[aria-checked="true"] > .switch { background: var(--accent); box-shadow: none; }
[aria-checked="true"] > .switch::after { transform: translateX(14px); }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* ---------- dashboard ---------- */

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: 4px 0 12px;
  padding: 0 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--surface-1);
  color: var(--ink-subtle);
  transition: border-color 0.15s var(--ease);
}
.search:focus-within { border-color: var(--hairline-strong); }
.search input {
  flex: 1;
  min-width: 0;
  height: 42px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  outline: none;
}
.search input::placeholder { color: var(--ink-subtle); }
.search input::-webkit-search-cancel-button { filter: grayscale(1); }

.status {
  padding: 4px 2px 12px;
  color: var(--ink-subtle);
  font-size: 14px;
}
.status:empty { display: none; }
.status.dashboard-status-error { color: var(--bad); }

.list {
  display: grid;
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  overflow: hidden;
}
.list:empty { display: none; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 60px;
  padding: 10px 12px 10px 14px;
  border: 0;
  border-top: 1px solid var(--hairline);
  background: transparent;
  color: var(--ink);
  text-align: left;
  transition: background-color 0.12s var(--ease);
}
.row:first-child { border-top: 0; }
.row:hover { background: var(--surface-2); }
.row:active { background: var(--surface-3); }
.row:focus-visible { outline-offset: -2px; }

.row-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink-subtle);
}
.row-icon .icon { width: 18px; height: 18px; }
.row[data-kind="folder"] .row-icon,
.row[data-kind="bank"] .row-icon { color: var(--accent-ink); background: var(--accent-soft); }

.row-copy { flex: 1; min-width: 0; }

.row-title {
  display: block;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.1px;
  overflow-wrap: anywhere;
}

.row-meta {
  display: block;
  margin-top: 2px;
  color: var(--ink-subtle);
  font-size: 13px;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.row-meta:empty { display: none; }

.row-badge {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.row-end {
  display: grid;
  place-items: center;
  width: 20px;
  flex-shrink: 0;
  color: var(--ink-tertiary);
}
.row-end .icon { width: 18px; height: 18px; }
.row-end .spinner { width: 18px; height: 18px; }
.row:hover .row-end { color: var(--ink-subtle); }

.row.is-empty { cursor: default; }
.row.is-empty:hover { background: transparent; }

/* Dashboard announcements (/api/ads). Quiet on purpose: no accent fill, just
   a dot beside the label. Not a button: tapping does nothing yet. */
.ad-slot:empty { display: none; }
#ad-top { margin-bottom: 12px; }
#ad-bottom { margin-top: 12px; }
.ad {
  display: grid;
  gap: 2px;
  padding: 12px 16px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  background: var(--surface-1);
}
.ad + .ad { margin-top: 8px; }
.ad-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-subtle);
  font-size: 12px;
  font-weight: 500;
}
.ad-label::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.ad-title {
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}

.continue {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  margin: 4px 0 16px;
  padding: 14px 14px 14px 16px;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-lg);
  background: var(--accent-soft);
  color: var(--ink);
  text-align: left;
  transition: transform 0.1s var(--ease);
}
.continue:active { transform: scale(0.99); }
.continue-copy { flex: 1; min-width: 0; }
.continue-label {
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 600;
}
.continue-title {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.continue-meta {
  display: block;
  margin-top: 2px;
  color: var(--ink-subtle);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.continue .icon-play {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}
.continue .icon-play .icon { width: 16px; height: 16px; fill: currentColor; stroke: none; margin-left: 2px; }

.skeleton {
  display: block;
  height: 60px;
  border-top: 1px solid var(--hairline);
  background: linear-gradient(90deg, transparent, var(--surface-2), transparent) 0 0 / 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
.skeleton:first-child { border-top: 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- quiz ---------- */

.progress-rail {
  height: 2px;
  background: transparent;
}
.progress-bar {
  width: 0;
  height: 100%;
  background: var(--accent);
  transform-origin: left;
  transition: width 0.4s var(--ease-out);
}

#quiz .page,
#results .page {
  padding-bottom: calc(var(--stepper-h) + 32px + env(safe-area-inset-bottom));
}

.q { padding-top: 12px; }

.q-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--ink-subtle);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.quiz-heading-meta { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
.quiz-heading-meta .crumb { margin: 0; color: var(--ink); font-size: 16px; font-weight: 600; line-height: 1.2; }
.question-dots { display: inline-flex; align-items: center; gap: 5px; min-height: 14px; }
.question-dot { position: relative; display: block; flex: 0 0 13px; width: 13px; height: 13px; box-sizing: border-box; border-radius: 50%; background: var(--surface-3); }
.question-dot.is-correct { background: var(--ok); }
.question-dot.is-correct::after { content: ""; position: absolute; left: 5px; top: 4px; width: 3px; height: 5px; border: solid #fff; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
.question-dot.is-wrong { background: var(--bad); }
.question-dot.is-wrong::before, .question-dot.is-wrong::after { content: ""; position: absolute; left: 5.5px; top: 3px; width: 1.5px; height: 7px; border-radius: 2px; background: #fff; transform: rotate(45deg); }
.question-dot.is-wrong::after { transform: rotate(-45deg); }
.question-dot.is-skipped { background: #1685d8; }
.question-dot.is-skipped::after { content: ""; position: absolute; inset: 3px; border: 1.5px solid #fff; border-radius: 50%; }
.quiz-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.quiz-review-btn { padding-inline: 12px; }
.q-id {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-tertiary);
}
.q-verdict {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
}
.q-verdict .icon { width: 13px; height: 13px; stroke-width: 2.5; }
.q-verdict[data-verdict="correct"] { background: var(--ok-soft); color: var(--ok); }
.q-verdict[data-verdict="wrong"] { background: var(--bad-soft); color: var(--bad); }
.q-verdict[data-verdict="skipped"] { background: var(--surface-2); color: var(--ink-subtle); }

.q-text {
  font-size: 17px;
  line-height: 1.6;
  letter-spacing: -0.1px;
  color: var(--ink);
  overflow-wrap: break-word;
}

.q-media {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}
.q-media img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 56vh;
  border-radius: var(--r-lg);
  border: 1px solid var(--hairline);
  background: #fff;
}

.options {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 12px 14px 12px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  background: var(--surface-1);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  text-align: left;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease);
}
.option:hover { border-color: var(--hairline-strong); background: var(--surface-2); }
.option:active { transform: scale(0.99); }

.option-key {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  margin-top: -2px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-sm);
  color: var(--ink-subtle);
  font-size: 13px;
  font-weight: 600;
  transition: inherit;
}
.option-key .icon { width: 15px; height: 15px; stroke-width: 2.5; }

.option-text {
  flex: 1;
  min-width: 0;
  padding-top: 1px;
  overflow-wrap: anywhere;
}
.option-text img { display: block; margin-top: 8px; border-radius: var(--r-sm); }

.option.is-selected {
  border-color: var(--ink-muted);
  background: var(--surface-2);
}
.option.is-selected .option-key { border-color: var(--ink); background: var(--ink); color: var(--canvas); }

.option.is-correct {
  border-color: var(--ok-line);
  background: var(--ok-soft);
}
.option.is-correct .option-key { border-color: var(--ok); background: var(--ok); color: #fff; }

.option.is-wrong {
  border-color: var(--bad-line);
  background: var(--bad-soft);
}
.option.is-wrong .option-key { border-color: var(--bad); background: var(--bad); color: #fff; }

.option.is-dim { color: var(--ink-subtle); }
.option.is-eliminated, .option.is-eliminated:hover { border-color: #55565d; background: #55565d; color: #fff; cursor: not-allowed; opacity: .78; }
.option.is-eliminated .option-key { border-color: #777982; background: #777982; color: #fff; }

#results .option { cursor: default; }
#results .option:active { transform: none; }

.reveal {
  margin-top: 16px;
  display: flex;
  justify-content: center;
}

.explanation {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
}

.explanation-title {
  margin-bottom: 10px;
  color: var(--ink-subtle);
  font-size: 13px;
  font-weight: 600;
}

.media-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.audio-block {
  display: grid;
  gap: 6px;
  width: 100%;
}
.audio-block span {
  color: var(--ink-subtle);
  font-size: 13px;
  font-weight: 500;
}
.audio-block audio { width: 100%; height: 40px; }

.video-slot:empty { display: none; }
.video-slot {
  width: 100%;
  margin-top: 4px;
  overflow: hidden;
  border-radius: var(--r-lg);
  background: #000;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
}
.video-slot video { width: 100%; height: 100%; display: block; }
.video-slot .media-error { padding: 16px; color: #fff; font-size: 14px; text-align: center; }

/* Long-form HTML from the banks: questions and explanations. */
.prose {
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink-muted);
  overflow-wrap: break-word;
}
.q-text.prose { font-size: 17px; line-height: 1.6; color: var(--ink); }
@media (min-width: 768px) {
  .q-text.prose { font-size: 18px; }
  .prose { font-size: 16.5px; }
}
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p { margin: 0 0 0.8em; }
.prose strong, .prose b { color: var(--ink); font-weight: 600; }
.prose h1, .prose h2, .prose h3, .prose h4, .prose h5 {
  margin: 1.4em 0 0.5em;
  color: var(--ink);
  font-size: 1.05em;
  font-weight: 600;
  line-height: 1.35;
}
.prose ul, .prose ol { margin: 0 0 0.9em; padding-left: 1.3em; }
.prose li { margin: 0.3em 0; padding-left: 0.2em; }
.prose li::marker { color: var(--ink-tertiary); }
.prose a { color: var(--accent-ink); }
.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 12px 0;
  border-radius: var(--r-md);
  background: #fff;
}
.prose hr { border: 0; border-top: 1px solid var(--hairline); margin: 1.5em 0; }
.prose sup, .prose sub { line-height: 0; }
.prose blockquote {
  margin: 0 0 1em;
  padding-left: 12px;
  border-left: 2px solid var(--hairline-strong);
}

.table-scroll {
  margin: 0 0 1em;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
}
.prose table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.45;
}
.prose th, .prose td {
  max-width: 15rem;
  padding: 8px 10px;
  border-bottom: 1px solid var(--hairline);
  border-right: 1px solid var(--hairline);
  vertical-align: top;
  text-align: left;
}
.prose tr > :last-child { border-right: 0; }
.prose tr:last-child > * { border-bottom: 0; }
.prose th, .prose thead td, .prose tr:first-child > td > strong:only-child { color: var(--ink); }
.prose th, .prose thead td { background: var(--surface-1); font-weight: 600; }
.prose td p, .prose th p { margin: 0 0 0.4em; }
.prose td p:last-child, .prose th p:last-child { margin: 0; }

/* ---------- stepper ---------- */

.stepper {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-bar);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  max-width: calc(var(--reading) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--hairline);
}
.stepper .btn { min-height: 46px; }
.stepper { grid-template-columns: minmax(0, 0.5fr) minmax(0, 1fr) minmax(0, 1fr); transition: grid-template-columns 0.28s var(--ease-out); }
.stepper #fifty-fifty { min-width: 0; overflow: hidden; opacity: 1; transition: opacity 0.18s var(--ease), padding 0.28s var(--ease-out), border-width 0.28s var(--ease-out); }
.stepper #fifty-fifty[hidden] { display: flex; min-width: 0; padding-inline: 0; border-width: 0; opacity: 0; pointer-events: none; }
.stepper.has-answer { grid-template-columns: minmax(0, 3fr) 0fr minmax(0, 7fr); }
.stepper.has-answer #fifty-fifty { padding-inline: 0; border-width: 0; }
.next-label.label-in { animation: quiz-label-in 0.2s var(--ease-out) both; }
@keyframes quiz-label-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

@media (min-width: 768px) {
  .stepper {
    bottom: 16px;
    border: 1px solid var(--hairline);
    border-radius: var(--r-xl);
    padding: 8px;
    max-width: calc(var(--reading) - 32px);
    box-shadow: var(--pop-shadow);
  }
}

#mark-review[aria-pressed="true"] {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-ink);
}
#mark-review[aria-pressed="true"] .icon { fill: currentColor; }
#fifty-fifty:disabled { color: var(--ink-tertiary); }
#fifty-fifty-modal { width: min(92vw, 440px); }
#fifty-fifty-modal > p { color: var(--ink-muted); line-height: 1.55; margin: 12px 0 22px; }
#fifty-fifty-modal .modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#fifty-fifty-modal .modal-head h2 { margin: 0; font-size: 20px; }
@media (max-width: 640px) {
  #fifty-fifty-modal {
    inset: auto 0 0;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    border-radius: var(--r-xl) var(--r-xl) 0 0;
  }
}

#result-question-number { font-variant-numeric: tabular-nums; min-width: 88px; }

/* ---------- results ---------- */

.score {
  padding: 20px 0 24px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--hairline);
}

.score-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 14px;
}

.score-value {
  font-size: 48px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -1.5px;
  font-variant-numeric: tabular-nums;
}
.score-unit { font-size: 28px; color: var(--ink-subtle); letter-spacing: 0; margin-left: 2px; }

.score-line {
  color: var(--ink-subtle);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin-top: 20px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.stat {
  padding: 10px 12px;
  border-left: 1px solid var(--hairline);
}
.stat:first-child { border-left: 0; }
.stat dt { color: var(--ink-subtle); font-size: 12px; font-weight: 500; }
.stat dd {
  margin-top: 2px;
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stat-ok dd { color: var(--ok); }
.stat-bad dd { color: var(--bad); }

.score-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 16px;
}
.score-actions #take-again { grid-column: 1 / -1; }
.score-actions .btn { min-height: 42px; padding: 0 10px; font-size: 14px; }
@media (min-width: 560px) {
  .score-actions { grid-template-columns: auto auto auto; justify-content: start; }
  .score-actions #take-again { grid-column: auto; }
}
.score-actions .icon { width: 17px; height: 17px; }

/* ---------- sheets and modals (native <dialog>) ---------- */

dialog {
  padding: 0;
  border: 0;
  color: var(--ink);
  background: transparent;
}
dialog::backdrop {
  background: var(--scrim);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: fade-in 0.3s var(--ease);
  transition: opacity 0.26s var(--ease-in), display 0.26s allow-discrete, overlay 0.26s allow-discrete;
}

/* Dialogs open with keyframes and close with transitions: allow-discrete keeps a
   closing dialog on screen until it has left. Browsers without it close at once. */
dialog {
  transition: opacity 0.26s var(--ease-in), transform 0.26s var(--ease-in),
    display 0.26s allow-discrete, overlay 0.26s allow-discrete;
}
dialog:not([open]) { pointer-events: none; }
dialog:not([open])::backdrop { opacity: 0; }

.sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: 100%;
  max-height: min(84dvh, 720px);
  margin: 0;
  padding: 8px var(--gutter) calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: var(--surface-1);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet:not([open]) { transform: translateY(100%); }
.sheet[open] { display: flex; flex-direction: column; gap: 14px; animation: sheet-up 0.46s var(--ease-sheet); }
.sheet::before {
  content: "";
  align-self: center;
  width: 36px;
  height: 4px;
  margin-bottom: 2px;
  border-radius: var(--r-pill);
  background: var(--hairline-strong);
}

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

@media (min-width: 768px) {
  .sheet {
    inset: 0 0 0 auto;
    width: 400px;
    max-height: none;
    height: 100dvh;
    padding: 16px 20px 20px;
    border-top: 0;
    border-left: 1px solid var(--hairline);
    border-radius: 0;
  }
  .sheet::before { display: none; }
  .sheet:not([open]) { transform: translateX(100%); }
  .sheet[open] { animation: sheet-in 0.46s var(--ease-sheet); }
}

@keyframes sheet-in { from { transform: translateX(100%); } }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sheet-head h2 { font-size: 17px; font-weight: 600; letter-spacing: -0.2px; }

.chips {
  grid-auto-columns: auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-subtle);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.chip[aria-checked="true"] {
  background: var(--canvas);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--hairline);
}
.chip-count { color: var(--ink-tertiary); font-variant-numeric: tabular-nums; }

.qgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 8px;
}

.qcell {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--canvas);
  color: var(--ink-subtle);
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.qcell:hover { border-color: var(--hairline-strong); color: var(--ink); }
.qcell.is-answered { background: var(--surface-3); border-color: var(--hairline-strong); color: var(--ink); }
.qcell.is-correct { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.qcell.is-wrong { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }
.qcell.is-current { box-shadow: 0 0 0 2px var(--ink); border-color: transparent; }
.qcell.is-marked::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.qgrid-empty {
  grid-column: 1 / -1;
  padding: 24px 0;
  color: var(--ink-subtle);
  font-size: 14px;
  text-align: center;
}

.sheet-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--hairline);
}
.sheet-summary {
  flex: 1;
  color: var(--ink-subtle);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.shortcuts {
  color: var(--ink-subtle);
  font-size: 13px;
}
.shortcuts summary { cursor: pointer; padding: 4px 0; }
.shortcuts dl { display: grid; gap: 8px; margin-top: 8px; }
.shortcuts dl div { display: flex; justify-content: space-between; gap: 12px; }
.shortcuts dd { text-align: right; }
@media (hover: none) { .shortcuts { display: none; } }

.modal {
  position: fixed; /* same place open or closing (a closing dialog is no longer :modal) */
  inset: 0;
  width: min(400px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-xl);
  background: var(--surface-1);
  box-shadow: var(--pop-shadow);
}
.modal:not([open]) { opacity: 0; transform: scale(0.97); }
.modal[open] { animation: modal-in 0.32s var(--ease-out); }
.modal h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; }
.modal p { margin-top: 8px; color: var(--ink-subtle); font-size: 15px; line-height: 1.5; }
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 20px;
}

/* ---------- edit profile ---------- */

.profile-photo {
  display: flex;
  align-items: center;
  gap: 16px;
}
.avatar-lg { width: 72px; height: 72px; flex-shrink: 0; margin: 0; }
.avatar-lg .icon { width: 32px; height: 32px; }
.profile-photo-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.field input[readonly] { background: var(--surface-2); color: var(--ink-subtle); }
.modal .field-help { margin-top: 0; font-size: 13px; }
#profile-panel [hidden] { display: none; }
.field input[readonly]:focus { border-color: var(--hairline-strong); box-shadow: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--stepper-h) + 24px + env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  display: none;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--ink);
  color: var(--canvas);
  font-size: 14px;
  font-weight: 500;
  transform: translateX(-50%);
  box-shadow: var(--pop-shadow);
}

/* ---------- exam timer, modes, custom quiz ---------- */

.timer {
  flex-shrink: 0;
  padding: 4px 9px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill);
  background: var(--surface-1);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}
.timer.is-low {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-ink);
  animation: breathe 2s ease-in-out infinite;
}
.timer[hidden] { display: none; }

.q-source {
  overflow: hidden;
  color: var(--ink-tertiary);
  font-size: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.mode-options {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}
.mode-options-row { grid-template-columns: 1fr 1fr; margin-top: 0; }

.mode-option {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  background: var(--canvas);
  color: var(--ink);
  text-align: left;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}
.mode-option strong { font-size: 15px; font-weight: 600; }
.mode-option span { color: var(--ink-subtle); font-size: 13px; line-height: 1.4; }
.mode-option[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.row-highlight {
  background: var(--accent-soft);
}
.row-highlight:hover { background: color-mix(in srgb, var(--accent) 12%, var(--surface-1)); }
.row-highlight .row-icon { background: var(--accent); color: #fff; }
.row-highlight .row-title { color: var(--accent-ink); font-weight: 600; }

.custom-banks {
  display: grid;
  gap: 12px;
}
.custom-group {
  margin: 0;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  background: var(--canvas);
  overflow: hidden;
}
.custom-group legend {
  float: left;
  width: 100%;
  padding: 0;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-2);
}
.custom-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 12px;
  border-top: 1px solid var(--hairline);
  font-size: 14px;
  line-height: 1.35;
  cursor: pointer;
}
.custom-group legend + .custom-check { border-top: 0; }
.custom-check-group { border-top: 0; font-weight: 600; }
.custom-check input {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin: 0;
  accent-color: var(--accent);
}

.custom-count {
  display: grid;
  grid-template-columns: auto 64px 1fr;
  align-items: center;
  gap: 8px;
}
.custom-count label { font-size: 14px; font-weight: 500; color: var(--ink-muted); }
.custom-count input {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-md);
  background: var(--canvas);
  color: var(--ink);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.count-chips { display: flex; gap: 4px; justify-content: flex-end; }
.count-chips .chip { border: 1px solid var(--hairline); background: var(--canvas); min-height: 34px; padding: 0 8px; }

/* Count, mode and Start stay in reach while the bank list scrolls. */
.custom-foot {
  position: sticky;
  bottom: calc(-16px - env(safe-area-inset-bottom));
  display: grid;
  gap: 12px;
  margin: 0 calc(-1 * var(--gutter)) calc(-16px - env(safe-area-inset-bottom));
  padding: 14px var(--gutter) calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline);
  background: var(--surface-1);
}
@media (min-width: 768px) {
  .custom-foot { bottom: -20px; margin: 0 -20px -20px; padding: 14px 20px 20px; }
}

.custom-status {
  min-height: 1.4em;
  color: var(--ink-subtle);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.custom-status.is-error { color: var(--bad); }

/* ---------- motion ----------
   New things enter; things that stay put never move. Entrances use
   --ease-out and 'backwards' fill (so :active press feedback still works
   afterwards), exits use --ease-in and are shorter. Only opacity and
   transform animate. app.js adds the enter-* classes and --i (stagger). */

@keyframes fade-in { from { opacity: 0; } }
@keyframes enter-up { from { opacity: 0; transform: translateY(10px); } }
@keyframes enter-right { from { opacity: 0; transform: translateX(16px); } }
@keyframes enter-left { from { opacity: 0; transform: translateX(-16px); } }
@keyframes enter-soft { from { opacity: 0; transform: translateY(6px); } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.96); } }
@keyframes pop { from { opacity: 0; transform: scale(0.6); } }
@keyframes pop-soft { from { opacity: 0; transform: scale(0.85); } }
@keyframes grow { from { transform: scaleX(0); } }
@keyframes breathe { 50% { opacity: 0.6; } }
@keyframes nudge {
  20% { transform: translateX(-4px); }
  45% { transform: translateX(3px); }
  70% { transform: translateX(-1.5px); }
}
@keyframes tint-in { from { background-color: var(--surface-1); border-color: var(--hairline); } }
@keyframes dim-in { from { color: var(--ink); } }

/* Dashboard: rows (and the continue card) cascade in, 24ms apart. */
.enter-up,
.enter-forward,
.enter-next,
.enter-prev {
  animation: enter-up 0.44s var(--ease-out) calc(var(--i, 0) * 24ms) backwards;
}
.enter-forward,
.enter-next { animation-name: enter-right; }
.enter-prev { animation-name: enter-left; }

/* A new question slides in from the side it came from; its options follow. */
.q.enter-next,
.q.enter-prev { animation-duration: 0.36s; }
.q:is(.enter-up, .enter-next, .enter-prev) .option {
  animation: enter-soft 0.4s var(--ease-out) calc(60ms + var(--i, 0) * 32ms) backwards;
}
.q:is(.enter-up, .enter-next, .enter-prev) .explanation {
  animation: fade-in 0.4s var(--ease-out) 0.16s backwards;
}

/* Answering: the choice tints in and its key pops; a wrong choice nudges,
   then the right answer pops; the explanation rises in last. */
.enter-answer .option:is(.is-selected, .is-correct) { animation: tint-in 0.3s var(--ease-out) backwards; }
.enter-answer .option.is-wrong {
  animation: tint-in 0.3s var(--ease-out) backwards, nudge 0.4s var(--ease-out);
}
.enter-answer .option.is-dim { animation: dim-in 0.3s var(--ease-out) backwards; }
.enter-answer .option:is(.is-selected, .is-correct, .is-wrong) .option-key {
  animation: pop 0.42s var(--ease-spring) backwards;
}
.enter-answer .options:has(.is-wrong) .is-correct,
.enter-answer .options:has(.is-wrong) .is-correct .option-key { animation-delay: 0.12s; }
.enter-answer .explanation { animation: enter-up 0.46s var(--ease-out) 0.14s backwards; }


/* Chrome that appears with a view: the stepper rises, the progress line draws. */
.view:not(.hidden) .stepper { animation: enter-up 0.5s var(--ease-out) 0.08s backwards; }
#quiz:not(.hidden) .progress-bar { animation: grow 0.7s var(--ease-out) 0.12s backwards; }

/* Results: score first, then the four stats one by one, then the actions. */
#results:not(.hidden) .score-head { animation: enter-up 0.5s var(--ease-out) backwards; }
#results:not(.hidden) .stat { animation: enter-up 0.5s var(--ease-out) calc(0.1s + var(--i, 0) * 50ms) backwards; }
.stat:nth-child(2) { --i: 1; }
.stat:nth-child(3) { --i: 2; }
.stat:nth-child(4) { --i: 3; }
#results:not(.hidden) .score-actions { animation: enter-up 0.5s var(--ease-out) 0.3s backwards; }

/* Top bar icons swap with a small pop; row chevrons lean towards the tap. */
.topbar .icon-btn:not(.hidden),
.topbar .brand:not(.hidden) { animation: pop-soft 0.3s var(--ease-out); }
.row-end .icon { transition: transform 0.2s var(--ease-out); }
@media (hover: hover) {
  .row:hover .row-end .icon { transform: translateX(2px); }
}
.row-end .spinner { animation: spin 0.8s linear infinite, fade-in 0.2s var(--ease); }

[role="tabpanel"]:not(.hidden) { animation: fade-in 0.24s var(--ease); }

.toast { animation: toast-in 0.32s var(--ease-out); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

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

/* ---------- FMGE Qbank custom styles ---------- */

#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--canvas);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.loading-content {
  text-align: center;
}

.loading-content .spinner {
  margin: 0 auto 16px;
}

#loading-text {
  color: var(--ink-muted);
  font-size: 14px;
}

.home-grid {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.home-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  cursor: pointer;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.1s var(--ease);
  text-align: left;
  width: 100%;
  animation: enter-up 0.4s var(--ease-out) calc(var(--i, 0) * 60ms) backwards;
}

.home-card:hover {
  background: var(--surface-2);
  border-color: var(--hairline-strong);
}

.home-card:active {
  transform: scale(0.98);
}

.home-card.highlight {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.home-card.highlight:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.home-card-content {
  flex: 1;
}

.home-card-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--ink);
}

.home-card-subtitle {
  font-size: 14px;
  color: var(--ink-subtle);
  margin: 0;
}

.home-card-arrow {
  font-size: 24px;
  color: var(--ink-tertiary);
  margin-left: 12px;
}

.session-card, .test-card {
  display: block;
  padding: 16px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.1s var(--ease);
  text-align: left;
  width: 100%;
  animation: enter-soft 0.36s var(--ease-out) calc(var(--i, 0) * 40ms) backwards;
}

.session-card:hover, .test-card:hover {
  background: var(--surface-2);
  border-color: var(--hairline-strong);
}

.session-card:active, .test-card:active {
  transform: scale(0.98);
}

.session-title, .test-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--ink);
}

.session-meta, .test-meta {
  font-size: 13px;
  color: var(--ink-subtle);
  margin: 0;
}

.panel {
  border: none;
  border-radius: var(--r-xl);
  padding: 0;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow: hidden;
}

.panel::backdrop {
  background: var(--scrim);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--hairline);
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.panel-content {
  padding: 20px;
  overflow-y: auto;
  max-height: calc(80vh - 60px);
}

/* Modal (50/50 confirm) */
.modal {
  border: none;
  border-radius: var(--r-xl);
  padding: 0;
  max-width: 400px;
  width: 90%;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--hairline);
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.modal p {
  padding: 20px;
  margin: 0;
  color: var(--ink-muted);
  font-size: 15px;
  line-height: 1.5;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 20px 20px;
}

.modal-actions .btn {
  min-height: 44px;
}

.custom-step-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--ink);
}

.custom-step-desc {
  font-size: 14px;
  color: var(--ink-subtle);
  margin: 0 0 16px;
}

.custom-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.custom-option {
  padding: 12px 16px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.custom-option:hover {
  background: var(--surface-2);
  border-color: var(--accent);
}

.custom-input-wrap {
  display: flex;
  gap: 8px;
  grid-column: 1 / -1;
}

.custom-count-input {
  flex: 1;
  padding: 12px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  font-size: 14px;
  color: var(--ink);
}

.custom-submit {
  padding: 12px 24px;
  background: var(--accent);
  color: white;
  border: none;
}

.custom-submit:hover {
  background: var(--accent-hover);
}

.custom-subjects {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.score-card {
  text-align: center;
  padding: 24px;
  background: var(--surface-1);
  border-radius: var(--r-lg);
  margin-bottom: 20px;
}

.score-percent {
  font-size: 48px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 8px;
}

.score-line {
  font-size: 14px;
  color: var(--ink-subtle);
  margin: 0 0 20px;
}

.score-breakdown {
  display: flex;
  justify-content: center;
  gap: 32px;
}

.score-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.score-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--ink);
}

.score-label {
  font-size: 12px;
  color: var(--ink-subtle);
  margin-top: 4px;
}

.result-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: var(--surface-1);
  border-radius: var(--r-md);
  margin-bottom: 16px;
}

#result-question-number {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-muted);
}

.history-grid {
  display: grid;
  gap: 12px;
}

.history-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.1s var(--ease);
  text-align: left;
  width: 100%;
  animation: enter-soft 0.36s var(--ease-out) calc(var(--i, 0) * 40ms) backwards;
}

.history-card:hover {
  background: var(--surface-2);
  border-color: var(--hairline-strong);
}

.history-card:active {
  transform: scale(0.98);
}

.history-card.no-review {
  opacity: 0.6;
}

.history-card-content {
  flex: 1;
}

.history-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--ink);
}

.history-subtitle {
  font-size: 13px;
  color: var(--ink-subtle);
  margin: 0;
}

.history-card-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.history-percent {
  font-size: 20px;
  font-weight: 700;
}

.history-marks {
  font-size: 13px;
  color: var(--ink-subtle);
}

.history-empty {
  text-align: center;
  color: var(--ink-subtle);
  padding: 40px 20px;
}

.progress-track {
  height: 3px;
  background: var(--surface-2);
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s var(--ease);
}

.q-text {
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  margin-bottom: 20px;
}

.q-text img {
  max-width: 100%;
  height: auto;
  border-radius: var(--r-sm);
  margin: 12px 0;
}

.q-images {
  margin-bottom: 20px;
}

.q-images img {
  max-width: 100%;
  height: auto;
  border-radius: var(--r-sm);
  margin-bottom: 8px;
}

.options {
  display: grid;
  gap: 12px;
  margin-bottom: 20px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  text-align: left;
  width: 100%;
}

.option:hover {
  background: var(--surface-2);
  border-color: var(--hairline-strong);
}

.option.is-selected {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.option.is-correct {
  background: var(--ok-soft);
  border-color: var(--ok);
}

.option.is-wrong {
  background: var(--bad-soft);
  border-color: var(--bad);
}

.option.is-dim {
  opacity: 0.5;
}

.option.is-eliminated,
.option.is-eliminated:hover {
  border-color: #55565d;
  background: #55565d;
  color: #fff;
  cursor: not-allowed;
  opacity: 0.78;
}

.option.is-eliminated .option-key {
  border-color: #777982;
  background: #777982;
  color: #fff;
}

.option-key {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-muted);
}

.option.is-selected .option-key {
  background: var(--accent);
  color: white;
}

.option.is-correct .option-key {
  background: var(--ok);
  color: white;
}

.option.is-wrong .option-key {
  background: var(--bad);
  color: white;
}

.option-text {
  flex: 1;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
}

.option-text img {
  max-width: 100%;
  height: auto;
  border-radius: var(--r-sm);
  margin: 8px 0;
}

.explanation {
  padding: 16px;
  background: var(--surface-1);
  border-radius: var(--r-md);
  margin-top: 20px;
}

.explanation h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 12px;
  color: var(--ink-muted);
}

.explanation p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  margin: 0 0 8px;
}

.explanation img {
  max-width: 100%;
  height: auto;
  border-radius: var(--r-sm);
  margin: 12px 0;
}

.q-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--ink-subtle);
}

.q-verdict {
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
}

.q-verdict.is-correct {
  background: var(--ok-soft);
  color: var(--ok);
}

.q-verdict.is-wrong {
  background: var(--bad-soft);
  color: var(--bad);
}

.q-verdict.is-skipped {
  background: var(--surface-2);
  color: var(--ink-subtle);
}

.stepper {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  background: var(--canvas);
  border-top: 1px solid var(--hairline);
}

.stepper button {
  flex: 1;
}

/* Custom quiz builder (full-page view) */
.custom-content {
  padding: 20px 16px;
}

.custom-step-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--ink);
}

.custom-step-desc {
  font-size: 14px;
  color: var(--ink-muted);
  margin: 0 0 24px;
}

.custom-options {
  display: grid;
  gap: 12px;
}

.custom-option {
  padding: 16px 20px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  text-align: left;
}

.custom-option:hover {
  background: var(--surface-2);
  border-color: var(--hairline-strong);
}

.custom-subjects {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.custom-input-wrap {
  display: flex;
  gap: 8px;
}

.custom-input-wrap input {
  flex: 1;
  padding: 12px 16px;
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  font-size: 15px;
  color: var(--ink);
}

.custom-input-wrap .custom-option {
  flex-shrink: 0;
  padding: 12px 20px;
}

.history-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-muted);
  font-size: 15px;
}
