/* ============================================================
   Nutrition Course — shared stylesheet
   Every lesson and reference document links this file.
   Goal: one consistent course, readable on a phone, prints well.
   ============================================================ */

:root {
  --paper:      #fdfbf6;
  --paper-sunk: #f5f1e8;
  --ink:        #2b2622;
  --ink-soft:   #6b6259;
  --rule:       #e0d8c9;

  --green:      #4a7c4e;   /* protein, good, correct */
  --green-pale: #eaf2ea;
  --amber:      #b8791f;   /* caution, portion warnings */
  --amber-pale: #fbf1e0;
  --red:        #a8412f;   /* limits, wrong answers */
  --red-pale:   #f8eae7;
  --blue:       #3c6382;   /* neutral highlight, numbers */
  --blue-pale:  #e9eff4;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans:  ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono:  ui-monospace, "Cascadia Mono", Consolas, monospace;

  --measure: 34rem;
}

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

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

body {
  margin: 0;
  padding: 0 1.25rem 6rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.62;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}

/* ---------- Layout ---------- */

.wrap { max-width: var(--measure); margin: 0 auto; }
.wide { max-width: 44rem; margin-left: auto; margin-right: auto; }

/* ---------- Masthead ---------- */

.masthead {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 3rem 0 1.25rem;
  border-bottom: 2px solid var(--ink);
}

.eyebrow {
  font-family: var(--sans);
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 .6rem;
}

h1 {
  font-size: clamp(1.9rem, 6vw, 2.6rem);
  line-height: 1.12;
  font-weight: 600;
  margin: 0 0 .5rem;
  letter-spacing: -.015em;
}

.standfirst {
  font-size: 1.08rem;
  color: var(--ink-soft);
  font-style: italic;
  margin: 0 0 .5rem;
}

/* ---------- Headings ---------- */

h2 {
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.2;
  margin: 3rem 0 .3rem;
  letter-spacing: -.01em;
}

h2 .num {
  display: block;
  font-family: var(--sans);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: .35rem;
}

h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 2rem 0 .3rem;
}

h4 {
  font-family: var(--sans);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 1.5rem 0 .4rem;
}

p { margin: 0 0 1.05rem; }

.lede { font-size: 1.14rem; }

/* ---------- Inline ---------- */

strong { font-weight: 700; }

em { font-style: italic; }

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

/* An English technical term, first time it appears */
.term {
  font-weight: 700;
  color: var(--green);
  font-style: normal;
}

/* A number worth noticing */
.fig {
  font-family: var(--sans);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--blue);
}

/* ---------- Callouts ---------- */

.box {
  border-left: 3px solid var(--rule);
  background: var(--paper-sunk);
  padding: 1rem 1.15rem;
  margin: 1.75rem 0;
  border-radius: 0 5px 5px 0;
}
.box > :last-child { margin-bottom: 0; }
.box p:first-child { margin-top: 0; }

.box .label {
  display: block;
  font-family: var(--sans);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  margin-bottom: .5rem;
}

.box--key    { border-left-color: var(--green); background: var(--green-pale); }
.box--key .label { color: var(--green); }

.box--warn   { border-left-color: var(--amber); background: var(--amber-pale); }
.box--warn .label { color: var(--amber); }

.box--limit  { border-left-color: var(--red); background: var(--red-pale); }
.box--limit .label { color: var(--red); }

.box--source { border-left-color: var(--blue); background: var(--blue-pale); font-size: .92rem; }
.box--source .label { color: var(--blue); }

/* ---------- Tables ---------- */

.tablewrap { overflow-x: auto; margin: 1.75rem 0; -webkit-overflow-scrolling: touch; }

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 22rem;
  font-family: var(--sans);
  font-size: .87rem;
}

caption {
  caption-side: top;
  text-align: left;
  font-family: var(--sans);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding-bottom: .55rem;
}

th {
  text-align: left;
  font-weight: 700;
  font-size: .74rem;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border-bottom: 1.5px solid var(--ink);
  padding: .45rem .55rem;
  vertical-align: bottom;
}

