/* WhiteDevil QBank. One stylesheet, no framework.
   Tokens and rules are documented in Design.md: black, white and one red,
   with a "night" surface for the few things that should feel heavier
   (sign-in stage, resume card, timer, dock, score). Light is the default;
   dark ("night ward") is chosen in the account sheet. */

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

:root {
  color-scheme: light;
  --canvas: #ffffff;
  --surface-1: #f5f5f3;
  --surface-2: #ececea;
  --surface-3: #e1e1de;
  --hairline: #e3e3e0;
  --hairline-strong: #cfcfca;
  --ink: #121214;
  --ink-muted: #3d3d42;
  --ink-subtle: #6a6a70;
  --ink-tertiary: #97979c;

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

  --ok: #14713a;
  --ok-soft: #e6f4ea;
  --ok-line: rgba(20, 113, 58, 0.5);
  --bad: #b90718;
  --bad-soft: #fdecee;
  --bad-line: rgba(185, 7, 24, 0.5);
  --amber: #a15c00;
  --amber-soft: #fdf1dc;
  --amber-line: rgba(161, 92, 0, 0.45);
  --on-state: #ffffff; /* text on a solid ok, bad or amber fill */

  /* Night: always dark, in both themes. */
  --night: #0e0e10;
  --night-2: #18181b;
  --night-3: #242428;
  --night-line: #2c2c31;
  --night-ink: #f1f1ee;
  --night-muted: #a3a3a8;

  --focus: rgba(232, 9, 26, 0.55);
  --scrim: rgba(10, 10, 12, 0.5);
  --pop-shadow: 0 18px 48px -16px rgba(10, 10, 12, 0.3), 0 2px 6px rgba(10, 10, 12, 0.06);
  --bar-bg: rgba(255, 255, 255, 0.9);

  --font-display: "Bricolage Grotesque", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-sans: "Schibsted Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --r-xs: 4px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-pill: 999px;

  --gutter: 16px;
  --topbar-h: 56px;
  --stepper-h: 68px;
  --dock-h: 60px;
  --reading: 40rem;
  --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: #0e0e10;
  --surface-1: #17171a;
  --surface-2: #1f1f23;
  --surface-3: #2a2a2f;
  --hairline: #26262b;
  --hairline-strong: #3a3a41;
  --ink: #f1f1ee;
  --ink-muted: #c9c9cd;
  --ink-subtle: #94949b;
  --ink-tertiary: #6b6b72;

  --accent: #e8091a;
  --accent-hover: #f5212f;
  --accent-press: #c8081a;
  --accent-ink: #ff6672;
  --accent-soft: #2c1114;
  --accent-line: rgba(255, 102, 114, 0.45);

  --ok: #53c57a;
  --ok-soft: #11261a;
  --ok-line: rgba(83, 197, 122, 0.5);
  --bad: #ff6672;
  --bad-soft: #2c1114;
  --bad-line: rgba(255, 102, 114, 0.5);
  --amber: #f0b354;
  --amber-soft: #2b2112;
  --amber-line: rgba(240, 179, 84, 0.45);
  --on-state: #0e0e10;

  /* On a night canvas the night surfaces step up so they still read as cards. */
  --night: #18181b;
  --night-2: #202024;
  --night-3: #2a2a2f;
  --night-line: #34343a;

  --scrim: rgba(0, 0, 0, 0.64);
  --pop-shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.05);
  --bar-bg: rgba(14, 14, 16, 0.88);
}

@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: 48px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 600;
  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 .icon { width: 18px; height: 18px; }
.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-ink { background: var(--ink); color: var(--canvas); }
.btn-ink:hover:not(:disabled) { background: var(--ink-muted); }

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

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

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

