/* Amplituhedron — typeset mathematical plate
   The composition: a single editorial column on the left,
   the mesh breathing behind it across the full viewport,
   tiny margin readouts pinned to the right edge.
*/

@import url("https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,300;0,6..72,400;0,6..72,500;0,6..72,600;1,6..72,300;1,6..72,400;1,6..72,500;1,6..72,600&family=Instrument+Serif:ital@0;1&family=IBM+Plex+Mono:wght@300;400;500&display=swap");

:root {
  --ink:        #07080b;
  --ink-2:      #0c0d11;
  --bone:       #efe6d2;
  --bone-2:     #c9c0a9;
  --bone-3:     rgba(239, 230, 210, 0.62);
  --bone-4:     rgba(239, 230, 210, 0.32);
  --bone-5:     rgba(239, 230, 210, 0.14);
  --bone-6:     rgba(239, 230, 210, 0.06);
  --hair:       rgba(239, 230, 210, 0.18);

  --gold:       oklch(0.82 0.13 75);
  --gold-soft:  oklch(0.82 0.13 75 / 0.55);
  --crimson:    oklch(0.66 0.20 25);
  --magenta:    oklch(0.75 0.18 320);
  --pearl:      oklch(0.97 0.02 80);

  --serif: "Newsreader", "Cormorant Garamond", "EB Garamond", Georgia, serif;
  --display: "Instrument Serif", "Newsreader", Georgia, serif;
  --mono:  "IBM Plex Mono", "JetBrains Mono", ui-monospace, monospace;

  --t-fast: 180ms cubic-bezier(.2,.7,.2,1);
  --t-med:  420ms cubic-bezier(.2,.7,.2,1);
  --t-slow: 900ms cubic-bezier(.2,.7,.2,1);

  --plate-w: 540px;
  --gutter:  72px;
}

* { box-sizing: border-box; }

html, body, #root {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--ink);
  color: var(--bone);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.55;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "kern", "liga", "calt", "onum";
}

.shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

[hidden] { display: none !important; }

/* deep vignette + grain */
body::after {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 60;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.7'/></svg>");
}

::selection { background: var(--gold); color: var(--ink); }

/* ───────────────────────── stage ───────────────────────── */

.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

canvas.mesh {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  transition: filter var(--t-slow);
}

.stage--defect    canvas.mesh { filter: contrast(1.05) hue-rotate(-6deg); }
.stage--clinamen  canvas.mesh { filter: contrast(1.07) saturate(1.15); }
.stage--resolved  canvas.mesh { filter: contrast(1.07) brightness(1.05); }
.stage--sweep     canvas.mesh { filter: contrast(1.03); }

/* Vignette to make the typeset column readable */
.vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(to right,
      rgba(7, 8, 11, 0.94) 0,
      rgba(7, 8, 11, 0.78) calc(var(--plate-w) - 60px),
      rgba(7, 8, 11, 0.0)  calc(var(--plate-w) + 120px),
      rgba(7, 8, 11, 0.0)  calc(100% - 220px),
      rgba(7, 8, 11, 0.55) 100%
    ),
    radial-gradient(ellipse 60% 80% at 75% 55%, transparent, rgba(0,0,0,0.4));
}

/* fiducials in corners — surveyor's marks */
.fiducial {
  position: absolute;
  width: 14px; height: 14px;
  z-index: 12;
  color: var(--bone-4);
  pointer-events: none;
}
.fiducial::before, .fiducial::after {
  content: ""; position: absolute; background: currentColor;
}
.fiducial::before { left: 0; right: 0; top: 50%; height: 1px; }
.fiducial::after  { top: 0; bottom: 0; left: 50%; width: 1px; }
.fiducial.tl { top: 22px; left: 22px; }
.fiducial.tr { top: 22px; right: 22px; }
.fiducial.bl { bottom: 22px; left: 22px; }
.fiducial.br { bottom: 22px; right: 22px; }

/* ───────────────────────── meta strip (top) ───────────────────────── */

