@font-face {
  /* Jost -- OFL licensed, self-hosted (not loaded from a CDN) so titles and
     labels still render correctly offline. Variable font: one file covers
     the whole 500-700 weight range used below. */
  font-family: "Jost";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("../fonts/jost-variable.woff2") format("woff2");
}

:root {
  /* page chrome */
  --ink: #2b2926;
  --ink-soft: #33302c;
  --paper: #f7f5ef;
  --surface: #ffffff;
  --frame: #2b2926;
  --rule: #e4e0d7;
  --rule-lt: #ece8df;
  --display-font: "Jost", "Helvetica Neue", Arial, sans-serif;
  /* signature UI accent -- title cards / badges / index numbers only.
     Distinct from --hazard, which stays reserved for danger callouts inside diagrams. */
  --zissou-red: #c23b22;

  /* materials palette -- shared with every diagram, see style-refined.html.
     Left unchanged in dark mode: illustrations are self-contained SVGs with
     literal hex values, not wired to these variables. */
  --rock: #6b6357;
  --rock-shadow: #4f493f;
  --scree: #9c9382;
  --snow: #eef1ee;
  --ice: #b9d4dc;
  --water: #4f7e8c;
  --vegetation: #6f7d52;
  --void: #d7dee0;
  --rope: #c9a23a;
  --hazard: #b5432e;
}
[data-theme="dark"] {
  --ink: #ece6da;
  --ink-soft: #cfc7b6;
  --paper: #1c1a17;
  --surface: #272420;
  --frame: #6b6357;
  --rule: #3a3733;
  --rule-lt: #2e2b27;
  --rock: #ab9f8c;
  --water: #7fa6b2;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  line-height: 1.55;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 28px 96px; }

/* ---- persistent site nav ---- */
nav.site {
  border-bottom: 2px solid var(--frame);
  background: var(--paper);
  position: sticky; top: 0; z-index: 1002;
}
nav.site .row {
  max-width: 1080px; margin: 0 auto; padding: 0 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 64px;
}
nav.site a.brand {
  font-family: var(--display-font); font-size: 28px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--ink);
  text-decoration: none; white-space: nowrap; transition: opacity .2s ease;
}
nav.site .row:has(.nav-actions.search-active) a.brand { display: none; }
nav.site .row:has(.nav-actions.search-active) .theme-toggle,
nav.site .row:has(.nav-actions.search-active) .menu-toggle { display: none; }

.nav-actions {
  display: flex; align-items: center; gap: 2px;
  flex: 1 1 auto; justify-content: flex-end; min-width: 0;
}

.icon-btn {
  flex: none; background: none; border: none; padding: 10px; margin: 0; cursor: pointer;
  color: var(--ink); display: flex; align-items: center; transition: opacity .2s ease;
}
.icon-btn svg { width: 36px; height: 36px; display: block; }

