:root {
  color-scheme: dark;
  --bg: #080a10;
  --panel: rgba(18, 21, 31, 0.76);
  --panel-strong: #11151f;
  --line: rgba(230, 220, 190, 0.14);
  --line-bright: rgba(230, 220, 190, 0.34);
  --text: #f3efe3;
  --muted: #99988f;
  --gold: #d8b96a;
  --root3: #ff584d;
  --root6: #4e78ff;
  --root9: #24d46a;
  --serif: Georgia, "Times New Roman", serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 50% -20%, rgba(216, 185, 106, 0.10), transparent 38rem),
    linear-gradient(180deg, #0b0d14 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--sans);
}

button, input, select { font: inherit; }
button, select { color: inherit; }

.app-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 64px;
}

.masthead,
.panel-heading,
.strip-heading,
.family-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.masthead { margin-bottom: 28px; }
.brand-lockup { display: flex; align-items: center; gap: 18px; }
.orbital-logo { overflow: visible; flex: 0 0 auto; }
.masthead-logo { width: 64px; height: 64px; }
.logo-halo, .logo-cycle, .logo-triad polygon, .logo-core { vector-effect: non-scaling-stroke; }
.logo-halo { fill: none; stroke: rgba(216, 185, 106, 0.34); stroke-width: 1; }
.logo-cycle { fill: none; stroke: var(--gold); stroke-width: 2.4; stroke-linecap: round; stroke-dasharray: 0.16 0.84; }
.logo-triad { transform-origin: 60px 60px; }
.logo-triad polygon { fill: none; stroke-width: 2.1; stroke-linejoin: round; opacity: 0.82; }
.logo-triad-red { transform: rotate(40deg); }
.logo-triad-red polygon { stroke: var(--root3); }
.logo-triad-blue { transform: rotate(-40deg); }
.logo-triad-blue polygon { stroke: var(--root6); }
.logo-triad-green { transform: rotate(0deg); }
.logo-triad-green polygon { stroke: var(--root9); }
.logo-core { fill: var(--bg); stroke: var(--gold); stroke-width: 1.2; }
.logo-phi { fill: var(--gold); font: 29px var(--serif); text-anchor: middle; }

body.welcome-open { overflow: hidden; }
.welcome-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at center, rgba(216, 185, 106, 0.12), transparent 28rem),
    linear-gradient(180deg, #0b0d14, #070910);
  transition: opacity 500ms ease, visibility 500ms ease;
}
.welcome-screen[hidden] { display: none; }
.welcome-screen.is-leaving { opacity: 0; visibility: hidden; }
.welcome-content { width: min(100%, 760px); text-align: center; transition: transform 500ms ease; }
.welcome-screen.is-leaving .welcome-content { transform: scale(1.035); }
.orbital-logo-large { display: block; width: min(52vw, 310px); height: auto; margin: 0 auto 28px; filter: drop-shadow(0 0 30px rgba(216, 185, 106, 0.10)); }
.welcome-content h1 { margin-bottom: 16px; font-size: clamp(2.7rem, 8vw, 6rem); }
.welcome-content .eyebrow { margin-bottom: 12px; }
.welcome-subtitle { margin-bottom: 34px; color: var(--muted); letter-spacing: 0.17em; text-transform: uppercase; }
.welcome-enter { min-width: 210px; min-height: 50px; border-color: var(--gold); color: var(--text); background: rgba(216, 185, 106, 0.08); letter-spacing: 0.08em; }
.welcome-enter:hover { background: rgba(216, 185, 106, 0.16); }
.orbital-logo-large .logo-cycle { animation: logo-orbit 18s linear infinite; transform-origin: 60px 60px; }
.orbital-logo-large .logo-triad polygon { animation: logo-breathe 4.5s ease-in-out infinite alternate; }
.orbital-logo-large .logo-triad-blue polygon { animation-delay: -1.5s; }
.orbital-logo-large .logo-triad-green polygon { animation-delay: -3s; }
@keyframes logo-orbit { to { transform: rotate(360deg); } }
@keyframes logo-breathe { from { opacity: 0.48; } to { opacity: 0.95; } }
@media (prefers-reduced-motion: reduce) {
  .orbital-logo-large .logo-cycle, .orbital-logo-large .logo-triad polygon { animation: none; }
  .welcome-screen, .welcome-content { transition: none; }
}

