:root {
  /* Glauca palette — github.com/tiagojct/glauca (Pruina light / Profundum dark).
     The --log- and --crew- slot names are inherited from the prior Pequod theme
     so the ~130 downstream references (and script.js canvas reads) keep working with
     only the values changed. The neutral ramp is one fixed pale→deep cool scale
     shared by both modes: light picks pale steps for surfaces + deep for ink,
     dark inverts. Crew slots carry Glauca's blue mark plus the extended hues
     (folium green, bacca red) and the blue-copper warm axis that diagcalc's
     colour-coded metrics still need. */
  /* Neutrals (glaucum/pruina/saxum): pale bloom → deep sea */
  --log-50:  #F0F4F6;
  --log-100: #E8EEF2;
  --log-150: #D9E2E7;
  --log-200: #CDD7DC;
  --log-300: #B7CDD6;
  --log-400: #93B7C9;
  --log-500: #6C93A8;
  --log-600: #4D7391;
  --log-700: #2A3540;
  --log-800: #16303F;
  --log-900: #171F26;
  --log-950: #10161C;

  /* Crew accents (light variants) — Glauca hues, deepened for AA on the pale ground */
  --crew-ahab:     #B34A44;  /* bacca red — error / rule-out failed */
  --crew-starbuck: #007AFF;  /* dies blue — info / focus ring / pre-test marker */
  --crew-queequeg: #0B62CF;  /* accent blue — primary action */
  --crew-pip:      #8F5E08;  /* copper — warning / threshold bands (AA text 5.0:1) */
  --crew-ishmael:  #55646D;  /* cinis gray — muted / axis */
  --crew-stubb:    #B97435;  /* copper — LR+ trace (mark, not text) */
  --crew-tashtego: #307719;  /* folium green — LR− / success (AA text 5.0:1) */
  --crew-daggoo:   #8F4F16;  /* deep copper — sequential second-stage */

  /* Semantic tokens — legacy Pequod slot names, Glauca values. */
  --bg:             var(--log-50);
  --surface:        var(--log-100);
  --surface-soft:   rgba(240, 244, 246, 0.92);
  --border:         var(--log-200);
  --text:           var(--log-800);
  --text-strong:    var(--log-900);
  --text-muted:     var(--crew-ishmael);
  --primary:        var(--crew-queequeg);
  --primary-strong: var(--log-800);
  --secondary:      var(--crew-starbuck);
  --success:        var(--crew-tashtego);
  --warning:        var(--crew-pip);
  --error:          var(--crew-ahab);
  --accent-warm:    var(--crew-stubb);
  --axis:           var(--log-400);

  /* Spacing scale — 4-pt grid. Use in padding/margin/gap to keep rhythm. */
  --space-1: 0.25rem;  /*  4px */
  --space-2: 0.5rem;   /*  8px */
  --space-3: 0.75rem;  /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-5: 1.5rem;   /* 24px */
  --space-6: 2rem;     /* 32px */
  --space-7: 3rem;     /* 48px */
  --space-8: 4rem;     /* 64px */

  /* Type scale — clamp-friendly steps. */
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.5rem;
  --text-2xl:  2rem;
  --text-3xl:  2.75rem;

  /* Corner radii. */
  --radius-1: 4px;
  --radius-2: 6px;
  --radius-3: 8px;
  --radius-pill: 999px;

  /* Motion */
  --duration-fast: 120ms;
  --duration-base: 200ms;
  --duration-slow: 320ms;
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);

  /* Elevation — used sparingly for hover lifts only */
  --shadow-1: 0 1px 2px rgba(16, 22, 28, 0.06), 0 1px 3px rgba(16, 22, 28, 0.04);
  --shadow-2: 0 2px 4px rgba(16, 22, 28, 0.08), 0 4px 10px rgba(16, 22, 28, 0.06);

  font-family: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: normal;
}

body {
  font-family: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  background-color: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0;
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
  width: min(1380px, 94vw);
  margin: 0 auto;
  padding: var(--space-5) 0 var(--space-6);
}

/* ── Unified keyboard focus ring ───────────────────────────────────────────
   One rule for every interactive element. :focus-visible means the ring only
   shows on keyboard navigation, never on mouse click — so the visual is
   intentional, not noisy. Starbuck cyan, 2 px offset. */
:is(
  button,
  [type="text"],
  [type="number"],
  [type="date"],
  [type="email"],
  select,
  summary,
  a,
  input[type="range"],
  input[type="checkbox"],
  [tabindex]
):focus-visible {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
  border-radius: 4px;
}

footer {
  font-size: 0.85em;
  text-align: center;
  padding: 1.5em;
  margin-top: 3em;
  background-color: transparent;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
}

footer .privacy-note {
  display: inline-block;
  margin: 0.5rem auto;
  padding: 0.45rem 0.9rem;
  border-radius: 4px;
  background-color: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
}

/* ── App bar (v4.0) ─────────────────────────────────────────────────────── */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(8px);
}

.app-bar-inner {
  width: min(1380px, 94vw);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  min-height: 3rem;
}

.app-bar-brand {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  min-width: 0;
}

.brand-mark {
  font-weight: 800;
  font-size: var(--text-lg);
  letter-spacing: 0.02em;
  color: var(--text-strong);
}

.app-bar-version {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  align-self: center;
}

.app-bar-divider {
  color: var(--text-muted);
  font-weight: 600;
}

.app-bar-case {
  font-size: var(--text-sm);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar-case.has-case {
  color: var(--text);
  font-weight: 600;
}

.app-bar-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.theme-toggle {
  width: auto;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-1);
  cursor: pointer;
  font-size: var(--text-base);
  line-height: 1;
  transition: background-color var(--duration-fast) var(--ease-out);
}

