/* Musical Machines: Companion Website — shared styles
   musicalmachines.scottbarton.info
*/

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

:root {
  --ink:        #1c1c1a;
  --ink2:       #52524e;
  --ink3:       #9a9a94;
  --rule:       #e2dfd6;
  --rule2:      #f0ede6;
  --bg:         #f6f4ef;
  --paper:      #ffffff;
  --banner:     #e5e5e3;
  --banner-rule: #b3b3af;
  --accent:     #0b5fff;
  --accent-lt:  #e5efff;
  --accent-mid: #4a7a5a;
  --danger:     #b3261e;
  --danger-lt:  #fbeae9;
  --table-header-bg: #3c6249;
  --table-body-bg:   #eaf2ec;
  --table-row-alt:   #dcebe0;
  --table-border:    #bcd6c4;
  --serif:      'EB Garamond', Georgia, serif;
  --sans:       'IBM Plex Sans', system-ui, sans-serif;
  --mono:       'IBM Plex Mono', monospace;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 19px;
  line-height: 1.6;
}

a { color: var(--accent); }

/* Italic correction: italic letters (e.g. variable names set in <em>, as in
   "mass (m)") lean right and otherwise crowd into or touch a following
   upright character — most visibly a closing parenthesis. A small trailing
   space fixes it without having to hand-adjust every occurrence. */
em, i {
  margin-right: 0.07em;
}

/* ── Navigation ── */
nav {
  background: var(--banner);
  border-bottom: 1px solid var(--rule);
  padding: 0 2.5rem;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  min-height: 56px;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  flex: 1 1 auto;
  min-width: 0;
}

.nav-links a {
  font-size: 14px;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 400;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  position: relative;
  border-right: 1px solid var(--banner-rule);
  transition: color 0.2s ease;
  white-space: nowrap;
}

.nav-links a::after {
  content: "";
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 0;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.2s ease;
}

.nav-links a:hover { color: var(--accent); }
.nav-links a:hover::after { transform: scaleX(1); }
.nav-links a.active { color: var(--accent); }
.nav-links a.active::after { transform: scaleX(1); }

/* ── Page header ──
   .page-header-inner mirrors .wrap's box model exactly (own padding +
   max-width + auto margins, no padding on the parent) so the two
   containers' content edges align pixel-for-pixel at any viewport width. */
.page-header {
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.page-header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 2.5rem 2.25rem;
}

.page-eyebrow {
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink3);
  font-weight: 500;
  margin-bottom: 0.6rem;
}

.page-title {
  font-family: var(--serif);
  font-size: 40px;
  font-style: italic;
  color: var(--ink);
  line-height: 1.15;
  margin-bottom: 0.5rem;
}

.page-desc {
  font-size: 17px;
  color: var(--ink2);
  line-height: 1.65;
  max-width: 580px;
}

/* ── Main wrapper ── */
.wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 2.5rem;
}

/* ── Section labels ── */
.section-label {
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink3);
  font-weight: 500;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1.5rem;
}

/* ── Content layout (sidebar + blocks) ── */
.content-layout {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 2.5rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 72px;
  /* Cap height to the viewport (minus the sticky offset and a bottom
     margin) and let the sidebar scroll internally — long "On this page"
     lists (e.g. multi-part chapters) would otherwise overflow off the
     bottom of the screen with no way to reach the remaining links. */
  max-height: calc(100vh - 72px - 24px);
  overflow-y: auto;
}

.sidebar-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 0.75rem;
}

.sidebar-label {
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink3);
  font-weight: 500;
}

.sidebar-collapse-toggle {
  font-family: var(--sans);
  font-size: 11px;
  color: var(--ink3);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.sidebar-collapse-toggle:hover { color: var(--accent); }

.back-to-top {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--accent-lt);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  text-decoration: none;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.15s ease, color 0.15s ease;
  z-index: 40;
}

