/* Tokens: light by default, dark when the system says so. */
:root {
  --bg: #f6f6f6;
  --surface: #ffffff;
  --surface-sunken: #f6f8fa;
  --border: #e2e7ee;
  --border-strong: #cbd3de;
  --text: #1a212c;
  --text-muted: #57637a;
  --text-subtle: #78849a;
  --text-faint: #a3aec0;
  --accent: #4f46e5;
  --accent-ring: rgb(99 102 241 / 0.30);
  --income: #059669;
  --dividend: #d97706;
  --danger: #be123c;
  --danger-soft: #fff1f2;
  --danger-border: #fecdd3;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 21 29 / 0.05), 0 1px 3px rgb(16 21 29 / 0.06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151d;
    --surface: #171e28;
    --surface-sunken: #131922;
    --border: #262f3c;
    --border-strong: #35404f;
    --text: #e8edf4;
    --text-muted: #a3aec0;
    --text-subtle: #8592a6;
    --text-faint: #6b7889;
    --accent: #818cf8;
    --accent-ring: rgb(129 140 248 / 0.38);
    --income: #34d399;
    --dividend: #fbbf24;
    --danger: #fda4af;
    --danger-soft: #3b2b37;
    --danger-border: rgb(244 63 94 / 0.28);
    --shadow: 0 1px 2px rgb(0 0 0 / 0.30), 0 1px 3px rgb(0 0 0 / 0.40);
  }
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

/* ---- Masthead ---- */

.masthead,
main {
  width: min(1100px, 100% - 2rem);
  margin-inline: auto;
}

.masthead {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  padding: 2rem 0 1.25rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  text-decoration: none;
  align-self: center;
}

.brand__mark { stroke: var(--accent); }
.brand__dot { fill: var(--income); stroke: none; }

.brand__name {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.masthead__tagline {
  margin: 0;
  color: var(--text-muted);
}

main {
  display: grid;
  gap: 1.25rem;
  padding-bottom: 3rem;
}

.card {
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* ---- Inputs ---- */

.inputs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-width: 0;
}

.field label {
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background-color: var(--surface);
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.field select {
  appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2378849a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.625rem center;
  background-size: 1rem;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.field--actions {
  justify-content: flex-end;
  align-items: flex-end;
}

.link-button {
  padding: 0.5rem 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.link-button:hover { text-decoration: underline; }

/* ---- Errors ---- */

.errors {
  padding: 0.875rem 1.125rem;
  border: 1px solid var(--danger-border);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
}

.errors ul { margin: 0; padding-left: 1.125rem; }

/* ---- Result ---- */

.result {
  display: grid;
  gap: 1.5rem;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); /* four tiles, five with dividends */
  gap: 1.25rem;
}

.stat {
  display: grid;
  gap: 2px;
  padding-left: 0.75rem;
  border-left: 3px solid var(--accent);
}

.stat--contributions { border-left-color: var(--text-faint); }
.stat--growth        { border-left-color: var(--income); }
.stat--dividends     { border-left-color: var(--dividend); }

.stat__label {
  color: var(--text-subtle);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat__value {
  font-size: 1.5rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.stat__note {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.chart { min-height: 360px; }

.scroll { overflow-x: auto; }

.years {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.years th {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-subtle);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-align: right;
  text-transform: uppercase;
  white-space: nowrap;
}

.years td {
  padding: 0.625rem 0.75rem;
  text-align: right;
  white-space: nowrap;
}

/* The two leading columns say when: the count of years, then the calendar
   year. Left-aligned as labels; the count narrow and quiet beside the year. */
.years th:nth-child(-n+2),
.years td:nth-child(-n+2) { text-align: left; }

.years td:first-child {
  width: 1%;
  color: var(--text-subtle);
}

.years tbody tr:nth-child(odd) { background: var(--surface-sunken); }

.footnote,
.noscript {
  margin: 0;
  color: var(--text-subtle);
  font-size: 0.8125rem;
}

.noscript { width: min(1100px, 100% - 2rem); margin: 1rem auto; }

@media (max-width: 900px) {
  .inputs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .inputs { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 1.125rem; }
  .field--actions { align-items: flex-start; }
}
