/* Lab: specimen list (lab index and homepage), experiment benches and their controls.
   Builds on the tokens and components in styles.css. Every selector is scoped to lab
   components because the homepage and the Crowns page also load this sheet. */

/* ---------- Small shared pieces ---------- */
.glyph {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  flex: none;
  overflow: visible;
}
.glyph-a {
  fill: var(--accent);
}
.glyph-seed {
  fill: var(--ink);
}
.glyph-b {
  fill: none;
  stroke: var(--rust);
  stroke-width: 2.4;
  stroke-linecap: round;
}
.glyph-edge {
  width: 1.1rem;
  stroke-width: 2.4;
  stroke-linecap: round;
}
.glyph-edge.pos {
  stroke: var(--accent);
}
.glyph-edge.neg {
  stroke: var(--rust);
}
.glyph-boundary {
  width: 1.1rem;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linecap: round;
}
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0 0.85rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  color: var(--ink);
  font: 500 var(--step--2) / 1 var(--mono);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition:
    border-color 0.2s,
    background-color 0.2s,
    color 0.2s,
    transform 0.3s var(--spring);
}
.chip:hover {
  border-color: var(--ink);
}
.chip:active {
  transform: scale(0.96);
}
.chip-live {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  color: var(--accent-ink);
}
.chip-live:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.is-live {
  color: var(--accent-ink);
}

/* ---------- Specimen list ---------- */
.specimens {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--ink);
}
.specimen {
  container-type: inline-size;
  border-bottom: 1px solid var(--line);
}
.specimen-card {
  display: grid;
  grid-template-areas: "meta" "title" "visual" "text";
  gap: 0.9rem;
  padding-block: clamp(1.5rem, 4vw, 2.75rem);
}
.specimen-meta {
  grid-area: meta;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1rem;
  color: var(--muted);
}
.specimen-meta .shipped {
  color: var(--accent-ink);
}
.specimen-title {
  grid-area: title;
  overflow-wrap: break-word;
  font-size: clamp(1.9rem, 6.2cqi, 3.6rem);
  font-weight: 650;
  line-height: 0.98;
  letter-spacing: -0.05em;
  max-width: 14ch;
}
.specimen-title a {
  transition: color 0.2s;
}
.specimen-title a:hover {
  color: var(--accent-ink);
}
.specimen-title .arrow {
  font-size: 0.6em;
  vertical-align: 0.35em;
  color: var(--accent);
}
.specimen-text {
  grid-area: text;
  display: grid;
  gap: 1rem;
  align-content: start;
}
.specimen-text > p:first-child {
  font-size: var(--step-1);
  color: var(--ink-2);
  max-width: 40ch;
}
.specimen-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.4rem;
}
.specimen-links .link {
  min-height: 44px;
  align-items: center;
}
.specimen-visual {
  grid-area: visual;
  min-width: 0;
}
.specimen-frame {
  position: relative;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  transition: border-color 0.25s;
}
.specimen-frame:hover {
  border-color: var(--line-strong);
}
.specimen-frame img,
.specimen-frame > canvas,
.specimen-frame > .form-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.specimen-frame img {
  object-fit: cover;
}
.frame-automaton {
  aspect-ratio: 127 / 64;
}
.specimen-frame .form-canvas {
  cursor: grab;
  touch-action: pan-y;
}
.specimen-frame .form-canvas:active {
  cursor: grabbing;
}
.form-canvas > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.specimen-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-top: 0.7rem;
}
.specimen-readout {
  min-width: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.specimen-readout.is-live {
  color: var(--accent-ink);
}
.specimen-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-left: auto;
}

@container (min-width: 720px) {
  .specimen-card {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "meta visual" "title visual" "text visual";
    column-gap: clamp(1.5rem, 4cqi, 3.5rem);
    row-gap: 1.1rem;
  }
  .specimen-text {
    margin-top: 0.4rem;
  }
  .specimen-card.is-flagship {
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  }
  .specimen-title {
    font-size: clamp(2.2rem, 5.2cqi, 4rem);
  }
}

