/* APOAPSIS: a drafting table at night.
   Chart navy paper, precise printed grid inside the plates, chalk drawn on top. */

:root {
  --navy: #131c30;
  --plate: #151f36;
  --plate-edge: #2b3a5e;
  --grid: #25334f;
  --chalk: #e6ecf4;
  --chalk-dim: rgba(230, 236, 244, 0.66);
  --chalk-faint: rgba(230, 236, 244, 0.38);
  --orange: #f0662e;
  --orange-dim: rgba(240, 102, 46, 0.55);
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --mono: "Space Mono", "SFMono-Regular", Menlo, monospace;
  --ease-drift: cubic-bezier(0.16, 0.84, 0.28, 0.99);
  --ease-settle: cubic-bezier(0.34, 1.42, 0.52, 0.98);
  --ease-draft: cubic-bezier(0.65, 0.02, 0.18, 0.99);
  --wrap: 1160px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: auto; }
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

body {
  background: var(--navy);
  color: var(--chalk);
  font-family: var(--serif);
  font-size: 1.22rem;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection { background: var(--orange); color: var(--navy); }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 clamp(18px, 4vw, 48px); }

a { color: var(--chalk); text-decoration-color: var(--orange-dim); text-decoration-thickness: 1px; text-underline-offset: 3px; transition: text-decoration-color 240ms var(--ease-drift), text-underline-offset 240ms var(--ease-drift); }
a:hover { text-decoration-color: var(--orange); text-underline-offset: 5px; }
a:focus-visible, button:focus-visible, input:focus-visible { outline: 2px dashed var(--orange); outline-offset: 3px; }

.skip {
  position: absolute; left: 18px; top: -60px; z-index: 40;
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase;
  background: var(--navy); border: 1px solid var(--chalk-dim); padding: 10px 16px;
  transition: top 220ms var(--ease-drift);
}
.skip:focus { top: 14px; }

/* ---------- type ---------- */

h1 {
  font-weight: 400;
  font-size: clamp(3rem, 8.5vw, 6.4rem);
  line-height: 0.98;
  letter-spacing: -0.012em;
  text-wrap: balance;
  margin: 0.18em 0 0.22em;
}
h2 {
  font-weight: 400;
  font-size: clamp(2.1rem, 4.6vw, 3.4rem);
  line-height: 1.04;
  text-wrap: balance;
  margin: 0.25em 0 0.4em;
}
.dek {
  font-style: italic;
  font-size: clamp(1.28rem, 2.2vw, 1.6rem);
  line-height: 1.45;
  color: var(--chalk-dim);
  max-width: 32ch;
  text-wrap: pretty;
}
.kicker, .log-tag, .contents-head, .colophon-head, .proc-head, .handling-head {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--chalk-dim);
}
.log-tag { color: var(--orange); letter-spacing: 0.18em; }
.log-tag::before { content: ""; display: inline-block; width: 26px; height: 1px; background: var(--orange-dim); vertical-align: middle; margin-right: 12px; }

.prose { max-width: 66ch; }
.prose p { text-wrap: pretty; margin-bottom: 1.1em; }
.prose p:last-child { margin-bottom: 0; }
.prose em { font-style: italic; }

.debrief {
  max-width: 52ch;
  font-style: italic;
  font-size: 1.28rem;
  color: var(--chalk-dim);
  border-left: 1px solid var(--grid);
  padding-left: 22px;
  margin-top: clamp(28px, 4vw, 44px);
  text-wrap: pretty;
}

.exercise {
  font-family: var(--mono);
  font-size: 0.86rem;
  line-height: 1.75;
  color: var(--chalk-dim);
  max-width: 62ch;
  margin: clamp(22px, 3vw, 34px) 0;
  padding: 16px 20px;
  border: 1px solid var(--grid);
  border-left: 3px solid var(--orange);
  text-wrap: pretty;
}
.exercise strong { color: var(--chalk); font-weight: 700; }
.exercise-center { margin-left: auto; margin-right: auto; }

