:root {
  --bg: #f6f3ec;
  --paper: #fffdf8;
  --ink: #1c2227;
  --muted: #5d656c;
  --line: #d9d3c6;
  --field: #ffffff;
  --a: #2457a6;
  --a-soft: #e6eefb;
  --b: #1d6b45;
  --b-soft: #e3f2e9;
  --warn: #8a4b00;
  --warn-soft: #fff1dc;
  --focus: #b8860b;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15191c;
    --paper: #1e2327;
    --ink: #e9e6df;
    --muted: #a5adb3;
    --line: #353c42;
    --field: #262c31;
    --a: #8db4f5;
    --a-soft: #1f2b3d;
    --b: #7fd1a3;
    --b-soft: #1b3127;
    --warn: #ffc77a;
    --warn-soft: #3a2b14;
    --focus: #e6b84a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--paper); padding: 6px 10px; z-index: 5; }

/* header */
.top { padding: 20px 0 8px; }
.brand { margin: 0 0 6px; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 10px; }
.lede { margin: 0 0 8px; }
.privacy { margin: 0 0 6px; font-weight: 600; color: var(--b); }
.example { margin: 0; font-size: .9rem; color: var(--muted); }

/* cards */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 14px 0;
}
h2 { font-size: 1.2rem; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
h3 { font-size: 1rem; margin: 18px 0 6px; }
.step {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--ink); color: var(--paper); font-size: .85rem; flex: none;
}
.hint { color: var(--muted); font-size: .88rem; margin: 6px 0 10px; }
small { display: block; color: var(--muted); font-size: .78rem; font-weight: 400; }

/* fields */
.f { display: block; font-weight: 600; font-size: .92rem; }
.f small { margin-bottom: 4px; }
.unit {
  display: flex; align-items: center; margin-top: 4px;
  background: var(--field); border: 1px solid var(--line); border-radius: 7px;
}
.unit:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.unit i { font-style: normal; color: var(--muted); padding: 0 2px 0 8px; }
.unit i:last-child { padding: 0 8px 0 2px; }
.unit input {
  flex: 1; min-width: 0; width: 100%; border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 16px; padding: 8px 6px;
}
.unit input:focus { outline: none; }
.unit input:disabled { color: var(--muted); }
.unit-inline { display: inline-flex; width: 8.5rem; vertical-align: middle; margin: 0 0 0 4px; }
input[type="text"].yname {
  font: inherit; font-weight: 700; font-size: 1rem; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 8px; flex: 1; min-width: 0;
}
input[type="text"].yname:focus, select:focus, button:focus-visible, input[type="radio"]:focus-visible,
input[type="checkbox"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.fields2 { display: grid; gap: 12px; margin: 12px 0; }
.fields4 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; font-size: .92rem; }
.check.small { font-weight: 400; }
input[type="radio"], input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--b); flex: none; }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; font-size: .92rem; padding: 0; margin-bottom: 6px; }
.seg { margin: 4px 0 8px; }
.seg label { display: inline-flex; gap: 6px; align-items: center; margin: 0 16px 6px 0; }
.seg-col label { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 8px; align-items: start; margin: 0 0 8px; }
.seg-col label input[type="radio"] { margin-top: 2px; }

/* plan grid: label | Plan A | Plan B */
.grid {
  display: grid; grid-template-columns: minmax(0, 1fr) 6.4rem 6.4rem;
  gap: 8px 8px; align-items: center;
}
.gh { font-weight: 700; text-align: center; padding: 6px 4px; border-radius: 7px; }
.gh small { font-size: .72rem; }
.ga { background: var(--a-soft); color: var(--a); }
.gb { background: var(--b-soft); color: var(--b); }
.gl { font-size: .9rem; font-weight: 600; }
.gc .unit { margin: 0; }
.gc .unit input { padding: 8px 4px; }
.na { text-align: center; color: var(--muted); font-size: .85rem; }
.na small { font-size: .72rem; }
#form.is-self .fam-only, #form:not(.is-self) .self-only, #form.no-copays .copay-row { display: none; }
.warn { background: var(--warn-soft); color: var(--warn); border-radius: 7px; padding: 8px 10px; font-size: .9rem; }

