:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-muted: #eef3ed;
  --input-bg: #ffffff;
  --chart-bg: #fbfcfa;
  --text: #15211b;
  --muted: #5c6b62;
  --line: #d8e0d9;
  --primary: #126a55;
  --primary-strong: #0b4d3d;
  --on-primary: #ffffff;
  --accent: #b65d2f;
  --danger: #b42318;
  --chart-base: #126a55;
  --chart-extra: #b65d2f;
  --chart-grid: #d8e0d9;
  --shadow: 0 18px 45px rgba(21, 33, 27, 0.1);
  --header-bg: rgba(247, 248, 245, 0.92);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101412;
  --surface: #171d1a;
  --surface-muted: #202923;
  --input-bg: #101512;
  --chart-bg: #111714;
  --text: #eef5ef;
  --muted: #a6b6ac;
  --line: #314036;
  --primary: #4fc19c;
  --primary-strong: #79d8b6;
  --on-primary: #08120e;
  --accent: #f0a36f;
  --danger: #ff8d86;
  --chart-base: #67d7ad;
  --chart-extra: #f0a36f;
  --chart-grid: #304038;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.25);
  --header-bg: rgba(16, 20, 18, 0.92);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

.container {
  width: min(1120px, calc(100% - 32px));
  margin-inline: auto;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid var(--line);
  background: var(--header-bg);
  backdrop-filter: blur(12px);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--on-primary);
}

.privacy-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 0.9rem;
  background: var(--surface);
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  justify-content: center;
}

.main-nav a {
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.93rem;
  font-weight: 800;
  padding: 9px 10px;
  text-decoration: none;
}

.main-nav a:hover,
.main-nav a.is-active {
  background: var(--surface-muted);
  color: var(--text);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 8px;
  cursor: pointer;
  font-weight: 800;
}

.theme-icon {
  display: block;
  width: 18px;
  line-height: 1;
  font-size: 1.1rem;
  text-align: center;
}

.app-shell {
  padding: 32px 0 56px;
}

.app-section[hidden] {
  display: none;
}

.home-section {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  gap: 24px;
  align-items: start;
}

.home-hero,
.faq-panel,
.section-top,
.article-grid article,
.analysis-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.home-hero {
  display: grid;
  grid-column: 1 / -1;
  justify-items: start;
  gap: 18px;
  padding: clamp(26px, 5vw, 54px);
}

.home-hero p:not(.eyebrow) {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  font-size: 1.08rem;
}

.faq-panel {
  grid-column: 1 / -1;
  padding: clamp(20px, 3vw, 28px);
}

.faq-panel details {
  border-top: 1px solid var(--line);
  padding: 16px 0;
}

.faq-panel details:first-of-type {
  border-top: 0;
}

.faq-panel summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 900;
}

.faq-panel p {
  max-width: 880px;
  margin: 10px 0 0;
  color: var(--muted);
}

.section-top {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
  padding: clamp(22px, 4vw, 34px);
}

.section-top h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

.section-note {
  margin: 8px 0 0;
  color: var(--muted);
}

.article-grid,
.analysis-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.article-grid article,
.analysis-card {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 22px;
}

.article-grid p,
.analysis-card p {
  margin: 0;
  color: var(--muted);
}

.article-grid h2,
.analysis-card h2 {
  font-size: 1.35rem;
}

.intro-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 24px;
  align-items: stretch;
  margin-bottom: 24px;
}

.intro-copy,
.summary-strip,
.debt-form,
.debts-panel,
.projection-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.intro-copy {
  padding: clamp(24px, 4vw, 42px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  max-width: 760px;
  font-size: clamp(2.15rem, 6vw, 4.5rem);
}

h2 {
  font-size: clamp(1.35rem, 3vw, 2rem);
}

h3 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

.intro-copy p:last-child {
  max-width: 680px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.summary-strip {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.summary-strip > div {
  display: grid;
  gap: 2px;
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 16px;
}

.summary-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.summary-strip strong {
  font-size: 1.35rem;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
  gap: 24px;
  align-items: start;
}

.debt-form,
.debts-panel {
  padding: clamp(20px, 3vw, 28px);
}

.section-heading {
  margin-bottom: 22px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-weight: 700;
}

.field:first-child {
  grid-column: 1 / -1;
}

.field input,
.field select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(18, 106, 85, 0.13);
}

.input-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input-bg);
}

.input-with-unit:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(18, 106, 85, 0.13);
}

.input-with-unit input {
  border: 0;
  box-shadow: none;
}

.input-with-unit input:focus {
  box-shadow: none;
}

.input-with-unit span {
  padding-right: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.field-error {
  min-height: 18px;
  color: var(--danger);
  font-weight: 700;
}

.mortgage-discounts {
  display: grid;
  gap: 14px;
  margin: 18px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.mortgage-discounts[hidden] {
  display: none;
}

.mortgage-discounts legend {
  padding: 0 6px;
  font-weight: 900;
}

.mortgage-discounts p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.mortgage-discount-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(140px, 0.45fr);
  gap: 12px;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.button.primary {
  background: var(--primary);
  color: var(--on-primary);
}

.button.primary:hover {
  background: var(--primary-strong);
}

.button.ghost {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.button.danger {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  background: var(--surface);
  color: var(--danger);
}

.button.danger:hover {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}

.empty-state {
  display: grid;
  gap: 6px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: var(--surface-muted);
}

.empty-state strong {
  color: var(--text);
}

.debt-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.debt-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--surface);
}

.debt-card.best-offer {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

.simulator-debt-card.best-offer {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

.adjustment-item.best-offer {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

.debt-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.debt-card h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.debt-type {
  color: var(--muted);
  font-size: 0.9rem;
}

.debt-card-actions {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 8px;
}

.edit-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 900;
  padding: 7px 10px;
}

.edit-button:hover {
  background: var(--surface-muted);
}

.remove-button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--danger);
  cursor: pointer;
  font-weight: 900;
  width: 36px;
  height: 36px;
}

.debt-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.debt-metrics span {
  display: grid;
  gap: 2px;
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.debt-metrics strong {
  color: var(--text);
  font-size: 0.98rem;
}

.projection-panel {
  display: grid;
  gap: 20px;
  margin-top: 24px;
  padding: clamp(20px, 3vw, 28px);
}

.compare-panel {
  margin-top: 24px;
}

.projection-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.34fr);
  gap: 18px;
  align-items: end;
}

