/* ============================================================================
   handbook.css — a single-scroll book/handbook reading layout.
   Self-contained: no Bootstrap, no framework. Drop-in alongside handbook.js.

   Layout: sticky left table-of-contents + a centered reading column, with a
   "Take it with you" footer pinned below the TOC. Below 768px the TOC is hidden
   and a compact "grab card" is surfaced under the title block instead.

   All visual choices live in the custom properties below — retheme by editing
   :root, not the rules underneath it.
   ============================================================================ */

:root {
  /* Palette — cream paper, near-black ink, one teal accent. */
  --hb-bg:            #fbf9f4;
  --hb-text:          #23262b;
  --hb-muted:         #555b64;
  --hb-accent:        #0b7c72;
  --hb-accent-strong: #0a655d;
  --hb-border:        rgba(35, 38, 43, .1);
  --hb-card-bg:       #fff;

  /* Type — serif reading body, serif display headings, sans UI chrome.
     The reading column is Newsreader (serif); only the chrome (TOC, labels,
     meta, pills) is IBM Plex Sans. */
  --hb-font-body:   "Newsreader", Georgia, "Times New Roman", serif;
  --hb-font-serif:  "Fraunces", Georgia, "Times New Roman", serif;
  --hb-font-ui:     "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --hb-font-italic: "Newsreader", Georgia, serif;

  /* Measure. */
  --hb-content-width: 51rem;
  --hb-toc-width:     15rem;
  --hb-gap:           3rem;
  --hb-scroll-offset: 120px; /* must match OFFSET in handbook.js */
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--hb-bg);
  color: var(--hb-text);
  font-family: var(--hb-font-body);
  font-size: 1rem;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* --- Grid: [TOC] [reading column] [free right gutter] -------------------- */
.hb-layout {
  display: grid;
  grid-template-columns:
    [toc] var(--hb-toc-width)
    [content] minmax(0, var(--hb-content-width))
    [end] 1fr;
  column-gap: var(--hb-gap);
  max-width: 75rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* --- Sidebar: sticky, full-height, footer pinned to the bottom ----------- */
.hb-toc {
  grid-column: toc;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 2rem 0 1.25rem;
  font-family: var(--hb-font-ui); /* sans chrome over the serif reading body */
}

.hb-toc__title {
  margin: 0 0 .75rem;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--hb-muted);
}

.hb-toc__nav {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.hb-toc__nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.hb-toc__nav ul ul { padding-left: .85rem; } /* nested = sub-section indent */

.hb-toc__nav a {
  display: block;
  padding: .18rem 0 .18rem .75rem;
  margin-left: -2px;
  border-left: 2px solid transparent;
  color: var(--hb-muted);
  font-size: .9rem;
  line-height: 1.35;
  text-decoration: none;
  transition: color .12s ease, border-color .12s ease;
}
.hb-toc__nav a:hover { color: var(--hb-text); }

/* Scrollspy target — set by handbook.js as you scroll. */
.hb-toc__nav a.active {
  color: var(--hb-accent);
  font-weight: 600;
  border-left-color: var(--hb-accent);
}

/* --- Reading column ----------------------------------------------------- */
.hb-content {
  grid-column: content;
  min-width: 0;
  padding: 2.5rem 0 6rem;
}

.hb-content a { color: var(--hb-accent); }
.hb-content a:hover { color: var(--hb-accent-strong); }

/* Title block */
.hb-title-block { margin-bottom: 2.5rem; }
.hb-title-block h1 {
  margin: 0;
  font-family: var(--hb-font-serif);
  font-weight: 600;
  line-height: 1.15;
  font-size: clamp(2rem, 1.4rem + 2.4vw, 3.1rem);
}
.hb-title-block .hb-subtitle {
  margin: .4rem 0 0;
  font-family: var(--hb-font-italic);
  font-style: italic;
  font-weight: 400;
  font-size: 1.35rem;
  color: var(--hb-muted);
}
.hb-meta {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* author | modified, each half-width — matches the reference spread */
  gap: 1rem;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--hb-border);
  font-family: var(--hb-font-ui);
  color: var(--hb-muted);
}
.hb-meta__heading {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--hb-muted);
}
.hb-meta__value { margin-top: .15rem; font-size: .95rem; }