.meta {
  position: absolute;
  top: 28px; left: 56px; right: 56px;
  z-index: 14;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--bone-3);
  font-weight: 400;
}
.meta__left, .meta__right {
  display: flex; align-items: center; gap: 12px;
}
.meta__mark {
  color: var(--bone);
  letter-spacing: 0.28em;
  font-weight: 500;
}
.meta__sep { color: var(--bone-5); }
.meta__dot {
  display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px var(--gold);
  animation: pulse 2.4s ease-in-out infinite;
}
.stage--defect    .meta__dot { background: var(--crimson); box-shadow: 0 0 12px var(--crimson); }
.stage--clinamen  .meta__dot { background: var(--magenta); box-shadow: 0 0 12px var(--magenta); }
.stage--resolved  .meta__dot { background: var(--pearl); box-shadow: 0 0 12px var(--pearl); animation-duration: 4s; }
/* meta toggle — the chevron + plate label is a button */
.meta__toggle {
  appearance: none;
  background: transparent;
  border: none;
  padding: 6px 12px 6px 4px;
  margin: -6px -8px -6px -2px;
  color: var(--bone-3);
  font-family: var(--mono);
  font-size: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  transition: color var(--t-fast), background var(--t-fast);
  border-radius: 2px;
  position: relative;
}
.meta__toggle:hover {
  color: var(--bone);
  background: rgba(239, 230, 210, 0.04);
}
.meta__toggle-chev {
  color: var(--gold);
  font-size: 11px;
  display: inline-block;
  transition: transform var(--t-fast), color var(--t-fast);
}
.meta__toggle:hover .meta__toggle-chev { color: var(--bone); }
.meta__toggle.is-open .meta__toggle-chev { color: var(--bone); }

.meta__toggle-hint {
  margin-left: 8px;
  color: var(--bone-4);
  font-size: 9.5px;
  letter-spacing: 0.22em;
  transition: color var(--t-fast);
  white-space: nowrap;
}
.meta__toggle-hint .kbd {
  display: inline-block;
  padding: 0 4px;
  margin-left: 4px;
  border: 1px solid var(--bone-5);
  font-size: 9px;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--bone-3);
  text-transform: uppercase;
}
.meta__toggle:hover .meta__toggle-hint { color: var(--bone-3); }
.meta__toggle.is-open .meta__toggle-hint { color: var(--bone-3); }
.meta__toggle.is-open .meta__toggle-hint .kbd { color: var(--bone-2); border-color: var(--bone-4); }

.meta__status { color: var(--bone); }

/* "controls" help button in top-right meta */
.meta__help {
  appearance: none;
  background: transparent;
  border: none;
  padding: 4px 8px;
  color: var(--bone-3);
  font-family: var(--mono);
  font-size: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 2px;
  transition: color var(--t-fast), background var(--t-fast);
}
.meta__help:hover {
  color: var(--bone);
  background: rgba(239, 230, 210, 0.04);
}
.meta__help .kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--bone-5);
  font-size: 9px;
  letter-spacing: 0;
  color: var(--bone-3);
  text-transform: uppercase;
}

/* Controls help overlay */
.help {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(7, 8, 11, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  cursor: pointer;
  animation: helpFade 200ms ease-out;
}
@keyframes helpFade { from { opacity: 0; } to { opacity: 1; } }

.help__card {
  background: var(--ink-2);
  border: 1px solid var(--hair);
  max-width: 640px;
  width: 100%;
  cursor: default;
  padding: 28px 32px;
  color: var(--bone-2);
}
.help__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1px solid var(--hair);
  padding-bottom: 14px;
  margin-bottom: 22px;
}
.help__title {
  font-family: var(--display);
  font-style: italic;
  font-size: 26px;
  color: var(--bone);
  letter-spacing: 0;
}
.help__close {
  appearance: none;
  background: transparent;
  border: 1px solid var(--bone-5);
  color: var(--bone-3);
  font-family: var(--mono);
  width: 26px;
  height: 26px;
  cursor: pointer;
  transition: all var(--t-fast);
}
.help__close:hover { color: var(--bone); border-color: var(--bone-3); }

.help__cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 36px;
}
.help__group h3 {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--bone-3);
  margin: 0 0 14px;
  font-weight: 500;
}
.help__group dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 18px;
  margin: 0;
  font-family: var(--mono);
  font-size: 11.5px;
}
.help__group dt {
  color: var(--bone-3);
  white-space: nowrap;
}
.help__group dd {
  color: var(--bone);
  margin: 0;
}
.help__group kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--bone-4);
  background: var(--bone-6);
  border-radius: 2px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--bone-2);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-right: 3px;
}
.help__foot {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--bone-6);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--bone-4);
}