.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.back-to-top:hover { background: var(--accent); color: #fff; }

.sidebar-link {
  display: block;
  padding: 6px 8px;
  font-size: 15px;
  color: var(--accent);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.12s;
  line-height: 1.4;
}

/* Second-level entries (subheadings) nested under a top-level section link.
   One tab-stop (16px) in from the left edge that top-level links use. */
.sidebar-sublink {
  padding-left: 16px;
  font-size: 13px;
  color: var(--ink2);
}

/* Third-level entries: a plain link inside a doubly-nested .sidebar-sublinks
   container (a subheading's own sub-subheadings). Depth is inferred from
   nesting rather than a dedicated class, so leaf markup stays simple. A
   full tab-stop (16px) further right than the second level. */
.sidebar-sublinks .sidebar-sublinks > .sidebar-link {
  padding-left: 32px;
  font-size: 12px;
  color: var(--ink3);
}

.sidebar-link:hover { color: var(--accent); border-left-color: var(--rule); }
.sidebar-link.active { color: var(--accent); border-left-color: var(--accent); font-weight: 700; }

/* ── Collapsible sidebar groups (a heading + its own nested list) ──
   A checkbox drives the collapse/expand state so no JS is needed. The
   checkbox is visually hidden (not display:none, so it stays keyboard
   focusable/toggleable) and its <label> renders as the disclosure arrow,
   kept separate from the heading's <a> so the link and the toggle can be
   clicked independently. The same .sidebar-group markup is reused at any
   depth (Part, or a subheading that itself has sub-subheadings) — nesting
   one .sidebar-group inside another's .sidebar-sublinks just works, and
   the rules below key off that nesting to shrink type/indent per level. */
.sidebar-group { margin-bottom: 2px; }

.sidebar-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sidebar-group-row {
  display: flex;
  align-items: stretch;
}

.sidebar-group-link { flex: 1 1 auto; }

/* A group nested inside another group's sublinks (i.e. not top-level)
   should land at the same 16px tab-stop as its sibling leaf sublinks.
   .sidebar-link already contributes 8px of its own left padding, so the
   row only needs to add the remaining 8px — not another full 16px, which
   would double up and push arrow-bearing headings out of alignment with
   their plain-link siblings. */
.sidebar-sublinks .sidebar-group-row { padding-left: 8px; }
.sidebar-sublinks .sidebar-group-link { font-size: 13px; color: var(--ink2); }

.sidebar-toggle-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  flex-shrink: 0;
  cursor: pointer;
  color: var(--ink3);
}

.sidebar-toggle-arrow:hover { color: var(--accent); }

.sidebar-toggle-arrow::before {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border-left: 4px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
}

.sidebar-toggle:checked ~ .sidebar-group-row .sidebar-toggle-arrow::before {
  transform: rotate(90deg);
}

.sidebar-toggle:focus-visible ~ .sidebar-group-row .sidebar-toggle-arrow {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.sidebar-sublinks { display: none; }
.sidebar-toggle:checked ~ .sidebar-sublinks { display: block; }

/* ── Content blocks ── */
.content-blocks {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  /* Grid items default to min-width:auto, so a wide descendant (e.g. a
     long unwrapped line in an .arduino-code block) can force this whole
     column wider instead of scrolling within its own overflow-x:auto
     container. min-width:0 lets the grid track shrink and pushes the
     overflow handling back down to the descendant. */
  min-width: 0;
}

.content-block {
  background: var(--paper);
  padding: 1.75rem 2rem;
}

.block-anchor { display: block; position: relative; top: -80px; visibility: hidden; }

/* ── Topic pages (music theory, instrument design, and every chapter page
   that follows): wider text column, larger type. Add class="topic-page"
   to <body>, alongside a page-specific class if one is useful, and it
   picks up this whole treatment — no need to touch these selectors when
   a new chapter page is added. ── */
.topic-page .wrap,
.topic-page .page-header-inner {
  max-width: 1400px;
}

.topic-page .block-body {
  font-size: 20px;
}

.topic-page .block-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 30px;
  font-weight: 500;
  line-height: 1.2;
}

