:root {
  --bg: #f8faf9;
  --surface: #ffffff;
  --ink: #1a1f1d;
  --muted: #57605c;
  --line: #e3e8e6;
  --accent: #0f766e;
  --accent-ink: #115e59;
  --accent-soft: #e4f4f1;
  --behind: #c2410c;
  --behind-ink: #9a3412;
  --behind-soft: #fdeee4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6;
  font-size: 17px;
}

header.site {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

header.site .wrap {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.9rem 1.25rem;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.brand span { color: var(--accent); }

.tagline { color: var(--muted); font-size: 0.85rem; }

main, header.site .wrap, footer .wrap {
  max-width: 760px;
  margin: 0 auto;
}

main { padding: 1.5rem 1.25rem 3rem; }

h1 { font-size: 1.7rem; line-height: 1.25; margin: 0.5rem 0 0.4rem; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; margin: 2.2rem 0 0.6rem; }
h3 { font-size: 1.05rem; margin: 1.4rem 0 0.4rem; }

p.lead { color: var(--muted); margin-top: 0; }

a { color: var(--accent-ink); }

/* Tracker */
.tracker {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  margin: 1.25rem 0;
}

.tracker-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.tracker-controls label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}

.tracker-controls input, .tracker-controls select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--surface);
  min-width: 0;
}

.tracker-controls input:focus, .tracker-controls select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

#chart {
  width: 100%;
  height: 190px;
  display: block;
}

.totals {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 2px solid var(--ink);
}

.totals .box {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  flex: 1 1 10rem;
}

.totals .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-ink);
  font-weight: 600;
}

.totals .value {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tracker.behind .totals .box { background: var(--behind-soft); }
.tracker.behind .totals .label { color: var(--behind-ink); }

.status {
  margin-top: 0.9rem;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.tracker.behind .status { background: var(--behind-soft); color: var(--behind-ink); }

.hint { font-size: 0.85rem; color: var(--muted); margin: 0.5rem 0 0; }

/* Content */
.example, .note {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  margin: 1rem 0;
}

table.ref {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

table.ref th, table.ref td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

table.ref th {
  background: var(--bg);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

table.ref tr:last-child td { border-bottom: 0; }

.table-scroll { overflow-x: auto; }

.formula {
  background: var(--ink);
  color: #f7faf9;
  border-radius: 8px;
  padding: 0.8rem 1.1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
  overflow-x: auto;
  margin: 1rem 0;
}

details.faq {
  border-bottom: 1px solid var(--line);
  padding: 0.6rem 0;
}

details.faq summary {
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0;
}

details.faq p { margin: 0.5rem 0 0.25rem; color: var(--muted); }

footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}
footer .wrap { padding: 1.25rem; }

@media (max-width: 540px) {
  body { font-size: 16px; }
  .tracker { padding: 0.75rem; margin-left: -0.35rem; margin-right: -0.35rem; }
  .totals .value { font-size: 1.25rem; }
}
