/* ============================================================
   HOP Optimisation Protocol — editorial-brutalist stylesheet
   EB Garamond + JetBrains Mono; oxblood + ink on bone
   ============================================================ */

:root {
  --bone:        #F4EFE6;
  --bone-deep:   #ECE5D7;
  --bone-mark:   #E2D9C5;
  --ink:         #1A1814;
  --ink-soft:    #3D3833;
  --ink-fade:    #7A7268;
  --oxblood:     #7C2D2D;
  --oxblood-deep:#5A1F1F;
  --ink-blue:    #2C3E5C;
  --ink-blue-soft:#5A6E8C;
  --rule:        #B8AE99;

  --serif: "EB Garamond", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --mono:  "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --display: "Major Mono Display", "JetBrains Mono", monospace;

  --measure: 36rem;
  --measure-wide: 50rem;
}

* { box-sizing: border-box; }

html {
  background: var(--bone);
  color: var(--ink);
  font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.55;
  background: var(--bone);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(184, 174, 153, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(184, 174, 153, 0.06) 0%, transparent 50%);
  background-attachment: fixed;
}

/* ============================================================
   SITE HEADER (per-page)
   ============================================================ */

.site-head {
  border-bottom: 1px solid var(--ink);
  background: var(--bone);
  padding: 1.6rem 0 0.8rem;
}

.site-head::before {
  content: "";
  display: block;
  height: 4px;
  background: var(--ink);
  margin-bottom: 1.4rem;
}

.site-head .wrap {
  max-width: 100rem;
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.site-title {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-variant: small-caps;
  letter-spacing: 0.1em;
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
}

.site-title b {
  color: var(--oxblood);
  font-weight: 800;
}

.breadcrumb {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-fade);
  margin: 0;
}

.breadcrumb a {
  color: var(--ink-fade);
  text-decoration: none;
  transition: color 0.15s;
}

.breadcrumb a:hover { color: var(--oxblood); }
.breadcrumb .sep { margin: 0 0.5rem; color: var(--rule); }

/* ============================================================
   LAYOUT: TOC sidebar + main column
   ============================================================ */

.layout {
  display: grid;
  grid-template-columns: minmax(15rem, 18rem) minmax(0, 1fr);
  gap: 2rem;
  max-width: 100rem;
  margin: 0 auto;
  padding: 0 2rem;
  position: relative;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 0 1.5rem;
  }
}

/* ============================================================
   TOC SIDEBAR
   ============================================================ */

.toc-sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100vh;
  overflow-y: auto;
  padding: 3rem 1rem 3rem 0;
  border-right: 1px solid var(--rule);
  background: linear-gradient(to right, var(--bone) 0%, var(--bone) 95%, transparent 100%);
}

@media (max-width: 1100px) {
  .toc-sidebar {
    position: relative;
    top: auto;
    max-height: none;
    padding: 1rem 0;
    border-right: none;
    border-bottom: 1px solid var(--rule);
    margin: 1rem 0;
    background: var(--bone-deep);
  }
}

.toc-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
}

.toc-title {
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
  font-variant: small-caps;
  letter-spacing: 0.08em;
}

.toc-version {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--ink-fade);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-top: 0.3rem;
}

.toc-list, .toc-sublist {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-section { margin-bottom: 0.7rem; }

.toc-link {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  text-decoration: none;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
  padding: 0.2rem 0;
  transition: color 0.15s;
}

.toc-link:hover, .toc-link.current { color: var(--oxblood); }
.toc-link.current { font-weight: 700; }
.toc-link.current::before {
  content: "▸";
  position: absolute;
  margin-left: -1.2rem;
  color: var(--oxblood);
  font-size: 0.8rem;
}

.toc-num {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--ink-fade);
  flex-shrink: 0;
  min-width: 1.8rem;
}

.toc-link.current .toc-num { color: var(--oxblood); font-weight: 700; }

.toc-divider {
  margin: 1.4rem 0 0.8rem;
  padding-top: 1rem;
  border-top: 1px solid var(--bone-mark);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-fade);
}

/* ============================================================
   DOCUMENT BODY
   ============================================================ */

.document-body {
  max-width: 100%;
  padding: 3rem 0 4rem;
}

.section {
  margin-bottom: 4rem;
}

.section-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--ink);
}

.section-num-display {
  font-family: var(--display);
  font-size: 0.85rem;
  letter-spacing: 0.15em;
  color: var(--oxblood);
  margin-bottom: 0.5rem;
  text-transform: lowercase;
}

.section-title {
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0;
}

.section-body {
  max-width: var(--measure);
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.7;
}

.section-body h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 3rem 0 1rem;
  scroll-margin-top: 1rem;
}