.menu-toggle .menu-icon-top,
.menu-toggle .menu-icon-mid,
.menu-toggle .menu-icon-bottom {
  transform-box: fill-box; transform-origin: center;
  transition: transform .2s ease, opacity .2s ease;
}
.menu-toggle[aria-expanded="true"] .menu-icon-top { transform: translateY(6px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] .menu-icon-mid { opacity: 0; }
.menu-toggle[aria-expanded="true"] .menu-icon-bottom { transform: translateY(-6px) rotate(-45deg); }

.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* collapsed by default -- just the magnifying-glass icon -- until search-ui.js
   adds .search-active, which reveals the real input and hides the icon */
.search-open { display: flex; }
.nav-actions.search-active .search-open { display: none; }

.search-wrap {
  display: none; position: relative; align-items: center; gap: 8px;
  flex: 0 1 320px; min-width: 120px; max-width: 320px;
  transition: flex-basis .25s ease, max-width .25s ease;
}
.nav-actions.search-active .search-wrap { display: flex; flex: 1 1 auto; max-width: 100%; }
#search { margin: 0; position: relative; flex: 1 1 auto; min-width: 0; }

.site-menu {
  display: none; position: fixed; inset: 0; background: var(--paper);
  z-index: 1000; overflow-y: auto;
}
.site-menu.open { display: block; }
.menu-links {
  display: flex; flex-direction: column; justify-content: center;
  min-height: 100%; max-width: 1080px; margin: 0 auto; padding: 100px 28px 60px;
}
.menu-links a {
  font-family: var(--display-font); font-weight: 700; text-transform: uppercase;
  font-size: 28px; line-height: 1.25; letter-spacing: .005em;
  color: var(--ink); text-decoration: none;
  padding: 16px 0;
}
.menu-links a:first-child { padding-top: 0; }
.menu-links a:hover { color: var(--zissou-red); }

/* dims the whole page while search is active, so results read as a modal
   overlay rather than a small dropdown content bleeds through behind */
.search-wrap::before {
  content: ""; position: fixed; inset: 0; background: rgba(20, 18, 16, .55);
  z-index: 15; opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.nav-actions.search-active .search-wrap::before { opacity: 1; pointer-events: auto; }

.search-close {
  display: none; position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  z-index: 17; background: none; border: none; padding: 0; margin: 0;
  color: var(--rock); cursor: pointer;
}
.search-close svg { width: 36px; height: 36px; display: block; }
.nav-actions.search-active .search-close { display: block; }

/* ---- masthead: title-card composition, centered ---- */
header.top {
  border-bottom: 2px solid var(--frame); padding: 46px 0 32px; margin-bottom: 8px;
  text-align: center;
}
.kicker {
  font-family: var(--display-font); font-weight: 600; font-size: 12px; letter-spacing: .18em;
  text-transform: uppercase; color: #fff; background: var(--zissou-red);
  display: inline-block; padding: 6px 16px; margin: 20px 0 22px; border-radius: 2px;
  overflow-wrap: anywhere; max-width: 100%;
}
h1 {
  font-family: var(--display-font); font-weight: 700; text-transform: uppercase;
  font-size: clamp(30px, 5.4vw, 56px); line-height: 1.05; margin: 0; letter-spacing: .005em;
}
.lede { margin: 18px auto 0; max-width: 56ch; font-size: 17px; color: var(--ink-soft); }
.meta {
  font-family: var(--display-font); font-weight: 500; font-size: 12px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--rock); margin-top: 22px;
  display: flex; gap: 22px; flex-wrap: wrap; justify-content: center;
}
/* ---- table of contents, numbered like a manifest ---- */
nav.toc {
  margin: 40px 0 8px; padding: 22px 26px;
  background: var(--surface); border-radius: 4px; column-gap: 34px; column-count: 4;
  counter-reset: toc;
}
nav.toc h2 {
  font-family: var(--display-font); font-weight: 600; font-size: 11px; letter-spacing: .18em;
  text-transform: uppercase; color: var(--rock); margin: 0 0 12px; column-span: all;
  overflow-wrap: break-word;
}
nav.toc a {
  display: block; color: var(--ink); text-decoration: none; font-size: 15px; padding: 3px 0;
  break-inside: avoid; counter-increment: toc;
}
nav.toc a:before {
  content: counter(toc, decimal-leading-zero);
  font-family: var(--display-font); font-weight: 600; font-size: 11px; color: var(--zissou-red);
  margin-right: 8px;
}
nav.toc a:hover { color: var(--zissou-red); }

.section-rule {
  margin: 64px 0 24px; padding-bottom: 16px; border-bottom: 2px solid var(--frame);
}
.section-rule h2 {
  font-family: var(--display-font); font-weight: 600; font-size: 15px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--rock); margin: 0; white-space: nowrap;
}
.section-rule + .entry { border-top: none; }

.grade-table-wrap {
  margin: 0 0 40px; padding: 22px 26px; border-radius: 4px;
  background: var(--surface); overflow-x: auto;
}
.grade-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.grade-table th, .grade-table td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--rule); }
.grade-table thead th {
  font-family: var(--display-font); font-weight: 600; font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--rock);
}
.grade-table thead th a { color: inherit; text-decoration: none; }
.grade-table thead th a:hover { color: var(--zissou-red); }
.grade-table tbody td:first-child { font-weight: 600; color: var(--ink); }
.grade-table tbody tr:last-child td { border-bottom: none; }
.grade-table-note {
  margin: 14px 0 0; font-size: 13px; color: var(--rock); font-style: italic;
}

.empty-section {
  margin: 40px 0; padding: 48px 16px; text-align: center;
  border: 1px dashed var(--scree); border-radius: 4px; background: var(--rule-lt);
  font-family: var(--display-font); font-size: 13px; color: var(--rock);
}