/* Crowns: a real generated board, rendered as markup so it follows the theme. */
.crowns-frame {
  justify-self: end;
  width: 100%;
  max-width: 27rem;
}
.crowns-board {
  --cr-t0: color-mix(in oklab, var(--accent) 20%, var(--white));
  --cr-t1: color-mix(in oklab, var(--rust) 34%, var(--white));
  --cr-t2: color-mix(in oklab, var(--ink) 36%, var(--white));
  --cr-t3: color-mix(in oklab, var(--accent) 42%, var(--white));
  --cr-t4: color-mix(in oklab, var(--rust) 66%, var(--white));
  --cr-t5: color-mix(in oklab, var(--accent) 64%, var(--white));
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  aspect-ratio: 1;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--ink) 16%, var(--white));
  gap: 1px;
}
.crowns-board i {
  --tint: var(--white);
  display: grid;
  place-items: center;
  background: var(--tint);
  box-shadow: none;
}
.crowns-board .t {
  box-shadow: inset 0 2px 0 var(--ink);
}
.crowns-board .l {
  box-shadow: inset 2px 0 0 var(--ink);
}
.crowns-board .t.l {
  box-shadow:
    inset 0 2px 0 var(--ink),
    inset 2px 0 0 var(--ink);
}
/* Region tones: the six from crowns.css (tests keep the copies identical), one per region,
   neighbours far apart, the large regions calm and the small ones strong. */
.crowns-board .r0,
.crowns-board .r5 {
  --tint: var(--cr-t1);
}
.crowns-board .r1 {
  --tint: var(--cr-t0);
}
.crowns-board .r2 {
  --tint: var(--cr-t2);
}
.crowns-board .r3 {
  --tint: var(--cr-t5);
}
.crowns-board .r4 {
  --tint: var(--cr-t4);
}
.crowns-board .r6 {
  --tint: var(--cr-t3);
}
.crowns-board svg {
  width: 52%;
  height: 52%;
  fill: var(--ink);
}
@media (prefers-reduced-motion: no-preference) {
  .specimen-card:hover .crowns-board svg {
    animation: crown-settle 0.5s steps(4) both;
  }
  .specimen-card:hover .crowns-board i:nth-child(odd) svg {
    animation-delay: 0.06s;
  }
}
@keyframes crown-settle {
  from {
    transform: translateY(-22%) scale(0.8);
    opacity: 0.3;
  }
}

/* Homepage variant: the same rows, tighter. */
.specimens-compact .specimen-card {
  padding-block: clamp(1.25rem, 3vw, 2rem);
}
.specimens-compact .specimen-title {
  font-size: clamp(1.7rem, 4.6cqi, 2.6rem);
}
@container (min-width: 720px) {
  .specimens-compact .specimen-card {
    grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  }
  .specimens-compact .specimen-frame:not(.frame-automaton) {
    aspect-ratio: 16 / 9;
  }
  .specimens-compact .crowns-frame {
    max-width: 17rem;
  }
}

/* ---------- Experiment pages ---------- */
.lab-heading h1,
.detail-heading h1 {
  overflow-wrap: break-word;
}
/* Experiment headings stay compact so the bench starts in the first screen:
   title on the left, the one-paragraph brief beside it, aligned to the bench columns. */
.page-heading.detail-heading {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  column-gap: clamp(1.5rem, 3.6vw, 3.5rem);
  align-items: end;
  max-width: none;
  padding-block: clamp(0.5rem, 1.5vw, 1.25rem) clamp(1.5rem, 3vw, 2.5rem);
}
.detail-meta {
  grid-column: 1 / -1;
}
.detail-heading h1 {
  margin-top: clamp(0.5rem, 1.6vw, 1.25rem);
  font-size: var(--step-4);
  line-height: 0.98;
}
.page-heading.detail-heading > p {
  margin-top: 0;
  font-size: var(--step-0);
  max-width: 46ch;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  padding-right: 0.35rem;
  color: var(--muted);
  font: 500 var(--step--2) / 1 var(--mono);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  transition: color 0.2s;
}
.back-link:hover {
  color: var(--accent-ink);
}
.back-link span {
  display: inline-block;
  transition: transform 0.3s var(--spring);
}
.back-link:hover span {
  transform: translateX(-3px);
}

