* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.viz-root {
  color-scheme: light;
  --page:           #f9f9f7;
  --surface-1:      #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --muted:          #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --good:           #006300;
  --bad:            #d03b3b;

  --series-1:       #eb6834; /* primary accent + net worth line */
  --series-1-wash:  rgba(235,104,52,0.10);
  --series-2:       #2a78d6; /* baseline line */

  background: var(--page);
  color: var(--text-primary);
  min-height: 100vh;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface-1:      #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --muted:          #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255,255,255,0.10);
    --good:           #0ca30c;
    --bad:            #e66767;

    --series-1:       #d95926;
    --series-1-wash:  rgba(217,89,38,0.14);
    --series-2:       #3987e5;
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface-1:      #1a1a19;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --muted:          #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255,255,255,0.10);
  --good:           #0ca30c;
  --bad:            #e66767;

  --series-1:       #d95926;
  --series-1-wash:  rgba(217,89,38,0.14);
  --series-2:       #3987e5;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  max-width: 1120px;
  margin: 0 auto;
  border-bottom: 1px solid var(--border);
}

.hero-intro {
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px 24px 36px;
  animation: fadeInUp 0.5s ease both;
}
.hero-intro h1 {
  font-size: clamp(28px, 4.6vw, 42px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin: 0 0 14px;
  max-width: 16ch;
}
.hero-intro h1 em {
  font-style: normal;
  color: var(--series-1);
}
.hero-lede {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 54ch;
  margin: 0;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.brand-mark { color: var(--series-1); font-size: 14px; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text-primary); }

.sticky-summary {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
  transform: translateY(-100%);
  opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.sticky-summary.visible { transform: translateY(0); opacity: 1; }
.sticky-label { font-size: 13px; color: var(--text-secondary); }
.sticky-value { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }

.layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 4px 24px 64px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 900px) {
  .layout { grid-template-columns: 340px 1fr; align-items: start; }
  .sidebar { position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow-y: auto; }
  .sidebar .events-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  /* 16px stops iOS Safari from auto-zooming the viewport on input focus */
  .input-wrap input, .mini-field input { font-size: 16px; }
  .input-wrap input { padding: 12px 6px; }
  .mini-field input { padding: 10px 8px; }
  .switch { width: 40px; height: 24px; }
  .switch-track::before { width: 20px; height: 20px; }
  .switch input:checked + .switch-track::before { transform: translateX(16px); }
  .event-header { padding: 2px 0; }
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}

.sidebar { display: flex; flex-direction: column; gap: 20px; }

.sidebar > .card, .results > .card { animation: fadeInUp 0.5s ease both; }
.sidebar > .card:nth-child(2) { animation-delay: 0.06s; }
.sidebar > .card:nth-child(3) { animation-delay: 0.12s; }
.results > .card:nth-child(2) { animation-delay: 0.06s; }

.form-card h2, .goal-card h2 { margin: 0 0 4px; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.goal-intro { margin: 0 0 16px; font-size: 13px; color: var(--text-secondary); }

.form-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.form-card-head h2 { margin: 0; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn svg { width: 15px; height: 15px; }
.icon-btn:hover { color: var(--series-1); border-color: var(--series-1); }

.btn-continue {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
  padding: 13px 16px;
  border: none;
  border-radius: 8px;
  background: var(--series-1);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-continue svg { width: 18px; height: 18px; }

.form-summary {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--text-primary);
  font-family: inherit;
}
.form-summary:hover { border-color: var(--series-1); }
.form-summary-text { font-size: 13px; line-height: 1.5; color: var(--text-secondary); }
.form-summary .edit-icon { width: 16px; height: 16px; flex: none; color: var(--muted); }

.numbers-chip {
  display: none;
  position: fixed;
  top: 76px;
  left: 16px;
  z-index: 25;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  background: var(--series-1);
  color: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.18);
  cursor: pointer;
}
.numbers-chip svg { width: 19px; height: 19px; }

@media (min-width: 900px) {
  .numbers-chip, .btn-continue { display: none !important; }
  body.numbers-collapsed .form-card { display: none; }
  body.numbers-collapsed .form-summary { display: flex; }
}

@media (max-width: 899px) {
  .btn-continue { display: flex; }

  body:not(.numbers-collapsed) .goal-card,
  body:not(.numbers-collapsed) .events-card,
  body:not(.numbers-collapsed) .results { display: none; }

  body.numbers-collapsed:not(.numbers-overlay) .form-card { display: none; }
  body.numbers-collapsed:not(.numbers-overlay) .numbers-chip { display: flex; }
  body.numbers-collapsed:not(.numbers-overlay) .hero-intro { padding-top: 70px; }

  body.numbers-overlay .form-card {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 60;
    overflow-y: auto;
    border-radius: 0;
    border: none;
    animation: none;
  }
  body.numbers-overlay { overflow: hidden; }
}

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 16px;
  background: var(--page);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  flex: 1;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.segmented input:checked + label { background: var(--series-1); color: #fff; }
.segmented input:focus-visible + label { box-shadow: 0 0 0 3px var(--series-1-wash); }

.field-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--page);
  padding: 0 10px;
}
.input-wrap:focus-within {
  border-color: var(--series-1);
  box-shadow: 0 0 0 3px var(--series-1-wash);
}
.input-wrap .prefix, .input-wrap .suffix {
  color: var(--muted);
  font-size: 14px;
}
.input-wrap input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  padding: 10px 6px;
  font-size: 14px;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.input-wrap input::-webkit-outer-spin-button,
.input-wrap input::-webkit-inner-spin-button { opacity: 0.4; }

.disclaimer {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  margin: 20px 0 0;
}

.results { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.events-card { display: flex; flex-direction: column; gap: 16px; }
.events-head h2 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.events-sub { margin: 0; font-size: 13px; color: var(--text-secondary); }

.events-grid {
  display: grid;
  grid-template-columns: 1fr;
  align-items: start;
  gap: 10px;
}
@media (min-width: 640px) {
  .events-grid { grid-template-columns: 1fr 1fr; }
}

.event-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--page);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.event-card:has(input:checked) {
  border-color: color-mix(in srgb, var(--series-1) 35%, var(--border));
  background: var(--series-1-wash);
}

.event-header {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.event-icon {
  width: 19px;
  height: 19px;
  flex: none;
  color: var(--text-secondary);
  transition: color 0.15s ease;
}
.event-header:has(input:checked) .event-icon { color: var(--series-1); }
.event-title { font-size: 14px; font-weight: 500; color: var(--text-primary); }

.heading-icon { width: 17px; height: 17px; vertical-align: -3px; color: var(--series-1); }

.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
  flex: none;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.switch-track {
  position: absolute;
  inset: 0;
  background: var(--gridline);
  border-radius: 999px;
  transition: background 0.15s ease;
}
.switch-track::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: var(--surface-1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  transition: transform 0.15s ease;
}
.switch input:checked + .switch-track { background: var(--series-1); }
.switch input:checked + .switch-track::before { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--series-1-wash); }

.event-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
.event-fields[hidden] { display: none; }
.mini-field label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}
.mini-field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
  padding: 7px 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.mini-field input:focus {
  outline: none;
  border-color: var(--series-1);
  box-shadow: 0 0 0 3px var(--series-1-wash);
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 480px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 640px) {
  .stat-row { grid-template-columns: repeat(3, 1fr); }
}

