/*
  Ledger stock and ink. The visual model is a mortgage note: hairline rules,
  numbered clauses, figures set in a serif with tabular numerals so columns of
  money line up. Meaning is never carried by colour alone; every state that has
  a colour also has a word.
*/

:root {
  --paper: #eef1ec;
  --paper-sunk: #e4e8e1;
  --ink: #143028;
  --ink-soft: #4c5f58;
  --rule: #a8b5ac;
  --rule-fine: #c8d1c8;
  --ledger: #2e6b52;
  --limit: #8a5a00;
  --refuse: #7e2b22;
  --navy: #102a43;
  --sky: #2d6f8e;

  --serif: Georgia, "Iowan Old Style", "Source Serif Pro", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --measure: 66ch;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 0.6rem 1rem;
  z-index: 10;
}
.skip:focus { left: 0; }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--ledger);
  outline-offset: 2px;
}

/* ---------- Masthead ---------- */

.masthead {
  max-width: 78rem;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 1.75rem;
  border-bottom: 1px solid var(--rule);
}

.wordmark, .eyebrow {
  font-family: var(--serif);
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  margin: 0 0 1.5rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-family: var(--sans);
  font-size: 0.76rem;
  font-weight: 700;
}

.masthead h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.9rem, 5vw, 3rem);
  line-height: 1.12;
  letter-spacing: -0.015em;
  margin: 0 0 1rem;
  max-width: 22ch;
}

.standfirst {
  margin: 0;
  max-width: var(--measure);
  color: var(--ink-soft);
  font-size: 1.02rem;
}

/* ---------- Layout ---------- */

.calculator-main {
  max-width: 78rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: grid;
  gap: 3rem;
  align-items: start;
}

@media (min-width: 62rem) {
  .calculator-main {
    grid-template-columns: minmax(0, 24rem) minmax(0, 1fr);
    gap: 4rem;
  }
  .results { position: sticky; top: 2rem; }
}

/* ---------- Form ---------- */

form { margin: 0; }

fieldset {
  border: 0;
  border-top: 1px solid var(--rule-fine);
  margin: 0 0 2rem;
  padding: 1.25rem 0 0;
}

fieldset:first-of-type { border-top: 0; padding-top: 0; }

legend {
  font-family: var(--serif);
  font-size: 1.15rem;
  padding: 0;
  margin-bottom: 0.35rem;
}

.fieldset-note {
  margin: 0 0 1.25rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
  max-width: 48ch;
}

.field { margin-bottom: 1.4rem; }

label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.2rem;
}

.optional {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.hint {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--ink-soft);
  max-width: 46ch;
}

input[type="text"], select {
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  font-size: 1.05rem;
  width: 100%;
  padding: 0.5rem 0.6rem;
  background: var(--paper-sunk);
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink);
}

select { font-family: var(--sans); font-size: 0.95rem; }

input[type="text"]:disabled {
  color: var(--ink-soft);
  background: transparent;
  border-style: dashed;
}

.input-wrap {
  display: flex;
  align-items: stretch;
  gap: 0.4rem;
}
.input-wrap .unit {
  font-family: var(--serif);
  color: var(--ink-soft);
  align-self: center;
  font-size: 1.05rem;
}

.field.checkbox label,
.cap-none label,
.feature label {
  font-weight: 400;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  line-height: 1.4;
}

input[type="checkbox"], input[type="radio"] {
  margin: 0.25rem 0 0;
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--ledger);
  flex: none;
}

.mode-options { display: grid; gap: 0.6rem; margin-top: 0.6rem; }
.mode-option {
  font-weight: 400;
  display: flex;
  gap: 0.55rem;
  align-items: center;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--rule-fine);
  border-radius: 2px;
  cursor: pointer;
}
.mode-option:has(input:checked) {
  border-color: var(--ledger);
  background: var(--paper-sunk);
  font-weight: 600;
}

/* Cap rows: a number and an explicit "no limit" choice, kept visibly distinct */
.cap-row {
  display: grid;
  gap: 0.4rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--rule-fine);
}
.cap-row:last-child { border-bottom: 0; }
.cap-controls { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.cap-controls .input-wrap { max-width: 9rem; }
.cap-none label { font-size: 0.9rem; align-items: center; }

.feature { margin-bottom: 0.55rem; font-size: 0.92rem; }

.actions { margin-top: 2rem; }

button.primary {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  color: var(--paper);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 0.75rem 1.4rem;
  cursor: pointer;
}
button.primary:hover { background: var(--ledger); border-color: var(--ledger); }

/* ---------- Errors ---------- */

.error-summary {
  border: 1px solid var(--refuse);
  border-left-width: 5px;
  padding: 1rem 1.1rem;
  margin-bottom: 1.75rem;
  background: var(--paper-sunk);
}
.error-summary h2 {
  font-family: var(--serif);
  font-size: 1.05rem;
  margin: 0 0 0.5rem;
  color: var(--refuse);
}
.error-summary ul { margin: 0; padding-left: 1.1rem; font-size: 0.92rem; }
.error-summary li { margin-bottom: 0.4rem; }
.error-summary a { color: var(--refuse); }

.field-error {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.86rem;
  color: var(--refuse);
  font-weight: 600;
}
.field-error::before { content: "Problem: "; }

input[aria-invalid="true"], select[aria-invalid="true"] {
  border-color: var(--refuse);
  border-width: 2px;
}

/* ---------- Results ---------- */

.results { font-size: 1rem; }
.placeholder { color: var(--ink-soft); font-style: italic; }

.answer {
  border-top: 3px solid var(--ink);
  padding-top: 1.25rem;
  margin-bottom: 2.5rem;
}
.answer h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.35rem, 3vw, 1.75rem);
  line-height: 1.25;
  margin: 0 0 1.25rem;
  max-width: 30ch;
}

