:root {
  --bg: #fafaf7;
  --ink: #1d1d1b;
  --muted: #6a6a66;
  --rule: #e2e2dc;
  --accent: #2a6f4d;
  --danger: #b44a3a;
  --card: #ffffff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0 0 2rem;
  color: var(--muted);
}

form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
  margin-bottom: 1.75rem;
}

fieldset {
  border: 1px solid var(--rule);
  background: var(--card);
  border-radius: 6px;
  padding: 0.9rem 1rem 1rem;
  margin: 0;
  min-width: 0;
}

fieldset.start { grid-column: 1 / -1; }

legend {
  padding: 0 0.4rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent);
}

label {
  display: grid;
  gap: 0.25rem;
  margin: 0.8rem 0;
  font-size: 0.9rem;
}

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.field-head span { color: var(--ink); }
.field-head em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.78rem;
}

.slider-pair {
  display: grid;
  grid-template-columns: 1fr 10ch;
  gap: 0.75rem;
  align-items: center;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.slider-pair input[type="text"] {
  width: 100%;
  padding: 0.3rem 0.45rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #fff;
  font: inherit;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.slider-pair input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
}

.remember-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
  margin: 0;
}

.remember-toggle input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}

.form-actions button {
  appearance: none;
  background: #fff;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 4px;
  padding: 0.4rem 1rem;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.form-actions button:hover {
  background: var(--accent);
  color: #fff;
}

.form-actions button:active {
  transform: translateY(1px);
}

#message {
  padding: 0.75rem 1rem;
  background: #fff6e5;
  border: 1px solid #e0c585;
  border-radius: 4px;
  margin-bottom: 1.5rem;
  color: #6d5100;
}

#summary {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

#summary h2 { margin: 0 0 0.6rem; font-size: 1rem; }

#summary dl {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem 1.5rem;
  margin: 0;
}

#summary dl > div { display: flex; flex-direction: column; }
#summary dt { font-size: 0.8rem; color: var(--muted); }
#summary dd { margin: 0.15rem 0 0; font-variant-numeric: tabular-nums; font-size: 1.05rem; font-weight: 600; }

#chart-wrap h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}
.muted { color: var(--muted); font-weight: 400; }

#chart {
  width: 100%;
  height: 460px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  display: block;
}

#chart .gridline { stroke: #eee; shape-rendering: crispEdges; }
#chart .axis path, #chart .axis line { stroke: #bbb; }
#chart .axis text { fill: var(--muted); font-size: 11px; }
#chart .zero-line { stroke: #999; stroke-dasharray: 2 3; }
#chart .transition-line { stroke: #666; stroke-dasharray: 4 3; }
#chart .transition-label { fill: var(--muted); font-size: 11px; }
#chart .run { fill: none; stroke-width: 1; stroke-opacity: 0.18; }
#chart .run.failed { stroke: var(--danger); stroke-opacity: 0.35; }
#chart .run.highlight { stroke-width: 2.4; stroke-opacity: 1; }

#cashflow-wrap { margin-top: 1.5rem; }
#cashflow-wrap h2 { margin: 0 0 0.5rem; font-size: 1rem; }

#cashflow-chart {
  width: 100%;
  height: 220px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  display: block;
}

#cashflow-chart .bar.contribution { fill: var(--accent); fill-opacity: 0.7; }
#cashflow-chart .bar.withdrawal { fill: var(--danger); fill-opacity: 0.7; }
#cashflow-chart .axis path, #cashflow-chart .axis line { stroke: #bbb; }
#cashflow-chart .axis text { fill: var(--muted); font-size: 11px; }
#cashflow-chart .zero-line { stroke: #555; shape-rendering: crispEdges; }
#cashflow-chart .transition-line { stroke: #666; stroke-dasharray: 4 3; }
#cashflow-chart .transition-label { fill: var(--muted); font-size: 11px; }
#cashflow-chart .gridline { stroke: #eee; shape-rendering: crispEdges; }

#legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  list-style: none;
  padding: 0.75rem 0 0;
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

#legend li { display: flex; align-items: center; gap: 0.4rem; }
#legend .swatch {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 2px;
}

footer {
  margin-top: 2rem;
  color: var(--muted);
  font-size: 0.85rem;
}

footer code { background: #eee; padding: 0 0.3em; border-radius: 3px; }

@media (max-width: 720px) {
  form { grid-template-columns: 1fr; }
  #summary dl { grid-template-columns: 1fr 1fr; }
  .slider-pair { grid-template-columns: 1fr 9ch; }
}
