html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden; /* prevent fixed-element horizontal scroll on mobile */
}
body {
  overflow-x: hidden; /* clip stray overflow without breaking Safari viewport recalc */
}
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: monospace;
  padding: 12px;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}
.hero {
  text-align: center;
  margin-bottom: 14px;
}
.hero-title {
  font-size: 22px;
  font-weight: bold;
  color: var(--text);
  line-height: 28px; /* pixel value: CJK fallback can't expand past this */
  min-height: 56px; /* 2 lines × 28px */
  letter-spacing: -0.3px;
  margin-bottom: 8px;
  padding-right: 40px; /* clear fixed top-right buttons */
}
.hero-sub {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-sub);
}
.hero-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  line-height: 17px; /* pin: CJK fallback isolation */
  white-space: nowrap;
}
.hero-actions {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.hero-amount {
  color: var(--accent-init);
  font-weight: bold;
}
.hero-sp {
  color: var(--accent);
}
.hero-re {
  color: var(--accent-re);
}
.hero-select {
  background: transparent;
  border: none;
  border-bottom: 1px solid currentColor;
  outline: none;
  font-family: monospace;
  font-size: 13px;
  cursor: pointer;
  padding: 0 14px 1px 0;
  -webkit-appearance: none;
  appearance: none;
  background-repeat: no-repeat;
  background-position: right 2px center;
  background-size: 8px 5px;
}
.hero-select.hero-sp {
  background-image: var(--arrow-sp);
}
.hero-select.hero-re {
  background-image: var(--arrow-re);
}
.hero-select option {
  background: var(--surface);
  color: var(--text);
}
/* Abbreviation-display wrapper for selects */
.abbr-wrap {
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.abbr-text {
  display: inline-block;
  font-family: monospace;
  font-size: 13px;
  font-weight: normal;
  border-bottom: 1px solid currentColor;
  padding: 0 14px 1px 0;
  white-space: nowrap;
  pointer-events: none;
  background-repeat: no-repeat;
  background-position: right 2px center;
  background-size: 8px 5px;
}
.abbr-wrap.hero-sp .abbr-text {
  color: var(--accent);
  background-image: var(--arrow-sp);
}
.abbr-wrap.hero-re .abbr-text {
  color: var(--accent-re);
  background-image: var(--arrow-re);
}
.abbr-wrap.hero-init .abbr-text {
  color: var(--accent-init);
  background-image: var(--arrow-init);
}
/* State/metro/city chips — default dim arrow */
.abbr-wrap:not(.hero-sp):not(.hero-re):not(.hero-init) .abbr-text {
  background-image: var(--arrow-dim);
}
/* Lang button in fixed top-right: box matching theme button */
.hero-actions .abbr-wrap {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.hero-actions .abbr-text {
  background-image: none;
  padding: 0;
  border-bottom: none;
  font-size: 13px;
  line-height: 1;
}
.abbr-sel {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 13px;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}
.hero-divider {
  color: var(--text-nano);
  margin: 0 7px;
}
.ctrl-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 24px; /* pin row height: CJK label can't expand the row */
  margin-bottom: 5px;
  font-size: 11px;
  line-height: 14px; /* prevent CJK font fallback expanding line boxes */
  color: var(--text-mid);
}
.ctrl-row input[type="range"] {
  flex: 1;
}
.ctrl-row .val {
  color: var(--val);
  font-weight: bold;
  min-width: 36px;
}
/* ── Year range brush: [1995] ━━━━━━━━━ [2026] ── */
#year-range-row {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 6px 0 4px;
  touch-action: none; /* prevent scroll from stealing handle touches across the whole row */
}
#yr-start-label {
  width: 52px; /* fallback; JS overrides via lastPL in updateRangeBar() */
  flex-shrink: 0;
  font-size: 11px;
  font-family: monospace;
  color: var(--text-mid);
  white-space: nowrap;
  text-align: right;
  padding-right: 6px;
  pointer-events: none;
  touch-action: none;
}
#yr-end-label {
  flex-shrink: 0;
  font-size: 11px;
  font-family: monospace;
  color: var(--text-mid);
  white-space: nowrap;
  text-align: left;
  padding-left: 6px;
  pointer-events: none;
  touch-action: none;
  /* width set dynamically by JS to match chart PR */
}
#year-range-bar {
  position: relative;
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  user-select: none;
  touch-action: none;
  overflow: visible;
}
/* selected fill between handles */
#year-range-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--text-mid);
  opacity: 0.4;
  pointer-events: none;
  border-radius: 3px;
}
/* wait mode: hide handles, make fill a draggable block */
#year-range-bar.wait-mode .yr-handle {
  display: none;
}
#year-range-bar.wait-mode #year-range-fill {
  pointer-events: auto;
  cursor: grab;
  opacity: 0.55;
  top: -3px;
  bottom: -3px;
}
#year-range-bar.wait-mode #year-range-fill:active {
  cursor: grabbing;
}
/* clamp handle: narrow visual bar, wide touch target */
.yr-handle {
  position: absolute;
  top: -7px;
  bottom: -7px;
  width: 6px;
  background: var(--text-mid);
  border-radius: 2px;
  cursor: ew-resize;
  transform: translateX(-50%);
  touch-action: none;
}
/* invisible touch target centered on the 6px visual bar */
.yr-handle::after {
  content: "";
  position: absolute;
  top: -6px;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
}
/* three grip lines */
.yr-handle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 6px;
  background: rgba(128, 128, 128, 0.5);
  box-shadow:
    0 -3px 0 rgba(128, 128, 128, 0.5),
    0 3px 0 rgba(128, 128, 128, 0.5);
  border-radius: 1px;
}
/* ── Icon buttons (theme toggle, share) ─────────────────────────────── */
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-sub);
  font-family: monospace;
  font-size: 13px;
  padding: 0;
  width: 22px;
  height: 22px;
  cursor: pointer;
  line-height: 22px;
  text-align: center;
  vertical-align: middle;
}
/* ── Improvement % select ───────────────────────────────────────────── */
#improv-slider {
  flex: 1;
  background: var(--surface);
  color: var(--text-mid);
  border: 1px solid var(--border);
  padding: 2px 4px;
  font-size: 11px;
  font-family: monospace;
}
#improv-slider option {
  background: var(--surface);
  color: var(--text);
}
/* ── Unify all range input accent colors ────────────────────────────── */
input[type="range"] {
  accent-color: var(--text-mid);
}
.toggle-group {
  display: flex;
  gap: 4px;
  align-items: center;
}
.toggle-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-lo);
  font-family: monospace;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  word-break: keep-all;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
