:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-strong: #184f95;
  --good: #0ca30c;
  --critical: #d03b3b;
  --band-outer: rgba(42, 120, 214, 0.12);
  --band-inner: rgba(42, 120, 214, 0.24);
  /* Validated categorical palette (dataviz skill reference/palette.md) -- fixed hue order,
     never cycled/regenerated; a 9th series folds into a neutral "Other" instead of a new hue. */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  /* Non-color tokens. Theme-invariant, so unlike the palette above they're declared once
     rather than repeated in each theme block. An 8px-derived spacing scale replaces the
     ad-hoc 4/8/12/16/20/24px values that had accumulated, so vertical rhythm is consistent
     between sections instead of per-rule. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.04);
  --shadow-md: 0 1px 3px rgba(11, 11, 11, 0.06), 0 8px 24px -12px rgba(11, 11, 11, 0.10);
  --content-max: 1280px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-strong: #86b6ef;
    --good: #0ca30c;
    --critical: #e66767;
    --band-outer: rgba(57, 135, 229, 0.16);
    --band-inner: rgba(57, 135, 229, 0.30);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page-plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-strong: #86b6ef;
  --good: #0ca30c;
  --critical: #e66767;
  --band-outer: rgba(57, 135, 229, 0.16);
  --band-inner: rgba(57, 135, 229, 0.30);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

/* Several elements toggled via the `hidden` attribute also set their own `display`
   (e.g. .field, .panel) which otherwise wins the cascade over the UA default. */
[hidden] {
  display: none !important;
}

main {
  flex: 1;
  min-width: 0;
}

.page-view {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.page-header {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-4);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

/* Separates the app chrome from the working area below. Full-bleed via a wrapper border
   would need extra markup, so the rule rides on the layout's own top edge instead. */
.app-layout {
  border-top: 1px solid var(--border);
  padding-top: var(--space-5);
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--space-5) var(--space-7);
  display: flex;
  align-items: flex-start;
  gap: 24px;
}

.side-nav {
  flex: none;
  width: 176px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 20px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
}

.side-nav__btn {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.side-nav__icon {
  width: 18px;
  height: 18px;
  flex: none;
  color: currentColor;
  opacity: 0.85;
}

.side-nav__btn:hover {
  background: var(--page-plane);
  color: var(--text-primary);
}

.side-nav__btn[aria-selected="true"] {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent-strong);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}

.side-nav__btn[aria-selected="true"] .side-nav__icon {
  opacity: 1;
}

/* Hover must not flip the selected item back to a solid fill -- it would undo the tinted
   treatment above the moment the pointer crossed it. */
.side-nav__btn[aria-selected="true"]:hover {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent-strong);
}

.page-header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: var(--space-1) 0 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  cursor: pointer;
  flex: none;
}

.page-header__actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}

.header-account {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-signout-button {
  padding: 6px 14px;
  font-size: 0.82rem;
}

/* Sign in / Register, shown to a guest in place of the signed-in account block. Register is the
   filled button because creating an account is what actually unlocks saving -- signing in is for
   people who already know they have one. Both are sized to match the sign-out button so the
   header keeps one control height whichever state it's in. */
.header-guest {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.header-guest .secondary-button,
.header-register-button {
  padding: 6px 14px;
  font-size: 0.82rem;
}

.landing-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: color-mix(in srgb, var(--page-plane) 92%, transparent);
  backdrop-filter: blur(2px);
}

.landing-card {
  width: 100%;
  max-width: 380px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.landing-guest-button {
  width: 100%;
  margin-top: 16px;
}

.landing-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.landing-divider::before,
.landing-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--gridline);
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-md);
}

.card h2 {
  margin: 0 0 var(--space-5);
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

/* Section headings inside a card. Previously 0.95rem bold uppercase sitting flush against
   the preceding field with only a 24px gap, which read as an unstyled <h3> rather than a
   divider -- "PORTFOLIO WEIGHTS" landed directly under the year inputs with nothing
   separating them. Now smaller and muted, with a hairline rule above doing the actual
   dividing, so the card reads as distinct sections instead of one undifferentiated column. */
.card h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  color: var(--text-muted);
  margin: var(--space-6) 0 var(--space-4);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}