.mode-nav {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 12px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.mode-nav button {
  min-height: 58px;
  border: 0;
  border-left: 1px solid var(--line);
  color: var(--muted);
  text-align: left;
  letter-spacing: 0.02em;
}
.mode-nav button:first-child { border-left: 0; }
.mode-nav button span { margin-right: 12px; color: var(--gold); font-family: var(--serif); }
.mode-nav button[aria-pressed="true"] { color: var(--text); background: rgba(216, 185, 106, 0.07); box-shadow: inset 0 -2px var(--gold); }

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 0.69rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1, h2 { font-family: var(--serif); font-weight: 400; }
h1 { margin-bottom: 0; font-size: clamp(2rem, 5vw, 4rem); line-height: 0.95; }
h1 span { color: var(--gold); font-style: italic; }
h2 { margin-bottom: 0; font-size: 1.7rem; }

.cycle-mark { text-align: right; }
.cycle-mark span, .cycle-mark strong { display: block; }
.cycle-mark span { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.12em; }
.cycle-mark strong { margin-top: 5px; font-family: var(--serif); font-size: 1.55rem; font-weight: 400; }

.control-deck {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto auto;
  align-items: end;
  gap: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(11, 14, 22, 0.74);
}

.control-deck label { display: grid; gap: 7px; }
.control-deck label > span { color: var(--muted); font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; }

.transport { display: flex; gap: 7px; }
button, select {
  min-height: 40px;
  border: 1px solid var(--line-bright);
  background: transparent;
  border-radius: 2px;
  cursor: pointer;
}
button { padding: 0 16px; }
button:hover, button:focus-visible, select:hover, select:focus-visible { border-color: var(--gold); outline: none; }
.transport .play { min-width: 80px; color: #090b10; background: var(--gold); border-color: var(--gold); }
select { padding: 0 34px 0 11px; }
input[type="range"] { width: 100%; accent-color: var(--gold); }

.view-switch {
  display: flex;
  justify-content: center;
  margin: 22px 0 10px;
}

.mode-page { animation: mode-enter 260ms ease both; }
.mode-page[hidden] { display: none; }
@keyframes mode-enter { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.mode-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding: 32px 24px 22px;
  border-bottom: 1px solid var(--line);
}
.mode-heading h2 { font-size: clamp(2rem, 4vw, 3.5rem); }
.mode-heading p:last-child { max-width: 680px; margin: 10px 0 0; color: var(--muted); line-height: 1.6; }
.family-filters { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.family-filters button { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.family-filters button[aria-pressed="true"] { color: var(--text); border-color: var(--gold); background: rgba(216, 185, 106, 0.07); }
.root-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.root-3 { color: var(--root3); }
.root-6 { color: var(--root6); }
.root-9 { color: var(--root9); }

.emergence-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; min-height: 650px; border-bottom: 1px solid var(--line); }
#emergence-svg { display: block; width: min(100%, 760px); height: auto; margin: 0 auto; padding: 20px; }
.emergence-ledger { display: flex; flex-direction: column; justify-content: center; padding: 34px; border-left: 1px solid var(--line); }
.emergence-ledger > strong { font-family: var(--serif); font-size: 3.3rem; font-weight: 400; }
.emergence-ledger > p:not(.eyebrow) { color: var(--muted); line-height: 1.55; }
.root-totals { margin: 24px 0; border-top: 1px solid var(--line); }
.root-totals > div { display: flex; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--line); }
.root-totals span { display: flex; align-items: center; gap: 9px; color: var(--muted); }
.root-totals strong { font-family: var(--serif); font-size: 1.2rem; font-weight: 400; }
.current-construction { margin-top: 14px; }
.current-construction span { display: block; color: var(--muted); font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; }
.current-construction strong { display: block; margin-top: 6px; font-family: var(--serif); font-size: 4rem; font-weight: 400; }

.emergence-ring { fill: none; stroke: var(--line-bright); stroke-width: 1.2; }
.emergence-spoke { stroke: var(--line); stroke-width: 0.8; }
.emergence-node { fill: var(--panel-strong); stroke: var(--line-bright); stroke-width: 1.2; }
.emergence-node-label { fill: var(--muted); font: 15px var(--serif); text-anchor: middle; dominant-baseline: middle; }
.emergence-triangle { fill: color-mix(in srgb, var(--tri-color) 3%, transparent); stroke: var(--tri-color); stroke-width: 1.5; stroke-linejoin: round; vector-effect: non-scaling-stroke; opacity: 0.54; }
.emergence-triangle.current { fill: color-mix(in srgb, var(--tri-color) 10%, transparent); stroke-width: 3; opacity: 1; }
.emergence-center { fill: var(--panel-strong); stroke: var(--gold); stroke-width: 1; }
.emergence-center-text { fill: var(--text); font: 44px var(--serif); text-anchor: middle; dominant-baseline: middle; }
.emergence-center-caption { fill: var(--muted); font: 9px var(--sans); letter-spacing: 0.14em; text-anchor: middle; }

.streams-heading { align-items: center; }
.stream-equation { flex: 0 0 auto; text-align: right; }
.stream-equation span { display: block; color: var(--muted); font-family: var(--serif); font-size: 1.2rem; }
.stream-equation strong { display: block; font-family: var(--serif); font-size: 4rem; font-weight: 400; line-height: 0.95; }
.stream-window { position: relative; overflow-x: auto; padding: 32px 24px 28px; border-bottom: 1px solid var(--line); scrollbar-color: var(--gold) transparent; }
.stream-labels { position: sticky; left: 0; z-index: 3; display: grid; grid-template-rows: repeat(5, 48px); float: left; width: 110px; margin-right: 12px; background: var(--bg); }
.stream-labels span { display: flex; align-items: center; color: var(--muted); font-size: 0.65rem; letter-spacing: 0.1em; text-transform: uppercase; }
.stream-grid { display: grid; grid-template-columns: repeat(24, 50px); min-width: 1200px; }
.stream-column { display: grid; grid-template-rows: repeat(5, 48px); border-left: 1px solid var(--line); cursor: pointer; }
.stream-column:last-child { border-right: 1px solid var(--line); }
.stream-cell { display: grid; place-items: center; border-bottom: 1px solid var(--line); font-family: var(--serif); font-size: 1.25rem; }
.stream-cell.index { color: var(--muted); font-family: var(--sans); font-size: 0.65rem; }
.stream-cell.result { color: var(--family-color); font-size: 1rem; }
.stream-column.active { background: color-mix(in srgb, var(--family-color) 9%, transparent); box-shadow: inset 0 0 0 1px var(--family-color); }
.stream-column.active .stream-cell { color: var(--family-color); }
.stream-detail { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.stream-detail > div { padding: 24px; border-left: 1px solid var(--line); }
.stream-detail > div:first-child { border-left: 0; }
.stream-detail span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase; }
.stream-detail strong { font-family: var(--serif); font-size: 1.3rem; font-weight: 400; }

.matrix-heading { align-items: center; }
.matrix-key { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 18px; }
.matrix-key span { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.72rem; }
.phase-key { display: inline-block; width: 18px; height: 3px; }
.phase-a { background: var(--root9); }
.phase-b { background: var(--root6); }
.phase-c { background: var(--root3); }
.matrix-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; border-bottom: 1px solid var(--line); }
.matrix-scroll { min-width: 0; overflow: auto; padding: 24px; scrollbar-color: var(--gold) transparent; }
.matrix-grid {
  display: grid;
  grid-template-columns: 34px repeat(24, minmax(28px, 1fr));
  min-width: 940px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.matrix-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 31px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--serif);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
  min-width: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}
