:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --text: #17201b;
  --muted: #5a665f;
  --border: #dfe4df;
  --accent: #0b7a53;
  --accent-ink: #ffffff;
  --accent-soft: #e2f3eb;
  --gold: #c98a0b;
  --c0: #0b7a53; --c1: #d14b3c; --c2: #3a6fd8; --c3: #c98a0b; --c4: #8a5cc7;
  --danger: #b4372f;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --surface: #18201c; --text: #e7ece9; --muted: #9aa8a0; --border: #2a342f;
    --accent: #3ccb92; --accent-ink: #062016; --accent-soft: #15302a; --gold: #f0b440;
    --c0: #3ccb92; --c1: #f07a6a; --c2: #74a3ff; --c3: #f0b440; --c4: #b897f0; --danger: #ef7d74;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #18201c; --text: #e7ece9; --muted: #9aa8a0; --border: #2a342f;
  --accent: #3ccb92; --accent-ink: #062016; --accent-soft: #15302a; --gold: #f0b440;
  --c0: #3ccb92; --c1: #f07a6a; --c2: #74a3ff; --c3: #f0b440; --c4: #b897f0; --danger: #ef7d74;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.6;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
.wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; }

/* Header */
header.site { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
header.site .wrap { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 12px; padding-bottom: 12px; }
.logo { font-weight: 800; font-size: 1.2rem; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.logo span { color: var(--accent); }
nav.top { display: flex; align-items: center; gap: 14px; }
nav.top a { color: var(--muted); text-decoration: none; font-size: .95rem; }
nav.top a:hover { color: var(--accent); }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 6px 9px; cursor: pointer; font-size: .95rem; margin: 0; }

main { padding: 26px 0 48px; }
h1 { font-size: clamp(1.6rem, 4.5vw, 2.2rem); line-height: 1.2; margin: 0 0 8px; letter-spacing: -.015em; }
h2 { font-size: 1.3rem; margin-top: 36px; }
.lead { color: var(--muted); font-size: 1.05rem; margin-top: 0; }
.badge { display: inline-block; background: var(--accent-soft); color: var(--accent); font-size: .78rem; font-weight: 700; padding: 3px 9px; border-radius: 99px; margin-bottom: 10px; }

/* Calculator card */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin: 20px 0; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: 4px; }
.hint { font-weight: 400; color: var(--muted); }
input, select { width: 100%; padding: 10px 12px; font-size: 1rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-family: inherit; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 9px 14px; font-size: .92rem; font-weight: 600; cursor: pointer; font-family: inherit; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
button:hover { filter: brightness(1.07); }

.results { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-top: 18px; }
.stat { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.stat.hi { background: var(--accent-soft); border-color: transparent; }
.stat .k { font-size: .8rem; color: var(--muted); }
.stat .v { font-size: 1.3rem; font-weight: 750; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat.hi .v { color: var(--accent); font-size: 1.5rem; }
.error { color: var(--danger); margin-top: 10px; }
.error.note { color: var(--muted); }
.error:empty { display: none; }

.share { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.share .wa { background: #25d366; color: #062b14; }
.embed-box { width: 100%; margin-top: 10px; font-family: ui-monospace, Consolas, monospace; font-size: .8rem; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }

/* Tables & charts */
table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 6px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { position: sticky; top: 0; background: var(--surface); }
.table-scroll { overflow: auto; max-height: 380px; margin-top: 16px; }
.chart { margin-top: 18px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 15px; font-family: inherit; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart polyline { stroke-width: 3; stroke-linejoin: round; }
.chart .s0 { stroke: var(--c0); } .chart .s1 { stroke: var(--c2); } .chart .s2 { stroke: var(--c3); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--muted); margin-top: 8px; }
.lg i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.lg i.s0, .stack .c0, .lg i.c0 { background: var(--c0); }
.lg i.s1, .stack .c1, .lg i.c1 { background: var(--c2); }
.lg i.s2 { background: var(--c3); }
.stack .c1, .lg i.c1 { background: var(--c1); }
.stack .c2, .lg i.c2 { background: var(--c2); }
.stack .c3, .lg i.c3 { background: var(--c3); }
.stack .c4, .lg i.c4 { background: var(--c4); }
.stack { display: flex; height: 22px; border-radius: 6px; overflow: hidden; margin-top: 18px; background: var(--border); }
.stack span { display: block; height: 100%; }

/* Home */
.search { margin: 18px 0 6px; }
.search input { padding: 13px 14px; font-size: 1.05rem; }
.cat { margin-top: 28px; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.tools { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.tools a.card { display: block; text-decoration: none; color: var(--text); margin: 0; transition: border-color .15s, transform .15s; }
.tools a.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.tools h3 { margin: 0 0 4px; font-size: 1.04rem; }
.tools p { margin: 0; color: var(--muted); font-size: .9rem; }
.hot { color: var(--gold); font-size: .75rem; font-weight: 700; margin-left: 6px; }
.empty { color: var(--muted); display: none; }

/* FAQ */
details.faq { border-bottom: 1px solid var(--border); padding: 12px 0; }
details.faq summary { cursor: pointer; font-weight: 650; }
details.faq p { margin: 8px 0 0; }

/* Ad slots: paste AdSense <ins> code inside each .ad-slot */
.ad-slot { margin: 24px 0; text-align: center; }
.ad-slot:empty { display: none; }

.related ul { padding-left: 18px; columns: 2 220px; }
footer.site { border-top: 1px solid var(--border); padding: 24px 0; color: var(--muted); font-size: .88rem; }
footer.site a { color: var(--muted); margin-right: 14px; }
.disclaimer { font-size: .8rem; color: var(--muted); margin: 8px 0 0; }

/* Embed mode: only the calculator, with a link back */
.embed body { background: var(--surface); }
.embed main > *:not(.calc):not(h1) { display: none; }
.embed main { padding: 12px 0; }
.embed h1 { font-size: 1.2rem; }
.embed .calc { margin: 8px 0; }
.powered { font-size: .8rem; color: var(--muted); text-align: right; margin-top: 8px; }

@media print {
  header.site, footer.site, .share, .ad-slot, .related, .search { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border-color: #ccc; }
}