.theme-toggle:hover {
  background-color: var(--surface-soft);
}

.lang-picker {
  display: inline-flex;
  align-items: center;
}

.lang-picker select {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  width: auto;
  border-radius: var(--radius-1);
  border: 1px solid var(--border);
  background-color: transparent;
  color: var(--text);
  cursor: pointer;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

h1 {
  font-size: var(--text-2xl);
  margin: 0 0 var(--space-3);
  font-weight: 700;
  letter-spacing: -0.01em;
}

h2 {
  font-size: var(--text-xl);
  margin-bottom: var(--space-4);
  color: var(--text-strong);
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ── About panel (formerly intro highlights) ───────────────────────────── */
.about-panel .about-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
}

.about-card {
  background-color: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  padding: var(--space-4);
}

.about-card h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-base);
  color: var(--text-strong);
  font-weight: 700;
}

.about-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 1.55;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
  align-items: start;
  margin-top: var(--space-5);
}

@media (min-width: 960px) {
  .workspace {
    grid-template-columns: minmax(340px, 34%) 1fr;
  }
  .panel-results {
    position: sticky;
    top: calc(3rem + var(--space-4));
  }
}

.panel {
  background-color: transparent;
  border-radius: 0;
  padding: var(--space-4) 0;
}

.panel-form {
  border-right: 1px solid var(--border);
  padding-right: var(--space-5);
}

@media (max-width: 959px) {
  .panel-form {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: var(--space-5);
  }
}