.btn-sm { min-height: 44px; padding: 0 14px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-square { width: 48px; padding: 0; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  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 .icon { width: 21px; height: 21px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { background: var(--surface-3); }
.icon-btn[aria-pressed="true"] { color: var(--amber); }
.icon-btn[aria-pressed="true"] .icon { fill: currentColor; }

/* Labels used across screens. */
.lbl,
.section-label {
  color: var(--ink-subtle);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.section-label { margin: 26px 0 8px; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink-muted);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-amber { background: var(--amber-soft); color: var(--amber); }
.tag-bad { background: var(--bad-soft); color: var(--bad); }

.meter {
  display: block;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--surface-2);
}
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--ink); }

/* Filter and path chips: 32px pills, "on" is an ink fill. The 44px hit
   area comes from the padding of the strip around them. */
.filter-chips,
.path-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 calc(-1 * var(--gutter));
  padding: 6px var(--gutter);
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar,
.path-chips::-webkit-scrollbar { display: none; }
.filter-chips.hidden,
.path-chips.hidden { display: none; }

.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  flex-shrink: 0;
  padding: 0 13px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-pill);
  background: var(--canvas);
  color: var(--ink-muted);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
}
.chip::after { content: ""; position: absolute; inset: -6px -2px; } /* 44px hit area */
.chip:hover { color: var(--ink); }
.chip[aria-checked="true"],
.chip[aria-current="page"] { border-color: var(--ink); background: var(--ink); color: var(--canvas); }
.chip-count { color: var(--ink-tertiary); font-variant-numeric: tabular-nums; }
.chip[aria-checked="true"] .chip-count { color: inherit; opacity: 0.7; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }

/* ---------- auth gate ---------- */

body.auth-open { overflow: hidden; }
body.auth-open .app { display: none; }

#auth-gate {
  position: fixed;
  inset: 0;
  z-index: var(--z-gate);
  overflow-y: auto;
  background: var(--canvas);
}

#auth-gate[data-state="checking"] .auth-shell,
#auth-gate[data-state="ready"] .auth-loading-panel,
#auth-gate.hidden .auth-loading-panel { display: none; }

.auth-loading-panel {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  min-height: 100dvh;
}

.auth-loading-title {
  color: var(--ink-subtle);
  font-size: 14px;
}

.auth-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* The brand stage: night, with the logo's red as a bar along the bottom. */
.auth-stage {
  display: grid;
  justify-items: start;
  gap: 10px;
  padding: calc(40px + env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 28px max(24px, env(safe-area-inset-left));
  border-bottom: 4px solid var(--accent);
  background: #0e0e10;
  color: #f1f1ee;
}

.auth-logo {
  width: 84px;
  height: 84px;
  margin-bottom: 8px;
  border-radius: 20px;
}

.auth-title {
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
}

.auth-sub {
  max-width: 30ch;
  color: #a3a3a8;
  font-size: 15px;
  line-height: 1.45;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 28px max(var(--gutter), 24px) calc(32px + env(safe-area-inset-bottom));
}

.auth-panel { display: grid; gap: 4px; }

.auth-heading {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.015em;
}

.auth-copy {
  margin-top: 6px;
  color: var(--ink-subtle);
  font-size: 15px;
  line-height: 1.55;
}

.auth-panel > .btn { margin-top: 20px; }

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}
.link-btn strong {
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.link-btn:hover { color: var(--ink); }
.link-btn .icon { width: 18px; height: 18px; }

.auth-back { justify-self: start; margin: -8px 0 6px -2px; }

.auth-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 16px;
  margin-top: 12px;
}

.auth-steps {
  display: grid;
  gap: 2px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}
.auth-steps li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  color: var(--ink-subtle);
  font-size: 15px;
}
.auth-steps li.is-done,
.auth-steps li.is-now { color: var(--ink); font-weight: 500; }
.auth-step-dot {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: 1px solid var(--hairline-strong);
  border-radius: 50%;
  color: var(--ink-subtle);
  font-size: 13px;
  font-weight: 600;
}
.auth-step-dot .icon { width: 15px; height: 15px; stroke-width: 2.25; }
.is-done > .auth-step-dot { border-color: var(--ok); background: var(--ok); color: var(--on-state); }
.is-now > .auth-step-dot { border-color: var(--amber-line); background: var(--amber-soft); color: var(--amber); }

.form {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.field { display: grid; gap: 6px; min-width: 0; }

.field label {
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 600;
}

.field .optional {
  color: var(--ink-tertiary);
  font-weight: 400;
}

.field input {
  width: 100%;
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-md);
  background: var(--canvas);
  color: var(--ink);
  font-size: 16px; /* 16px stops iOS zooming into the field */
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.field input:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 12%, transparent);
}

.field input[aria-invalid="true"] { border-color: var(--bad); }
.field input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--bad-soft); }

