/* =========================================================================
   Vegan Food Science — Design System
   A clean, magazine-inspired interface for learning plant-based food science.
   ========================================================================= */

:root {
  /* Palette — herb garden meets laboratory */
  --leaf-50:  #f3f8f1;
  --leaf-100: #e2efdc;
  --leaf-200: #c4dfb6;
  --leaf-300: #99c685;
  --leaf-400: #6dac57;
  --leaf-500: #4a9038;
  --leaf-600: #36732a;
  --leaf-700: #2c5b24;
  --leaf-800: #244820;
  --leaf-900: #1a3318;

  --cream-50:  #fdfaf3;
  --cream-100: #f7f0df;
  --cream-200: #ede1c4;

  --terra-400: #d97757;
  --terra-500: #c25b3a;
  --terra-600: #a4452a;

  --berry-500: #8c3a5e;
  --gold-500:  #d6a83a;
  --ink-900:   #14201a;
  --ink-700:   #2f3a35;
  --ink-500:   #5a6660;
  --ink-300:   #8a958f;
  --paper:     #fcfbf6;
  --paper-2:   #f5f2e8;
  --line:      #e1ddd0;

  /* Semantic */
  --bg:        var(--paper);
  --bg-alt:    var(--paper-2);
  --surface:   #ffffff;
  --text:      var(--ink-900);
  --text-soft: var(--ink-500);
  --border:    var(--line);
  --accent:    var(--leaf-600);
  --accent-soft: var(--leaf-100);
  --hot:       var(--terra-500);

  /* Typography */
  --font-serif: "Fraunces", "Iowan Old Style", "Apple Garamond", Georgia, serif;
  --font-sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono:  "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Layout */
  --maxw:      1180px;
  --maxw-prose: 720px;
  --radius:    14px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(20, 32, 26, 0.06), 0 1px 1px rgba(20, 32, 26, 0.04);
  --shadow:    0 6px 24px rgba(20, 32, 26, 0.08), 0 2px 6px rgba(20, 32, 26, 0.04);
  --shadow-lg: 0 24px 48px rgba(20, 32, 26, 0.14), 0 8px 16px rgba(20, 32, 26, 0.06);
}

[data-theme="dark"] {
  --bg:        #0f1814;
  --bg-alt:    #16221c;
  --surface:   #1c2a23;
  --text:      #f3eedf;
  --text-soft: #b9c3bb;
  --border:    #324438;
  --accent:    #9ed184;
  --accent-soft: #2a3f33;
  --hot:       #e69072;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow:    0 8px 26px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.6);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  html { scroll-behavior: auto; }
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.65;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; display: block; }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color .15s ease, color .15s ease; }
a:hover { border-bottom-color: currentColor; }
h1, h2, h3, h4 { font-family: var(--font-serif); font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; color: var(--text); }
h1 { font-size: clamp(2.2rem, 4.6vw, 3.8rem); margin: 0 0 .5em; }
h2 { font-size: clamp(1.6rem, 2.6vw, 2.2rem); margin: 2em 0 .6em; }
h3 { font-size: 1.25rem; margin: 1.6em 0 .4em; }
h4 { font-size: 1.05rem; margin: 1.2em 0 .3em; text-transform: uppercase; letter-spacing: .08em; color: var(--text-soft); }
p { margin: 0 0 1em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }
code { font-family: var(--font-mono); font-size: .92em; background: var(--bg-alt); padding: 0.12em 0.38em; border-radius: 4px; }
blockquote {
  margin: 1.5em 0;
  padding: 1em 1.4em;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-serif);
  font-size: 1.08em;
  font-style: italic;
  color: var(--text);
}
.container { max-width: var(--maxw); margin: 0 auto; padding: 0 1.4rem; }
.prose { max-width: var(--maxw-prose); margin: 0 auto; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: .35em 0; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: saturate(140%) blur(10px);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  border-bottom: 1px solid var(--border);
}
.topbar__inner {
  display: flex; align-items: center; justify-content: space-between;
  max-width: var(--maxw); margin: 0 auto; padding: 0.85rem 1.4rem;
  gap: 1rem;
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-family: var(--font-serif); font-weight: 600; font-size: 1.15rem; color: var(--text); border-bottom: 0; }
.brand__mark {
  width: 30px; height: 30px; display: grid; place-items: center;
  background: var(--accent); color: white; border-radius: 8px;
  font-family: var(--font-serif); font-size: 1.1rem; font-weight: 700;
}
.nav { display: flex; gap: .25rem; align-items: center; }
.nav a {
  color: var(--text-soft); border-bottom: 0;
  font-size: .95rem; padding: .45rem .8rem; border-radius: 8px;
  font-weight: 500;
}
.nav a:hover { color: var(--text); background: var(--bg-alt); }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--bg-alt); border-color: var(--text-soft); }
.menu-toggle { display: none; }

