:root {
  color-scheme: dark;
  --room: #201d20;
  --deck: #2b272b;
  --track: #141216;
  --paper: #f5eadd;
  --muted: #d2c6c3;
  --dim: #bfb0b0;
  --line: #4c4248;
  --gold: #ffd08a;
  --coral: #ffb19c;
  --mint: #b9dec8;
  --lane-gap: 19%;
  --row-size: 47px;
  --input-y: 17px;
  background: var(--room);
  color: var(--paper);
  font: 100% / 1.5 system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}
[hidden] { display: none !important; }

.page {
  max-width: 71rem;
  margin: 0 auto;
  padding: 3.65rem 2rem 3.35rem;
}

.page-head { margin-bottom: 1.5rem; }
h1 {
  font: 400 clamp(3.25rem, 7vw, 6.25rem) / .93 Georgia, serif;
  letter-spacing: -.071em;
  margin: 0 0 .9rem -.045em;
}
.page-head p {
  margin: 0;
  max-width: 51rem;
  color: var(--muted);
  font-size: clamp(1rem, 1.6vw, 1.16rem);
  line-height: 1.45;
}

.experiment {
  position: relative;
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  background: var(--deck);
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  box-shadow: 0 17px 44px #110b1270, inset 0 1px #ffffff09;
}

.plate-bank {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 1.3rem 1.35rem;
}

.plates {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .6rem;
}