.field input[type="date"] { min-width: 0; }

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

.password-field { position: relative; }
.password-field input { padding-right: 52px; }

.toggle-password {
  position: absolute;
  top: 50%;
  right: 3px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-subtle);
  transform: translateY(-50%);
}
.toggle-password:hover { color: var(--ink); }
.toggle-password .icon-hide,
.toggle-password[aria-pressed="true"] .icon-show { display: none; }
.toggle-password[aria-pressed="true"] .icon-hide { display: block; }

.auth-message {
  font-size: 14px;
  line-height: 1.45;
}
.auth-message:empty { display: none; }
.auth-message[data-tone="error"] { color: var(--bad); }
.auth-message[data-tone="success"] { color: var(--ok); }

.form-hint {
  color: var(--ink-subtle);
  font-size: 13px;
  text-align: center;
}

/* Phones: once past the log-in card, the stage shrinks to a strip so the form leads. */
@media (max-width: 899px) {
  #auth-gate:not([data-step="login"]) .auth-stage {
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 0 12px;
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: 16px;
  }
  #auth-gate:not([data-step="login"]) .auth-logo { width: 44px; height: 44px; margin: 0; border-radius: 11px; }
  #auth-gate:not([data-step="login"]) .auth-title { font-size: 19px; letter-spacing: -0.01em; }
  #auth-gate:not([data-step="login"]) .auth-sub { display: none; }
}

/* iPad landscape and laptops: stage on the left, a 380px form on the right. */
@media (min-width: 900px) {
  .auth-shell { flex-direction: row; }
  .auth-stage {
    flex: 1;
    align-content: end;
    padding: 56px clamp(40px, 6vw, 88px) 64px;
  }
  .auth-logo { width: 96px; height: 96px; border-radius: 22px; }
  .auth-title { font-size: clamp(48px, 5.4vw, 72px); }
  .auth-sub { font-size: 17px; }
  .auth-card {
    flex: 0 0 auto;
    align-self: center;
    width: calc(380px + 2 * 48px);
    max-width: none;
    margin: 0;
    padding: 48px;
  }
}

/* ---------- 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;
  height: var(--topbar-h);
  width: 100%;
  margin: 0;
  padding: 0 max(20px, env(safe-area-inset-right)) 0 max(20px, 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. */
.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: 44px;
  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-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; }

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