.marginalia {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.8;
  color: var(--chalk-dim);
  border-left: 1px solid var(--grid);
  padding-left: 18px;
  max-width: 40ch;
  margin: 26px 0;
}
.marginalia p { margin-bottom: 0.9em; text-wrap: pretty; }
.marginalia p:last-child { margin-bottom: 0; }

/* ---------- masthead ---------- */

.masthead { padding: clamp(20px, 3vw, 36px) 0 clamp(40px, 6vw, 84px); }

.topline {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--chalk-dim);
  border-bottom: 1px solid var(--grid);
  padding-bottom: 14px;
  margin-bottom: clamp(36px, 6vw, 72px);
}
.topline span:first-child { color: var(--chalk); }

.mast-grid {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: clamp(28px, 5vw, 72px);
  align-items: start;
}
.mast-side { display: flex; flex-direction: column; align-items: center; gap: 26px; padding-top: 10px; }

.seal { width: clamp(120px, 14vw, 170px); color: var(--chalk-dim); }
.seal-text { font-family: var(--mono); font-size: 8.8px; letter-spacing: 0.3em; fill: var(--chalk-dim); text-transform: uppercase; }
.fig-mini { width: min(320px, 100%); }

.handling { margin-top: clamp(26px, 3.4vw, 44px); max-width: 46ch; }
.handling-head { margin-bottom: 10px; }
.handling ul { list-style: none; }
.handling li {
  font-family: var(--mono); font-size: 0.8rem; line-height: 1.7; color: var(--chalk-dim);
  padding: 9px 0 9px 24px; position: relative; text-wrap: pretty;
  border-top: 1px solid var(--grid);
}
.handling li::before { content: "\2192"; position: absolute; left: 2px; color: var(--orange); }

/* ---------- plates (the instruments) ---------- */

.plate {
  position: relative;
  background: var(--plate);
  border: 1px solid var(--plate-edge);
  box-shadow: 0 24px 60px -38px rgba(0, 0, 0, 0.9);
}
.plate::after {
  content: ""; position: absolute; inset: 6px; pointer-events: none;
  background:
    linear-gradient(var(--chalk), var(--chalk)) left 0 top 0 / 14px 1px,
    linear-gradient(var(--chalk), var(--chalk)) left 0 top 0 / 1px 14px,
    linear-gradient(var(--chalk), var(--chalk)) right 0 top 0 / 14px 1px,
    linear-gradient(var(--chalk), var(--chalk)) right 0 top 0 / 1px 14px,
    linear-gradient(var(--chalk), var(--chalk)) left 0 bottom 0 / 14px 1px,
    linear-gradient(var(--chalk), var(--chalk)) left 0 bottom 0 / 1px 14px,
    linear-gradient(var(--chalk), var(--chalk)) right 0 bottom 0 / 14px 1px,
    linear-gradient(var(--chalk), var(--chalk)) right 0 bottom 0 / 1px 14px;
  background-repeat: no-repeat;
  opacity: 0.4;
}
.plate canvas { display: block; width: 100%; touch-action: none; cursor: crosshair; }

#cv-hero { aspect-ratio: 1 / 0.94; }
#cv1 { aspect-ratio: 16 / 10.4; }
#cv2 { aspect-ratio: 1 / 1.02; }
#cv3 { aspect-ratio: 4 / 3.15; }
#cv4 { aspect-ratio: 1 / 0.92; }
#cv5 { aspect-ratio: 4 / 3.05; }

.fig-tag {
  position: absolute; top: 14px; left: 16px; z-index: 3;
  font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--chalk-dim);
}

.plate-mini { width: min(320px, 100%); }
.mini-caption {
  font-family: var(--mono); font-size: 0.72rem; line-height: 1.7; letter-spacing: 0.04em;
  color: var(--chalk-dim); padding: 12px 4px 0; text-align: center; text-wrap: balance;
}