@media (max-width: 800px) {
  .nav { display: none; position: absolute; top: 100%; left: 0; right: 0;
         background: var(--surface); border-bottom: 1px solid var(--border);
         padding: .5rem 1rem 1rem; flex-direction: column; align-items: stretch; gap: .15rem; }
  .nav.open { display: flex; }
  .nav a { padding: .7rem .9rem; }
  .menu-toggle { display: grid; }
}

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden;
  padding: clamp(3rem, 8vw, 7rem) 0 clamp(2rem, 6vw, 5rem);
}
.hero::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(60% 50% at 80% 0%, color-mix(in srgb, var(--leaf-300) 25%, transparent), transparent 70%),
    radial-gradient(50% 60% at 0% 100%, color-mix(in srgb, var(--terra-400) 18%, transparent), transparent 70%);
}
.hero__kicker {
  display: inline-flex; align-items: center; gap: .5rem;
  background: var(--accent-soft); color: var(--accent);
  padding: .3rem .75rem; border-radius: 999px;
  font-size: .82rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase;
}
.hero__title { font-size: clamp(2.4rem, 6vw, 4.6rem); line-height: 1.05; margin: 1rem 0 1.2rem; max-width: 18ch; }
.hero__title em { font-style: italic; color: var(--accent); }
.hero__lede { font-size: 1.18rem; color: var(--text-soft); max-width: 56ch; margin: 0 0 1.8rem; }
.hero__cta { display: flex; gap: .8rem; flex-wrap: wrap; }
.hero__stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5rem; margin-top: 3.5rem; padding-top: 2rem; border-top: 1px solid var(--border); }
.hero__stat .n { font-family: var(--font-serif); font-size: 2rem; color: var(--accent); display: block; line-height: 1; }
.hero__stat .l { color: var(--text-soft); font-size: .88rem; }
@media (max-width: 700px) { .hero__stats { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .8rem 1.3rem; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; font-weight: 600; font-size: .98rem;
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
  text-decoration: none; border-bottom: 0; font-family: var(--font-sans);
}
.btn--primary { background: var(--accent); color: white; box-shadow: var(--shadow-sm); }
.btn--primary:hover { background: var(--leaf-700); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn--ghost:hover { background: var(--bg-alt); border-color: var(--text-soft); }
.btn--lg { padding: 1rem 1.5rem; font-size: 1.05rem; }

/* ---------- Section ---------- */
.section { padding: clamp(3rem, 6vw, 5rem) 0; }
.section--alt { background: var(--bg-alt); }
.section__head { text-align: center; margin-bottom: 3rem; }
.section__head .eyebrow { color: var(--accent); font-weight: 600; letter-spacing: .1em; text-transform: uppercase; font-size: .85rem; }
.section__head h2 { margin-top: .5rem; }
.section__head p { color: var(--text-soft); max-width: 60ch; margin: 0 auto; }

/* ---------- Cards (modules grid) ---------- */
.modules { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.2rem; }
.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.4rem 1.4rem;
  display: flex; flex-direction: column; gap: .6rem;
  transition: transform .15s ease, box-shadow .2s ease, border-color .2s ease;
  position: relative; overflow: hidden;
}
.module-card::after {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--terra-500));
  opacity: 0; transition: opacity .2s ease;
}
.module-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--accent); }
.module-card:hover::after { opacity: 1; }
.module-card a.cover-link { position: absolute; inset: 0; z-index: 1; border-bottom: 0; }
.module-card__num {
  font-family: var(--font-serif); font-size: 1.6rem; color: var(--accent);
  font-weight: 600;
}
.module-card__title { font-family: var(--font-serif); font-size: 1.25rem; font-weight: 600; color: var(--text); margin: 0; line-height: 1.25; }
.module-card__desc { color: var(--text-soft); font-size: .94rem; margin: 0; flex: 1; }
.module-card__meta { display: flex; gap: .6rem; align-items: center; color: var(--text-soft); font-size: .82rem; margin-top: .6rem; flex-wrap: wrap; }
.module-card__meta .dot { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: .4; }
.module-card .badge { background: var(--accent-soft); color: var(--accent); padding: .15rem .55rem; border-radius: 999px; font-weight: 600; font-size: .75rem; }
.module-card.completed::before {
  content: "✓"; position: absolute; top: 1rem; right: 1rem;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: white; display: grid; place-items: center;
  font-size: .9rem; font-weight: 700; z-index: 2;
}

/* ---------- Module page layout ---------- */
.module-shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 3rem; padding: 3rem 0; }

.sidebar {
  position: sticky; top: 80px; align-self: start;
  font-size: .9rem;
}
.sidebar h4 { margin-top: 0; }
.sidebar__toc { margin-bottom: 1.2rem; }
.sidebar__toc summary {
  list-style: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: .82rem; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-soft);
  padding: .25rem 0;
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar__toc summary::-webkit-details-marker { display: none; }
.sidebar__toc summary::after {
  content: "";
  width: 8px; height: 8px;
  border-right: 2px solid var(--text-soft);
  border-bottom: 2px solid var(--text-soft);
  transform: rotate(45deg);
  transition: transform .15s ease;
  display: none;
}
.sidebar__meta { padding-top: 1rem; border-top: 1px solid var(--border); }
.sidebar__meta h4 { margin: 0 0 .3rem; }
.sidebar__meta p { margin: .25rem 0; }

