/* The site's one stylesheet: light and dark, readable on a phone first. */
:root {
  /* "Lab notebook": ink-navy lines, indigo + saffron. Square corners, hard shadows, mono headings. */
  --bg: #eef4f1;
  --surface: #fafcfb;
  --text: #26303d;
  --muted: #566170;
  --line: #cfdcd6;
  --ink: #1d2b53;
  --accent: #1f6f78;
  --accent-soft: #e0ece7;
  --hot: #ff7a00;
  --pos: #0a7d4f;
  --neg: #c4261d;
  --key-bg: #fff1dc;
  --key-line: #ff7a00;
  --radius: 6px;
  --shadow: 0 2px 8px rgba(20,30,80,.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
  --heading: #111827;
  --accent-hover: #124f57;
  --input-line: #9aa5cf;
  --bar1: #1d2b53;
  --bar2: #1f6f78;
  --bar-soft: #c4cde8;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.65 var(--font);
}
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px; }
a { color: var(--accent); text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.9rem; margin: 1.6rem 0 0.6rem; }
h2 { font-size: 1.35rem; margin: 2.2rem 0 0.6rem; }
h3 { font-size: 1.05rem; margin: 0 0 0.3rem; }
p, ul, ol { margin: 0 0 1rem; }
blockquote {
  margin: 1rem 0; padding: 0.6rem 1rem;
  border-left: 4px solid var(--accent); background: var(--accent-soft); border-radius: 0 var(--radius) var(--radius) 0;
}
blockquote p { margin: 0; }

/* header and footer */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top .bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding-top: 10px; padding-bottom: 10px; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.05rem; }
nav { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; font-size: 0.95rem; flex: 1 1 auto; }
nav a { color: var(--muted); text-decoration: none; padding: 2px 0; }
nav a:hover, nav a[aria-current="page"] { color: var(--accent); }
footer { margin-top: 3rem; border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 0.85rem; }
footer .wrap { padding-top: 1.2rem; padding-bottom: 1.6rem; }
footer a { color: var(--muted); }

/* page parts */
.hero h1 { font-size: 2.1rem; margin-top: 2rem; }
.lead { font-size: 1.1rem; color: var(--muted); }
.small { font-size: 0.88rem; color: var(--muted); }
.crumbs { font-size: 0.88rem; color: var(--muted); margin: 1.2rem 0 0; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.note { padding: 0.9rem 1.1rem; border-radius: var(--radius); background: var(--accent-soft); margin: 1.2rem 0; }
.note.key { background: var(--key-bg); border: 1px solid var(--key-line); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.card {
  display: block; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--text); text-decoration: none;
}
.card:hover { border-color: var(--accent); }
.card p { margin: 0; font-size: 0.92rem; color: var(--muted); }
.card .who { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); margin-bottom: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 1.2rem 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .label { font-size: 0.85rem; color: var(--muted); }

.list { padding-left: 1.2rem; }
.list li { margin-bottom: 0.5rem; }
.articles { list-style: none; padding: 0; }
.articles li { padding: 0.7rem 0; border-bottom: 1px solid var(--line); }

/* tables scroll sideways on phones instead of breaking the page */
.table-wrap { overflow-x: auto; margin: 1rem 0 1.4rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
caption { text-align: left; padding: 8px 12px; color: var(--muted); }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 600; color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
article td, article th { white-space: normal; }

.ad { margin: 1.6rem 0; min-height: 90px; }  /* refined below */

/* calculators dropdown (works without JavaScript) */
.dropdown { position: relative; }
.dropdown summary { cursor: pointer; color: var(--muted); list-style: none; padding: 2px 0; }
.dropdown summary::-webkit-details-marker { display: none; }
.dropdown summary::after { content: " ▾"; }
.dropdown[open] summary { color: var(--accent); }
.dropdown .menu {
  position: absolute; top: 100%; left: 0; z-index: 10; margin-top: 6px; min-width: 260px; max-height: 70vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 6px;
}
.dropdown .menu a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: 0.93rem; }
.dropdown .menu a:hover { background: var(--accent-soft); }
.dropdown .menu a.all { font-weight: 600; color: var(--accent); }

/* language switch */
.switch { display: flex; gap: 4px; }
.switch a { font-size: 0.85rem; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); text-decoration: none; }
.switch a.on { background: var(--accent); border-color: var(--accent); color: #fff; }
body.lang-hi { font-family: "Noto Sans Devanagari", var(--font); }

/* calculators */
form.calc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 1.2rem 0; }
form.calc .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
form.calc label { display: flex; flex-direction: column; gap: 4px; font-size: 0.92rem; }
form.calc label span { font-weight: 600; }
form.calc small { color: var(--muted); font-size: 0.8rem; }
form.calc input, form.calc select {
  font: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); width: 100%;
}
form.calc input:focus, form.calc select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.rows { margin-top: 14px; }
.rows .row-head, .rows .row { display: grid; grid-template-columns: 28px 1fr 1fr; gap: 8px; align-items: center; margin-bottom: 6px; }
.rows .row-head { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.add-row { margin: 4px 0 6px; font: inherit; font-size: 0.9rem; padding: 7px 12px; border-radius: 8px; border: 1px dashed var(--accent); background: transparent; color: var(--accent); cursor: pointer; }
.calc-error { margin: 12px 0 0; padding: 8px 12px; border-radius: 8px; background: var(--key-bg); border: 1px solid var(--key-line); font-size: 0.92rem; }
.results { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 16px; }
.out { display: flex; flex-direction: column; }
.out span { font-size: 0.85rem; color: var(--muted); }
.out strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.out.main strong { font-size: 1.6rem; color: var(--accent); }
.split { grid-column: 1 / -1; display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--line); }
.split .inv { background: var(--muted); }
.split .gain { background: var(--accent); }