@media (max-width: 700px) {
  .help__cols { grid-template-columns: 1fr; gap: 24px; }
  .help__card { padding: 22px 24px; }
}

/* Tweaks panel — override default bottom-right placement so it
   doesn't collide with the bottom nav strip. Move it above the nav. */
body .twk-panel {
  bottom: 96px;
  transform-origin: bottom right;
}
@media (max-width: 880px), (max-aspect-ratio: 4/5) {
  body .twk-panel {
    bottom: 80px;
    right: 12px;
    width: calc(100vw - 24px);
    max-width: 280px;
  }
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(0.85); }
}

/* ───────────────────────── the plate ───────────────────────── */

.plate {
  position: absolute;
  top: 88px;
  bottom: 96px; /* room for bottom nav */
  left: var(--gutter);
  width: var(--plate-w);
  z-index: 11;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--bone-5) transparent;

  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.55;
  color: var(--bone);

  transition:
    transform var(--t-med),
    opacity var(--t-med),
    filter var(--t-med);
  will-change: transform, opacity;
}

/* When closed, the plate slides off-screen left and fades.
   The vignette also lifts so the mesh has the full field. */
.stage.is-closed .plate {
  transform: translateX(calc(-1 * (var(--plate-w) + var(--gutter) + 24px)));
  opacity: 0;
  pointer-events: none;
  filter: blur(6px);
}
.stage.is-closed .vignette {
  opacity: 0.35;
}
.vignette {
  transition: opacity var(--t-med);
}
.plate::-webkit-scrollbar { width: 6px; }
.plate::-webkit-scrollbar-thumb { background: var(--bone-5); }
.plate::-webkit-scrollbar-track { background: transparent; }

.plate__title {
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: 56px;
  line-height: 1.02;
  letter-spacing: -0.005em;
  color: var(--bone);
  margin: 0 0 36px;
  text-wrap: balance;
}
.plate__num {
  display: inline-block;
  font-family: var(--display);
  font-style: italic;
  font-size: 30px;
  color: var(--gold);
  margin-right: 16px;
  vertical-align: 0.18em;
  letter-spacing: 0;
}

.plate__lede {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--bone-2);
  margin: 0 0 26px;
  text-wrap: pretty;
}
.plate__lede em, .plate p em {
  font-style: italic;
  color: var(--bone);
  font-weight: 400;
}

.plate p {
  margin: 0 0 22px;
  color: var(--bone-2);
  text-wrap: pretty;
}

.grasse {
  color: var(--bone);
  font-family: var(--display);
  font-style: italic;
  font-size: 24px;
  letter-spacing: 0;
  white-space: nowrap;
}

.ncs sub { font-size: 0.62em; color: var(--bone-3); }

/* editable inline numerals */
.num {
  display: inline-block;
  outline: none;
  cursor: text;
  font-family: var(--display);
  font-style: italic;
  font-size: 1.1em;
  color: var(--gold);
  padding: 0 0.04em;
  border-bottom: 1px dotted var(--bone-4);
  transition: color var(--t-fast), border-color var(--t-fast);
  min-width: 0.7em;
  text-align: center;
}
.num:hover { border-bottom-style: solid; border-bottom-color: var(--gold-soft); }
.num:focus { border-bottom-style: solid; border-bottom-color: var(--gold); color: var(--bone); }

/* ───────────────────────── matrix specimen ───────────────────────── */

.matrix {
  margin: 0 0 28px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 0;
  padding: 4px 0;
}

.matrix__brack {
  font-family: var(--display);
  font-style: italic;
  font-weight: 300;
  color: var(--bone-3);
  line-height: 1;
  display: flex;
  align-items: stretch;
  user-select: none;
  font-size: clamp(48px, 14vw, 80px);
  /* stretch the bracket to the full height of the grid via transform on the glyph */
  align-self: stretch;
}
.matrix__brack--l { padding-right: 8px; justify-content: flex-end; }
.matrix__brack--r { padding-left: 8px; justify-content: flex-start; }
.matrix__brack > * { display: block; }
.matrix__brack {
  /* keep the bracket glyph centered to the data block */
  align-items: center;
}

/* Scroll horizontally if d gets wide */
.matrix__scroll {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 10px 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--bone-5) transparent;
  min-width: 0;
}
.matrix__scroll::-webkit-scrollbar { height: 5px; }
.matrix__scroll::-webkit-scrollbar-thumb { background: var(--bone-5); border-radius: 4px; }
.matrix__scroll::-webkit-scrollbar-track { background: transparent; }