.lab-fallback {
  display: grid;
  gap: 0.8rem;
  max-width: 46rem;
}
.lab-fallback img {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.lab-fallback figcaption {
  color: var(--muted);
  font-size: var(--step--1);
}

.bench {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "plot primary" "plot secondary";
  column-gap: clamp(1.5rem, 3.6vw, 3.5rem);
  align-items: start;
}
.bench-plot {
  grid-area: plot;
  position: sticky;
  top: calc(var(--header-h) + 1rem);
  min-width: 0;
}
.bench-primary {
  grid-area: primary;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.1rem;
  min-width: 0;
}
.bench-secondary {
  grid-area: secondary;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
  align-content: start;
  min-width: 0;
  margin-top: 1.75rem;
}
.plot-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 1.6rem;
  margin-bottom: 0.6rem;
}
.plot-badge {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
}
.plot-badge.is-live {
  color: var(--accent-ink);
}
.plot-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
}
.plot-frame canvas {
  display: block;
  width: 100%;
  height: auto;
}
#decision-field {
  aspect-ratio: 1;
  cursor: crosshair;
  touch-action: manipulation;
}
#automaton {
  aspect-ratio: 127 / 64;
}
.axis-label {
  position: absolute;
  color: var(--muted);
  font: 500 var(--step--2) / 1 var(--mono);
  pointer-events: none;
}
.axis-y {
  top: 10px;
  left: calc(50% + 8px);
}
.axis-x {
  right: 10px;
  top: calc(50% + 8px);
}
.plot-coords {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 6px 8px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--white) 90%, transparent);
  color: var(--ink);
  pointer-events: none;
}
.plot-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.4rem 1.25rem;
  margin-top: 0.7rem;
  color: var(--muted);
}
.plot-legend > span {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.5rem;
}
.plot-legend > span > span {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-right: 0.6rem;
}
.hint-touch,
.plot-legend .hint-touch {
  display: none;
}
@media (hover: none) {
  .hint-touch,
  .plot-legend .hint-touch {
    display: inline;
  }
  .hint-mouse,
  .plot-legend .hint-mouse {
    display: none;
  }
}

.control-group {
  display: grid;
  gap: 0.55rem;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.control-group > legend,
.control-label {
  padding: 0;
  margin-bottom: 0.55rem;
  color: var(--muted);
  font: 500 var(--step--2) / 1.4 var(--mono);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--paper-2);
}
.segmented button {
  min-width: 0;
  overflow-wrap: anywhere;
  min-height: 44px;
  padding: 0.4rem 0.5rem;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: var(--step--1);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  transition:
    background-color 0.2s,
    color 0.2s,
    transform 0.3s var(--spring);
}
.segmented button:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--white) 70%, transparent);
}
.segmented button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}
.segmented button:active {
  transform: scale(0.97);
}
.train-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.train-row .btn {
  min-height: 48px;
}
.train-button {
  flex: 1 1 9rem;
  justify-content: space-between;
}
.train-icon {
  width: 11px;
  height: 12px;
  background: currentColor;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}