.panel-form,
.panel-results {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.panel-heading {
  margin-bottom: 1.25rem;
}

.panel-heading-inline {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.panel-kicker {
  margin: 0 0 0.35rem;
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.resource-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

.section-heading {
  margin-bottom: 2rem;
}

.section-heading p {
  color: var(--text-muted);
  max-width: 640px;
}

form {
  background-color: transparent;
  border-radius: 8px;
  padding: 0;
  box-shadow: none;
  border: none;
}

.form-row {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}

.form-row label {
  font-weight: 600;
}

.full {
  width: 100%;
}

select {
  padding: 0.85rem 1rem;
  border: 2px solid var(--border);
  border-radius: 4px;
  background-color: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s;
  cursor: pointer;
}

select:focus {
  border-color: var(--primary);
  outline: none;
}

optgroup {
  font-weight: 600;
  color: var(--text-strong);
  font-style: normal;
}

option {
  padding: 0.5rem;
  color: var(--text);
}

.help-text {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.confusion-matrix {
  border: 2px solid var(--log-150);
  border-radius: 8px;
  padding: 1.25rem;
  margin: 0 0 2rem;
  background-color: var(--surface-soft);
}

.confusion-matrix legend {
  font-weight: 600;
  padding: 0 0.75rem;
}

.grid-container {
  display: grid;
  grid-template-columns: 92px repeat(2, minmax(120px, 1fr));
  gap: 0.75rem;
  align-items: stretch;
}

.grid-header {
  text-align: center;
  padding: 0.75rem;
  border-radius: 4px;
  font-weight: 600;
  color: var(--log-50);
  background-color: var(--primary);
}

.grid-label {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.75rem;
  border-radius: 4px;
  font-weight: 600;
  color: var(--log-50);
  background-color: var(--log-700);
  text-align: center;
}

.grid-item {
  text-align: center;
  padding: 0.75rem;
  background-color: var(--bg);
  border-radius: 4px;
  border: 2px solid var(--border);
  box-shadow: none;
  transition: border-color 0.2s ease;
}

.grid-item:hover {
  border-color: var(--log-400);
}

/* Input Styling — use JetBrains Mono for numeric input grids so digits align */
.grid-item input,
.preTestProb {
  width: 100%;
  padding: 0.85rem 1rem;
  margin: 0;
  border: 2px solid var(--border);
  border-radius: 4px;
  box-sizing: border-box;
  transition: border-color 0.2s;
  font-size: 1rem;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  background-color: var(--bg);
  color: var(--text);
}

.grid-item input::placeholder,
.preTestProb::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.grid-item input:focus,
.preTestProb:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: none;
}

/* Button Styles */
button {
  width: 100%;
  background: var(--primary);
  color: var(--log-50);
  padding: 0.9rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1em;
  font-family: inherit;
  font-weight: 600;
  transition: background-color 0.2s;
}

button:hover {
  background-color: var(--primary-strong);
  transform: none;
  box-shadow: none;
}

.secondary {
  background: transparent;
  color: var(--text-muted);
  border: 2px solid var(--border);
  box-shadow: none;
}

.secondary:hover {
  background-color: var(--log-150);
  border-color: var(--log-300);
  box-shadow: none;
}

.form-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.feedback {
  min-height: 1.25rem;
  font-weight: 600;
}

.feedback.success {
  color: var(--success);
}

.feedback.error {
  color: var(--crew-ahab);
}

.results-section {
  margin-top: 0;
}

.results-actions {
  display: flex;
  justify-content: flex-end;
  margin: 0;
}

/* ── Results hierarchy (v4.0) ───────────────────────────────────────────── */

.results-headline {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: var(--space-5);
  row-gap: var(--space-4);
}

@media (min-width: 540px) {
  .results-headline {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.results-secondary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  column-gap: var(--space-5);
  row-gap: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
}

/* Result cards: no fills, no borders — typography and the inline bar/band
   carry the visual signal. Minimal. */
.result-card {
  background-color: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: relative;
}

.result-card:empty { display: none; }

.result-card h3 {
  margin: 0;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.3;
}

/* Reserve two lines of label height in the headline strip so single-line
   labels (Sensitivity, Specificity) align with two-line ones (Post-test
   probability …) — values sit on a shared baseline across cards. */
.results-headline .result-card h3 {
  min-height: calc(var(--text-xs) * 1.3 * 2);
}

.result-value {
  font-size: var(--text-xl);
  font-weight: 700;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text-strong);
  margin: 0;
  line-height: 1.05;
}

.result-ci {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  margin: 0;
}

.result-note {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.result-card--lg .result-value { font-size: var(--text-2xl); }
.result-card--sm .result-value { font-size: var(--text-lg); }

/* ── Bayesian update strip ─────────────────────────────────────────────── */
.bayesian-update {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.bayesian-update:empty {
  display: none;
}

.bayesian-row {
  display: grid;
  grid-template-columns: 6rem auto 1fr auto 4.5rem;
  column-gap: var(--space-3);
  align-items: center;
  font-size: var(--text-sm);
}

@media (max-width: 600px) {
  .bayesian-row {
    grid-template-columns: 1fr auto auto;
    grid-template-areas:
      "label label lr"
      "from axis to";
    row-gap: var(--space-1);
  }
  .bayesian-row-label { grid-area: label; }
  .bayesian-row-lr    { grid-area: lr; }
  .bayesian-row-from  { grid-area: from; }
  .bayesian-axis      { grid-area: axis; }
  .bayesian-row-to    { grid-area: to; }
}

/* Below the 520 px mark the 3-row template above still squeezes the axis
   into a half-width column. Stack everything onto its own line so the
   pre-test → axis → post-test progression reads as a top-to-bottom flow. */
@media (max-width: 520px) {
  .bayesian-row {
    grid-template-columns: 1fr;
    grid-template-areas:
      "label"
      "from"
      "axis"
      "to"
      "lr";
    row-gap: var(--space-2);
    text-align: left;
  }
}

.bayesian-row-label {
  font-weight: 700;
  color: var(--text);
}

.bayesian-row-from,
.bayesian-row-to {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
}

.bayesian-row-from {
  color: var(--text-muted);
  text-align: right;
}

.bayesian-row-to {
  color: var(--text-strong);
  font-weight: 700;
  text-align: left;
}

.bayesian-row-lr {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  text-align: right;
  font-size: var(--text-xs);
  white-space: nowrap;
}

.bayesian-axis {
  position: relative;
  height: 1.5rem;
}

.bayesian-axis::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background-color: var(--border);
  transform: translateY(-50%);
}

.bayesian-axis-trail {
  position: absolute;
  top: 50%;
  height: 2px;
  transform: translateY(-50%);
  background-color: var(--text-muted);
}

.bayesian-row--warm .bayesian-axis-trail { background-color: var(--accent-warm); height: 3px; }
.bayesian-row--cool .bayesian-axis-trail { background-color: var(--success);     height: 3px; }

/* Big, clearly visible arrowhead at the post end of the trail. */
.bayesian-axis-trail::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -10px;
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  transform: translateY(-50%);
}

.bayesian-row--warm .bayesian-axis-trail::after { border-left: 11px solid var(--accent-warm); }
.bayesian-row--cool .bayesian-axis-trail::after { border-left: 11px solid var(--success); }

/* RTL: arrow points left when post-test < pre-test (e.g. negative test). */
.bayesian-axis.rtl .bayesian-axis-trail::after {
  right: auto;
  left: -10px;
  border-left: none;
  border-right: 11px solid;
}

.bayesian-row--warm .bayesian-axis.rtl .bayesian-axis-trail::after { border-right-color: var(--accent-warm); }
.bayesian-row--cool .bayesian-axis.rtl .bayesian-axis-trail::after { border-right-color: var(--success); }

.bayesian-axis-pre,
.bayesian-axis-post {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

.bayesian-axis-pre {
  width: 10px;
  height: 10px;
  background: var(--bg);
  border: 2px solid var(--text-muted);
  z-index: 2;
}

.bayesian-axis-post {
  width: 12px;
  height: 12px;
  z-index: 3;
  border: 2px solid var(--bg);
}

.bayesian-row--warm .bayesian-axis-post { background-color: var(--accent-warm); }
.bayesian-row--cool .bayesian-axis-post { background-color: var(--success); }

/* ── Inline fill bar on percentage result cards ────────────────────────── */
.result-bar {
  position: relative;
  height: 3px;
  border-radius: var(--radius-pill);
  background-color: var(--border);
  overflow: hidden;
  margin: var(--space-1) 0 0;
}

.result-bar-fill {
  display: block;
  height: 100%;
  border-radius: var(--radius-pill);
  background-color: var(--text-muted);
  transition: width var(--duration-base) var(--ease-out);
}

.result-bar--neutral .result-bar-fill { background-color: var(--secondary); }
.result-bar--warm .result-bar-fill    { background-color: var(--accent-warm); }
.result-bar--cool .result-bar-fill    { background-color: var(--success); }

/* ── Clinical-utility band indicators on LR / DOR cards ────────────────── */
.result-band {
  position: relative;
  display: flex;
  height: 6px;
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin: var(--space-1) 0 0;
}

.result-band-zone {
  flex: 1 1 0;
  position: relative;
}

/* LR+: weak → limited → useful → rule-in */
.result-band--lr-plus .result-band-zone--0 { background-color: rgba(168, 55, 50, 0.35); }
.result-band--lr-plus .result-band-zone--1 { background-color: rgba(202, 100, 53, 0.35); }
.result-band--lr-plus .result-band-zone--2 { background-color: rgba(106, 74, 0, 0.35); }
.result-band--lr-plus .result-band-zone--3 { background-color: rgba(23, 124, 85, 0.40); }

/* LR-: rule-out → useful → limited → weak */
.result-band--lr-minus .result-band-zone--0 { background-color: rgba(23, 124, 85, 0.40); }
.result-band--lr-minus .result-band-zone--1 { background-color: rgba(106, 74, 0, 0.35); }
.result-band--lr-minus .result-band-zone--2 { background-color: rgba(202, 100, 53, 0.35); }
.result-band--lr-minus .result-band-zone--3 { background-color: rgba(168, 55, 50, 0.35); }

/* DOR: poor → limited → useful → very strong */
.result-band--dor .result-band-zone--0 { background-color: rgba(168, 55, 50, 0.35); }
.result-band--dor .result-band-zone--1 { background-color: rgba(202, 100, 53, 0.35); }
.result-band--dor .result-band-zone--2 { background-color: rgba(106, 74, 0, 0.35); }
.result-band--dor .result-band-zone--3 { background-color: rgba(23, 124, 85, 0.40); }

.result-band-marker {
  position: absolute;
  top: 50%;
  width: 3px;
  height: 12px;
  transform: translate(-50%, -50%);
  border-radius: 1px;
  background-color: var(--text-strong);
  pointer-events: none;
  z-index: 1;
}

[data-theme="dark"] .result-band-marker {
  background-color: var(--log-50);
}

.interpretation {
  margin-top: 0;
}

.interpretation details {
  border: 2px solid var(--log-150);
  border-radius: 4px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  background-color: var(--bg);
}

.interpretation summary {
  font-weight: 600;
  cursor: pointer;
}

.interpretation p {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
}

/* Dataset Reference */
.dataset-reference {
  margin-top: 1rem;
  padding: 1rem;
  background-color: var(--surface);
  border-left: 4px solid var(--primary);
  border-radius: 4px;
  font-size: 0.9rem;
}

.dataset-reference h4 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--text-strong);
}

.dataset-reference p {
  margin: 0.25rem 0;
  color: var(--text);
}

.dataset-reference .reference-citation {
  font-style: italic;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Fagan Nomogram */
.fagan-nomogram {
  background-color: var(--surface);
  border-radius: 8px;
  padding: 1.5rem;
  border: 2px solid var(--border);
  margin-bottom: 1.5rem;
  text-align: center;
}

.fagan-nomogram h3 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
  color: var(--text-strong);
}

.fagan-nomogram canvas {
  max-width: 100%;
  width: 600px;
  height: 400px;
  margin-top: 1rem;
  border: 1px solid var(--log-150);
  border-radius: 4px;
}

.fagan-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.5rem 0.75rem;
  margin: 1rem auto 0;
  max-width: 600px;
  padding: 0.75rem 1rem;
  background-color: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-align: left;
}

.fagan-summary-item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.fagan-summary-item dt {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0;
}

.fagan-summary-item dd {
  margin: 0;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Unified disclosure marker ─────────────────────────────────────────────
   One thin outlined chevron for every collapsible panel: two 1.5 px strokes
   (border-right + border-bottom) rotated 45° so they form a right-pointing
   "›" rather than a filled triangle. Inherits text colour via currentColor.
   Rotates to point down on [open]. */
.advanced-settings > summary::before,
.history-panel > summary::before,
.roc-panel > summary::before,
.threshold-panel > summary::before,
.sequential-test > summary::before,
.prevalence-explorer > summary::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 0.65em 2px 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  vertical-align: middle;
  opacity: 0.55;
  transition: transform 0.15s ease;
}

.advanced-settings[open] > summary::before,
.history-panel[open] > summary::before,
.roc-panel[open] > summary::before,
.threshold-panel[open] > summary::before,
.sequential-test[open] > summary::before,
.prevalence-explorer[open] > summary::before {
  transform: rotate(45deg);
  margin-top: -2px;
  margin-bottom: 0;
}

@media (prefers-reduced-motion: reduce) {
  .advanced-settings > summary::before,
  .history-panel > summary::before,
  .roc-panel > summary::before,
  .threshold-panel > summary::before,
  .sequential-test > summary::before,
  .prevalence-explorer > summary::before {
    transition: none;
  }
}

/* ── Summary tags (tool / reference) ───────────────────────────────────────
   Small badges inside disclosure summaries that mark which panels are
   interactive tools (filled, Queequeg) and which are read-only reference
   material (outlined, muted). Sit right after the chevron and before the
   summary's strong text. */
.summary-tag {
  display: inline-block;
  margin-right: var(--space-3);
  padding: 2px var(--space-2);
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.4;
  vertical-align: 2px;
  white-space: nowrap;
}

.summary-tag--tool {
  background-color: var(--primary);
  color: var(--log-50);
}

.summary-tag--ref {
  background-color: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* Advanced settings (inside the form panel) */
.advanced-settings {
  margin-bottom: 1.25rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  background-color: var(--bg-elevated, transparent);
}

.advanced-settings > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  list-style: none;
}

.advanced-settings > summary::-webkit-details-marker {
  display: none;
}

.advanced-settings .form-row {
  margin: 0.75rem 0 0;
}

/* Calculation history panel */
.history-panel {
  background-color: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-top: 1.5rem;
}

.history-panel > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-strong);
  font-size: 1.05rem;
  line-height: 1.4;
  list-style: none;
}