.history-page { padding-top: 28px; }
.history-overview {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0 0 24px;
  padding: 16px 18px;
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  background: var(--surface-1);
}
.history-overview[hidden] { display: none; }
.history-overview-score { display: grid; gap: 1px; }
.history-overview-score strong { font-size: 25px; line-height: 1.1; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.history-overview-score span, .history-overview-meta span { color: var(--ink-subtle); font-size: 12px; }
.history-overview-meta { display: grid; gap: 1px; margin-left: auto; text-align: right; }
.history-overview-meta strong { font-size: 13px; font-weight: 600; }
.history-list:empty { display: none; }
.history-group { margin: 0 0 26px; }
.history-group-title {
  margin: 0 0 8px;
  color: var(--ink-subtle);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.history-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 2px;
  border-top: 1px solid var(--hairline);
}
.history-entry:last-child { border-bottom: 1px solid var(--hairline); }
.history-entry-copy { min-width: 0; }
.history-entry-title {
  display: block;
  font-size: 14px;
  font-weight: 550;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.history-entry-date { display: block; margin-top: 3px; color: var(--ink-subtle); font-size: 12px; }
.history-entry-counts { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 6px; color: var(--ink-subtle); font-size: 12px; font-variant-numeric: tabular-nums; }
.history-entry-counts .is-correct { color: var(--ok); }
.history-entry-counts .is-wrong { color: var(--bad); }
.history-entry-end { display: grid; justify-items: end; gap: 2px; }
.history-entry-accuracy { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.history-entry-review { min-height: 32px; padding: 0; border: 0; background: transparent; color: var(--ink); font: 550 12px var(--font-sans); cursor: pointer; }
.history-entry-review:hover:not(:disabled) { color: var(--accent-ink); }
.history-entry-review:disabled { color: var(--ink-tertiary); cursor: default; }
.history-empty { padding: 36px 0; color: var(--ink-subtle); text-align: center; }
.history-review-modal {
  position: fixed;
  inset: 50% auto auto 50%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(760px, calc(100vw - 32px));
  max-width: none;
  max-height: min(90dvh, 900px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: var(--r-xl);
  background: var(--canvas);
  box-shadow: var(--pop-shadow);
  transform: translate(-50%, -50%);
}
.history-review-modal:not([open]) { opacity: 0; transform: translate(-50%, calc(-50% + 8px)) scale(.98); }
.history-review-modal[open] { animation: history-modal-in .24s var(--ease-out); }
@keyframes history-modal-in { from { opacity: 0; transform: translate(-50%, calc(-50% + 8px)) scale(.98); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.history-review-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--hairline); background: var(--bar-bg); }
.history-review-head h2 { margin: 2px 0 0; font-size: 15px; font-weight: 600; line-height: 1.3; }
.history-review-head .crumb { font-size: 11px; }
.history-review-content { width: 100%; max-width: var(--reading); padding: 16px var(--gutter); overflow: auto; overscroll-behavior: contain; }
.history-review-controls { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 12px; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--hairline); background: var(--canvas); }
.history-review-controls .crumb { text-align: center; }
@media (max-width: 480px) {
  .history-overview { padding: 14px; }
  .history-entry { gap: 8px; padding: 12px 0; }
  .history-entry-counts { gap: 3px 6px; font-size: 11px; }
  .history-entry-title { font-size: 13px; }
  .history-review-modal { width: 100vw; max-height: 94dvh; border-radius: var(--r-lg); }
}
@media (prefers-reduced-motion: reduce) { .history-review-modal[open] { animation: none; } }

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

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

/* ---------- shell additions ---------- */

#dashboard-title.brand-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand { width: 44px; height: 44px; }
.avatar { width: 44px; height: 44px; }
.avatar-md { width: 48px; height: 48px; flex-shrink: 0; }
.more { position: relative; }
.more .menu { right: 0; left: auto; }

/* Room for the floating dock under the dashboard and history. */
body[data-view="dashboard"] .page,
body[data-view="history"] .page { padding-bottom: calc(var(--dock-h) + 40px + env(safe-area-inset-bottom)); }

/* ---------- dock ---------- */

.dock {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: var(--z-bar);
  display: flex;
  align-items: center;
  gap: 2px;
  height: var(--dock-h);
  padding: 6px;
  border: 1px solid var(--night-line);
  border-radius: var(--r-pill);
  background: var(--night);
  color: var(--night-muted);
  box-shadow: var(--pop-shadow);
  transform: translateX(-50%);
}
body.auth-open .dock,
body[data-view="quiz"] .dock,
body[data-view="results"] .dock { display: none; }

.dock-btn {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
}
.dock-btn .icon { width: 21px; height: 21px; }
.dock-btn:hover,
.dock-btn[aria-current="page"] { color: var(--night-ink); background: var(--night-2); }

.dock-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  margin: 0 4px;
  padding: 0 18px 0 14px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: #fff;
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
}
.dock-main .icon { width: 19px; height: 19px; }
.dock-main:hover { background: var(--accent-hover); }

/* ---------- account sheet ---------- */

.account-head { display: flex; align-items: center; gap: 12px; }
.account-head .menu-heading { flex: 1; min-width: 0; padding: 0; border: 0; display: grid; gap: 2px; }
.account-head .menu-heading strong { font-family: var(--font-display); font-size: 18px; font-weight: 700; }

.stat-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--surface-1);
}
.stat-card span { color: var(--ink-subtle); font-size: 12.5px; font-weight: 500; }
.stat-card strong {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-card small { color: var(--ink-subtle); font-size: 13px; font-weight: 500; }

.menu-list { display: grid; margin: 0 -8px; }
.menu-list .menu-item { min-height: 52px; border-radius: var(--r-md); }
.menu-item .menu-end { width: 16px; height: 16px; color: var(--ink-tertiary); }
.menu-item-bad,
.menu-item-bad .icon { color: var(--bad); }
.menu-list .hidden { display: none; }

/* ---------- home ---------- */

.path-chips { margin-bottom: 4px; }
.path-chip { gap: 4px; }
.path-chip .icon { width: 14px; height: 14px; }
@media (max-width: 767px) { .path-chips { display: none; } }

#continue-slot:empty { display: none; }
#continue-slot { display: grid; gap: 10px; margin: 4px 0 6px; }

/* The night resume card. */
.resume {
  display: grid;
  gap: 10px;
  width: 100%;
  padding: 18px 18px 16px;
  border: 0;
  border-radius: 18px;
  background: var(--night);
  color: var(--night-ink);
  text-align: left;
}
.resume:active { transform: scale(0.99); }
.resume-label { color: var(--night-muted); font-size: 12.5px; font-weight: 600; }
.resume-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.015em;
}
.resume-meter { display: flex; align-items: center; gap: 10px; color: var(--night-muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.resume-meter .meter { flex: 1; background: var(--night-3); }
.resume-meter .meter > span { background: var(--accent); }
.resume-go { display: flex; align-items: center; gap: 6px; min-height: 28px; font-size: 14.5px; font-weight: 600; }
.resume-go .icon { width: 16px; height: 16px; }

.first-run {
  display: grid;
  gap: 6px;
  padding: 18px;
  border-radius: 18px;
  background: var(--night);
  color: var(--night-ink);
}
.first-run strong { font-family: var(--font-display); font-size: 20px; font-weight: 700; }
.first-run span { color: var(--night-muted); font-size: 14.5px; line-height: 1.45; }

/* Rows: tiles on the left, status on the right. */
.tile {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 10px;
  background: var(--surface-1);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
}
.tile .icon { width: 19px; height: 19px; }
.tile-ink { background: var(--ink); color: var(--canvas); }

.row { min-height: 60px; }
.row-meter { display: block; max-width: 220px; margin-top: 8px; height: 4px; }
.row-meter > span { background: var(--accent); }
.row-side { display: flex; align-items: center; gap: 10px; flex-shrink: 0; color: var(--ink-subtle); font-size: 13px; font-variant-numeric: tabular-nums; }
.row-side .icon { width: 18px; height: 18px; color: var(--ink-tertiary); }
.resume-btn {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  background: var(--ink);
  color: var(--canvas);
  font-size: 13px;
  font-weight: 600;
}

.session-head {
  padding: 22px 0 6px;
  color: var(--ink-subtle);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.session-head:first-child { padding-top: 6px; }
.list.is-grouped { display: block; border: 0; border-radius: 0; background: none; overflow: visible; }
.list.is-grouped > .list { margin-bottom: 4px; }

#dashboard-search-wrap { margin-bottom: 8px; }
#dashboard-filters { margin-bottom: 6px; }

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

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

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

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

.quiz-head { font-family: var(--font-sans); font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
.quiz-bar .crumb { font-variant-numeric: tabular-nums; }
.quiz-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

/* Practice: one 4px segment per question. */
.segs {
  display: flex;
  gap: 3px;
  max-width: calc(var(--reading) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0 var(--gutter) 8px;
}
.seg { flex: 1; height: 4px; min-width: 2px; border-radius: 2px; background: var(--surface-3); }
.seg.is-ok { background: var(--ok); }
.seg.is-bad { background: var(--bad); }
.seg.is-sk { background: var(--ink-tertiary); }
.seg.is-fl { background: var(--amber); }
.seg.is-cur { background: var(--ink); }

/* Exam: a strip of numbered cells. */
.exam-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  max-width: calc(var(--reading) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 2px var(--gutter) 10px;
  scrollbar-width: none;
}
.exam-strip::-webkit-scrollbar { display: none; }
.ecell {
  position: relative;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  padding: 0;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-sm);
  background: var(--canvas);
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ecell.is-answered { border-color: var(--ink); background: var(--ink); color: var(--canvas); }
.ecell.is-cur { box-shadow: 0 0 0 2px var(--canvas), 0 0 0 4px var(--accent); }
.ecell.is-marked::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--canvas);
  border-radius: 50%;
  background: var(--amber);
}

#quiz[data-mode="exam"] .segs,
#quiz:not([data-mode="exam"]) .exam-strip,
#quiz[data-mode="exam"] #mark-review,
#quiz[data-mode="exam"] #fifty-fifty,
#quiz[data-mode="exam"] #reveal-btn,
#quiz:not([data-mode="exam"]) #exam-mark { display: none; }

/* Night timer pill. */
.timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r-pill);
  background: var(--night);
  color: var(--night-ink);
  font-size: 13.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.timer .icon { width: 15px; height: 15px; }
.timer.is-low { background: var(--accent); color: #fff; animation: breathe 1.6s var(--ease) infinite; }
.timer[hidden] { display: none; }

.q { padding-top: 14px; }
.q-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.q-tags:empty { display: none; }
.q-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.q-label .lbl { font-size: 13px; }
.clear-answer {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.clear-answer:disabled { visibility: hidden; }

/* Options: 56px, one column, a 28px key. */
.options { gap: 10px; margin-top: 22px; }
.option {
  min-height: 56px;
  padding: 13px 14px 13px 13px;
  border-color: var(--hairline-strong);
  border-radius: var(--r-lg);
  background: var(--canvas);
}
.option:hover { background: var(--surface-1); border-color: var(--ink-tertiary); }
.option-key { width: 28px; height: 28px; border-radius: 8px; }
.option.is-selected { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.option.is-correct { border-color: var(--ok); box-shadow: inset 0 0 0 1px var(--ok); background: var(--ok-soft); }
.option.is-wrong { border-color: var(--bad); box-shadow: inset 0 0 0 1px var(--bad); background: var(--bad-soft); }
.option.is-correct .option-key,
.option.is-wrong .option-key { color: var(--on-state); }

/* ---------- explanation ---------- */

.explanation {
  display: grid;
  gap: 14px;
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--hairline);
}
.ex-answers { display: grid; gap: 6px; }
.ex-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  background: var(--surface-1);
  font-size: 14.5px;
  line-height: 1.4;
}
.ex-row .lbl { flex: 0 0 92px; }
.ex-row strong { font-weight: 600; }
.ex-row.is-ok strong { color: var(--ok); }
.ex-row.is-bad strong { color: var(--bad); }
.explanation-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.015em;
}
.explanation .prose { font-size: 15.5px; line-height: 1.62; }
.ex-others {
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
}
.ex-others summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 14px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.ex-others summary::-webkit-details-marker { display: none; }
.ex-others summary .icon { width: 18px; height: 18px; color: var(--ink-subtle); transition: transform 0.2s var(--ease); }
.ex-others[open] summary .icon { transform: rotate(180deg); }
.ex-others .prose { padding: 0 14px 14px; }
.ex-actions { display: flex; flex-wrap: wrap; gap: 8px; }

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

.stepper {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-bar);
  display: flex;
  gap: 8px;
  max-width: calc(var(--reading) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline);
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  backdrop-filter: saturate(160%) blur(14px);
}
.stepper .btn { flex-shrink: 0; }
.stepper #next-btn { flex: 1; min-width: 0; }
.stepper #fifty-fifty { padding: 0 14px; }
.stepper #fifty-fifty[hidden] { display: none; }
#quiz[data-mode="exam"] #exam-mark { flex: 1; min-width: 0; }
#quiz[data-mode="exam"] #next-btn { background: var(--ink); color: var(--canvas); }
#exam-mark[aria-pressed="true"] { border-color: var(--amber-line); background: var(--amber-soft); color: var(--amber); }
#exam-mark[aria-pressed="true"] .icon { fill: currentColor; }
#reveal-btn[aria-pressed="true"] { border-color: var(--ink); }
#fifty-fifty:disabled { color: var(--ink-tertiary); }
.next-label.label-in { animation: quiz-label-in 0.2s var(--ease-out) both; }
@keyframes quiz-label-in { from { opacity: 0; transform: translateY(4px); } }

.results-stepper { display: grid; grid-template-columns: 1fr auto 1fr; }

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

#fifty-fifty-modal { width: min(92vw, 440px); }
#fifty-fifty-modal > p { color: var(--ink-muted); line-height: 1.55; margin: 12px 0 0; }
#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; }
#result-question-number { font-variant-numeric: tabular-nums; min-width: 88px; }

/* ---------- 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; }

.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 { display: flex; align-items: center; min-height: 44px; cursor: pointer; }
.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-danger { display: grid; gap: 8px; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--hairline); }
.profile-danger h3 { font-size: 15px; font-weight: 600; }
.profile-danger p { margin: 0; font-size: 14px; }
.btn-danger { border: 1px solid var(--bad-line); background: var(--canvas); color: var(--bad); }
.btn-danger:hover:not(:disabled) { background: var(--bad-soft); }
.btn-danger-solid { background: var(--bad); color: #fff; }
#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);
}

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

.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 .chip-count { margin-left: auto; font-size: 13px; color: var(--ink-subtle); } /* ink-tertiary fails AA on canvas */
.custom-sources { border: 1px solid var(--hairline); border-radius: var(--r-lg); background: var(--canvas); overflow: hidden; }
.custom-sources summary { display: flex; align-items: center; min-height: 44px; padding: 0 12px; font-size: 14px; font-weight: 500; cursor: pointer; }
.custom-sources summary span { margin-left: auto; color: var(--ink-subtle); font-weight: 400; }
.custom-sources .custom-check:first-of-type { border-top: 1px solid var(--hairline); }
.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); }

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

