/* Learn Omega — the field guide. Same warm world as the Om storybook,
   translated to a reading surface: cream paper, Source Serif 4 voice,
   terracotta accents, watercolor Om as guide. Comp C's grammar:
   artifact left · SVG leader wires · keyed notes right. */

@font-face { font-family: "Source Serif 4"; src: url("fonts/source-serif-4-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("fonts/source-serif-4-latin-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url("fonts/source-serif-4-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "Hanken Grotesk"; src: url("fonts/hanken-grotesk-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Hanken Grotesk"; src: url("fonts/hanken-grotesk-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }

:root {
  --paper: #f4efe4;
  --paper-deep: #ece4d3;
  --card: #efe9d7;
  --ink: #2e2a24;
  --ink-soft: #6b6154;
  --clay: #b0403a;
  --clay-deep: #94332e;
  --sage: #8fa382;
  --sage-wash: rgba(143, 163, 130, 0.28);
  --rule: rgba(46, 42, 36, 0.14);
  --rail-w: clamp(14.5rem, 16vw, 16.25rem); /* widest title, "Working With the Agent", fits on one line */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; }

html {
  /* fluid root: 16px through ~1440px, ~18px at 2560px, 20px at 4K —
     uses a big monitor's space without forcing the reader to zoom */
  font-size: clamp(16px, 0.2vw + 13.1px, 20px);
  scroll-behavior: smooth;
  scrollbar-color: rgba(107, 97, 84, 0.42) var(--paper);
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Source Serif 4", Georgia, serif;
  -webkit-font-smoothing: antialiased;
  background-color: var(--paper-deep);
  background-image: url("assets/plates/paper-v2.webp");
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-blend-mode: multiply;
}

::selection { background: var(--sage-wash); }
a { color: var(--clay); text-decoration-color: rgba(176,64,58,.35); text-underline-offset: 3px; }
code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.88em;
  background: rgba(46, 42, 36, 0.055);
  border: 1px solid rgba(46, 42, 36, 0.08);
  padding: 0.06em 0.32em;
  border-radius: 3px;
}

/* ---- rail ---- */

.rail {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--rail-w);
  padding: 4.5vh 0 4vh 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  border-right: 1px solid var(--rule);
  background: linear-gradient(90deg, rgba(236,228,211,.6), transparent 60%);
}

.rail-brand {
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.24em;
  line-height: 1.5;
  color: var(--clay);
  text-decoration: none;
  margin-bottom: 2.2rem;
}

.rail a {
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  font-size: 0.85rem;
  letter-spacing: 0.01em;
  line-height: 1.35;
  text-decoration: none;
  color: var(--ink-soft);
  padding: 0.42rem 0.4rem 0.42rem 0.55rem;
  display: flex;
  gap: 0.55rem;
  align-items: baseline;
  border-radius: 4px;
  transition: color .2s, background-color .2s;
}
.rail a:hover { color: var(--ink); }
.rail a.on {
  color: var(--clay);
  font-weight: 600;
  background: rgba(176, 64, 58, 0.065);
}

/* keyboard affordance */
a:focus-visible, .toc-row:focus-visible, .stone:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: 3px;
  border-radius: 4px;
}
.rail a.on .rnum { opacity: 1; }

.rnum {
  font-size: 0.7rem;
  opacity: 0.55;
  min-width: 3ch; /* VIII is the widest numeral; every title starts on one edge */
}

/* ---- page frame ---- */

body { position: relative; }
.book {
  position: static;
  margin-left: var(--rail-w);
  padding: 4.5vh 5.5vw 8vh;
  max-width: 101.25rem;
}

.chapter {
  position: relative;
  scroll-margin-top: 2vh;
  padding-top: 7.5vh;
  margin-top: 4vh;
  border-top: 1px solid var(--rule);
}
.chapter:first-of-type { margin-top: 6vh; }
.chapter .vignette { top: 4.5vh; }
.cover-page { position: relative; }

.breadcrumb {
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 1rem;
}

.vignette {
  position: absolute;
  top: -2vh;
  right: -1.5vw;
  width: clamp(11.875rem, 20vw, 20rem);
  height: auto;
  pointer-events: none;
  mix-blend-mode: multiply;
}

.ch-title {
  font-size: clamp(2.1rem, 3.4vw, 3.1rem);
  font-weight: 600;
  line-height: 1.04;
  letter-spacing: -0.015em;
  margin: 0.2em 0 0.35em;
  max-width: 18ch;
  text-wrap: balance;
}

.standfirst {
  font-style: italic;
  font-size: clamp(1.15rem, 1.55vw, 1.32rem);
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: 54ch;
  margin: 0 0 3.2rem;
}