#btn-additive,
#btn-reinvest,
#btn-rental,
#btn-primary {
  min-width: 80px;
}
#label-start,
#label-end,
#label-improv {
  min-width: 92px;
}
#label-cashflow,
#label-includes,
#label-propmode,
#label-tax-bracket,
#label-refi,
#label-hpi-source {
  min-width: 74px;
}
#btn-refi-0,
#btn-refi-1,
#btn-refi-2,
#btn-refi-3 {
  min-width: 24px;
}
#btn-refi-rate,
#btn-refi-ltv {
  min-width: 36px;
}
#refi-type-group {
  display: none;
}
#row-ltv-pct {
  display: none;
}
#sg-refi .toggle-btn {
  flex: 1;
  justify-content: center;
  min-width: 56px;
}
.toggle-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}
.toggle-btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.settings-divider {
  border: none;
  border-top: 1px solid var(--border-dim);
  margin: 8px 0 8px;
}
.assm-title {
  font-size: 10px;
  font-weight: bold;
  color: var(--text-sub);
  text-align: center;
  margin-bottom: 4px;
}
#assumptions-line {
  font-size: 10px;
  line-height: 14px; /* 2 lines × 14px = 28px */
  color: var(--text-lo);
  text-align: center;
  margin-bottom: 8px;
}
#chart-wrap {
  width: 100%;
}
canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.slider-wrap {
  margin: 8px 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.slider-wrap input {
  flex: 1;
}
#year-label {
  font-size: 14px;
  color: var(--text);
  font-weight: bold;
  min-width: 60px;
}
#play-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--val);
  font-family: monospace;
  font-size: 16px;
  width: 32px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}
