/* IDBD Explorer. One deliberate dark theme: a graphite instrument panel. */

:root {
  color-scheme: dark;

  /* The story page's palette and type, so Advanced reads as the same site. */
  --bg: #08090a;
  --bg-deep: #050606;
  --surface: #101113;
  --surface-2: #16181b;
  --hairline: rgb(255 255 255 / 0.08);
  --hairline-strong: rgb(255 255 255 / 0.14);

  --ink: #f4f5f6;
  --ink-2: #a1a7b0;
  --ink-3: #7c828c;

  /* Data marks, the same hues as the story: amber IDBD, blue LMS. */
  --idbd: #ffb547;
  --lms: #5b8def;
  --autostep: #38b29a;
  --truth: #9aa3b0;
  --warn: #f2a03d;

  --focus: #f4f5f6;

  --step-1: 0.25rem;
  --step-2: 0.5rem;
  --step-3: 0.75rem;
  --step-4: 1rem;
  --step-5: 1.5rem;
  --step-6: 2rem;
  --step-7: 3rem;
  --step-8: 4.5rem;

  --sans: Geist, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  --radius-card: 16px;
  --radius: 10px;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  overflow-x: hidden;
}

h1,
h2,
h3 {
  font-weight: 600;
  margin: 0;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.375rem, 6vw, 3.5rem);
  line-height: 1.04;
  letter-spacing: -0.035em;
}

h2 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  line-height: 1.08;
  letter-spacing: -0.03em;
}

h3 {
  font-size: 1.0625rem;
  line-height: 1.3;
}

p {
  margin: 0;
}

a {
  color: var(--ink-2);
  text-decoration: none;
  transition: color 150ms var(--ease);
}

a:hover {
  color: var(--ink);
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.9em;
}

.eyebrow {
  font-family: var(--mono);
  font-size: 0.8125rem;
  color: var(--ink-2);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: var(--step-4);
  top: -3rem;
  z-index: 10;
  padding: var(--step-2) var(--step-3);
  background: var(--surface-2);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  transition: top 120ms ease;
}

.skip-link:focus {
  top: var(--step-4);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ---------- site header, shared with the story page ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 15;
  background: rgb(8 9 10 / 0.8);
  backdrop-filter: saturate(1.8) blur(20px);
  -webkit-backdrop-filter: saturate(1.8) blur(20px);
  border-bottom: 1px solid var(--hairline);
}

.header-row {
  max-width: 1280px;
  margin: 0 auto;
  padding: 4px var(--step-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px 16px;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  color: var(--ink);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0 24px;
  font-size: 14px;
}

.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.nav a[aria-current="page"] {
  color: var(--ink);
}

@media (max-width: 640px) {
  .nav {
    gap: 0 16px;
  }

  .nav .wide-only {
    display: none;
  }
}

/* A faint glow behind the masthead, as on the story page. */
body::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 900px;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(40rem 26rem at 78% 10%, rgb(255 181 71 / 0.09), transparent 70%),
    radial-gradient(34rem 24rem at 8% 0%, rgb(91 141 239 / 0.07), transparent 70%);
}

/* ---------- glossary ---------- */

.glossary {
  display: grid;
  gap: var(--step-3);
  padding: var(--step-4);
  background: rgb(255 255 255 / 0.02);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
}

.glossary-head {
  display: grid;
  gap: var(--step-1);
}

.glossary-list {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: var(--step-3) var(--step-5);
  font-size: 0.875rem;
}

.glossary-list div {
  display: grid;
  gap: 2px;
}

.glossary-list dt {
  color: var(--idbd);
  font-weight: 500;
}

.glossary-list dd {
  margin: 0;
  color: var(--ink-2);
}

/* ---------- masthead ---------- */

.masthead,
main,
.colophon {
  max-width: 1280px;
  margin: 0 auto;
  padding-inline: var(--step-4);
}

.masthead {
  padding-top: var(--step-7);
  padding-bottom: var(--step-6);
  border-bottom: 1px solid var(--hairline);
  display: grid;
  gap: var(--step-4);
}

.masthead h1 {
  max-width: 18ch;
}