.history-panel > summary::-webkit-details-marker {
  display: none;
}

.history-list {
  list-style: none;
  margin: 1rem 0 0.75rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: center;
  background-color: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
}

.history-item input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
  cursor: pointer;
}

.history-item-label {
  display: grid;
  gap: 0.15rem;
  cursor: pointer;
  min-width: 0;
}

.history-item-title {
  font-weight: 700;
  color: var(--text);
}

.history-item-meta,
.history-item-stats {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  color: var(--text-muted);
  word-break: break-word;
}

.history-item-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history-item-actions {
  display: flex;
  gap: 0.4rem;
}

.history-item-actions button {
  width: auto;
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
}

.history-item-delete {
  padding: 0.4rem 0.6rem;
  color: var(--crew-ahab);
  border-color: var(--border);
}

.history-item-delete:hover {
  background-color: var(--crew-ahab);
  color: var(--log-50);
}

.history-compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin: 0.5rem 0 1rem;
}

.history-compare-table th,
.history-compare-table td {
  padding: 0.45rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.history-compare-table thead th {
  background-color: var(--surface-soft);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom-width: 2px;
}

.history-compare-table tbody th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.history-compare-table tbody td {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 600;
}

.history-compare:empty {
  display: none;
}

@media (max-width: 720px) {
  .history-item {
    grid-template-columns: auto 1fr;
  }
  .history-item-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

/* STARD critical-appraisal panel */
.stard-panel .panel-kicker {
  color: var(--crew-pip);
}

.stard-panel details {
  border: 2px solid var(--log-150);
  border-radius: 4px;
  padding: 0.85rem 1.1rem;
  margin-bottom: 0.75rem;
  background-color: var(--bg);
}

.stard-panel summary {
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}

.stard-panel details p {
  margin: 0.6rem 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.stard-panel details em {
  font-style: italic;
  color: var(--text);
}

/* Cohen's kappa companion panel */
.kappa-panel .panel-kicker {
  color: var(--crew-tashtego);
}

.kappa-matrix {
  margin-top: 0.5rem;
  margin-bottom: 1rem;
}

.kappa-panel .form-actions {
  grid-template-columns: auto auto;
  justify-content: flex-start;
  gap: 0.75rem;
}

.kappa-panel .form-actions button {
  width: auto;
  padding: 0.55rem 1.1rem;
}

.kappa-result {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.kappa-result:empty {
  display: none;
}

.kappa-stat {
  background-color: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.kappa-stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.kappa-stat-value {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.kappa-error {
  color: var(--crew-ahab);
  font-weight: 600;
  margin: 0;
}

/* ROC reconstruction panel */
.roc-panel {
  background-color: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-top: 1.5rem;
}

.roc-panel > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-strong);
  font-size: 1.05rem;
  line-height: 1.4;
  list-style: none;
}

.roc-panel > summary::-webkit-details-marker {
  display: none;
}

.roc-table-wrapper {
  overflow-x: auto;
  margin: 1rem 0;
}

.roc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.roc-table th,
.roc-table td {
  padding: 0.45rem 0.5rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.roc-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  border-bottom-width: 2px;
}

.roc-table input[type="number"] {
  width: 100%;
  min-width: 60px;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background-color: var(--bg);
  color: var(--text);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.roc-table input[type="number"]:focus {
  border-color: var(--primary);
  outline: none;
}

.roc-remove {
  width: auto;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--crew-ahab);
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 700;
}

.roc-remove:hover {
  background-color: var(--crew-ahab);
  color: var(--log-50);
}

.roc-panel .form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 0.75rem;
  margin: 0.5rem 0 1rem;
}

/* Synthetic rows are scaffolding — fainter so the user can still tell them
   apart from rows they typed themselves. They become first-class as soon as
   the user edits any cell (the JS strips the class on input). */
.roc-row--synthetic input[type="number"] {
  color: var(--text-muted);
  border-style: dashed;
}

.roc-panel .form-actions button {
  width: auto;
  padding: 0.6rem 1rem;
}

.roc-panel canvas {
  display: block;
  width: 100%;
  max-width: 480px;
  aspect-ratio: 1 / 1;
  height: auto;
  margin: 0 auto 1rem;
  border: 1px solid var(--log-150);
  border-radius: 4px;
  background: var(--bg);
}

.roc-readout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.roc-flash {
  grid-column: 1 / -1;
  margin: 0;
  padding: 0.55rem 0.85rem;
  border-radius: 4px;
  background-color: var(--surface);
  border-left: 3px solid var(--secondary);
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.4;
}

.roc-stat {
  background-color: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.roc-stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.roc-stat-value {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

/* Bias warnings callout */
.bias-warnings {
  display: none;
  margin: 0 0 1rem;
  padding: 0.9rem 1.1rem;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--crew-pip);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.92rem;
}

.bias-warnings.visible {
  display: block;
}

.bias-warnings-heading {
  margin: 0 0 0.4rem;
  font-weight: 700;
  color: var(--crew-pip);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.78rem;
}

.bias-warnings-list {
  margin: 0;
  padding-left: 1.2rem;
}

.bias-warnings-list li {
  margin-bottom: 0.35rem;
}

.bias-warnings-list li:last-child {
  margin-bottom: 0;
}

/* Pauker–Kassirer decision thresholds */
.threshold-panel {
  background-color: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-top: 1.5rem;
}

.threshold-panel > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-strong);
  font-size: 1.05rem;
  line-height: 1.4;
  list-style: none;
}

.threshold-panel > summary::-webkit-details-marker {
  display: none;
}

.threshold-input {
  margin: 1rem 0 1.25rem;
}

.threshold-input label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.threshold-input output {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--crew-pip);
  font-weight: 700;
  font-size: 1.05rem;
}

.threshold-input input[type="range"] {
  width: 100%;
  height: 1.5rem;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.threshold-input input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--log-150);
  border-radius: 3px;
}