/* ---- staff: the facing-page unit ---- */

.staff { margin: 0 auto 4.5rem; max-width: 82.5rem; content-visibility: auto; contain-intrinsic-size: auto 60vh; }
.chapter .foot, .ch-head { max-width: 82.5rem; margin-inline: auto; }
/* keep chapter-opening text clear of the absolute vignette ornament */
.chapter .ch-head { padding-right: clamp(12.5rem, 21vw, 21.25rem); }
.ch-head .standfirst { max-width: 56ch; }

.staff-title {
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  font-weight: 600;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 1.1rem;
}

.staff-grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 58fr) minmax(0, 42fr);
  column-gap: clamp(2.4rem, 4.4vw, 4.8rem);
  align-items: start;
}

/* SVG leader wires bridging the code card and the marginalia column */
.wires {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}
.wire {
  fill: none;
  stroke: rgba(176, 64, 58, 0.18);
  stroke-width: 1.1;
  stroke-dasharray: 2.5 3.5;
}
.wire-draw {
  fill: none;
  stroke: var(--clay);
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  transition:
    stroke-dashoffset 0.38s var(--ease-out),
    opacity 0.22s var(--ease-out);
}
.wire-draw.lit {
  stroke-dashoffset: 0;
  opacity: 0.92;
}
.wire-dot {
  fill: rgba(176, 64, 58, 0.36);
  transform-box: fill-box;
  transform-origin: center;
  transition:
    fill 0.26s var(--ease-out),
    transform 0.38s var(--spring);
}
.wire-dot.lit {
  fill: var(--clay);
  transform: scale(1.45);
}

/* figure — the artifact being read */

.figure {
  position: relative;
  z-index: 2;
  border-radius: 12px;
  background-clip: padding-box;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset;
}

.code-card {
  background: var(--card);
  border: 1px solid rgba(46, 42, 36, 0.09);
  padding: 1.05rem 1.15rem;
}
.code-card.diag-card {
  background: #ebe3cf;
  border-color: rgba(176, 64, 58, 0.22);
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -0.25rem 0 0.7rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
}
.code-file {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--clay-deep);
  letter-spacing: 0.03em;
}

.rows { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.93rem; line-height: 1.85; }

