/* =========================================================================
   LMDCAT design system — mobile first.
   Small screens get the base rules; wider viewports only add to them.
   ====================================================================== */

:root {
  /* Brand: teal reads medical without the coldness of a clinical blue. */
  --brand: #0D9488;
  --brand-strong: #0F766E;
  --brand-ink: #ffffff;
  --brand-tint: #E6F5F3;
  --brand-tint-2: #CFEAE6;

  --bg: #F6F8FA;
  --surface: #FFFFFF;
  --surface-2: #F1F4F8;
  --border: #E5E8EE;
  --border-strong: #CFD5DF;

  --text: #0B1420;
  --text-2: #4A5566;
  --text-3: #8894A6;

  --ok: #047857;
  --ok-tint: #E6F5EE;
  --ok-border: #A7DCC4;
  --bad: #DC2626;
  --bad-tint: #FDEAEA;
  --bad-border: #F3B4B4;
  --warn: #B45309;
  --warn-tint: #FDF2E3;

  /* Layered, low-opacity shadows — depth without a drop-shadow look. */
  --sh-1: 0 1px 2px rgba(11, 20, 32, 0.05);
  --sh-2: 0 1px 3px rgba(11, 20, 32, 0.07), 0 4px 12px rgba(11, 20, 32, 0.05);
  --sh-3: 0 2px 6px rgba(11, 20, 32, 0.08), 0 12px 28px rgba(11, 20, 32, 0.09);
  --sh-brand: 0 3px 10px rgba(13, 148, 136, 0.28);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 24px;
  --r-full: 999px;

  --app-bar: 56px;
  --tab-bar: 62px;
  --page: 720px;

  --ease: cubic-bezier(0.32, 0.72, 0, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #2DD4BF;
    --brand-strong: #14B8A6;
    --brand-ink: #04211E;
    --brand-tint: #0E2F2C;
    --brand-tint-2: #14403C;

    --bg: #090E15;
    --surface: #111A24;
    --surface-2: #17212D;
    --border: #202D3C;
    --border-strong: #2C3D50;

    --text: #E9EEF5;
    --text-2: #9BAABD;
    --text-3: #6A7B90;

    --ok: #34D399;
    --ok-tint: #0C2A21;
    --ok-border: #1F5B47;
    --bad: #FB7185;
    --bad-tint: #2E1119;
    --bad-border: #6B2431;
    --warn: #FBBF24;
    --warn-tint: #2E2410;

    --sh-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --sh-2: 0 1px 3px rgba(0, 0, 0, 0.45), 0 4px 12px rgba(0, 0, 0, 0.35);
    --sh-3: 0 2px 6px rgba(0, 0, 0, 0.5), 0 12px 28px rgba(0, 0, 0, 0.45);
    --sh-brand: 0 3px 12px rgba(45, 212, 191, 0.22);

    color-scheme: dark;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
  /* Room for the fixed bars, plus the home indicator on a notched phone. */
  padding-bottom: calc(var(--tab-bar) + env(safe-area-inset-bottom));
}

body.no-tabs { padding-bottom: env(safe-area-inset-bottom); }

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.02em; font-weight: 700; }

a { color: var(--brand-strong); }
@media (prefers-color-scheme: dark) { a { color: var(--brand); } }

img, svg { max-width: 100%; }
[hidden] { display: none !important; }

/* Only ever show focus rings for keyboard users. */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

/* Kill the blue tap flash; every interactive element has its own :active state. */
button, a, .tap { -webkit-tap-highlight-color: transparent; }

/* =========================== app bar ================================== */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  height: calc(var(--app-bar) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

@supports not (backdrop-filter: blur(1px)) {
  .appbar { background: var(--surface); }
}

.appbar-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 16px;
  font-weight: 700;
  /* Long topic names must not push the bar's buttons off screen. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(150deg, var(--brand) 0%, var(--brand-strong) 100%);
  color: var(--brand-ink);
  font-size: 15px;
  font-weight: 800;
  box-shadow: var(--sh-brand);
  flex: 0 0 auto;
}

/* A 40px box around a 20px glyph: the icon looks small, the target is not. */
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background 140ms var(--ease);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chip svg { width: 15px; height: 15px; }
.chip:active { background: var(--surface-2); }

/* =========================== layout ================================== */
main { max-width: var(--page); margin: 0 auto; padding: 16px 16px 28px; }
.stack > * + * { margin-top: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  box-shadow: var(--sh-1);
}
.card-flush { padding: 0; overflow: hidden; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.eyebrow {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 0;
}

.h-lg { font-size: 21px; }
.h-md { font-size: 17px; }
.muted { color: var(--text-2); }
.small { font-size: 13.5px; }
.center { text-align: center; }

/* =========================== buttons ================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  font: inherit;
  font-weight: 650;
  font-size: 15.5px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 120ms var(--ease), background 140ms var(--ease), box-shadow 140ms var(--ease);
}
.btn:active { transform: scale(0.985); }
.btn svg { width: 18px; height: 18px; flex: 0 0 auto; }

.btn-primary {
  background: linear-gradient(160deg, var(--brand) 0%, var(--brand-strong) 100%);
  color: var(--brand-ink);
  box-shadow: var(--sh-brand);
}
.btn-primary:disabled { opacity: 0.5; box-shadow: none; cursor: default; transform: none; }

.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); box-shadow: var(--sh-1); }
.btn-secondary:active { background: var(--surface-2); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:active { background: var(--surface-2); }

.btn-block { width: 100%; }
.btn-lg { min-height: 54px; font-size: 16.5px; }
.btn-sm { min-height: 38px; padding: 0 14px; font-size: 13.5px; border-radius: var(--r-sm); }

/* =========================== hero (landing) =========================== */
.hero { padding: 30px 0 8px; text-align: center; position: relative; }

/* Two soft brand washes instead of a flat block of colour. */
.hero::before {
  content: "";
  position: absolute;
  inset: -60px -40px auto;
  height: 320px;
  background:
    radial-gradient(60% 60% at 30% 0%, var(--brand-tint) 0%, transparent 70%),
    radial-gradient(50% 50% at 80% 10%, var(--brand-tint-2) 0%, transparent 70%);
  z-index: -1;
  pointer-events: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 13px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--sh-1);
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text-2);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }

