/* ============================================================
   viz.css — Shared visualization styles
   Based on the CFA visualization design system.
   Loaded automatically on all /visualizations/ pages.

   ------------------------------------------------------------
   Guidelines for new visualizations
   ------------------------------------------------------------
   1. Prefer shared classes over local redefinitions. Shared:
      .container .hero .section .section-label
      .viz-box .viz-row .viz-col .viz-title
      .slider-group .slider-row .slider-col .slider-label .slider-val .slider-sublabel
      .btn .btn.btn-orange .scenario-btn.active
      .fit-stats .fit-stat .fit-stat-label .fit-stat-value
      .note (+ .note.warn .note.caveat) .equation
      .info-btn .info-overlay .info-modal .info-close
      .data-table .legend

   2. Use palette variables, not literal hex. Categorical series
      colors (use in order for multi-line/multi-group charts):
        --series-1 teal   --series-2 orange  --series-3 blue
        --series-4 purple --series-5 yellow
      Reserved semantic colors (do not use as series):
        --red      bright error / bad-fit
        --red-dark muted caveat notes
        --green    emphasis / reference links (see .ref)
        --teal     also doubles as the primary accent

   3. Font-size scale (em, not rem, so nested elements compose):
        0.70em  .fit-stat-label, small uppercase kickers
        0.75em  .section-label, .slider-group-title
        0.78em  .viz-title, .legend, .data-table
        0.82em  .slider-label, .slider-val, .btn, .data-table
        0.92em  .note, .equation
        1.15em  .fit-stat-value (large readout)
        1.5em   .section h2
        2.4em   .hero h1

   4. In <canvas> code, read palette from CSS vars at init:
        const css = getComputedStyle(document.documentElement);
        const teal = css.getPropertyValue('--teal').trim();
      Do not embed literal palette hexes in JS.
   ============================================================ */

:root {
  --bg: #0f1117;
  --bg-surface: #181a24;
  --bg-elevated: #1e2030;
  --text: #c9cdd8;
  --text-bright: #e8ecf4;
  --text-dim: #b0b4c0;

  /* Categorical palette (5 series colors) */
  --teal: #2dd4bf;
  --teal-dim: rgba(45,212,191,0.15);
  --orange: #f97316;
  --orange-dim: rgba(249,115,22,0.15);
  --blue: #3b82f6;
  --blue-dim: rgba(59,130,246,0.15);
  --purple: #a78bfa;
  --purple-dim: rgba(167,139,250,0.15);
  --yellow: #eab308;
  --yellow-dim: rgba(234,179,8,0.15);
  --green: #4ade80;
  --green-dim: rgba(74,222,128,0.15);

  /* Series aliases — use these when color has no semantic meaning */
  --series-1: var(--teal);
  --series-2: var(--orange);
  --series-3: var(--blue);
  --series-4: var(--purple);
  --series-5: var(--yellow);

  /* Reserved semantic colors */
  --red: #ef4444;           /* errors, bad fit */
  --red-dim: rgba(239,68,68,0.15);
  --red-dark: #8b1a1a;      /* muted caveat notes */

  --mono: 'IBM Plex Mono', monospace;
  --serif: 'Source Serif 4', Georgia, serif;
  --border: #2a2d3a;
}

/* Widen PaperMod content area for visualizations */
.post-content:has(.container) { max-width: 1000px; }
.main:has(.container) { --main-width: 1040px; }
.post-header .post-title { display: none; }

/* Container */
.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0;
}

/* Hero header */
.hero {
  padding: 100px 0 60px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 60px;
}
.hero h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 2.4em;
  color: var(--text-bright);
  line-height: 1.2;
  margin-bottom: 16px;
}
.hero .subtitle {
  font-family: var(--mono);
  font-size: 1.0rem;
  color: var(--text);
  line-height: 1.6;
}