#results[data-pane="summary"] .results-review,
#results[data-pane="summary"] .results-stepper,
#results[data-pane="review"] .results-summary { display: none; }

.score {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 22px 20px 20px;
  border-radius: 20px;
  background: var(--night);
  color: var(--night-ink);
}
.score-value {
  font-family: var(--font-display);
  font-size: 76px;
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.score-unit { margin-left: 2px; color: var(--night-muted); font-size: 34px; letter-spacing: 0; }
.score-line { font-size: 16px; font-weight: 600; }
.score-delta { color: var(--night-muted); font-size: 14px; }
.score-delta[hidden] { display: none; }
.score-delta.is-up { color: #53c57a; }
.score-meter { display: flex; height: 6px; overflow: hidden; margin-top: 4px; border-radius: 3px; background: var(--night-3); }
.score-meter span { display: block; height: 100%; }
#score-meter-ok { background: #53c57a; }
#score-meter-bad { background: #ff6672; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 6px; }
.stat { display: grid; gap: 2px; padding-left: 12px; border-left: 1px solid var(--night-line); }
.stat:first-child { padding-left: 0; border-left: 0; }
.stat dt { color: var(--night-muted); font-size: 12px; font-weight: 500; }
.stat dd { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-ok dd { color: #53c57a; }
.stat-bad dd { color: #ff6672; }

.score-actions { display: grid; gap: 8px; margin-top: 14px; }
.score-actions-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.topics { display: grid; gap: 4px; }
.topics[hidden] { display: none; }
.topic-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 44px; align-items: center; gap: 12px; min-height: 44px; font-size: 14.5px; }
.topic-row span:last-child { text-align: right; color: var(--ink-subtle); font-variant-numeric: tabular-nums; }
.topic-row .meter > span { background: var(--ok); }

.review-list { display: grid; gap: 10px; margin-top: 10px; }
.review-card {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--hairline);
  border-radius: 16px;
  background: var(--canvas);
  color: var(--ink);
  text-align: left;
}
.review-card:hover { border-color: var(--hairline-strong); background: var(--surface-1); }
.review-head { display: flex; align-items: center; gap: 8px; color: var(--ink-subtle); font-size: 12.5px; font-weight: 600; }
.review-q {
  display: -webkit-box;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.45;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.review-ans { display: grid; gap: 2px; font-size: 13.5px; color: var(--ink-muted); }
.review-ans .is-bad { color: var(--bad); font-weight: 600; }
.review-ans .is-ok { color: var(--ok); font-weight: 600; }
.review-empty { padding: 28px 0; color: var(--ink-subtle); text-align: center; }

/* ---------- sheets: start, navigator, finish ---------- */

.sheet { gap: 14px; }
.sheet .handle { display: none; }

.start-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.start-head h2 { font-family: var(--font-display); font-size: 21px; font-weight: 700; letter-spacing: -0.015em; }
.shuffle-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--ink-tertiary);
  font-size: 12.5px;
  font-weight: 600;
}
.shuffle-toggle .icon { width: 17px; height: 17px; }
.shuffle-toggle[aria-checked="true"] { color: var(--accent-ink); }
.start-modes { grid-template-columns: 1fr 1fr; margin-top: 0; }
.mode-option { min-height: 96px; border-radius: 16px; }
.mode-option-night { border-color: var(--night); background: var(--night); color: var(--night-ink); }
.mode-option-night span { color: var(--night-muted); }
.mode-option-night:hover { background: var(--night-2); }
.mode-icon { color: var(--accent-ink); }
.mode-icon .icon { width: 20px; height: 20px; }
.start-hint { color: var(--ink-subtle); font-size: 13px; text-align: center; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--ink-subtle); font-size: 12.5px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--surface-3); }
.legend .lg-ok { background: var(--ok); }
.legend .lg-bad { background: var(--bad); }
.legend .lg-fl { background: var(--amber); }
.legend .lg-na { border: 1px solid var(--hairline-strong); background: var(--canvas); }

