/* ---------------------------------------------------------------------
   Tokens — validated categorical pair (blue = distribution, orange = you)
   ------------------------------------------------------------------- */
:root {
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --grid-line:   #e1e0d9;
  --axis-line:   #c3c2b7;
  --border:      rgba(11, 11, 11, 0.10);
  --curve:       #2a78d6;   /* categorical slot 1 — the all-portfolios aggregate */
  --curve-wash:  rgba(42, 120, 214, 0.10);
  --you:         #eb6834;   /* categorical slot 2 — emphasis: your return */
  --you-wash:    rgba(235, 104, 52, 0.12);
  --focus-ring:  #2a78d6;
  /* categorical slot 3 (aqua) as a sequential ramp for k_eff concentration --
     validated all-pairs against --curve/--you in both modes (dataviz skill's
     palette.md: "first three slots validate all-pairs"). lo = concentrated
     (k_eff~1, full palette anchor), hi = diffuse (k_eff~100, blended toward
     the surface) -- same hue, monotone lightness, per the sequential formula. */
  --keff-lo:     #1baf7a;
  --keff-hi:     #b8e5d4;

  --font-display: ui-serif, Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --font-body:    system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono:    ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, "Liberation Mono", monospace;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page:        #0d0d0d;
    --surface:     #1a1a19;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --muted:       #898781;
    --grid-line:   #2c2c2a;
    --axis-line:   #383835;
    --border:      rgba(255, 255, 255, 0.10);
    --curve:       #3987e5;
    --curve-wash:  rgba(57, 135, 229, 0.14);
    --you:         #d95926;
    --you-wash:    rgba(217, 89, 38, 0.16);
    --focus-ring:  #3987e5;
    --keff-lo:     #199e70;
    --keff-hi:     #a3d8c6;
    color-scheme: dark;
  }
}

/* ---------------------------------------------------------------------
   Base
   ------------------------------------------------------------------- */
* { box-sizing: border-box; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  /* faint graph-paper texture — grid-line sits one step off the page color,
     so the ruling reads as paper, not decoration */
  background-image:
    repeating-linear-gradient(0deg, var(--grid-line) 0 1px, transparent 1px 48px),
    repeating-linear-gradient(90deg, var(--grid-line) 0 1px, transparent 1px 48px);
  background-color: var(--page);
  background-attachment: fixed;
  margin: 0 auto;
  max-width: 960px;
  padding: 2rem 1.5rem 4rem;
  line-height: 1.5;
}

a { color: var(--curve); }
a:visited { color: var(--curve); }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------
   Header
   ------------------------------------------------------------------- */
.site-header {
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.75rem;
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.6rem;
}
.site-header h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.2rem, 5vw, 3rem);
  letter-spacing: -0.01em;
  margin: 0 0 0.5rem;
}
.tagline {
  font-family: var(--font-body);
  color: var(--ink-2);
  max-width: 42em;
  margin: 0;
  font-size: 1.02rem;
}

/* ---------------------------------------------------------------------
   Controls
   ------------------------------------------------------------------- */
.controls {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.1rem 1.25rem;
  margin: 0 0 1.25rem;
}
.control {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.9rem;
  flex: 1 1 12rem;
}
.control-wide { flex: 2 1 18rem; }
.control-label {
  font-family: var(--font-body);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.control-hint { font-weight: normal; }

select#window-select,
input#user-return {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--axis-line);
  border-radius: 4px;
  padding: 0.45rem 0.6rem;
}
select#window-select:focus-visible,
input#user-return:focus-visible { outline-offset: 1px; }

.range-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
input[type="range"] {
  flex: 1;
  accent-color: var(--curve);
}
output#keff-label {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  min-width: 3.5em;
  text-align: right;
  font-size: 0.9rem;
}

.input-affix {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--page);
  border: 1px solid var(--axis-line);
  border-radius: 4px;
  padding: 0 0.6rem;
}
.input-affix input {
  border: none;
  background: transparent;
  padding: 0.45rem 0;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--ink);
}
.input-affix input:focus-visible { outline: none; }
.input-affix:focus-within { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.input-affix span { color: var(--muted); font-family: var(--font-mono); font-size: 0.9rem; }

/* ---------------------------------------------------------------------
   Verdict callout — the emphasis moment
   ------------------------------------------------------------------- */
.verdict {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--you-wash);
  border-left: 3px solid var(--you);
  border-radius: 0 6px 6px 0;
  padding: 0.85rem 1.1rem;
  margin: 0 0 1.25rem;
}
.verdict .verdict-num { color: var(--you); }

/* ---------------------------------------------------------------------
   View toggle (Journeys / Distribution)
   ------------------------------------------------------------------- */
.view-toggle {
  display: inline-flex;
  gap: 2px;
  background: var(--page);
  border: 1px solid var(--axis-line);
  border-radius: 6px;
  padding: 2px;
  margin-bottom: 0.6rem;
}
.view-toggle-btn {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-2);
  background: transparent;
  border: none;
  border-radius: 4px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
}
.view-toggle-btn:hover:not(:disabled) { color: var(--ink); }
.view-toggle-btn[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px var(--border);
}
.view-toggle-btn:disabled {
  color: var(--muted);
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------------------------------------------------------------------
   Chart
   ------------------------------------------------------------------- */
.chart-section { margin-bottom: 1rem; }
.chart-frame {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem 0.25rem;
}
svg#chart {
  width: 100%;
  height: auto;
  display: block;
}
svg#chart:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }

.chart-caption {
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.5rem 0.2rem 0;
}