/* Sections */
.section {
  margin-bottom: 80px;
}
.section-label {
  font-family: var(--mono);
  font-size: 0.75em;
  font-weight: 600;
  color: var(--teal);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}
.section h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.5em;
  color: var(--text-bright);
  margin-bottom: 16px;
}
.section p {
  margin-bottom: 16px;
  max-width: 680px;
}
.section p:last-of-type {
  margin-bottom: 28px;
}

/* Inline math/code highlight */
.m {
  font-family: var(--mono);
  font-size: 0.88em;
  color: var(--teal);
  padding: 1px 4px;
  background: var(--teal-dim);
  border-radius: 3px;
}

/* Visualization containers */
.viz-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px;
  margin-bottom: 24px;
}
.viz-box.wide {
  padding: 28px 20px;
}
.viz-row {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.viz-col {
  flex: 1;
  min-width: 280px;
}
.viz-title {
  font-family: var(--mono);
  font-size: 0.78em;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

/* Sliders */
.slider-group {
  margin-bottom: 20px;
}
.slider-group-title {
  font-family: var(--mono);
  font-size: 0.75em;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
/* Horizontal slider row: label | slider | value. Good for short labels. */
.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.slider-label {
  font-family: var(--mono);
  font-size: 0.82em;
  color: var(--text);
  width: 28px;
  text-align: right;
  flex-shrink: 0;
}
/* Wide-label variant: use when the label is a phrase rather than a symbol. */
.slider-row.wide .slider-label {
  width: auto;
  text-align: left;
  color: var(--text-dim);
}
/* 42px is a min, not a cap. A fixed `width` fit "0.30" but not "-0.36": at the
   17px base, 0.82em of IBM Plex Mono is ~8.4px per glyph, so five characters need
   ~42px and the minus sign tipped every negative-range slider over the edge. The
   box could not grow, so the value wrapped onto a second line and pushed the row
   taller. `min-width` keeps every 4-character value aligned exactly as before and
   lets the rest grow; `nowrap` guarantees a numeric readout never breaks in two,
   whatever font actually resolves.
   `nowrap` alone isn't enough, though: PaperMod's reset.css sets
   `body { word-break: break-word }`, which is inherited and gives the browser
   permission to break mid-token specifically to avoid overflow -- it overrides
   `white-space: nowrap`'s no-break behavior whenever the row is squeezed (e.g. a
   range input that can't shrink enough, see the `min-width: 0` note below). Reset
   both break properties here so a numeric readout can never split. */
.slider-val {
  font-family: var(--mono);
  font-size: 0.82em;
  color: var(--teal);
  min-width: 42px;
  text-align: right;
  flex-shrink: 0;
  font-weight: 600;
  white-space: nowrap;
  word-break: keep-all;
  overflow-wrap: normal;
}
/* Stacked slider cell: label (with inline value span) on top, slider below.
   Good for long labels and multi-column grids. Pair with .slider-val for the value.
   `justify-content: flex-end` keeps sliders aligned to the bottom of each cell so
   they line up horizontally across a multi-column grid even when label heights vary. */
.slider-col {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  font-family: var(--mono);
  font-size: 0.82em;
}
.slider-col label {
  color: var(--text-dim);
}
/* In a stacked cell the value sits inline after the label text, so it shrinks to
   fit. `min-width: 0` cancels the 42px floor from the base rule, which these never
   had (the old base set `width`, and `width: auto` here overrode it outright). */
.slider-col .slider-val {
  width: auto;
  min-width: 0;
  text-align: left;
}
/* In a column flex context, the base `input[type="range"] { flex: 1 }` rule
   stretches the input vertically — thickening the track. Reset to natural height. */
.slider-col input[type="range"] {
  flex: none;
}
/* Small sublabel sitting under a slider (e.g. units, brief explanation). */
.slider-sublabel {
  font-family: var(--mono);
  font-size: 0.72em;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Range input theming */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0; /* form controls have a non-zero automatic min-width; without
    this a flex row can't compress the track enough to leave room for a wide
    label + value, and something has to give -- see .slider-val above. */
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--teal);
  cursor: pointer;
  border: 2px solid var(--bg-surface);
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--teal);
  cursor: pointer;
  border: 2px solid var(--bg-surface);
}
input[type="range"].orange-slider::-webkit-slider-thumb {
  background: var(--orange);
}
input[type="range"].orange-slider::-moz-range-thumb {
  background: var(--orange);
}

/* Select / dropdown styling */
select {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 10px;
  cursor: pointer;
  outline: none;
}
select:focus {
  border-color: var(--teal);
}

/* Buttons */
.btn {
  font-family: var(--mono);
  font-size: 0.82em;
  font-weight: 600;
  padding: 10px 20px;
  border: 1px solid var(--teal);
  background: transparent;
  color: var(--teal);
  border-radius: 5px;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: all 0.2s;
}
.btn:hover {
  background: var(--teal-dim);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn.btn-orange {
  border-color: var(--orange);
  color: var(--orange);
}
.btn.btn-orange:hover {
  background: var(--orange-dim);
}
.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* Stat cards */
.fit-stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.fit-stat {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 18px;
  min-width: 110px;
}
.fit-stat-label {
  font-family: var(--mono);
  font-size: 0.7em;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}
.fit-stat-value {
  font-family: var(--mono);
  font-size: 1.15em;
  font-weight: 600;
  color: var(--text-bright);
}
.fit-stat-value.good { color: var(--teal); }
.fit-stat-value.poor { color: var(--orange); }
.fit-stat-value.bad { color: var(--red); }

/* Note boxes */
.note {
  background: var(--bg-elevated);
  border-left: 3px solid var(--teal);
  padding: 14px 18px;
  margin: 20px 0;
  font-size: 0.92em;
  border-radius: 0 6px 6px 0;
  max-width: 680px;
}
.note.warn {
  border-left-color: var(--orange);
}
.note.caveat {
  border-left-color: var(--red-dark);
}
.note + .note {
  margin-top: 8px;
}

/* Equation display */
.equation {
  font-family: var(--mono);
  font-size: 0.92em;
  color: var(--text-bright);
  background: var(--bg-elevated);
  padding: 14px 20px;
  border-radius: 6px;
  margin: 16px 0;
  display: inline-block;
  letter-spacing: 0.01em;
}

/* Equation hover tooltips */
.eq-sym {
  position: relative;
  cursor: help;
  border-bottom: 1px dashed var(--text-dim);
  padding: 0 1px;
  transition: color 0.15s;
}
.eq-sym:hover { color: var(--teal); }
.eq-tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  z-index: 100;
  white-space: pre;
  font-size: 0.82em;
  line-height: 1.5;
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  pointer-events: none;
  min-width: max-content;
}
.eq-tip .tip-label {
  color: var(--teal);
  font-size: 0.9em;
  margin-bottom: 6px;
  display: block;
  white-space: nowrap;
}
.eq-tip .tip-matrix {
  color: var(--text-bright);
  font-family: var(--mono);
  white-space: pre;
}
.eq-tip .tip-matrix pre {
  display: inline;
  margin: 0;
  padding: 0;
  font-family: inherit;
  color: inherit;
  white-space: pre;
  line-height: 1.2;
}
.eq-sym:hover .eq-tip { display: block; }

/* Info buttons */
.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  border: 1.5px solid var(--text-dim);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-left: 8px;
  vertical-align: middle;
  transition: all 0.2s;
  position: relative;
  top: -2px;
  line-height: 1;
}
.info-btn:hover {
  border-color: var(--teal);
  color: var(--teal);
  background: var(--teal-dim);
}
.info-btn.hero-info {
  width: 32px;
  height: 32px;
  font-size: 0.47em;
  border-width: 2px;
  top: -4px;
}