/* Body headings — chapters (h2) and sections (h3). scroll-margin keeps the
   anchor target clear of the top when deep-linked. */
.hb-content h2,
.hb-content h3,
.hb-content h4 {
  font-family: var(--hb-font-serif);
  font-weight: 600;
  line-height: 1.2;
  scroll-margin-top: var(--hb-scroll-offset);
}
.hb-content h2 {
  margin: 3rem 0 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--hb-border);
  font-size: 1.85rem;
}
.hb-content section:first-of-type > h2 { border-top: none; padding-top: 0; margin-top: 1rem; }
.hb-content h3 { margin: 2.25rem 0 .75rem; font-size: 1.35rem; }
.hb-content h4 { margin: 1.75rem 0 .5rem; font-size: 1.1rem; }

.hb-content p,
.hb-content ul,
.hb-content ol { margin: 0 0 1.1rem; }

.hb-content pre {
  background: #f4f1ea;
  border: 1px solid var(--hb-border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-size: .875rem;
}
.hb-content code {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9em;
}
.hb-content :not(pre) > code {
  background: rgba(11, 124, 114, .08);
  color: var(--hb-accent-strong);
  padding: .1em .35em;
  border-radius: 4px;
}
.hb-content blockquote {
  margin: 1.5rem 0;
  padding: .25rem 0 .25rem 1.25rem;
  border-left: 3px solid var(--hb-accent);
  color: var(--hb-muted);
  font-style: italic;
}

/* ============================================================================
   "Take it with you" — download bar + source/author links.
   Lives in .hb-toc__footer on desktop; mirrored into .hb-grab-card on mobile.
   ============================================================================ */
.hb-toc__footer {
  flex: 0 0 auto;
  margin-top: 1.4rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--hb-border);
}

.hb-dl__label,
.hb-grab-card__label {
  display: block;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--hb-muted);
  margin-bottom: .6rem;
}

.hb-dl__pills,
.hb-grab-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

/* Download pill — rounded outline that fills with the accent on hover. */
.hb-pill {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .34rem .85rem;
  font-size: .82rem;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--hb-accent-strong);
  text-decoration: none;
  border: 1px solid rgba(11, 124, 114, .35);
  border-radius: 999px;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.hb-pill::before { content: "\2193"; font-size: .9em; opacity: .7; } /* ↓ */
.hb-pill--plain::before { content: none; }
.hb-pill:hover {
  background: var(--hb-accent);
  border-color: var(--hb-accent);
  color: #fff;
}
.hb-pill:hover::before { opacity: 1; }

/* Source / author rows */
.hb-links {
  display: flex;
  flex-direction: column;
  margin-top: 1.1rem;
}
.hb-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .9rem;
  color: var(--hb-muted);
}
.hb-row + .hb-row { margin-top: .55rem; }
.hb-row__label { flex: 0 0 auto; min-width: 8rem; }

.hb-socials {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.hb-socials a {
  display: inline-block;
  width: 22px;
  height: 22px;
  line-height: 0;
  color: var(--hb-muted);
  transition: color .12s ease, transform .12s ease;
}
.hb-socials a:hover { color: var(--hb-accent); transform: translateY(-1px); }
.hb-socials svg { display: block; width: 22px; height: 22px; }

/* ============================================================================
   Mobile grab card — hidden on desktop, shown under the title below 768px.
   ============================================================================ */
.hb-grab-card { display: none; }

@media (max-width: 768px) {
  .hb-layout {
    grid-template-columns: minmax(0, 1fr);
    padding: 0 1.25rem;
  }
  .hb-toc { display: none; }
  .hb-content { grid-column: 1; padding-top: 1.75rem; }

  .hb-grab-card {
    display: block;
    margin: 1.6rem 0 2.4rem;
    padding: 1.1rem 1.15rem 1.2rem;
    border: 1px solid rgba(11, 124, 114, .28);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(11, 124, 114, .05), rgba(11, 124, 114, .02));
    font-family: var(--hb-font-ui);
  }
  .hb-grab-card__btn {
    flex: 1 1 auto;
    justify-content: center;
    min-height: 2.6rem;
    background: var(--hb-card-bg);
    border-radius: 9px;
  }
  .hb-grab-card__links {
    margin-top: .95rem;
    padding-top: .85rem;
    border-top: 1px solid rgba(11, 124, 114, .16);
  }
}

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