.section-body h2::before {
  content: "";
  display: block;
  width: 3rem;
  height: 2px;
  background: var(--oxblood);
  margin-bottom: 0.8rem;
}

.section-body h3 {
  font-family: var(--serif);
  font-size: 1.18rem;
  font-weight: 700;
  font-style: italic;
  line-height: 1.3;
  margin: 2.2rem 0 0.7rem;
}

.section-body h4 {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 700;
  margin: 1.6rem 0 0.6rem;
  color: var(--ink-soft);
}

.section-body p {
  margin: 0 0 1.1em;
}

.section-body a {
  color: var(--ink-blue);
  text-decoration: underline;
  text-decoration-color: var(--ink-blue-soft);
  text-underline-offset: 2px;
  transition: color 0.15s;
}

.section-body a:hover {
  color: var(--oxblood);
  text-decoration-color: var(--oxblood);
}

.section-body a.xref {
  color: var(--oxblood);
  text-decoration: none;
  border-bottom: 1px dotted var(--oxblood);
  white-space: nowrap;
}

.section-body a.xref:hover {
  background: var(--oxblood);
  color: var(--bone);
  border-bottom-color: transparent;
}

.section-body strong { font-weight: 700; }
.section-body em { font-style: italic; }

.section-body ul, .section-body ol {
  margin: 1em 0 1.4em;
  padding-left: 1.5rem;
}

.section-body li {
  margin-bottom: 0.5em;
  line-height: 1.55;
}

.section-body ul li::marker { color: var(--oxblood); }
.section-body ol li::marker {
  color: var(--oxblood);
  font-family: var(--mono);
  font-size: 0.85em;
}

.section-body blockquote {
  margin: 1.8em 0;
  padding: 0.2em 0 0.2em 1.5rem;
  border-left: 3px solid var(--oxblood);
  font-style: italic;
  color: var(--ink-soft);
  font-size: 1.05rem;
  line-height: 1.5;
}

.section-body blockquote p { margin: 0.6em 0; }

.section-body code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bone-mark);
  padding: 0.1em 0.35em;
  border-radius: 2px;
}

.section-body pre {
  background: var(--ink);
  color: var(--bone);
  padding: 1.4rem 1.6rem;
  margin: 1.6em 0;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.5;
  border-left: 4px solid var(--oxblood);
}

.section-body pre code {
  background: transparent;
  color: var(--bone);
  padding: 0;
  font-size: inherit;
}

.section-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.8em 0;
  font-size: 0.92rem;
}

.section-body th, .section-body td {
  text-align: left;
  padding: 0.6em 0.8em;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
  line-height: 1.5;
}

.section-body th {
  font-weight: 700;
  font-variant: small-caps;
  letter-spacing: 0.05em;
  font-size: 0.85rem;
  border-bottom: 2px solid var(--ink);
}

.section-body hr {
  border: none;
  height: 1px;
  background: var(--rule);
  margin: 2.5em 0;
}

/* ============================================================
   CHAPTER NAV (prev/next bottom-of-page)
   ============================================================ */

.chapter-nav {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
  font-family: var(--serif);
}

.chapter-nav a {
  flex: 1;
  text-decoration: none;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.8rem 0;
  transition: color 0.15s;
}

.chapter-nav a:hover { color: var(--oxblood); }

.chapter-nav .next { text-align: right; }

.chapter-nav .dir {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-fade);
}

.chapter-nav .ttl {
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
  font-style: italic;
}

/* ============================================================
   LANDING PAGE FRONTISPIECE
   ============================================================ */

.frontispiece {
  border-bottom: 1px solid var(--ink);
  padding: 4rem 2rem 3rem;
}

.frontispiece-inner {
  max-width: 64rem;
  margin: 0 auto;
}

.frontispiece-meta {
  display: flex;
  gap: 2.5rem;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-fade);
  margin-bottom: 2.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
}

.frontispiece-meta .meta-line { display: flex; gap: 0.6rem; align-items: baseline; }
.frontispiece-meta .meta-value { color: var(--ink); font-weight: 500; }

