/* ============================================================
   Molecular Nutrition — U-M themed responsive textbook styles
   Prototype. Self-contained (does not depend on tufte.css).
   Theming via custom properties: change the palette/fonts here.
   ============================================================ */

:root {
  /* University of Michigan core palette */
  --um-blue:        #00274C;  /* primary; text-safe on white */
  --um-maize:       #FFCB05;  /* ACCENT ONLY — fails contrast as text */
  --um-blue-deep:   #001a33;  /* nav hover */
  --um-blue-link:   #105998;  /* links: ~5.3:1 on white, AA */
  --um-blue-tint:   #eef3f8;  /* note background */

  --ink:            #1a1a1a;
  --ink-soft:       #444;
  --rule:           #d4dae0;
  --bg:             #ffffff;

  --font-body: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-head: "Source Sans 3", "Helvetica Neue", Arial, sans-serif;

  /* Layout knobs — tune the reading column / margin gutter here */
  --gutter:      35%;   /* right padding reserved for margin notes */
  --note-width:  30%;
  --note-pull:  -33%;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

html { font-size: 100%; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  margin: 0;
}

/* reading container */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

article { counter-reset: sidenote-counter; }

p, li { font-size: 1.125rem; }
p { margin: 0 0 1.1rem; }

a { color: var(--um-blue-link); text-decoration: underline; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

/* ---------- headings ---------- */
h1, h2, h3, h4 {
  font-family: var(--font-head);
  color: var(--um-blue);
  font-weight: 600;
  line-height: 1.2;
}
h1 {
  font-size: 2.5rem;
  margin: 0.4em 0 0.6em;
  border-bottom: 3px solid var(--um-maize);   /* maize accent, not text */
  padding-bottom: 0.3rem;
}
h2 { font-size: 1.7rem; margin: 2rem 0 0.6rem; }
h3 { font-size: 1.3rem; margin: 1.6rem 0 0.5rem; color: var(--ink); }

.newthought { font-variant: small-caps; font-weight: 600; letter-spacing: 0.02em; }

/* abstract / blockquote */
blockquote {
  border-left: 4px solid var(--um-maize);
  margin: 1.5rem 0;
  padding: 0.2rem 0 0.2rem 1.2rem;
  color: var(--ink-soft);
}

/* ============================================================
   Top navigation — U-M blue bar, maize active accent
   JS-free: each part is a <details> dropdown.
   ============================================================ */
.site-nav {
  background: var(--um-blue);
  color: #fff;
  font-family: var(--font-head);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
}
.site-nav .nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1.5rem;
}
.site-nav .brand {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.85rem 0;
  margin-right: auto;
  border-bottom: 3px solid transparent;
}
.site-nav .brand:hover { border-bottom-color: var(--um-maize); }

.nav-collapse { display: inline; }
.nav-burger {
  list-style: none;
  cursor: pointer;
  color: #fff;
  font-weight: 600;
  padding: 0.85rem 0;
}
.nav-burger::-webkit-details-marker { display: none; }
.burger-icon { font-size: 1.2rem; }

.nav-menu {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0;
  padding: 0;
}

/* ---- Desktop (>=800px): menu always visible inline, no hamburger ---- */
@media (min-width: 800px) {
  .nav-burger { display: none; }
  .nav-collapse::details-content {     /* show regardless of open state */
    content-visibility: visible;
    display: contents;
  }
}

/* ---- Mobile (<800px): hamburger toggles a stacked menu ---- */
@media (max-width: 799px) {
  .nav-collapse { margin-left: auto; }
  .nav-menu { flex-direction: column; width: 100%; padding-bottom: 0.5rem; }
  .nav-menu > li { width: 100%; }
  .nav-menu details > summary { display: block; }
  .nav-dropdown { box-shadow: none; border-top: none; background: var(--um-blue-deep); }
  .nav-dropdown a { color: #fff; padding-left: 2rem; }
  .nav-dropdown a:hover, .nav-dropdown a:focus { background: rgba(255,255,255,0.12); }
}
.nav-menu > li { position: relative; }

.nav-menu details > summary {
  list-style: none;
  cursor: pointer;
  color: #fff;
  padding: 0.85rem 0.9rem;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.nav-menu details > summary::-webkit-details-marker { display: none; }
.nav-menu details > summary::after { content: " \25BE"; opacity: 0.7; font-size: 0.8em; }
.nav-menu details > summary:hover { background: var(--um-blue-deep); border-bottom-color: var(--um-maize); }

.nav-menu details[open] > summary { background: var(--um-blue-deep); border-bottom-color: var(--um-maize); }

.nav-dropdown {
  list-style: none;
  margin: 0;
  padding: 0.4rem 0;
  background: #fff;
  min-width: 16rem;
  box-shadow: 0 6px 18px rgba(0,0,0,0.22);
  border-top: 3px solid var(--um-maize);
}
@media (min-width: 800px) {
  .nav-dropdown { position: absolute; left: 0; top: 100%; }
}
.nav-dropdown a {
  display: block;
  color: var(--um-blue);
  text-decoration: none;
  font-size: 1rem;
  padding: 0.45rem 1rem;
}
.nav-dropdown a:hover,
.nav-dropdown a:focus { background: var(--um-blue-tint); }
.nav-dropdown a[aria-current="page"] {
  font-weight: 700;
  border-left: 4px solid var(--um-maize);
  padding-left: calc(1rem - 4px);
}

/* ---------- chapter meta / PDF button ---------- */
.chapter-meta {
  font-family: var(--font-head);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  align-items: baseline;
  margin-bottom: 1.5rem;
  color: var(--ink-soft);
}
.chapter-meta .updated { font-size: 0.9rem; color: var(--ink-soft); }
/* dot separator between byline and date when both present */
.chapter-meta .byline + .updated::before {
  content: "•";
  margin-right: 1rem;
  color: var(--rule);
}
.pdf-button {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--um-blue);
  color: #fff !important;
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: 4px;
}
.pdf-button:hover { background: var(--um-blue-deep); }

/* chapter footer holding the per-chapter PDF download */
.chapter-footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--um-maize);
}