.threshold-input input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--crew-pip);
  border-radius: 50%;
  margin-top: -6px;
  cursor: pointer;
  transition: transform 0.1s;
}

.threshold-input input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

.threshold-input input[type="range"]::-moz-range-track {
  height: 6px;
  background: var(--log-150);
  border-radius: 3px;
}

.threshold-input input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--crew-pip);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

/* :focus ring handled globally by the :focus-visible block near the top. */

.threshold-gauge {
  position: relative;
  display: flex;
  height: 28px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin: 1rem 0 0.5rem;
}

.threshold-zone {
  height: 100%;
  flex-grow: 0;
  flex-shrink: 0;
  min-width: 0;
}

.threshold-zone-no    { background-color: var(--crew-ahab); opacity: 0.6; }
.threshold-zone-test  { background-color: var(--crew-pip); opacity: 0.55; }
.threshold-zone-treat { background-color: var(--crew-tashtego); opacity: 0.6; }

.threshold-marker {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  transform: translateX(-50%);
  pointer-events: none;
}

.threshold-marker-pt {
  background-color: var(--log-900);
}

.threshold-marker-pt::after {
  content: "Pt";
  position: absolute;
  top: -1.1rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--log-900);
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.threshold-marker-pre {
  background-color: var(--crew-queequeg);
  width: 3px;
}

