:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #12202e;
  --muted: #5b6b7c;
  --line: #d8e0e8;
  --brand: #0b6e4f;
  --brand-dark: #08563e;
  --accent: #f0b429;
  --danger: #b42318;
  --warn-bg: #fff7e6;
  --ok-bg: #e8f7f1;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(18, 32, 46, 0.08);
  --font: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--brand); }
img { max-width: 100%; }

.wrap {
  width: min(960px, calc(100% - 1.5rem));
  margin-inline: auto;
}

.site-header {
  background: var(--ink);
  color: #fff;
  padding: 0.75rem 0;
}
.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.logo {
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: #fff;
}
.nav-stub a {
  color: #c9d4df;
  text-decoration: none;
  font-size: 0.875rem;
  margin-left: 0.75rem;
}
.nav-stub a:hover { color: #fff; }

.hero {
  padding: 1.25rem 0 0.5rem;
}
.hero h1 {
  font-size: clamp(1.45rem, 4.5vw, 2rem);
  line-height: 1.2;
  margin: 0 0 0.5rem;
}
.hero .lede {
  color: var(--muted);
  margin: 0 0 1rem;
  font-size: 1rem;
}
.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.badge {
  font-size: 0.75rem;
  background: #e6eef5;
  color: #33485c;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

.calc-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1.25rem;
}
.calc-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  align-items: center;
}
.preset-row label { font-size: 0.85rem; color: var(--muted); }
.preset-row select {
  flex: 1;
  min-width: 160px;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  font: inherit;
}

.grid {
  display: grid;
  gap: 0.75rem;
}
@media (min-width: 640px) {
  .grid.two { grid-template-columns: 1fr 1fr; }
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.field .hint {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 400;
  margin-top: 0.15rem;
}
.field input, .field select {
  width: 100%;
  padding: 0.65rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}
.field input:focus, .field select:focus {
  outline: 2px solid rgba(11, 110, 79, 0.35);
  border-color: var(--brand);
}
.inline-toggle {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}
.inline-toggle button {
  flex: 1;
  border: 1px solid var(--line);
  background: #f7fafc;
  padding: 0.45rem;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}
.inline-toggle button[aria-pressed="true"] {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}
button.primary {
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  flex: 1;
  min-width: 140px;
}
button.primary:hover { background: var(--brand-dark); }
button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}

.results {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
  display: none;
}
.results.is-visible { display: block; }
.primary-result {
  background: var(--ok-bg);
  border: 1px solid #b7e4d1;
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.75rem;
}
.primary-result .label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.primary-result .value {
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  font-weight: 750;
  color: var(--brand-dark);
  font-variant-numeric: tabular-nums;
}
.metrics {
  display: grid;
  gap: 0.5rem;
}
@media (min-width: 540px) {
  .metrics { grid-template-columns: 1fr 1fr; }
}
.metric {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}
.metric .k { font-size: 0.75rem; color: var(--muted); }
.metric .v {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.metric .v.neg { color: var(--danger); }
.metric .v.pos { color: var(--brand-dark); }

.errors, .warnings {
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  display: none;
}
.errors.is-visible, .warnings.is-visible { display: block; }
.errors { background: #fef3f2; border: 1px solid #fecdca; color: var(--danger); }
.warnings { background: var(--warn-bg); border: 1px solid #f5d78e; color: #7a5a00; }
.errors ul, .warnings ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }

.affiliate {
  display: none;
  margin-top: 0.85rem;
  padding: 0.85rem;
  border: 1px dashed #9bb7a8;
  border-radius: 10px;
  background: #f3faf7;
}
.affiliate.is-visible { display: block; }
.affiliate h3 { margin: 0 0 0.35rem; font-size: 1rem; }
.affiliate p { margin: 0 0 0.65rem; font-size: 0.9rem; color: var(--muted); }
.affiliate .cta-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.affiliate a.cta {
  display: inline-block;
  text-decoration: none;
  background: #fff;
  border: 1px solid var(--brand);
  color: var(--brand-dark);
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.section h2 {
  margin: 0 0 0.6rem;
  font-size: 1.2rem;
}
.section h3 {
  margin: 1rem 0 0.4rem;
  font-size: 1rem;
}
.section p, .section li { color: #2a3a4a; }
.formula-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  background: #0f1c28;
  color: #d7e6f5;
  padding: 0.85rem;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre;
}
table.example {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.example th, table.example td {
  border: 1px solid var(--line);
  padding: 0.45rem 0.55rem;
  text-align: left;
}
table.example th { background: #eef3f7; }

.faq details {
  border-top: 1px solid var(--line);
  padding: 0.65rem 0;
}
.faq details:first-of-type { border-top: none; }
.faq summary {
  cursor: pointer;
  font-weight: 650;
}
.links-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.9rem;
}

.site-footer {
  padding: 1.5rem 0 2.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.disclaimer {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.75rem;
}

.pct-inline-hint {
  color: #8a5a00;
  background: #fff6e5;
  border-left: 3px solid #e0a800;
  padding: 0.25rem 0.5rem;
  display: block;
  margin-top: 0.25rem;
}
.pct-inline-hint[hidden] { display: none !important; }

/* Mode tabs */
.mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}
.mode-tabs button {
  flex: 1;
  min-width: 7rem;
  border: 1px solid var(--line);
  background: #f7fafc;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.mode-tabs button[aria-selected="true"] {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  font-weight: 650;
}
.mode-panel[hidden] { display: none !important; }
.double-count-banner {
  background: var(--warn-bg);
  border: 1px solid #f5d78e;
  color: #7a5a00;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin: 0.5rem 0 0.75rem;
}
.ceil-note {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.cta-row a.cta.secondary {
  border-style: dashed;
}
.primary-result.dual {
  display: grid;
  gap: 0.65rem;
}
@media (min-width: 540px) {
  .primary-result.dual { grid-template-columns: 1fr 1fr; }
}
.primary-result .subvalue {
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* P4 extras */

.mode-tabs { display:flex; flex-wrap:wrap; gap:0.35rem; margin-bottom:0.85rem; }
.mode-tabs button { flex:1; min-width:7rem; border:1px solid var(--line); background:#f7fafc; padding:0.55rem 0.65rem; border-radius:8px; font:inherit; font-size:0.9rem; cursor:pointer; }
.mode-tabs button[aria-selected="true"] { background:var(--brand); color:#fff; border-color:var(--brand); font-weight:650; }
.double-count-banner { background:var(--warn-bg); border:1px solid #f5d78e; color:#7a5a00; padding:0.65rem 0.75rem; border-radius:8px; font-size:0.9rem; margin:0.5rem 0 0.75rem; }
.ceil-note { font-size:0.8rem; color:var(--muted); margin-top:0.25rem; }
.primary-result.dual { display:grid; gap:0.65rem; }
@media (min-width:540px){ .primary-result.dual { grid-template-columns:1fr 1fr; } }
.primary-result .subvalue { font-size:1.05rem; font-weight:700; font-variant-numeric:tabular-nums; }
.handoff-note { background:#e8f0fe; border:1px solid #b6d0fe; color:#1a4b8c; padding:0.65rem 0.75rem; border-radius:8px; font-size:0.9rem; margin-bottom:0.75rem; }
.results.is-visible, .errors.is-visible, .warnings.is-visible { display:block; }
.results { display:none; }
.errors, .warnings { display:none; }