.figure { margin: clamp(26px, 4vw, 46px) 0 0; }
.figure figcaption, .figcaption-solo figcaption {
  font-style: italic; font-size: 1.02rem; line-height: 1.6; color: var(--chalk-dim);
  max-width: 72ch; margin: 18px auto 0; text-align: center; text-wrap: pretty;
}
.figcaption-solo { margin: 20px 0 0; }
.figure-boxed { max-width: 880px; margin-left: auto; margin-right: auto; }

/* ---------- handles ---------- */

.handle {
  position: absolute; top: 0; left: 0; z-index: 5;
  width: 44px; height: 44px;
  background: transparent; border: none; border-radius: 50%;
  cursor: grab; touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.handle.dragging { cursor: grabbing; }
.handle:focus-visible { outline: 2px dashed var(--orange); outline-offset: -4px; }

/* ---------- panels: readouts + buttons ---------- */

.panel { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 18px 34px; align-items: flex-start; justify-content: space-between; }
.panel-center { justify-content: center; flex-direction: column; align-items: center; }

.data { display: flex; flex-wrap: wrap; gap: 14px 34px; }
.data > div { min-width: 120px; }
.data dt {
  font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--chalk-faint); margin-bottom: 4px;
}
.data dd {
  font-family: var(--mono); font-size: 0.95rem; color: var(--chalk);
  font-variant-numeric: tabular-nums;
}
.data dd.hot { color: var(--orange); }
.data-stack { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 22px; margin: 24px 0; }

.btnrow { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btngroup { display: flex; gap: 0; }
.btngroup .btn { border-right-width: 0; }
.btngroup .btn:last-child { border-right-width: 1px; }

.btn {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--chalk); background: transparent;
  border: 1px solid rgba(230, 236, 244, 0.32);
  padding: 11px 16px; cursor: pointer;
  transition: border-color 220ms var(--ease-drift), color 220ms var(--ease-drift), background-color 220ms var(--ease-drift);
}
.btn:hover { border-color: var(--orange); color: var(--orange); }
.btn:active { background-color: rgba(240, 102, 46, 0.12); }
.btn[aria-pressed="true"] { background: var(--chalk); color: var(--navy); border-color: var(--chalk); }
.btn[aria-pressed="true"]:hover { border-color: var(--chalk); }
.btn-quiet { border-style: dashed; color: var(--chalk-dim); }
.btn-quiet:hover { color: var(--orange); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ---------- stamps ---------- */

.stamp {
  position: absolute; right: 7%; top: 10%; z-index: 6;
  display: none; flex-direction: column; align-items: center; gap: 2px;
  padding: 14px 22px 12px;
  border: 3px double var(--orange);
  color: var(--orange);
  font-family: var(--mono); text-transform: uppercase;
  font-size: 1.02rem; letter-spacing: 0.2em; font-weight: 700;
  transform: rotate(-6deg);
  background: rgba(19, 28, 48, 0.55);
  pointer-events: none;
}
.stamp .stamp-sub { font-size: 0.62rem; font-weight: 400; letter-spacing: 0.3em; opacity: 0.85; }
.stamp.on { display: flex; animation: stamp-in 380ms var(--ease-settle) both; }
@keyframes stamp-in {
  0% { transform: rotate(-6deg) scale(1.7); opacity: 0; }
  62% { transform: rotate(-6deg) scale(0.94); opacity: 1; }
  100% { transform: rotate(-6deg) scale(1); opacity: 1; }
}

/* ---------- contents ---------- */

.contents { padding: clamp(20px, 3vw, 40px) 0; border-top: 1px solid var(--grid); border-bottom: 1px solid var(--grid); }
.contents-head { margin-bottom: 18px; }
.contents ol { list-style: none; }
.contents li { border-top: 1px solid var(--grid); }
.contents li:last-child { border-bottom: 1px solid var(--grid); }
.contents a {
  display: grid; grid-template-columns: 64px minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 18px; align-items: baseline;
  padding: 13px 6px; text-decoration: none;
  transition: padding-left 260ms var(--ease-drift), background-color 260ms var(--ease-drift);
}
.contents a:hover { padding-left: 18px; background-color: rgba(37, 51, 79, 0.25); }
.toc-no { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.2em; color: var(--orange); }
.toc-name { font-size: 1.35rem; }
.toc-note { font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.06em; color: var(--chalk-dim); text-align: right; }

/* ---------- sections ---------- */

.manifesto { padding: clamp(48px, 8vw, 110px) 0 clamp(24px, 4vw, 60px); }
.manifesto .log-tag { margin-bottom: 18px; }

.chapter { padding: clamp(64px, 10vw, 150px) 0 0; }
.ch-head { margin-bottom: clamp(18px, 2.6vw, 30px); }
.ch-head-center { text-align: center; }
.ch-head-center .log-tag::before { display: none; }
.prose-center { margin-left: auto; margin-right: auto; text-align: left; }

/* ch2: rail left, tall plate right */
.ch2-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: clamp(28px, 4.5vw, 64px); align-items: start; }
.ch2-fig { margin-top: 0; position: sticky; top: 24px; }

