:root {
  --paper: #f4f7f5;
  --ink: #102a43;
  --ink-soft: #486581;
  --teal: #0c7c72;
  --teal-dark: #075e57;
  --teal-pale: #dff3ef;
  --amber: #f0b429;
  --amber-pale: #fff7dd;
  --red: #c2413a;
  --line: #cbd5dc;
  --line-dark: #9fb0bd;
  --white: #fff;
  --shadow: 0 18px 50px rgba(16, 42, 67, .09);
  --radius: 14px;
  font-family: "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--paper); }
button, input, select { font: inherit; }
button, select, input { color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid rgba(12, 124, 114, .3); outline-offset: 3px; }

.topbar {
  height: 72px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 clamp(20px, 5vw, 72px); border-bottom: 1px solid var(--line);
  background: rgba(244, 247, 245, .94); position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(12px);
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; font-weight: 720; letter-spacing: -.02em; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; background: var(--ink); color: var(--white); border-radius: 9px; font-family: Georgia, serif; font-size: 21px; }
.icon-button, .close-button { border: 1px solid var(--line-dark); background: transparent; border-radius: 9px; min-height: 42px; padding: 0 13px; display: inline-flex; gap: 8px; align-items: center; font-weight: 650; }
.icon-button:hover, .secondary-button:hover { border-color: var(--teal); color: var(--teal-dark); background: var(--teal-pale); }
.demo-back-link { min-height: 42px; display: inline-flex; align-items: center; padding: 0 14px; text-decoration: none; white-space: nowrap; }

.page-shell { width: min(1440px, 100%); margin: 0 auto; padding: 0 clamp(18px, 4vw, 60px) 48px; }
.intro { padding: clamp(54px, 8vw, 112px) 0 clamp(40px, 6vw, 76px); max-width: 1020px; }
.eyebrow, .section-index { color: var(--teal-dark); font-size: 12px; line-height: 1; letter-spacing: .16em; text-transform: uppercase; font-weight: 800; margin: 0 0 14px; }
h1 { font-size: clamp(42px, 6.4vw, 88px); max-width: 1000px; line-height: .98; letter-spacing: -.055em; margin: 0; font-weight: 760; }
.intro-copy { max-width: 700px; font-size: clamp(18px, 2vw, 23px); line-height: 1.5; color: var(--ink-soft); margin: 28px 0 24px; }
.demo-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 0 0 18px; color: var(--ink-soft); font-size: 14px; }
.demo-badge { display: inline-flex; align-items: center; min-height: 30px; padding: 4px 10px; border: 1px solid rgba(12, 124, 114, .35); border-radius: 999px; background: var(--teal-pale); color: var(--teal-dark); }
.demo-meta a { color: var(--teal-dark); font-weight: 700; text-underline-offset: 3px; }
.profile-stamp { display: inline-flex; gap: 9px; align-items: center; border-top: 1px solid var(--line-dark); padding-top: 13px; color: var(--ink-soft); font-size: 14px; }
.stamp-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 5px var(--teal-pale); margin-right: 4px; }

