/* =========================================================================
   FIN 30600 Interactive Tools — shared house style + layout skeleton.
   Matches the lecture decks (theme/ndcollegiate.sty "Collegiate Editorial"):
   Libertinus Sans body + Libertinus Serif display titles in ND navy, gold
   vertical-rule headers with a letterspaced grey eyebrow, white pages.
   Chart text stays Arial to match the lecture FIGURES (figure style guide).
   No build step; plain CSS custom properties.
   ========================================================================= */

/* Libertinus = maintained successor of Linux Libertine (serif) / Linux
   Biolinum (sans), the exact faces the beamer template uses. Self-hosted
   woff2, SIL OFL 1.1 (see ../vendor/fonts/). */
@font-face {
  font-family: 'Libertinus Sans';
  src: url('../vendor/fonts/LibertinusSans-Regular.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Libertinus Sans';
  src: url('../vendor/fonts/LibertinusSans-Bold.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Libertinus Sans';
  src: url('../vendor/fonts/LibertinusSans-Italic.woff2') format('woff2');
  font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
  font-family: 'Libertinus Serif';
  src: url('../vendor/fonts/LibertinusSerif-Regular.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Libertinus Serif';
  src: url('../vendor/fonts/LibertinusSerif-Bold.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Libertinus Serif';
  src: url('../vendor/fonts/LibertinusSerif-Italic.woff2') format('woff2');
  font-weight: 400; font-style: italic; font-display: swap;
}

/* The HTML `hidden` attribute must beat any author `display` rule (a plain
   [hidden] loses to e.g. `.ctrl { display:flex }` in this very stylesheet —
   that bug shipped once per-tool; the guard now lives here for every page). */
[hidden] { display: none !important; }

:root {
  /* House palette (locked in DESIGN.md) */
  --blue:   #0072B2;   /* primary series */
  --gold:   #C99700;   /* secondary series (ND web gold, deck's ndbgold) */
  --goldmetal: #AE9142; /* ND metallic gold — deck's chrome accent (ndgold) */
  --navy:   #0A234B;   /* chrome / headers (ND identity) */
  --softblue: #EBF1F8; /* deck softblue (progress-bar track) */
  --softgray: #F5F7FA; /* deck softgray (beamer button bg) */
  --red:    #D62728;   /* reference / "overpriced" dashed lines only */
  --grid:   #DDDDDD;   /* chart gridlines */
  --axis:   #666666;   /* axis spine / tick color */
  --label:  #333333;   /* axis + data labels */

  /* Neutral UI shades derived from the above */
  --ink:      #1a1a1a;
  --muted:    #5F6978;  /* deck ndgrey */
  --panel-bg: #f6f7f9;
  --panel-border: #e2e5ea;
  --card-bg:  #ffffff;
  --page-bg:  #ffffff;

  /* Metrics */
  --font-base: 16px;
  --stroke-scale: 1;
  --point-scale: 1;
  --panel-width: 300px;

  /* Body = the deck's sans (Biolinum → Libertinus Sans, self-hosted);
     display = the deck's serif titles; charts = Arial like the lecture
     figures (matplotlib house style). */
  --font-stack: 'Libertinus Sans', 'Linux Biolinum O', Arial, Helvetica, sans-serif;
  --font-display: 'Libertinus Serif', 'Linux Libertine O', Georgia, 'Times New Roman', serif;
  --font-chart: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  color: var(--ink);
  font-family: var(--font-stack);
  font-size: var(--font-base);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- header -- */

/* White letterhead header, as on the deck's frames: gold vertical rule,
   grey letterspaced uppercase eyebrow, navy SERIF title; closed off by the
   letterhead rule (thin navy line + short thick accent block). */
.app-header {
  background: var(--page-bg);
  color: var(--ink);
  padding: 1rem 1.4rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  position: relative;
  border-bottom: 1px solid var(--navy);
}
.app-header::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -3px;
  width: 56px;
  height: 5px;
  background: var(--navy);
}
.app-header .titles {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  border-left: 3px solid var(--goldmetal);
  padding-left: 0.8rem;
}
.app-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.15;
}
.app-header .subtitle {
  order: -1; /* eyebrow sits ABOVE the title, as on the frames */
  margin: 0;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}
.app-header .header-actions { display: flex; gap: 0.6rem; align-items: center; }

.btn {
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--navy);
  background: var(--softgray);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: var(--softblue); }
.btn.active { background: var(--gold); border-color: var(--gold); color: #fff; }

/* ----------------------------------------------------- tool app layout --- */

.tool-main {
  display: flex;
  gap: 1.25rem;
  padding: 1.25rem 1.4rem;
  align-items: flex-start;
  max-width: 1500px;
  margin: 0 auto;
}

.controls-panel {
  flex: 0 0 var(--panel-width);
  width: var(--panel-width);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 1rem 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.controls-panel h2 {
  margin: 0 0 0.2rem;
  font-size: 0.95rem;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}
.controls-panel .group { display: flex; flex-direction: column; gap: 0.7rem; }
.controls-panel .group-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 0.25rem;
}

.chart-area {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.chart-box {
  background: var(--card-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.5rem 0.6rem;
}

/* MathJax (standalone tex2svg doesn't inject its own stylesheet):
   container display + visually-hide the duplicate assistive MathML */
mjx-container[jax="SVG"] { direction: ltr; display: inline-block; }
mjx-container[jax="SVG"] > svg { overflow: visible; vertical-align: middle; }
mjx-assistive-mml {
  position: absolute !important;
  top: 0; left: 0;
  clip: rect(1px, 1px, 1px, 1px);
  padding: 1px 0 0 0 !important;
  border: 0 !important;
  display: block !important;
  width: auto !important;
  overflow: hidden !important;
}

/* live formula strip below the chart */
.formula-strip {
  background: var(--card-bg);
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--goldmetal); /* deck's gold vertical-rule motif */
  border-radius: 8px;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  overflow-x: auto;
}
.formula-strip .formula-row { margin: 0.25rem 0; }

/* readouts block */
.readouts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.5rem 1rem;
}
.readout {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}
.readout .k { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.readout .v { font-size: 1.1rem; font-weight: 700; color: var(--navy); }
.readout .v.blue { color: var(--blue); }
.readout .v.gold { color: var(--gold); }

/* -------------------------------------------------------------- controls -- */

.ctrl { display: flex; flex-direction: column; gap: 0.3rem; }
.ctrl-head { display: flex; justify-content: space-between; align-items: baseline; }
.ctrl-label { font-size: 0.85rem; color: var(--label); font-weight: 600; }
.ctrl-readout {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}
.ctrl-range { width: 100%; accent-color: var(--blue); height: calc(1.1rem * var(--stroke-scale)); cursor: pointer; }
.ctrl-number { flex-direction: row; align-items: center; justify-content: space-between; gap: 0.5rem; }
.ctrl-numinput {
  font-family: inherit;
  font-size: 0.9rem;
  width: 5.5rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
}
.ctrl-toggle { flex-direction: row; align-items: center; gap: 0.5rem; cursor: pointer; }
.ctrl-checkbox { width: 1.1rem; height: 1.1rem; accent-color: var(--blue); cursor: pointer; }
.ctrl-toggle-label { font-size: 0.85rem; color: var(--label); font-weight: 600; }

/* ---------------------------------------------------------------- chart --- */

/* Render at the chart's designed (attribute) size; shrink to fit narrow
   containers but NEVER scale up — unbounded width:100% made charts (text
   included) grow until they filled a wide screen. */
svg.finchart { display: block; width: auto; max-width: 100%; height: auto; }
svg.finchart .grid { stroke: var(--grid); stroke-width: 1; }
svg.finchart .spine { stroke: var(--axis); stroke-width: calc(1.2px * var(--stroke-scale)); }
svg.finchart .tick { fill: var(--label); font-size: calc(12px * var(--stroke-scale)); font-family: var(--font-chart); }
svg.finchart .tick-x { text-anchor: middle; }
svg.finchart .tick-y { text-anchor: end; }
svg.finchart .axis-title {
  fill: var(--label);
  font-size: calc(13px * var(--stroke-scale));
  font-weight: 600;
  text-anchor: middle;
  font-family: var(--font-chart);
}
/* NB: no stroke-width rule for .series here — a stylesheet rule would
   override the per-path width chart.js sets (inline style, already scaled
   by --stroke-scale). */
svg.finchart .datalabel { font-size: calc(12px * var(--stroke-scale)); font-family: var(--font-chart); }
/* .halo (chart.text {halo:true} / LabelPlacer): white outline painted BEHIND
   the glyphs so a data label stays legible where a curve runs behind it. */
svg.finchart .datalabel.halo {
  paint-order: stroke fill;
  stroke: var(--card-bg);
  stroke-width: 0.3em; /* follows the label's font size (incl. --stroke-scale) */
  stroke-linejoin: round;
}
svg.finchart .marker { /* radius handled inline; scaled by --point-scale where used */ }

/* hover tooltip (overlay layer, built by tools) */
.chart-tooltip {
  fill: var(--navy);
  font-size: calc(11px * var(--stroke-scale));
  font-family: var(--font-chart);
}
.chart-tooltip-bg { fill: #fff; stroke: var(--panel-border); }

/* --------------------------------------------------------------- footer --- */

.app-footer {
  padding: 1rem 1.4rem;
  position: relative;
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
/* echo of the deck's footline: thin gold progress bar on a softblue track */
.app-footer::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(to right, var(--gold) 0 38%, var(--softblue) 38%);
}

/* two side-by-side chart columns inside a chart-area (e.g. σ–E[r] plane next
   to the utility-vs-y chart, or the frontier next to the tangency weights) */
.chart-row {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 1.1rem;
  align-items: start;
}
@media (max-width: 1150px) { .chart-row { grid-template-columns: 1fr; } }

/* --------------------------------------------------- landing (index) ------ */

.landing { max-width: 1500px; margin: 0 auto; padding: 1.75rem 1.4rem 3rem; }
/* unreleased tool (release gating — see releases.js) */
.tool-card.locked {
  opacity: 0.55;
  filter: grayscale(0.6);
  cursor: default;
  pointer-events: none;
}
.tool-card.locked .lecture-ref { color: var(--muted); }
.landing .lead { color: var(--muted); font-size: 1.02rem; margin: 0 0 1.5rem; }
.card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.1rem;
}
@media (max-width: 1150px) { .card-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .card-grid { grid-template-columns: 1fr; } }
.tool-card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--panel-border);
  border-top: 4px solid var(--goldmetal);
  border-radius: 10px;
  padding: 1.1rem 1.2rem 1.25rem;
  color: inherit;
  transition: box-shadow 0.15s, transform 0.15s;
}
.tool-card:hover { text-decoration: none; box-shadow: 0 6px 18px rgba(10, 35, 75, 0.12); transform: translateY(-2px); }
.tool-card h3 { margin: 0 0 0.35rem; color: var(--navy); font-family: var(--font-display); font-size: 1.18rem; }
.tool-card p { margin: 0 0 0.6rem; color: var(--muted); font-size: 0.9rem; }
.tool-card .lecture-ref {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--goldmetal);
  background: rgba(201, 151, 0, 0.1);
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --------------------------------------------------- responsive stacking -- */

@media (max-width: 900px) {
  .tool-main { flex-direction: column; }
  .controls-panel { flex: 1 1 auto; width: 100%; }
  .chart-area { width: 100%; }
}