.matrix__grid {
  display: grid;
  gap: 4px 0;
  align-items: center;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum", "zero";
  color: var(--bone);
  width: max-content;
}

.matrix__corner { width: 24px; }

.matrix__row-label {
  font-family: var(--display);
  font-style: italic;
  font-size: 18px;
  color: var(--bone-3);
  padding-right: 18px;
  letter-spacing: 0;
  text-align: right;
  white-space: nowrap;
}

.matrix__col-label {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.08em;
  color: var(--bone-4);
  padding: 0 8px 8px;
  text-transform: lowercase;
  text-align: center;
  white-space: nowrap;
  border-bottom: 1px solid var(--bone-6);
}

/* the data cell — sign + body sit in their own columns inside .matrix__c,
   but easier: each cell IS the cell, and we render sign/body as inner spans */
.matrix__c {
  display: inline-grid;
  grid-template-columns: 8px 1fr;
  align-items: baseline;
  padding: 3px 8px;
  white-space: nowrap;
  font-size: 12px;
  line-height: 1.2;
  position: relative;
  min-width: 56px;
  text-align: right;
  transition: color var(--t-fast);
}
.matrix__sign {
  text-align: right;
  color: var(--bone-3);
  font-weight: 500;
}
.matrix__body {
  text-align: right;
  color: var(--bone);
}

/* alternating column tint for tracking rhythm */
.matrix__grid > .matrix__c:nth-child(2n) { background: rgba(239, 230, 210, 0.018); }

.matrix figcaption,
.pluckers figcaption {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--bone-6);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--bone-3);
}
.matrix figcaption .dim,
.pluckers figcaption .dim { color: var(--bone-4); }

/* ───────────────────────── plückers ───────────────────────── */

.pluckers {
  margin: 0 0 28px;
  display: grid;
  gap: 4px;
}
.pluckers__cells {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px 28px;
  font-variant-numeric: tabular-nums;
}
.pluckers__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--bone-6);
}
.pluckers__sym {
  font-family: var(--display);
  font-style: italic;
  font-size: 17px;
  color: var(--bone-3);
}
.pluckers__sym sub {
  font-family: var(--mono);
  font-style: normal;
  font-size: 9px;
  color: var(--bone-3);
  letter-spacing: 0.06em;
  vertical-align: baseline;
  position: relative;
  bottom: -0.25em;
}
.pluckers__val {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--bone);
}
.pluckers__val.is-pos { color: var(--gold); }
.pluckers__val.is-neg { color: var(--crimson); }

/* ───────────────────────── amplitude — climactic numeral ──────── */

.amplitude {
  display: flex;
  align-items: baseline;
  gap: 20px;
  margin: 0 0 28px;
  padding: 6px 0 18px;
  border-bottom: 1px solid var(--bone-5);
}
.amplitude__val {
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: 64px;
  line-height: 0.85;
  color: var(--bone);
  letter-spacing: -0.005em;
  font-variant-numeric: tabular-nums;
  transition: color var(--t-med);
}
.stage--defect    .amplitude__val { color: var(--crimson); }
.stage--clinamen  .amplitude__val { color: var(--magenta); }
.stage--resolved  .amplitude__val { color: var(--pearl); }

.spark {
  flex: 1;
  height: 28px;
  min-width: 80px;
  color: var(--gold);
  stroke: currentColor;
  opacity: 0.85;
  align-self: center;
}
.spark--defect    { color: var(--crimson); }
.spark--clinamen  { color: var(--magenta); }
.spark--resolved  { color: var(--pearl); }

/* ───────────────────────── state line + actions ───────────── */

.state-line {
  font-family: var(--serif);
  font-style: italic;
  font-size: 17px;
  color: var(--bone-3);
  margin: 0 0 22px !important;
  text-wrap: pretty;
}
.state-line em {
  color: var(--bone);
  font-style: italic;
}
.stage--defect    .state-line em { color: var(--crimson); }
.stage--clinamen  .state-line em { color: var(--magenta); }
.stage--resolved  .state-line em { color: var(--pearl); }

.actions {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--bone-2);
  margin-bottom: 32px !important;
  text-wrap: pretty;
}