.matrix-cell.header { cursor: default; }
.matrix-cell.header { color: var(--gold); background: rgba(216, 185, 106, 0.04); font-family: var(--sans); font-size: 0.58rem; }
.matrix-cell.phase-band { color: var(--text); background: color-mix(in srgb, var(--phase-color) 8%, transparent); }
.matrix-cell.phase-band::after { content: ""; position: absolute; inset: 4px auto 4px 2px; width: 2px; background: var(--phase-color); opacity: 0.7; }
.matrix-cell.source-cell { z-index: 1; color: #080a10; background: var(--phase-color); box-shadow: inset 0 0 0 2px var(--text); font-weight: 700; }
.matrix-cell.source-cell::after { display: none; }
.matrix-inspector { display: flex; flex-direction: column; justify-content: center; padding: 30px; border-left: 1px solid var(--line); }
.matrix-inspector > strong { font-family: var(--serif); font-size: 4.5rem; font-weight: 400; line-height: 0.95; }
.matrix-inspector > p:not(.eyebrow) { margin-top: 10px; color: var(--muted); font-family: var(--serif); }
#matrix-mini-wheel { display: block; width: 100%; max-width: 250px; margin: 8px auto 20px; }
.mini-ring { fill: none; stroke: var(--line-bright); stroke-width: 1; }
.mini-node { fill: var(--panel-strong); stroke: var(--line-bright); stroke-width: 1; }
.mini-node.active { fill: var(--tri-color); stroke: var(--text); stroke-width: 1.5; }
.mini-triangle { fill: color-mix(in srgb, var(--tri-color) 7%, transparent); stroke: var(--tri-color); stroke-width: 2; }
.mini-label { fill: var(--muted); font: 9px var(--serif); text-anchor: middle; dominant-baseline: middle; }
.mini-label.active { fill: #080a10; font-weight: 700; }
.matrix-values { border-top: 1px solid var(--line); }
.matrix-values > div { display: flex; justify-content: space-between; gap: 20px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.matrix-values span { color: var(--muted); font-size: 0.7rem; }
.matrix-values strong { font-family: var(--serif); font-weight: 400; }

.recursive-heading { align-items: center; }
.recursive-controls { display: grid; min-width: 390px; gap: 13px; }
.projection-switch { display: flex; }
.projection-switch button { flex: 1; padding-inline: 12px; color: var(--muted); }
.projection-switch button[aria-pressed="true"] { color: var(--text); border-color: var(--gold); background: rgba(216, 185, 106, 0.07); }
.recursive-control-row { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 12px; }
.recursive-control-row > span { color: var(--muted); font-size: 0.65rem; letter-spacing: 0.09em; text-transform: uppercase; }
.compact-switch { display: flex; }
.compact-switch button { flex: 1; min-height: 34px; padding-inline: 9px; color: var(--muted); font-size: 0.72rem; }
.compact-switch button[aria-pressed="true"] { color: var(--text); border-color: var(--gold); background: rgba(216, 185, 106, 0.07); }
.compact-switch button:disabled, #recursive-camera:disabled { cursor: not-allowed; opacity: 0.35; }
.encoding-note { display: flex; align-items: center; justify-content: space-between; min-height: 34px; padding: 0 11px; border: 1px solid var(--line); }
.encoding-note span { color: var(--muted); font-size: 0.65rem; letter-spacing: 0.09em; text-transform: uppercase; }
.encoding-note strong { color: var(--gold); font-family: var(--serif); font-weight: 400; }
#recursive-camera { min-height: 34px; }
.recursive-controls label { display: grid; gap: 8px; }
.recursive-controls label span { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; }
.recursive-controls label strong { color: var(--text); }
.recursive-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; border-bottom: 1px solid var(--line); }
.recursive-canvas { min-width: 0; padding: 12px 20px 24px; }
#recursive-svg { display: block; width: min(100%, 880px); height: auto; margin: 0 auto; }
.projection-caption { max-width: 720px; margin: -4px auto 0; color: var(--muted); font-size: 0.73rem; text-align: center; }
.recursive-inspector { display: flex; flex-direction: column; justify-content: center; padding: 30px; border-left: 1px solid var(--line); }
.recursive-inspector > strong { font-family: var(--serif); font-size: 4.5rem; font-weight: 400; line-height: 0.95; }
.recursive-inspector > p:not(.eyebrow) { margin: 10px 0 22px; color: var(--muted); font-family: var(--serif); }
.raw-fibonacci-list { border-top: 1px solid var(--line); }
.raw-fibonacci-list > div { padding: 13px 0; border-bottom: 1px solid var(--line); }
.raw-fibonacci-list span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 0.68rem; }
.raw-fibonacci-list strong { display: block; overflow-wrap: anywhere; font-family: var(--serif); font-size: 1rem; font-weight: 400; }
.recursive-facts { display: grid; grid-template-columns: 1fr 1fr; margin-top: 22px; }
.recursive-facts > div { padding: 12px 0; border-bottom: 1px solid var(--line); }
.recursive-facts > div:nth-child(even) { padding-left: 15px; border-left: 1px solid var(--line); }
.recursive-facts span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 0.63rem; letter-spacing: 0.07em; text-transform: uppercase; }
.recursive-facts strong { font-family: var(--serif); font-weight: 400; }
.recursive-shell { fill: none; stroke: var(--line); stroke-width: 1; }
.recursive-ray { stroke: var(--line); stroke-width: 0.7; }
.recursive-path { fill: none; stroke: var(--line-bright); stroke-width: 1.1; }
.recursive-bridge { fill: none; stroke: var(--line); stroke-width: 0.75; }
.recursive-node { fill: var(--node-color); stroke: var(--bg); stroke-width: 1; opacity: 0.68; }
.recursive-node.active { stroke: var(--text); stroke-width: 2; opacity: 1; }
.recursive-node-label { fill: var(--text); font: 9px var(--sans); text-anchor: middle; paint-order: stroke; stroke: var(--bg); stroke-width: 3; }
.recursive-triangle { fill: color-mix(in srgb, var(--tri-color) 7%, transparent); stroke: var(--tri-color); stroke-width: 2.4; stroke-linejoin: round; }
.recursive-axis-label { fill: var(--muted); font: 9px var(--sans); letter-spacing: 0.1em; text-anchor: middle; }
.recursive-current-ring { fill: none; stroke: var(--gold); stroke-width: 0.8; stroke-dasharray: 3 6; opacity: 0.42; }
.recursive-origin { fill: var(--gold); opacity: 0.7; }
.recursive-future { fill: none; stroke: var(--line); stroke-width: 0.7; stroke-dasharray: 2 6; }