/* warm editorial syntax tokens — all >= 4.8:1 on both card and sage highlight */
.tk-kw { color: var(--clay-deep); font-weight: 600; }
.tk-ty { color: #221e19; font-weight: 600; }
.tk-st { color: #355840; }
.tk-nu { color: #7c4724; }
.tk-cm { color: #685e50; font-style: italic; }

.ln {
  display: flex;
  border-radius: 4px;
  align-items: flex-start;
  padding: 0.05rem 0.5rem;
  margin: 0 -0.35rem;
  transition: background-color 0.28s var(--ease-out);
}
.ln.anno { cursor: pointer; }
.ln.hl { background: var(--sage-wash); }
.ln.anno.lit { background: rgba(176, 64, 58, 0.13); }
.lntail { white-space: nowrap; }
.lnkeys {
  margin-left: 1.35ch;
  display: inline-flex; gap: 0.4em; align-items: center; vertical-align: middle;
  white-space: nowrap; /* inline after the last token: rides the wrap with the text it annotates */
  text-indent: 0; overflow-wrap: normal; /* undo the hanging-indent props .lnt would hand down */
}

/* marginalia keys — circled numeral binding a note to its line */
.key {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.7em; height: 1.7em; padding: 0 0.2em;
  border: 1.3px solid var(--clay); border-radius: 50%;
  color: var(--clay); background: var(--card);
  font-family: "Hanken Grotesk", sans-serif;
  font-size: 0.75em; font-weight: 600; line-height: 1;
  user-select: none;
  will-change: transform;
  transition:
    background-color 0.26s var(--ease-out),
    color 0.26s var(--ease-out),
    box-shadow 0.32s var(--ease-out),
    transform 0.42s var(--spring);
}
.ln.lit .key, .key.lit {
  background: var(--clay);
  color: var(--paper);
  transform: translateY(-1px) scale(1.1);
  box-shadow: 0 3px 8px -2px rgba(176, 64, 58, 0.42);
}
.lnn {
  flex: 0 0 3.4ch; /* border-box: 2ch of digits + 1.4ch gap, so 1- and 2-digit lines share one code edge */
  color: var(--ink-soft);
  opacity: .78;
  font-size: .7em;
  font-variant-numeric: tabular-nums;
  line-height: 2.5;
  user-select: none;
  padding-right: 1.4ch;
  text-align: right;
}
.lnt {
  color: #3a352c;
  white-space: break-spaces;   /* wrap instead of scrolling; trailing padding spaces take real width instead of hanging off the edge */
  overflow-wrap: anywhere;     /* a long token may split rather than overflow */
  min-width: 0;
  padding-left: calc(var(--indent, 0ch) + 2ch); /* the line's own indent, then continuations sit two steps in */
  text-indent: -2ch;
}

.table-card {
  background: var(--card);
  border: 1px solid rgba(46, 42, 36, 0.09);
  padding: 1.2rem 1.35rem;
}

.table-card table { border-collapse: collapse; width: 100%; font-size: 0.96rem; }
.table-card th {
  font-family: "Hanken Grotesk", sans-serif;
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-align: left;
  padding: 0 0.9rem 0.7rem 0;
  border-bottom: 1px solid var(--rule);
}
.table-card td {
  padding: 0.7rem 0.9rem 0.7rem 0;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  line-height: 1.55;
}
.table-card tr:last-child td { border-bottom: 0; }
.table-card td:first-child { font-weight: 600; }

.prose-card {
  background: var(--card);
  border: 1px solid rgba(46, 42, 36, 0.09);
  padding: 1.4rem 1.55rem;
  font-size: 1.03rem;
  line-height: 1.7;
}

/* notes — the guide's margin column */

.notes {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 1.8rem;
  height: 100%;
}
.note {
  position: relative;
  padding: 0.34rem 0.65rem 0.8rem 2.15rem;
  font-size: 0.97rem;
  line-height: 1.52;
  max-width: 46ch;
  border-radius: 8px;
  will-change: transform;
  transition:
    background-color 0.28s var(--ease-out),
    box-shadow 0.32s var(--ease-out),
    transform 0.38s var(--ease-out);
}
.note[data-for] { cursor: pointer; }
.note.lit {
  background: rgba(176, 64, 58, 0.065);
  box-shadow: 0 4px 14px -6px rgba(46, 42, 36, 0.14);
  transform: translateX(3px);
}
.note p { margin: 0; }
.ndot {
  position: absolute;
  left: 0.75rem; top: 0.76em;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--clay);
}
.nkey {
  position: absolute;
  left: 0.25rem; top: 0.38em;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.7em; height: 1.7em; padding: 0 0.2em;
  border: 1.3px solid var(--clay); border-radius: 50%;
  color: var(--clay); background: var(--paper);
  font-family: "Hanken Grotesk", sans-serif;
  font-size: 0.72rem; font-weight: 600; line-height: 1;
  user-select: none;
  will-change: transform;
  transition:
    background-color 0.26s var(--ease-out),
    color 0.26s var(--ease-out),
    box-shadow 0.32s var(--ease-out),
    transform 0.42s var(--spring);
}
.note.lit .nkey {
  background: var(--clay);
  color: var(--paper);
  transform: translateY(-1px) scale(1.1);
  box-shadow: 0 3px 8px -2px rgba(176, 64, 58, 0.42);
}

/* foot: prev/next stones */

.foot {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  margin-top: 3.5rem;
  padding-top: 1.8rem;
  border-top: 1px solid var(--rule);
}

.stone {
  font-family: "Hanken Grotesk", sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 0.55em 1.15em;
  border: 1px solid var(--rule);
  border-radius: 999px 60% 999px 55% / 999px 999px 60% 999px;
  transition: color .2s, border-color .2s, background-color .2s;
}
.stone:hover {
  color: var(--clay);
  border-color: rgba(176,64,58,.5);
  background: rgba(176, 64, 58, 0.045);
}

/* ---- cover ---- */

.cover-page {
  max-width: 82.5rem;
  margin-inline: auto;
}
.cover-page .breadcrumb { margin-bottom: 2.6rem; }
.cover-body { max-width: 66ch; }
.cover-page h1 {
  font-size: clamp(3rem, 6.2vw, 5.2rem);
  font-weight: 600;
  line-height: 0.98;
  letter-spacing: -0.02em;
  margin: 0 0 1.8rem;
}
.cover-page h1 em { color: var(--clay); }
.thesis { font-size: clamp(1.1rem, 1.45vw, 1.28rem); line-height: 1.65; margin: 0 0 1.35rem; max-width: 58ch; }

.toc { margin: 2.8rem 0 2rem; }
.toc-row {
  display: grid;
  grid-template-columns: 3.2ch minmax(0, 17ch) minmax(0, 1fr);
  gap: 1.1rem;
  align-items: baseline;
  padding: 0.8rem 0.45rem;
  border-top: 1px solid var(--rule);
  border-radius: 4px;
  text-decoration: none;
  color: var(--ink);
  transition: background-color .15s;
}
.toc-row:last-child { border-bottom: 1px solid var(--rule); }
.toc-row:hover { background: rgba(176, 64, 58, 0.045); }
.toc-row:hover .toc-title { color: var(--clay); }
.toc-num { font-family: "Hanken Grotesk", sans-serif; font-size: .74rem; font-weight: 600; letter-spacing: .04em; color: var(--clay); }
.toc-title { font-weight: 600; font-size: 1.05rem; transition: color .15s; }
.toc-stand { color: var(--ink-soft); font-style: italic; font-size: 0.93rem; line-height: 1.45; }

.coderef { font-size: .92rem; color: var(--ink-soft); font-style: italic; max-width: 56ch; }

.dramatis {
  margin: 6rem auto 0;
  max-width: 82.5rem;
  padding-top: 3.5rem;
  border-top: 1px solid var(--rule);
}
.dramatis figcaption { margin-bottom: 0.9rem; }
.dramatis img {
  width: 100%;
  height: auto;
  display: block;
  mix-blend-mode: multiply;
}
.dramatis .stone { display: inline-block; margin-top: 1.6rem; }

/* ---- end matter: glossary + colophon ---- */

.endmatter {
  margin: 6rem auto 0;
  max-width: 82.5rem;
  padding-top: 3.5rem;
  border-top: 1px solid var(--rule);
}
.endmatter .standfirst { max-width: 54ch; }
.gloss {
  margin: 2.2rem 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(18.75rem, 1fr));
  gap: 0;
}
.gterm {
  border-top: 1px solid var(--rule);
  padding: 0.95rem 1.5rem 1.15rem 0;
}
.gterm dt {
  font-family: "Hanken Grotesk", sans-serif;
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--clay);
  margin-bottom: 0.35rem;
}
.gterm dd {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink-soft);
}
.gterm dd code, .gloss dt code { text-transform: none; }
.colophon p {
  max-width: 58ch;
  font-size: 1.02rem;
  line-height: 1.7;
  color: var(--ink-soft);
  margin-top: 1.8rem;
}
.colophon .stone { display: inline-block; margin: 1.6rem 0 4rem; }

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