.act {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: var(--serif);
  font-style: italic;
  font-size: 17px;
  color: var(--bone);
  letter-spacing: 0;
  position: relative;
  transition: color var(--t-fast);
  white-space: nowrap;
}
.act__bracket {
  color: var(--bone-4);
  font-style: italic;
  transition: color var(--t-fast);
  margin: 0 1px;
}
.act__label {
  border-bottom: 1px dotted var(--bone-4);
  padding: 0 1px;
  transition: border-color var(--t-fast), color var(--t-fast);
}
.act__kbd {
  margin-left: 6px;
  display: inline-block;
  vertical-align: 0.2em;
  font-family: var(--mono);
  font-style: normal;
  font-size: 9px;
  padding: 0 4px;
  border: 1px solid var(--bone-5);
  color: var(--bone-3);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.act:hover .act__bracket { color: var(--gold); }
.act:hover .act__label   { border-bottom-color: var(--gold); color: var(--bone); }

/* active states */
.act.is-active .act__bracket { color: var(--bone-2); }
.act.is-active .act__label {
  color: var(--ink);
  background: var(--gold);
  border-bottom-color: transparent;
  padding: 0 6px;
}
.act.is-gold.is-active .act__label    { background: var(--gold);    color: var(--ink); }
.act.is-magenta.is-active .act__label { background: var(--magenta); color: var(--ink); }
.act.is-crimson.is-active .act__label { background: var(--crimson); color: var(--bone); }
.act.is-pearl.is-active .act__label   { background: var(--pearl);   color: var(--ink); }

/* ───────────────────────── theorem rows ───────────────────────── */

.thm {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  padding: 11px 0;
  border-top: 1px solid var(--bone-6);
  align-items: baseline;
  font-size: 14px;
}
.thm:last-of-type { border-bottom: 1px solid var(--bone-6); margin-bottom: 24px; }

.thm__name {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--bone-3);
}
.thm__body {
  font-family: var(--display);
  font-style: italic;
  font-size: 18px;
  color: var(--bone);
  text-align: right;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.thm__body em {
  font-style: italic;
  color: var(--bone);
}
.thm__op {
  color: var(--gold);
  font-style: normal;
  font-family: var(--mono);
}
.thm__detail {
  font-family: var(--mono);
  font-size: 9.5px;
  font-style: normal;
  color: var(--bone-3);
  letter-spacing: 0.1em;
  margin-left: 6px;
}
.thm__body--blocked em { color: var(--bone-3); }

/* ───────────────────────── plate footer ───────────────────────── */

.plate__foot {
  margin-top: 32px;
  padding-top: 18px;
  border-top: 1px solid var(--bone-5);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--bone-3);
}
.plate__cite { color: var(--bone-2); }
.plate__cite .mono { color: var(--bone); font-weight: 500; }
.plate__cite--small {
  color: var(--bone-4);
  font-size: 9.5px;
}
.plate__cite--small em {
  font-family: var(--display);
  font-style: italic;
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--bone);
  vertical-align: -0.1em;
}

/* ───────────────────────── right margin readouts ────────────── */

.margin {
  position: absolute;
  top: 50%;
  right: 56px;
  transform: translateY(-50%);
  z-index: 11;
  display: flex;
  flex-direction: column;
  gap: 26px;
  text-align: right;
  pointer-events: none;
  /* don't overlap the bottom nav */
  max-height: calc(100vh - 220px);
}
.margin__group {
  display: flex; flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}
.margin__label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--bone-3);
}
.margin__val {
  font-family: var(--display);
  font-style: italic;
  font-size: 26px;
  color: var(--bone);
  line-height: 1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.margin__pct {
  margin-left: 8px;
  font-family: var(--mono);
  font-size: 10px;
  font-style: normal;
  color: var(--bone-3);
  letter-spacing: 0.06em;
  vertical-align: 0.2em;
}

/* ───────────────────────── stage state variations per plate ───────── */

.stage--i    .meta__mark::before    { content: "i · "; opacity: 0.5; }
.stage--ii   .meta__mark::before    { content: "ii · "; opacity: 0.5; }
.stage--iii  .meta__mark::before    { content: "iii · "; opacity: 0.5; }
.stage--iv   .meta__mark::before    { content: "iv · "; opacity: 0.5; }
.stage--v    .meta__mark::before    { content: "v · "; opacity: 0.5; }

/* ───────────────────────── spectrum (plate i) ───────────────────────── */

.spectrum {
  margin: 0 0 28px;
  display: grid;
  gap: 8px;
}
.spectrum__bars {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: end;
  gap: 5px;
  height: 64px;
  padding: 8px 0;
  border-bottom: 1px solid var(--bone-6);
}
.spectrum__bar {
  background: var(--bone-5);
  min-height: 4px;
  border-radius: 1px;
  transition: height 120ms cubic-bezier(.2,.7,.2,1), background var(--t-fast);
}
.spectrum__bar.is-pinned {
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold-soft);
}
.spectrum figcaption {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--bone-3);
}
.spectrum figcaption .dim { color: var(--bone-4); }