td {
  padding: .45rem .55rem;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}

td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

tbody tr:hover { background: var(--paper-sunk); }

tr.total td {
  font-weight: 700;
  border-top: 1.5px solid var(--ink);
  border-bottom: none;
  background: var(--green-pale);
}

.good { color: var(--green); font-weight: 700; }
.bad  { color: var(--red);   font-weight: 700; }

/* ---------- Lists ---------- */

ul, ol { margin: 0 0 1.05rem; padding-left: 1.35rem; }
li { margin-bottom: .4rem; }
li > ul, li > ol { margin-top: .4rem; margin-bottom: .4rem; }

/* Comparison pair: do this, not that */
.swap {
  display: grid;
  grid-template-columns: 1fr;
  gap: .75rem;
  margin: 1.75rem 0;
}
@media (min-width: 33rem) { .swap { grid-template-columns: 1fr 1fr; } }

.swap > div { padding: .9rem 1rem; border-radius: 5px; font-size: .95rem; }
.swap > div > :last-child { margin-bottom: 0; }
.swap .no  { background: var(--red-pale);   border-left: 3px solid var(--red); }
.swap .yes { background: var(--green-pale); border-left: 3px solid var(--green); }
.swap h5 {
  font-family: var(--sans); font-size: .7rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase; margin: 0 0 .4rem;
}
.swap .no h5  { color: var(--red); }
.swap .yes h5 { color: var(--green); }

/* ---------- Meal plan cards ---------- */

.meal {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1rem 1.15rem;
  margin: 1.1rem 0;
  background: #fff;
}
.meal h3 {
  margin: 0 0 .15rem;
  font-family: var(--sans);
  font-size: .95rem;
  letter-spacing: .01em;
}
.meal .time {
  font-family: var(--sans); font-size: .7rem; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase; color: var(--amber);
  margin-bottom: .6rem;
}
.meal table { font-size: .84rem; min-width: 0; }
.meal > :last-child { margin-bottom: 0; }

/* ---------- Progress / footer nav ---------- */

.nav {
  max-width: var(--measure);
  margin: 4rem auto 0;
  padding-top: 1.25rem;
  border-top: 2px solid var(--ink);
  font-family: var(--sans);
  font-size: .87rem;
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1.5rem;
  justify-content: space-between;
}
.nav a { text-decoration: none; font-weight: 600; }
.nav a:hover { text-decoration: underline; }

.ask {
  max-width: var(--measure);
  margin: 2.5rem auto 0;
  padding: 1rem 1.15rem;
  border: 1.5px dashed var(--green);
  border-radius: 6px;
  background: var(--green-pale);
  font-size: .95rem;
}
.ask > :last-child { margin-bottom: 0; }
.ask strong { color: var(--green); }

/* ---------- Source list ---------- */

.sources {
  max-width: var(--measure);
  margin: 2.5rem auto 0;
  font-size: .82rem;
  color: var(--ink-soft);
  font-family: var(--sans);
  line-height: 1.5;
}
.sources h4 { margin-top: 0; }
.sources ol { padding-left: 1.2rem; }
.sources li { margin-bottom: .5rem; }

/* ---------- Quiz widget (assets/quiz.js) ---------- */

.quiz {
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  padding: 1.15rem 1.25rem;
  margin: 2rem 0;
  background: #fff;
}

.quiz .qlabel {
  font-family: var(--sans);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: .5rem;
}

.quiz .qtext { font-weight: 600; margin-bottom: .85rem; }

.quiz .opts { display: grid; gap: .45rem; }

.quiz button.opt {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--sans);
  font-size: .92rem;
  line-height: 1.4;
  padding: .65rem .8rem;
  border: 1.5px solid var(--rule);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.quiz button.opt:hover:not(:disabled) { border-color: var(--ink-soft); background: var(--paper-sunk); }
.quiz button.opt:disabled { cursor: default; }