.qgrid { grid-template-columns: repeat(6, 1fr); gap: 8px; }
.qcell { border-radius: 10px; }
.qcell.is-correct { color: var(--ok); }
.qcell.is-marked::after { background: var(--amber); }
#submit-test.is-ready { border-color: var(--ink); background: var(--ink); color: var(--canvas); }

.count-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.count-card { display: grid; gap: 2px; padding: 12px 14px; border-radius: 14px; background: var(--surface-1); }
.count-card span { color: var(--ink-subtle); font-size: 12.5px; font-weight: 500; }
.count-card strong { font-family: var(--font-display); font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.count-card.is-bad strong { color: var(--bad); }
.count-card.is-amber strong { color: var(--amber); }
.finish-missed[hidden] { display: none; }
.finish-missed .section-label { margin-top: 4px; }
.finish-actions { display: grid; gap: 8px; }

/* ---------- wide layouts ---------- */

/* iPad portrait and up: one centred reading column. */
@media (min-width: 768px) {
  #question-host,
  .results-summary,
  .results-review { max-width: 660px; }
}

/* Laptops and iPad landscape: once answered, the explanation sits on the
   left and the question stays on the right. Before answering it is one
   centred column. */
@media (min-width: 1024px) {
  #question-host:has(.q.is-shown) { max-width: 76rem; }
  .q.is-shown {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 48px;
    align-items: start;
  }
  .q.is-shown > .explanation {
    grid-column: 1;
    grid-row: 1;
    position: sticky;
    top: calc(var(--topbar-h) + 64px);
    max-height: calc(100dvh - var(--topbar-h) - 64px - var(--stepper-h) - 48px);
    overflow-y: auto;
    margin-top: 0;
    padding: 0 8px 0 0;
    border-top: 0;
  }
  .q.is-shown > .q-main { grid-column: 2; grid-row: 1; }
  #quiz:has(.q.is-shown) .stepper { max-width: calc(var(--reading) - 16px); }
}

/* ---------- 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) .segs { 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-value { 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); }

/* Sign-in: the loading state waits a beat (quick restores never flash it),
   then logo, title and card rise in turn. */
.auth-loading-panel { animation: fade-in 0.3s var(--ease) 0.25s backwards; }
#auth-gate[data-state="ready"] .auth-stage > *,
#auth-gate[data-state="ready"] .auth-card { animation: enter-up 0.56s var(--ease-out) backwards; }
#auth-gate[data-state="ready"] .auth-logo { animation-name: modal-in; }
#auth-gate[data-state="ready"] .auth-title { animation-delay: 0.06s; }
#auth-gate[data-state="ready"] .auth-sub { animation-delay: 0.12s; }
#auth-gate[data-state="ready"] .auth-card { animation-delay: 0.18s; }
.auth-panel: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;
  }
}

/* ---------- small additions ---------- */

.explanation .prose > p.ex-key,
.ex-key { color: var(--ink); font-size: 16.5px; font-weight: 500; line-height: 1.55; }
.legend .lg-ans { background: var(--ink); }
.sheet-summary strong { color: var(--ink); font-weight: 700; }
.row[data-status="progress"] .row-end { display: none; }
.row .tile { align-self: center; }
.stat-cards { margin-top: 2px; }
.list .tile { background: var(--canvas); box-shadow: inset 0 0 0 1px var(--hairline); }
.list .tile-ink { background: var(--ink); box-shadow: none; }
.ecell::before { content: ""; position: absolute; inset: -4px -3px; } /* 44px hit area */

/* Grid children must not grow to fit a wide table. */
.explanation > *, .ex-others .prose { min-width: 0; }