.hero-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  grid-column: 1 / -1;
  border-left: 3px solid var(--series-1);
}
.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}
.hero-figure {
  font-size: clamp(30px, 7vw, 40px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.stat-sub { font-size: 12px; color: var(--muted); }

.stat-card { display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.stat-value { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.stat-good { color: var(--good); }
.stat-bad { color: var(--bad); }

.goal-progress { margin-top: 14px; }
.goal-progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
#goalProgressPct { font-weight: 600; color: var(--text-primary); }
.goal-progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--gridline);
  overflow: hidden;
}
.goal-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--series-1);
  transition: width 0.3s ease, background 0.3s ease;
}
.goal-progress-fill.on-track { background: var(--good); }
.goal-progress-fill.behind { background: var(--bad); }
.goal-progress-delta { display: block; margin-top: 6px; font-size: 12px; color: var(--text-secondary); }

.chart-card { display: flex; flex-direction: column; gap: 4px; }
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.chart-head h2 { margin: 0; font-size: 15px; font-weight: 600; }

.legend { display: flex; gap: 16px; }
.legend[hidden] { display: none; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}
.swatch-1 { background: var(--series-1); }
.swatch-2 { background: var(--series-2); }

.chart-wrap { position: relative; width: 100%; }
#chartSvg { width: 100%; height: auto; display: block; touch-action: pan-y; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  transform: translate(-50%, -110%);
  white-space: nowrap;
  z-index: 5;
}
.tooltip-age { font-weight: 600; margin-bottom: 4px; color: var(--text-primary); }
.tooltip-row { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.tooltip-row + .tooltip-row { margin-top: 2px; }

.chart-foot { margin-top: 6px; }
.link-btn {
  background: none;
  border: none;
  color: var(--series-1);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 0;
}
.link-btn:hover { text-decoration: underline; }

.table-wrap { margin-top: 10px; overflow-x: auto; border-top: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  text-align: right;
  padding: 8px 10px;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
th { color: var(--text-secondary); font-weight: 500; }
