@import url("./fonts.css");

/* Highbury Mk II: canonical tutorial stylesheet. */

:root {
  color-scheme: light;
  --paper: #eaeef4;
  --panel: #ffffff;
  --well: #e5eaf1;
  --line: #d1d8e3;
  --text: #141821;
  --head: #080c14;
  --muted: #5c6675;
  --muted2: #333c4b;
  --acc: #1b52c9;
  --soft: #e4ecfd;
  --red: #c8102e;
  --red-soft: #fbdfe3;
  --steel: #42506b;
  --amber: #c67a12;
  --shadow: 0 1px 2px rgba(16, 28, 56, 0.05), 0 10px 34px rgba(16, 28, 56, 0.10);
  --display: "Zilla Slab", "Rockwell", Georgia, serif;
  --reading: "Piazzolla", Georgia, "Iowan Old Style", serif;
  --mono: "Fragment Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --measure-prose: 50rem;
  --measure-wide: 1080px;
  --toc-col: 212px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0a0d13;
  --panel: #12161f;
  --well: #191e29;
  --line: #28303f;
  --text: #e5e8ef;
  --head: #f4f6fb;
  --muted: #8a93a3;
  --muted2: #c0c6d2;
  --acc: #6f9bff;
  --soft: #16213a;
  --red: #ef4b60;
  --red-soft: #39161c;
  --steel: #8b97ad;
  --amber: #e0a54a;
  --shadow: none;
}

* {
  box-sizing: border-box;
}

button, input, select {
  font: inherit;
}

button, input, select, a {
  outline-offset: 4px;
}

img, svg {
  max-width: 100%;
}

code, pre, .mono {
  font-family: var(--mono);
}

.nav-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.map-toggle,
.theme-toggle {
  cursor: pointer;
}

h1 {
  max-width: 920px;
  margin: 0;
  font-size: clamp(3.4rem, 9vw, 7.6rem);
  font-weight: 600;
  letter-spacing: -0.045em;
  line-height: 0.86;
}

.chapter-page h1 {
  max-width: 750px;
  font-size: clamp(3.2rem, 8vw, 6.4rem);
}

.chapter-contract p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.48;
}