#play-btn:active {
  background: var(--btn-active-bg);
}
#speed-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-mid);
  font-family: monospace;
  font-size: 11px;
  width: 32px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}
#speed-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}
#speed-btn:active {
  background: var(--btn-active-bg);
}
.legend-wrap {
  margin-left: -12px;
  margin-right: -12px; /* span full viewport width without 100vw overflow */
  text-align: center;
  margin-top: 10px;
}
.legend {
  display: inline-flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 24px;
  text-align: left;
}
.legend-col {
  display: grid;
  grid-template-columns: 12px max-content max-content;
  column-gap: 8px;
  row-gap: 4px;
}
#leader-bar {
  text-align: center;
  margin-top: 6px;
  min-height: 14px;
}
.legend-leader {
  font-size: 11px;
  color: var(--text-mid);
  white-space: nowrap;
}
.leg-item {
  display: contents;
  font-size: 11px;
  cursor: pointer;
  user-select: none;
}
.leg-item > * {
  align-self: center;
  transition: opacity 0.15s;
}
.leg-item.hidden > * {
  opacity: 0.3;
}
.leg-item.hidden .leg-dot {
  background: var(--border) !important;
}
.leg-dot {
  width: 12px;
  height: 3px;
  border-radius: 2px;
}
.table-wrap {
  overflow-x: auto;
  margin-top: 14px;
}
table {
  border-collapse: collapse;
  font-size: 10px;
  width: 100%;
}
th,
td {
  border: 1px solid var(--border);
  padding: 4px 6px;
  text-align: right;
  white-space: nowrap;
  transition: opacity 0.15s;
}
th {
  background: var(--table-head-bg);
  color: var(--table-head-text);
}
td:first-child,
th:first-child {
  text-align: left;
}
.col-hidden {
  opacity: 0.2;
}
.note {
  font-size: 10px;
  color: var(--text-lo);
  margin-top: 12px;
  line-height: 1.6;
}
#note-dynamic-line {
  margin: 3px 0 6px;
  white-space: nowrap;
  overflow-x: auto;
}
#note-dynamic-line strong {
  display: inline;
  margin: 0;
}
.note strong {
  color: var(--text-sub);
  display: block;
  margin-top: 8px;
  margin-bottom: 2px;
}
.note strong:first-child {
  margin-top: 0;
}
.note ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.note li::before {
  content: "· ";
  color: var(--text-dim);
}
.note li {
  padding-left: 10px;
  text-indent: -10px;
}
.note .group-hd {
  color: var(--text-sub);
  font-style: italic;
  margin-top: 6px;
  padding-left: 0;
  text-indent: 0;
}
.note .group-hd::before {
  content: "";
}
.note a {
  color: var(--link);
  text-decoration: none;
}
.built-by {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-faint);
  text-align: center;
}
.built-by-label {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 8px;
}
.bmc-btn {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: #ffdd00;
  color: #000;
  text-decoration: none;
  font-size: 10px;
  font-weight: bold;
  white-space: nowrap;
  transition: opacity 0.15s;
}
.bmc-btn:hover {
  opacity: 0.85;
}
.socials {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}
.social-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text-sub);
  text-decoration: none;
  font-family: monospace;
  font-size: 11px;
  padding: 4px 10px;
  border: 1px solid var(--border-social);
  border-radius: 4px;
  transition:
    border-color 0.15s,
    color 0.15s;
  white-space: nowrap;
}
.social-link:hover {
  border-color: var(--text-lo);
  color: var(--val);
}
.social-icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  vertical-align: middle;
}
.note .src-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 0;
}
.note .src-list li {
  display: inline;
  text-indent: 0;
  padding: 0;
}
.note .src-list li::before {
  content: "· ";
}
/* ── Communication improvements ─────────────────────────────────── */
#chart-wrap {
  position: relative;
}
#chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--tooltip-bg);
  border: 1px solid var(--tooltip-border);
  padding: 5px 8px;
  font-family: monospace;
  font-size: 10px;
  color: var(--tooltip-text);
  border-radius: 3px;
  display: none;
  z-index: 10;
  line-height: 1.8;
  min-width: 130px;
  white-space: nowrap;
}
#outcome-callout {
  font-size: 11px;
  line-height: 1.7;
  color: var(--text-sub);
  text-align: left;
  margin: 4px 0 2px;
  min-height: 28px;
}
#outcome-callout strong {
  color: var(--text-hi);
  font-weight: bold;
}
#methodology-note {
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
  margin: 2px 0 4px;
}
#methodology-note a {
  color: var(--text-dim);
  text-decoration: none;
}
#methodology-note a:hover {
  color: var(--text-sub);
}
#primary-note {
  font-size: 11px;
  color: var(--primary-note-text);
  background: var(--primary-note-bg);
  border-left: 2px solid var(--primary-note-border);
  padding: 4px 8px;
  margin: 3px 0;
  line-height: 1.5;
  display: none;
}
#primary-note strong {
  color: var(--primary-note-strong);
}
/* Portrait: 1 column. Landscape or wide desktop: 2 columns. */
#settings-grid {
  grid-template-columns: 1fr;
}
@media (orientation: landscape), (min-width: 768px) {
  #settings-grid {
    grid-template-columns: 1fr 1fr;
  }
  #sg-prop {
    order: 1;
  }
  #sg-incl {
    order: 2;
  }
  #sg-refi {
    order: 3;
  }
  #sg-cf {
    order: 4;
  }
  #sg-hpi {
    order: 5;
  }
}
/* ── Landscape chart height: managed by JS updateChartMaxHeight() (accounts for body zoom) ── */
/* ── Landscape mobile: tighter cap + compressed hero ── */
@media (orientation: landscape) and (max-height: 500px) {
  #chart-wrap {
    max-height: 44vh; /* fallback only — JS overrides with zoom-corrected value */
  }
  .hero {
    margin-bottom: 6px;
  }
  .hero-title {
    font-size: 16px;
    line-height: 20px;
    min-height: 0;
    margin-bottom: 4px;
  }
  .hero-sub {
    gap: 4px;
    font-size: 11px;
  }
}
/* ── Proportional scaling: tablet / desktop / 4K ─────────────────────── */
@media (min-width: 1100px) {
  body {
    zoom: 1.1;
  }
}
@media (min-width: 1250px) {
  body {
    zoom: 1.25;
  }
}
@media (min-width: 1600px) {
  body {
    zoom: 1.6;
  }
}
@media (min-width: 2400px) {
  body {
    zoom: 2.3;
  }
}
@media (min-width: 3840px) {
  body {
    zoom: 3.5;
  }
}
.tip {
  display: inline-flex;
  align-items: center;
}
.tip-icon {
  position: relative;
  font-size: 9px;
  margin-left: 3px;
  color: var(--text-mid);
  opacity: 0.7;
  cursor: help;
  user-select: none;
}
.tip-icon[data-tip]::before {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: var(--tt-x, 50%);
  right: auto;
  transform: var(--tt-tx, translateX(-50%));
  background: var(--surface);
  color: var(--text-hi);
  font-size: 11px;
  line-height: 1.5;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 3px;
  white-space: pre-line;
  width: min(240px, 90vw);
  text-align: left;
  z-index: 999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.tip-icon[data-tip]:hover::before,
.tip-icon[data-tip].open::before {
  opacity: 1;
}
.tip-right .tip-icon[data-tip]::before {
  --tt-x: 0px;
  --tt-tx: none;
}
.tip-icon.tip-flipped[data-tip]::before {
  bottom: auto;
  top: calc(100% + 6px);
}
.tip-left .tip-icon[data-tip]::before {
  --tt-x: auto;
  right: 0;
  --tt-tx: none;
}
.leg-cagr {
  font-size: 10px;
  color: var(--text-sub);
}
/* ── Return decomposition panel ─────────────────────────────────── */
#decomp-panel {
  margin: 10px 0 6px;
  font-family: monospace;
}
#decomp-title {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
#decomp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.decomp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}
.decomp-table-head {
  text-align: left;
  padding-bottom: 3px;
  font-size: 9px;
  letter-spacing: 0.04em;
}
.decomp-row {
  cursor: pointer;
  user-select: none;
}
.decomp-lbl {
  color: var(--text-lo);
  white-space: nowrap;
  padding-right: 5px;
  text-align: right;
  width: 90px;
  transition: color 0.1s;
}
.decomp-row:hover .decomp-lbl {
  color: var(--val);
}
.decomp-row.active-edu .decomp-lbl {
  color: var(--val);
}
.decomp-row.decomp-sub .decomp-lbl {
  font-size: 10px;
  padding-left: 8px;
  opacity: 0.8;
}
.decomp-row.decomp-sub .decomp-amt {
  font-size: 10px;
  opacity: 0.8;
}
.decomp-row.decomp-sub .decomp-bar-track {
  height: 3px;
}
.decomp-row.decomp-sub .decomp-bar {
  height: 3px;
}
.decomp-bar-td {
  width: 80px;
  max-width: 80px;
  vertical-align: middle;
}
.decomp-bar-track {
  height: 5px;
  background: var(--surface);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}