@media (max-width: 1100px) {
  .staff-grid { grid-template-columns: 1fr; }
  .wires { display: none; }
  .notes { margin-top: 1.2rem; }
  .note { max-width: 56ch; padding-left: 1.7rem; }
}

/* ---- print: the field guide survives paper ---- */

@media print {
  html { scroll-behavior: auto; }
  body { background: #f7f4ea; }
  .rail, .wires { display: none; }
  .book { margin-left: 0; padding: 0; max-width: none; }
  .chapter { padding-top: 2rem; }
  .vignette { width: 120px; }
  .staff { content-visibility: visible; contain-intrinsic-size: none; break-inside: avoid; }
  .staff-grid { grid-template-columns: 1fr; }
  .notes { margin-top: 0.8rem; }
  .note { position: static !important; top: auto !important; }
  .figure, .note { break-inside: avoid; }
  .foot { display: none; }
  a[href^="#"]::after { content: ""; }
}

@media (max-width: 900px) {
  .rail {
    position: sticky;
    top: 0;
    z-index: 20;
    width: auto;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 0.2rem;
    padding: 0.55rem 0.9rem;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    background: rgba(244, 239, 228, 0.94);
    backdrop-filter: blur(8px);
  }
  .rail::-webkit-scrollbar { display: none; }
  .rail-brand {
    margin: 0 0.5rem 0 0;
    flex: 0 0 auto;
    font-size: 0.7rem;
    line-height: 1.15;
  }
  .rail a {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    line-height: 1.25;
  }
  .rail a.on {
    background: rgba(176, 64, 58, 0.11);
  }
  .rnum { min-width: auto; }
  .book { margin-left: 0; padding: 2.5vh 5vw 8vh; }
  .chapter { scroll-margin-top: 3.4rem; padding-top: 4.5vh; }
  .vignette { position: static; float: right; width: 115px; margin: 0 0 0.8rem 1rem; }
  .chapter .ch-head { padding-right: 0; }
  .toc-row {
    grid-template-columns: 3ch minmax(0, 1fr);
    gap: 0.25rem 0.75rem;
  }
  .toc-stand { grid-column: 2; }
}

/* Phones: a code row fits ~33 characters at desktop size, so imports and state
   headers broke mid-word. Smaller mono and tighter card padding fit ~42. */
@media (max-width: 520px) {
  .rows { font-size: 0.8rem; line-height: 1.75; }
  .code-card { padding: 0.9rem 0.75rem; }
}
