/* ByteBook Training Handbook - the reader.
   Warm paper, deep green, editorial headings: the same language as ByteBook
   itself, arranged for long-form reading rather than for a dashboard. */

:root {
  --paper: #faf9f3;
  --surface: #fdfcf8;
  --ink: #1f1e1a;
  --ink-soft: #3d3b36;
  --muted: #6a6760;
  --border: #e2ddd1;
  --border-light: #eae5d9;
  --green: #1a3a2a;
  --green-600: #1f5335;
  --green-500: #306d49;
  --green-50: #edf3ef;
  --gold: #c9a227;
  --gold-soft: #faf4e6;
  --error: #a23b32;
  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "IBM Plex Mono", Menlo, monospace;
  --measure: 70ch;
  --nav-width: 268px;
  --page-height: min(72vh, 720px);
  --page-gap: 64px;
}

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

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body.book {
  margin: 0;
  background: var(--paper);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--green); color: #fff; padding: 12px 18px; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

a { color: var(--green-600); text-decoration-color: rgba(31, 83, 53, 0.28); text-underline-offset: 2px; }
a:hover { color: var(--green); text-decoration-color: currentColor; }

/* ── Bar ───────────────────────────────────────────────────────────────── */
.book-bar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px;
  background: rgba(250, 249, 243, 0.94);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.book-bar-brand { display: flex; align-items: baseline; gap: 8px; text-decoration: none; margin-right: auto; }
.book-bar-name { font-family: var(--serif); font-size: 19px; font-weight: 500; color: var(--green); }
.book-bar-sub { font-size: 12.5px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.book-bar-btn {
  font: inherit; font-size: 14px; font-weight: 500;
  padding: 7px 14px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--ink-soft); cursor: pointer;
}
.book-bar-btn:hover { border-color: var(--green-500); color: var(--green); }
#contents-toggle { display: none; }
.book-bar-progress {
  position: absolute; left: 0; bottom: -1px; height: 2px; width: 0;
  background: var(--gold); transition: width 120ms linear;
}

/* ── Layout ────────────────────────────────────────────────────────────── */
.book-shell {
  display: grid; grid-template-columns: var(--nav-width) minmax(0, 1fr);
  max-width: 1180px; margin: 0 auto; padding: 0 18px;
  gap: 0;
}

.book-nav {
  position: sticky; top: 58px; align-self: start;
  max-height: calc(100vh - 58px); overflow-y: auto;
  padding: 30px 22px 60px 0;
  border-right: 1px solid var(--border-light);
  font-size: 14.5px;
}
.book-nav-title {
  font-size: 11.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 16px;
}
.book-nav-part {
  font-family: var(--serif); font-size: 15px; color: var(--green);
  margin: 22px 0 8px; font-weight: 500;
}
.book-nav-list { list-style: none; margin: 0 0 4px; padding: 0; }
.book-nav-list li { margin: 0; }
.book-nav-list a {
  display: grid; grid-template-columns: 22px 1fr; gap: 8px;
  padding: 6px 8px 6px 6px; border-radius: 6px;
  color: var(--ink-soft); text-decoration: none; line-height: 1.35;
}
.book-nav-list a:hover { background: var(--green-50); color: var(--green); }
.book-nav-list a[aria-current="page"] { background: var(--green-50); color: var(--green); font-weight: 500; }
.book-nav-num { font-family: var(--mono); font-size: 11.5px; color: var(--muted); padding-top: 3px; }
.book-nav-links { margin: 14px 0 0; font-size: 13.5px; }
.book-nav-links a { color: var(--muted); text-decoration: none; }
.book-nav-links a:hover { color: var(--green); text-decoration: underline; }

.book-main { min-width: 0; padding: 40px 0 120px 56px; }
.book-chapter, .book-cover { max-width: var(--measure); }