.lede {
  max-width: 62ch;
  font-size: clamp(1rem, 1.6vw, 1.1875rem);
  line-height: 1.5;
  color: var(--ink-2);
}

.masthead-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--step-4);
  font-size: 0.875rem;
}

.build-info,
.run-header,
.pairs {
  margin: 0;
  display: grid;
  gap: var(--step-2) var(--step-4);
  font-size: 0.8125rem;
}

.build-info {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  border-top: 1px solid var(--hairline);
  padding-top: var(--step-4);
}

.build-info div,
.run-header div,
.pairs div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.build-info dt,
.run-header dt,
.pairs dt {
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.build-info dd,
.run-header dd,
.pairs dd {
  margin: 0;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* ---------- sections ---------- */

.section {
  padding-block: var(--step-7);
  border-bottom: 1px solid var(--hairline);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--step-3);
  margin-bottom: var(--step-4);
}

.section-lede {
  max-width: 70ch;
  color: var(--ink-2);
  margin-bottom: var(--step-5);
}

.sample-badge {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  border: 1px solid var(--hairline-strong);
  border-radius: 100px;
  padding: 2px var(--step-3);
  white-space: nowrap;
}

.note {
  font-size: 0.8125rem;
  color: var(--ink-3);
  max-width: 68ch;
}

.notice {
  padding: var(--step-3) var(--step-4);
  border: 1px solid var(--hairline-strong);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.875rem;
}

.notice.failure {
  margin-bottom: var(--step-5);
}

.notice.replay {
  margin-bottom: var(--step-5);
  border-left-color: var(--ink-3);
}

.notice.replay.error {
  border-left-color: var(--warn);
}

.notice strong {
  font-weight: 600;
}

/* ---------- panels ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  padding: var(--step-4);
  display: grid;
  gap: var(--step-3);
  align-content: start;
  min-width: 0;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--step-2);
}

.panel-title {
  font-family: var(--sans);
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0;
}

.guided-grid {
  display: grid;
  align-items: start;
  gap: var(--step-4);
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
}

.panel-grid {
  display: grid;
  gap: var(--step-4);
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

/* Two columns, with the weight list running alongside the two time charts. */
@media (min-width: 901px) {
  .panel-grid {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    grid-template-areas:
      "error error"
      "weights alpha"
      "inspector events"
      "table table";
  }

  #weights-panel {
    grid-area: weights;
  }

  #error-panel {
    grid-area: error;
  }

  #alpha-panel {
    grid-area: alpha;
  }

  #events-panel {
    grid-area: events;
  }

  #inspector-panel {
    grid-area: inspector;
  }

  #table-panel {
    grid-area: table;
  }
}

