:root {
  --ink: #16202b;
  --muted: #5d6b7a;
  --line: #d8dee6;
  --bg: #f6f7f9;
  --card: #ffffff;
  --accent: #1f5f8b;
  --accent-soft: #e8f1f7;
  --a: #1f5f8b;
  --a-soft: #e8f1f7;
  --b: #7a4b8f;
  --b-soft: #f2e9f7;
  --warn: #a3400f;
  --warn-soft: #fdf0e6;
  --ok: #1d6b45;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

header.top {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: baseline;
}
header.top h1 { font-size: 17px; margin: 0; }
header.top .sub { color: var(--muted); font-size: 12px; }
header.top .spacer { flex: 1; }

main { padding: 18px 20px 60px; max-width: 1500px; margin: 0 auto; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card > h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 4px;
}
.card > .hint, .hint {
  color: var(--muted);
  font-size: 12px;
  margin: 0 0 12px;
}

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

label.field { display: block; }
label.field > span.lab {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 3px;
}
input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  font: inherit;
  color: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.percent-input {
  display: flex;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}
.percent-input input[type="number"] {
  border: none;
  border-radius: 0;
  min-width: 0;
  flex: 1;
}
.percent-input input[type="number"]:focus { outline: none; }
.percent-input:focus-within { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.percent-suffix { padding: 0 8px 0 2px; color: var(--muted); font-size: 12px; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
label.check input { margin-top: 3px; }

button {
  font: inherit;
  padding: 7px 13px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #17486a; color: #fff; }
button.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; }
.linklike-nav {
  font: inherit;
  padding: 7px 13px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  display: inline-block;
}
.linklike-nav:hover { border-color: var(--accent); color: var(--accent); }
button.tiny { padding: 3px 8px; font-size: 12px; }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.strategy-picker { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.strategy-picker select { padding: 5px 6px; }
#btn-run:disabled { opacity: 0.6; cursor: wait; }
#strategy-select:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- people --- */
.people { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; }
.person {
  border: 1px solid var(--line);
  border-left: 5px solid var(--a);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fff;
}
.person.b { border-left-color: var(--b); }
.person > header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--a-soft);
  color: var(--a);
  font-weight: 700;
  font-size: 12px;
  flex: none;
}
.person.b .badge { background: var(--b-soft); color: var(--b); }
.person > header .who { font-weight: 600; }
.person > header .who em { font-style: normal; color: var(--muted); font-weight: 400; }
.conditional {
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 10px;
  background: #fbfcfd;
}
.conditional > .why { font-size: 12px; color: var(--muted); margin: 0 0 8px; }

/* --- tables --- */
.tablewrap { overflow-x: auto; }
/* The year-by-year results table: its own bounded height and vertical scrollbar, so
   the sticky header above (`th { position: sticky; top: 0 }`) has a scrolling
   container to stick *within* -- without this, the whole page scrolls instead of the
   table, the header scrolls away with everything else, and there is nothing for
   `position: sticky` to attach to. `overscroll-behavior: contain` keeps the two
   scrollbars independent: scrolling with the pointer over the table scrolls the
   table, and stops there rather than "leaking" into the page once the table's own
   content runs out; move the pointer off the table and the page's own scrollbar
   takes over, as it would for any other element on the page. */
.ledger-scroll { max-height: 65vh; overflow-y: auto; overscroll-behavior: contain; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 9px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); text-align: right; position: sticky; top: 0; background: var(--card); }
th:first-child, td:first-child { text-align: left; }
td.txt, th.txt { text-align: left; white-space: normal; }
tbody tr:hover { background: var(--accent-soft); }
tr.event td { font-weight: 600; }
td.neg { color: var(--warn); }
.results table { font-size: 13px; }
.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.results-head h2 { margin: 0; }

.accounts table th, .accounts table td { border-bottom: 1px solid var(--line); }
.accounts input, .accounts select { min-width: 96px; }
.accounts td { padding: 4px 6px; }
.owner-a { color: var(--a); font-weight: 600; }
.owner-b { color: var(--b); font-weight: 600; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fff; }
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat .v { font-size: 19px; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat.bad .v { color: var(--warn); }
.stat.good .v { color: var(--ok); }

.notice { border-radius: 6px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.notice.error { background: var(--warn-soft); border: 1px solid #eccdb5; color: var(--warn); }
.notice.info { background: var(--accent-soft); border: 1px solid #cfe2ee; }
.notice code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.regime-rows { display: grid; gap: 8px; }
.regime-row { display: flex; gap: 8px; align-items: center; }
.regime-row input { max-width: 110px; }
.regime-row select { max-width: 170px; }

.periods td:first-child { white-space: normal; }
.periods .boundary { color: var(--muted); font-size: 12px; }

/* --- disclaimer gate and footer --- */
.disclaimer-gate[hidden] { display: none; }
.disclaimer-gate {
  position: fixed;
  inset: 0;
  background: rgba(22, 32, 43, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.disclaimer-box {
  background: var(--card);
  border-radius: 10px;
  max-width: 560px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 22px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.disclaimer-box h2 { margin-top: 0; }
.disclaimer-text p { font-size: 13px; line-height: 1.55; color: var(--ink); }
.disclaimer-check {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 13px;
  margin: 14px 0;
}
.disclaimer-check input { margin-top: 3px; }
.disclaimer-footer {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 14px 16px 24px;
}
button.linklike {
  background: none;
  border: none;
  padding: 0;
  margin-left: 6px;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
}

@media (max-width: 640px) {
  main { padding: 14px 12px 40px; }
  .card { padding: 12px; }
}