/* ───────────────────────── segmented picker (plates iii, v) ───── */

.picker {
  display: flex;
  border: 1px solid var(--hair);
  margin: 4px 0 22px;
  align-items: stretch;
}
.picker__opt {
  appearance: none;
  flex: 1;
  background: transparent;
  border: none;
  border-right: 1px solid var(--hair);
  color: var(--bone-3);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  padding: 11px 10px;
  cursor: pointer;
  transition: all var(--t-fast);
}
.picker__opt:last-child { border-right: none; }
.picker__opt:hover { color: var(--bone); background: var(--bone-6); }
.picker__opt.is-active {
  color: var(--ink);
  background: var(--gold);
}

/* ───────────────────────── Fano lines (plate iv) ─────────────── */

.fano-lines {
  margin: 0 0 24px;
  display: grid;
  gap: 0;
  border-top: 1px solid var(--bone-6);
}
.fano-line {
  display: grid;
  grid-template-columns: auto auto auto auto auto 1fr;
  align-items: baseline;
  gap: 8px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--bone-6);
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--bone-3);
  letter-spacing: 0.05em;
  transition: all var(--t-fast);
}
.fano-line__byte {
  color: var(--bone-2);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum", "zero";
  padding: 1px 6px;
  border: 1px solid var(--bone-6);
  letter-spacing: 0.1em;
}
.fano-line__op {
  color: var(--bone-4);
}
.fano-line__label {
  margin-left: 16px;
  font-family: var(--display);
  font-style: italic;
  font-size: 16px;
  color: var(--bone-3);
  letter-spacing: 0;
  text-align: right;
  white-space: nowrap;
}

.fano-line.is-current {
  background: rgba(239, 230, 210, 0.04);
  border-bottom-color: var(--gold-soft);
}
.fano-line.is-current .fano-line__byte {
  color: var(--gold);
  border-color: var(--gold-soft);
  background: rgba(0, 0, 0, 0.25);
}
.fano-line.is-current .fano-line__label {
  color: var(--bone);
}
.fano-line.is-current .fano-line__op {
  color: var(--gold);
}

/* ───────────────────────── bottom nav ───────────────────────── */

.constellation {
  position: absolute;
  right: 28px;
  bottom: 92px;
  z-index: 19;
  display: flex;
  gap: 7px;
  align-items: center;
}

.constellation a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 24px;
  padding: 0 7px;
  border: 1px solid var(--hair);
  color: var(--bone-3);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  background: rgba(7, 8, 11, 0.42);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}

.constellation a:hover,
.constellation a.is-current {
  border-color: var(--gold-soft);
  color: var(--gold);
  background: rgba(239, 185, 89, 0.08);
}

.nav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 76px;
  z-index: 18;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 0;
  background: linear-gradient(to top, var(--ink) 30%, rgba(7,8,11,0.0));
  padding: 14px 56px 16px;
}

.nav__arrow {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--bone-3);
  font-family: var(--mono);
  font-size: 18px;
  width: 42px;
  cursor: pointer;
  transition: color var(--t-fast);
}
.nav__arrow:hover { color: var(--gold); }

.nav__plates {
  display: flex;
  margin: 0;
  padding: 0;
  list-style: none;
  border-left: 1px solid var(--hair);
  border-right: 1px solid var(--hair);
  flex: 1;
  max-width: 880px;
}
.nav__plates li {
  flex: 1;
  display: flex;
  border-right: 1px solid var(--hair);
}
.nav__plates li:last-child { border-right: none; }