.toc { list-style: none; padding: 0; margin: .5rem 0 0; }
.toc li { margin: .2rem 0; }
.toc a {
  display: block; padding: .35rem .7rem; border-radius: 6px;
  color: var(--text-soft); border-bottom: 0;
}
.toc a:hover { background: var(--bg-alt); color: var(--text); }
.toc a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Mobile: sidebar in normal flow, TOC collapsed by default */
@media (max-width: 950px) {
  .module-shell { grid-template-columns: 1fr; gap: 1.2rem; padding: 1.5rem 0 2rem; }
  .sidebar {
    position: static;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .9rem 1.1rem;
  }
  .sidebar__toc summary::after { display: inline-block; margin-left: .5rem; transform: rotate(45deg) translate(-2px, -2px); }
  .sidebar__toc[open] summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
  .sidebar__toc:not([open]) .toc { display: none; }
  .sidebar__meta { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; padding-top: .8rem; }
  .sidebar__meta h4 { margin: 0; }
  .sidebar__meta p { margin: 0; }
}

.module-complete {
  margin-top: 2.5rem; padding: 1.4rem; text-align: center;
  background: var(--bg-alt); border-radius: var(--radius);
  border: 1px dashed var(--border);
}
.module-complete .btn { min-width: 240px; }

.module-header {
  margin-bottom: 2.5rem; padding-bottom: 2rem; border-bottom: 1px solid var(--border);
}
.module-header__crumbs { color: var(--text-soft); font-size: .9rem; margin-bottom: 1rem; }
.module-header__crumbs a { color: var(--text-soft); }
.module-header__title { margin: .3rem 0 .8rem; }
.module-header__lede { font-size: 1.15rem; color: var(--text-soft); max-width: 60ch; }
.pill {
  display: inline-block; padding: .25rem .7rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: .8rem; font-weight: 600; letter-spacing: .04em;
  margin-right: .4rem;
}
.pill--terra { background: color-mix(in srgb, var(--terra-400) 20%, transparent); color: var(--terra-600); }
.pill--berry { background: color-mix(in srgb, var(--berry-500) 18%, transparent); color: var(--berry-500); }
.pill--gold  { background: color-mix(in srgb, var(--gold-500) 22%, transparent); color: #8a6c1f; }

/* ---------- Callouts ---------- */
.callout {
  margin: 2rem 0; padding: 1.2rem 1.4rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}
.callout__title {
  display: flex; align-items: center; gap: .5rem;
  font-family: var(--font-serif); font-weight: 600;
  color: var(--accent); margin-bottom: .4rem;
}
.callout--lab { border-color: var(--terra-400); background: color-mix(in srgb, var(--terra-400) 6%, var(--surface)); }
.callout--lab .callout__title { color: var(--terra-600); }
.callout--key { border-left: 4px solid var(--accent); border-radius: 0 var(--radius) var(--radius) 0; }
.callout--note { background: var(--bg-alt); }
.callout--warn { border-color: var(--gold-500); background: color-mix(in srgb, var(--gold-500) 8%, var(--surface)); }
.callout--warn .callout__title { color: #8a6c1f; }

/* ---------- Lab card ---------- */
.lab {
  margin: 2.5rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.lab__head {
  background: linear-gradient(135deg, var(--terra-500), var(--terra-600));
  color: white; padding: 1.2rem 1.4rem;
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
}
.lab__head h3 { color: white; margin: 0; font-size: 1.2rem; }
.lab__head .tag { background: rgba(255,255,255,.18); padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.lab__body { padding: 1.4rem; }
.lab__body h4 { margin-top: 1.2rem; color: var(--terra-600); }
.lab__body h4:first-child { margin-top: 0; }
.lab__body ol, .lab__body ul { padding-left: 1.4em; }
.lab__body li { margin: .3em 0; }

/* ---------- Quiz ---------- */
.quiz {
  margin: 2.5rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.6rem;
  box-shadow: var(--shadow-sm);
}
.quiz__title { margin: 0 0 1rem; font-family: var(--font-serif); }
.quiz-q { margin-bottom: 1.2rem; padding-bottom: 1.2rem; border-bottom: 1px dashed var(--border); }
.quiz-q:last-of-type { border-bottom: 0; padding-bottom: 0; }
.quiz-q__q { font-weight: 600; margin-bottom: .6rem; }
.quiz-q__opts { display: flex; flex-direction: column; gap: .35rem; }
.quiz-opt {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .8rem;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  background: var(--bg); transition: background .15s, border-color .15s;
  font-size: .96rem;
}
.quiz-opt:hover { background: var(--bg-alt); }
.quiz-opt input { accent-color: var(--accent); }
.quiz-opt.correct { background: color-mix(in srgb, var(--leaf-400) 18%, var(--bg)); border-color: var(--leaf-500); }
.quiz-opt.wrong   { background: color-mix(in srgb, var(--terra-400) 18%, var(--bg)); border-color: var(--terra-500); }
.quiz-q__exp {
  margin-top: .6rem; padding: .7rem .9rem; border-radius: 8px;
  background: var(--accent-soft); color: var(--text);
  font-size: .92rem; display: none;
}
.quiz-q__exp.show { display: block; }
.quiz__actions { display: flex; gap: .6rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.quiz__score { font-weight: 600; color: var(--accent); margin-left: auto; }

/* ---------- Progress + nav between modules ---------- */
.module-progress {
  display: flex; align-items: center; gap: 1rem; margin: 2rem 0;
}
.progress-bar {
  flex: 1; height: 8px; background: var(--bg-alt);
  border-radius: 999px; overflow: hidden; position: relative;
}
.progress-bar__fill {
  height: 100%; background: linear-gradient(90deg, var(--accent), var(--terra-500));
  border-radius: 999px; transition: width .4s ease;
}
.next-prev {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
  margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border);
}
.next-prev a {
  background: var(--surface); border: 1px solid var(--border);
  padding: 1rem 1.2rem; border-radius: var(--radius);
  display: block; border-bottom: 0; transition: border-color .15s, transform .12s;
}
.next-prev a:hover { border-color: var(--accent); transform: translateY(-1px); }
.next-prev a small { color: var(--text-soft); font-size: .82rem; display: block; margin-bottom: .15rem; }
.next-prev a strong { color: var(--text); font-family: var(--font-serif); font-weight: 600; }
.next-prev .right { text-align: right; }
@media (max-width: 600px) { .next-prev { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 1.5rem 0; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
th, td { padding: .8rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--bg-alt); font-weight: 600; font-family: var(--font-sans); font-size: .88rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 50%, transparent); }

/* ---------- Glossary ---------- */
.glossary-search {
  width: 100%; padding: .9rem 1.2rem; font-size: 1rem;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  margin: 1rem 0 2rem;
}
.glossary-search:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.glossary-letter { font-family: var(--font-serif); color: var(--accent); margin: 1.6rem 0 .6rem; font-size: 1.6rem; border-bottom: 1px solid var(--border); padding-bottom: .3rem; }
.glossary-term { padding: 1rem 0; border-bottom: 1px solid var(--border); }
.glossary-term dt { font-weight: 600; font-family: var(--font-serif); font-size: 1.1rem; color: var(--text); margin-bottom: .25rem; }
.glossary-term dd { margin: 0; color: var(--text-soft); }
.glossary-term.hidden { display: none; }

/* ---------- Footer ---------- */
.footer {
  background: var(--bg-alt); border-top: 1px solid var(--border);
  padding: 3rem 0 2rem; margin-top: 4rem;
}
.footer__grid {
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 2.5rem;
}
@media (max-width: 750px) { .footer__grid { grid-template-columns: 1fr 1fr; } }
.footer h4 { margin-top: 0; font-size: .82rem; color: var(--text-soft); }
.footer ul { list-style: none; padding: 0; margin: 0; }
.footer li { margin: .3rem 0; }
.footer a { color: var(--text-soft); border-bottom: 0; }
.footer a:hover { color: var(--accent); }
.footer__bottom { border-top: 1px solid var(--border); margin-top: 2rem; padding-top: 1.2rem; color: var(--text-soft); font-size: .85rem; display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; }

/* ---------- Track timeline (curriculum) ---------- */
.track {
  display: grid; gap: 1rem;
  position: relative;
}
.track__row {
  display: grid; grid-template-columns: auto 1fr; gap: 1.5rem;
  align-items: start;
}
.track__num {
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--border);
  display: grid; place-items: center;
  font-family: var(--font-serif); font-size: 1.4rem; color: var(--accent);
  font-weight: 600; flex-shrink: 0; box-shadow: var(--shadow-sm);
}
.track__card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.2rem 1.4rem;
  transition: border-color .2s, transform .15s, box-shadow .2s;
}
.track__card:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.track__card h3 { margin: 0 0 .35rem; }
.track__card h3 a { color: var(--text); border-bottom: 0; }
.track__card h3 a:hover { color: var(--accent); }
.track__card p { margin: 0 0 .6rem; color: var(--text-soft); font-size: .96rem; }
.track__topics { display: flex; flex-wrap: wrap; gap: .35rem; }
.track__topic {
  font-size: .78rem; background: var(--bg-alt);
  color: var(--text-soft); padding: .15rem .55rem; border-radius: 999px;
}

/* ---------- Misc ---------- */
.kbd { font-family: var(--font-mono); font-size: .82em; background: var(--bg-alt); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: .05em .4em; }
.tag-row { display: flex; gap: .5rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.center { text-align: center; }
.muted { color: var(--text-soft); }
.diagram {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.2rem; margin: 1.5rem 0;
}
.diagram svg { width: 100%; height: auto; }
.fig-caption { color: var(--text-soft); font-size: .88rem; text-align: center; margin-top: .6rem; font-style: italic; }

/* Highlight reveal */
.reveal {
  opacity: 0; transform: translateY(8px);
  transition: opacity .5s ease, transform .5s ease;
}
.reveal.in { opacity: 1; transform: translateY(0); }

/* Keyboard focus */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Touch + mobile typography polish ---------- */
@media (max-width: 700px) {
  body { font-size: 18px; }
  .btn { min-height: 44px; padding: .85rem 1.2rem; }
  .icon-btn { width: 44px; height: 44px; }
  .quiz-opt { min-height: 44px; }
}

/* ---------- Reading progress (top-of-page bar on module pages) ---------- */
.read-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  background: transparent; z-index: 60; pointer-events: none;
}
.read-progress__fill {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--terra-500));
  transition: width .12s linear;
}