.train-icon[data-icon="pause"] {
  clip-path: none;
  background: linear-gradient(90deg, currentColor 0 36%, transparent 36% 64%, currentColor 64%);
}
.is-training .train-button {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.bench-progress {
  position: relative;
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--paper-2);
}
.bench-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
}
/* Tick marks: the bar advances in fortieths of the run. */
.bench-progress::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg,
    transparent 0 calc(2.5% - 2px),
    var(--paper) calc(2.5% - 2px) 2.5%
  );
}
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 5.5rem), 1fr));
  gap: 0 var(--gutter);
  margin: 0;
  border-top: 1px solid var(--ink);
}
.metrics > div {
  display: grid;
  gap: 0.35rem;
  align-content: start;
  padding-top: 0.75rem;
  min-width: 0;
}
.metrics dt {
  color: var(--muted);
  overflow-wrap: anywhere;
}
.metrics dd {
  font-size: clamp(1.5rem, 2.6vw, 2.25rem);
  font-weight: 650;
  line-height: 1;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.is-training .metrics dd {
  color: var(--accent-ink);
}
.point-class {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.point-class label {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0 0.95rem 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  font-size: var(--step--1);
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s;
}
.point-class label:has(input:checked) {
  border-color: var(--ink);
}
.point-class input {
  margin: 0;
  accent-color: var(--accent);
}
.lab-details {
  border-top: 1px solid var(--line);
}
.lab-details summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 44px;
  list-style: none;
  color: var(--ink-2);
  font-size: var(--step--1);
  font-weight: 600;
  cursor: pointer;
}
.lab-details summary::-webkit-details-marker {
  display: none;
}
.lab-details summary::after {
  content: "+";
  font: 500 1.1rem/1 var(--mono);
  color: var(--muted);
  transition: transform 0.3s var(--spring);
}
.lab-details[open] summary::after {
  transform: rotate(45deg);
}
.lab-details summary:hover {
  color: var(--ink);
}
.point-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.point-form label {
  display: grid;
  gap: 0.35rem;
  flex: 1 1 5rem;
  min-width: 0;
  color: var(--muted);
  font: 500 var(--step--2) / 1 var(--mono);
  text-transform: uppercase;
}
.point-form input {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  font: 500 var(--step-0) / 1 var(--mono);
  color: var(--ink);
}
.point-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
.point-form button {
  min-height: 44px;
}
.status-line {
  min-height: 3.2em;
  color: var(--muted);
  font-size: var(--step--1);
}
.range-label {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 1rem;
  color: var(--muted);
  font: 500 var(--step--2) / 1.4 var(--mono);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.range-label output {
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
}
.range-label input,
.probe-controls input {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  height: 44px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Network figure */
.network-section {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 7fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  align-items: center;
  padding-top: clamp(4.5rem, 9vw, 8rem);
}
.network-copy {
  display: grid;
  gap: 1.1rem;
  align-content: start;
}
.network-copy h2 {
  font-size: var(--step-4);
  max-width: 13ch;
}
.network-copy > p:not(.eyebrow) {
  color: var(--muted);
  font-size: var(--step-1);
  max-width: 40ch;
}
.network-figure {
  min-width: 0;
  padding: clamp(1rem, 2.2vw, 1.5rem);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
}
.network-stage {
  display: flex;
  align-items: center;
  aspect-ratio: 500 / 330;
}
.network-stage svg,
.network-fallback {
  display: block;
  width: 100%;
  height: auto;
}
.network-edge {
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.network-edge.pos,
.network-node.pos {
  stroke: var(--accent);
}
.network-edge.neg,
.network-node.neg {
  stroke: var(--rust);
}
.network-node-base {
  fill: var(--white);
}
.network-node {
  stroke-width: 1.4;
}
.network-node.pos {
  fill: var(--accent);
}
.network-node.neg {
  fill: var(--rust);
}
.network-label {
  fill: var(--muted);
  font: 500 11px var(--mono);
  letter-spacing: 0.02em;
  text-anchor: middle;
}
/* Labels are in SVG units; keep them near 10px on screen when the diagram shrinks. */
@media (max-width: 640px) {
  .network-label {
    font-size: 17px;
  }
}
.probe-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1.5rem;
  margin-top: 0.75rem;
}
.probe-controls label {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 0.6rem;
  color: var(--muted);
  font: 500 var(--step--2) / 1 var(--mono);
  text-transform: uppercase;
}
.probe-controls output {
  justify-self: end;
  color: var(--accent-ink);
  font-variant-numeric: tabular-nums;
}
.network-figure figcaption {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1.25rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.network-figure figcaption > span {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}
#network-caption {
  color: var(--accent-ink);
}

/* Automaton rule table and seed */
.rule-table {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.rule-table li {
  display: grid;
  justify-items: center;
  gap: 5px;
}
.rule-in {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  max-width: 40px;
}
.rule-in i,
.rule-out {
  display: block;
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--paper-2);
  box-shadow: inset 0 0 0 1px var(--line);
}
.rule-in i[data-on] {
  background: var(--ink);
  box-shadow: none;
}
.rule-out {
  width: calc((100% - 4px) / 3);
  max-width: 12px;
}
.rule-table li[data-on] .rule-out {
  background: var(--accent);
  box-shadow: none;
}
.rule-binary {
  color: var(--ink);
  letter-spacing: 0.18em;
}
.seed-cells {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 3px;
  max-width: 26rem;
}
.seed-cells button {
  min-width: 0;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--white);
  transition:
    background-color 0.15s,
    transform 0.3s var(--spring);
}
.seed-cells button:hover {
  border-color: var(--ink);
}
.seed-cells button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
}
.seed-cells button:active {
  transform: scale(0.92);
}
.seed-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.seed-actions .quiet-button {
  min-height: 44px;
}

/* Form study */
.form-stage {
  position: relative;
  overflow: hidden;
  aspect-ratio: 6 / 5;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
}
.form-stage .form-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: pan-y;
}
.form-stage .form-canvas:active {
  cursor: grabbing;
}
.stage-label {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  pointer-events: none;
}
.stage-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.7rem;
}
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.form-actions .quiet-button {
  min-height: 44px;
}
.form-actions .quiet-button[aria-pressed="true"],
.chip[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

/* Next link at the foot of each experiment */
.next-note {
  margin-top: clamp(4.5rem, 9vw, 8rem);
  padding-top: 0.9rem;
  border-top: 1px solid var(--ink);
}
.next-note > a {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1.5rem;
  margin-top: 0.9rem;
}
.next-note h2 {
  min-width: 0;
  overflow-wrap: break-word;
  font-size: var(--step-3);
  max-width: 26ch;
  transition: color 0.2s;
}
.next-note .arrow {
  font-size: var(--step-3);
  line-height: 1;
  color: var(--accent);
}
.next-note > a:hover h2 {
  color: var(--accent-ink);
}

/* A canvas morphs into the matching experiment on navigation. */
@media (prefers-reduced-motion: no-preference) {
  [data-specimen="network"] .specimen-frame,
  #learning-panel .plot-frame {
    view-transition-name: lab-network;
  }
  [data-specimen="automaton"] .specimen-frame,
  #emergence-panel .plot-frame {
    view-transition-name: lab-automaton;
  }
  [data-specimen="form"] .specimen-frame,
  .form-workbench .form-stage {
    view-transition-name: lab-form;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .page-heading.detail-heading {
    grid-template-columns: minmax(0, 1fr);
  }
  .page-heading.detail-heading > p {
    margin-top: 0.75rem;
  }
  .bench {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas: "plot" "primary" "secondary";
  }
  .bench-plot {
    position: static;
  }
  .bench-primary {
    margin-top: 1rem;
  }
  .network-section {
    grid-template-columns: minmax(0, 1fr);
  }
  .form-stage {
    aspect-ratio: 4 / 3;
  }
}
/* Phones: the pattern sits above the plot and Train rides along the bottom of the
   screen while the bench is in view, so the controls stay next to the field. */