/* ============================================================
   Home / index page
   ============================================================ */
.home-authors { color: var(--ink-soft); font-family: var(--font-head); }
.book-callout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--um-blue-tint);
  border-left: 5px solid var(--um-maize);
  padding: 1.2rem 1.4rem;
  margin: 2rem 0;
}
.book-callout h2 { margin: 0 0 0.2rem; }
.book-callout p { margin: 0; color: var(--ink-soft); }
.chapter-list { list-style: none; padding-left: 0; }
.chapter-list li { font-size: 1.125rem; padding: 0.15rem 0; }
.chapter-list li a { text-decoration: none; }
.chapter-list li a:hover { text-decoration: underline; }
.home-footer {
  margin-top: 3rem; padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-head); font-size: 0.9rem; color: var(--ink-soft);
}

/* ============================================================
   Sidenotes & marginnotes — checkbox-hack disclosure
   (label + checkbox + span are all phrasing content, so the marker stays
   inline inside the paragraph — <details> cannot, it gets ejected from <p>.)
   Desktop (>=1000px): note always shown, floated into the right margin.
   Mobile: note hidden (but kept in the a11y tree); tap the marker to expand.
   ============================================================ */

/* clickable inline marker */
.note-toggle { cursor: pointer; }
.sn-num,
.mn-mark {
  color: var(--um-blue-link);
  font-weight: 700;
  font-size: 0.7em;
  vertical-align: super;
  line-height: 0;
}
.mn-mark { font-weight: 400; }

/* checkbox: visually hidden but keyboard-focusable + in the a11y tree */
.note-toggle-input {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.sidenote, .marginnote {
  font-family: var(--font-head);
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--ink-soft);
}
.sn-num-prefix { font-weight: 700; color: var(--um-blue); }

/* keyboard focus feedback (the hidden checkbox's adjacent note) */
.note-toggle-input:focus-visible + .sidenote,
.note-toggle-input:focus-visible + .marginnote {
  outline: 3px solid var(--um-blue-link);
  outline-offset: 2px;
}

/* ---- Mobile (<1000px): collapsed, tap-to-expand ---- */
@media (max-width: 999px) {
  /* hidden but readable by screen readers (clip, not display:none) */
  .sidenote, .marginnote {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
  }
  .note-toggle-input:checked + .sidenote,
  .note-toggle-input:checked + .marginnote {
    position: static;
    width: auto; height: auto;
    overflow: visible;
    clip: auto; clip-path: none;
    display: block;
    background: var(--um-blue-tint);
    border-left: 3px solid var(--um-maize);
    padding: 0.6rem 0.8rem;
    margin: 0.5rem 0 0.8rem 1.2rem;
  }
}

/* ---- Desktop (>=1000px): always shown, floated into the margin ---- */
@media (min-width: 1000px) {
  article { padding-right: var(--gutter); position: relative; }
  .sidenote, .marginnote {
    display: block;
    float: right;
    clear: right;
    width: var(--note-width);
    margin-right: var(--note-pull);
    margin-top: 0.1rem;
    margin-bottom: 1rem;
  }
}

/* ============================================================
   Figures
   ============================================================ */
figure { margin: 1.5rem 0; }
figure img { max-width: 100%; height: auto; display: block; }
figcaption {
  font-family: var(--font-head);
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.4;
  margin-top: 0.4rem;
}

figure.figure { max-width: 100%; }

/* margin figures + margin tables float into the gutter on desktop */
@media (min-width: 1000px) {
  figure.marginfigure,
  figure.margintable {
    float: right;
    clear: right;
    width: var(--note-width);
    margin-right: var(--note-pull);
    margin-top: 0.2rem;
  }
}

/* margin tables: compact, full available width of their column */
figure.margintable { margin: 1.2rem 0; }
figure.margintable table { width: 100%; font-size: 0.95rem; }
figure.margintable figcaption { margin-top: 0.3rem; }

/* ============================================================
   Tables — booktabs feel, responsive scroll on small screens
   ============================================================ */
table {
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 1rem;
  width: auto;
}
.table-wrap, figure > table { overflow-x: auto; display: block; }
th, td { padding: 0.5rem 0.9rem; text-align: left; }
thead th { border-bottom: 2px solid var(--um-blue); font-family: var(--font-head); }
tbody tr + tr td { border-top: 1px solid var(--rule); }

/* ============================================================
   Accessibility helpers (carried over from existing site)
   ============================================================ */
.skip-link {
  position: absolute;
  top: -3rem; left: 0.5rem;
  background: var(--um-blue);
  color: #fff;
  padding: 0.5rem 1rem;
  text-decoration: none;
  z-index: 10000;
  border-radius: 0 0 4px 4px;
  transition: top 0.12s;
}
.skip-link:focus { top: 0; }

a:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--um-blue-link);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ============================================================
   Print — the typeset PDF is the canonical print artifact, but
   make the HTML degrade sanely too: drop nav, expand notes.
   ============================================================ */
@media print {
  .site-nav, .pdf-button, .skip-link { display: none; }
  article { padding-right: 0; }
  details.sidenote > .sn-body,
  details.marginnote > .mn-body { display: block; float: none; width: auto; margin: 0.4rem 0; }
}