@media (max-width: 900px) {
  .guided-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- the derivation ladder (D14) ---------- */

.ladder-panel {
  position: relative;
}

.ladder {
  list-style: none;
  counter-reset: rung;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0;
}

.rung {
  counter-increment: rung;
  display: grid;
  grid-template-columns: 1.75rem minmax(0, 1fr);
  gap: var(--step-3);
  padding-block: var(--step-3);
  border-top: 1px solid var(--hairline);
}

.rung:first-child {
  border-top: 0;
}

.rung::before {
  content: counter(rung);
  font-family: var(--mono);
  font-size: 0.6875rem;
  color: var(--ink-3);
  border: 1px solid var(--hairline-strong);
  border-radius: 100px;
  width: 1.5rem;
  height: 1.5rem;
  display: grid;
  place-items: center;
  margin-top: 2px;
}

.rung-body {
  display: grid;
  gap: var(--step-1);
  min-width: 0;
}

.rung-label {
  font-size: 0.8125rem;
  color: var(--ink-2);
}

.rung-value {
  font-family: var(--mono);
  font-size: 1.0625rem;
  font-variant-numeric: tabular-nums;
}

.rung-note {
  font-size: 0.8125rem;
  color: var(--ink-3);
}

.rung.gate {
  background: linear-gradient(90deg, rgb(255 181 71 / 0.09), transparent 70%);
  border-top-color: var(--hairline-strong);
}

.rung.gate .rung-value {
  color: var(--idbd);
}

.factors {
  display: flex;
  flex-wrap: wrap;
  gap: var(--step-2);
  margin-top: var(--step-1);
}

.factor {
  font-family: var(--mono);
  font-size: 0.75rem;
  border: 1px solid var(--hairline-strong);
  border-radius: 6px;
  padding: 1px var(--step-2);
  color: var(--ink-2);
}

.factor .sign {
  color: var(--ink);
}

/* ---------- controls ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--step-4);
  padding: var(--step-4);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  margin-bottom: var(--step-4);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--step-2);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
  background: rgb(255 255 255 / 0.03);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  padding: 0 var(--step-4);
  cursor: pointer;
  transition: background 150ms var(--ease), border-color 150ms var(--ease);
}

.button:hover:not(:disabled) {
  background: rgb(255 255 255 / 0.07);
}

.button.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
  font-weight: 600;
}

.button.primary:hover:not(:disabled) {
  background: #ffffff;
}

.button:disabled {
  color: var(--ink-3);
  cursor: not-allowed;
  opacity: 0.6;
}

.button[aria-checked="true"],
.button[aria-pressed="true"] {
  background: rgb(255 181 71 / 0.12);
  border-color: var(--idbd);
}

.field {
  display: grid;
  gap: var(--step-1);
  min-width: 0;
}

.field label {
  font-family: var(--mono);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.field select,
.field input {
  font-family: var(--mono);
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--bg-deep);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  padding: var(--step-2);
  min-width: 0;
  width: 100%;
}

.playback-state {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-left: auto;
}

.settings-grid {
  display: grid;
  gap: var(--step-4);
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  padding: var(--step-4);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  margin-bottom: var(--step-4);
  align-items: start;
}

.settings-grid .wide {
  grid-column: span 2;
}

.settings-grid .apply {
  grid-column: 1 / -1;
  justify-items: start;
}

@media (max-width: 560px) {
  .settings-grid .wide {
    grid-column: auto;
  }

  .playback-state {
    margin-left: 0;
  }
}

.run-header {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  padding: var(--step-4);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  margin-bottom: var(--step-5);
}

.run-details {
  margin-bottom: var(--step-5);
}

.run-details > summary {
  display: none;
}

.run-details .run-header {
  margin-bottom: 0;
}

.idle-note {
  display: none;
}

/* Phones: fold the run definition and, before the first sample, show one line per panel
   in place of empty charts, zero bars and a table of zeros. */
@media (max-width: 700px) {
  .run-details > summary {
    display: list-item;
    cursor: pointer;
    min-height: 44px;
    padding: var(--step-3) var(--step-4);
    background: var(--surface);
    border: 1px solid var(--hairline);
    border-radius: var(--radius-card);
    font-size: 0.875rem;
    color: var(--ink-2);
  }

  .run-details[open] > summary {
    margin-bottom: var(--step-3);
  }

  #experiment[data-idle="true"] .idle-note {
    display: block;
  }

  #experiment[data-idle="true"] .panel :is(.legend, .chart, .weight-list, .pairs, .chart-readout, .event-list, .scroll-hint, .table-scroll, #event-summary, #inspector-meaning, #error-panel > .note:last-child) {
    display: none;
  }
}

.run-header .wide-pair {
  grid-column: span 2;
}

@media (max-width: 560px) {
  .run-header .wide-pair {
    grid-column: auto;
  }
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--step-2);
}

/* ---------- legends ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--step-2) var(--step-4);
  font-size: 0.8125rem;
  color: var(--ink-2);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: var(--step-2);
}

.swatch {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}

/* ---------- weight list ---------- */

.weight-list {
  display: grid;
  gap: 2px;
}

.weight-row {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr);
  align-items: center;
  gap: var(--step-3);
  padding: 2px var(--step-2);
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.weight-row:hover {
  background: var(--surface-2);
}

.weight-row[aria-selected="true"] {
  border-color: var(--hairline-strong);
  background: var(--surface-2);
}

.weight-row .name {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink-2);
}

.weight-row[aria-selected="true"] .name {
  color: var(--ink);
}

.weight-row svg {
  display: block;
  width: 100%;
  height: 20px;
}

/* ---------- charts ---------- */

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: hidden;
}

.chart.timeline svg {
  height: 44px;
}