/* ---------- Module hero illustration ---------- */
.module-hero {
  position: relative;
  margin: -1rem 0 1.2rem;
  height: 180px;
  border-radius: var(--radius);
  background:
    radial-gradient(60% 80% at 80% 0%, color-mix(in srgb, var(--accent) 28%, transparent), transparent 70%),
    radial-gradient(50% 70% at 0% 100%, color-mix(in srgb, var(--terra-400) 22%, transparent), transparent 70%),
    var(--bg-alt);
  overflow: hidden;
  display: grid; place-items: center;
  border: 1px solid var(--border);
}
.module-hero svg { width: 70%; height: 80%; max-width: 520px; color: var(--accent); }
.module-hero__num {
  position: absolute; top: 1rem; left: 1.2rem;
  font-family: var(--font-serif); font-size: .9rem;
  letter-spacing: .15em; text-transform: uppercase; color: var(--text-soft);
}
@media (max-width: 700px) { .module-hero { height: 130px; } }

/* ---------- Search ---------- */
.search-trigger {
  display: inline-flex; align-items: center; gap: .55rem;
  padding: .35rem .7rem; border-radius: 8px;
  background: var(--bg-alt); border: 1px solid var(--border);
  color: var(--text-soft); cursor: pointer; font-size: .88rem;
  font-family: var(--font-sans); min-width: 180px; min-height: 38px;
}
.search-trigger:hover { background: var(--surface); color: var(--text); }
.search-trigger .kbd { margin-left: auto; }
@media (max-width: 800px) {
  .search-trigger { min-width: 0; padding: 0; width: 44px; height: 44px; justify-content: center; }
  .search-trigger span:not(.search-trigger__icon), .search-trigger .kbd { display: none; }
}