.headline-figures {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
}
.figure dt {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-bottom: 0.25rem;
  max-width: 22ch;
}
.figure dd {
  margin: 0;
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.5rem, 4vw, 2rem);
  line-height: 1.1;
}
.figure .sub {
  display: block;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-top: 0.3rem;
}

/* The derivation ledger: the point of the whole tool */
.ledger { margin-bottom: 2.5rem; }
.ledger h3, .results h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.2rem;
  margin: 0 0 0.35rem;
}
.ledger .lead, .results .lead {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
  max-width: 52ch;
}

.ledger ol {
  list-style: none;
  counter-reset: clause;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}
.ledger li {
  counter-increment: clause;
  display: grid;
  grid-template-columns: 1.9rem minmax(0, 1fr) auto;
  gap: 0.4rem 0.75rem;
  align-items: baseline;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--rule-fine);
}
.ledger li::before {
  content: counter(clause);
  font-family: var(--serif);
  color: var(--ink-soft);
  font-size: 0.9rem;
}
.ledger .clause-label { font-size: 0.93rem; }
.ledger .clause-value {
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
  text-align: right;
  white-space: nowrap;
}
.ledger .clause-note {
  grid-column: 2 / -1;
  font-size: 0.84rem;
  color: var(--ink-soft);
}
.ledger li.binding { background: var(--paper-sunk); }
.ledger li.binding .clause-value { color: var(--limit); }

/* Provenance word, never a colour on its own */
.tag {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.05rem 0.35rem;
  white-space: nowrap;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}
caption {
  text-align: left;
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin-bottom: 0.5rem;
  max-width: 52ch;
}
th, td {
  text-align: right;
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--rule-fine);
}
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--ink-soft);
  border-bottom-color: var(--rule);
}
td { font-family: var(--serif); }
tr.ceiling td { font-weight: 700; }
tr.ceiling td:first-child::after {
  content: " lifetime ceiling";
  font-family: var(--sans);
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--limit);
}

.section { margin-bottom: 2.5rem; }

.assumptions { padding-left: 1.1rem; margin: 0; }
.assumptions li {
  margin-bottom: 0.6rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
  max-width: 56ch;
}

.refusal {
  border: 1px solid var(--refuse);
  border-left-width: 5px;
  padding: 1.25rem;
}
.refusal h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.3rem;
  margin: 0 0 0.6rem;
  color: var(--refuse);
}
.refusal p { margin: 0 0 0.75rem; max-width: 52ch; font-size: 0.95rem; }
.refusal p:last-child { margin-bottom: 0; }

.colophon {
  border-top: 1px solid var(--rule);
  max-width: 78rem;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 3rem;
}
.colophon p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
  max-width: var(--measure);
}

/* ---------- Shared site shell ---------- */

.site-header {
  max-width: 78rem;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  border-bottom: 1px solid var(--rule);
}

.site-name {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--serif);
  font-weight: 700;
  line-height: 1.15;
}

.rate-mark {
  width: 2rem;
  height: 1.5rem;
  display: inline-flex;
  align-items: end;
  gap: 0.18rem;
  padding: 0.2rem;
  border-left: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.rate-mark i {
  display: block;
  width: 0.34rem;
  background: var(--ledger);
}
.rate-mark i:nth-child(1) { height: 35%; }
.rate-mark i:nth-child(2) { height: 62%; }
.rate-mark i:nth-child(3) { height: 95%; }

.site-header nav, .colophon nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.1rem;
}

.site-header nav a, .colophon nav a {
  color: var(--ink-soft);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.25em;
  font-size: 0.84rem;
}

.site-header nav a[aria-current="page"] {
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.colophon nav { margin-top: 1.25rem; }
.copyright { margin-top: 1rem !important; font-size: 0.76rem !important; }

/* ---------- Editorial pages ---------- */

.article-main {
  max-width: 72rem;
  margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
  display: grid;
  grid-template-columns: minmax(0, 44rem) minmax(12rem, 18rem);
  gap: 4rem;
  align-items: start;
}

.article {
  min-width: 0;
}

.article h1 {
  margin: 0 0 1rem;
  font-family: var(--serif);
  font-size: clamp(2rem, 6vw, 3.3rem);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.025em;
}

.article h2 {
  margin: 2.5rem 0 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--rule-fine);
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 400;
  line-height: 1.2;
}