.hero h1 {
  margin: 18px 0 12px;
  font-size: clamp(27px, 8.4vw, 42px);
  font-weight: 800;
  letter-spacing: -0.035em;
}
.hero .lede {
  margin: 0 auto;
  max-width: 30em;
  color: var(--text-2);
  font-size: clamp(15px, 4vw, 17.5px);
}
.hero-cta { margin-top: 26px; display: grid; gap: 10px; }
@media (min-width: 520px) {
  .hero-cta { grid-auto-flow: column; justify-content: center; }
  .hero-cta .btn { min-width: 190px; }
}

/* =========================== stats =================================== */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--sh-1);
}
.stat-n {
  display: block;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.stat-k { font-size: 11px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); }

/* =========================== feature rows ============================ */
.features { display: grid; gap: 10px; }
.feature { display: flex; gap: 13px; align-items: flex-start; }
.feature-ico {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  flex: 0 0 auto;
  border-radius: 11px;
  background: var(--brand-tint);
  color: var(--brand-strong);
}
@media (prefers-color-scheme: dark) { .feature-ico { color: var(--brand); } }
.feature-ico svg { width: 19px; height: 19px; }
.feature h3 { font-size: 15px; margin-bottom: 2px; }
.feature p { margin: 0; color: var(--text-2); font-size: 13.5px; }

/* =========================== list rows =============================== */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li + li { border-top: 1px solid var(--border); }

.row-link {
  display: flex;
  align-items: center;
  gap: 12px;
  /* 60px tall: comfortably past the 44px minimum touch target. */
  min-height: 60px;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--text);
  transition: background 130ms var(--ease);
}
.row-link:active { background: var(--surface-2); }

.row-ico {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--brand-tint);
  color: var(--brand-strong);
  font-size: 13.5px;
  font-weight: 800;
}
@media (prefers-color-scheme: dark) { .row-ico { color: var(--brand); } }

.row-body { flex: 1 1 auto; min-width: 0; }
/* Both are spans, so they need to be told to stack. */
.row-title { display: block; font-weight: 650; font-size: 15px; }
.row-meta { display: block; color: var(--text-3); font-size: 12.5px; margin-top: 1px; }
.row-chev { color: var(--text-3); flex: 0 0 auto; }
.row-chev svg { width: 18px; height: 18px; display: block; }

/* =========================== forms =================================== */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; font-weight: 650; color: var(--text-2); margin-bottom: 6px; }

.input {
  width: 100%;
  min-height: 52px;
  padding: 0 15px;
  font: inherit;
  font-size: 16px; /* 16px keeps iOS Safari from zooming on focus. */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
.input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}
.input::placeholder { color: var(--text-3); }

/* =========================== toasts ================================== */
.toast {
  max-width: var(--page);
  margin: 12px auto 0;
  padding: 12px 15px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--sh-2);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.toast svg { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; }
.toast-ok { color: var(--ok); border-color: var(--ok-border); background: var(--ok-tint); }
.toast-bad { color: var(--bad); border-color: var(--bad-border); background: var(--bad-tint); }
@media (min-width: 752px) { .toast { margin-top: 16px; } }

/* =========================== bottom tab bar ========================== */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}
@supports not (backdrop-filter: blur(1px)) { .tabbar { background: var(--surface); } }

.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--tab-bar);
  text-decoration: none;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 650;
  background: none;
  border: 0;
  cursor: pointer;
}
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--brand-strong); }
@media (prefers-color-scheme: dark) { .tab[aria-current="page"] { color: var(--brand); } }
.tab:active { background: var(--surface-2); }

/* =========================== quiz ==================================== */
/* The progress bar sits under the app bar and stays put while options scroll. */
.quiz-progress {
  position: sticky;
  top: calc(var(--app-bar) + env(safe-area-inset-top));
  z-index: 25;
  height: 3px;
  background: var(--border);
}
.quiz-progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--brand) 0%, var(--brand-strong) 100%);
  transition: width 240ms var(--ease);
}
@media (prefers-reduced-motion: reduce) { .quiz-progress-bar { transition: none; } }