.debt-selector {
  align-self: end;
}

.chart-wrap {
  position: relative;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--chart-bg);
  padding: 14px;
}

.chart-wrap canvas {
  display: block;
  width: 100%;
  height: min(46vh, 380px);
  cursor: crosshair;
  touch-action: none;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  max-width: min(260px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  pointer-events: none;
}

.chart-tooltip strong,
.chart-tooltip span {
  display: block;
}

.chart-tooltip span {
  color: var(--muted);
  font-size: 0.86rem;
}

.projection-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.projection-metrics span {
  display: grid;
  gap: 2px;
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.projection-metrics strong {
  color: var(--text);
  font-size: 0.98rem;
  overflow-wrap: anywhere;
}

.adjustment-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.adjustment-grid.single {
  grid-template-columns: minmax(0, 1fr);
}

.adjustment-form,
.adjustment-list-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
}

.adjustment-list-panel {
  grid-column: 1 / -1;
}

.field[hidden] {
  display: none;
}

.compact-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.adjustment-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.simulator-intro {
  display: grid;
  gap: 8px;
  border-left: 4px solid var(--primary);
  margin-bottom: 18px;
  padding: 2px 0 2px 14px;
}

.simulator-intro p {
  margin: 0;
}

.simulator-intro p:last-child {
  max-width: 980px;
  color: var(--text);
  font-size: 1.02rem;
}

.simulator-debt-card {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}

.simulator-adjustments-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 16px;
}

.simulator-adjustment-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.simulator-adjustment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 8px;
}

.simulator-adjustment-chip .remove-button {
  width: 30px;
  height: 30px;
}

.simulator-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.simulator-card-header strong,
.simulator-card-header span {
  display: block;
}

.simulator-card-header span:not(.strategy-badge) {
  color: var(--muted);
  font-size: 0.9rem;
}

.strategy-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 900;
  padding: 7px 10px;
}

.simulator-card-metrics {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.strategy-comparison-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.strategy-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 14px;
}

.strategy-panel h3 {
  margin: 0;
  font-size: 1rem;
}

.mini-chart-wrap {
  position: relative;
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--chart-bg);
  padding: 10px;
}

.mini-chart-wrap canvas {
  display: block;
  width: 100%;
  height: 260px;
  cursor: crosshair;
  touch-action: none;
}

.mini-chart-tooltip {
  max-width: min(300px, calc(100% - 28px));
}

.adjustment-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.adjustment-item strong {
  display: block;
}

.adjustment-item span {
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 860px) {
  .home-section,
  .intro-panel,
  .workspace-grid,
  .projection-header,
  .adjustment-grid {
    grid-template-columns: 1fr;
  }

  .header-content {
    flex-wrap: wrap;
  }

  .main-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 10px;
  }

  .summary-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .article-grid,
  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .projection-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .simulator-card-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .strategy-comparison-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 0.96rem;
  }

  .container {
    width: min(100% - 24px, 1120px);
  }

  .header-content {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding: 12px 0;
  }

  .main-nav {
    order: initial;
    width: 100%;
  }

  .main-nav a {
    flex: 0 0 auto;
  }

  .header-actions {
    display: grid;
    width: 100%;
    justify-content: stretch;
  }

  .privacy-pill {
    width: 100%;
    justify-content: center;
  }

  .theme-toggle {
    justify-self: end;
  }

  .privacy-pill {
    border-radius: 8px;
  }

  .app-shell {
    padding: 18px 0 36px;
  }

  .intro-panel,
  .workspace-grid {
    gap: 16px;
    margin-bottom: 16px;
  }

  .home-section {
    gap: 16px;
  }

  .intro-copy,
  .home-hero,
  .faq-panel,
  .section-top,
  .debt-form,
  .debts-panel,
  .projection-panel {
    padding: 18px;
  }

  .section-top {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 2.1rem;
  }

  h2 {
    font-size: 1.45rem;
  }

  .summary-strip {
    padding: 12px;
  }

  .form-actions,
  .button {
    width: 100%;
  }

  .summary-strip,
  .form-grid,
  .mortgage-discount-grid,
  .debt-metrics,
  .projection-metrics,
  .compact-grid {
    grid-template-columns: 1fr;
  }

  .chart-wrap {
    min-height: 230px;
    padding: 8px;
  }

  .chart-wrap canvas {
    height: 260px;
  }

  .adjustment-item {
    grid-template-columns: 1fr;
  }

  .simulator-card-header {
    display: grid;
  }

  .strategy-badge {
    justify-self: start;
  }

  .simulator-card-metrics {
    grid-template-columns: 1fr;
  }

  .adjustment-item .remove-button {
    width: 100%;
  }
}