.search-modal {
  position: fixed; inset: 0; z-index: 100;
  background: color-mix(in srgb, #000 35%, transparent);
  display: none; align-items: flex-start; justify-content: center;
  padding: 8vh 1rem 1rem;
}
.search-modal.open { display: flex; }
.search-modal__panel {
  width: min(640px, 100%);
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  overflow: hidden; display: flex; flex-direction: column; max-height: 80vh;
}
.search-modal__input-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .9rem 1rem; border-bottom: 1px solid var(--border);
}
.search-modal__input {
  flex: 1; border: 0; background: transparent; outline: none;
  color: var(--text); font-size: 1.05rem; font-family: var(--font-sans);
}
.search-modal__close {
  background: transparent; border: 1px solid var(--border); color: var(--text-soft);
  border-radius: 6px; padding: .15rem .45rem; cursor: pointer; font-size: .82rem;
}
.search-results { overflow-y: auto; padding: .4rem; }
.search-result {
  display: block; padding: .8rem 1rem; border-radius: 8px;
  border: 1px solid transparent; border-bottom: 0; color: var(--text);
}
.search-result:hover, .search-result.active { background: var(--bg-alt); border-color: var(--border); }
.search-result strong { display: block; font-family: var(--font-serif); font-weight: 600; font-size: 1.02rem; }
.search-result small { color: var(--text-soft); font-size: .82rem; }
.search-result mark { background: color-mix(in srgb, var(--gold-500) 30%, transparent); color: inherit; padding: 0 1px; border-radius: 2px; }
.search-empty { padding: 2rem 1rem; text-align: center; color: var(--text-soft); }

/* ---------- Kitchen Mode ---------- */
.lab__kitchen-toggle {
  margin-left: auto; display: inline-flex; align-items: center; gap: .5rem;
  background: rgba(255,255,255,.2); color: white; border: 1px solid rgba(255,255,255,.35);
  padding: .5rem .9rem; border-radius: 8px; font-weight: 600; font-size: .88rem;
  cursor: pointer; font-family: var(--font-sans); min-height: 38px;
}
.lab__kitchen-toggle:hover { background: rgba(255,255,255,.28); }