.block-subhead {
  font-family: var(--serif);
  font-style: italic;
  font-size: 27px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.25;
  margin: 1.5rem 0 0.5rem;
}

.block-subsubhead {
  font-family: var(--serif);
  font-style: italic;
  font-size: 21px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.25;
  margin: 1.25rem 0 0.4rem;
}

/* Indent paragraphs that continue a block, but not the one opening it.
   Headings are followed by paragraphs in two different markup shapes:
   (1) heading, then a separate .block-body wrapper holding the p's, or
   (2) heading nested inside an existing .block-body, with the p's as
   direct following siblings. Both need a text-indent:0 override. */
.topic-page .block-body p {
  text-indent: 1.5em;
}

.topic-page .block-title + .block-body p:first-child,
.topic-page .block-subhead + .block-body p:first-child,
.topic-page .block-subsubhead + .block-body p:first-child,
.topic-page .block-subhead + p,
.topic-page .block-subsubhead + p {
  text-indent: 0;
}

/* Equations and lists always sit mid-paragraph (the surrounding prose is
   one continuous thought split around a centered equation or an embedded
   list), not a real paragraph break, so text resuming after one of these —
   directly, or after a figure inserted between the equation and the
   resuming text — should read as a continuation, not a new paragraph.
   Note: .arduino-code-wrap is deliberately NOT in this list. A code block
   can either continue a walkthrough (next line explains what you just saw)
   or close one out before a genuinely new paragraph starts — that's not
   distinguishable from DOM structure alone, so paragraphs following a code
   block default to indented and use the standalone .no-indent class
   (below) for the specific cases that are continuations. */
.topic-page .equation + .block-body p:first-child,
.topic-page .equation + .figure + .block-body p:first-child,
.topic-page ul + .block-body p:first-child,
.topic-page ol + .block-body p:first-child {
  text-indent: 0;
}

/* Escape hatch for the opposite case: a genuinely new paragraph (not a
   continuation of the equation above it) happens to land as the first
   child of a .block-body directly following an .equation. Add
   class="new-paragraph" to that .block-body to restore the normal indent. */
.topic-page .block-body.new-paragraph p:first-child {
  text-indent: 1.5em;
}

/* Escape hatch for the rare one-off case where a figure itself falls
   mid-paragraph (the resuming text is a continuation, not a new paragraph),
   which can't be detected generically from sibling structure alone. */
.topic-page .block-body.no-indent p:first-child {
  text-indent: 0;
}

/* Same escape hatch, but applicable to any single <p> directly (not just
   a block-body's first child) — e.g. text resuming after an intervening
   example-block, lesson-block, or figure mid-paragraph. Add class="no-indent"
   straight on the <p> in question. */
.topic-page .block-body p.no-indent {
  text-indent: 0;
}

/* ── Equations ──
   Upright by default, matching standard math typesetting convention
   (ISO 80000-2): only variable letters are italic, while numbers, units,
   and labels stay roman. The markup already wraps each variable in <em>;
   this rule just stops italicizing everything else around them. */
.equation {
  font-family: var(--serif);
  font-size: 20px;
  color: var(--ink);
  text-align: center;
  margin: 1rem 0;
}

.equation sup { font-style: normal; }
.equation sub { font-style: normal; }

/* Vertically stacked fraction (numerator / rule / denominator), used in
   place of an inline "a / b" wherever an equation divides one quantity by
   another. Not used for unit notation like m/sec or N/m — those stay
   inline text since stacking them would read as a formula, not a unit. */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  margin: 0 0.2em;
  line-height: 1.3;
}

.frac-num,
.frac-den {
  display: block;
  padding: 0 0.15em;
}

.frac-num {
  border-bottom: 1px solid currentColor;
}

/* ── Data tables ── */
.table-wrap {
  overflow-x: auto;
  margin: 0.5rem 0 1.25rem;
  border: 1px solid var(--table-border);
}

.data-table {
  border-collapse: collapse;
  font-size: 14px;
  color: var(--ink);
  width: 100%;
}

