/* ------------------------------------------------------------------
   Design tokens
------------------------------------------------------------------ */
:root {
  --bg:        #ffffff;
  --bg-soft:   #f4f6f8;
  --bg-panel:  #ffffff;
  --border:    #d8dee5;
  --border-strong: #b3bdc7;
  --text:      #16202b;
  --text-soft: #56636f;
  --text-mute: #79858f;
  --accent:    #0b6b5e;
  --accent-bg: #e6f2f0;
  --accent-strong: #084f45;
  --warn-bg:   #fdf4e3;
  --warn-bd:   #e6cf9c;
  --radius:    8px;
  /* rem, not ch: `ch` resolves against each element's own font-size, so
     headings would get a much wider column than body text and stop aligning. */
  --measure:   40rem;
  --wide:      920px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #12171d;
    --bg-soft:   #1a2129;
    --bg-panel:  #1a2129;
    --border:    #2f3945;
    --border-strong: #46525f;
    --text:      #e6ebf0;
    --text-soft: #a9b4bf;
    --text-mute: #8a95a0;
    --accent:    #4fd1bd;
    --accent-bg: #16302d;
    --accent-strong: #7fe3d3;
    --warn-bg:   #2b2416;
    --warn-bd:   #5c4a22;
  }
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.62;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--wide); margin: 0 auto; padding: 0 20px; }

/* Everything in the content column is centred on the page, not flush left.
   The catch-all picks up headings and paragraphs that sit loose in <main>. */
.prose,
.col { max-width: var(--measure); margin-inline: auto; }
main .wrap > h2,
main .wrap > h3,
main .wrap > p { max-width: var(--measure); margin-inline: auto; }

h1, h2, h3, h4 { line-height: 1.25; font-weight: 700; letter-spacing: -0.011em; }
h1 { font-size: clamp(1.75rem, 1.3rem + 2vw, 2.5rem); margin: 0 0 .5rem; }
h2 { font-size: clamp(1.3rem, 1.15rem + .7vw, 1.6rem); margin: 2.6rem 0 .7rem; }
h3 { font-size: 1.09rem; margin: 1.9rem 0 .45rem; }
h4 { font-size: .97rem; margin: 1.4rem 0 .35rem; }
p  { margin: 0 0 1.05rem; }
ul, ol { margin: 0 0 1.05rem; padding-left: 1.3rem; }
li { margin-bottom: .4rem; }
strong { font-weight: 650; }

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

code, .num { font-family: var(--mono); font-size: .93em; font-variant-numeric: tabular-nums; }

hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }

.lede { font-size: 1.09rem; color: var(--text-soft); max-width: var(--measure); }
.muted { color: var(--text-mute); font-size: .87rem; }
.small { font-size: .87rem; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* ------------------------------------------------------------------
   Header / nav / footer
------------------------------------------------------------------ */
.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 20;
}
.site-header .wrap {
  display: flex; align-items: center; gap: 1.4rem;
  min-height: 56px; flex-wrap: wrap;
}
.brand {
  font-weight: 700; font-size: 1rem; letter-spacing: -0.02em;
  color: var(--text); text-decoration: none; white-space: nowrap;
}
.brand span { color: var(--accent); }
.site-nav { display: flex; gap: 1.1rem; margin-left: auto; flex-wrap: wrap; }
.site-nav a {
  font-size: .92rem; color: var(--text-soft); text-decoration: none; padding: 4px 0;
  border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--text); }
.site-nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

.skip {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff; padding: 10px 16px; z-index: 100;
}
.skip:focus { left: 0; }

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 4rem; padding: 2rem 0 3rem;
  font-size: .88rem; color: var(--text-mute);
}
.site-footer .cols { display: flex; gap: 2.5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.site-footer h4 { margin: 0 0 .5rem; font-size: .82rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-soft); }
.site-footer ul { list-style: none; padding: 0; margin: 0; }
.site-footer li { margin-bottom: .3rem; }
.site-footer a { color: var(--text-soft); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

main { padding: 2.2rem 0 0; }

.breadcrumb { font-size: .85rem; color: var(--text-mute); margin-bottom: 1rem; }
.breadcrumb a { color: var(--text-soft); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* ------------------------------------------------------------------
   Calculator: kJ <-> kcal
------------------------------------------------------------------ */
.calc {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-panel);
  padding: 1.25rem;
  margin: 1.5rem auto 1.75rem;
  max-width: 720px;
}
.calc-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: .75rem;
  align-items: end;
}
@media (max-width: 560px) {
  .calc-grid { grid-template-columns: 1fr; }
  .swap-cell { justify-self: start; }
}

.field label {
  display: block; font-size: .82rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-soft); margin-bottom: .35rem;
}
.field input[type="number"], .field input[type="text"], .field select {
  width: 100%;
  font-family: var(--mono);
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
  padding: .6rem .7rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  min-height: 48px;
}
.field select { font-family: var(--sans); font-size: 1rem; }
.field input:focus { border-color: var(--accent); }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

.swap-cell { padding-bottom: .35rem; }
.swap-btn {
  border: 1px solid var(--border-strong); background: var(--bg-soft); color: var(--text-soft);
  border-radius: 6px; width: 44px; height: 48px; cursor: pointer;
  font-size: 1.05rem; line-height: 1; display: flex; align-items: center; justify-content: center;
}
.swap-btn:hover { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }

.calc-out {
  margin-top: .9rem; padding-top: .9rem; border-top: 1px solid var(--border);
  font-size: .92rem; color: var(--text-soft);
  display: flex; gap: 1.5rem; flex-wrap: wrap;
}
.calc-out b { color: var(--text); font-family: var(--mono); font-weight: 600; }