/* ── Chapter furniture ─────────────────────────────────────────────────── */
.book-part {
  font-size: 11.5px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 14px;
}
.book-chapter h1, .book-cover h1 {
  font-family: var(--serif); font-weight: 500; color: var(--green);
  font-size: clamp(32px, 4.6vw, 46px); line-height: 1.12;
  margin: 0 0 16px; letter-spacing: -0.015em;
}
.book-meta {
  display: flex; flex-wrap: wrap; gap: 16px; margin: 0 0 22px;
  font-size: 13px; color: var(--muted);
}
.book-meta-item { display: inline-flex; align-items: center; gap: 6px; }
.book-summary {
  font-family: var(--serif); font-size: 20px; line-height: 1.55;
  color: var(--ink); margin: 0 0 34px; padding-bottom: 30px;
  border-bottom: 1px solid var(--border);
}

.book-body h2 {
  font-family: var(--serif); font-weight: 500; font-size: 27px; line-height: 1.24;
  color: var(--green); margin: 52px 0 14px; letter-spacing: -0.01em;
  scroll-margin-top: 80px;
  break-after: avoid;
}
.book-body h3 {
  font-family: var(--sans); font-weight: 600; font-size: 17px;
  color: var(--ink); margin: 34px 0 10px; scroll-margin-top: 80px;
  break-after: avoid;
}
.book-body p { margin: 0 0 18px; }
.book-body strong { color: var(--ink); font-weight: 600; }
.book-body em { font-style: italic; }
.book-body ul, .book-body ol { margin: 0 0 20px; padding-left: 24px; }
.book-body li { margin: 0 0 9px; }
.book-body li > p { margin-bottom: 8px; }
.book-body code {
  font-family: var(--mono); font-size: 0.87em;
  background: var(--green-50); color: var(--green-600);
  padding: 2px 6px; border-radius: 4px;
}
.book-body pre {
  background: #12261c; color: #e8efe9; border-radius: 10px;
  padding: 16px 18px; overflow-x: auto; margin: 0 0 22px;
  font-size: 14px; line-height: 1.6;
}
.book-body pre code { background: none; color: inherit; padding: 0; font-size: 14px; }
.book-body blockquote {
  margin: 26px 0; padding: 4px 0 4px 22px;
  border-left: 3px solid var(--gold);
  font-family: var(--serif); font-size: 20px; line-height: 1.5; color: var(--ink);
}
.book-body blockquote p { margin: 0; }

/* ── The page: one screenful of the book at a time ─────────────────────── */
.book-pages {
  position: relative;
  height: var(--page-height);
  overflow: hidden;
  perspective: 2200px;
  perspective-origin: 50% 50%;
}
.book-pages-inner {
  height: 100%;
  column-fill: auto;
  column-gap: var(--page-gap);
  transform: translateX(0);
  transition: transform 460ms cubic-bezier(.22, .61, .36, 1);
  will-change: transform;
}
/* A whole idea stays on one page. */
.book-body .callout,
.book-body pre,
.book-body blockquote,
.book-head { break-inside: avoid; }
/* A long table may run on to the next page, but never through the middle of
   a row. */
.book-body table { break-inside: auto; }
.book-body thead { break-after: avoid; }
.book-body tr { break-inside: avoid; }
.book-head { padding-bottom: 4px; }

/* The turning leaf: a copy of the page, swinging about the spine. */
.book-leaf {
  position: absolute; inset: 0; z-index: 4;
  overflow: hidden;
  background: var(--paper);
  transform-origin: left center;
  backface-visibility: hidden;
  pointer-events: none;
}
.book-leaf::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(to right, rgba(14, 36, 25, 0) 62%, rgba(14, 36, 25, .10) 100%);
}
.book-leaf .book-pages-inner { transition: none !important; }
.book-leaf.running.leaf-out { animation: leaf-out 560ms ease-in-out forwards; }
.book-leaf.running.leaf-in { animation: leaf-in 560ms ease-in-out forwards; }
@keyframes leaf-out {
  0% { transform: rotateY(0deg); box-shadow: 0 0 0 rgba(14, 36, 25, 0); }
  100% { transform: rotateY(-104deg); box-shadow: 30px 0 50px -24px rgba(14, 36, 25, .34); }
}
@keyframes leaf-in {
  0% { transform: rotateY(-104deg); box-shadow: 30px 0 50px -24px rgba(14, 36, 25, .34); }
  100% { transform: rotateY(0deg); box-shadow: 0 0 0 rgba(14, 36, 25, 0); }
}