/* ---- entries ---- */
.entry {
  display: grid; grid-template-columns: 1fr 1.15fr; gap: 30px; align-items: center;
  padding: 34px 0; border-top: 2px solid var(--frame);
}
.entry.no-fig { grid-template-columns: 1fr; }
.entry.no-fig .txt { max-width: 720px; }
.entry.is-quote .def {
  font-style: italic; font-size: 22px; line-height: 1.45; color: var(--ink);
}
.entry.is-quote .def p { position: relative; padding-left: 34px; }
.entry.is-quote .def p:before {
  content: "\201C"; position: absolute; left: 0; top: -6px;
  font-family: Georgia, serif; font-size: 46px; font-style: normal; color: var(--zissou-red);
}
.entry .term {
  font-family: var(--display-font); font-weight: 700; text-transform: uppercase;
  font-size: 26px; margin: 0 0 6px; letter-spacing: .005em; scroll-margin-top: 64px;
}
.entry .syn { font-style: italic; color: var(--rock); margin: 0 0 14px; font-size: 15px; }
.entry .syn b {
  font-style: normal; font-weight: 600; color: var(--ink-soft); letter-spacing: .02em;
  font-family: var(--display-font); font-size: 11px; text-transform: uppercase;
  display: block; margin-bottom: 2px;
}
.entry .def { margin: 0; font-size: 16.5px; color: var(--ink-soft); }
.entry .def p { margin: 0 0 14px; }
.entry .def p:last-child { margin-bottom: 0; }
.entry .def ol {
  margin: 0; padding: 0; list-style: none; counter-reset: deflist;
}
.entry .def ol li {
  counter-increment: deflist; position: relative; padding-left: 32px; margin-bottom: 18px;
}
.entry .def ol li:before {
  content: counter(deflist, decimal-leading-zero);
  position: absolute; left: 0; top: 1px;
  font-family: var(--display-font); font-weight: 600; font-size: 11px; color: var(--zissou-red);
}
.entry .def ol li b { color: var(--ink); }
.entry .cat {
  font-family: var(--display-font); font-weight: 600; font-size: 10.5px; letter-spacing: .14em;
  text-transform: uppercase; color: #fff; background: var(--zissou-red); margin: 0 0 12px;
  display: inline-flex; align-items: center; padding: 5px 12px; border-radius: 3px;
}
.fig .frame {
  position: relative; border: 2px solid transparent; background: var(--surface);
  border-radius: 4px; padding: 10px; cursor: zoom-in; transition: border-color .15s ease;
}
.fig .frame:hover { border-color: var(--zissou-red); }
.fig svg { width: 100%; height: auto; display: block; }
.fig .frame svg text { font-family: var(--display-font); }
.fig .knot-link {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 20px 22px; border-radius: 4px;
  background: var(--surface); text-decoration: none; color: var(--ink);
  border: 2px solid transparent; transition: border-color .15s ease;
}
.fig .knot-link:hover { border-color: var(--zissou-red); }
.fig .knot-link-text { display: flex; flex-direction: column; gap: 4px; }
.fig .knot-link-kicker {
  font-family: var(--display-font); font-weight: 600; font-size: 11px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--rock);
}
.fig .knot-link-name {
  font-family: var(--display-font); font-weight: 700; font-size: 20px; text-transform: uppercase;
}
.fig .knot-link-arrow { color: var(--zissou-red); font-size: 18px; flex: none; }

footer {
  margin-top: 70px; padding-top: 22px; border-top: 2px solid var(--frame);
  font-family: var(--display-font); font-size: 12px; color: var(--rock);
}
.footer-row { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 14px; }
.footer-logo {
  font-family: var(--display-font); font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink);
}
.footer-disclaimer {
  margin: 14px 0 0; font-size: 11px; color: var(--rock); max-width: 640px;
}

/* ---- home hub ---- */
.hub-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 36px 0; }
.hub-card {
  display: block; border-radius: 4px; background: var(--surface);
  padding: 22px 20px; text-decoration: none; color: var(--ink);
  border: 2px solid transparent; transition: border-color .15s ease;
}
.hub-card:hover { border-color: var(--zissou-red); }
.hub-card h3 {
  font-family: var(--display-font); font-weight: 700; text-transform: uppercase;
  margin: 0 0 6px; font-size: 17px; letter-spacing: .005em;
}
.hub-card p { margin: 0; font-size: 13.5px; color: var(--ink-soft); }
.hub-card .count {
  font-family: var(--display-font); font-weight: 600; font-size: 10.5px; letter-spacing: .14em;
  text-transform: uppercase; color: #fff; background: var(--zissou-red); margin: 0 0 10px;
  display: inline-block; padding: 4px 10px; border-radius: 3px;
}
#search { margin: 0; position: relative; }

/* ---- pagefind search: re-themed via its documented CSS custom properties
   rather than fighting its internal markup ---- */