.decomp-bar {
  height: 5px;
  border-radius: 2px;
  position: absolute;
  top: 0;
  left: 0;
  transition: width 0.25s ease;
}
.decomp-amt {
  padding-left: 5px;
  text-align: left;
  white-space: nowrap;
}
#decomp-divider {
  border: none;
  border-top: 1px solid var(--border-dim);
  margin: 4px 0;
}
#decomp-edu {
  font-size: 10px;
  color: var(--text-lo);
  line-height: 1.65;
  margin-top: 6px;
  min-height: 16px;
  border-left: 2px solid var(--border-dim);
  padding-left: 6px;
}
@keyframes arrow-bounce {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.55;
  }
  50% {
    transform: translateY(-5px);
    opacity: 1;
  }
}
#decomp-hint {
  font-size: 13px;
  margin-top: 6px;
  text-align: center;
}
.hint-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  line-height: 1.8;
}
.hint-arrows {
  display: inline-flex;
  gap: 3px;
}
.ha {
  display: inline-block;
  animation: arrow-bounce 1.3s ease-in-out infinite;
}
.ha:nth-child(1) {
  animation-delay: 0s;
}
.ha:nth-child(2) {
  animation-delay: 0.18s;
}
.ha:nth-child(3) {
  animation-delay: 0.36s;
}
/* ── Story row: CTA box — always pulses ── */
#story-row {
  animation: cta-pulse 1.7s ease-in-out infinite;
  border-style: solid !important;
  border-color: rgba(152, 152, 216, 0.7) !important;
  border-width: 1.5px !important;
  opacity: 1 !important;
}
/* No underline on the abbr-text inside the box — box already signals interaction */
#story-wrap .abbr-text {
  border-bottom: none;
}
/* ── Overlay legend row (above chart) ── */
@keyframes cta-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(152, 152, 216, 0.6);
    border-color: rgba(152, 152, 216, 0.7);
    opacity: 0.9;
  }
  55% {
    box-shadow: 0 0 0 8px rgba(152, 152, 216, 0);
    border-color: #9898d8;
    opacity: 1;
  }
}
#overlay-legend-row:not(.active) .leg-dot {
  background: var(--border) !important;
  transition: background 0.15s;
}
#legend.overlay-active .leg-dot,
#legend.overlay-active .leg-text,
#legend.overlay-active .leg-cagr {
  opacity: 0.2;
  transition: opacity 0.15s;
}
#wait-summary {
  font-size: 10px;
  font-family: monospace;
  color: var(--text-mid);
  text-align: center;
  line-height: 1.8;
  margin: 3px 0 4px;
  min-height: 0;
}
.wait-math {
  display: block;
  font-size: 9px;
  color: var(--text-sub);
  opacity: 0.75;
  line-height: 1.5;
  margin-bottom: 3px;
  letter-spacing: 0.01em;
}