.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .9rem; }
.chip {
  font-family: var(--mono); font-size: .84rem;
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--text-soft);
  border-radius: 999px; padding: .3rem .7rem; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-bg); }

.formula {
  background: var(--bg-soft); border-left: 3px solid var(--accent);
  padding: .85rem 1rem; margin: 1.2rem 0; border-radius: 0 6px 6px 0;
  font-family: var(--mono); font-size: .95rem; overflow-x: auto;
}
.formula .r { display: block; margin: .2rem 0; white-space: nowrap; }

.note {
  background: var(--warn-bg); border: 1px solid var(--warn-bd);
  border-radius: 6px; padding: .85rem 1rem; margin: 1.2rem auto;
  font-size: .93rem; max-width: var(--measure);
}
.note p:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------------
   Tables
------------------------------------------------------------------ */
.table-scroll { overflow-x: auto; margin: 1.2rem auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--border); }
th {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-soft); font-weight: 650; white-space: nowrap;
}
td.n, th.n { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
th.n { font-family: var(--sans); }
tbody tr:hover { background: var(--bg-soft); }
table caption { text-align: left; font-size: .85rem; color: var(--text-mute); padding-bottom: .5rem; }

.nutri-table td:first-child { width: 45%; }
.nutri-table tr.head td {
  font-weight: 700; background: var(--bg-soft); font-size: .8rem;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-soft);
}
.nutri-table tr.sub td:first-child { padding-left: 1.7rem; color: var(--text-soft); }
.nutri-table tr.total td { font-weight: 700; border-bottom-width: 2px; border-bottom-color: var(--border-strong); }
.dv { color: var(--text-mute); font-size: .85em; }

/* ------------------------------------------------------------------
   Cards / grids
------------------------------------------------------------------ */
.cards { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  margin: 1.4rem auto; max-width: 760px; }
.card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1rem; text-decoration: none; color: inherit; display: block;
  background: var(--bg-panel);
}
.card:hover { border-color: var(--accent); background: var(--accent-bg); }
.card b { display: block; font-size: 1rem; margin-bottom: .15rem; }
.card .k { font-family: var(--mono); color: var(--accent); font-weight: 600; }
.card .s { font-size: .84rem; color: var(--text-mute); }

.searchbar {
  width: 100%; max-width: 420px; font-size: 1rem; padding: .6rem .8rem;
  border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--bg); color: var(--text); margin: 1rem auto .3rem; min-height: 44px; display: block;
}

/* ------------------------------------------------------------------
   FAQ
------------------------------------------------------------------ */
.faq { max-width: var(--measure); margin: 1.2rem auto; }
.faq details {
  border-bottom: 1px solid var(--border); padding: .2rem 0;
}
.faq summary {
  cursor: pointer; padding: .75rem 0; font-weight: 600; list-style: none;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--accent); font-size: 1.25rem; font-weight: 400; }
.faq details[open] summary::after { content: "\2212"; }
.faq details > *:not(summary) { padding-bottom: .4rem; }

/* ------------------------------------------------------------------
   Misc
------------------------------------------------------------------ */
.tabs { display: flex; gap: .3rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--text-soft);
  padding: .4rem .85rem; border-radius: 6px; cursor: pointer; font-size: .9rem;
}
.tab[aria-selected="true"] { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.result-box {
  border: 1px solid var(--accent); background: var(--accent-bg);
  border-radius: var(--radius); padding: 1.1rem 1.25rem; margin: 1.3rem 0;
}
.result-box .big {
  font-family: var(--mono); font-size: clamp(1.8rem, 1.4rem + 2vw, 2.4rem);
  font-weight: 700; color: var(--accent-strong); line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.result-box .sub { font-size: .92rem; color: var(--text-soft); margin-top: .2rem; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 1.1rem 1.8rem; }
/* Unit sits tight against its number; the wide gap belongs between tiles. */
.result-box .big { white-space: nowrap; }
.result-box .u { font-size: .5em; margin-left: .09em; font-weight: 600; letter-spacing: 0; }

.macro-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; margin: .6rem 0 .5rem; background: var(--bg-soft); }
.macro-bar i { display: block; height: 100%; }
.macro-p { background: #2f7ec4; } .macro-c { background: #d99a2b; } .macro-f { background: #c0562f; }
.macro-key { display: flex; gap: 1.1rem; flex-wrap: wrap; font-size: .86rem; color: var(--text-soft); }
.macro-key span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: .35rem; }
.macro-key .p::before { background: #2f7ec4; }
.macro-key .c::before { background: #d99a2b; }
.macro-key .f::before { background: #c0562f; }

.toc {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .9rem 1.1rem; margin: 1.6rem auto; background: var(--bg-soft);
  max-width: var(--measure); font-size: .92rem;
}
.toc b { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-soft); margin-bottom: .45rem; }
.toc ol { margin: 0; padding-left: 1.2rem; }
.toc li { margin-bottom: .2rem; }

.inline-list { display: flex; gap: .5rem; flex-wrap: wrap; list-style: none; padding: 0; }
.inline-list a {
  font-size: .88rem; border: 1px solid var(--border); border-radius: 999px;
  padding: .25rem .7rem; text-decoration: none; color: var(--text-soft); display: inline-block;
}
.inline-list a:hover { border-color: var(--accent); color: var(--accent); }

/* Must beat inline display:contents on the metric/imperial field groups. */
[hidden] { display: none !important; }

.js-only { display: none; }
.has-js .js-only { display: block; }
.has-js .no-js { display: none; }