body.kitchen-on { overflow: hidden; }
.kitchen-mode {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg); color: var(--text);
  display: none; flex-direction: column;
  font-size: 18px;
}
.kitchen-mode.open { display: flex; }
.kitchen-mode__bar {
  display: flex; align-items: center; gap: .8rem;
  padding: .9rem 1.1rem; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.kitchen-mode__title {
  font-family: var(--font-serif); font-weight: 600; font-size: 1.1rem;
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kitchen-mode__close {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: 40px; height: 40px; border-radius: 8px; cursor: pointer;
  display: grid; place-items: center; flex-shrink: 0;
}
.kitchen-mode__body { overflow-y: auto; padding: 1.2rem 1.2rem 6rem; flex: 1; }
.kitchen-mode__body .prose-wrap { max-width: 640px; margin: 0 auto; }
.kitchen-mode__body h4 { color: var(--accent); margin-top: 1.6rem; }
.kitchen-step {
  display: flex; gap: .9rem; align-items: flex-start;
  padding: 1rem 1.1rem; margin: .55rem 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; cursor: pointer;
  transition: background .15s, border-color .15s;
  font-size: 1.05rem; line-height: 1.45;
  user-select: none;
}
.kitchen-step:hover { background: var(--bg-alt); }
.kitchen-step__check {
  width: 26px; height: 26px; border-radius: 6px;
  border: 2px solid var(--accent); flex-shrink: 0;
  display: grid; place-items: center; margin-top: 1px;
  background: var(--bg);
}
.kitchen-step.done { opacity: .55; }
.kitchen-step.done .kitchen-step__check {
  background: var(--accent); border-color: var(--accent);
}
.kitchen-step.done .kitchen-step__check::after {
  content: "✓"; color: white; font-weight: 700; font-size: 16px; line-height: 1;
}
.kitchen-step.done .kitchen-step__text { text-decoration: line-through; }

.kitchen-timer {
  position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: .55rem .8rem .55rem 1rem;
  display: flex; align-items: center; gap: .55rem; box-shadow: var(--shadow);
  z-index: 210; font-family: var(--font-mono);
}
.kitchen-timer__display { font-size: 1.05rem; min-width: 60px; text-align: center; }
.kitchen-timer__btn {
  background: var(--accent); color: white; border: 0;
  border-radius: 999px; padding: .35rem .8rem; cursor: pointer;
  font-family: var(--font-sans); font-weight: 600; font-size: .82rem;
}
.kitchen-timer__btn--ghost { background: transparent; color: var(--text-soft); border: 1px solid var(--border); }
.kitchen-timer__presets { display: flex; gap: .25rem; }
.kitchen-timer__presets button {
  background: var(--bg-alt); border: 0; color: var(--text);
  padding: .25rem .55rem; border-radius: 999px; cursor: pointer; font-size: .78rem;
}

/* ---------- Spaced repetition (Review page) ---------- */
.review-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow-sm);
  max-width: 640px; margin: 2rem auto;
}
.review-card__meta { color: var(--text-soft); font-size: .82rem; margin-bottom: .6rem; text-transform: uppercase; letter-spacing: .08em; }
.review-card__q { font-family: var(--font-serif); font-size: 1.3rem; margin: 0 0 1.2rem; }
.review-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem;
  max-width: 640px; margin: 0 auto 1rem;
}
.review-stat {
  background: var(--bg-alt); border-radius: var(--radius-sm);
  padding: .9rem; text-align: center;
}
.review-stat__n { font-family: var(--font-serif); font-size: 1.6rem; color: var(--accent); display: block; line-height: 1; }
.review-stat__l { font-size: .78rem; color: var(--text-soft); text-transform: uppercase; letter-spacing: .06em; }
.review-empty { text-align: center; padding: 3rem 1rem; color: var(--text-soft); }
@media (max-width: 600px) { .review-stats { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Comments (giscus) ---------- */
.comments {
  margin-top: 4rem; padding-top: 2rem;
  border-top: 1px solid var(--border);
}
.comments__head { margin-bottom: 1rem; }
.comments__head h2 { margin: 0 0 .3rem; }

/* ---------- Today panel (returning visitors) ---------- */
.today {
  padding: clamp(2rem, 5vw, 4rem) 0 0;
}
.today__panel {
  background:
    radial-gradient(60% 70% at 90% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%),
    radial-gradient(50% 60% at 0% 100%, color-mix(in srgb, var(--terra-400) 14%, transparent), transparent 70%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1.4rem, 3vw, 2.4rem);
  box-shadow: var(--shadow-sm);
}
.today__greeting { margin-bottom: 1.5rem; }
.today__eyebrow { color: var(--accent); font-weight: 600; letter-spacing: .1em; text-transform: uppercase; font-size: .85rem; }
.today__title { font-family: var(--font-serif); font-size: clamp(1.5rem, 3vw, 2.1rem); margin: .35rem 0 0; }
.today__cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.today__card {
  display: flex; flex-direction: column; gap: .35rem;
  padding: 1.2rem 1.3rem;
  background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  text-decoration: none; border-bottom: 0; color: var(--text);
  transition: border-color .15s, transform .15s, box-shadow .2s;
  min-height: 120px;
}
.today__card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.today__card small { color: var(--text-soft); font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; }
.today__card strong { font-family: var(--font-serif); font-weight: 600; font-size: 1.08rem; line-height: 1.3; }
.today__card .today__cta { color: var(--accent); font-weight: 600; font-size: .92rem; margin-top: auto; }
.today__card--primary { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.today__card--fact strong { font-weight: 500; font-style: italic; font-size: 1rem; line-height: 1.4; }
.today__dismiss {
  background: transparent; border: 0; color: var(--text-soft);
  font-size: .85rem; cursor: pointer; margin-top: 1.2rem;
  text-decoration: underline; text-underline-offset: 3px;
}
.today__dismiss:hover { color: var(--text); }

/* ---------- Interactive visualizations (shared) ---------- */
.viz {
  margin: 2.5rem 0;
  padding: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.viz__head { padding: 1.4rem 1.6rem .9rem; }
.viz__tag {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
}
.viz__title { margin: .5rem 0 .3rem; font-size: 1.25rem; }
.viz__sub { color: var(--text-soft); font-size: .95rem; margin: 0; max-width: 60ch; }
.viz__body { padding: 0 1.6rem 1.4rem; }
.viz__caption { padding: .9rem 1.6rem 1.4rem; color: var(--text-soft); font-size: .85rem; font-style: italic; border-top: 1px solid var(--border); margin: 0; }

/* Maillard */
.viz-maillard__pan {
  position: relative; border-radius: var(--radius-sm); overflow: hidden;
  background: #2a1a10; margin-bottom: 1rem;
}
.viz-maillard__canvas { display: block; width: 100%; height: 200px; }
.viz-maillard__readout {
  position: absolute; top: .8rem; left: .9rem;
  background: rgba(0,0,0,0.55); color: white;
  padding: .35rem .7rem; border-radius: 999px;
  font-family: var(--font-mono); font-size: .85rem;
  display: flex; align-items: center; gap: .55rem;
}
.viz-maillard__readout .viz-maillard__phase { font-family: var(--font-sans); opacity: .85; }
.viz-maillard__label { display: block; font-size: .85rem; color: var(--text-soft); margin: .8rem 0 .3rem; }
.viz-maillard__label input[type="range"] { width: 100%; accent-color: var(--accent); }
.viz-maillard__compounds {
  list-style: none; padding: 0; margin: 1rem 0 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .5rem;
}
.viz-maillard__compounds li {
  display: flex; align-items: center; gap: .5rem;
  padding: .55rem .8rem; background: var(--bg-alt);
  border: 1px solid var(--border); border-radius: 8px;
  opacity: .35; transition: opacity .25s, border-color .25s, background .25s;
  font-size: .9rem;
}
.viz-maillard__compounds li.on {
  opacity: 1; border-color: var(--accent); background: var(--surface);
}
.viz-maillard__compounds .dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--accent));
  flex-shrink: 0; box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 30%, transparent);
}
.viz-maillard__compounds .name { font-weight: 600; }
.viz-maillard__compounds small { color: var(--text-soft); margin-left: auto; font-size: .8rem; }