.quiz-fill {
  min-height: calc(100vh - var(--app-bar) - var(--tab-bar) - 58px);
  min-height: calc(100dvh - var(--app-bar) - var(--tab-bar) - 58px);
  display: flex;
  flex-direction: column;
}
.quiz-fill .quiz-actions { margin-top: auto; }

.quiz-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.counter {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.stem {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.45;
  margin: 0 0 16px;
  letter-spacing: -0.012em;
}

/* One option per row on a phone: full width is the easiest thumb target. */
.options { display: grid; gap: 9px; }

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 12px 14px;
  text-align: left;
  font: inherit;
  font-size: 15.5px;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color 140ms var(--ease), background 140ms var(--ease), transform 120ms var(--ease);
}
.option:active:not(:disabled) { transform: scale(0.99); }
.option:disabled { cursor: default; }

.option-key {
  display: grid;
  place-items: center;
  width: 30px; height: 30px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 800;
}
.option-text { flex: 1 1 auto; min-width: 0; }

/* The right answer is always revealed, whether or not it was picked. */
.option.is-correct { border-color: var(--ok); background: var(--ok-tint); }
.option.is-correct .option-key { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.option.is-wrong { border-color: var(--bad); background: var(--bad-tint); }
.option.is-wrong .option-key { background: var(--bad); border-color: var(--bad); color: var(--surface); }

.verdict { margin-top: 16px; animation: rise 220ms var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .verdict { animation: none; } }

.verdict-line { display: flex; align-items: center; gap: 7px; margin: 0; font-weight: 700; font-size: 14.5px; }
.verdict-line svg { width: 17px; height: 17px; }
.verdict-line.ok { color: var(--ok); }
.verdict-line.bad { color: var(--bad); }

.solution {
  margin-top: 11px;
  padding: 13px 15px;
  background: var(--surface-2);
  border-radius: var(--r-md);
  border-left: 3px solid var(--brand);
  color: var(--text-2);
  font-size: 14.5px;
  line-height: 1.6;
  overflow-x: auto;
}
.solution-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 4px;
}

/* Next sits above the tab bar, in reach of a thumb, and never covers an option. */
.quiz-actions {
  position: sticky;
  bottom: calc(var(--tab-bar) + env(safe-area-inset-bottom) + 10px);
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.quiz-actions .btn { flex: 1 1 auto; }
.score {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Score ring on the summary card. */
.result-ring {
  --pct: 0;
  width: 128px; height: 128px;
  margin: 4px auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    conic-gradient(var(--brand) calc(var(--pct) * 1%), var(--border) 0),
    var(--surface);
  position: relative;
}
.result-ring::after {
  content: "";
  position: absolute;
  inset: 11px;
  border-radius: 50%;
  background: var(--surface);
}
.result-ring > div { position: relative; text-align: center; }
.result-pct { display: block; font-size: 30px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.result-sub { font-size: 12px; color: var(--text-3); font-weight: 650; }

/* =========================== realtime feed =========================== */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  border-radius: var(--r-full);
  border: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-3);
  white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill[data-state="live"] { color: var(--ok); border-color: var(--ok-border); background: var(--ok-tint); }
.pill[data-state="connecting"] { color: var(--warn); background: var(--warn-tint); }
.pill[data-state="offline"] { color: var(--bad); border-color: var(--bad-border); background: var(--bad-tint); }

.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.feed li {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 11px 13px;
  background: var(--surface-2);
  animation: rise 220ms var(--ease);
}
@media (prefers-reduced-motion: reduce) { .feed li { animation: none; } }
.feed .row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.feed .name { font-weight: 700; font-size: 14px; }
.feed .meta { color: var(--text-3); font-size: 11.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.feed pre {
  margin: 7px 0 0;
  padding: 9px 10px;
  background: var(--surface);
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 12px;
  color: var(--text-2);
}

/* =========================== misc ==================================== */
.empty { color: var(--text-3); font-size: 14px; margin: 0; }

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { border-collapse: collapse; width: 100%; font-size: 14px; }
.table th, .table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-3); }
.table tbody tr:last-child td { border-bottom: 0; }

code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 12.5px;
}

.foot { max-width: var(--page); margin: 0 auto; padding: 22px 16px; color: var(--text-3); font-size: 12px; text-align: center; }

/* KaTeX must inherit our colour and never widen the page. */
.katex { color: inherit; font-size: 1.03em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }

/* =========================== wider screens =========================== */
@media (min-width: 640px) {
  main { padding: 22px 20px 32px; }
  .card { padding: 22px; }
  .options { grid-template-columns: 1fr 1fr; }
  .stats { gap: 10px; }
  .stat { padding: 16px 12px; }
  .stat-n { font-size: 25px; }
  .features { grid-template-columns: 1fr 1fr; gap: 16px; }
  .stem { font-size: 18px; }
}
