:root {
  color-scheme: light;
  --ink: #182e48;
  --muted: #4f6277;
  --paper: #f4f7fb;
  --line: #d8e3ef;
  --blue: #255d9b;
  --navy: #173b66;
  --ice: #e8f2fe;
  --surface: #f6f9fd;
  font-family: "Hiragino Sans", "Yu Gothic", Meiryo, "Noto Sans CJK JP", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); line-height: 1.65; }
.wrap { width: min(750px, calc(100% - 48px)); margin-inline: auto; }
.hero { padding: 24px 0 19px; text-align: center; }
.hero p { margin: 6px auto 0; color: var(--muted); font-size: .91rem; }
h1, h2, h3 { line-height: 1.4; }
h1 { margin: 0; font-size: clamp(1.3rem, 2.6vw, 1.68rem); letter-spacing: .035em; }
.small { display: none; }
.workspace { padding-bottom: 42px; }
.toolbar, .guides, .modes, .actions, .legend { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar { justify-content: space-between; gap: 10px; padding: 0 0 9px; border-bottom: 1px solid var(--line); }
.modes { gap: 0; padding: 3px; background: #edf3fa; border-radius: 7px; }
button, a, input, select { font: inherit; }
button { cursor: pointer; color: inherit; }
.modes button, .guides button, .guides a {
  min-height: 44px;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-weight: 750;
  font-size: .875rem;
}
.modes button[aria-pressed=true] { background: var(--navy); color: #fff; }
.guides button, .guides a { color: var(--navy); }
.guides button { background: var(--surface); border-color: var(--line); }
.guides a { display: inline-flex; align-items: center; text-underline-offset: 3px; }
.mode-info { color: var(--muted); font-size: .84rem; margin: 10px 2px 18px; }
details.chapter, .result-card { border: 1px solid var(--line); border-radius: 12px; background: #fff; margin: 0 0 14px; }
summary { cursor: pointer; }
.chapter > summary {
  list-style: none;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 9px 15px;
  min-height: 54px;
  background: var(--ice);
  border-radius: 11px;
  color: var(--navy);
  font-size: 1.05rem;
  font-weight: 800;
  scroll-margin-top: 12px;
}
.chapter[open] > summary { border-radius: 11px 11px 0 0; }
.chapter > summary::-webkit-details-marker { display: none; }
.chapter > summary::after {
  content: "＋";
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid #b9cfe5;
  color: var(--blue);
  font-size: 1rem;
}
.chapter[open] > summary::after { content: "－"; }
.num {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border-radius: 6px;
  background: #d5e6f8;
  color: var(--navy);
  font-size: .77rem;
  font-variant-numeric: tabular-nums;
}
.summary-value { display: block; color: var(--muted); font-size: .76rem; font-weight: 500; overflow-wrap: anywhere; }
.chapter-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 17px;
  border-top: 1px solid var(--line);
  padding: 19px;
}
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.field { display: grid; grid-template-rows: 1fr auto auto; min-width: 0; font-size: .85rem; font-weight: 700; }
.field span { align-self: end; margin-bottom: 5px; }
.field small, .choice-group > small { display: block; margin-top: 5px; line-height: 1.5; }
.choice-group > small { color: var(--muted); font-size: .8rem; }
.field small, .hint { color: var(--muted); font-weight: 400; font-size: .8rem; }
.field input, .field select {
  width: 100%;
  min-width: 0;
  height: 44px;
  padding: 6px 10px;
  border: 1px solid #a7bad0;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 500;
}
.field input[type=date] { appearance: none; }
.field input[data-money] { font-variant-numeric: tabular-nums; }
fieldset { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
legend { font-size: .86rem; font-weight: 800; margin-bottom: 7px; }
.options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 12px;
}
.options label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  min-height: 42px;
  padding: 5px 7px;
  border-bottom: 1px solid var(--line);
  font-size: .85rem;
  cursor: pointer;
}
.options label:has(:checked) {
  background: var(--surface);
  box-shadow: inset 0 -2px var(--blue);
  color: var(--navy);
  font-weight: 750;
}
.options input { flex: none; accent-color: var(--blue); width: 1rem; height: 1rem; margin: 0; }
.choice-group--housing .options { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.choice-group--loanType .options { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.choice-hint { margin: 7px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.5; }
[hidden] { display: none !important; }
.subgroup { margin-top: 15px; padding-top: 13px; border-top: 1px solid var(--line); }
.subgroup h3 { margin: 0 0 10px; font-size: .95rem; }
.actions { justify-content: center; margin-top: 17px; }
.primary { min-height: 48px; padding: 8px 28px; border: 1px solid var(--navy); border-radius: 8px; background: var(--navy); color: #fff; font-weight: 800; }
.status { color: var(--muted); font-size: .84rem; }
.status:empty { display: none; }
#results { margin-top: 27px; outline: none; }
#results h2 { margin: 0 0 10px; font-size: 1.35rem; }
.result-card { padding: 18px; overflow-wrap: anywhere; }
.result-card h3 { margin: 0 0 10px; font-size: 1.04rem; }
.result-overview { border-top: 3px solid var(--blue); }
.result-status { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 0 0 11px; color: var(--muted); font-size: .83rem; }
.result-status span:first-child { font-weight: 750; color: var(--navy); }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.metric { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .82rem; }
.metric strong { display: block; color: var(--navy); font-size: 1.22rem; font-variant-numeric: tabular-nums; }
.metric--featured {
  grid-column: 1 / -1;
  grid-row: 1;
  padding: 13px 15px;
  border: 0;
  border-radius: 8px;
  background: var(--ice);
  font-weight: 750;
}
.metric--featured strong { font-size: clamp(1.55rem, 4.4vw, 2rem); }
.tax-breakdown { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 14px; margin: 13px 0; font-size: .85rem; }
.tax-breakdown dt { color: var(--muted); }
.tax-breakdown dd { margin: 0; font-weight: 750; }
.hold-notice { margin: 0 0 12px; padding: 11px 13px; border: 1px solid #e9ca8f; border-radius: 8px; background: #fff7e6; font-size: .86rem; }
.hold-notice strong { display: block; color: #764213; }
.result-notes { border-top: 1px solid var(--line); padding-top: 9px; color: var(--muted); font-size: .83rem; }
.result-notes summary { font-weight: 700; }
.chart-row { display: grid; grid-template-columns: 4rem minmax(0, 1fr) max-content; gap: 8px; align-items: center; margin: 5px 0; font-size: .8rem; }
.track { display: flex; min-width: 0; height: 11px; background: #edf3fb; border-radius: 4px; overflow: hidden; }
.national { background: var(--blue); }
.local { background: #d5a64d; }
.legend { margin: 0 0 9px; font-size: .8rem; }
.legend i { display: inline-block; width: .85em; height: .85em; margin-right: 4px; }
.scroller { max-width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; font-size: .83rem; }
th, td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { display: grid; grid-template-columns: 4.2rem minmax(0, 1fr); align-items: start; gap: 7px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.checks button { border: 0; padding: 1px 2px; background: transparent; text-decoration: underline; text-align: left; overflow-wrap: anywhere; }
.badge { justify-self: start; padding: 2px 7px; border-radius: 5px; background: var(--ice); color: var(--navy); font-size: .75rem; font-weight: 800; }
.badge.hold, .badge.fail { background: #fff2d9; color: #764213; }
/* Guide topics stay in the page so readers can return to the form. */
.guide-panel {
  margin: 0 0 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  font-size: .87rem;
}
.guide-panel h2 { margin: 0 0 8px; font-size: 1.12rem; }
.guide-panel ol { padding-inline-start: 1.35rem; }
.guide-link { border: 0; padding: 4px 0; background: transparent; color: var(--blue); font-weight: 750; text-decoration: underline; text-underline-offset: 3px; }
.chapter-links { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chapter-links a { display: inline-flex; align-items: center; padding: 5px 9px; min-height: 36px; border: 1px solid var(--line); border-radius: 6px; background: white; font-size: .82rem; text-decoration: none; }
.result-heading { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: start; gap: 4px 10px; }
footer { border-top: 1px solid var(--line); padding: 14px 0; color: var(--muted); font-size: .78rem; text-align: center; }
footer span { margin-left: 8px; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid #9c6014; outline-offset: 2px; }
@media (max-width: 740px) {
  .wrap { width: calc(100% - 40px); }
  .hero { padding: 19px 0 13px; }
  .chapter-body { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 13px; }
  .chapter > summary { padding: 10px 12px; }
}
@media (max-width: 550px) {
  .small { display: initial; }
  .toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; padding: 0 0 5px; }
  .modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .guides { justify-content: space-between; gap: 3px; }
  .guides button, .guides a { padding-inline: 5px; font-size: .76rem; }
  .choice-group--housing .options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choice-group--loanType .options { gap: 0 3px; }
  .choice-group--housing label, .choice-group--loanType label { gap: 4px; padding-inline: 3px; font-size: .76rem; }
  .options { gap: 0 6px; }
  .options label { font-size: .8rem; }
  .field-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .metrics { gap: 0 8px; }
  .metric:not(.metric--featured) strong { font-size: 1.02rem; }
  .result-card { padding: 12px; }
  .chart-row { grid-template-columns: 3.2rem minmax(0, 1fr) max-content; }
}

@media (max-width: 355px) {
  .options label { gap: 4px; padding-inline: 3px; }
  .choice-group--loanType label { flex-direction: column; justify-content: center; text-align: center; }
}

body { background: #fff; }
main { max-width: 750px; margin-inline: auto; background: var(--paper); }
main .wrap { width: auto; margin-inline: 18px; }
.entry-panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
@media (min-width: 551px) {
  .field-grid { row-gap: 5px; }
  .field-grid > .field { grid-row: span 3; grid-template-rows: subgrid; padding-bottom: 7px; }
}
@media (max-width: 740px) {
  main { width: calc(100% - 40px); }
  main .wrap { margin-inline: 12px; }
  .entry-panel { padding: 9px; }
}
@media (max-width: 355px) {
  main { width: calc(100% - 24px); }
  main .wrap { margin-inline: 8px; }
  .entry-panel { padding: 7px; }
}
@media (min-width: 551px) {
  .choice-group--housing .options { gap: 0 5px; }
  .choice-group--housing .options label { padding-inline: 4px; gap: 5px; font-size: .81rem; }
}
@media (max-width: 355px) {
  .choice-group--energy .options label:first-child { grid-column: 1 / -1; }
}

.chapter[open] > summary .summary-value, .summary-value:empty { display: none; }
.chapter-help { justify-self: start; }
.input-more { margin-top: 13px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; }
.input-more summary { color: var(--navy); font-size: .86rem; font-weight: 750; }
.input-more[open] > :nth-child(2) { margin-top: 10px; }
.term-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.term-controls label { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.term-controls input { flex: 1; }
.term-controls input[type=hidden] { display: none; }
.check-note { margin: 2px 0 0; font-size: .82rem; color: var(--muted); }
.result-card > summary { font-weight: 750; color: var(--navy); }
.input-help {
  position: fixed;
  z-index: 3;
  right: 14px;
  bottom: 12px;
  width: min(330px, calc(100% - 28px));
  max-height: 28dvh;
  overflow: auto;
  padding: 9px 12px;
  border: 1px solid #b9cfe5;
  border-radius: 10px;
  background: #fcfdff;
  box-shadow: 0 6px 20px #173b6622;
  font-size: .82rem;
}
.help-top { display: flex; align-items: center; justify-content: space-between; gap: 7px; }
.help-top h2 { margin: 0; font-size: .88rem; color: var(--navy); }
.help-top button { min-height: 34px; border: 1px solid var(--line); border-radius: 6px; background: white; }
.input-help p { margin: 5px 0; overflow-wrap: anywhere; }
#help-question { font-weight: 750; }
#help-entry { color: var(--muted); }
@media (min-width: 1240px) {
  .input-help { left: calc(50% + 388px); right: auto; top: 110px; bottom: auto; width: min(242px, calc(50% - 402px)); max-height: 68dvh; }
}

.result-notes dt { font-weight: 700; }
.result-notes dd { margin: 2px 0 9px; }

.quick-totals { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; margin-top: 9px; }
.quick-totals { margin-bottom: 12px; }
.quick-totals .metric { grid-row: auto; grid-column: auto; padding: 11px; border: 1px solid var(--line); border-radius: 8px; }
.quick-totals .metric h3, .quick-totals .metric p { margin: 0; }
.quick-totals .metric p { margin-top: 5px; color: var(--muted); }
.quick-checks button { display: block; }
#quick-fields .chapter .guide-link { align-self: start; }
@media (max-width: 550px) { .quick-totals { grid-template-columns: 1fr; } }

.quick-assumptions { background:var(--surface); border:1px solid var(--line); border-radius:9px; padding:12px; margin-bottom:14px; font-size:.86rem; }
.quick-assumptions h2 { font-size:1rem; margin:0 0 6px; }
.quick-assumptions p { margin:5px 0; }
.quick-assumptions summary { font-weight:700; margin-top:8px; }
.quick-assumptions .guide-link { margin-top:6px; text-align:left; }
.field-question {
  border:0; background:transparent; padding:0 0 4px; text-align:left; line-height:1.5;
  color:var(--ink); font-size:inherit; font-weight:750; cursor:pointer;
  text-decoration:underline; text-decoration-color:#b4c7dc; text-underline-offset:3px;
}
.field > .field-question { align-self:end; }
.choice-group legend { max-width:100%; }
.options label { align-items:flex-start; min-height:56px; padding:8px; background:#fff; border:1px solid var(--line); border-radius:7px; margin-bottom:5px; }
.options input { margin-top:3px; }
.options label small { display:block; color:var(--muted); font-size:.74rem; line-height:1.4; margin-top:3px; font-weight:400; }
.choice-group--housing .options { grid-template-columns:repeat(2,minmax(0,1fr)); }
.choice-group--housing .options label { padding:8px; }
.document-note { padding:8px 10px; margin:8px 0; background:var(--surface); border-radius:6px; font-size:.83rem; }
.document-note:empty { display:none; }
.quick-balance { padding:8px 10px; background:var(--surface); border-radius:6px; font-size:.85rem; }
.quick-balance strong { white-space:nowrap; }
.help-top { position:sticky; top:0; background:#fcfdff; border-bottom:1px solid var(--line); padding-bottom:5px; }
#help-question { font-size:.88rem; margin:8px 0; }
#help-content h4 { color:var(--navy); font-size:.82rem; margin:7px 0 1px; }
#help-content p { margin:0 0 6px; }
@media (max-width:1239px) {
  .input-help { position:static; width:100%; grid-column:1 / -1; grid-row:auto; max-height:42dvh; margin:8px 0; }
  .field-grid > .input-help { grid-column:1 / -1; }
}
.mortgage-wp-help-gutter #input-help {
  --help-offset: min(var(--embed-help-top, 110px), max(0px, calc(100% - 56px)));
  position: fixed;
  inset: var(--help-offset) 12px auto auto;
  width: 216px;
  max-height: min(var(--embed-help-height, 68dvh), calc(100% - var(--help-offset)));
  margin: 0;
}
@media (max-width:355px) {
  .choice-group--energy .options label:first-child { grid-column:auto; }
  .choice-group--loanType .options { grid-template-columns:1fr; }
  .choice-group--loanType label { flex-direction:row; justify-content:start; text-align:left; }
}
.unit-control { display:grid; grid-template-columns:minmax(0,1fr) auto; align-items:center; gap:5px; }
.unit-control > span { align-self:center; margin:0; color:var(--muted); font-size:.8rem; }
@media (max-width:355px) {
  .choice-group--housing .options label:has([value="resale"]),
  .choice-group--housing .options label:has([value=""]) { grid-column:1 / -1; }
}

/* Shared spacing for questions, cards, and conditional fields. */
.mode-info { margin: 8px 0; }
.chapter-body { padding-top: 24px; }
.field > .field-question, .choice-group legend { margin-bottom: 10px; }
.field-question {
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
  text-decoration: none;
}
.field-question::after {
  content: "？";
  flex: 0 0 1.15rem;
  color: var(--blue);
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: .74rem;
  line-height: 1.12rem;
  text-align: center;
}
.field small, .choice-group > small { margin-top: 8px; }
.choice-group { margin-bottom: 24px; }
.options, .choice-group--housing .options, .choice-group--loanType .options { gap: 10px; }
.options label { margin: 0; align-self: stretch; }
.choice-group--loanUse .options, .choice-group--incomeDoc0 .options, .choice-group--incomeDoc1 .options { grid-template-columns: repeat(2, minmax(0,1fr)); }
.loan-ownership { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 17px; }
.loan-ownership h3 { font-size: 1rem; margin: 0 0 14px; color: var(--navy); }
.condition-notice { background: #fff7e8; border: 1px solid #ecd6ab; padding: 8px 10px; border-radius: 6px; color: #63421d; font-size: .84rem; }
.quick-totals small, .quick-recap small { display: block; font-size: .78rem; color: var(--muted); }
.quick-recap { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; margin: 10px 0; }
.quick-recap dd { margin: 0; }
.quick-recap dt { font-size: .8rem; }
.quick-assumptions .guide-link { margin: 0; display: inline; }
@media (min-width: 551px) {
  .field-grid { row-gap: 3px; }
  .field-grid > .field { padding-bottom: 17px; }
}
@media (max-width: 550px) {
  .chapter-body { padding-top: 18px; }
  .field-grid { gap: 17px; }
  .field > .field-question, .choice-group legend { margin-bottom: 7px; }
  .options, .choice-group--housing .options, .choice-group--loanType .options { gap: 7px; }
  .choice-group .options { grid-template-columns: minmax(0, 1fr); }
}

.result-issue { margin-block: 12px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; }
.result-issue h4 { margin: 0; color: var(--navy); }
.result-issue .checks li, .result-notes .checks li { display: block; }
.result-issue .checks li:last-child { border-bottom: 0; }
.comparison-list > li { margin-block: 8px; }

.launch-scope { margin-block: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.launch-scope .field-grid { grid-template-columns: minmax(0, 1fr); }
.quick-result-links { display: grid; gap: 6px; justify-items: start; }
.chapter-links #clear-inputs { margin-inline-start: auto; min-height: 40px; padding-inline: 12px; }
#restored-note { margin-block: 4px 8px; font-size: .82rem; }
.quick-result-links { gap: 12px; }
.tax-breakdown .tax-explanation { margin-block: 4px; color: var(--muted); font-weight: 400; }

@media (max-width: 550px) {
  .toolbar { gap: 8px; }
  .modes button { padding-inline: 4px; }
  .guides { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .guides button, .guides a { justify-content: center; text-align: center; }
  .chapter-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chapter-links a, .chapter-links #clear-inputs {
    justify-content: center;
    min-height: 44px;
    margin-inline-start: 0;
    padding-inline: 4px;
    text-align: center;
  }
}

.launch-scope h2 { margin: 0 0 8px; font-size: 1rem; }