/* Emulsion */
.viz-emulsion__canvas {
  display: block; width: 100%; height: auto; max-height: 320px;
  border-radius: var(--radius-sm); background: var(--bg-alt);
}
.viz-emulsion__controls,
.viz-extruder__controls {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem; margin: 1rem 0 .5rem;
}
.viz-emulsion__controls label,
.viz-extruder__controls label {
  display: flex; flex-direction: column; gap: .35rem;
  font-size: .85rem; color: var(--text-soft);
}
.viz-emulsion__controls input[type="range"],
.viz-extruder__controls input[type="range"] { accent-color: var(--accent); width: 100%; }
.viz-emulsion__val,
.viz-extruder__val { color: var(--text); font-weight: 600; font-family: var(--font-mono); font-size: .9rem; }
.viz-emulsion__readout,
.viz-extruder__readout {
  display: flex; gap: .5rem; align-items: baseline;
  background: var(--accent-soft); border-radius: var(--radius-sm);
  padding: .8rem 1rem; margin-top: .8rem;
}
.viz-emulsion__label,
.viz-extruder__label { color: var(--accent); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }
.viz-emulsion__status[data-state="breaking"],
.viz-emulsion__status[data-state="split"],
.viz-extruder__status[data-state="tvp"],
.viz-extruder__status[data-state="turbulent"] { color: var(--terra-600); }

.viz-extruder__canvas {
  display: block; width: 100%; height: auto; max-height: 240px;
  border-radius: var(--radius-sm); background: var(--bg-alt);
}