.frontispiece-title {
  font-family: var(--serif);
  font-weight: 800;
  font-size: clamp(3rem, 9vw, 6.5rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
  margin: 0 0 1.5rem;
}

.title-main { display: block; }
.title-cont {
  display: block;
  font-style: italic;
  font-weight: 500;
  color: var(--oxblood);
  margin-top: 0.2em;
}

.frontispiece-subtitle {
  font-family: var(--serif);
  font-size: clamp(1.1rem, 2.2vw, 1.5rem);
  line-height: 1.35;
  color: var(--ink-soft);
  font-style: italic;
  max-width: 36rem;
  margin: 0 0 2.5rem;
}

.frontispiece-authors {
  font-variant: small-caps;
  letter-spacing: 0.15em;
  margin-bottom: 2.5rem;
}

.author { font-weight: 600; }
.author-sep { color: var(--oxblood); margin: 0 0.8em; font-weight: bold; }

.frontispiece-epigraph {
  border-left: 2px solid var(--oxblood);
  padding-left: 1.5rem;
  margin: 2.5rem 0;
  max-width: 32rem;
  font-style: italic;
  font-size: 1.1rem;
  color: var(--ink-soft);
}

.frontispiece-epigraph p { margin: 0.4em 0; }

.epigraph-cite {
  font-style: normal;
  font-size: 0.85rem;
  color: var(--ink-fade);
  font-variant: small-caps;
  letter-spacing: 0.05em;
}

/* ============================================================
   LANDING TOC
   ============================================================ */

.landing-toc {
  max-width: 64rem;
  margin: 0 auto;
  padding: 3rem 2rem 5rem;
}

.landing-toc h2 {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 1.5rem;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 0.5rem;
}

.landing-toc h2:not(:first-of-type) { margin-top: 3rem; }

.landing-toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
}

.landing-toc li {
  border-bottom: 1px solid var(--bone-mark);
  padding: 0.8rem 0;
}

.landing-toc a {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  text-decoration: none;
  color: var(--ink);
  transition: color 0.15s;
}

.landing-toc a:hover { color: var(--oxblood); }

.landing-toc .toc-num {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--ink-fade);
  min-width: 3rem;
  flex-shrink: 0;
}

.landing-toc .toc-title-text {
  font-family: var(--serif);
  font-size: 1.1rem;
  font-weight: 600;
}

.landing-toc .toc-desc {
  display: block;
  font-family: var(--serif);
  font-size: 0.9rem;
  font-style: italic;
  color: var(--ink-fade);
  margin-top: 0.2rem;
}

/* ============================================================
   FOOTER
   ============================================================ */

.site-foot {
  margin-top: 4rem;
  padding: 2rem;
  text-align: center;
  font-family: var(--serif);
  color: var(--ink-fade);
  border-top: 1px solid var(--rule);
}

.site-foot .wrap {
  max-width: 64rem;
  margin: 0 auto;
}

.footer-note {
  font-style: italic;
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0 0 1em;
}

.footer-meta {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.footer-meta span { margin: 0 0.4rem; }

/* ============================================================
   ACCESSIBILITY
   ============================================================ */

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation: none !important; transition: none !important; }
}

/* ============================================================
   MOBILE / NARROW VIEWPORTS
   Desktop layout above is unchanged. Two problems killed mobile:
   (1) the grid collapsed to one column but kept source order, so
       every page opened with the whole table of contents before
       any content — a wall of pale bone-on-bone links.
   (2) the fixed multi-stop background gradient janks and washes
       out on iOS Safari, and long hashes/URLs forced horizontal
       zoom-out that shrank everything to grey mush.
   ============================================================ */

@media (max-width: 1100px) {
  /* flatten the fixed gradient; pin background to scroll */
  body {
    background-image: none;
    background-attachment: scroll;
  }

  /* lead with the document; drop the TOC to the foot of the page */
  .layout {
    display: flex;
    flex-direction: column;
    gap: 0;
  }
  .document-body { order: -1; padding-top: 1.5rem; }
  .toc-sidebar { order: 1; }

  /* long content-hashes / URLs must not force horizontal scroll */
  .section-body { overflow-wrap: anywhere; }
  .section-body pre { font-size: 0.78rem; padding: 1rem 1.1rem; }
  .section-body table { font-size: 0.85rem; }
}

@media (max-width: 768px) {
  body { font-size: 18px; }

  /* the TOC becomes a compact, de-emphasised foot-nav, not a wall */
  .toc-sidebar {
    margin: 3rem 0 0;
    padding: 1.4rem 0 0.5rem;
    background: transparent;
    border-top: 1px solid var(--rule);
    border-bottom: none;
  }
  .toc-list { columns: 2; column-gap: 1.2rem; }
  .toc-section { break-inside: avoid; margin-bottom: 0.45rem; }
  .toc-link { font-size: 0.85rem; }
  .toc-divider { column-span: all; }

  .section-body { font-size: 1.08rem; }
  .section-title { font-size: clamp(1.8rem, 8vw, 2.4rem); }
  .frontispiece { padding: 2.5rem 1.25rem 2rem; }
  .landing-toc { padding: 2rem 1.25rem 3.5rem; }
  .chapter-nav { flex-direction: column; gap: 0.6rem; }
  .chapter-nav .next { text-align: left; }
}
