:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --ink: #191d1a;
  --dim: #5e6862;
  --line: #e2e6e1;
  --accent: #157a52;
  --accent-soft: rgba(21, 122, 82, 0.12);
  --minus: #a34e36;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131614;
    --surface: #1a1e1b;
    --ink: #e5e9e4;
    --dim: #8e978f;
    --line: #262b27;
    --accent: #46b380;
    --accent-soft: rgba(70, 179, 128, 0.16);
    --minus: #d98e7a;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, "Segoe UI", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}

.bar, .shell, .mnav {
  max-width: 960px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 20px;
  padding-right: 20px;
}

.bar { padding-top: 20px; padding-bottom: 20px; }

.brand {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--dim);
  text-decoration: none;
}

.brand:hover { color: var(--ink); }

main {
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: 64px;
  min-width: 0;
}

/* ---------- calculator switcher ---------- */

.rail { display: none; }

.ng { margin-bottom: 18px; }

.nh {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 4px 14px;
}

.ng ul { list-style: none; margin: 0; padding: 0; }

.ng a {
  position: relative;
  display: block;
  padding: 4.5px 10px 4.5px 14px;
  border-radius: 5px;
  font-size: 13.5px;
  color: var(--dim);
  text-decoration: none;
}

.ng a:hover { color: var(--ink); background: var(--surface); }

.ng a[aria-current="page"] {
  color: var(--accent);
  font-weight: 600;
}

.ng a[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 50%;
  margin-top: -3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.mnav {
  margin-top: 4px;
  margin-bottom: 8px;
}

.mnav summary {
  display: inline-block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  user-select: none;
}

.mnav summary:hover { color: var(--ink); }

.mnav[open] summary { color: var(--accent); border-color: var(--accent); }

.mnav nav {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px 8px 6px;
  margin-top: 8px;
}

@media (min-width: 920px) {
  .mnav { display: none; }

  .shell {
    display: grid;
    grid-template-columns: 200px minmax(0, 640px);
    gap: 56px;
    justify-content: center;
  }

  .rail {
    display: block;
    position: sticky;
    top: 24px;
    align-self: start;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    padding-top: 12px;
  }

  main { margin: 0; }
}

h1 {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin: 12px 0 4px;
  text-wrap: balance;
}

.intro { color: var(--dim); }
.intro p { margin: 0 0 16px; }

h2 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.005em;
  margin: 40px 0 8px;
}

h3 { font-size: 15px; font-weight: 600; margin: 20px 0 2px; }

p { margin: 8px 0; }

a { color: var(--accent); text-underline-offset: 2px; }

/* ---------- calculator card ---------- */

.calc {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin: 8px 0 12px;
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

label { display: block; min-width: 0; }

.fl {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--dim);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fl em { font-style: normal; font-weight: 400; opacity: 0.7; }

.input {
  display: flex;
  align-items: center;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
}

.input span { padding: 0 2px 0 12px; color: var(--dim); font-size: 14px; }
.input .suffix { padding: 0 12px 0 2px; }

.input input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  padding: 0 12px 0 4px;
}

.input input:only-child { padding-left: 12px; }
.input input:focus { outline: none; }
.input input::placeholder { color: var(--dim); opacity: 0.55; }

.input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* number spinners off — they add uneven chrome */
.input input::-webkit-outer-spin-button,
.input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* ---------- result ledger ---------- */

.result {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 4px;
}

.result .row,
.headline {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
}

.headline { padding: 12px 0 4px; }

.headline .lbl {
  font-size: 13px;
  font-weight: 500;
  color: var(--dim);
}

.headline strong {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.breakdown { width: 100%; border-collapse: collapse; font-size: 14px; }

.breakdown th {
  text-align: left;
  font-weight: 400;
  color: var(--dim);
  padding: 7px 16px 7px 0;
}

.breakdown td {
  text-align: right;
  padding: 7px 0;
  white-space: nowrap;
}

.breakdown .fee td { color: var(--minus); }

.breakdown .sum th, .breakdown .sum td {
  font-weight: 600;
  color: var(--ink);
  border-top: 1px solid var(--line);
}

/* dormant until something is typed */
.result.idle .headline strong { color: var(--dim); font-weight: 500; }
.result.idle .breakdown { opacity: 0.5; }

@media (prefers-reduced-motion: no-preference) {
  .input, .breakdown, .headline strong { transition: border-color 0.12s, box-shadow 0.12s, opacity 0.12s, color 0.12s; }
}

/* ---------- page furniture ---------- */

.stamp {
  font-size: 13px;
  color: var(--dim);
  margin: 0 0 32px;
}

.stamp::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 8px;
  vertical-align: 1px;
}

.qa { margin: 16px 0; }
.qa h3 { margin: 0 0 2px; }
.qa p { margin: 0; color: var(--dim); }

.tw { overflow-x: auto; margin: 12px 0; }

.tw table { border-collapse: collapse; width: 100%; min-width: 420px; font-size: 14px; }

.tw th, .tw td {
  text-align: left;
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--line);
}

.tw th { font-size: 13px; font-weight: 500; color: var(--dim); }

.related { list-style: none; padding: 0; margin: 8px 0; }
.related li { margin: 5px 0; }
.related a { color: var(--ink); }
.related a:hover { color: var(--accent); }

.index { list-style: none; padding: 0; margin: 12px 0 0; }

.index li a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
}

.index li:first-child a { border-top: 1px solid var(--line); }
.index li b { font-weight: 600; white-space: nowrap; }
.index li span {
  color: var(--dim);
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.index li a:hover b { color: var(--accent); }

.foot {
  border-top: 1px solid var(--line);
  margin-top: 48px;
  font-size: 13px;
  color: var(--dim);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