@media (max-width: 900px) {
  #learning-panel {
    grid-template-areas: none;
    row-gap: 1rem;
  }
  #learning-panel .bench-plot,
  #learning-panel .bench-secondary {
    grid-area: auto;
  }
  #learning-panel .bench-primary {
    display: contents;
  }
  #learning-panel .bench-plot {
    order: 1;
  }
  #learning-panel .bench-primary > * {
    order: 2;
  }
  #learning-panel .bench-primary > .control-group:first-child {
    order: 0;
  }
  #learning-panel .bench-secondary {
    order: 3;
    margin-top: 0.5rem;
  }
  #learning-panel .train-row {
    position: sticky;
    bottom: 0;
    z-index: 3;
    padding-block: 0.6rem calc(0.6rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--line);
    background: var(--paper);
    flex-wrap: nowrap;
  }
  #learning-panel .train-button {
    flex: 1 1 0;
    min-width: 0;
    text-align: left;
  }
}
@media (max-width: 640px) {
  .metrics dd {
    font-size: 1.45rem;
  }
  .probe-controls {
    grid-template-columns: minmax(0, 1fr);
  }
  .next-note > a {
    align-items: start;
  }
  .rule-table {
    gap: 10px 9px;
  }
  .rule-in {
    gap: 1px;
  }
  .form-stage {
    aspect-ratio: 1;
  }
}

@media print {
  .specimen-controls,
  .bench-primary,
  .bench-secondary,
  .probe-controls {
    display: none !important;
  }
}