.threshold-marker-pre::after {
  content: "▼";
  position: absolute;
  bottom: -0.95rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--crew-queequeg);
}

[data-theme="dark"] .threshold-marker-pt {
  background-color: var(--log-100);
}

[data-theme="dark"] .threshold-marker-pt::after {
  color: var(--log-100);
}

.threshold-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin: 1.5rem 0 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.threshold-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.threshold-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.threshold-swatch.threshold-zone-no    { background-color: var(--crew-ahab); opacity: 0.6; }
.threshold-swatch.threshold-zone-test  { background-color: var(--crew-pip); opacity: 0.55; }
.threshold-swatch.threshold-zone-treat { background-color: var(--crew-tashtego); opacity: 0.6; }
.threshold-swatch-pt  { background-color: var(--log-900); }
.threshold-swatch-pre { background-color: var(--crew-queequeg); }

[data-theme="dark"] .threshold-swatch-pt { background-color: var(--log-100); }

.threshold-readout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.threshold-stat {
  background-color: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.threshold-stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.threshold-stat-value {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

/* Sequential / chained second test */
.sequential-test {
  background-color: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-top: 1.5rem;
}

.sequential-test > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-strong);
  font-size: 1.05rem;
  line-height: 1.4;
  list-style: none;
}

.sequential-test > summary::-webkit-details-marker {
  display: none;
}

.sequential-controls {
  margin: 1rem 0 1.25rem;
}

.sequential-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--text);
}

.sequential-controls select {
  margin-top: 0.25rem;
}

.sequential-pretest {
  margin: 0.85rem 0 0;
  padding: 0.65rem 0.85rem;
  background-color: var(--surface-soft);
  border: 1px solid var(--border);
  border-left: 4px solid var(--crew-daggoo);
  border-radius: 4px;
  font-size: 0.9rem;
  color: var(--text);
}

.sequential-pretest:empty {
  display: none;
}

.confusion-matrix.sequential-matrix {
  margin-top: 0.5rem;
  margin-bottom: 1rem;
}

.sequential-results:empty {
  display: none;
}

/* Prevalence sensitivity explorer */
.prevalence-explorer {
  background-color: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-top: 1.5rem;
}

.prevalence-explorer > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-strong);
  font-size: 1.05rem;
  line-height: 1.4;
  list-style: none;
}

.prevalence-explorer > summary::-webkit-details-marker {
  display: none;
}

.prevalence-explorer .help-text {
  margin: 0.75rem 0 1rem;
}

.prevalence-controls {
  margin: 1rem 0 1.25rem;
}

.prevalence-controls label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 600;
  margin-bottom: 0.6rem;
  color: var(--text);
}

.prevalence-controls output {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  font-weight: 700;
  font-size: 1.05rem;
}

.prevalence-controls input[type="range"] {
  width: 100%;
  height: 1.5rem;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.prevalence-controls input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--log-150);
  border-radius: 3px;
}

.prevalence-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--primary);
  border-radius: 50%;
  margin-top: -6px;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.prevalence-controls input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--crew-starbuck);
  transform: scale(1.1);
}

.prevalence-controls input[type="range"]::-moz-range-track {
  height: 6px;
  background: var(--log-150);
  border-radius: 3px;
}

.prevalence-controls input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

/* :focus ring handled globally by the :focus-visible block near the top. */

.prevalence-readout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0 1.25rem;
}

.prevalence-stat {
  background-color: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.prevalence-stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.prevalence-stat-value {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.prevalence-explorer canvas {
  width: 100%;
  max-width: 600px;
  height: 320px;
  border: 1px solid var(--log-150);
  border-radius: 4px;
  background: var(--bg);
  display: block;
  margin: 0 auto;
}

/* ── Threshold explorer demo ────────────────────────────────────────────── */

.threshold-demo {
  background-color: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-top: 1.5rem;
}

.threshold-demo > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-strong);
  font-size: 1.05rem;
  line-height: 1.4;
  list-style: none;
}

.threshold-demo > summary::-webkit-details-marker {
  display: none;
}

.threshold-demo .help-text {
  margin: 0.75rem 0 1rem;
}

.threshold-demo canvas {
  width: 100%;
  max-width: 600px;
  height: 200px;
  border: 1px solid var(--log-150);
  border-radius: 4px;
  background: var(--bg);
  display: block;
  margin: 0 auto;
}