.projection-heading { align-items: center; }
.projection-controls { display: grid; grid-template-columns: 1fr 1fr; min-width: 420px; gap: 13px 22px; }
.geometry-switch { display: grid; grid-template-columns: repeat(4, 1fr); grid-column: 1 / -1; }
.geometry-switch button { flex: 1; color: var(--muted); }
.geometry-switch button[aria-pressed="true"] { color: var(--text); border-color: var(--gold); background: rgba(216, 185, 106, 0.07); }
.behavior-switch { display: grid; grid-template-columns: 1fr 1fr; grid-column: 1 / -1; }
.behavior-switch button { color: var(--muted); }
.behavior-switch button[aria-pressed="true"] { color: var(--text); border-color: var(--gold); background: rgba(216, 185, 106, 0.07); }
.phase-offset-controls { display: grid; grid-template-columns: 1fr 1fr auto; grid-column: 1 / -1; align-items: end; gap: 12px; padding-top: 4px; }
.phase-offset-controls button { min-height: 38px; color: var(--gold); white-space: nowrap; }
.projection-controls label { display: grid; gap: 7px; }
.projection-controls label span { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.64rem; letter-spacing: 0.08em; text-transform: uppercase; }
.projection-controls label strong { color: var(--text); }
.projection-controls input:disabled { cursor: not-allowed; opacity: 0.35; }
.projection-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; border-bottom: 1px solid var(--line); }
.torus-canvas { min-width: 0; padding: 8px 16px 22px; }
.lab-layer-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; min-height: 50px; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.lab-layer-bar > label { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 0.72rem; }
.lab-layer-bar input { accent-color: var(--gold); }
.lab-layer-bar select { min-height: 32px; margin-left: 5px; }
.cage-family-filter { display: flex; margin-left: auto; }
.cage-family-filter button { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding-inline: 10px; color: var(--muted); }
.cage-family-filter button[aria-pressed="true"] { color: var(--text); border-color: var(--gold); background: rgba(216, 185, 106, 0.07); }
#torus-svg { display: block; width: min(100%, 920px); height: auto; margin: 0 auto; }
.torus-inspector { display: flex; flex-direction: column; justify-content: center; padding: 30px; border-left: 1px solid var(--line); }
.torus-formula { margin: 4px 0 24px; padding: 16px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.torus-formula p { margin: 0 0 7px; color: var(--muted); font-family: var(--serif); }
.torus-formula p:last-child { margin-bottom: 0; }
.torus-current span { display: block; color: var(--muted); font-size: 0.65rem; letter-spacing: 0.1em; text-transform: uppercase; }
.torus-current strong { display: block; margin-top: 5px; font-family: var(--serif); font-size: 4rem; font-weight: 400; line-height: 1; }
.torus-values { margin-top: 18px; border-top: 1px solid var(--line); }
.torus-values > div { display: flex; justify-content: space-between; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.torus-values span { color: var(--muted); font-size: 0.68rem; }
.torus-values strong { font-family: var(--serif); font-weight: 400; text-align: right; }
.torus-wire { fill: none; stroke: var(--line); stroke-width: 0.8; }
.torus-wire.major { stroke: var(--line-bright); }
.torus-path-segment { fill: none; stroke: var(--segment-color); stroke-width: var(--segment-width); opacity: var(--segment-opacity); }
.torus-node { fill: var(--node-color); stroke: var(--bg); stroke-width: 1; }
.torus-node.active { stroke: var(--text); stroke-width: 2; }
.torus-triad-edge { stroke: var(--tri-color); stroke-width: 2.6; }
.torus-triad-face { fill: color-mix(in srgb, var(--tri-color) 9%, transparent); stroke: none; }
.torus-label { fill: var(--text); font: 10px var(--sans); text-anchor: middle; paint-order: stroke; stroke: var(--bg); stroke-width: 3; }
.torus-axis { stroke: var(--line-bright); stroke-width: 0.8; marker-end: url(#axis-arrow); }
.torus-axis-label { fill: var(--muted); font: 9px var(--sans); }
.phase-strand { fill: none; stroke: var(--strand-color); stroke-width: 2.2; opacity: 0.82; }
.phase-strand-label { fill: var(--text); font: 10px var(--sans); paint-order: stroke; stroke: var(--bg); stroke-width: 3; }
.cage-frame-face { fill: color-mix(in srgb, var(--frame-color) 5%, transparent); stroke: none; }
.cage-frame-edge { fill: none; stroke: var(--frame-color); stroke-width: 1.15; opacity: 0.38; }
.cage-frame-edge.current { stroke-width: 3; opacity: 1; }
.helix-guide { fill: none; stroke: var(--line); stroke-width: 0.8; }
.helix-axis { stroke: var(--line-bright); stroke-width: 1; stroke-dasharray: 4 7; }
.geometry-guide { fill: none; stroke: var(--line); stroke-width: 0.8; }
.geometry-guide.major { stroke: var(--line-bright); }
.triadic-surface { fill: color-mix(in srgb, var(--surface-color) 12%, transparent); stroke: var(--surface-color); stroke-width: 0.45; opacity: 0.48; }
.centroid-spine { fill: none; stroke: var(--gold); stroke-width: 2.4; stroke-dasharray: 5 5; opacity: 0.9; }
.measurement-centroid { fill: var(--gold); stroke: var(--bg); stroke-width: 1.5; }
.frame-normal { stroke: var(--text); stroke-width: 1.5; stroke-dasharray: 4 3; }
.measurement-label { fill: var(--text); font: 9px var(--sans); text-anchor: middle; paint-order: stroke; stroke: var(--bg); stroke-width: 3; }

.wrap-heading { align-items: center; }
.wrap-controls { display: grid; grid-template-columns: 1fr 1fr; min-width: 520px; gap: 13px 22px; }
.wrap-shape-switch { display: grid; grid-template-columns: repeat(4, 1fr); grid-column: 1 / -1; }
.wrap-shape-switch button { color: var(--muted); }
.wrap-shape-switch button[aria-pressed="true"] { color: var(--text); border-color: var(--gold); background: rgba(216, 185, 106, 0.07); }
.wrap-controls label { display: grid; gap: 7px; }
.wrap-controls label span { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.64rem; letter-spacing: 0.08em; text-transform: uppercase; }
.wrap-controls label strong { color: var(--text); }
.wrap-digit-toggle { display: flex !important; align-items: center; grid-column: 1 / -1; color: var(--muted); font-size: 0.72rem; }
.wrap-digit-toggle input { accent-color: var(--gold); }
.wrap-controls > button { min-height: 38px; color: var(--muted); }
.wrap-controls > button[aria-pressed="true"] { color: var(--text); border-color: var(--gold); background: rgba(216, 185, 106, 0.07); }
.wrap-canvas-shell { padding: 18px; border-bottom: 1px solid var(--line); }
#wrap-canvas { display: block; width: min(100%, 1160px); height: auto; margin: 0 auto; background: #090b10; cursor: grab; touch-action: none; }
#wrap-canvas:active { cursor: grabbing; }
.wrap-interaction-hint { padding: 10px 4px 0; color: var(--muted); font-size: 0.67rem; letter-spacing: 0.06em; text-align: center; }
.wrap-readout { display: grid; grid-template-columns: repeat(4, 1fr); }
.wrap-readout > div { padding: 18px 22px; border-left: 1px solid var(--line); }
.wrap-readout > div:first-child { border-left: 0; }
.wrap-readout span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 0.63rem; letter-spacing: 0.08em; text-transform: uppercase; }
.wrap-readout strong { font-family: var(--serif); font-weight: 400; }

.analysis-heading { align-items: center; }
.analysis-reference { flex: 0 0 auto; padding: 16px 18px; border-left: 1px solid var(--line); }
.analysis-reference span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 0.64rem; letter-spacing: 0.1em; text-transform: uppercase; }
.analysis-reference strong { font-family: var(--serif); font-size: 1.05rem; font-weight: 400; }
.invariant-section, .offset-section { border-bottom: 1px solid var(--line); }
.section-title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding: 24px; border-bottom: 1px solid var(--line); }
.section-title-row h3 { margin: 0; font-family: var(--serif); font-size: 1.8rem; font-weight: 400; }
.section-title-row > span { color: var(--muted); font-size: 0.72rem; }
.invariant-layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); }
.invariant-metrics { display: grid; border-right: 1px solid var(--line); }
.invariant-metrics > div { padding: 15px 22px; border-bottom: 1px solid var(--line); }
.invariant-metrics > div:last-child { border-bottom: 0; }
.invariant-metrics span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 0.63rem; letter-spacing: 0.08em; text-transform: uppercase; }
.invariant-metrics strong { font-family: var(--serif); font-size: 1.05rem; font-weight: 400; }
.invariant-chart-wrap { min-width: 0; padding: 18px 22px; }
#invariant-chart { display: block; width: 100%; height: auto; }
.analysis-grid-line { stroke: var(--line); stroke-width: 1; }
.analysis-axis-label { fill: var(--muted); font: 9px var(--sans); text-anchor: middle; }
.analysis-area-line { fill: none; stroke: var(--root9); stroke-width: 2.2; }
.analysis-twist-line { fill: none; stroke: var(--root6); stroke-width: 2.2; }
.analysis-marker { fill: var(--gold); stroke: var(--text); stroke-width: 1; }
.chart-key { display: flex; flex-wrap: wrap; justify-content: center; gap: 15px; color: var(--muted); font-size: 0.7rem; }
.chart-key span { display: inline-flex; align-items: center; gap: 6px; }
.chart-key i { width: 18px; height: 2px; }
.area-key { background: var(--root9); }
.twist-key { background: var(--root6); }
.offset-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; }
.offset-grid-scroll { min-width: 0; overflow: auto; padding: 22px; scrollbar-color: var(--gold) transparent; }
.offset-grid { display: grid; grid-template-columns: 32px repeat(24, minmax(27px, 1fr)); min-width: 830px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.offset-cell { display: grid; place-items: center; min-width: 0; min-height: 30px; padding: 0; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); border-radius: 0; background: color-mix(in srgb, var(--score-color) var(--score-opacity), transparent); color: var(--muted); font-family: var(--serif); font-size: 0.75rem; }
.offset-cell.header { color: var(--gold); background: rgba(216,185,106,0.04); font-family: var(--sans); font-size: 0.58rem; cursor: default; }
.offset-cell.perfect { color: var(--text); box-shadow: inset 0 0 0 1px var(--gold); }
.offset-cell.selected { z-index: 1; color: #080a10; background: var(--gold); box-shadow: inset 0 0 0 2px var(--text); }
.offset-inspector { display: flex; flex-direction: column; justify-content: center; padding: 28px; border-left: 1px solid var(--line); }
.offset-inspector > strong { font-family: var(--serif); font-size: 3.4rem; font-weight: 400; line-height: 1; }
.offset-inspector > p:not(.eyebrow) { margin: 10px 0 20px; color: var(--muted); }
.offset-scores { border-top: 1px solid var(--line); }
.offset-scores > div { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.offset-scores span { color: var(--muted); font-size: 0.68rem; }
.offset-scores strong { font-family: var(--serif); font-weight: 400; }
#restore-canonical { margin-top: 20px; }
.offset-triads { display: grid; grid-template-columns: repeat(24, minmax(36px, 1fr)); gap: 4px; padding: 18px 22px; border-top: 1px solid var(--line); }
.offset-triad { display: grid; place-items: center; min-height: 38px; border-bottom: 2px solid var(--tri-color); color: var(--muted); font-family: var(--serif); font-size: 0.78rem; }
.offset-triad.match { color: var(--text); }
.view-switch button { border-color: transparent; color: var(--muted); }
.view-switch button[aria-pressed="true"] { color: var(--text); border-bottom-color: var(--gold); }

.visual-stage { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); }
.visual-panel { min-width: 0; padding: 24px; border-bottom: 1px solid var(--line); }
.visual-panel + .visual-panel { border-left: 1px solid var(--line); }
.panel-note, .strip-heading span { color: var(--muted); font-size: 0.75rem; }
.visual-panel svg { display: block; width: 100%; height: auto; max-height: 68vh; margin: 10px auto 0; overflow: visible; }
.visual-stage.orbit, .visual-stage.lift { grid-template-columns: minmax(0, 800px); justify-content: center; }
.visual-stage.orbit #lift-panel, .visual-stage.lift #orbit-panel { display: none; }
.visual-stage.orbit .visual-panel, .visual-stage.lift .visual-panel { border-left: 0; }

.reading {
  display: grid;
  grid-template-columns: 0.7fr 1.7fr 1fr;
  border-bottom: 1px solid var(--line);
}
.reading > div { padding: 26px; }
.reading > div + div { border-left: 1px solid var(--line); }
.triad { font-family: var(--serif); font-size: clamp(3.6rem, 8vw, 7rem); line-height: 0.85; }
.family-line { justify-content: flex-start; margin-top: 16px; color: var(--muted); font-size: 0.8rem; }
.family-swatch { width: 30px; height: 2px; background: var(--root9); }

.phase-readout { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; align-items: center; }
.phase-readout > div { min-width: 0; }
.phase-label, .phase-readout small { display: block; color: var(--muted); }
.phase-label { font-size: 0.65rem; letter-spacing: 0.11em; text-transform: uppercase; }
.phase-readout strong { display: block; margin: 7px 0; font-family: var(--serif); font-size: 3rem; font-weight: 400; }
.phase-readout small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.equation { display: grid; align-content: center; }
.equation p:not(.eyebrow) { margin-bottom: 8px; font-family: var(--serif); font-size: 1.1rem; }
.equation p:last-child { color: var(--muted); margin-bottom: 0; }

.sequence-strip { padding: 26px 0; }
.sequence { display: grid; grid-template-columns: repeat(24, minmax(32px, 1fr)); gap: 4px; margin-top: 16px; }
.sequence button { position: relative; min-width: 0; height: 52px; padding: 0; border-color: var(--line); font-family: var(--serif); font-size: 1.05rem; }
.sequence button::after { content: ""; position: absolute; right: 6px; bottom: 5px; left: 6px; height: 2px; background: var(--family); opacity: 0.5; }
.sequence button.active { border-color: var(--family); background: color-mix(in srgb, var(--family) 12%, transparent); }

.orbit-ring, .lift-guide { fill: none; stroke: var(--line); stroke-width: 1; }
.orbit-tick { stroke: var(--line-bright); stroke-width: 1; }
.orbit-node { fill: var(--panel-strong); stroke: var(--line-bright); stroke-width: 1.5; transition: 180ms ease; }
.orbit-node.active { fill: var(--active-color); stroke: var(--text); stroke-width: 2; }
.node-label { fill: var(--muted); font: 15px var(--serif); text-anchor: middle; dominant-baseline: middle; }
.node-label.active { fill: #080a10; font-weight: 700; }
.index-label { fill: var(--muted); font: 8px var(--sans); text-anchor: middle; dominant-baseline: middle; }
.tri-path { fill: color-mix(in srgb, var(--tri-color) 4%, transparent); stroke: var(--tri-color); stroke-width: 2.2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.tri-path.history { fill: none; stroke-width: 1.1; opacity: var(--opacity); }
.center-glyph { fill: none; stroke: var(--gold); stroke-width: 1.2; opacity: 0.75; }
.center-text { fill: var(--text); font: 42px var(--serif); text-anchor: middle; dominant-baseline: middle; }
.center-caption { fill: var(--muted); font: 9px var(--sans); letter-spacing: 0.15em; text-anchor: middle; }

.spiral-path { fill: none; stroke: var(--line-bright); stroke-width: 1; }
.lift-segment { stroke: var(--line); stroke-width: 1; }
.lift-node { fill: var(--node-color); stroke: var(--bg); stroke-width: 1.2; }
.lift-node.current { stroke: var(--text); stroke-width: 2; }
.lift-label { fill: var(--text); font: 10px var(--sans); text-anchor: middle; paint-order: stroke; stroke: var(--bg); stroke-width: 3; stroke-linejoin: round; }

@media (max-width: 900px) {
  .control-deck { grid-template-columns: auto 1fr; }
  .visual-stage { grid-template-columns: 1fr; }
  .visual-panel + .visual-panel { border-left: 0; }
  .reading { grid-template-columns: 1fr 2fr; }
  .equation { grid-column: 1 / -1; border-left: 0 !important; border-top: 1px solid var(--line); }
  .sequence { grid-template-columns: repeat(12, 1fr); }
  .emergence-layout { grid-template-columns: 1fr; }
  .emergence-ledger { border-top: 1px solid var(--line); border-left: 0; }
  .stream-detail { grid-template-columns: repeat(2, 1fr); }
  .stream-detail > div:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .stream-detail > div:nth-child(4) { border-top: 1px solid var(--line); }
  .matrix-layout { grid-template-columns: 1fr; }
  .matrix-inspector { border-top: 1px solid var(--line); border-left: 0; }
  .recursive-layout { grid-template-columns: 1fr; }
  .recursive-inspector { border-top: 1px solid var(--line); border-left: 0; }
  .projection-layout { grid-template-columns: 1fr; }
  .torus-inspector { border-top: 1px solid var(--line); border-left: 0; }
  .invariant-layout { grid-template-columns: 1fr; }
  .invariant-metrics { grid-template-columns: repeat(2, 1fr); border-right: 0; border-bottom: 1px solid var(--line); }
  .offset-layout { grid-template-columns: 1fr; }
  .offset-inspector { border-top: 1px solid var(--line); border-left: 0; }
  .offset-triads { grid-template-columns: repeat(12, 1fr); }
  .wrap-heading { align-items: flex-start; flex-direction: column; }
  .wrap-controls { width: 100%; min-width: 0; }
}

@media (max-width: 600px) {
  .app-shell { width: min(100% - 20px, 1440px); padding-top: 22px; }
  .masthead { align-items: flex-end; }
  .control-deck { grid-template-columns: 1fr; }
  .mode-nav { grid-template-columns: 1fr; }
  .mode-nav button { border-top: 1px solid var(--line); border-left: 0; }
  .mode-nav button:first-child { border-top: 0; }
  .transport button { flex: 1; }
  .view-switch button { padding-inline: 10px; }
  .visual-panel { padding: 18px 4px; }
  .reading { grid-template-columns: 1fr; }
  .reading > div + div { border-left: 0; border-top: 1px solid var(--line); }
  .phase-readout { grid-template-columns: repeat(3, 1fr); padding-inline: 12px !important; }
  .phase-readout strong { font-size: 2.2rem; }
  .sequence { grid-template-columns: repeat(8, 1fr); }
  .strip-heading { align-items: flex-start; flex-direction: column; }
  .mode-heading { align-items: flex-start; flex-direction: column; padding-inline: 12px; }
  .family-filters { justify-content: flex-start; }
  .emergence-layout { min-height: 0; }
  .emergence-ledger { padding: 24px 16px; }
  .streams-heading { align-items: flex-start; }
  .stream-equation { text-align: left; }
  .stream-window { padding-inline: 10px; }
  .stream-detail { grid-template-columns: 1fr; }
  .stream-detail > div { border-top: 1px solid var(--line); border-left: 0; }
  .stream-detail > div:first-child { border-top: 0; }
  .recursive-controls { width: 100%; min-width: 0; }
  .projection-switch { flex-wrap: wrap; }
  .recursive-canvas { padding-inline: 0; }
  .recursive-inspector { padding: 24px 16px; }
  .recursive-control-row { grid-template-columns: 1fr; }
  .projection-controls { width: 100%; min-width: 0; grid-template-columns: 1fr; }
  .geometry-switch { grid-column: auto; }
  .behavior-switch { grid-column: auto; }
  .phase-offset-controls { grid-template-columns: 1fr; grid-column: auto; }
  .torus-canvas { padding-inline: 0; }
  .torus-inspector { padding: 24px 16px; }
  .cage-family-filter { width: 100%; margin-left: 0; }
  .analysis-reference { width: 100%; border-top: 1px solid var(--line); border-left: 0; }
  .section-title-row { align-items: flex-start; flex-direction: column; padding-inline: 12px; }
  .invariant-metrics { grid-template-columns: 1fr; }
  .invariant-chart-wrap { padding-inline: 8px; }
  .offset-grid-scroll { padding-inline: 8px; }
  .offset-triads { grid-template-columns: repeat(8, 1fr); padding-inline: 8px; }
  .wrap-controls { grid-template-columns: 1fr; }
  .wrap-shape-switch { grid-template-columns: repeat(2, 1fr); grid-column: auto; }
  .wrap-digit-toggle { grid-column: auto; }
  .wrap-canvas-shell { padding-inline: 0; }
  .wrap-readout { grid-template-columns: 1fr 1fr; }
  .wrap-readout > div:nth-child(3) { border-left: 0; border-top: 1px solid var(--line); }
  .wrap-readout > div:nth-child(4) { border-top: 1px solid var(--line); }
}

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