:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f0f1ed;
  --fg: #1b1d1f;
  --muted: #5b6067;
  --border: #e1e2dc;
  --accent: #1d6b59;
  --accent-soft: #e2f0eb;
  --ok: #22693f;
  --ok-soft: #e1f1e7;
  --warn: #8a5300;
  --warn-soft: #faefd9;
  --bad: #a3302b;
  --bad-soft: #f7e2e0;
  --focus: #2f6fd6;
  --shadow: 0 1px 2px rgba(20, 24, 28, 0.05), 0 4px 16px rgba(20, 24, 28, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111315;
    --surface: #181b1e;
    --surface-2: #1f2327;
    --fg: #e7e8e9;
    --muted: #a1a6ac;
    --border: #2b3035;
    --accent: #5fc4a8;
    --accent-soft: #163a31;
    --ok: #74d39b;
    --ok-soft: #16301f;
    --warn: #e8b55e;
    --warn-soft: #382b14;
    --bad: #f2908a;
    --bad-soft: #3a1c1a;
    --focus: #7aa7ff;
    --shadow: none;
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding-inline: max(16px, 4vw);
  padding-block: 32px 48px;
}

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

a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible + span,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.2rem);
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.2rem;
  margin-bottom: 4px;
}

h3 {
  font-size: 1rem;
}

p {
  margin: 0 0 10px;
}

small,
.muted {
  color: var(--muted);
}

.num,
td.num,
th.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

/* ---------- header */

.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--warn);
  background: var(--warn-soft);
  border-radius: 999px;
  padding: 3px 10px;
  margin-bottom: 12px;
}

.lede {
  color: var(--muted);
  max-width: 62ch;
  margin-top: 8px;
}

.result {
  margin: 20px 0 8px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 1.05rem;
  font-weight: 500;
}

.page-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 0.9rem;
  margin-top: 12px;
}

/* ---------- sections */

section {
  margin-top: 36px;
}

.section-head {
  margin-bottom: 12px;
}

.section-head p {
  color: var(--muted);
  margin: 0;
  max-width: 70ch;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

/* ---------- basis control */

.basis {
  border: 0;
  padding: 0;
  margin: 0;
  min-width: 0;
}

.basis legend {
  font-weight: 600;
  margin-bottom: 8px;
  padding: 0;
}

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 100%;
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.segmented span {
  display: block;
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 0.92rem;
  color: var(--muted);
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--fg);
  font-weight: 600;
  box-shadow: var(--shadow);
  outline: 1px solid var(--border);
}

.hint {
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 8px;
}

/* ---------- tables */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

caption {
  text-align: left;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0 0 8px;
}

th,
td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  text-align: left;
}

thead th {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  white-space: nowrap;
}

tfoot td,
tfoot th {
  font-weight: 600;
  border-bottom: 0;
  background: var(--surface-2);
}

.payouts {
  min-width: 900px;
}

th[scope="row"],
.watch td:nth-child(-n + 2),
table.sub td:nth-child(-n + 3),
.options td:first-child {
  white-space: nowrap;
}

.payouts th[scope="row"] {
  white-space: normal;
  min-width: 210px;
}

.expander {
  white-space: nowrap;
}

.payouts tbody > tr.reseller > * {
  border-bottom: 1px solid var(--border);
}

.expander {
  all: unset;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 4px;
}

.expander::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
}

.expander[aria-expanded="true"]::before {
  transform: rotate(90deg);
}

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

.terms-line {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 400;
  margin-top: 2px;
}

tr.detail > td {
  background: var(--surface-2);
  padding: 10px 12px 14px;
}

table.sub {
  min-width: 760px;
  font-size: 0.86rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

table.sub th,
table.sub td {
  padding: 6px 10px;
}

.row-excluded td {
  color: var(--muted);
}

.row-held td:first-child {
  box-shadow: inset 3px 0 0 var(--warn);
}

.delta-up {
  color: var(--ok);
}

.delta-down {
  color: var(--bad);
}

/* ---------- pills */

.pill {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.pill-ok {
  color: var(--ok);
  background: var(--ok-soft);
}

.pill-warn {
  color: var(--warn);
  background: var(--warn-soft);
}

.pill-bad {
  color: var(--bad);
  background: var(--bad-soft);
}

.pill-neutral {
  color: var(--muted);
  background: var(--surface-2);
}

/* ---------- held + watch */

.held-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: 12px;
}

.held-card {
  padding: 14px 16px;
  border-left: 4px solid var(--warn);
  min-width: 0;
}

.held-card header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  margin-bottom: 6px;
}