/* A section heading that directly follows the card title needs no rule -- the title already
   opens the card, and a line immediately under it reads as a stray underline. Every other h3
   follows real content (a chart, a set of fields) and does need the separation, including the
   first one in a card, which is why this is an adjacency rule and not :first-of-type. */
.card h2 + h3 {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 20px;
}

.mode-toggle__btn {
  border: none;
  background: var(--surface-1);
  color: var(--text-secondary);
  padding: 8px 16px;
  font-size: 0.9rem;
  cursor: pointer;
}

.mode-toggle__btn[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.field-row label {
  font-weight: 600;
  font-size: 0.9rem;
}

select,
input[type="number"],
input[type="text"],
input[type="email"],
input[type="password"] {
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}

select {
  min-width: 220px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.field input {
  width: 100%;
}

.weights-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.weight-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.weight-row .weight-name {
  flex: 1;
  font-size: 0.9rem;
}

.weight-row input {
  width: 90px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.weight-row [data-role="name"] {
  flex: 1;
  width: auto;
  min-width: 0;
  text-align: left;
}

.weight-row input[data-role="weight"] {
  width: 90px;
  text-align: right;
}

.weight-row input[data-role="weight-slider"] {
  flex: none;
  width: 110px;
  accent-color: var(--accent);
}

.row-remove {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.row-remove:hover {
  background: color-mix(in srgb, var(--critical) 12%, var(--surface-1));
  color: var(--critical);
  border-color: var(--critical);
}

.pf-add-asset {
  margin-top: 10px;
}

.weight-total {
  margin: 12px 0 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

#historical-total,
#parametric-total {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-primary);
}

.flag {
  font-weight: 600;
}

.flag.ok::before {
  content: "✓ ";
  color: var(--good);
}

.flag.bad {
  color: var(--critical);
}

.flag.bad::before {
  content: "✕ ";
}

.asset-table,
.corr-table,
.results-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.88rem;
}

.asset-table th,
.asset-table td,
.results-table th,
.results-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--gridline);
  text-align: right;
}

.asset-table th:first-child,
.asset-table td:first-child,
.results-table th:first-child,
.results-table td:first-child {
  text-align: left;
}

.asset-table input {
  width: 100%;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.asset-table input[type="text"] {
  text-align: left;
}

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

.corr-table {
  min-width: 480px;
}

.corr-table th,
.corr-table td {
  padding: 4px 6px;
  text-align: center;
  font-size: 0.82rem;
}

.corr-table th {
  color: var(--text-secondary);
  font-weight: 500;
}

.corr-table input {
  width: 60px;
  padding: 4px 2px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}

.corr-table input::-webkit-outer-spin-button,
.corr-table input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.corr-table input:disabled {
  color: var(--text-muted);
  background: transparent;
  border-color: transparent;
}

.inflation-row {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

.checkbox-label input {
  width: auto;
}

.inline-input {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.inline-input input {
  width: 90px;
}

.advanced {
  margin-top: 20px;
}

.advanced summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.run-row {
  margin-top: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.run-button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.run-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.secondary-button {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}

.secondary-button:hover {
  background: var(--page-plane);
}

.portfolio-list {
  display: flex;
  flex-direction: column;
  margin-top: 16px;
}

.portfolio-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--gridline);
}

.portfolio-row:last-child {
  border-bottom: none;
}

.portfolio-row__name {
  font-weight: 600;
}

/* Marks a read-only example portfolio in the list. Sits inline after the name so the row says
   what it is before the reader reaches the missing Edit/Delete buttons. */
.badge {
  display: inline-block;
  margin-left: var(--space-2);
  padding: 1px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent-strong);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  vertical-align: middle;
}

.portfolio-row__actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.portfolio-row__actions .secondary-button {
  padding: 6px 14px;
  font-size: 0.82rem;
}

.error-banner {
  margin-top: 16px;
  padding: 10px 14px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--critical) 12%, var(--surface-1));
  color: var(--critical);
  font-size: 0.88rem;
}