.data-table th,
.data-table td {
  border: 1px solid var(--table-border);
  padding: 0.5rem 0.75rem;
  text-align: left;
  white-space: nowrap;
}

/* Cells holding a pros/cons-style list (e.g. the mechanism comparison
   table) need to wrap normally — nowrap is only meant for short, single-
   value cells like "Belt" / "12–40 m/s". */
.data-table td ul {
  white-space: normal;
}

.data-table th {
  background: var(--table-header-bg);
  font-weight: 500;
  color: #ffffff;
  border-color: var(--table-header-bg);
}

.data-table td {
  background: var(--table-body-bg);
}

.data-table tbody tr:nth-child(even) td {
  background: var(--table-row-alt);
}

.table-caption {
  font-size: 14px;
  color: var(--ink3);
  text-align: center;
  margin-bottom: 0.5rem;
}

.block-type-label {
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 500;
  margin-bottom: 0.6rem;
}

.block-type-label.writing  { color: #2a5c3a; }
.block-type-label.code     { color: #1e3a52; }
.block-type-label.exercise { color: #5c3e18; }
.block-type-label.media    { color: #4a2a52; }
.block-type-label.image    { color: #4a3e18; }

.block-title {
  font-size: 20px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

.block-body {
  font-size: 17px;
  color: var(--ink2);
  line-height: 1.75;
  margin-bottom: 1rem;
}

.block-body:last-child { margin-bottom: 0; }

.block-body p + p { margin-top: 0.85rem; }

/* ── Code blocks ── */
pre.code-block {
  background: #f8f7f4;
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.65;
  padding: 1.25rem 1.5rem;
  color: var(--ink2);
  overflow-x: auto;
  margin-bottom: 0.85rem;
  white-space: pre;
}

/* ── Inline code references in prose ──
   A literal code fragment quoted mid-sentence (a function name, a full
   line being explained, a variable) gets monospace + a light chip
   background, not bold — bold stays reserved for introducing new terms.
   Scoped away from .arduino-code code, which has its own full styling. */
.block-body code,
.lesson-block code,
.example-block code,
.content-list code {
  font-family: var(--mono);
  background: var(--rule2);
  color: var(--ink);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.85em;
}

/* ── Arduino-style sketch blocks ──
   Styled to evoke the Arduino IDE editor (white pane, sketch-name tab,
   classic keyword/function/comment colors) rather than the site's default
   .code-block. .arduino-code-wrap holds a header (filename + copy button)
   and a <pre><code>. Syntax coloring is applied by code-highlight.js,
   which wraps tokens in the .tok-* spans styled below; the raw text is
   kept in a data-code attribute so the Copy button always copies clean,
   unhighlighted source regardless of the applied spans. */
.arduino-code-wrap {
  border: 1px solid #d0cfc7;
  border-radius: 6px;
  overflow: hidden;
  margin: 0 0 1.1rem;
  background: #ffffff;
}

.arduino-code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: #eeece4;
  border-bottom: 1px solid #d0cfc7;
  padding: 0.45rem 0.75rem;
}

.arduino-code-filename {
  font-family: var(--mono);
  font-size: 13px;
  color: #5c5a4e;
}

.code-copy-btn {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink2);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.code-copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.code-copy-btn.copied { border-color: var(--accent-mid); color: var(--accent-mid); background: #eaf2ec; }

.arduino-code {
  margin: 0;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  background: #ffffff;
}

.arduino-code code {
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.65;
  color: #1c1c1a;
  white-space: pre;
  tab-size: 2;
}

/* Arduino IDE token colors. Five categories:
   - orange:      built-in functions — action words (pinMode, delay)
   - green/teal:  data types and built-in constants — the "storage
                   boxes" for values (int, float, HIGH)
   - light green: control-flow structure — the rules/loops that steer
                   the program (if, while, for)
   - gray:        comments
   - black:       plain text / anything unrecognized (the default)
   Plain weight throughout — color alone carries the distinction. */
.tok-comment  { color: #8a8a8a; }
.tok-string   { color: #8b3a3a; }
.tok-function { color: #ea580c; }
.tok-type     { color: #00918a; }
.tok-keyword  { color: #5c9b1d; }

/* ── Exercise blocks ── */
.exercise-block {
  background: #fdf9f4;
  border-left: 3px solid #c8a870;
  padding: 1rem 1.25rem;
  margin-bottom: 0.85rem;
}

.exercise-block p {
  font-size: 17px;
  color: var(--ink2);
  line-height: 1.7;
}

.exercise-block p + p { margin-top: 0.75rem; }

/* ── Content lists (bulleted/numbered lists within body prose) ── */
.content-list {
  margin: 0 0 1rem 4rem;
  color: var(--ink2);
  font-size: 20px;
  line-height: 1.75;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* ── Lesson blocks ── */
.lesson-block {
  background: var(--accent-lt);
  border-left: 3px solid var(--accent);
  padding: 1.1rem 1.35rem;
  margin-bottom: 0.85rem;
}

.lesson-block p {
  font-size: 18px;
  color: var(--ink);
  line-height: 1.7;
}

.lesson-block p + p { margin-top: 0.75rem; }

.lesson-block strong {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 14px;
}

/* Same treatment as .lesson-block strong (blue, small caps) but on a
   <span> rather than <strong>, for labels like "Syntax:" that should
   not be bold. */
.lesson-block-label {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 14px;
  font-weight: 400;
}

/* A function/keyword name label at the start of a lesson-block (e.g.
   "digitalWrite()", "switch...case") rather than the literal word "Lesson:".
   Uses .lesson-block strong's color/weight but must NOT uppercase, since
   these are actual code identifiers whose case is meaningful. Selector is
   scoped with the .lesson-block parent (rather than just .lesson-block-fn
   alone) so it outranks the generic ".lesson-block code" inline-code chip
   rule below — otherwise that rule's grey background/black ink wins. */
.lesson-block .lesson-block-fn {
  font-family: var(--mono);
  color: var(--accent);
  font-weight: 500;
  font-size: 15px;
  background: none;
  padding: 0;
}

/* Multi-line syntax (e.g. a full if/else or while block) inside a
   lesson-block's Syntax line. A single-line <code> chip reads badly once
   the syntax itself spans several conventionally-indented lines, so this
   renders as its own small code pane instead — plain <pre>, no nested
   <code>, so it isn't caught by the inline-code chip rule above. */
.lesson-block pre {
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--rule2);
  border: 1px solid rgba(11, 95, 255, 0.15);
  border-radius: 4px;
  padding: 0.65rem 0.9rem;
  margin-top: 0.4rem;
  overflow-x: auto;
  white-space: pre;
}

/* The name line stands alone above Syntax/definition lines, so it reads
   as a small heading rather than running text. */
.lesson-block-name .lesson-block-fn { font-size: 17px; font-weight: 700; }

/* ── Safety blocks (bounded, full-width, light red — safety guidelines
   that call for more visual weight than a lesson-block) ── */
.safety-block {
  background: var(--danger-lt);
  border: 1px solid var(--danger);
  border-radius: 4px;
  padding: 1.1rem 1.5rem 1.1rem 1.75rem;
  margin-bottom: 1.1rem;
}

.safety-block .content-list {
  margin: 0 0 0 1.5rem;
  color: var(--ink);
}

/* ── Example blocks (bounded, centered, light yellow — worked numeric
   examples that appear in shaded boxes in the print book) ── */
.example-block {
  max-width: 640px;
  margin: 0 auto 1rem;
  background: #fbf3d6;
  border: 1px solid #e0cf85;
  border-radius: 4px;
  padding: 1.1rem 1.5rem;
}

.example-block p {
  font-size: 18px;
  color: var(--ink);
  line-height: 1.7;
  text-indent: 0 !important;
}

.example-block p + p { margin-top: 0.75rem; }

.example-block strong {
  color: #8a6d1a;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 14px;
}

.example-block .equation {
  margin: 0.6rem 0 0;
}

/* ── Video embeds ── */
.video-wrap {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  background: var(--rule2);
  border: 1px solid var(--rule);
  margin-bottom: 0.75rem;
  max-width: 640px;
}

.video-wrap iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
}

.video-caption {
  font-size: 15px;
  color: var(--ink3);
  line-height: 1.5;
  max-width: 640px;
  margin-bottom: 1rem;
}

/* ── Content type tags ── */
.content-types { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 1rem; }

.ctype {
  font-size: 13px;
  padding: 3px 10px;
  font-weight: 500;
  letter-spacing: 0.03em;
  border: 1px solid var(--rule);
  color: var(--ink3);
  background: var(--paper);
}

.ctype.writing  { border-color: #b8d4c0; color: #2a5c3a; background: #f0f7f2; }
.ctype.code     { border-color: #b8c8d8; color: #1e3a52; background: #f0f4f8; }
.ctype.exercise { border-color: #d8c8b0; color: #5c3e18; background: #faf5ee; }
.ctype.media    { border-color: #d0b8d4; color: #4a2a52; background: #f6f0f8; }
.ctype.image    { border-color: #d0c8b0; color: #4a3e18; background: #faf8ee; }

/* ── Figure placeholders (pending image export from typeset PDF) ── */
.figure-placeholder {
  border: 1px dashed var(--banner-rule);
  background: var(--rule2);
  padding: 2rem 1.5rem;
  text-align: center;
  color: var(--ink3);
  font-size: 14px;
  margin-bottom: 0.5rem;
}

.figure-placeholder .figure-path {
  display: block;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink2);
  margin-top: 0.5rem;
}

.figure-caption {
  font-size: 14px;
  color: var(--ink3);
  text-align: center;
  margin-bottom: 1.25rem;
}

/* Site-wide figure sizing. Most photos read better at a fixed, moderate
   width than stretched to the full text column, so 600px is the default
   for every page. Modifier classes cover the exceptions (mindmaps, wide
   diagrams, small diagrams) — add one to the <figure> element only when
   a figure needs to deviate from the 600px default. */
.figure {
  margin: 0 auto 0.5rem;
  max-width: 600px;
}

.figure img {
  display: block;
  width: 100%;
  border: 1px solid var(--rule);
  background: var(--paper);
}

.figure-wide { max-width: 100%; }
.figure-medium { max-width: 800px; }
.figure-small { max-width: 480px; }

/* Notation figures vary wildly in native crop/aspect ratio (some tightly
   cropped to a single flat line, some tall diagrams). Give them a shared
   target height so notehead size reads as roughly consistent, instead of
   each one stretching to the full column width. */
.figure-notation .figure-frame {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 210px;
  margin-bottom: 0.5rem;
}

.figure-notation .figure-frame img {
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  border: 1px solid var(--rule);
  background: var(--paper);
  display: block;
}

/* ── Reference lists ── */
.reference-list {
  font-size: 15px;
  color: var(--ink2);
  line-height: 1.6;
  list-style: none;
}

.reference-list li {
  padding-left: 1.5em;
  text-indent: -1.5em;
  margin-bottom: 0.75rem;
}

/* ── Media page ── */
.chapter-group { margin-bottom: 2.5rem; }

.media-grid {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
}

.media-item {
  background: var(--paper);
  padding: 1.25rem 1.75rem;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.media-thumb-wrap {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  background: var(--rule2);
  border: 1px solid var(--rule);
}

.media-thumb-wrap iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
}

.media-ref {
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink3);
  font-weight: 500;
  margin-bottom: 0.3rem;
}

.media-title {
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 0.35rem;
  line-height: 1.3;
}

.media-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 0.75rem;
}

.media-links a {
  font-size: 15px;
  color: var(--accent);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 5px;
}

.media-links a:hover { text-decoration: underline; }

/* ── Home hero ── */
.hero {
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  padding: 3.5rem 2.5rem;
}

.hero-inner {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 3rem;
  align-items: start;
}

.hero-eyebrow {
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-mid);
  font-weight: 500;
  margin-bottom: 0.75rem;
}

.hero-title {
  font-family: var(--serif);
  font-size: 60px;
  font-style: italic;
  line-height: 1.0;
  color: var(--ink);
  margin-bottom: 0.3rem;
}

.hero-sub {
  font-size: 17px;
  color: var(--ink2);
  margin-bottom: 0.25rem;
}

.hero-author {
  font-size: 15px;
  color: var(--ink3);
  margin-bottom: 0.6rem;
}

/* Sits below both hero-inner columns (text and book cover), centered on
   the full page width. Same pill treatment as .hero-companion for visual
   consistency. */
.hero-desc-fab {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  margin-top: 1.5rem;
}

.site-fab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-lt);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.6rem 1.1rem;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.site-fab:hover { background: var(--accent); color: #fff; }
.site-fab svg { flex-shrink: 0; }

.hero-companion {
  display: inline-block;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-lt);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  margin-bottom: 1.75rem;
}

.hero-desc {
  font-size: 18px;
  color: var(--ink2);
  line-height: 1.75;
  max-width: 500px;
  margin-bottom: 2rem;
}

.hero-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border: 1px solid var(--rule);
  background: var(--rule);
}

.hero-nav-item {
  background: var(--paper);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  transition: background 0.12s;
}

.hero-nav-item:hover { background: var(--accent-lt); }

.hero-nav-num {
  font-size: 13px;
  color: var(--ink3);
  font-weight: 500;
  letter-spacing: 0.06em;
  flex-shrink: 0;
  width: 28px;
}

.hero-nav-label {
  font-size: 15px;
  color: var(--accent);
  font-weight: 500;
  flex: 1;
}

.hero-nav-arrow { font-size: 16px; color: var(--ink3); }

.book-cover {
  width: 100%;
  border: 1px solid var(--rule);
  display: block;
}

.book-meta {
  margin-top: 0.85rem;
  font-size: 14px;
  color: var(--ink3);
  line-height: 1.9;
}

.book-meta a { color: var(--accent); text-decoration: none; }
.book-meta a:hover { text-decoration: underline; }

.order-button {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.65rem 1.2rem;
  background: #f2e2a0;
  border: 1px solid #d3c088;
  font-weight: 500;
  font-size: 14px;
  border-radius: 8px;
  transition: background 0.12s;
}

.book-meta a.order-button { color: var(--ink); }

.book-meta a.order-button:hover { background: #e9d488; color: var(--ink); text-decoration: none; }

/* ── Home section overview grid ── */
.section-grid {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
}

.section-row {
  background: var(--paper);
  padding: 1.5rem 1.75rem;
}

.section-row-num {
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink3);
  font-weight: 500;
  margin-bottom: 0.3rem;
}

.section-row-title {
  font-family: var(--serif);
  font-size: 24px;
  font-style: italic;
  color: var(--ink);
  margin-bottom: 0.45rem;
}

.section-row-desc {
  font-size: 17px;
  color: var(--ink2);
  line-height: 1.65;
  max-width: 580px;
}

/* ── Footer ── */
footer {
  border-top: 1px solid var(--rule);
  background: var(--paper);
  padding: 1.5rem 2.5rem;
  margin-top: 3rem;
}

.footer-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.footer-text { font-size: 14px; color: var(--ink3); }
.footer-link { color: var(--accent); text-decoration: none; }
.footer-link:hover { text-decoration: underline; }

.footer-copyright {
  flex-basis: 100%;
  text-align: center;
  font-size: 13px;
  color: var(--ink3);
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--rule2);
}

/* ── Responsive ── */
@media (max-width: 700px) {
  nav { padding: 0.75rem 1.25rem; min-height: auto; }
  .nav-links { flex-wrap: wrap; }
  .nav-links a { padding: 0.5rem 0.75rem; font-size: 12px; }
  .hero-inner { grid-template-columns: 1fr; }
  .content-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .media-item { grid-template-columns: 1fr; }
  .wrap { padding: 1.5rem 1.25rem; }
  .page-header { padding: 1.5rem 1.25rem; }
}