.book-turn {
  display: flex; align-items: center; gap: 14px;
  max-width: var(--measure); margin: 18px 0 0;
}
.book-turn-btn {
  font: inherit; font-size: 22px; line-height: 1;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--green);
  cursor: pointer;
}
.book-turn-btn:hover { border-color: var(--green-500); background: var(--green-50); }
.book-turn-btn[disabled] { opacity: .35; cursor: default; }
.book-turn-count { font-size: 13.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.book-turn-hint { font-size: 12.5px; color: var(--muted); margin-left: auto; }
@media (max-width: 700px) { .book-turn-hint { display: none; } }

/* Tables: hairline rules, readable without shouting. */
.book-body table {
  width: 100%; border-collapse: collapse; margin: 0 0 26px;
  font-size: 15.5px; line-height: 1.5;
}
.book-body thead th {
  text-align: left; font-weight: 600; font-size: 12.5px;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
  padding: 0 14px 10px 0; border-bottom: 1px solid var(--border);
}
.book-body tbody td {
  padding: 11px 14px 11px 0; border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}
.book-body tbody tr:last-child td { border-bottom: none; }

/* ── Callouts ──────────────────────────────────────────────────────────── */
.callout {
  margin: 32px 0; padding: 20px 22px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--green-500);
  font-size: 16px;
}
.callout > *:last-child { margin-bottom: 0; }
.callout-title {
  font-family: var(--sans); font-size: 11.5px !important; font-weight: 600;
  letter-spacing: 0.13em; text-transform: uppercase; color: var(--green-500);
  margin: 0 0 12px !important;
}
.callout-aside { border-left-color: var(--green-500); background: var(--green-50); }
.callout-check { border-left-color: var(--gold); background: var(--gold-soft); }
.callout-check .callout-title { color: #8a6d15; }
.callout-check ol { padding-left: 22px; margin-bottom: 0; }
.callout-note { border-left-color: var(--muted); }

/* ── Citations ─────────────────────────────────────────────────────────── */
.cite {
  display: inline-block; text-decoration: none;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  color: var(--green-600); background: var(--green-50);
  border: 1px solid rgba(31, 83, 53, 0.16); border-radius: 999px;
  padding: 1px 9px; margin: 0 2px; white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease;
}
.cite:hover { background: #e0ece4; border-color: var(--green-500); color: var(--green); }
.cite::before { content: "§"; opacity: 0.5; margin-right: 4px; }

/* ── Cover ─────────────────────────────────────────────────────────────── */
.book-cover { padding-bottom: 20px; }
.book-cover-sub {
  font-family: var(--serif); font-size: 21px; line-height: 1.5;
  color: var(--ink); margin: 0 0 22px;
}
.book-cover-lede { font-size: 17px; margin: 0 0 34px; max-width: 62ch; }
.book-cover-stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 18px; padding: 26px 0; margin-bottom: 26px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.stat-value { display: block; font-family: var(--serif); font-size: 32px; color: var(--green); line-height: 1.1; }
.stat-label { display: block; font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.book-cover-note { font-size: 13.5px; color: var(--muted); margin: 0 0 22px; }
.book-cover-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 40px; }
.book-btn {
  display: inline-block; padding: 11px 20px; border-radius: 8px;
  background: var(--green); color: #faf9f3; font-size: 15px; font-weight: 500;
  text-decoration: none;
}
.book-btn:hover { background: var(--green-600); color: #fff; }
.book-btn-quiet { background: transparent; color: var(--green-600); border: 1px solid var(--border); }
.book-btn-quiet:hover { background: var(--green-50); color: var(--green); }

.toc-part { margin-top: 44px; }
.toc-part h2 {
  font-family: var(--serif); font-weight: 500; font-size: 22px;
  color: var(--green); margin: 0 0 6px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list li { border-bottom: 1px solid var(--border-light); }
.toc-list li:last-child { border-bottom: none; }
.toc-list a {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 12px;
  align-items: baseline; padding: 15px 6px; text-decoration: none;
  color: var(--ink); border-radius: 8px;
}
.toc-list a:hover { background: var(--green-50); }
.toc-num { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.toc-title { font-family: var(--serif); font-size: 19px; line-height: 1.3; color: var(--green); }
.toc-minutes { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.toc-summary {
  grid-column: 2 / -1; font-size: 14.5px; color: var(--muted);
  line-height: 1.5; margin-top: 2px;
}

/* ── References ────────────────────────────────────────────────────────── */
.cite-group { margin-top: 46px; }
.cite-group > h2 {
  font-family: var(--serif); font-weight: 500; font-size: 23px; color: var(--green);
  padding-bottom: 10px; border-bottom: 1px solid var(--border); margin: 0 0 4px;
}
.cite-item { padding: 22px 0; border-bottom: 1px solid var(--border-light); }
.cite-item h3 {
  font-family: var(--mono); font-size: 15px; font-weight: 500;
  color: var(--green-600); margin: 0 0 6px; scroll-margin-top: 80px;
}
.cite-title { font-family: var(--serif); font-size: 18px; color: var(--ink); margin: 0 0 12px; }
.cite-facts { display: grid; grid-template-columns: 150px 1fr; gap: 6px 16px; margin: 0; font-size: 14.5px; }
.cite-facts dt { color: var(--muted); font-size: 13px; }
.cite-facts dd { margin: 0; }
.cite-facts a { font-family: var(--mono); font-size: 13px; word-break: break-all; }
.cite-quote {
  margin: 14px 0 0; padding: 12px 16px; background: var(--surface);
  border: 1px solid var(--border); border-left: 3px solid var(--green-500);
  border-radius: 8px; font-size: 14.5px; line-height: 1.6; color: var(--ink-soft);
}

/* ── Pager ─────────────────────────────────────────────────────────────── */
.book-pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  max-width: var(--measure); margin: 64px 0 0;
  padding-top: 28px; border-top: 1px solid var(--border);
}
.book-pager-link {
  display: flex; flex-direction: column; gap: 4px; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); text-decoration: none;
}
.book-pager-link:hover { border-color: var(--green-500); background: var(--green-50); }
.book-pager-next { text-align: right; grid-column: 2; }
.book-pager-label { font-size: 11.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.book-pager-title { font-family: var(--serif); font-size: 17px; color: var(--green); }

/* ── Search ────────────────────────────────────────────────────────────── */
.book-search {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(31, 30, 26, 0.42); padding: 8vh 18px 18px;
}
.book-search[hidden] { display: none; }
.book-search-inner {
  max-width: 720px; margin: 0 auto; background: var(--paper);
  border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 30px 60px -20px rgba(14, 36, 25, 0.3);
  padding: 22px; max-height: 76vh; display: flex; flex-direction: column;
}
.book-search-label {
  font-size: 11.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
}
#search-input {
  font: inherit; font-size: 19px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--ink); width: 100%;
}
#search-input:focus { outline: 2px solid var(--green); outline-offset: 1px; }
.book-search-results { margin-top: 14px; overflow-y: auto; }
.search-result {
  display: block; padding: 12px 14px; border-radius: 9px;
  text-decoration: none; border: 1px solid transparent;
}
.search-result:hover, .search-result[aria-selected="true"] {
  background: var(--green-50); border-color: rgba(31, 83, 53, 0.18);
}
.search-result-part { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.search-result-title { display: block; font-family: var(--serif); font-size: 17px; color: var(--green); margin-top: 2px; }
.search-result-snippet { display: block; font-size: 14px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.search-result mark { background: rgba(201, 162, 39, 0.3); color: var(--ink); padding: 0 2px; }
.search-empty { padding: 18px 4px; color: var(--muted); font-size: 15px; }

/* ── Small screens ─────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  body.book { font-size: 16.5px; --page-height: min(62vh, 540px); --page-gap: 30px; }
  #contents-toggle { display: inline-block; }
  /* The bar stays above the drawer, so the button that opened it can close it
     again, and the drawer starts below the bar rather than behind it. */
  .book-bar { z-index: 45; }
  .book-shell { grid-template-columns: minmax(0, 1fr); padding: 0 20px; }
  .book-nav {
    position: fixed; z-index: 40; top: 56px; left: 0; bottom: 0;
    width: min(85vw, 340px); max-height: none;
    background: var(--paper); border-right: 1px solid var(--border);
    padding: 22px 22px 60px; transform: translateX(-102%);
    transition: transform 200ms ease; box-shadow: 0 20px 50px rgba(14, 36, 25, 0.22);
    overflow-y: auto;
  }
  .book-nav.open::after {
    /* A quiet backdrop, so it is obvious the page behind is dimmed while the
       drawer is open. Taps pass through, and the page closes it. */
    content: ""; position: fixed; top: 56px; left: min(85vw, 340px); right: 0; bottom: 0;
    background: rgba(31, 30, 26, 0.18); pointer-events: none;
  }
  .book-nav.open { transform: translateX(0); }
  .book-main { padding: 28px 0 90px; }
  .book-body h2 { font-size: 23px; margin-top: 42px; }
  .book-pager { grid-template-columns: 1fr; }
  .book-pager-next { grid-column: 1; text-align: left; }
  .book-body table { font-size: 15px; }
  .cite-facts { grid-template-columns: 1fr; gap: 2px; }
  .cite-facts dt { margin-top: 8px; }
}

/* ── Embedded: the same chapters, inside another page ──────────────────────
   With ?embed=1 the reader drops its own bar and contents rail so the host
   page can show a chapter in a frame. The chapter, the citations and the
   previous/next links stay, because those are the parts being read. */
body.book.embed .book-bar,
body.book.embed .book-nav,
body.book.embed .skip-link { display: none; }
body.book.embed .book-shell { display: block; max-width: none; padding: 0; }
body.book.embed .book-main { padding: 34px 30px 64px; max-width: 860px; margin: 0 auto; }
body.book.embed .book-chapter { max-width: none; }
body.book.embed .book-pager { max-width: none; margin-top: 46px; }
body.book.embed .book-cover { max-width: none; }
body.book.embed { --page-height: 540px; --page-gap: 34px; }

@media (max-width: 700px) {
  body.book.embed .book-main { padding: 26px 20px 52px; }
  body.book.embed { --page-height: 460px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .book-nav { transition: none; }
  .book-bar-progress { transition: none; }
}

/* ── Print: the whole book, without the furniture ──────────────────────── */
@media print {
  :root { --measure: none; }
  body.book { background: #fff; color: #000; font-size: 11.5pt; line-height: 1.5; }
  .book-bar, .book-nav, .book-pager, .book-search, .skip-link, .book-cover-actions { display: none !important; }
  .book-shell { display: block; max-width: none; padding: 0; }
  .book-main { padding: 0; }
  .book-chapter, .book-cover { max-width: none; page-break-after: always; }
  .book-chapter:last-child { page-break-after: auto; }
  .book-chapter h1 { font-size: 24pt; }
  .book-body h2 { font-size: 15pt; margin-top: 20pt; page-break-after: avoid; }
  .book-body h3 { page-break-after: avoid; }
  .book-body p, .book-body li { orphans: 3; widows: 3; }
  .book-body table, .callout, .book-body pre { page-break-inside: avoid; }
  /* Paper is one long column, not a stack of screens. */
  .book-pages { height: auto !important; overflow: visible !important; perspective: none; }
  .book-pages-inner { height: auto !important; transform: none !important; column-width: auto !important; }
  .book-turn, .book-leaf { display: none !important; }
  a { color: #000; text-decoration: none; }
  .cite { border: none; background: none; padding: 0; font-size: 9.5pt; }
  .cite::before { content: "["; }
  .cite::after { content: "]"; }
  .callout { background: none; border: 1px solid #999; }
}