.chart[tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.chart-readout {
  margin: 0;
  font-size: 0.75rem;
  color: var(--ink-2);
}

/* Sign flips come every 20 samples on the paper task, so each tick is faint and a dense
   run reads as a band. The event list carries the individual values. */
.flip-mark {
  stroke: var(--truth);
  stroke-width: 1;
  opacity: 0.45;
}

.chart.sparkline svg {
  height: 90px;
}

.axis-line {
  stroke: var(--hairline-strong);
  stroke-width: 1;
}

.grid-line {
  stroke: var(--hairline);
  stroke-width: 1;
}

.tick-label {
  fill: var(--ink-3);
  font-family: var(--mono);
  font-size: 9px;
}

.axis-title {
  fill: var(--ink-3);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.series-idbd {
  stroke: var(--idbd);
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.series-lms {
  stroke: var(--lms);
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.series-autostep {
  stroke: var(--autostep);
  fill: none;
  stroke-width: 2;
  stroke-dasharray: 7 4;
  stroke-linejoin: round;
}

.alpha-line {
  fill: none;
  stroke: var(--ink-3);
  stroke-width: 1;
}

/* 0.75 keeps the dashed lines at 3.3:1 against the panel, above the WCAG 3:1 minimum for marks. */
.alpha-line.irrelevant {
  stroke-dasharray: 9 5;
  opacity: 0.75;
}

.alpha-line.selected {
  stroke: var(--idbd);
  stroke-width: 2;
  opacity: 1;
}

.event-mark {
  stroke: var(--hairline-strong);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.event-glyph {
  fill: none;
  stroke: var(--truth);
  stroke-width: 1.5;
}

.crosshair {
  stroke: var(--ink-3);
  stroke-width: 1;
}

.empty-note {
  fill: var(--ink-3);
  font-family: var(--mono);
  font-size: 11px;
}

.hit-area {
  fill: transparent;
}

/* ---------- events and tables ---------- */

.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--step-1);
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--ink-2);
  max-height: 10.5rem;
  overflow-y: auto;
  padding-bottom: var(--step-3);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 1.5rem), transparent);
}

.event-list .pending {
  color: var(--warn);
}

.event-list .more {
  color: var(--ink-3);
}

.notice.error {
  margin: 0;
  border-left-color: var(--warn);
}

.scroll-hint {
  display: none;
  margin: 0;
}

@media (max-width: 700px) {
  .scroll-hint {
    display: block;
  }
}

@media (min-width: 901px) {
  .pairs.metrics {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--hairline);
  border-radius: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  padding: var(--step-2) var(--step-3);
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--hairline);
}

.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
}

.data-table thead th {
  font-weight: 500;
  font-size: 0.6875rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.data-table tbody tr:last-child th,
.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr[aria-selected="true"] {
  background: var(--surface-2);
}

/* ---------- tooltip ---------- */

.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  max-width: 17rem;
  padding: var(--step-2) var(--step-3);
  background: var(--bg-deep);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--ink);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.45);
}

/* ---------- colophon ---------- */

.colophon {
  padding-block: var(--step-6) var(--step-8);
  color: var(--ink-3);
  font-size: 0.8125rem;
}

.colophon p {
  max-width: 70ch;
}

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

/* GitHub and crates.io links as two-part pills, like the README's badges. */
.project-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.project-badge {
  display: inline-flex;
  align-items: stretch;
  min-height: 32px;
  border: 1px solid var(--hairline-strong);
  border-radius: 999px;
  overflow: hidden;
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
  transition: border-color 150ms ease;
}

.project-badge:hover {
  border-color: rgb(255 255 255 / 0.32);
}

.project-badge-label,
.project-badge-value {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
}

.project-badge-label {
  background: var(--surface-2);
  color: var(--ink-2, #a1a7b0);
}

.project-badge-value {
  background: var(--surface, #101113);
  color: var(--ink, #f4f5f6);
  font-family: var(--mono, ui-monospace, monospace);
  border-left: 1px solid var(--hairline-strong);
}

.project-badge:hover .project-badge-label {
  color: var(--ink, #f4f5f6);
}

.project-badge svg .badge-solid {
  fill: currentColor;
}
