:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --panel: #ffffff;
  --panel-strong: #20312b;
  --ink: #18211f;
  --muted: #60706b;
  --line: #d9ddd6;
  --accent: #1f7a5a;
  --accent-dark: #15543e;
  --accent-soft: #e6f3ed;
  --lower: #a94b43;
  --expected: #1f7a5a;
  --higher: #b77a18;
  --bar-initial: #2aa8df;
  --bar-deposits: #a8d8e8;
  --bar-interest: #ef8b13;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

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

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

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

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

h1 {
  margin-bottom: 10px;
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.2rem;
}

.header-copy,
.panel-heading p,
.chart-heading p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.language-control {
  display: grid;
  gap: 6px;
  min-width: 128px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.language-control select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

.calculator-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(320px, 0.88fr);
  gap: 18px;
  align-items: stretch;
}

.tool-panel,
.results-panel,
.chart-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 55px rgba(32, 49, 43, 0.08);
}

.tool-panel,
.results-panel,
.chart-section {
  padding: 22px;
}

.panel-heading {
  margin-bottom: 24px;
}

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

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

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

.input-with-unit:focus-within {
  border-color: var(--accent);
  outline: 3px solid rgba(31, 122, 90, 0.2);
}

.input-with-unit input {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  border: 0;
  outline: 0;
  padding: 10px 12px;
  color: var(--ink);
  background: transparent;
  font-size: 1.03rem;
  font-weight: 750;
}

.input-with-unit span {
  padding: 0 12px 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

input[type="range"] {
  width: 100%;
  min-height: 22px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.slider-scale {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.76rem;
}

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

.actions button {
  min-height: 44px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 18px;
  color: #fff;
  background: var(--accent);
  font-weight: 800;
  cursor: pointer;
}

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

.actions .secondary {
  color: var(--accent-dark);
  background: transparent;
}

.actions .secondary:hover {
  background: var(--accent-soft);
}

.results-panel {
  position: relative;
  display: grid;
  align-content: start;
  color: #f6fbf8;
  background: var(--panel-strong);
}

.results-topbar {
  display: contents;
}

.print-image-button {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  min-height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--panel-strong);
  background: #f6fbf8;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.14);
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.print-image-button:hover {
  background: var(--accent-soft);
}

.print-image-button:disabled {
  opacity: 0.68;
  cursor: progress;
}

.print-image-status {
  position: absolute;
  top: 50px;
  right: 12px;
  z-index: 8;
  width: max-content;
  max-width: min(340px, calc(100vw - 48px));
  border: 1px solid rgba(31, 122, 90, 0.24);
  border-radius: 7px;
  padding: 10px 12px;
  color: var(--accent-dark);
  background: #f6fbf8;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.2);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.print-image-status.visible {
  opacity: 1;
  transform: translateY(0);
}

.print-image-status.error {
  color: var(--lower);
}

.result-primary {
  padding-right: 70px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
}

.result-primary p,
.result-breakdown p {
  margin-bottom: 7px;
  color: rgba(246, 251, 248, 0.72);
  font-size: 0.82rem;
  font-weight: 750;
  text-transform: uppercase;
}

.result-primary strong {
  display: block;
  margin-bottom: 8px;
  font-size: clamp(2.25rem, 5vw, 4.25rem);
  line-height: 1;
  letter-spacing: -0.04em;
}

.result-primary span,
.breakdown-note {
  color: rgba(246, 251, 248, 0.72);
  font-size: 0.86rem;
  line-height: 1.45;
}

.result-breakdown {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  padding: 24px 0 20px;
}

.result-breakdown strong {
  font-size: clamp(1.25rem, 2.5vw, 1.8rem);
}

.contribution-bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.contribution-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #8bd0b3;
  transition: width 220ms ease;
}

.breakdown-note {
  margin: 9px 0 0;
}

.chart-section {
  margin-top: 18px;
}

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

.chart-tools {
  display: grid;
  justify-items: end;
  gap: 12px;
  min-width: min(100%, 440px);
}

.chart-type-toggle {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f3f5f2;
}

.chart-type-button {
  min-height: 34px;
  border: 0;
  border-radius: 5px;
  padding: 0 13px;
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
}

.chart-type-button:hover {
  color: var(--ink);
}

.chart-type-button.active {
  color: #fff;
  background: var(--accent);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 16px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
  white-space: nowrap;
}

.legend-swatch {
  width: 22px;
  height: 3px;
  border-radius: 2px;
}

.legend-item.lower .legend-swatch {
  background: var(--lower);
}

.legend-item.expected .legend-swatch {
  height: 4px;
  background: var(--expected);
}

.legend-item.higher .legend-swatch {
  background: var(--higher);
}

.legend-item.bar-initial .legend-swatch {
  height: 10px;
  background: var(--bar-initial);
}

.legend-item.bar-deposits .legend-swatch {
  height: 10px;
  background: var(--bar-deposits);
}

.legend-item.bar-interest .legend-swatch {
  height: 10px;
  background: var(--bar-interest);
}

.legend-item.balance .legend-swatch {
  background: var(--expected);
}

.chart-wrap {
  position: relative;
  min-height: 430px;
}

#growthChart {
  display: block;
  width: 100%;
  height: 430px;
  overflow: visible;
}