/* Info modal overlay */
.info-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.info-overlay.active {
  display: flex;
}
.info-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 580px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 32px;
  position: relative;
}
.info-modal-badge {
  font-family: var(--mono);
  font-size: 0.72em;
  color: var(--teal);
  background: var(--teal-dim);
  padding: 3px 10px;
  border-radius: 3px;
  display: inline-block;
  margin-bottom: 12px;
  letter-spacing: 0.03em;
}
.info-modal h3 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.25em;
  color: var(--text-bright);
  margin-bottom: 16px;
  line-height: 1.3;
}
.info-modal p {
  font-size: 0.94em;
  margin-bottom: 12px;
  line-height: 1.65;
  color: var(--text);
}
.info-modal p:last-child {
  margin-bottom: 0;
}
.info-modal .formula {
  font-family: var(--mono);
  font-size: 0.88em;
  color: var(--text-bright);
  background: var(--bg-elevated);
  padding: 10px 16px;
  border-radius: 5px;
  margin: 12px 0;
  display: inline-block;
}
.info-modal em {
  color: var(--text-bright);
  font-style: italic;
}
.info-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.info-close:hover {
  border-color: var(--text);
  color: var(--text);
}

/* Reference links — bold + green. Apply to inline citation <a> tags. */
.ref,
a.ref {
  font-weight: 600;
  color: var(--green);
}
.ref:hover,
a.ref:hover {
  color: var(--green);
  opacity: 0.8;
}