.pagefind-ui {
  --pagefind-ui-font: var(--display-font);
  --pagefind-ui-text: var(--ink);
  --pagefind-ui-background: var(--surface);
  --pagefind-ui-border: var(--rock);
  --pagefind-ui-border-width: 0px;
  --pagefind-ui-border-radius: 4px;
  --pagefind-ui-primary: var(--zissou-red);
  --pagefind-ui-tag: var(--rock);
  position: relative; z-index: 16; width: 100%;
}
.pagefind-ui__search-input {
  font-size: 14px; height: 48px !important; padding-top: 0 !important; padding-bottom: 0 !important;
  padding-right: 90px !important; padding-left: 60px !important; outline: none !important; box-shadow: none !important;
}
.pagefind-ui__form:before {
  width: 36px !important; height: 36px !important; top: 6px !important; left: 14px !important;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") !important;
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") !important;
}
.pagefind-ui__search-input:focus { outline: none !important; box-shadow: none !important; }
.pagefind-ui__search-input::placeholder { color: var(--scree); text-transform: uppercase; }
.pagefind-ui__search-clear { right: 42px !important; }
.pagefind-ui__search-clear { font-family: var(--display-font); font-weight: 600; color: var(--rock); }
.pagefind-ui__message {
  font-family: var(--display-font); font-size: 11px; letter-spacing: .1em;
  text-transform: uppercase; color: var(--rock); padding: 6px 4px;
}
.pagefind-ui__result-title { font-family: var(--display-font); font-weight: 700; text-transform: uppercase; letter-spacing: .005em; }
.pagefind-ui__result-link { color: var(--ink); }
.pagefind-ui__result-thumb { display: none !important; }
.pagefind-ui mark { background: none !important; color: var(--zissou-red) !important; font-weight: 600; }
.pagefind-ui__result-nested .pagefind-ui__result-link:before { content: "\2022" !important; right: calc(100% + .5em) !important; }

/* the results drawer renders in normal flow by default, which would inflate
   the height of the sticky nav it lives in -- float it as a full-width
   overlay panel instead, above the dimming backdrop */
.pagefind-ui__drawer {
  position: absolute !important; top: calc(100% + 8px) !important; left: 0 !important;
  width: 100% !important; max-height: 88vh !important; overflow-y: auto !important;
  z-index: 20 !important; background: var(--surface) !important; border-radius: 4px !important;
  padding: 6px 16px !important; box-shadow: 0 14px 36px rgba(0, 0, 0, .18) !important;
}

/* ---- lightbox (used to enlarge diagrams) ---- */
#lightbox {
  position: fixed; inset: 0; background: rgba(20, 18, 16, .88); display: none;
  align-items: center; justify-content: center; z-index: 1000; cursor: zoom-out; padding: 30px;
}
#lightbox.open { display: flex; }
#lightbox svg, #lightbox img { max-width: 92vw; max-height: 84vh; }
#lightbox .lb-close { position: absolute; top: 18px; right: 24px; color: #eee; font-size: 30px; line-height: 1; cursor: pointer; }

/* ---- inline term links + quick-reference popup ---- */
.term-link {
  background: none; border: none; padding: 0; margin: 0; font: inherit; color: var(--zissou-red);
  cursor: pointer; border-bottom: 1px dotted var(--zissou-red);
}
.term-link:hover { border-bottom-style: solid; }

#term-popup {
  position: fixed; inset: 0; background: rgba(20, 18, 16, .5); display: none;
  align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
#term-popup.open { display: flex; }
.tp-card {
  position: relative; background: var(--surface); border-radius: 6px; padding: 28px 26px 24px;
  max-width: 420px; width: 100%; box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.tp-close { position: absolute; top: 10px; right: 16px; font-size: 24px; line-height: 1; color: var(--rock); cursor: pointer; }
.tp-cat {
  font-family: var(--display-font); font-weight: 600; font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--scree); margin: 0 0 6px;
}
.tp-title {
  font-family: var(--display-font); font-weight: 700; text-transform: uppercase;
  font-size: 20px; margin: 0 0 6px; letter-spacing: .005em;
}
.tp-syn { font-style: italic; color: var(--rock); font-size: 13.5px; margin: 0 0 10px; }
.tp-def { font-size: 15px; color: var(--ink-soft); margin: 0 0 16px; }
.tp-link {
  font-family: var(--display-font); font-weight: 600; font-size: 12px; color: var(--zissou-red); text-decoration: none;
}
.tp-link:hover { text-decoration: underline; }

/* ---- responsive ---- */
@media (max-width: 720px) {
  nav.toc { column-count: 1; }
  .entry { grid-template-columns: 1fr; gap: 18px; }
  .hub-grid { grid-template-columns: 1fr; }
  nav.site .row { height: auto; flex-wrap: wrap; padding: 10px 20px; }
  .menu-links { padding: 100px 20px 60px; }
}

@media print {
  body { background: #fff; }
  nav.site, #lightbox { display: none !important; }
  .entry { break-inside: avoid; page-break-inside: avoid; }
  nav.toc { break-inside: avoid; }
}
