:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-muted: #eef3ee;
  --ink: #18211f;
  --muted: #52615c;
  --border: #cfd9d3;
  --primary: #176b5c;
  --primary-dark: #0e4e43;
  --accent: #bf6f2f;
  --danger: #a3332c;
  --success: #1f7a46;
  --warning: #9a6517;
  --focus: #163d7a;
  --shadow: 0 18px 45px rgba(31, 44, 40, 0.11);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -5rem;
  z-index: 5;
  background: var(--ink);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 6px;
}

.skip-link:focus {
  top: 1rem;
}

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

.site-header {
  padding: 48px 0 30px;
  background:
    linear-gradient(115deg, rgba(23, 107, 92, 0.14), rgba(191, 111, 47, 0.08)),
    var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 390px);
  gap: 28px;
  align-items: end;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
legend,
p {
  margin-top: 0;
}

h1 {
  max-width: 790px;
  margin-bottom: 0.75rem;
  font-size: clamp(2rem, 5vw, 4.6rem);
  line-height: 1.02;
}

.subtitle {
  margin-bottom: 1rem;
  color: var(--primary-dark);
  font-size: clamp(1.1rem, 2.4vw, 1.6rem);
  font-weight: 850;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2vw, 1.65rem);
  line-height: 1.2;
}

.intro {
  max-width: 740px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.1rem;
}

.disclaimer {
  background: #fff8e8;
  border: 1px solid #e2c781;
  border-left: 5px solid var(--warning);
  border-radius: 8px;
  padding: 1rem;
  color: #403113;
}

.app-shell {
  padding: 28px 0 48px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.scenario-panel,
.comparison-panel,
.explanation-panel {
  padding: 22px;
}

.planner-grid {
  display: grid;
  grid-template-columns: minmax(320px, 450px) minmax(0, 1fr);
  gap: 22px;
  margin: 22px 0;
  align-items: start;
}

.input-panel,
.status-panel,
.chart-panel {
  padding: 22px;
}

.results-stack {
  display: grid;
  gap: 22px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.section-heading.compact {
  margin-bottom: 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.button {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 42px;
  padding: 0.65rem 0.9rem;
  font-weight: 750;
}

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

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

.button.secondary {
  background: var(--surface-muted);
  color: var(--ink);
  border-color: var(--border);
}

.button.secondary:hover {
  background: #e2ebe5;
}

.scenario-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.scenario-card {
  min-height: 112px;
  padding: 1rem;
  text-align: left;
  background: #fbfcfa;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
}

.scenario-card:hover,
.scenario-card.active {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 2px rgba(23, 107, 92, 0.2);
}

.scenario-card span {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 1.05rem;
  font-weight: 800;
}

.scenario-card small {
  display: block;
  color: var(--muted);
  line-height: 1.35;
}

.helper-text,
.calculation-note {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

fieldset {
  margin: 18px 0 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 10px;
  font-weight: 850;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--ink);
  font-weight: 700;
}

label span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #b8c6bf;
  border-radius: 6px;
  padding: 0.62rem 0.7rem;
  background: #fff;
  color: var(--ink);
}

input:invalid {
  border-color: var(--danger);
}

.tip {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 900;
}

.tip span {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 3;
  display: none;
  width: min(260px, 80vw);
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.35;
}

.tip:hover span,
.tip:focus span {
  display: block;
}

.validation {
  margin-top: 16px;
  color: var(--danger);
  font-weight: 700;
}

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

.metric {
  min-height: 118px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

.metric span {
  display: block;
  color: var(--muted);
  font-weight: 750;
}

.metric strong {
  display: block;
  margin-top: 0.5rem;
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.15;
}

.track-badge {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  background: var(--surface-muted);
  color: var(--ink);
  font-weight: 850;
  white-space: nowrap;
}

.track-badge.good {
  background: #dff3e7;
  color: var(--success);
}

.track-badge.warn {
  background: #fff1d2;
  color: var(--warning);
}

.track-badge.bad {
  background: #fbe0df;
  color: var(--danger);
}

.track-message {
  margin: 16px 0 8px;
  font-weight: 750;
}

canvas {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  background: #fbfcfa;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.legend-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: -1px;
}

.legend-dot.savings {
  background: var(--primary);
}

.legend-dot.target {
  background: var(--accent);
}

.legend-dot.expense {
  background: var(--danger);
}

.comparison-panel {
  margin-bottom: 22px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 0.85rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-muted);
  font-size: 0.9rem;
}

.status-good {
  color: var(--success);
  font-weight: 850;
}

.status-warn {
  color: var(--warning);
  font-weight: 850;
}

.status-bad {
  color: var(--danger);
  font-weight: 850;
}

.explanation-list {
  margin: 0;
  padding-left: 1.2rem;
}

.explanation-list li + li {
  margin-top: 0.45rem;
}

.site-footer {
  padding: 24px 0 36px;
  color: var(--muted);
}

.site-footer p {
  margin-bottom: 0;
}

@media (max-width: 900px) {
  .header-grid,
  .planner-grid {
    grid-template-columns: 1fr;
  }

  .section-heading {
    display: grid;
  }

  .actions {
    justify-content: flex-start;
  }

  .scenario-picker {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .container {
    width: min(100% - 22px, 1180px);
  }

  .site-header {
    padding-top: 34px;
  }

  .field-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .scenario-panel,
  .comparison-panel,
  .explanation-panel,
  .input-panel,
  .status-panel,
  .chart-panel {
    padding: 16px;
  }

  .button {
    width: 100%;
  }
}

@media print {
  body {
    background: #fff;
  }

  .site-header,
  .site-footer,
  .input-panel,
  .actions,
  .skip-link {
    display: none;
  }

  .container {
    width: 100%;
  }

  .app-shell {
    padding: 0;
  }

  .planner-grid {
    display: block;
  }

  .panel {
    box-shadow: none;
    break-inside: avoid;
    margin-bottom: 16px;
  }
}