/* ch4: rail left, tall plate right (ch5 next door runs the mirror) */
.ch4-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: clamp(24px, 4vw, 56px); align-items: start; }
.ch4-fig { margin-top: 0; order: 2; }
.ch4-rail { order: 1; }
.attempt-log { list-style: none; }
.attempt-log li { padding: 6px 0; border-top: 1px dashed var(--grid); }
.attempt-log li:first-child { border-top: none; }
.attempt-log:empty::after { content: "no attempts yet"; color: var(--chalk-faint); }

.scrubrow { display: flex; gap: 16px; align-items: center; margin-top: 16px; }
.scrub-label { font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--chalk-dim); }
input[type="range"] {
  flex: 1; appearance: none; -webkit-appearance: none; height: 34px; background: transparent; cursor: ew-resize; min-width: 120px;
}
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: repeating-linear-gradient(90deg, var(--chalk-faint) 0 7px, transparent 7px 12px); }
input[type="range"]::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 18px; height: 18px; margin-top: -8px;
  background: var(--orange); border: none;
  transform: rotate(45deg);
  transition: transform 200ms var(--ease-settle);
}
input[type="range"]:active::-webkit-slider-thumb { transform: rotate(45deg) scale(1.25); }
input[type="range"]::-moz-range-track { height: 2px; background: rgba(230, 236, 244, 0.3); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; background: var(--orange); border: none; border-radius: 0; transform: rotate(45deg); }

/* ch5: plate left, procedure right */
.ch5-grid { display: grid; grid-template-columns: minmax(0, 8fr) minmax(0, 4fr); gap: clamp(24px, 4vw, 56px); align-items: start; margin-top: clamp(24px, 3.5vw, 40px); }
.ch5-fig { margin-top: 0; }
.ch5-rail { border: 1px solid var(--grid); padding: 22px 22px 26px; }
.proc-head { margin-bottom: 14px; }
.proc { list-style: none; counter-reset: step; }
.proc li {
  font-family: var(--mono); font-size: 0.78rem; line-height: 1.65; color: var(--chalk-dim);
  padding: 11px 0 11px 34px; position: relative; border-top: 1px solid var(--grid); text-wrap: pretty;
}
.proc-box {
  position: absolute; left: 2px; top: 13px; width: 13px; height: 13px;
  border: 1.5px solid var(--chalk-dim);
  transition: border-color 300ms var(--ease-drift), background-color 300ms var(--ease-drift), box-shadow 300ms var(--ease-drift);
}
.proc li.done { color: var(--chalk); }
.proc li.done .proc-box { border-color: var(--orange); background:
  linear-gradient(45deg, transparent 42%, var(--orange) 42% 58%, transparent 58%),
  linear-gradient(-45deg, transparent 42%, var(--orange) 42% 58%, transparent 58%);
}
.ch5-rail .data-stack { grid-template-columns: 1fr; gap: 12px; margin: 22px 0 0; }

.closing { padding: clamp(70px, 10vw, 140px) 0 clamp(50px, 7vw, 100px); }
.closing .log-tag { margin-bottom: 18px; }

/* ---------- colophon ---------- */