/* ---------- Modal (shared by journal + certificate) ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 220;
  background: color-mix(in srgb, #000 50%, transparent);
  display: none; align-items: flex-start; justify-content: center;
  padding: 6vh 1rem 1rem; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  width: min(560px, 100%); box-shadow: var(--shadow-lg);
  border: 1px solid var(--border); overflow: hidden;
  animation: modal-rise .25s ease;
}
@keyframes modal-rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.2rem; border-bottom: 1px solid var(--border);
}
.modal__head h3 { margin: 0; font-family: var(--font-serif); }
.modal__close {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
}
.modal__body { padding: 1.2rem; }
.modal__foot { padding: .9rem 1.2rem; display: flex; gap: .5rem; justify-content: flex-end; border-top: 1px solid var(--border); background: var(--bg-alt); }
.modal--cert { width: min(740px, 100%); }
.modal .field { display: block; margin: 1rem 0; }
.modal .field span { display: block; font-size: .85rem; color: var(--text-soft); margin-bottom: .35rem; }
.modal .field input[type="text"],
.modal .field input[type="file"],
.modal .field textarea {
  width: 100%; padding: .7rem .9rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font-family: var(--font-sans); font-size: .98rem;
}
.modal .field textarea { resize: vertical; }

.ratings { display: grid; gap: .7rem; margin: .5rem 0 1rem; }
.rating { display: grid; grid-template-columns: 100px 1fr 36px; gap: .8rem; align-items: center; font-size: .9rem; }
.rating input[type="range"] { accent-color: var(--accent); }
.rating output { font-family: var(--font-mono); color: var(--accent); font-weight: 600; }

.cert-preview { margin-top: 1rem; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: #fdfaf3; }
.cert-preview svg { display: block; width: 100%; height: auto; }

/* Lab "Log this batch" button */
.lab__journal-btn {
  display: inline-flex; align-items: center; gap: .5rem;
  background: rgba(255,255,255,.2); color: white; border: 1px solid rgba(255,255,255,.35);
  padding: .5rem .9rem; border-radius: 8px; font-weight: 600; font-size: .88rem;
  cursor: pointer; font-family: var(--font-sans); min-height: 38px;
}
.lab__journal-btn:hover { background: rgba(255,255,255,.28); }

/* Journal page */
.journal__bar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 1rem; margin: 1rem 0 2rem;
}
.journal__list { display: grid; gap: 1.5rem; }
.journal-entry {
  display: grid; grid-template-columns: 220px 1fr; gap: 1.2rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
}
@media (max-width: 700px) { .journal-entry { grid-template-columns: 1fr; } }
.journal-entry__photo {
  width: 100%; height: 100%; min-height: 160px; max-height: 240px;
  object-fit: cover;
}
.journal-entry__photo--empty { background: var(--bg-alt); }
.journal-entry__body { padding: 1.1rem 1.2rem; display: flex; flex-direction: column; gap: .6rem; }
.journal-entry__body h3 { margin: 0; font-family: var(--font-serif); font-size: 1.15rem; }
.journal-entry__body header { display: flex; justify-content: space-between; flex-wrap: wrap; align-items: baseline; gap: .5rem; }
.journal-entry__body header small { color: var(--text-soft); }
.journal-entry__ratings { display: flex; flex-wrap: wrap; gap: .35rem; }
.rating-chip {
  background: var(--accent-soft); color: var(--accent);
  padding: .2rem .6rem; border-radius: 999px; font-size: .8rem;
}
.rating-chip strong { font-weight: 600; margin-right: .3rem; }
.journal-entry__notes { color: var(--text); font-size: .95rem; margin: 0; }
.journal-entry__del {
  align-self: flex-start; background: transparent; border: 0;
  color: var(--text-soft); font-size: .85rem; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px; padding: 0;
}
.journal-entry__del:hover { color: var(--terra-600); }

/* Toast */
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink-900); color: white;
  padding: .7rem 1.1rem; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 250;
  opacity: 0; transition: opacity .2s, transform .25s;
  font-size: .92rem;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Print ---------- */
@media print {
  .topbar, .footer, .next-prev, .module-progress, .module-complete,
  .lab__kitchen-toggle, .lab__journal-btn, .nav, .icon-btn, .search-trigger, .comments,
  .read-progress, .module-hero, .today, .journal__bar [data-j-print],
  .journal-entry__del, .modal-overlay { display: none !important; }
  body { background: white !important; color: black !important; font-size: 11pt; }
  .container { max-width: none; padding: 0; }
  .module-shell { display: block; padding: 0; }
  .sidebar { display: none; }
  .lab { page-break-inside: avoid; box-shadow: none; }
  .lab__head { background: #444 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .journal-entry { page-break-inside: avoid; border: 1px solid #ccc !important; box-shadow: none !important; }
  .journal-entry__photo { max-height: 180px; }
  a { color: inherit; text-decoration: underline; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 9pt; color: #666; }
}