.nav__plate {
  appearance: none;
  background: transparent;
  border: none;
  width: 100%;
  cursor: pointer;
  padding: 8px 14px 10px;
  text-align: left;
  display: grid;
  grid-template-rows: auto auto;
  gap: 1px;
  align-items: baseline;
  position: relative;
  transition: background var(--t-fast);
}
.nav__plate::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: var(--bone-5);
  transition: background var(--t-fast), height var(--t-fast);
}
.nav__plate:hover { background: rgba(239, 230, 210, 0.04); }
.nav__plate:hover::before { background: var(--bone-3); }

.nav__roman {
  font-family: var(--display);
  font-style: italic;
  font-size: 16px;
  color: var(--bone-3);
  letter-spacing: 0;
  line-height: 1;
  margin-right: 8px;
  display: inline-block;
  vertical-align: -0.05em;
}
.nav__name {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  color: var(--bone-2);
  text-transform: none;
  display: inline-block;
}
.nav__death {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: 0.18em;
  color: var(--bone-4);
  text-transform: uppercase;
  grid-column: 1 / -1;
  margin-top: 2px;
}

.nav__plate.is-active::before { background: var(--gold); height: 2px; }
.nav__plate.is-active { background: rgba(239, 230, 210, 0.06); }
.nav__plate.is-active .nav__roman { color: var(--gold); }
.nav__plate.is-active .nav__name  { color: var(--bone); }
.nav__plate.is-active .nav__death { color: var(--bone-3); }

/* ───────────────────────── responsive ───────────────────────── *
   Two thresholds matter: the column gets too cramped for inline
   margin readouts (<1280), and the viewport goes portrait/narrow
   (<900 or aspect <1). Below the portrait threshold the layout flips:
   the mesh sits in a bounded top region, the typeset column flows
   beneath it in normal page order.
*/

@media (max-width: 1280px) {
  :root { --plate-w: 460px; --gutter: 48px; }
  .plate__title { font-size: 46px; }
  .amplitude__val { font-size: 52px; }
  .margin { right: 36px; gap: 20px; }
  .margin__val { font-size: 22px; }
  .nav { padding: 12px 32px 16px; }
  .nav__name { font-size: 9.5px; letter-spacing: 0.08em; }
  .nav__death { font-size: 8px; letter-spacing: 0.16em; }
}

@media (max-width: 1040px) {
  :root { --plate-w: 400px; --gutter: 36px; }
  .plate { font-size: 15.5px; padding-right: 18px; }
  .plate__title { font-size: 40px; }
  .plate__num { font-size: 24px; }
  .grasse { font-size: 21px; }
  .amplitude__val { font-size: 48px; }
  .margin { right: 24px; gap: 16px; }
  .margin__val { font-size: 20px; }
  .meta { left: 36px; right: 36px; }
  .meta__left .meta__sep:nth-of-type(2),
  .meta__left span:nth-last-child(2) { display: none; }
}