.chart-frame {
  fill: #fbfcfa;
  stroke: var(--line);
}

.chart-grid {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-axis-label,
.chart-tick,
.chart-end-label {
  fill: var(--muted);
  font-family: inherit;
}

.chart-tick {
  font-size: 12px;
}

.chart-axis-label {
  font-size: 12px;
  font-weight: 750;
}

.chart-end-label {
  font-size: 11px;
  font-weight: 800;
}

.series-line {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.series-line.lower {
  stroke: var(--lower);
  stroke-width: 2.2;
  stroke-dasharray: 7 6;
}

.series-line.expected {
  stroke: var(--expected);
  stroke-width: 4;
}

.series-line.higher {
  stroke: var(--higher);
  stroke-width: 2.2;
  stroke-dasharray: 3 5;
}

.series-end {
  stroke: #fff;
  stroke-width: 2;
}

.series-end.lower,
.hover-dot.lower {
  fill: var(--lower);
}

.series-end.expected,
.hover-dot.expected {
  fill: var(--expected);
}

.series-end.higher,
.hover-dot.higher {
  fill: var(--higher);
}

.bar-segment {
  stroke: #fff;
  stroke-width: 0.7;
}

.bar-segment.initial {
  fill: var(--bar-initial);
}

.bar-segment.deposits {
  fill: var(--bar-deposits);
}

.bar-segment.interest {
  fill: var(--bar-interest);
}

.initial-balance-reference {
  stroke: var(--bar-initial);
  stroke-width: 2;
  stroke-dasharray: 5 4;
}

.initial-balance-label {
  fill: var(--bar-initial);
  font-family: inherit;
  font-size: 11px;
  font-weight: 800;
}

.balance-line {
  fill: none;
  stroke: var(--expected);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.balance-dot {
  fill: #fff;
  stroke: var(--expected);
  stroke-width: 2.5;
}

.bar-highlight {
  fill: rgba(24, 33, 31, 0.07);
}

.hover-guide {
  stroke: var(--ink);
  stroke-width: 1;
  stroke-dasharray: 3 4;
  opacity: 0.45;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  min-width: 200px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  padding: 10px 12px;
  color: #f6fbf8;
  background: rgba(32, 49, 43, 0.96);
  box-shadow: 0 10px 28px rgba(24, 33, 31, 0.2);
  pointer-events: none;
  font-size: 0.8rem;
}

.tooltip-title {
  margin-bottom: 7px;
  font-weight: 800;
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 0;
}

.tooltip-row.expected {
  font-weight: 800;
}

@media (max-width: 800px) {
  .calculator-layout {
    grid-template-columns: 1fr;
  }

  .chart-heading {
    display: grid;
  }

  .chart-tools {
    justify-items: start;
    min-width: 0;
  }

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

@media (max-width: 600px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 20px;
  }

  .app-header {
    display: grid;
  }

  .language-control {
    grid-template-columns: auto 88px;
    align-items: center;
  }

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

  .tool-panel,
  .results-panel,
  .chart-section {
    padding: 17px;
  }

  .chart-wrap,
  #growthChart {
    min-height: 350px;
    height: 350px;
  }

  .actions button {
    flex: 1;
  }

  .print-image-button {
    top: 10px;
    right: 10px;
  }

  .print-image-status {
    top: 46px;
    right: 10px;
    width: 100%;
    max-width: calc(100% - 20px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .contribution-bar span {
    transition: none;
  }
}
