:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f1efe9;
  --text: #1c2420;
  --muted: #5b655f;
  --border: #dfdbd2;
  --accent: #2f6b4f;
  --accent-strong: #234f3a;
  --accent-soft: #e4efe8;
  --on-accent: #ffffff;
  --warn-bg: #fff4dc;
  --warn-text: #6b4a00;
  --error-bg: #fde8e6;
  --error-text: #9b1c14;
  --shadow: 0 1px 2px rgba(28, 36, 32, .04), 0 6px 20px rgba(28, 36, 32, .06);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614;
    --surface: #1a201d;
    --surface-2: #222a26;
    --text: #e7ece9;
    --muted: #9ba7a0;
    --border: #2e3833;
    --accent: #79c9a2;
    --accent-strong: #a0dcbf;
    --accent-soft: #1e3a2c;
    --on-accent: #0f1a14;
    --warn-bg: #3a2f12;
    --warn-text: #f3d48a;
    --error-bg: #3d1a17;
    --error-text: #f4b7b1;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121614;
  --surface: #1a201d;
  --surface-2: #222a26;
  --text: #e7ece9;
  --muted: #9ba7a0;
  --border: #2e3833;
  --accent: #79c9a2;
  --accent-strong: #a0dcbf;
  --accent-soft: #1e3a2c;
  --on-accent: #0f1a14;
  --warn-bg: #3a2f12;
  --warn-text: #f3d48a;
  --error-bg: #3d1a17;
  --error-text: #f4b7b1;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
}
a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); letter-spacing: -.02em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }

/* ---------- header ---------- */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand svg { color: var(--accent); flex: none; }
.brand:hover { color: var(--text); }

.unit-toggle { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.unit-toggle button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: .875rem; font-weight: 600;
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
}
.unit-toggle button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.unit-toggle button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.site-nav { border-top: 1px solid var(--border); }
.nav-row { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; padding-top: 6px; padding-bottom: 6px; }
.nav-row::-webkit-scrollbar { display: none; }
.site-nav a {
  flex: none; color: var(--muted); text-decoration: none; font-size: .9rem; font-weight: 500;
  padding: 6px 12px; border-radius: 8px; white-space: nowrap;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }

/* ---------- page ---------- */
main.wrap { padding-top: 28px; padding-bottom: 48px; }
.crumbs { font-size: .875rem; margin-bottom: 10px; }
.crumbs a { text-decoration: none; }
.lede { color: var(--muted); font-size: 1.05rem; max-width: 70ch; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.calc { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; margin: 24px 0 36px; align-items: start; }
.calc + .calc { margin-top: 0; }
.inputs { padding: 22px; }
.inputs h2 { margin-bottom: 16px; }
.results { padding: 22px; position: sticky; top: 16px; }

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field > .label { display: block; font-weight: 600; font-size: .925rem; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: .825rem; margin: 6px 0 0; }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; margin-bottom: 16px; }
.field-row .field { margin-bottom: 0; }

.input { display: flex; align-items: stretch; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); overflow: hidden; }
.input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input input, .input select {
  flex: 1; min-width: 0; width: 100%; border: 0; background: transparent; color: var(--text);
  font: inherit; padding: 10px 12px; outline: none;
}
.input .prefix, .input .unit {
  display: flex; align-items: center; padding: 0 12px; background: var(--surface-2); color: var(--muted);
  font-size: .875rem; white-space: nowrap;
}
.input .prefix { border-right: 1px solid var(--border); }
.input .unit { border-left: 1px solid var(--border); }
select { appearance: none; -webkit-appearance: none; cursor: pointer; }
.input.select { position: relative; }
.input.select::after {
  content: ""; position: absolute; right: 14px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); pointer-events: none;
}
.input.select select { padding-right: 36px; }
.input select option { color: #1c2420; background: #fff; }

.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; font-size: .925rem; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.group-title { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 12px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---------- results ---------- */
.results-title { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 12px; }
.primary { background: var(--accent-soft); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.primary-label { font-size: .875rem; color: var(--muted); font-weight: 600; }
.primary-value { font-size: clamp(1.9rem, 5vw, 2.4rem); font-weight: 750; color: var(--accent); letter-spacing: -.02em; line-height: 1.15; margin: 2px 0; font-variant-numeric: tabular-nums; }
.primary-sub { font-size: .9rem; color: var(--text); }

.rows { margin: 0; }
.rows-heading { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 16px 0 4px; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row dt { color: var(--text); font-size: .925rem; }
.row dd { margin: 0; font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; }
.row-hint { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; }
.row-total { border-top: 2px solid var(--text); border-bottom: 0; margin-top: 4px; }
.row-total dt, .row-total dd { font-weight: 750; }
.row:has(.chips) { flex-direction: column; align-items: stretch; gap: 8px; }
.row:has(.chips) dd { text-align: left; }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-size: .825rem; font-weight: 500; }

.msg { border-radius: 10px; padding: 10px 14px; font-size: .9rem; margin-bottom: 12px; }
.msg-warn { background: var(--warn-bg); color: var(--warn-text); }
.msg-error { background: var(--error-bg); color: var(--error-text); }
.note { color: var(--muted); font-size: .825rem; margin: 14px 0 0; }

/* ---------- article / related ---------- */
.info { max-width: 75ch; }
.info h2 { margin-top: 1.6em; }
.info ul, .info ol { padding-left: 1.3em; margin: 0 0 1em; }
.info li { margin-bottom: .35em; }
.formula { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .875rem; overflow-x: auto; white-space: pre; }

.related { margin-top: 40px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tool-card { display: block; padding: 18px; text-decoration: none; color: var(--text); transition: border-color .15s, transform .15s; }
.tool-card:hover { border-color: var(--accent); color: var(--text); transform: translateY(-2px); }
.tool-card h3 { color: var(--accent); margin-bottom: 4px; }
.tool-card p { color: var(--muted); font-size: .9rem; margin: 0; }
.tool-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 12px; }

.hero { padding: 12px 0 8px; }
.hero .lede { font-size: 1.15rem; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: .85rem; padding: 22px 0; }
.site-footer p { margin: 0 0 .4em; }

@media (max-width: 760px) {
  main.wrap { padding-top: 20px; }
  .calc { grid-template-columns: minmax(0, 1fr); }
  .results { position: static; }
  .inputs, .results { padding: 18px; }
  .brand span { font-size: 1rem; }
  .unit-toggle button { padding: 6px 10px; }
}
@media (max-width: 420px) {
  .field-row { grid-template-columns: minmax(0, 1fr); }
}
