:root {
  --bg: #f7f3ea;
  --surface: #fffdf8;
  --ink: #23271f;
  --muted: #5d6356;
  --line: #ddd5c4;
  --brand: #3b5d3a;
  --brand-ink: #ffffff;
  --accent: #b5652b;
  --warn-bg: #fbefd9;
  --warn-ink: #6b4310;
  --ok: #2f6b3a;
  --bad: #a13a26;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a15;
    --surface: #20241d;
    --ink: #ebe8df;
    --muted: #a9ad9f;
    --line: #353b30;
    --brand: #8fbf7f;
    --brand-ink: #10140e;
    --accent: #e0995f;
    --warn-bg: #3a2f1c;
    --warn-ink: #f2d6a8;
    --ok: #8fd19a;
    --bad: #f08f7a;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--brand); }
a:hover { color: var(--accent); }
img { max-width: 100%; }
[hidden] { display: none !important; }

.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.calcs { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .92rem; }
.calcs a { text-decoration: none; color: var(--muted); }
.calcs a[aria-current] { color: var(--brand); font-weight: 600; }

main { max-width: 980px; margin: 0 auto; padding: 20px 16px 40px; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.2; margin: .3em 0 .3em; }
h2 { font-size: 1.3rem; margin: 1.6em 0 .5em; }
h3 { font-size: 1.05rem; margin: 1.2em 0 .3em; }
.lede { font-size: 1.08rem; color: var(--muted); max-width: 46em; }

/* Calculator */
.calc {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px;
  margin: 20px 0 8px;
}
@media (max-width: 760px) { .calc { grid-template-columns: minmax(0, 1fr); } }
.calc form, .result {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
}
.units { border: 0; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.units legend { font-weight: 600; margin-bottom: 6px; padding: 0; }
.seg { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; }
.seg:has(input:checked) { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.field label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: 4px; }
.input { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); overflow: hidden; }
.input:focus-within { outline: 2px solid var(--brand); outline-offset: 1px; }
.input input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink); font: inherit; padding: 9px 10px; }
.input input:focus { outline: none; }
.unit { display: flex; align-items: center; padding: 0 10px; color: var(--muted); font-size: .9rem; border-left: 1px solid var(--line); }
.unit.pre { border-left: 0; border-right: 1px solid var(--line); }
select {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px;
}
.prices { margin-top: 14px; }
.prices summary { cursor: pointer; font-weight: 600; margin-bottom: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
button {
  font: inherit; cursor: pointer; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
button:hover { border-color: var(--brand); }
.status { min-height: 1.4em; margin: 8px 0 0; color: var(--ok); font-size: .92rem; }

.result-title { margin-top: 0; }
.summary { color: var(--muted); margin-top: -.3em; }
.list { list-style: none; padding: 0; margin: 0; }
.list li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px dashed var(--line); font-size: 1.05rem; font-weight: 600;
}
.list li::before { content: ""; flex: 0 0 14px; height: 14px; margin-top: 5px; border: 2px solid var(--brand); border-radius: 3px; }
.list li span:first-child { flex: 1; }
.amt { color: var(--muted); font-weight: 500; white-space: nowrap; }
.total { text-align: right; font-size: 1.1rem; }
.details { margin: 14px 0 0; display: grid; gap: 6px; }
.details div { display: flex; justify-content: space-between; gap: 12px; font-size: .92rem; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; text-align: right; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; padding: 10px 12px; font-size: .92rem; }
.errors { color: var(--bad); }
.checks { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: .92rem; }
.checks caption { text-align: left; font-weight: 600; margin-bottom: 4px; }
.checks th, .checks td { text-align: left; padding: 5px 4px; border-bottom: 1px solid var(--line); }
.checks .pass td:last-child { color: var(--ok); font-weight: 600; }
.checks .fail td:last-child { color: var(--bad); font-weight: 600; }
.note { color: var(--muted); font-size: .88rem; }

.prose { max-width: 46em; }
.formula { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 8px; padding: 12px 12px 12px 32px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9rem; }
.formula li { margin: 4px 0; }
.examples > li { margin-bottom: 10px; }
.examples p { margin: 0 0 4px; }

.cards { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.cards a {
  display: block; height: 100%; padding: 14px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); text-decoration: none; color: var(--ink);
}
.cards a:hover { border-color: var(--brand); }
.cards strong { display: block; color: var(--brand); margin-bottom: 4px; }
.cards span { font-size: .9rem; color: var(--muted); }

.app {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px;
  margin-top: 36px; padding: 18px; border-radius: var(--radius); background: var(--brand); color: var(--brand-ink);
}
.app h2 { margin: 0 0 4px; font-size: 1.15rem; }
.app p { margin: 0; max-width: 40em; }
.app .soon { font-weight: 700; border: 1px solid currentColor; border-radius: 999px; padding: 6px 14px; white-space: nowrap; }
.app .btn { color: var(--brand); background: var(--brand-ink); padding: 8px 16px; border-radius: 999px; font-weight: 700; text-decoration: none; white-space: nowrap; }

.foot { border-top: 1px solid var(--line); padding: 20px 16px 32px; color: var(--muted); font-size: .88rem; }
.foot > * { max-width: 980px; margin-left: auto; margin-right: auto; }
.foot nav { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 10px; }

.fallback { display: block; color: var(--ink); }
.fallback textarea { display: block; width: 100%; margin-top: 4px; font: inherit; font-size: .85rem; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }

@media print {
  :root { --bg: #fff; --surface: #fff; --ink: #000; --muted: #333; --line: #999; --brand: #000; --warn-bg: #fff; --warn-ink: #000; --ok: #000; --bad: #000; color-scheme: light; }
  .top, .foot, .app, .calc form, .prose, .lede, noscript, .calc-page h1 + .lede { display: none !important; }
  body { background: #fff; color: #000; }
  main { padding: 0; }
  .calc { display: block; margin: 0; }
  .result { border: 0; padding: 0; background: #fff; color: #000; }
  .warn { border: 1px solid #999; }
  .list li::before { border-color: #000; }
}