.quiz button.opt.is-right {
  border-color: var(--green); background: var(--green-pale); font-weight: 700;
}
.quiz button.opt.is-wrong {
  border-color: var(--red); background: var(--red-pale); text-decoration: line-through;
}

.quiz .fb {
  margin-top: .85rem;
  padding: .7rem .85rem;
  border-radius: 5px;
  font-size: .93rem;
  display: none;
}
.quiz .fb.show { display: block; }
.quiz .fb.right { background: var(--green-pale); border-left: 3px solid var(--green); }
.quiz .fb.wrong { background: var(--amber-pale); border-left: 3px solid var(--amber); }

.quiz-score {
  font-family: var(--sans);
  font-size: .9rem;
  font-weight: 700;
  text-align: center;
  padding: .9rem;
  margin: 2rem 0;
  border-radius: 6px;
  background: var(--paper-sunk);
  border: 1.5px solid var(--rule);
}

/* ---------- Calculator widget (assets/calorie-calculator.js) ---------- */

.calc {
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  padding: 1.25rem;
  margin: 2rem 0;
  background: #fff;
}

.calc .row {
  display: grid;
  grid-template-columns: 1fr;
  gap: .35rem;
  margin-bottom: .9rem;
}
@media (min-width: 30rem) {
  .calc .row { grid-template-columns: 8.5rem 1fr; align-items: center; gap: .75rem; }
}

.calc label {
  font-family: var(--sans);
  font-size: .84rem;
  font-weight: 600;
}

.calc input[type="number"], .calc select {
  font-family: var(--sans);
  font-size: .95rem;
  padding: .5rem .6rem;
  border: 1.5px solid var(--rule);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  width: 100%;
}
.calc input:focus, .calc select:focus { outline: 2px solid var(--blue); outline-offset: 1px; }

.calc .segs { display: flex; gap: .4rem; flex-wrap: wrap; }
.calc .segs button {
  font-family: var(--sans); font-size: .88rem; font-weight: 600;
  padding: .5rem .9rem; border: 1.5px solid var(--rule); border-radius: 5px;
  background: var(--paper); color: var(--ink); cursor: pointer;
}
.calc .segs button[aria-pressed="true"] {
  background: var(--green); border-color: var(--green); color: #fff;
}

.calc .out { margin-top: 1.25rem; padding-top: 1.1rem; border-top: 1.5px solid var(--ink); }

.calc .out .hint {
  font-family: var(--sans); font-size: .86rem; color: var(--ink-soft);
  text-align: center; padding: 1rem 0;
}

.calc .results { display: grid; gap: .55rem; }

.calc .res {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding: .7rem .85rem; border-radius: 5px; background: var(--paper-sunk);
  border-left: 3px solid var(--rule);
}
.calc .res.hero { background: var(--green-pale); border-left-color: var(--green); }
.calc .res.pick { background: var(--blue-pale);  border-left-color: var(--blue); }

.calc .res .k { font-family: var(--sans); font-size: .84rem; font-weight: 600; }
.calc .res .k small { display: block; font-weight: 400; color: var(--ink-soft); font-size: .78rem; }
.calc .res .v {
  font-family: var(--sans); font-size: 1.35rem; font-weight: 700;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.calc .res .v small { font-size: .72rem; font-weight: 600; color: var(--ink-soft); }

/* ---------- Print ---------- */

@media print {
  :root { --paper: #fff; --paper-sunk: #f4f4f4; }
  html { font-size: 11pt; }
  body { padding: 0; background: #fff; }
  .masthead { padding-top: 0; }
  .nav, .ask, .quiz .opts, .calc .segs { display: none; }
  .quiz, .calc, .meal, .box, table { break-inside: avoid; }
  h2, h3 { break-after: avoid; }
  .tablewrap { overflow: visible; }
  a { color: var(--ink); text-decoration: none; }
  .sources a::after { content: " (" attr(href) ")"; font-size: .8em; word-break: break-all; }
  .box, .meal, .quiz { border: 1px solid #bbb; }
}