.axis { stroke: var(--axis-line); stroke-width: 1; }
.grid { stroke: var(--grid-line); stroke-width: 1; }
.tick {
  fill: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.axis-caption {
  fill: var(--muted);
  font-family: var(--font-body);
  font-size: 12px;
}

.cdf {
  fill: none;
  stroke: var(--curve);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.cdf-area { fill: var(--curve-wash); }

/* Journeys fan band: two nested washes in the aggregate's own hue (blue),
   same convention as the CDF's area wash -- outer = 5th-95th (lighter),
   inner = 25th-75th (a second, darker step of the same wash), median is the
   bold .cdf line reused as-is so "the aggregate" reads the same color in
   both views. */
.fan-band-outer { fill: var(--curve-wash); }
.fan-band-inner { fill: var(--curve); opacity: 0.16; }

/* ETF real paths: dashed to read as "actual," distinct from both the
   translucent simulated strands and the bold aggregate/median line. */
.anchor-path {
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}
.anchor-path-label {
  fill: var(--ink-2);
  font-family: var(--font-body);
  font-size: 11px;
}
/* Declutter dot: when several real ETF paths end within a couple pixels of
   each other, this marks each one's decluttered position (beside its own
   label) so they stay individually identifiable, matching the Distribution
   view's anchor markers. */
.anchor-path-dot {
  fill: var(--ink-2);
  stroke: var(--surface);
  stroke-width: 1.5;
}

/* Shared by both chart views: one strand per non-null k_eff bucket in
   Distribution, one per simulated portfolio path in Journeys. Base state is
   thin and translucent on purpose -- with up to ~200 strands drawn, the
   density of overlap is itself the signal (where the family agrees vs.
   spreads out); individual strand color is a sequential ramp (see
   --keff-lo/--keff-hi), not identity, so no strand needs to be individually
   legible against the surface (the WARN-band aqua-vs-light-surface contrast
   noted in the dataviz palette is mitigated here by the highlight + tooltip,
   not by solid-mark contrast). Distribution highlights exactly one strand
   (the selected bucket); Journeys highlights a band of strands near the
   selected concentration -- both just add/remove this same class. */
.strand {
  fill: none;
  stroke-width: 1;
  opacity: 0.16;
  vector-effect: non-scaling-stroke;
}
.strand-highlight {
  opacity: 1;
  stroke-width: 2;
}

.keff-legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.4rem 0.2rem 0;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
}
.keff-legend-bar {
  flex: 1;
  max-width: 12rem;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--keff-lo), var(--keff-hi));
}

.anchor {
  fill: var(--muted);
  stroke: var(--surface);
  stroke-width: 2;
}
.anchor-label {
  fill: var(--ink-2);
  font-family: var(--font-body);
  font-size: 11px;
}
.anchor-leader {
  stroke: var(--muted);
  stroke-width: 1;
  opacity: 0.6;
}
/* Off-scale markers: their true value sits outside the robust p0.5-p99.5
   display domain, so the marker/label render clamped to the plot edge at
   reduced opacity -- the shape (triangle vs. circle/flag) plus the faded
   look signal "there's more past here," with the exact value in the tooltip. */
.anchor-edge { opacity: 0.55; }
.anchor-label-edge { opacity: 0.7; }

.you-guide {
  stroke: var(--you);
  stroke-width: 1;
  opacity: 0.45;
}
.you-marker {
  fill: var(--you);
  stroke: var(--surface);
  stroke-width: 2;
}
.you-edge { opacity: 0.55; }
.you-flag-label {
  fill: var(--you);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.04em;
}

.crosshair-line {
  stroke: var(--ink-2);
  stroke-width: 1;
  opacity: 0.55;
}
.crosshair-dot {
  fill: var(--curve);
  stroke: var(--surface);
  stroke-width: 2;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: var(--page);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.4;
  padding: 0.4rem 0.55rem;
  border-radius: 4px;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  z-index: 2;
}
.tooltip strong { font-size: 0.85rem; }
.tooltip-strand { opacity: 0.8; }

/* ---------------------------------------------------------------------
   Stats, table, footer
   ------------------------------------------------------------------- */
.stats {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  color: var(--ink-2);
  margin: 1rem 0 0.5rem;
  /* a pathological achievable-envelope multiple (a real published window's
     compounded worst/best case can run to a dozen-plus digits) must wrap
     rather than force horizontal scroll on the page */
  overflow-wrap: anywhere;
}
.stats b { color: var(--ink); font-weight: 600; }

.data-table-wrap {
  margin: 0.75rem 0 1.5rem;
  font-size: 0.85rem;
}
.data-table-wrap summary {
  cursor: pointer;
  color: var(--ink-2);
  font-family: var(--font-body);
}
.data-table-wrap summary:hover { color: var(--ink); }
.table-scroll { overflow-x: auto; margin-top: 0.6rem; }
#data-table {
  border-collapse: collapse;
  width: 100%;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
#data-table th, #data-table td {
  text-align: right;
  padding: 0.3rem 0.75rem;
  border-bottom: 1px solid var(--grid-line);
}
#data-table th:first-child, #data-table td:first-child { text-align: left; }
#data-table caption {
  caption-side: top;
  text-align: left;
  color: var(--muted);
  font-family: var(--font-body);
  font-variant-numeric: normal;
  padding-bottom: 0.4rem;
}

footer {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
footer a { text-decoration: underline; text-underline-offset: 2px; }
.meta-sep { margin: 0 0.5em; }
#meta { font-family: var(--font-mono); }

/* ---------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------- */
@media (max-width: 640px) {
  .controls { flex-direction: column; align-items: stretch; }
  .control-wide { flex: 1; }
}

/* ---------------------------------------------------------------------
   Reduced motion — no chart animation is shipped, but keep this guard so
   future additions default to respecting it.
   ------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