.plate {
  margin: 0;
  padding: .45rem .45rem .5rem;
  border: 1px solid #584b53;
  border-radius: .64rem;
  background: #383037;
  box-shadow: 0 3px 7px #120d1348;
}
.plate[data-state="failed"] { border-color: #a46c62; }
.plate[data-state="fixed"] { border-color: #6e8f7f; }
.plate figcaption {
  width: 100%;
  color: var(--muted);
  padding: .08rem .32rem .43rem;
  line-height: 1.2;
  font-size: .9rem;
  font-weight: 610;
}
.plate[data-state="failed"] figcaption { color: var(--coral); }
.plate[data-state="fixed"] figcaption { color: var(--mint); }

.bitmap {
  display: block;
  width: 100%;
  aspect-ratio: 20 / 14;
  border-radius: .25rem;
  background: var(--track);
  overflow: hidden;
}
.bitmap .cell { shape-rendering: crispEdges; }
.bitmap .anchor {
  fill: none;
  stroke: var(--gold);
  stroke-width: .12;
  stroke-linejoin: round;
}
.bitmap .anchor--quiet { opacity: .65; }
.bitmap .stamp-frame {
  fill: none;
  stroke: var(--gold);
  stroke-width: .17;
}
.bitmap .delta {
  fill: none;
  stroke: var(--coral);
  stroke-width: .105;
}
.bitmap .delta--fixed { stroke: var(--mint); }
.bitmap .stamp-pulse {
  fill: none;
  stroke: var(--gold);
  stroke-width: .15;
  transform-box: fill-box;
  transform-origin: center;
  animation: expose 660ms ease-out both;
}
@keyframes expose {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(2.9); }
}

.readout {
  min-height: 74px;
  padding: .8rem .25rem 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
}
.feedback {
  font-size: .93rem;
  line-height: 1.35;
  color: var(--muted);
}
.feedback strong, .feedback span { display: block; }
.feedback strong {
  color: var(--paper);
  font-weight: 630;
  margin-bottom: .16rem;
}
.experiment[data-signal="fail"] .feedback strong { color: var(--coral); }
.experiment[data-signal="repair"] .feedback strong,
.experiment[data-signal="pass"] .feedback strong { color: var(--mint); }
.sample-button {
  border: 1px solid #788779;
  background: #343c37;
  color: var(--mint);
  border-radius: .48rem;
  min-height: 44px;
  padding: .25rem .56rem;
  white-space: nowrap;
  font-size: .89rem;
}

.workbench {
  min-width: 0;
  padding: 1.15rem;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.circuit {
  background: var(--track);
  border: 1px solid #584b53;
  border-radius: .77rem;
  padding: .6rem 0 .25rem;
}
.lane-labels {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin: 0 2.5%;
  text-align: center;
  font-size: .84rem;
  font-weight: 650;
  color: var(--dim);
}
.lane-labels span:nth-child(3) { color: var(--gold); }

.tracks {
  height: calc(var(--input-y) + var(--row-size) * 5 + 28px);
  position: relative;
  isolation: isolate;
}
.wire-layer, .switch-layer, .pixel-layer, .flyer-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.wire {
  position: absolute;
  width: 1px;
  top: var(--input-y);
  bottom: 12px;
  background: #5b4954;
}
.wire--centre { background: #927754; }
.wire::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 8px;
  height: 8px;
  transform: translate(-50%, 50%);
  background: var(--track);
  border: 1px solid #7f6976;
}
.wire--centre::after {
  width: 12px;
  height: 12px;
  border-color: var(--gold);
}

.gate {
  position: absolute;
  pointer-events: auto;
  width: calc(var(--lane-gap) + 30px);
  height: 44px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: .6rem;
  background: transparent;
  padding: 0 10px;
}
.gate svg {
  display: block;
  width: calc(100% - 10px);
  height: 23px;
  overflow: visible;
}
.gate .bar {
  fill: #372e37;
  stroke: #a48a9a;
  stroke-width: 1.15;
  vector-effect: non-scaling-stroke;
}
.gate .pin {
  fill: #bc9dac;
  stroke: none;
}
.gate .split { display: none; }
@media (hover: hover) {
  .gate:hover .bar { stroke: var(--paper); fill: #56404b; }
  .transport button:hover:not(:disabled), .sample-button:hover { background: #4a3d47; }
}
.gate:active .bar { fill: #6b4e58; }
.gate[data-current] .bar { stroke: var(--gold); }
.gate[data-current] .pin { fill: var(--gold); }
.gate[aria-pressed="true"] .bar {
  fill: #4c2b2d;
  stroke: var(--coral);
  stroke-dasharray: 3 3;
}
.gate[aria-pressed="true"] .pin { fill: var(--coral); }
.gate[aria-pressed="true"] .split {
  display: inline;
  fill: none;
  stroke: var(--coral);
  stroke-width: 1.35;
  vector-effect: non-scaling-stroke;
}

.pixel, .flyer, .previous-pixel {
  display: block;
  width: 23px;
  height: 23px;
  position: absolute;
  transform: translate(-50%, -50%);
  border: 1px solid var(--pixel-border, #b6a4a9);
  border-radius: 2px;
  background: var(--brightness, #181418);
}
.pixel {
  box-shadow: 0 1px 4px #0007;
}
.pixel[data-centre] { outline: 2px solid var(--gold); outline-offset: 2px; }
.pixel[data-inverted] { outline: 2px solid var(--coral); outline-offset: 2px; }
.previous-pixel {
  margin-left: 23px;
  width: 13px;
  height: 13px;
  border: 1px dashed var(--coral);
  box-shadow: 0 0 0 2px var(--track);
}
.flyer-layer { z-index: 3; }
.flyer { z-index: 1; }

.transport {
  display: grid;
  grid-template-columns: minmax(60px, 1.1fr) repeat(4, minmax(48px, 1fr));
  gap: .3rem;
  align-items: center;
  margin-top: .56rem;
}
.transport button {
  min-height: 44px;
  border: 1px solid #60515b;
  border-radius: .47rem;
  background: #3a3039;
  padding: 0 .15rem;
  font-weight: 610;
  font-size: .9rem;
}
.transport button:disabled {
  color: #b0a4a8;
  background: #2b252c;
  border-color: #493c46;
}
.transport #step:not(:disabled) {
  border-color: #9b7854;
  color: var(--gold);
}
.transport button:active:not(:disabled), .sample-button:active { background: #56404b; }
.stage-label {
  color: var(--gold);
  font-size: .88rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: center;
}

.proof {
  margin-top: 1.6rem;
  padding-top: .85rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.proof p { margin: 0 0 .4rem; }
.proof strong { color: var(--paper); }
.proof nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.1rem;
  font-size: .9rem;
}
.proof a {
  color: var(--gold);
  text-underline-offset: .23em;
  text-decoration-color: #b69770;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

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

@media (max-width: 820px) {
  :root { --row-size: 44px; --input-y: 14px; }
  .page { max-width: 38rem; padding: 1.16rem 1rem 2rem; }
  h1 { font-size: clamp(2.75rem, 13.5vw, 5.5rem); margin-bottom: .65rem; }
  .page-head { margin-bottom: .95rem; }
  .page-head p { max-width: 35rem; line-height: 1.34; }
  .experiment { grid-template-columns: minmax(0, 1fr); border-radius: .9rem; }
  .plate-bank { padding: .57rem .57rem 0; }
  .plates { gap: .42rem; }
  .plate { padding: .32rem .29rem .33rem; }
  .plate figcaption { padding: .1rem .23rem .35rem; }
  .readout { min-height: 64px; padding: .5rem .2rem .4rem; }
  .workbench { padding: 0 .57rem .57rem; border-left: 0; }
  .circuit { padding-top: .34rem; }
  .proof { margin-top: 1.24rem; }
}

@media (max-width: 480px) and (max-height: 735px) {
  .page { padding-top: .66rem; }
  .page-head { margin-bottom: .62rem; }
  h1 { font-size: clamp(2.3rem, 11vw, 2.8rem); margin-bottom: .42rem; }
  .page-head p { line-height: 1.27; }
  .readout { min-height: 56px; padding-block: .37rem .25rem; }
  .transport { margin-top: .39rem; }
}

@media (max-width: 350px) {
  .page { padding-inline: .72rem; }
  .transport { grid-template-columns: minmax(49px, .85fr) repeat(4, minmax(44px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; }
}