.muted {
  color: var(--text-secondary);
}

.small {
  font-size: 0.82rem;
}

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.stat-tile {
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
}

.stat-tile__label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
}

.stat-tile__value {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Results headline.
   Every output used to be an equal-weight tile, so "Median final value" carried exactly the
   same emphasis as "Simulations: 20,000" -- an echo of an input. The one number a user came
   for was left for them to find. This promotes it to a hero figure, keeps the two other real
   outcomes as supporting tiles, and demotes the input echoes to the meta line below. */
/* Container for the results summary. A plain block, not the tile grid it used to be: it now
   holds a headline row and a meta line, which a grid laid out as side-by-side cells. */
.results-summary {
  display: block;
}

.result-headline {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: var(--space-5);
  margin-bottom: var(--space-4);
}

.result-hero {
  flex: 1 1 260px;
  min-width: 0;
}

.result-hero__label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  color: var(--text-muted);
}

.result-hero__value {
  font-size: clamp(2.25rem, 4.5vw, 3.25rem);
  font-weight: 650;
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin-top: var(--space-2);
}

.result-hero__sub {
  margin-top: var(--space-2);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Two tiles side by side rather than an auto-fit grid: auto-fit collapsed them into a narrow
   vertical stack pinned to the far right of the headline row, which read as two stray boxes
   rather than a pair supporting the hero figure. */
.result-metrics {
  flex: 0 1 440px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  align-content: center;
}

@media (max-width: 700px) {
  .result-metrics {
    flex-basis: 100%;
  }
}

/* Run parameters. These describe the run rather than report a result, so they read as one
   quiet line instead of competing with the numbers above. */
.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-5);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.result-meta__item + .result-meta__item::before {
  content: "·";
  margin-right: var(--space-3);
  color: var(--axis);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 8px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.chart-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 14px;
  height: 10px;
  border-radius: 2px;
  flex: none;
}

.legend-swatch.line {
  height: 2px;
  border-radius: 1px;
}

.pie-chart-row {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  margin: 4px 0 8px;
}

.pie-chart {
  width: 180px;
  height: 180px;
  flex: none;
}

.pie-chart path {
  stroke: var(--surface-1);
  stroke-width: 0.5;
}

.pie-legend {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  flex: 1;
  min-width: 180px;
}

.chart-wrap {
  position: relative;
}

#fan-chart {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
}

.axis-text {
  fill: var(--text-muted);
  font-size: 11px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

/* Axis titles sit a step above the tick labels in emphasis but stay recessive against the
   data -- they name the scale, they aren't part of it. */
.axis-title {
  fill: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 500;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.gridline {
  stroke: var(--gridline);
  stroke-width: 1;
}

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

.crosshair {
  stroke: var(--text-muted);
  stroke-width: 1;
  pointer-events: none;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.8rem;
  box-shadow: 0 4px 12px rgba(11, 11, 11, 0.12);
  white-space: nowrap;
  transform: translate(-50%, -110%);
}

.tooltip__year {
  font-weight: 600;
  margin-bottom: 4px;
}

.tooltip__row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.tooltip__row .value {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.table-toggle {
  margin-top: 16px;
}

.table-toggle .table-scroll {
  max-height: 320px;
  overflow-y: auto;
}

.results-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
}

.table-toggle summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.results-table td,
.results-table th {
  font-variant-numeric: tabular-nums;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 720px) {
  .app-layout {
    flex-direction: column;
  }

  .side-nav {
    width: 100%;
    flex-direction: row;
    position: static;
    overflow-x: auto;
  }

  .side-nav__btn {
    flex: 1;
    justify-content: center;
    text-align: center;
  }
}

@media (max-width: 600px) {
  .page-header {
    flex-direction: column;
  }

  select {
    min-width: 0;
    flex: 1;
  }
}