.article h3 {
  margin: 1.75rem 0 0.45rem;
  font-size: 1rem;
}

.article p, .article li { max-width: 66ch; }
.article a, .article-aside a { color: var(--ledger); }
.article .intro { font-size: 1.12rem; color: var(--ink-soft); }
.article ul, .article ol { padding-left: 1.3rem; }
.article li { margin-bottom: 0.55rem; }

.callout {
  margin: 1.5rem 0;
  padding: 1rem 1.1rem;
  border-left: 4px solid var(--ledger);
  background: var(--paper-sunk);
}
.callout p { margin: 0; }

.article-aside {
  position: sticky;
  top: 1.5rem;
  border-top: 3px solid var(--ink);
  padding-top: 1rem;
}
.article-aside h2 {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 400;
  margin: 0 0 0.7rem;
}
.article-aside ul { list-style: none; padding: 0; margin: 0; }
.article-aside li { margin: 0 0 0.65rem; font-size: 0.86rem; }

.term-list {
  margin: 1.5rem 0;
}
.term-list div {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--rule-fine);
}
.term-list dt { font-weight: 700; }
.term-list dd { margin: 0.2rem 0 0; color: var(--ink-soft); }

.faq-list details {
  border-bottom: 1px solid var(--rule-fine);
  padding: 1rem 0;
}
.faq-list summary {
  cursor: pointer;
  font-family: var(--serif);
  font-size: 1.08rem;
  font-weight: 700;
}
.faq-list details p { margin-bottom: 0; }

.button-link {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.65rem 1rem;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper) !important;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
}
.button-link:hover { background: var(--ledger); border-color: var(--ledger); }

@media (max-width: 54rem) {
  .site-header { align-items: flex-start; flex-direction: column; }
  .article-main { grid-template-columns: 1fr; gap: 2.5rem; }
  .article-aside { position: static; }
}

.nowrap { white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ------------------------------------------------------------------ *
 * Plain English toggle
 *
 * Intentional but subordinate to the calculator. State is carried by the
 * button's own words and by aria-pressed, never by colour alone.
 * ------------------------------------------------------------------ */

/* The class sets display, so the hidden attribute must win explicitly.
   Without this a visitor with JavaScript disabled sees a dead button. */
.text-mode[hidden] { display: none; }

.text-mode {
  max-width: 78rem;
  margin: 0 auto;
  padding: 0 1.5rem 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.text-mode-button {
  font-family: var(--sans, system-ui, sans-serif);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink, #143028);
  background: transparent;
  border: 1px solid var(--rule, #a8b5ac);
  border-radius: 2px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
}

.text-mode-button:hover {
  border-color: var(--ledger, #2e6b52);
  background: var(--paper-sunk, #e4e8e1);
}

.text-mode-button[aria-pressed="true"] {
  border-color: var(--ledger, #2e6b52);
  border-width: 2px;
  padding: calc(0.45rem - 1px) calc(0.9rem - 1px);
}

.text-mode-state {
  margin: 0;
  font-size: 0.85rem;
  color: var(--ink-soft, #4c5f58);
}

/* The mortgage term kept visible beneath a plain-language label. */
.term-note {
  display: block;
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--ink-soft, #4c5f58);
  margin-top: 0.15rem;
}

.hint .term-note { display: inline-block; }

/* ------------------------------------------------------------------ *
 * Optional sections: present but visually secondary to the ARM inputs
 * ------------------------------------------------------------------ */

fieldset.secondary legend {
  font-size: 1rem;
  color: var(--ink-soft, #4c5f58);
}

fieldset.secondary {
  border-top-style: dashed;
}

.housing-field .input-wrap { max-width: 14rem; }

.unit.period {
  font-size: 0.85rem;
  color: var(--ink-soft, #4c5f58);
}

/* ------------------------------------------------------------------ *
 * Optional results
 * ------------------------------------------------------------------ */

.housing-result .group-head td {
  padding-top: 1rem;
  font-family: var(--sans, system-ui, sans-serif);
  font-size: 0.82rem;
  color: var(--ink-soft, #4c5f58);
  border-bottom: 0;
}

.housing-result .pi-row td,
.housing-result .total-row td {
  font-weight: 700;
}

.housing-result .total-row td {
  border-top: 2px solid var(--rule, #a8b5ac);
  border-bottom: 0;
}

.scenario-costs { margin-bottom: 2rem; }

.payoff-result .warning,
.lead.warning {
  border-left: 3px solid var(--limit, #8a5a00);
  padding-left: 0.9rem;
}

@media (max-width: 30rem) {
  .text-mode { flex-direction: column; gap: 0.35rem; }
}