.colophon { border-top: 1px solid var(--grid); padding: clamp(40px, 6vw, 80px) 0 60px; }
.colophon-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(24px, 4vw, 56px); }
.colophon-head { margin-bottom: 12px; }
.roll { font-size: 1.02rem; line-height: 1.65; color: var(--chalk-dim); text-wrap: pretty; }
.guide-link { color: var(--chalk); }
.fine { margin-top: 44px; font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--chalk-faint); }

.noscript-note { font-family: var(--mono); font-size: 0.8rem; color: var(--orange); padding-top: 20px; padding-bottom: 20px; }

/* ---------- reveal ---------- */

.js .rv { opacity: 0; transform: translateY(14px); }
.js .rv.in { opacity: 1; transform: translateY(0); transition: opacity 700ms var(--ease-drift), transform 700ms var(--ease-drift); }
@media (prefers-reduced-motion: reduce) {
  .js .rv { opacity: 1; transform: none; }
  .js .rv.in { transition: none; }
  html { scroll-behavior: auto; }
  .stamp.on { animation: none; }
  input[type="range"]::-webkit-slider-thumb { transition: none; }
}

/* ---------- guide page ---------- */

.guide-body .prose { margin-bottom: 34px; }
.listing { margin: clamp(26px, 4vw, 44px) 0; }
.listing-tag { font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--orange); margin-bottom: 10px; }
.listing pre {
  background: #0f1729; border: 1px solid var(--plate-edge);
  padding: 20px 24px; overflow-x: auto;
  font-family: var(--mono); font-size: 0.8rem; line-height: 1.7; color: var(--chalk-dim);
}
.listing code .cm { color: rgba(230, 236, 244, 0.4); font-style: italic; }
.listing code .hl { color: var(--chalk); }
.guide-note { border-left: 3px solid var(--orange); padding: 14px 20px; font-family: var(--mono); font-size: 0.82rem; line-height: 1.75; color: var(--chalk-dim); margin: 30px 0; max-width: 62ch; text-wrap: pretty; }
.pass-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 0.8rem; margin: 20px 0; }
.pass-table th, .pass-table td { text-align: left; padding: 12px 14px; border: 1px solid var(--grid); vertical-align: top; line-height: 1.6; }
.pass-table th { color: var(--chalk-faint); letter-spacing: 0.16em; text-transform: uppercase; font-size: 0.66rem; font-weight: 400; }
.pass-table td { color: var(--chalk-dim); }

/* ---------- responsive ---------- */

@media (max-width: 980px) {
  .mast-grid { grid-template-columns: 1fr; }
  .mast-side { flex-direction: row; flex-wrap: wrap; justify-content: flex-start; align-items: flex-start; }
  .ch2-grid, .ch4-grid, .ch5-grid { grid-template-columns: 1fr; }
  .ch2-fig { position: static; order: -1; }
  .ch4-fig { order: 1; }
  .ch4-rail { order: 2; }
  .colophon-grid { grid-template-columns: 1fr; }
  .contents a { grid-template-columns: 52px minmax(0, 1fr); }
  .toc-note { display: none; }
}

@media (max-width: 560px) {
  body { font-size: 1.12rem; }
  .wrap { padding: 0 16px; }
  #cv1 { aspect-ratio: 1 / 1.06; }
  #cv2 { aspect-ratio: 1 / 1.2; }
  #cv3 { aspect-ratio: 1 / 1.18; }
  #cv4 { aspect-ratio: 1 / 1.06; }
  #cv5 { aspect-ratio: 1 / 1.14; }
  .data { gap: 12px 20px; }
  .data > div { min-width: 100px; }
  .panel { flex-direction: column; }
  .scrubrow { flex-wrap: wrap; }
  .scrub-label { width: 100%; }
  .stamp { font-size: 0.8rem; padding: 10px 14px 9px; right: 5%; }
  .btn { padding: 12px 13px; font-size: 0.68rem; }
  .plate-mini { width: 100%; }
  .toc-name { font-size: 1.15rem; }
}