/* metal charts */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; margin: 1rem 0; }
.chart { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; font-size: 0.9rem; }
.spark { display: block; width: 100%; height: 48px; margin-top: 6px; }
.spark polyline { stroke: var(--accent); }
.spark.neg polyline { stroke: var(--neg); }
code { font-size: 0.9em; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  h1, .hero h1 { font-size: 1.6rem; }
  .top { position: static; }
  .switch { margin-left: auto; }
  nav { order: 3; flex-basis: 100%; }
  .dropdown .menu { position: fixed; left: 16px; right: 16px; top: auto; min-width: 0; }
  th, td { padding: 6px 8px; white-space: normal; }
  td.num, th { white-space: nowrap; }
  td:first-child { min-width: 7.5rem; }
}

/* ---- Setup Lab look: ink borders, hard shadows, monospace headings ---- */
/* plain solid page background: nothing behind the text competes with it */
body { background: var(--bg); }
h1, h2, h3, .brand, th, .stat .value, .out strong { font-family: var(--mono); }
h1 { font-weight: 800; letter-spacing: -0.03em; }
h2 { display: inline-block; padding: 2px 10px 2px 0; border-bottom: 3px solid var(--hot); }
.hero h1 { text-transform: none; }
.hero h1::before { content: "> "; color: var(--hot); }
.top { border-bottom: 1px solid var(--line); }
.brand { color: var(--ink); letter-spacing: 0.02em; }
nav a[aria-current="page"], nav a:hover { color: var(--text); box-shadow: inset 0 -3px 0 var(--hot); }
.dropdown[open] summary { color: var(--text); }
footer { border-top: 1px solid var(--line); }
a { text-decoration-thickness: 2px; text-decoration-color: var(--hot); }
.card, .stat, .chart, form.calc, .table-wrap, .dropdown .menu, .note {
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.card { transition: transform .08s, box-shadow .08s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(20,30,80,.12); border-color: var(--accent); }
.card .who { font-family: var(--mono); color: var(--hot); font-weight: 700; }
.note { background: var(--accent-soft); }
.note.key { background: var(--key-bg); border-color: var(--ink); border-left: 10px solid var(--hot); }
blockquote { border-left: 6px solid var(--hot); border-radius: 0; }
.stat .value { color: var(--accent); }
th { background: var(--accent-soft); color: var(--text); font-family: var(--mono); }
.table-wrap th, .table-wrap td { border-bottom: 1px solid var(--line); }
form.calc input, form.calc select { border: 1px solid var(--input-line); border-radius: 4px; background: var(--surface); }
form.calc input:focus, form.calc select:focus { outline: 3px solid var(--hot); outline-offset: 0; }
.add-row { border: 1px dashed var(--accent); border-radius: 4px; color: var(--text); }
.add-row:hover { background: var(--hot); color: #fff; border-style: solid; }
.calc-error { border: 1px solid var(--line); border-left: 10px solid var(--hot); border-radius: 0; }
.out.main strong { color: var(--accent); background: linear-gradient(transparent 62%, color-mix(in srgb, var(--hot) 40%, transparent) 62%); display: inline-block; }
.split { border-radius: 4px; border: 1px solid var(--line); height: 16px; }
.split .gain { background: var(--hot); }
.switch a { border: 1px solid var(--line); border-radius: 4px; color: var(--text); }
.switch a.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.dropdown .menu a { border-radius: 0; }
.dropdown .menu a:hover { background: var(--hot); color: #fff; }
.dropdown .menu a.all { color: var(--accent); }
code { border-radius: 0; font-family: var(--mono); border: 1px solid var(--line); }
.spark polyline { stroke: var(--accent); stroke-width: 2.5; }
article, main { background: transparent; }

/* ---- colours chosen for easy reading: soft sage-mist page (no glare), dark slate text (not pure black),
   calm teal links; header = deep navy title bar + teal menu bar ---- */
.top { background: none; border: 0; }
.titlebar { background: var(--bar1); color: #fff; }
.titlebar .bar { padding-top: 12px; padding-bottom: 12px; }
.brand { color: #fff; font-size: 1.15rem; }
.tagline { color: var(--bar-soft); font-size: 0.85rem; flex: 1 1 auto; }
.menubar { background: var(--bar2); border-bottom: 3px solid #f0a23a; }
.menubar nav { gap: 2px 6px; flex: none; padding: 0; }
.menubar nav a, .menubar .dropdown summary { color: #fff; padding: 10px 12px; display: inline-block; font-weight: 500; }
.menubar nav a:hover, .menubar nav a[aria-current="page"], .menubar .dropdown[open] summary {
  background: rgba(255,255,255,.16); color: #fff; box-shadow: inset 0 -3px 0 #f0a23a;
}
.titlebar .switch a { color: #fff; border: 1px solid rgba(255,255,255,.45); }
.titlebar .switch a.on { background: #f0a23a; border-color: #f0a23a; color: #1d2b53; }
.dropdown .menu { top: calc(100% + 3px); }
footer { background: var(--bar1); color: var(--bar-soft); border-top: 3px solid #f0a23a; }
footer a { color: #fff; }
.note.key { background: var(--key-bg); }
@media (max-width: 560px) {
  .top { position: static; }
  .tagline { display: none; }
  .menubar nav { order: 0; }
  .menubar nav a, .menubar .dropdown summary { padding: 8px 9px; }
}

.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand .logo { flex: none; }

/* ======================= Reading comfort layer (typography, spacing, contrast) =======================
   Based on common readability guidance: 16-18px body, line-height 1.6-1.75, 60-75 characters per line, a clear
   size/weight step between heading levels, text contrast above 7:1, tap targets of at least 44px, 8px spacing. */
:root { --muted: #4a5565; --text: #1f2937; --accent: #19606a; --space: 8px; }
html { scroll-behavior: smooth; }
body { font-size: 18px; line-height: 1.7; font-weight: 400; font-family: var(--font); text-rendering: optimizeLegibility;
       -webkit-font-smoothing: antialiased; }
main.wrap { max-width: 920px; padding-top: 8px; padding-bottom: 24px; }
/* a comfortable line length for reading; wide things (tables, calculators, cards) keep the full width */
main p, main li, .lead { max-width: 68ch; }
main p { margin: 0 0 1.15em; }
/* headings: sans-serif for easy reading (monospace only for numbers), clear steps in size and weight */
h1, h2, h3, .hero h1 { font-family: var(--font); color: var(--heading); }
h1 { font-size: clamp(1.75rem, 4.2vw, 2.35rem); line-height: 1.2; font-weight: 800; margin: 1.4rem 0 0.9rem; letter-spacing: -0.02em; }
h2 { font-size: clamp(1.3rem, 3vw, 1.6rem); line-height: 1.3; font-weight: 700; margin: 2.6rem 0 0.9rem; border-bottom-width: 3px; }
h3 { font-size: 1.15rem; line-height: 1.35; font-weight: 700; margin: 0 0 0.4rem; }
h1 + p, h2 + p, h3 + p { margin-top: 0; }
.hero h1::before { content: none; }
.hero h1 { font-size: clamp(1.9rem, 5vw, 2.6rem); margin-top: 1.6rem; }
.lead { font-size: 1.15rem; line-height: 1.65; color: var(--muted); margin-bottom: 1.4rem; }
.small, .crumbs { font-size: 0.92rem; line-height: 1.55; color: var(--muted); }
strong { font-weight: 700; color: var(--heading); }
ul, ol { padding-left: 1.4em; }
li { margin-bottom: 0.5em; }
li::marker { color: var(--accent); }

/* links: clearly links, but calm */
a { text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
main a:hover { color: var(--accent-hover); text-decoration-thickness: 2.5px; }
:focus-visible { outline: 3px solid #f0a23a; outline-offset: 2px; border-radius: 3px; }

/* menus: big enough to tap, not crowded */
.menubar nav a, .menubar .dropdown summary { font-size: 1rem; min-height: 44px; line-height: 24px; padding: 10px 14px; }
.brand { font-size: 1.2rem; letter-spacing: 0; }
.tagline { font-size: 0.9rem; }
.dropdown .menu a { padding: 11px 14px; font-size: 1rem; line-height: 1.4; }

/* cards and boxes: air inside, one calm rhythm */
.cards { gap: 16px; margin: 1.2rem 0 1.8rem; }
.card { padding: 18px 20px; }
.card h3 { margin-bottom: 6px; }
.card p { font-size: 0.97rem; line-height: 1.55; max-width: none; }
.card .who { font-size: 0.78rem; letter-spacing: 0.06em; margin-bottom: 6px; }
.note { padding: 16px 20px; line-height: 1.6; }
.note p:last-child { margin-bottom: 0; }
blockquote { padding: 14px 20px; }

/* numbers: tabular monospace stays for figures, with weight and size that read easily */
.stats { gap: 16px; }
.stat { padding: 16px 18px; }
.stat .value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; margin-bottom: 2px; }
.stat .label { font-size: 0.95rem; line-height: 1.4; }

/* tables: roomy rows, soft stripes, no cramped columns */
th, td { padding: 12px 14px; line-height: 1.45; }
th { font-size: 0.85rem; letter-spacing: 0.04em; }
tbody tr:nth-child(even) { background: rgba(31, 111, 120, 0.045); }
tbody tr:hover { background: rgba(31, 111, 120, 0.09); }
caption { padding: 12px 14px; font-size: 0.95rem; }

/* calculators: the part people use most */
form.calc { padding: 24px; margin: 1.4rem 0 1.8rem; }
form.calc .fields { gap: 18px 24px; }
form.calc label { gap: 6px; font-size: 1rem; }
form.calc label span { font-weight: 600; color: var(--heading); }
form.calc small { font-size: 0.88rem; line-height: 1.45; }
form.calc input, form.calc select { font-size: 1.05rem; min-height: 48px; padding: 10px 14px; color: var(--heading); }
form.calc input:hover, form.calc select:hover { border-color: var(--accent); }
.results { margin-top: 24px; padding: 20px; gap: 16px 24px; background: var(--accent-soft); border: 1px solid var(--line); border-radius: 6px; }
.out span { font-size: 0.95rem; line-height: 1.4; }
.out strong { font-size: 1.3rem; font-weight: 700; line-height: 1.3; }
.out.main { grid-column: 1 / -1; padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.out.main strong { font-size: clamp(1.9rem, 6vw, 2.5rem); font-weight: 800; }
.calc-error { padding: 12px 16px; font-size: 1rem; }
.add-row { padding: 10px 16px; font-size: 1rem; min-height: 44px; }

/* metal rate charts */
.charts { gap: 16px; }
.chart { padding: 14px 16px; font-size: 0.97rem; }

/* footer */
footer { font-size: 0.92rem; line-height: 1.7; }
footer .wrap { padding-top: 24px; padding-bottom: 28px; }

/* phones: a touch smaller text, same comfort */
@media (max-width: 560px) {
  body { font-size: 17px; line-height: 1.68; }
  main.wrap { padding-left: 16px; padding-right: 16px; }
  h2 { margin-top: 2.2rem; }
  form.calc { padding: 16px; }
  .results { padding: 16px; }
  th, td { padding: 10px 10px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* ======================= Dark theme (chosen with the button in the title bar; remembered per visitor) =======================
   Not pure black and not pure white: a deep blue-grey page with soft off-white text lowers glare and keeps the contrast. */
html[data-theme="dark"] {
  --bg: #0f1720; --surface: #17212c; --text: #e3e9ef; --muted: #a8b3c0; --line: #2b3947; --ink: #e3e9ef;
  --heading: #f3f6f9; --accent: #5fc3cf; --accent-soft: #162c33; --accent-hover: #9be3ec; --hot: #f0a23a;
  --pos: #4ccf9a; --neg: #ff8a80; --key-bg: #2d2514; --key-line: #f0a23a; --input-line: #4a5b6c;
  --bar1: #0a111b; --bar2: #14525a; --bar-soft: #b5c0d0;
  --shadow: 0 2px 10px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
html[data-theme="dark"] .card:hover { box-shadow: 0 6px 18px rgba(0, 0, 0, .55); }
html[data-theme="dark"] tbody tr:nth-child(even) { background: rgba(95, 195, 207, 0.06); }
html[data-theme="dark"] tbody tr:hover { background: rgba(95, 195, 207, 0.12); }
html[data-theme="dark"] .menubar { border-bottom-color: #f0a23a; }
html[data-theme="dark"] .note { border-color: var(--line); }
html[data-theme="dark"] .out.main strong { background: linear-gradient(transparent 62%, rgba(240, 162, 58, .35) 62%); }
html[data-theme="dark"] form.calc input, html[data-theme="dark"] form.calc select { background: #0f1720; color: var(--text); }
html[data-theme="dark"] .split .inv { background: #6b7a8c; }

/* theme button (shown only when JavaScript runs) */
.theme-toggle { display: none; align-items: center; gap: 6px; min-height: 36px; padding: 4px 12px; font: inherit; font-size: 0.88rem;
  color: #fff; background: transparent; border: 1px solid rgba(255, 255, 255, .45); border-radius: 4px; cursor: pointer; }
.theme-toggle:hover { background: rgba(255, 255, 255, .14); }
html.js .theme-toggle { display: inline-flex; }
.theme-toggle .icon { font-size: 1.05rem; line-height: 1; }
@media (max-width: 560px) { .theme-toggle .label { display: none; } .theme-toggle { margin-left: 6px; } }

/* ======================= Ad space =======================
   Reserved height so the page does not jump when an ad loads, a small "Advertisement" label so nobody mistakes it for
   content, and generous distance from buttons and inputs (Google's rules forbid ads that invite accidental clicks). */
.ad { clear: both; margin: 2.75rem 0; padding: 0; min-height: 280px; text-align: center; overflow: hidden; max-width: 100%; }
.ad::before { content: "Advertisement"; display: block; margin-bottom: 6px; font-size: 0.72rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); }
.ad ins { display: block; min-height: 250px; background: var(--accent-soft); border-radius: 4px; }
.ad ins[data-ad-status="unfilled"] { display: none; }                       /* no ad came: no empty box */
.ad:has(ins[data-ad-status="unfilled"]) { min-height: 0; margin: 0; }
.ad:has(ins[data-ad-status="unfilled"])::before { content: none; }
form.calc + .ad, .calc-error + .ad { margin-top: 3rem; }                    /* keep clear of the calculator buttons */
@media (max-width: 560px) { .ad { min-height: 300px; margin: 2.25rem 0; } }

/* ======================= One-line header: logo + name on the left, menu in the middle, language/theme on the right ======================= */
.titlebar { border-bottom: 3px solid #f0a23a; }
.titlebar .bar { flex-wrap: nowrap; gap: 8px 22px; padding-top: 0; padding-bottom: 0; min-height: 64px; }
.titlebar .brand { flex: none; }
.titlebar nav { flex: 1 1 auto; gap: 0 4px; margin: 0; align-self: stretch; align-items: stretch; flex-wrap: nowrap; }
.titlebar nav a, .titlebar nav .dropdown summary { color: #fff; display: inline-flex; align-items: center; min-height: 64px; padding: 0 14px;
  font-size: 1rem; font-weight: 500; line-height: 1.2; }
.titlebar nav .dropdown { display: flex; align-items: stretch; }
.titlebar nav a:hover, .titlebar nav a[aria-current="page"], .titlebar .dropdown[open] summary {
  background: rgba(255, 255, 255, .12); color: #fff; box-shadow: inset 0 -4px 0 #f0a23a; }
.titlebar .dropdown .menu { top: 100%; margin-top: 0; }
.titlebar .switch, .titlebar .theme-toggle { flex: none; }
.titlebar .tagline, .menubar { display: none; }
/* narrower screens: the menu drops to its own row under the logo so nothing is squeezed */
@media (max-width: 900px) {
  .titlebar .bar { flex-wrap: wrap; min-height: 0; padding-top: 8px; padding-bottom: 0; }
  .titlebar .brand { order: 1; padding-bottom: 6px; }
  .titlebar .switch { order: 2; margin-left: auto; padding-bottom: 6px; }
  .titlebar .theme-toggle { order: 3; margin-bottom: 6px; }
  .titlebar nav { order: 4; flex: 1 0 100%; flex-wrap: wrap; }
  .titlebar nav a, .titlebar nav .dropdown summary { min-height: 46px; padding: 0 12px; white-space: nowrap; }
}

/* ======================= Compact rhythm (final word on spacing) =======================
   One scale: 4 / 8 / 12 / 16 / 24 / 32 px. Sections are separated by 32px, items inside a section by 12-16px. */
body { font-size: 17px; line-height: 1.65; }
main.wrap { padding-top: 0; padding-bottom: 16px; }
h1 { font-size: clamp(1.6rem, 3.6vw, 2.05rem); font-weight: 700; line-height: 1.2; letter-spacing: -0.015em; margin: 1.25rem 0 0.6rem; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); margin: 1.25rem 0 0.6rem; }
h2 { font-size: 1.3rem; line-height: 1.3; margin: 2rem 0 0.7rem; padding-right: 0; }
h3 { font-size: 1.08rem; margin: 0 0 0.25rem; }
main p { margin: 0 0 0.9em; }
.lead { font-size: 1.08rem; margin-bottom: 1rem; }
.hero { margin-bottom: 0.5rem; }
.hero p { font-size: 1.05rem; color: var(--muted); max-width: 64ch; margin-bottom: 0.5rem; }
li { margin-bottom: 0.35em; }
ul, ol { margin: 0 0 1em; }
.crumbs { margin: 0.9rem 0 0; }

.cards { gap: 12px; margin: 0.8rem 0 1rem; }
.card { padding: 14px 16px; }
.card p { font-size: 0.94rem; line-height: 1.5; }
.stats { gap: 12px; margin: 0.9rem 0; }
.stat { padding: 12px 14px; }
.stat .value { font-size: 1.5rem; }
.note { padding: 12px 16px; margin: 1rem 0; }
blockquote { padding: 10px 16px; margin: 1rem 0; }

.table-wrap { margin: 0.7rem 0 0.9rem; }
th, td { padding: 9px 14px; line-height: 1.4; }
th.num { text-align: right; }
caption { padding: 10px 14px; }
main p.small { margin: 0.3rem 0 0.9rem; }

form.calc { padding: 18px 20px; margin: 0.9rem 0 1.2rem; }
form.calc .fields { gap: 14px 20px; }
form.calc input, form.calc select { min-height: 44px; padding: 8px 12px; }
.results { margin-top: 16px; padding: 14px 16px; gap: 12px 20px; }
.out.main { padding-bottom: 8px; }
.out.main strong { font-size: clamp(1.7rem, 5vw, 2.1rem); }
.rows { margin-top: 10px; }

.chart { padding: 10px 14px; }
.charts { gap: 12px; margin: 0.8rem 0; }

.ad { margin: 2rem 0; min-height: 250px; }
footer { margin-top: 2rem; }
footer .wrap { padding-top: 18px; padding-bottom: 22px; }

@media (max-width: 560px) {
  body { font-size: 16.5px; }
  h2 { margin-top: 1.7rem; }
  form.calc { padding: 14px; }
  .results { padding: 12px; }
}

/* ======================= Professional header =======================
   One bar, wider than the text column so the logo sits at the left edge: [logo + name] [menu] ........ [theme]. */
.titlebar { box-shadow: 0 2px 10px rgba(10, 17, 27, .18); }
.titlebar .bar { max-width: 1240px; padding-left: 24px; padding-right: 24px; gap: 0 28px; position: relative; }
.titlebar .brand { font-family: var(--font); font-weight: 800; font-size: 1.22rem; letter-spacing: 0.01em; gap: 10px; white-space: nowrap; padding: 0; }
.titlebar nav { flex: 1 1 auto; justify-content: flex-start; }
.titlebar nav a, .titlebar nav .dropdown summary { white-space: nowrap; padding: 0 16px; }
.titlebar .dropdown { position: static; }
.titlebar .dropdown summary::after { content: ""; display: inline-block; margin-left: 8px; width: 7px; height: 7px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-2px) rotate(45deg); transition: transform .15s; }
.titlebar .dropdown[open] summary::after { transform: translateY(1px) rotate(225deg); }
.titlebar .switch { margin-left: auto; }

/* Calculators menu: a wide panel, 3 rows and as many columns as needed, filled column by column */
.titlebar .dropdown .menu { position: absolute; left: auto; right: 24px; top: 100%; margin: 0; padding: 14px 16px 10px;
  width: min(1060px, calc(100vw - 48px)); max-height: none; overflow: visible; background: var(--surface);
  border: 1px solid var(--line); border-top: 3px solid #f0a23a; border-radius: 0 0 8px 8px; box-shadow: 0 14px 30px rgba(10, 17, 27, .25); }
.titlebar .dropdown .mega { display: grid; grid-auto-flow: column; grid-template-rows: repeat(3, auto);
  grid-auto-columns: minmax(150px, 1fr); gap: 2px 10px; }
.titlebar .dropdown .mega a { display: block; min-height: 0; padding: 9px 12px; border-radius: 6px; color: var(--text);
  font-size: 0.95rem; font-weight: 500; line-height: 1.3; white-space: normal; box-shadow: none; background: none; }
.titlebar .dropdown .mega a:hover, .titlebar .dropdown .mega a:focus-visible { background: var(--accent-soft); color: var(--accent); box-shadow: none; }
.titlebar .dropdown .menu a.all { display: block; margin-top: 8px; padding: 10px 12px; border-top: 1px solid var(--line); border-radius: 0;
  font-weight: 700; color: var(--accent); min-height: 0; background: none; box-shadow: none; }
.titlebar .dropdown .menu a.all:hover { background: none; text-decoration: underline; }

/* theme button: a plain round icon, no text */
.theme-toggle { width: 40px; height: 40px; min-height: 0; padding: 0; justify-content: center; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .35); }
.theme-toggle .i-sun { display: none; }
html[data-theme="dark"] .theme-toggle .i-moon { display: none; }
html[data-theme="dark"] .theme-toggle .i-sun { display: block; }
.theme-toggle svg { display: block; }

@media (max-width: 900px) {
  .titlebar .bar { padding-left: 16px; padding-right: 16px; gap: 0 12px; }
  .titlebar .dropdown { position: relative; }
  .titlebar .dropdown .menu { position: fixed; left: 12px; right: 12px; top: auto; width: auto; max-height: 70vh; overflow-y: auto; border-radius: 8px; }
  .titlebar .dropdown .mega { grid-auto-flow: row; grid-template-rows: none; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) { .titlebar .dropdown .mega { grid-template-columns: 1fr; } }

/* header spans the full width: logo at the far left, theme button at the far right; the menu panel is centred under the bar */
.titlebar .bar { max-width: none; padding-left: 28px; padding-right: 28px; }
.titlebar .dropdown .menu { left: 50%; right: auto; transform: translateX(-50%); width: min(980px, calc(100vw - 48px)); }
.titlebar .dropdown .mega { grid-auto-columns: minmax(130px, 1fr); }
@media (max-width: 900px) { .titlebar .dropdown .menu { left: 12px; right: 12px; transform: none; width: auto; } }

/* the highlighter stroke sits under the number only, not across the whole panel */
.out.main strong { align-self: flex-start; width: auto; display: inline-block; padding: 0 4px; margin-left: -4px; }