.chapter-card .card-number {
  color: var(--amber);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.chapter-card .card-description {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.52;
}

.chapter-card .card-arrow {
  position: absolute;
  right: 1.2rem;
  bottom: 1rem;
  color: var(--acc);
  font-family: var(--mono);
}

.concrete-example {
  border-left-color: var(--amber);
}

.check {
  border-left-color: var(--steel);
  background: color-mix(in srgb, var(--well) 50%, var(--panel));
}

.hardware-reality {
  border-left-color: var(--amber);
}

.source-spotlight {
  border-left-color: var(--acc);
  background: var(--soft);
}

.callout-label {
  display: block;
  margin-bottom: 0.42rem;
  color: var(--head);
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.check .callout-label {
  color: var(--steel);
}

.mental-model p:last-child,
.concrete-example p:last-child,
.misconception p:last-child,
.check p:last-child,
.source-spotlight p:last-child {
  margin-bottom: 0;
}

blockquote cite {
  display: block;
  margin-top: 0.7rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.66rem;
  font-style: normal;
}

.equation-reading {
  display: block;
  margin-top: 0.6rem;
  color: var(--muted);
  font-family: var(--reading);
  font-size: 0.85rem;
  white-space: normal;
}

.ledger {
  overflow: hidden;
  margin: 1.8rem 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.ledger-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.28fr) 1fr;
  border-top: 1px solid var(--line);
}

.ledger-row:first-child {
  border-top: 0;
}

.ledger-key, .ledger-value {
  padding: 0.8rem 1rem;
}

.ledger-value {
  font-size: 0.92rem;
}

.table-wrap {
  overflow-x: auto;
  margin: 1.8rem 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

th, td {
  padding: 0.72rem 0.9rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

tr:last-child td {
  border-bottom: 0;
}

.sequence {
  margin: 2.2rem 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sequence-actors {
  display: grid;
  grid-template-columns: repeat(var(--actors), minmax(130px, 1fr));
  gap: 0.6rem;
  overflow-x: auto;
  margin: 1rem 0;
}

.sequence-actor strong, .sequence-actor small {
  display: block;
}

.sequence-actor strong {
  color: var(--head);
  font-family: var(--display);
}

.sequence-actor small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.6rem;
  text-transform: uppercase;
}

.sequence-message {
  display: grid;
  grid-template-columns: minmax(90px, 0.28fr) 1fr;
  gap: 1rem;
  align-items: center;
}

.sequence-route {
  color: var(--step-color);
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.sequence-copy strong {
  display: block;
  color: var(--head);
  font-family: var(--display);
  font-size: 1.25rem;
}

.sequence-copy p {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
}

.sequence-wire {
  margin-top: 0.8rem;
  white-space: pre-wrap;
}

.sequence-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.9rem;
}

.sequence-controls button:disabled {
  cursor: default;
  opacity: 0.42;
}

.sequence-count {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.66rem;
}

.sequence-fallback {
  margin: 1rem 0 0;
  padding-left: 1.3rem;
  color: var(--muted);
  font-size: 0.83rem;
}

.sequence.is-ready .sequence-fallback {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.interactive-intro {
  margin: 0.3rem 0 1rem;
  color: var(--muted);
  font-size: 0.87rem;
}

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

.control {
  display: grid;
  gap: 0.3rem;
}

.control label {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.interactive-output {
  margin-top: 1rem;
  padding: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 0.55rem;
}

.metric {
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--well);
}

.metric .value {
  display: block;
  color: var(--head);
  font-family: var(--display);
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1;
}

.metric .label {
  display: block;
  margin-top: 0.35rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.6rem;
  text-transform: uppercase;
}

.bar-chart {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.bar {
  display: grid;
  grid-template-columns: minmax(82px, 0.24fr) 1fr minmax(48px, auto);
  gap: 0.5rem;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.65rem;
}

.source-list li {
  margin: 0.55rem 0;
}

.citation {
  font-family: var(--mono);
  font-size: 0.67em;
  vertical-align: super;
}

.prev-next a:last-child {
  text-align: right;
}

.prev-next small, .prev-next strong {
  display: block;
}

.prev-next small {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.62rem;
  text-transform: uppercase;
}

.prev-next strong {
  color: var(--head);
  font-family: var(--display);
  font-size: 1.08rem;
}

.source-index {
  display: grid;
  gap: 1rem;
}

.source-card {
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  scroll-margin-top: 74px;
}

.source-card p {
  margin: 0.45rem 0 0;
  font-size: 0.87rem;
}

.source-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.63rem;
  text-transform: uppercase;
}

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

.glossary article {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.glossary p {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

html {
  scroll-behavior: smooth;
  background: var(--paper);
}

body {
  margin: 0;
  color: var(--text);
  background: var(--paper);
  font-family: var(--reading);
  font-size: 16px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  font-optical-sizing: auto;
}

a {
  color: var(--acc);
  text-decoration-color: currentColor;
  text-underline-offset: 3px;
  text-decoration-thickness: 1.5px;
}

a:hover {
  text-decoration-color: var(--acc);
  text-decoration-thickness: 2.5px;
}

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

code {
  padding: 0.08em 0.34em;
  border: 0;
  border-radius: 3px;
  background: var(--well);
  font-size: 0.82em;
}

pre {
  overflow-x: auto;
  margin: 1rem 0;
  padding: 1rem 1.15rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--well);
  color: var(--text);
  font-size: 0.76rem;
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
}

.site-nav {
  position: sticky;
  z-index: 40;
  top: 0;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(12px);
  min-height: 56px;
}

.nav-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 1rem;
  align-items: center;
  width: min(calc(100% - 32px), var(--measure-wide));
  min-height: 55px;
  margin: 0 auto;
}

.nav-home {
  overflow: hidden;
  color: var(--head);
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-toggle,
.theme-toggle {
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.map-toggle,
.nav-actions a,
.theme-toggle {
  min-width: 44px;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-align: center;
  text-decoration: none;
  display: inline-grid;
  min-height: 44px;
  place-items: center;
}

.map-toggle[aria-expanded="true"] {
  border-color: var(--acc);
  background: var(--soft);
  color: var(--acc);
}

.journey {
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  border-bottom-color: var(--line);
  scrollbar-width: none;
}

.journey::-webkit-scrollbar {
  display: none;
}

.journey-inner {
  display: flex;
  width: max-content;
  min-width: min(100%, var(--measure-wide));
  margin: 0 auto;
  padding: 0.35rem 1rem;
}

.journey a {
  position: relative;
  padding: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.04em;
  text-decoration: none;
  display: inline-grid;
  min-width: 44px;
  min-height: 44px;
  place-items: center;
}

.journey a + a::before {
  position: absolute;
  left: -1px;
  color: var(--line);
  content: "/";
}

.journey a[aria-current="page"] {
  color: var(--acc);
  font-weight: 700;
}

.page-grid {
  display: block;
}

.page {
  width: min(calc(100% - 44px), var(--measure-wide));
  margin: 22px auto 60px;
  padding: 44px 52px 40px;
  position: relative;
  max-width: var(--measure-wide);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  counter-reset: section;
}

.page.wide, .index-page {
  width: min(calc(100% - 44px), var(--measure-wide));
}

.index-page::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 6px;
  background: var(--red);
  content: "";
  pointer-events: none;
}

body:not([data-page="index.html"]) .page::before {
  position: absolute;
  top: 44px;
  bottom: 40px;
  left: 24px;
  width: 1px;
  background: repeating-linear-gradient(var(--line) 0 6px, transparent 6px 12px);
  content: "";
  pointer-events: none;
}

.page > .eyebrow,
.page > h1,
.page > .lede,
.page > .origin-note,
.page > .hero-meta,
.page > section > :not(.sequence):not(.interactive):not(.table-wrap):not(.equation):not(.ledger):not(.chapter-contract),
.page > .source-notes > *,
.page > [data-source-index],
.page > [data-prev-next] {
  max-width: var(--measure-prose);
}

.page > section {
  max-width: none;
}

.page > section > .sequence,
.page > section > .interactive,
.page > section > .table-wrap,
.page > section > .equation,
.page > section > .ledger,
.page > section > .chapter-contract,
.page > .chapter-plate,
.page > .part-rule,
.page > .chapter-grid,
.page > .glossary {
  max-width: none;
}

.eyebrow {
  display: flex;
  margin: 0 0 14px;
  padding-top: 0.55rem;
  border-top: 2px solid var(--amber);
  color: var(--acc);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  gap: 10px;
  align-items: center;
  padding: 0;
  border: 0;
}

.eyebrow::before {
  width: 26px;
  height: 2px;
  flex: none;
  background: var(--acc);
  content: "";
}

h1, h2, h3, h4 {
  color: var(--head);
  font-family: var(--display);
  text-wrap: balance;
  letter-spacing: -0.01em;
}

h1, .chapter-page h1 {
  margin: 0 0 12px;
  font-size: clamp(29px, 7vw, 40px);
  font-weight: 600;
  line-height: 1.06;
}

h2 {
  margin: 42px 0 8px;
  font-size: clamp(20px, 5vw, 25px);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.14;
  scroll-margin-top: 86px;
}

section > h2 {
  counter-increment: section;
}

section > h2::before {
  display: inline;
  margin-right: 0.45rem;
  color: var(--acc);
  content: "§" counter(section);
  font-family: var(--mono);
  font-size: 0.62em;
  font-weight: 400;
  letter-spacing: 0;
}

.source-notes > h2::before,
body[data-page="glossary.html"] section > h2::before,
body[data-page="sources.html"] section > h2::before {
  content: none;
}

h3 {
  margin: 30px 0 7px;
  font-size: clamp(18px, 3vw, 21px);
  line-height: 1.2;
  font-weight: 600;
}

h4 {
  margin: 24px 0 6px;
  font-size: 1rem;
}

p, li {
  text-wrap: pretty;
}

p {
  margin: 0 0 14px;
}

.lede {
  max-width: 780px;
  margin: 0 0 8px;
  color: var(--muted2);
  font-size: 19px;
  line-height: 1.5;
}

.origin-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.2rem;
  margin: 22px 0 0;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hero-meta b {
  color: var(--acc);
  font-weight: 400;
}

.chapter-plate {
  position: relative;
  margin: 26px 0 36px;
  padding: 18px 0 18px 68px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-top-color: var(--line);
  border-bottom-color: var(--line);
}

.chapter-number {
  position: absolute;
  top: 16px;
  left: 0;
  color: var(--acc);
  font-family: var(--mono);
  font-size: 30px;
  font-weight: 400;
  line-height: 1;
}

.chapter-contract {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.chapter-contract > div {
  padding: 1rem;
  background: var(--well);
}

.contract-key {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--acc);
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.part-rule {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 1rem;
  margin: 44px 0 18px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.part-rule span {
  font-family: var(--mono);
  font-size: 0.67rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--acc);
}

.part-rule strong {
  color: var(--head);
  font-family: var(--display);
  font-size: 1.2rem;
  font-weight: 600;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.chapter-card {
  position: relative;
  min-height: 190px;
  padding: 18px 18px 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: none;
  color: var(--text);
  text-decoration: none;
  transition: border-color 150ms ease, transform 150ms ease;
}

.chapter-card:hover {
  transform: translateY(-2px);
  border-color: var(--acc);
}

.chapter-card .card-number, .chapter-card .card-arrow {
  color: var(--acc);
}

.chapter-card .card-title {
  display: block;
  margin: 0.65rem 0 0.45rem;
  color: var(--head);
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.12;
}

.mental-model, .concrete-example, .misconception, .check, .source-spotlight, .hardware-reality, .field-note {
  position: relative;
  margin: 20px 0;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--acc);
  border-radius: 0 8px 8px 0;
  background: var(--soft);
  color: var(--text);
}

.concrete-example, .hardware-reality {
  border-left-color: var(--amber);
  background: var(--well);
}

.misconception {
  border-left-color: var(--steel);
  background: var(--well);
}

.check, .source-spotlight {
  border-left-color: var(--acc);
  background: var(--soft);
}

.callout-label, .misconception .callout-label, .check .callout-label {
  color: var(--acc);
  font-size: 10px;
  letter-spacing: 0.12em;
}

.misconception .callout-label {
  color: var(--steel);
}

blockquote {
  margin: 20px 0;
  padding: 15px 18px;
  border-left: 2px solid var(--steel);
  background: var(--well);
  color: var(--muted2);
  font-size: 17px;
  font-style: italic;
  border-radius: 0 8px 8px 0;
}

.equation {
  overflow-x: auto;
  margin: 1.8rem 0;
  padding: 1.2rem;
  border-top: 2px solid var(--amber);
  border-bottom: 1px solid var(--line);
  color: var(--head);
  background: var(--well);
  font-family: var(--mono);
  font-size: clamp(0.84rem, 2vw, 1.05rem);
  text-align: center;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}

.ledger, .table-wrap {
  border-radius: 8px;
  background: var(--panel);
}

.ledger-key {
  border-right: 1px solid var(--line);
  color: var(--acc);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  min-width: 420px;
  font-variant-numeric: tabular-nums;
}

th {
  color: var(--muted2);
  background: var(--well);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

td:first-child {
  color: var(--acc);
  font-family: var(--mono);
}

.sequence, .interactive {
  border-radius: 8px;
  background: var(--panel);
  box-shadow: none;
}

.sequence-title, .interactive-title {
  color: var(--head);
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 600;
}

.sequence-actor {
  min-width: 130px;
  padding: 0.72rem;
  border: 1px solid var(--line);
  border-top: 4px solid var(--actor-color);
  border-radius: 8px;
  background: var(--well);
  text-align: center;
}

.sequence-track {
  min-height: 118px;
  padding: 1rem;
  border: 1px dashed var(--steel);
  border-radius: 8px;
  background: var(--well);
  border-color: var(--line);
}

.sequence-controls button, .interactive button {
  padding: 0.5rem 0.78rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--head);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.68rem;
  min-width: 44px;
  min-height: 44px;
}

.sequence-controls .primary, .interactive button.primary {
  border-color: var(--acc);
  background: var(--acc);
  color: white;
}

.interactive {
  margin: 2.2rem 0;
  padding: 1.1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--well);
  box-shadow: var(--shadow);
}

.control input, .control select {
  width: 100%;
  padding: 0.58rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  min-height: 44px;
  font-size: 16px;
}

.interactive-output, .metric {
  border-radius: 8px;
  background: var(--panel);
}

.bar-track {
  overflow: hidden;
  height: 12px;
  border-radius: 99px;
  background: var(--panel);
}

.bar-fill {
  height: 100%;
  width: var(--bar-size);
  border-radius: inherit;
  background: var(--bar-color, var(--acc));
}

.source-notes {
  margin-top: 44px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.source-notes h2 {
  margin-top: 0;
  font-size: 1.35rem;
}

.source-list {
  padding-left: 0;
  color: var(--muted);
  font-size: 0.84rem;
  list-style: none;
}

.source-list li, .page section > ul > li, .page section > ol > li {
  position: relative;
  margin-bottom: 8px;
  padding-left: 22px;
}

.source-list li::before, .page section > ul > li::before {
  position: absolute;
  top: 0.7em;
  left: 4px;
  width: 2px;
  height: 11px;
  background: var(--acc);
  content: "";
}

.source-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.08rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--acc);
  font-family: var(--mono);
  font-size: 0.57rem;
  text-transform: uppercase;
}

.prev-next {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 38px;
}

.prev-next a {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--well);
  text-decoration: none;
  min-height: 72px;
}

.site-footer {
  width: min(calc(100% - 44px), var(--measure-wide));
  margin: 0 auto;
  padding: 18px 0 36px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.source-card, .glossary article {
  border-radius: 8px;
  background: var(--panel);
}

.source-card h3 {
  margin: 0;
  font-size: 1.1rem;
}

.glossary h2 {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--acc);
}

.toc-rail {
  display: none;
}

.toc-heading {
  margin: 0 0 10px 13px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.toc-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 6px 0 6px 13px;
  border-left: 2px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.32;
  text-decoration: none;
}

.toc-link:hover, .toc-link.active {
  border-left-color: var(--acc);
  color: var(--acc);
}

.toc-link.active {
  font-weight: 600;
}

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

}

@media (min-width: 1200px) {
  .page-grid {
    display: grid;
    grid-template-columns:
      minmax(16px, 1fr)
      minmax(0, var(--measure-wide))
      clamp(28px, 3vw, 44px)
      minmax(184px, var(--toc-col))
      minmax(16px, 1fr);
    align-items: start;
  }

  .page-grid > .page {
    grid-column: 2;
    width: 100%;
    margin-right: 0;
    margin-left: 0;
  }

  .toc-rail {
    position: sticky;
    top: 80px;
    display: block;
    grid-column: 4;
    margin-top: 34px;
    padding-bottom: 24px;
  }

}

@media (max-width: 720px) {
  .nav-inner {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  .page,
  .page.wide,
  .index-page {
    width: min(calc(100% - 28px), var(--measure-wide));
    padding: 34px 22px;
  }

  body:not([data-page="index.html"]) .page::before {
    top: 34px;
    bottom: 34px;
    left: 11px;
  }

  .chapter-grid,
  .chapter-contract,
  .interactive-grid,
  .glossary {
    grid-template-columns: 1fr;
  }

  .chapter-plate {
    padding-left: 52px;
  }

  .ledger-row {
    grid-template-columns: 1fr;
  }

  .ledger-key {
    padding-bottom: 3px;
    border-right: 0;
  }

  .ledger-value {
    padding-top: 3px;
  }

  .sequence-message,
  .prev-next {
    grid-template-columns: 1fr;
  }

  .prev-next a:last-child {
    text-align: left;
  }

}

@media (max-width: 480px) {
  body {
    background: var(--panel);
  }

  .nav-inner {
    width: calc(100% - 16px);
    gap: 8px;
  }

  .nav-home {
    font-size: 0.92rem;
  }

  .page,
  .page.wide,
  .index-page {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 26px 18px 40px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  body:not([data-page="index.html"]) .page::before {
    top: 26px;
    bottom: 40px;
    left: 8px;
  }

  .part-rule {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .sequence,
  .interactive {
    padding: 12px;
  }

  .bar {
    grid-template-columns: minmax(72px, 0.32fr) 1fr;
  }

  .bar > :last-child {
    grid-column: 2;
  }

}

@media print {
  .site-nav,
  .journey,
  .toc-rail,
  .sequence-controls,
  .map-toggle,
  .theme-toggle {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .page {
    width: auto;
    max-width: none;
    padding: 0;
  }

  .chapter-card,
  .interactive,
  .sequence {
    box-shadow: none;
  }

}