/* Portrait / narrow — plate becomes a full-screen overlay when open */
@media (max-width: 880px), (max-aspect-ratio: 4/5) {
  :root { --plate-w: 100%; --gutter: 0; }

  .shell {
    height: 100vh;
    overflow: hidden;
  }

  .stage {
    height: 100vh;
    overflow: hidden;
  }

  canvas.mesh {
    position: absolute;
    inset: 0;
    height: 100%;
    width: 100%;
  }

  .vignette {
    position: absolute;
    inset: 0;
    background:
      radial-gradient(ellipse 80% 70% at 50% 40%, transparent, rgba(0,0,0,0.45));
  }

  .meta {
    top: 14px;
    left: 18px;
    right: 18px;
    font-size: 9px;
    letter-spacing: 0.18em;
  }
  .meta__left, .meta__right { gap: 6px; flex-wrap: wrap; }
  .meta__left span:nth-child(n+4),
  .meta__left .meta__sep:nth-of-type(n+2) { display: none; }
  .meta__right span:nth-child(n+5),
  .meta__right .meta__sep:nth-of-type(n+2) { display: none; }
  .meta__toggle-hint { display: none; }
  .meta__help { font-size: 9px; }
  .meta__help span:first-child { display: none; }

  .fiducial.tl, .fiducial.tr { top: 10px; }
  .fiducial.tl { left: 10px; }
  .fiducial.tr { right: 10px; }
  .fiducial.bl, .fiducial.br { display: none; }

  /* Margin readouts — visible only when plate is closed */
  .margin {
    position: absolute;
    top: auto;
    bottom: 90px;
    right: 18px;
    left: 18px;
    transform: none;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
    text-align: left;
    gap: 12px 20px;
    max-height: none;
  }
  .stage.is-open .margin { display: none; }
  .margin__group { align-items: flex-start; }
  .margin__label { font-size: 8px; letter-spacing: 0.2em; }
  .margin__val { font-size: 18px; }
  .margin__pct { font-size: 9px; }

  .constellation {
    right: 18px;
    bottom: 72px;
    gap: 5px;
  }
  .constellation a {
    min-width: 26px;
    height: 22px;
    padding: 0 5px;
    font-size: 8px;
  }

  /* Plate: floating overlay over the mesh when open */
  .plate {
    position: absolute;
    top: 52px;
    bottom: 84px;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 28px 22px 32px;
    overflow-y: auto;
    overflow-x: hidden;
    background:
      linear-gradient(to bottom, rgba(7,8,11,0.85) 0, rgba(7,8,11,0.95) 60px, var(--ink) 240px);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    z-index: 14;
    font-size: 15.5px;
  }
  .stage.is-closed .plate {
    transform: translateY(8%);
    opacity: 0;
    pointer-events: none;
    filter: blur(8px);
  }

  .plate__title { font-size: 38px; }
  .plate__num { font-size: 22px; margin-right: 12px; }
  .plate__lede { font-size: 16px; }
  .grasse { font-size: 20px; }
  .amplitude { padding-bottom: 14px; }
  .amplitude__val { font-size: 44px; }
  .actions, .state-line { font-size: 16px; }
  .act { font-size: 16px; }

  .pluckers__cells { grid-template-columns: 1fr 1fr; gap: 4px 18px; }

  .matrix__brack { font-size: clamp(40px, 11vw, 64px); }
  .matrix__row-label { font-size: 16px; padding-right: 12px; }
  .matrix__c { min-width: 48px; font-size: 11px; padding: 3px 6px; }

  .thm { grid-template-columns: 1fr; gap: 6px; padding: 12px 0; }
  .thm__body { justify-content: flex-start; text-align: left; }
  .thm__name { font-size: 9px; }

  /* Bottom nav: fixed at bottom */
  .nav {
    position: absolute;
    height: 64px;
    padding: 10px 14px 12px;
    background: rgba(7,8,11,0.96);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--hair);
    z-index: 20;
  }
  .nav__arrow { font-size: 16px; width: 32px; }
  .nav__plates { max-width: none; }
  .nav__name { display: none; }
  .nav__death { display: none; }
  .nav__plate {
    grid-template-rows: 1fr;
    padding: 10px 4px;
    justify-items: center;
    text-align: center;
  }
  .nav__roman { font-size: 18px; margin-right: 0; }

  /* Fano lines: simpler grid */
  .fano-line { grid-template-columns: auto auto auto auto auto; }
  .fano-line__label { grid-column: 1 / -1; margin-left: 0; text-align: left; font-size: 14px; }

  /* Spectrum: shrink */
  .spectrum__bars { height: 52px; }

  /* Picker: stack labels */
  .picker__opt { font-size: 8.5px; letter-spacing: 0.16em; padding: 10px 6px; }
}

/* Very narrow (phones) */
@media (max-width: 520px) {
  canvas.mesh { height: 50vh; min-height: 300px; }
  .vignette { height: 50vh; }
  .plate { margin-top: 50vh; padding: 24px 18px 28px; }
  .margin {
    bottom: calc(35vh + 14px);
    right: 14px;
    left: 14px;
    gap: 10px 14px;
  }
  .margin__val { font-size: 16px; }
  .constellation {
    left: 14px;
    right: 14px;
    justify-content: center;
  }
  .plate__title { font-size: 32px; line-height: 1.05; }
  .amplitude { flex-direction: column; align-items: stretch; gap: 8px; }
  .amplitude__val { font-size: 38px; }
  .spark { width: 100%; }
  .pluckers__cells { grid-template-columns: 1fr; }
}

@media (max-height: 600px) and (min-aspect-ratio: 1/1) {
  /* short landscape: tighten vertical metrics */
  .meta { top: 14px; }
  .plate { top: 56px; bottom: 14px; }
  .plate__title { font-size: 36px; margin-bottom: 22px; }
  .amplitude__val { font-size: 40px; }
}