.held-card .id {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--warn);
  margin-right: 6px;
}

.held-card .amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.held-card .amount small {
  display: block;
  font-weight: 400;
  font-size: 0.75rem;
}

.held-card .meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.held-card p {
  font-size: 0.92rem;
}

.held-card dl {
  margin: 0;
}

.held-card dt {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.held-card dd {
  margin: 0 0 8px;
  font-size: 0.92rem;
}

.options {
  margin-top: 4px;
  font-size: 0.86rem;
}

.options td,
.options th {
  padding: 5px 8px;
}

.watch {
  min-width: 720px;
}

.notes {
  margin: 12px 0 0;
  padding-left: 20px;
  font-size: 0.92rem;
}

.subhead {
  margin: 24px 0 8px;
}

/* ---------- assumptions, checks, questions */

.prose {
  padding: 16px 20px;
}

.prose ul,
.prose ol {
  margin: 0;
  padding-left: 20px;
}

.prose li {
  margin-bottom: 7px;
}

.prose li:last-child {
  margin-bottom: 0;
}

.terms-table {
  min-width: 640px;
}

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

.checks li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.checks li:last-child {
  border-bottom: 0;
}

.checks .pill {
  grid-row: span 2;
  align-self: start;
  margin-top: 2px;
}

.checks .name {
  font-weight: 600;
}

.checks .detail {
  font-size: 0.86rem;
  color: var(--muted);
  min-width: 0;
  overflow-wrap: anywhere;
}

.questions li {
  font-weight: 500;
}

footer {
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

noscript p {
  padding: 12px 16px;
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 8px;
}

/* ---------- statements page */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-top: 24px;
}

.controls label {
  font-weight: 600;
}

select,
button.btn {
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
}

button.btn {
  cursor: pointer;
  font-weight: 600;
}

button.btn:hover {
  background: var(--surface-2);
}

.statement {
  margin-top: 20px;
  padding: 20px;
}

.statement-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.statement-head p {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.statement h3 {
  margin: 22px 0 8px;
  font-size: 0.95rem;
}

.statement .lines {
  min-width: 720px;
}

.statement .lines td:first-child {
  white-space: nowrap;
}

.line-note {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
}

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

.adjustments li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 16px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.92rem;
}

.adjustments li > div {
  min-width: 0;
  flex: 1 1 260px;
}

.adjustments .reason {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
}

.totals {
  margin: 18px 0 0 auto;
  max-width: 360px;
  font-size: 0.95rem;
}

.totals div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 5px 0;
}

.totals .due {
  border-top: 2px solid var(--fg);
  margin-top: 4px;
  padding-top: 8px;
  font-weight: 700;
  font-size: 1.05rem;
}

.how {
  margin-top: 20px;
  padding: 14px 16px;
  background: var(--accent-soft);
  border-radius: 8px;
  font-size: 0.92rem;
}

.how h3 {
  margin: 0 0 6px;
}

.how p {
  margin: 0 0 6px;
}

.how p:last-child {
  margin: 0;
}

.copy-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 18px;
}

.copy-status {
  font-size: 0.88rem;
  color: var(--muted);
}

textarea.csv {
  width: 100%;
  min-height: 160px;
  margin-top: 10px;
  font: 0.8rem/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.rounding-note {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.terms-foot {
  font-weight: 400;
  color: var(--muted);
}

.stack-gap {
  margin-top: 12px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }
  .wrap {
    padding-block: 20px 36px;
  }
  .result {
    font-size: 1rem;
    padding: 14px;
  }
  .statement {
    padding: 14px;
  }
  .segmented {
    display: flex;
  }
  .segmented label {
    flex: 1 1 auto;
  }
  .segmented span {
    text-align: center;
    padding: 7px 10px;
  }
}