/* Scenario/toggle buttons */
.scenario-btn {
  transition: all 0.2s;
}
.scenario-btn.active {
  background: var(--teal-dim);
  border-color: var(--teal);
  color: var(--teal);
}

/* Data tables — numeric/centered grid (e.g. correlation matrices) */
.data-table {
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.82em;
}
.data-table th {
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 0.85em;
  letter-spacing: 0.04em;
  padding: 6px 12px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 5px 12px;
  text-align: center;
  color: var(--text);
}

/* Domain tables — left-aligned comparison/contrast tables.
   Mono body, dim uppercase headers, dim row-label first column,
   light row borders, teal hover highlight. Use .yes/.no/.maybe
   spans inside <td> for traffic-light value coloring. Page-specific
   th color modifiers (e.g. teal/orange column tints) stay local. */
.domain-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-family: var(--mono);
  font-size: 0.82em;
}
.domain-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.domain-table td {
  padding: 6px 12px;
  border-bottom: 1px solid rgba(42,45,58,0.5);
  color: var(--text);
  vertical-align: top;
}
.domain-table td:first-child {
  color: var(--text-dim);
  white-space: nowrap;
}
.domain-table tr:hover td {
  background: var(--teal-dim);
}
.domain-table code {
  background: rgba(42,45,58,0.6);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text-bright);
  font-size: 0.92em;
}
.domain-table .yes { color: var(--green); }
.domain-table .no { color: var(--red); }
.domain-table .maybe { color: var(--orange); }
@media (max-width: 720px) {
  .domain-table { font-size: 0.78em; }
  .domain-table th, .domain-table td { padding: 6px 8px; }
}

/* Footer */
.viz-footer {
  border-top: 1px solid var(--border);
  padding: 40px 0;
  margin-top: 40px;
}
.viz-footer p {
  font-family: var(--mono);
  font-size: 0.78em;
  color: var(--text-dim);
}

/* Legend */
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 0.78em;
  color: var(--text-dim);
  margin-bottom: 12px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Canvas containers — use on wrapper divs around <canvas> elements */
canvas {
  display: block;
  width: 100%;
}

/* Responsive */
@media (max-width: 640px) {
  .hero h1 { font-size: 1.7em; }
  .viz-row { flex-direction: column; }
  .viz-col { min-width: auto; }
  .viz-box { padding: 16px; }
  .fit-stats { flex-direction: column; }
}