.threshold-demo-controls {
  margin: 1rem 0 1.25rem;
}

.threshold-demo-controls label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 600;
  margin-bottom: 0.6rem;
  color: var(--text);
}

.threshold-demo-controls output {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  font-weight: 700;
  font-size: 1.05rem;
}

.threshold-demo-controls input[type="range"] {
  width: 100%;
  height: 1.5rem;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.threshold-demo-controls input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--log-150);
  border-radius: 3px;
}

.threshold-demo-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--primary);
  border-radius: 50%;
  margin-top: -6px;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.threshold-demo-controls input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--crew-starbuck);
  transform: scale(1.1);
}

.threshold-demo-controls input[type="range"]::-moz-range-track {
  height: 6px;
  background: var(--log-150);
  border-radius: 3px;
}

.threshold-demo-controls input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.threshold-demo-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0 1.25rem;
}

.threshold-demo-stat {
  background-color: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.threshold-demo-stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.threshold-demo-stat-value {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.threshold-demo-stat-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

.threshold-demo-matrix {
  display: grid;
  grid-template-columns: 80px 1fr 1fr;
  grid-template-rows: 32px 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
  font-size: 0.85rem;
  margin: 1rem 0;
}

.threshold-demo-cell {
  background: var(--surface);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.25rem;
}

.threshold-demo-cell.head {
  background: var(--surface-soft);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
  font-size: 0.68rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.threshold-demo-cell-n {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: -0.01em;
}

.threshold-demo-cell.tp .threshold-demo-cell-n { color: var(--success); }
.threshold-demo-cell.tn .threshold-demo-cell-n { color: var(--success); }
.threshold-demo-cell.fp .threshold-demo-cell-n { color: var(--error); }
.threshold-demo-cell.fn .threshold-demo-cell-n { color: var(--error); }

.threshold-demo-cell-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

.threshold-demo-note {
  font-size: 0.85rem;
  color: var(--text);
  margin-top: 0.75rem;
  min-height: 2.2rem;
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
  .threshold-demo-controls input[type="range"]::-webkit-slider-thumb {
    transition: none;
  }
}

/* References Section */
.references {
  margin-top: 0;
}

.references details {
  border: 2px solid var(--log-150);
  border-radius: 4px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  background-color: var(--bg);
}

.references summary {
  font-weight: 600;
  cursor: pointer;
}

.reference-list {
  margin: 1rem 0 0;
  padding-left: 1.5rem;
  color: var(--text-muted);
}

.reference-list li {
  margin-bottom: 0.75rem;
  line-height: 1.6;
}

.reference-list strong {
  color: var(--text-strong);
}

/* Tooltip */
.tooltip {
  position: relative;
  display: inline-block;
  cursor: help;
  border-bottom: 1px dotted var(--log-400);
}

.tooltip .tooltip-text {
  visibility: hidden;
  width: 280px;
  background-color: var(--log-950);
  color: var(--log-50);
  text-align: left;
  border-radius: 6px;
  padding: 0.75rem;
  position: absolute;
  z-index: 1000;
  bottom: 125%;
  left: 50%;
  margin-left: -140px;
  opacity: 0;
  transition: opacity 0.3s;
  font-size: 0.85rem;
  line-height: 1.4;
  border: 2px solid var(--log-950);
}

.tooltip .tooltip-text::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: var(--log-950) transparent transparent transparent;
}

.tooltip:hover .tooltip-text,
.tooltip:focus .tooltip-text {
  visibility: visible;
  opacity: 1;
}

/* Dark Mode — Glauca Profundum */
[data-theme="dark"] {
  /* Crew accents (dark variants) — Glauca hues, brightened for the Profundum ground */
  --crew-ahab:     #E08C8C;  /* bacca red */
  --crew-starbuck: #8FD0FF;  /* dies bright — info / focus ring */
  --crew-queequeg: #3D97FF;  /* accent — primary action */
  --crew-pip:      #DCB36A;  /* copper — warning / threshold bands */
  --crew-ishmael:  #8C8C8C;  /* cinis — Glauca's exact dark muted (5.4:1) */
  --crew-stubb:    #E0A878;  /* copper — LR+ trace */
  --crew-tashtego: #7FC95F;  /* folium bright — LR− / success */
  --crew-daggoo:   #D3A26E;  /* copper mid — sequential second-stage */

  /* Semantic tokens — legacy slot names, Glauca Profundum values. */
  --bg:             var(--log-950);
  --surface:        var(--log-900);
  --surface-soft:   rgba(16, 22, 28, 0.9);
  --border:         var(--log-700);
  --text:           var(--log-100);
  --text-strong:    var(--log-100);
  --text-muted:     var(--crew-ishmael);
  --primary:        var(--crew-queequeg);
  --primary-strong: var(--log-100);
  --secondary:      var(--crew-starbuck);
  --success:        var(--crew-tashtego);
  --warning:        var(--crew-pip);
  --error:          var(--crew-ahab);
  --accent-warm:    var(--crew-stubb);
  --axis:           var(--log-300);
}

a {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}

a:hover {
  color: var(--primary-strong);
  border-bottom-color: var(--primary-strong);
}

@media (max-width: 720px) {
  .workspace,
  .resource-grid {
    grid-template-columns: 1fr;
  }

  .header-controls {
    position: static;
    justify-content: center;
    margin-bottom: 1rem;
  }

  /* Keep the matrix as a 3-column grid on mobile (narrow label column +
     two flex input columns). Earlier rules collapsed to 2 columns and
     hid the row labels — users lost the Test +/Test − context entirely. */
  .grid-container {
    grid-template-columns: minmax(48px, max-content) 1fr 1fr;
    gap: 0.4rem;
  }

  .grid-header,
  .grid-label {
    font-size: var(--text-xs);
    padding: 0.4rem;
    line-height: 1.2;
  }

  .form-actions {
    grid-template-columns: 1fr;
  }

  .panel-heading-inline {
    flex-direction: column;
  }

  .intro-highlights {
    grid-template-columns: 1fr;
  }

  .probability-chart {
    padding: 1.25rem;
  }

  .chart-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .chart-value {
    justify-self: flex-start;
  }

  .fagan-nomogram canvas {
    width: 100%;
    height: auto;
  }

  .tooltip .tooltip-text {
    width: 220px;
    margin-left: -110px;
    font-size: 0.8rem;
  }

  .panel {
    padding: 1rem;
  }

  .reference-list {
    font-size: 0.9rem;
  }
}

@media print {
  /* Force a clean light theme regardless of the user's current setting */
  :root,
  [data-theme="dark"] {
    --bg:           #FFFFFF;
    --surface:      #FFFFFF;
    --surface-soft: #FFFFFF;
    --text:         #000000;
    --text-strong:  #000000;
    --text-muted:   #444444;
    --border:       #999999;
  }

  @page {
    size: A4 portrait;
    margin: 14mm;
  }

  body {
    background-image: none !important;
    color: #000;
    font-size: 10pt;
    line-height: 1.4;
  }

  .container {
    width: 100%;
    padding: 0;
  }

  /* Hide everything interactive or not essential for the handout */
  .theme-toggle,
  .header-controls,
  .form-actions,
  .feedback,
  .advanced-settings,
  .secondary,
  button,
  .results-actions,
  .bias-warnings,
  #prevalenceExplorer,
  #sequentialTest,
  #thresholdPanel,
  #rocPanel,
  #historyPanel,
  .kappa-panel,
  .interpretation,
  .stard-panel,
  .dataset-reference,
  #datasetSelect,
  label[for="datasetSelect"],
  #dataset-help,
  footer,
  script {
    display: none !important;
  }

  /* Show the form values but as a printable summary, not the inputs */
  .workspace {
    display: block;
  }

  /* Style inputs as static printable text */
  .grid-item input,
  .preTestProb,
  select {
    border: 1px solid #999 !important;
    background: #FFF !important;
    color: #000 !important;
    box-shadow: none !important;
    -webkit-appearance: none;
    appearance: none;
    padding: 0.3rem 0.5rem;
  }

  .grid-header {
    background: #000 !important;
    color: #FFF !important;
  }

  .grid-label {
    background: #444 !important;
    color: #FFF !important;
  }

  /* Force collapsibles open so their content prints */
  details {
    display: block !important;
  }

  details > *:not(summary) {
    display: revert !important;
  }

  details summary {
    list-style: none;
    cursor: default;
    font-weight: 700;
    margin-bottom: 0.4rem;
  }

  .panel {
    background: transparent;
    border: none;
    padding: 0;
    backdrop-filter: none;
    page-break-inside: avoid;
  }

  .panel-results {
    margin-top: 1rem;
  }

  .intro {
    border-bottom: 1px solid #000;
    background: transparent;
  }

  .intro .container {
    padding: 0 0 0.5rem;
  }

  .intro-highlights {
    display: none;
  }

  h1 {
    font-size: 18pt;
    margin: 0 0 0.25rem;
  }

  h2 {
    font-size: 13pt;
    margin: 1rem 0 0.5rem;
  }

  .lead,
  .tag,
  .panel-kicker {
    display: none;
  }

  .results-headline,
  .results-secondary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.4rem;
    margin-bottom: 0.5rem;
  }

  .results-secondary {
    grid-template-columns: repeat(3, 1fr);
  }

  .result-card {
    background: #FFFFFF;
    border: 1px solid #BBB;
    padding: 0.4rem 0.6rem;
    page-break-inside: avoid;
    box-shadow: none;
  }

  .result-card h3 {
    font-size: 8pt;
    color: #000;
  }

  .result-card--lg .result-value {
    font-size: 13pt;
  }

  .result-value {
    font-size: 11pt;
  }

  .result-ci,
  .result-note {
    color: #333;
    font-size: 8.5pt;
  }

  .bayesian-update {
    page-break-inside: avoid;
    background: #FFF;
    border: 1px solid #BBB;
    padding: 0.4rem 0.6rem;
    margin: 0.4rem 0;
  }

  .bayesian-axis-trail { background: #444 !important; }
  .bayesian-axis-pre { background: #FFF; border-color: #444; }
  .bayesian-axis-post { background: #000 !important; border-color: #FFF; }
  .bayesian-axis-pre-label, .bayesian-axis-post-label { color: #000; }

  .result-bar { background: #EEE; border-color: #CCC; }
  .result-bar-fill { background: #444 !important; }

  .result-band { border-color: #CCC; }
  .result-band-zone { background: #EEE !important; }
  .result-band-marker { background: #000 !important; border-color: #FFF; }

  .fagan-nomogram {
    page-break-inside: avoid;
    background: #FFF;
    border: 1px solid #BBB;
  }

  .fagan-summary {
    background: #FFF;
    border: 1px solid #BBB;
  }

  .references {
    page-break-before: auto;
  }

  .references details {
    background: transparent;
    border: 1px solid #DDD;
  }

  .references details[open] summary {
    margin-bottom: 0.5rem;
  }

  a {
    color: #000;
    border-bottom: none;
    text-decoration: none;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 8pt;
    color: #555;
    word-break: break-all;
  }
}

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