.workspace { display: grid; grid-template-columns: minmax(300px, 390px) minmax(0, 1fr); gap: clamp(24px, 4vw, 56px); align-items: start; }
.input-panel { background: var(--ink); color: var(--white); border-radius: var(--radius); padding: clamp(24px, 3vw, 38px); position: sticky; top: 86px; max-height: calc(100vh - 104px); overflow-y: auto; box-shadow: var(--shadow); scrollbar-color: #53708a transparent; }
.input-panel .section-index, .input-panel .field-error { color: #8fe3d7; }
.input-panel h2 { color: var(--white); }
.section-heading { display: grid; grid-template-columns: 95px minmax(0, 1fr); align-items: start; margin-bottom: 26px; }
.compact-heading { display: block; }
.section-heading h2 { margin: 0; font-size: clamp(27px, 3vw, 38px); letter-spacing: -.035em; line-height: 1.08; }
.section-heading p:not(.section-index) { margin: 8px 0 0; color: var(--ink-soft); }

.entity-switch { border: 0; padding: 0; margin: 0 0 22px; }
.entity-switch legend, .field-label { font-size: 13px; font-weight: 680; margin-bottom: 8px; display: block; }
.entity-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.entity-switch legend { grid-column: 1 / -1; }
.entity-switch label { position: relative; }
.entity-switch input { position: absolute; opacity: 0; }
.entity-switch span { display: grid; place-items: center; min-height: 44px; border: 1px solid #53708a; border-radius: 8px; font-weight: 750; }
.entity-switch input:checked + span { background: var(--teal); border-color: var(--teal); }
.entity-switch input:focus-visible + span { outline: 3px solid rgba(143, 227, 215, .6); outline-offset: 2px; }
.choice-switch { border: 0; padding: 0; margin: 0 0 24px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice-switch legend { grid-column: 1 / -1; font-size: 13px; font-weight: 680; margin-bottom: 8px; }
.choice-switch label { position: relative; }
.choice-switch input { position: absolute; opacity: 0; }
.choice-switch span { min-height: 58px; border: 1px solid #53708a; border-radius: 8px; display: grid; align-content: center; padding: 9px 12px; }
.choice-switch strong { font-size: 14px; }
.choice-switch small { color: #b7c9d5; margin-top: 3px; }
.choice-switch input:checked + span { background: rgba(12,124,114,.34); border-color: #8fe3d7; }
.choice-switch input:focus-visible + span { outline: 3px solid rgba(143,227,215,.6); outline-offset: 2px; }
.field { display: block; margin: 0 0 20px; }
.field-group { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(100px, .8fr); gap: 12px; }
.money-input { display: flex; align-items: center; background: rgba(255,255,255,.08); border: 1px solid #53708a; border-radius: 8px; overflow: hidden; transition: border-color .18s, background .18s; }
.money-input:focus-within { border-color: #8fe3d7; background: rgba(255,255,255,.12); }
.money-input input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; padding: 12px 8px 12px 13px; color: var(--white); font-family: "Cascadia Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.money-input > span { color: #b7c9d5; padding-right: 12px; }
.hint { display: inline-grid; place-items: center; width: 17px; height: 17px; border: 1px solid #7290a8; border-radius: 50%; font-size: 11px; color: #b7c9d5; margin-left: 4px; }
.field-error { min-height: 17px; display: block; font-size: 12px; line-height: 1.35; margin-top: 5px; }
.field-note { display: block; color: #b7c9d5; font-size: 11px; line-height: 1.45; margin-top: 6px; }
.input-panel select, .plain-input { width: 100%; min-height: 44px; border: 1px solid #53708a; border-radius: 8px; background: #173b58; color: var(--white); padding: 8px 11px; }
.route-divider { display: flex; align-items: center; gap: 10px; margin: 31px 0 22px; color: #8fe3d7; font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.route-divider::after { content: ""; height: 1px; flex: 1; background: #53708a; }
.month-grid-scroll { overflow-x: auto; margin: 12px 0; border: 1px solid #53708a; border-radius: 9px; }
.month-grid { min-width: 720px; }
.month-grid th, .month-grid td { border-bottom: 1px solid #365772; padding: 7px 6px; }
.month-grid thead th { color: #b7c9d5; font-size: 10px; }
.month-grid tbody th { color: var(--white); width: 45px; }
.month-grid input { width: 112px; border: 1px solid #53708a; border-radius: 5px; background: rgba(255,255,255,.07); color: var(--white); padding: 7px; font: 12px "Cascadia Mono", Consolas, monospace; }
.month-grid td:nth-child(4) input, .month-grid td:nth-child(6) input { width: 64px; }
.yes-no { border: 0; border-bottom: 1px solid #365772; padding: 0 0 13px; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 10px 18px; }
.yes-no legend { width: 100%; font-size: 12px; line-height: 1.4; font-weight: 650; margin-bottom: 7px; }
.yes-no label { font-size: 12px; color: #dbe7ee; }
.equal-fields { grid-template-columns: .65fr 1.35fr; }
.primary-button, .secondary-button { border-radius: 9px; min-height: 46px; padding: 0 17px; font-weight: 760; border: 1px solid transparent; }
.primary-button { background: var(--teal); color: var(--white); width: 100%; }
.primary-button:hover { background: #119387; }
.secondary-button { background: var(--white); border-color: var(--line-dark); color: var(--ink); }
.form-status { min-height: 20px; font-size: 13px; line-height: 1.4; margin: 11px 0 0; }

.results-panel { min-width: 0; }
.best-result { display: grid; grid-template-columns: 1fr auto; gap: 16px 30px; align-items: end; background: var(--teal-pale); border: 1px solid #a6d8d1; border-radius: var(--radius); padding: clamp(24px, 4vw, 42px); margin-bottom: 18px; }
.best-label, .best-caption { color: var(--teal-dark); font-size: 12px; text-transform: uppercase; letter-spacing: .11em; font-weight: 800; }
.best-result h3 { margin: 8px 0 0; font-size: clamp(25px, 3vw, 40px); letter-spacing: -.035em; }
.best-amount-wrap { text-align: right; }
.best-amount { display: block; font-family: "Cascadia Mono", Consolas, monospace; font-size: clamp(29px, 4vw, 50px); letter-spacing: -.045em; margin-top: 7px; white-space: nowrap; }
.best-context { grid-column: 1 / -1; margin: 4px 0 0; padding-top: 14px; border-top: 1px solid #a6d8d1; color: var(--teal-dark); }
.chart-card { border: 1px solid var(--line); background: var(--white); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.card-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 15px; margin-bottom: 10px; }
.card-heading h3 { margin: 0; font-size: 18px; }
.card-heading span { color: var(--ink-soft); font-size: 12px; }
.chart-scroll { overflow-x: auto; }
#profit-chart { width: 100%; min-width: 690px; display: block; }
.chart-label { fill: var(--ink); font: 600 12px "Segoe UI", sans-serif; }
.chart-value { fill: var(--ink); font: 700 12px "Cascadia Mono", monospace; }
.chart-axis { stroke: var(--line-dark); stroke-width: 1; }

.comparison-section, .detail-section { margin-top: clamp(70px, 10vw, 130px); }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; color: var(--ink-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.comparison-table { min-width: 850px; border-top: 2px solid var(--ink); }
.comparison-table th, .comparison-table td { border-bottom: 1px solid var(--line); padding: 16px 12px; vertical-align: middle; }
.comparison-table th:first-child { width: 118px; }
.matrix-button { width: 100%; min-height: 74px; padding: 10px; border: 1px solid transparent; border-radius: 9px; background: transparent; text-align: left; }
.matrix-button:hover, .matrix-button[aria-pressed="true"] { border-color: var(--teal); background: var(--teal-pale); }
.matrix-button.eligibility-inapplicable { opacity: .58; text-decoration-color: var(--red); }
.matrix-button.eligibility-insufficient_data { border-style: dashed; }
.matrix-amount { display: block; font: 720 15px "Cascadia Mono", Consolas, monospace; white-space: nowrap; }
.matrix-note { display: block; color: var(--ink-soft); font-size: 11px; margin-top: 5px; }
.matrix-empty { color: var(--line-dark); text-align: center; }
.winner-tag { display: inline-block; margin-top: 6px; color: var(--teal-dark); font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }

.detail-heading { grid-template-columns: 1fr auto; gap: 24px; }
.scenario-picker { display: grid; gap: 7px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.scenario-picker select { min-width: min(360px, 76vw); min-height: 44px; padding: 0 38px 0 12px; border: 1px solid var(--line-dark); border-radius: 8px; background: var(--white); }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .7fr); gap: clamp(25px, 5vw, 68px); align-items: start; }
.pnl-table { border-top: 2px solid var(--ink); min-width: 570px; }
.pnl-table th, .pnl-table td { padding: 14px 12px; border-bottom: 1px solid var(--line); }
.pnl-table td:nth-child(n+2), .pnl-table th:nth-child(n+2) { text-align: right; font-family: "Cascadia Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.pnl-table tr.total td { font-weight: 800; border-top: 2px solid var(--ink); color: var(--teal-dark); }
.pnl-table tr.subtotal td { font-weight: 720; }
.explanation-panel { border-left: 2px solid var(--ink); padding-left: 24px; }
.explanation-panel h3 { margin: 0 0 12px; font-size: 20px; }
.explanation-panel p { color: var(--ink-soft); line-height: 1.6; }
.metric-list { margin: 24px 0; }
.metric-list div { display: flex; justify-content: space-between; gap: 15px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.metric-list dt { color: var(--ink-soft); }
.metric-list dd { margin: 0; font: 700 13px "Cascadia Mono", Consolas, monospace; }
.warning-list { display: grid; gap: 8px; margin: 20px 0; }
.warning-item { background: var(--amber-pale); border-left: 4px solid var(--amber); padding: 11px 13px; font-size: 13px; line-height: 1.45; }
.legal-sources { display: grid; gap: 7px; margin: 20px 0; font-size: 12px; }
.legal-sources strong { color: var(--ink); }
.legal-sources a { color: var(--teal-dark); text-underline-offset: 3px; }
.disclaimer { margin-top: 80px; border-top: 1px solid var(--line-dark); padding: 24px 0 0; color: var(--ink-soft); font-size: 14px; line-height: 1.55; }

.settings-dialog { width: min(760px, calc(100% - 24px)); max-height: calc(100vh - 24px); border: 0; border-radius: var(--radius); padding: 0; color: var(--ink); box-shadow: 0 30px 90px rgba(16,42,67,.28); }
.settings-dialog::backdrop { background: rgba(16,42,67,.62); backdrop-filter: blur(4px); }
.dialog-top { position: sticky; top: 0; z-index: 2; display: flex; justify-content: flex-end; padding: 12px; background: rgba(255,255,255,.94); }
.close-button { font-size: 25px; width: 42px; justify-content: center; padding: 0; }
.settings-content { padding: 4px clamp(22px, 5vw, 52px) 45px; }
.settings-content h2 { font-size: clamp(30px, 5vw, 47px); margin: 0; letter-spacing: -.04em; }
.settings-intro { color: var(--ink-soft); line-height: 1.55; margin: 14px 0 30px; }
.settings-group { margin: 30px 0; }
.settings-group h3 { border-bottom: 2px solid var(--ink); padding-bottom: 10px; margin: 0 0 16px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.settings-field { display: grid; gap: 7px; font-size: 13px; font-weight: 650; }
.settings-field input { width: 100%; min-height: 43px; border: 1px solid var(--line-dark); border-radius: 8px; padding: 8px 11px; font-family: "Cascadia Mono", Consolas, monospace; }
.settings-field small { color: var(--ink-soft); font-weight: 400; }
.settings-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.settings-actions .primary-button { grid-column: 1 / -1; }
.file-button { display: grid; place-items: center; }
.file-button input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; }

@media (max-width: 940px) {
  .workspace { grid-template-columns: 1fr; }
  .input-panel { position: static; max-height: none; overflow: visible; }
  .detail-grid { grid-template-columns: 1fr; }
  .explanation-panel { border-left: 0; border-top: 2px solid var(--ink); padding: 24px 0 0; }
}

@media (max-width: 640px) {
  .topbar { height: 62px; padding-inline: 12px; gap: 10px; }
  .brand { gap: 8px; font-size: 14px; }
  .brand-mark { width: 32px; height: 32px; }
  .demo-back-link { min-height: 36px; padding-inline: 9px; font-size: 12px; }
  .desktop-only { display: none; }
  .intro { padding-top: 48px; }
  h1 { font-size: clamp(39px, 12vw, 58px); }
  .section-heading { grid-template-columns: 1fr; gap: 3px; }
  .best-result { grid-template-columns: 1fr; }
  .best-amount-wrap { text-align: left; }
  .detail-heading { grid-template-columns: 1fr; }
  .scenario-picker select { width: 100%; min-width: 0; }
  .settings-grid, .settings-actions { grid-template-columns: 1fr; }
  .settings-actions .primary-button { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