/* years */
.year { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 0 0 12px; }
.yhead { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.person { border-top: 1px dashed var(--line); padding: 8px 0 4px; position: relative; }
.person legend { font-size: .82rem; color: var(--muted); float: left; margin: 0 0 6px; }
.person .x { float: right; }
.pfields { clear: both; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pfields .f { font-size: .85rem; }
.yfoot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.ybills { font-size: .88rem; color: var(--muted); }
.addyear { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.addyear label { font-weight: 600; font-size: .92rem; }
select {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 8px; max-width: 100%;
}

/* buttons */
button {
  font: inherit; font-size: .95rem; font-weight: 600; cursor: pointer;
  background: var(--ink); color: var(--paper); border: 1px solid var(--ink); border-radius: 7px; padding: 9px 14px;
}
button.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
button.small, button.x { font-size: .82rem; padding: 5px 10px; }
button.x { background: transparent; color: var(--muted); border-color: var(--line); }

/* results */
.results { border-width: 2px; border-color: var(--ink); min-height: 420px; }
.headline { font-size: 1.08rem; font-weight: 600; margin: 4px 0 12px; }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.sum th, .sum td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.sum th:first-child { text-align: left; font-weight: 600; }
.sum thead th { font-size: .82rem; color: var(--muted); font-weight: 600; }
.sum thead th:nth-child(2) { color: var(--a); }
.sum thead th:nth-child(3) { color: var(--b); }
.sum tr.total th, .sum tr.total td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--ink); }
.drivers { margin: 0; padding-left: 20px; }
.drivers li { margin: 4px 0; }
details.bd { border-top: 1px solid var(--line); padding: 8px 0; }
details.bd summary { cursor: pointer; font-weight: 600; }
.bdgrid { display: grid; gap: 10px; margin-top: 8px; }
.receipt { font-size: .9rem; font-variant-numeric: tabular-nums; }
.receipt caption { text-align: left; font-weight: 700; padding: 4px 0; }
.receipt td { padding: 3px 0; border-bottom: 1px dotted var(--line); }
.receipt td.n { text-align: right; white-space: nowrap; padding-left: 8px; }
.receipt tr.total td { font-weight: 700; border-bottom: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; }
.status { font-size: .9rem; color: var(--b); font-weight: 600; }

.notes ul { padding-left: 20px; margin: 0; }
.notes li { margin: 6px 0; font-size: .93rem; }
.sources { font-size: .82rem; color: var(--muted); margin: 12px 0 0; }
.foot { color: var(--muted); font-size: .85rem; padding: 8px 0 28px; }

@media (min-width: 640px) {
  h1 { font-size: 2rem; }
  .grid { grid-template-columns: minmax(0, 1fr) 9rem 9rem; gap: 8px 14px; }
  .fields2 { grid-template-columns: 1fr 1fr; align-items: end; }
  .fields4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .pfields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bdgrid { grid-template-columns: 1fr 1fr; gap: 24px; }
}
@media (min-width: 900px) {
  .pfields { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media print {
  :root { --bg: #fff; --paper: #fff; --ink: #000; --muted: #444; --line: #bbb; --field: #fff; }
  body { font-size: 11pt; background: #fff; color: #000; }
  .noprint, .skip, .example, .x, button { display: none !important; }
  .card { border: 1px solid #bbb; padding: 10px 12px; margin: 8px 0; break-inside: avoid; }
  .results { min-height: 0; border: 2px solid #000; }
  #app { display: flex; flex-direction: column; }
  #results { order: -1; }
  .year { break-inside: avoid; }
  .unit { border-color: #bbb; }
  details.bd { break-inside: avoid; }
  details.bd summary { list-style: none; }
  .wrap { max-width: none; padding: 0; }
  a { color: #000; }
}
