/* Microvis: the shared look of the start page and all tools.
   Minimal: Helvetica/Arial, square corners, hairlines instead of shadows, black and white with one blue (--brand)
   for what you can click or move. The economics colours (--accent*, --l2-*) are those of the notes' figures. */

/* ---------- colours and type ---------- */

:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --ink: #111318;
  --muted: #5d6370;
  --line: #e1e3e8;
  --grid: #eceef2;
  --brand: #1d5bd8;
  --on-accent: #ffffff;
  --accent: #2361a3;      /* isoquants, substitution */
  --accent-soft: rgba(35, 97, 163, 0.12);
  --accent-2: #c4561b;    /* rays, scale */
  --accent-2-soft: rgba(196, 86, 27, 0.12);
  --accent-3: #2b8452;    /* tangents, highlights */
  --accent-4: #8b3fb8;    /* second point z' */
  /* lecture 2 figures: Step 1 (CM) blue, Step 2 (PM') red, supply orange, isocost grey */
  --l2-blue: #4a90e2;
  --l2-red: #d0021b;
  --l2-orange: #f5a623;
  --l2-grey: #9b9b9b;
  --l2-profit: rgba(43, 132, 82, 0.22);
  --dec: #b4462b;
  --const: #4b5563;
  --inc: #2b8452;
  --radius: 0px;
  --font: "Helvetica Neue", Helvetica, Arial, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f12;
    --panel: #14171c;
    --ink: #e9ecf1;
    --muted: #9aa1ad;
    --line: #272b33;
    --grid: #20242b;
    --brand: #7aa7ff;
    --on-accent: #0d0f12;
    --accent: #6fa8e6;
    --accent-soft: rgba(111, 168, 230, 0.16);
    --accent-2: #f0894b;
    --accent-2-soft: rgba(240, 137, 75, 0.16);
    --accent-3: #5cc08a;
    --accent-4: #c58af0;
    --l2-red: #ff4d5e;
    --l2-profit: rgba(92, 192, 138, 0.25);
    --dec: #f08a6c;
    --const: #b7beca;
    --inc: #5cc08a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d0f12;
  --panel: #14171c;
  --ink: #e9ecf1;
  --muted: #9aa1ad;
  --line: #272b33;
  --grid: #20242b;
  --brand: #7aa7ff;
  --on-accent: #0d0f12;
  --accent: #6fa8e6;
  --accent-soft: rgba(111, 168, 230, 0.16);
  --accent-2: #f0894b;
  --accent-2-soft: rgba(240, 137, 75, 0.16);
  --accent-3: #5cc08a;
  --accent-4: #c58af0;
  --l2-red: #ff4d5e;
  --l2-profit: rgba(92, 192, 138, 0.25);
  --dec: #f08a6c;
  --const: #b7beca;
  --inc: #5cc08a;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }

h1, h2, h3 { line-height: 1.25; margin: 0; }

[hidden] { display: none !important; }

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

.site-header {
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px 16px 18px;
}
.site-header > div { min-width: 0; max-width: 100%; }
.eyebrow { margin: 0 0 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.eyebrow a { color: var(--ink); font-weight: 700; text-decoration: none; }
.eyebrow a:hover { color: var(--brand); }
.eyebrow .sep { margin: 0 4px; opacity: 0.6; }
.site-header h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
/* Header formulas: each piece stays on one line, pieces wrap on a narrow screen, and there is room above
   and below for tall fractions, so no scrollbar appears unless a single piece is wider than the screen. */
.subtitle {
  max-width: 100%;
  margin: 6px 0 0;
  padding: 5px 0 8px;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.9;
  color: var(--ink);
}
.subtitle .katex, .subtitle .katex-html { white-space: nowrap; }
.subtitle .tex-piece { display: inline-block; margin-right: 2.2em; }
.subtitle .tex-piece:last-child { margin-right: 0; }

main { max-width: 1600px; margin: 0 auto; padding: 0 16px 32px; }

.status-banner {
  max-width: 1600px;
  margin: 0 auto 14px;
  padding: 10px 16px;
  border: 1px solid var(--dec);
  color: var(--dec);
  background: var(--panel);
  font-size: 14px;
}
.status-banner p { margin: 0; }
.status-banner p + p { margin-top: 4px; }
@media (max-width: 1632px) { .status-banner { margin-left: 16px; margin-right: 16px; } }

/* ---------- panels ---------- */

.panel {
  min-width: 0;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.panel > h2, .panel-head h2 { font-size: 15px; font-weight: 700; letter-spacing: -0.005em; }
.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.caption { margin: 8px 0 0; font-size: 13px; line-height: 1.55; color: var(--muted); }
.note { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.warn { margin: 6px 0 0; font-size: 13px; color: var(--dec); }

/* colour keys in captions: a short line, a dashed line or a dot in the colour of the curve */
.key { display: inline-block; width: 18px; height: 0; border-top: 3px solid currentColor; vertical-align: middle; margin-right: 3px; }
.key.dash { border-top-style: dashed; }
.key.dot { width: 9px; height: 9px; border: 0; border-radius: 50%; background: currentColor; }
.c-accent { color: var(--accent); }
.c-accent-2 { color: var(--accent-2); }
.c-accent-3 { color: var(--accent-3); }
.c-accent-4 { color: var(--accent-4); }
.c-muted { color: var(--muted); }
.c-ink { color: var(--ink); }
.c-l2-blue { color: var(--l2-blue); }
.c-l2-red { color: var(--l2-red); }
.c-l2-orange { color: var(--l2-orange); }
.c-l2-grey { color: var(--l2-grey); }

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

.group { padding: 14px 0; border-top: 1px solid var(--line); }
.group:first-child { border-top: 0; padding-top: 0; }
.group:last-child { padding-bottom: 0; }
.group > h2 {
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

select, input[type="number"], button { font: inherit; color: var(--ink); }

select {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
}

.ctrl { margin: 10px 0; }
.ctrl-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
  font-size: 14px;
}
.ctrl-label .hint { color: var(--muted); font-size: 12px; text-align: right; }
.ctrl-row { display: flex; align-items: center; gap: 10px; }
.ctrl-row input[type="range"] { flex: 1; min-width: 0; }
input[type="number"] {
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  text-align: right;
}
.ctrl-row input[type="number"] { width: 72px; flex: none; }

input[type="range"] { accent-color: var(--brand); height: 24px; margin: 0; }
input[type="checkbox"] { accent-color: var(--brand); width: 16px; height: 16px; margin: 0; }

.check { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 14px; cursor: pointer; }

/* segmented switch: black when chosen */
.seg { display: flex; border: 1px solid var(--ink); }
.seg button {
  flex: 1;
  padding: 8px 6px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--panel); }

/* small buttons: presets, pins, cameras */
.btn-row { display: flex; flex-wrap: wrap; gap: 4px; }
.btn-row button, .go-row button {
  padding: 4px 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.go-row button { padding: 4px 12px; }
.btn-row button:hover, .go-row button:hover, .seg button:hover:not([aria-pressed="true"]) { border-color: var(--ink); }
.btn-row button[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--panel); font-weight: 600; }

button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.go-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0; font-size: 14px; }
.go-row input[type="number"] { width: 64px; }
.notes-form { color: var(--muted); }

.pair-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 8px 0; font-size: 14px; }
.pair-row input[type="number"] { width: 70px; }
.pair-row .who { min-width: 22px; font-weight: 700; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid currentColor;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge.decreasing { color: var(--dec); }
.badge.constant { color: var(--const); }
.badge.increasing { color: var(--inc); }

.formula { padding: 4px 0; overflow: hidden; font-size: 14px; }
.formula .katex-display { margin: 4px 0; }

/* set by shared/ui.js when a formula box really is too wide: then, and only then, it scrolls */
.scrolls { overflow-x: auto !important; }

/* "How to read this": the idea in a sentence or two, then a few things to try */
details.howto { font-size: 14px; }
details.howto summary { cursor: pointer; font-weight: 700; }
details.howto p { margin: 8px 0 0; }
details.howto ul { margin: 8px 0 0; padding-left: 18px; }
details.howto li { margin: 4px 0 0; }
details.howto li::marker { color: var(--muted); }

details.sub-details { margin-top: 10px; font-size: 14px; }
details.sub-details summary { cursor: pointer; color: var(--muted); font-weight: 600; }

/* ---------- readouts ---------- */

.readouts dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin: 8px 0 0;
  font-size: 14px;
}
.readouts dt { color: var(--muted); }
.readouts dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.readouts .sentence { margin: 10px 0 0; font-size: 14px; }

.status-line { margin: 6px 0 0; font-size: 13px; font-weight: 600; min-height: 2.6em; }
.status-line.low { color: var(--l2-red); }
.status-line.min { color: var(--l2-blue); }
.status-line.high { color: var(--muted); }
.ok-mark { color: var(--inc); font-weight: 700; }
.no-mark { color: var(--dec); font-weight: 700; }

.checks { list-style: none; margin: 8px 0 0; padding: 0; font-size: 14px; }
.checks li { display: grid; grid-template-columns: 22px 1fr; gap: 2px 6px; padding: 7px 0; border-top: 1px solid var(--line); }
.checks li:first-child { border-top: 0; }
.checks .mark { font-weight: 700; text-align: center; }
.checks .ok { color: var(--inc); }
.checks .no { color: var(--dec); }
.checks .na { color: var(--muted); }
.checks .def { grid-column: 2; color: var(--muted); font-size: 13px; }

table.data { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 5px 4px; text-align: right; border: 1px solid var(--line); }
table.data th { color: var(--muted); font-weight: 600; background: var(--bg); }
table.data td { cursor: pointer; }
table.data td:hover { outline: 2px solid var(--accent); outline-offset: -2px; }
table.data td.sel { outline: 3px solid var(--accent-2); outline-offset: -3px; font-weight: 700; }

/* ---------- tool layout: controls | main plot | side panels ---------- */

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) minmax(0, 400px);
  grid-template-areas: "controls main side";
  gap: 14px;
  align-items: start;
}
.layout > .controls { grid-area: controls; }
.layout > .plot3d-panel, .layout > .main-panel { grid-area: main; }
.layout > .side { grid-area: side; display: grid; gap: 14px; min-width: 0; }

.plot { width: 100%; }
.plot-3d { height: 640px; }
.plot-2d { height: 320px; }
.plot-main { height: 620px; touch-action: none; cursor: crosshair; }

@media (max-width: 1250px) {
  .layout {
    grid-template-columns: 300px minmax(0, 1fr);
    grid-template-areas: "controls main" "side side";
  }
  .layout > .side { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
}

@media (max-width: 800px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "controls" "main" "side";
  }
  .plot-3d { height: 440px; }
  .plot-2d { height: 300px; }
  .plot-main { height: 400px; }
  .site-header h1 { font-size: 23px; }
}

/* ---------- previous / next tool, footer ---------- */

.pager {
  max-width: 1568px;
  margin: 8px auto 0;
  padding: 14px 0 0;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 14px;
}
@media (max-width: 1600px) { .pager { margin-left: 16px; margin-right: 16px; } }
.pager a { color: var(--ink); text-decoration: none; font-weight: 700; font-size: 15px; }
.pager .next { text-align: right; }
.pager a span { display: block; margin-bottom: 2px; font-size: 12px; font-weight: 500; color: var(--muted); }
.pager .prev span::before { content: "\2190  "; }
.pager .next span::after { content: "  \2192"; }
.pager .all { padding-top: 16px; font-size: 13px; font-weight: 500; color: var(--muted); }
.pager a:hover, .pager a:hover span { color: var(--brand); }
@media (max-width: 640px) {
  .pager { grid-template-columns: 1fr 1fr; gap: 10px 14px; }
  .pager .all { grid-column: 1 / -1; grid-row: 2; padding-top: 0; }
}

.site-footer { max-width: 1600px; margin: 0 auto; padding: 18px 16px 28px; font-size: 13px; color: var(--muted); }

/* ---------- start page ---------- */

.home .site-header, .home main, .home .site-footer { max-width: 1240px; }
.home .site-header { padding-top: 48px; padding-bottom: 8px; }
.home .site-header h1 { font-size: 40px; letter-spacing: -0.03em; }
.lead { max-width: 640px; margin: 10px 0 0; font-size: 18px; line-height: 1.45; color: var(--muted); }
.wip { max-width: 640px; margin: 14px 0 26px; padding: 9px 12px; border: 1px solid var(--line); background: var(--panel); font-size: 13.5px; color: var(--muted); }
.wip b { color: var(--ink); }
.lecture-nav { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.lecture-nav a { padding: 2px 0; font-size: 13.5px; font-weight: 500; color: var(--ink); text-decoration: none; border-bottom: 1px solid transparent; white-space: nowrap; }
.lecture-nav a:hover { color: var(--brand); border-bottom-color: var(--brand); }
.lecture-nav a b { margin-right: 4px; color: var(--muted); font-weight: 500; }

.lecture { margin-top: 40px; scroll-margin-top: 16px; }
.lecture-title { margin-bottom: 14px; font-size: 20px; font-weight: 700; letter-spacing: -0.015em; }
.lecture-no { display: block; margin-bottom: 3px; font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

/* the tiles: one grid, cells separated by hairlines; an incomplete last row leaves the empty cells blank */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.card {
  position: relative;
  display: block;
  padding: 20px 20px 22px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  color: inherit;
  text-decoration: none;
  transition: background-color 0.12s;
}
.card:hover { background: var(--bg); }
.card .glyph { display: block; width: 64px; height: 64px; margin: 0 0 14px -4px; color: var(--ink); }
.card .glyph .a { stroke: var(--brand); }
.card .glyph .af { fill: var(--brand); }
.card h3 { margin-bottom: 6px; font-size: 16.5px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }
.card:hover h3 { color: var(--brand); }
.card .star { margin-right: 3px; color: var(--muted); }
.card p { margin: 0; font-size: 14px; line-height: 1.5; color: var(--muted); }

/* where you can hover: a preview of the tool covers the tile */
.card .preview { display: none; }
@media (hover: hover) and (pointer: fine) {
  .card .preview { display: block !important; position: absolute; inset: 0; z-index: 2; background: var(--panel); opacity: 0; pointer-events: none; transition: opacity 0.15s; }
  .card .preview img { width: 100%; height: 100%; object-fit: contain; padding: 8px; }
  .card:hover .preview, .card:focus-visible .preview { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .card .preview, .card { transition: none; } }

@media (max-width: 640px) {
  .home .site-header { padding-top: 28px; }
  .home .site-header h1 { font-size: 32px; }
  .lead { font-size: 16.5px; }
  .card { padding: 16px; }
  /* on a phone the drawing sits left of the text, so the list stays short */
  .card { display: grid; grid-template-columns: 56px 1fr; column-gap: 14px; }
  .card .glyph { grid-row: 1 / span 2; width: 56px; height: 56px; margin: 0; }
}

/* a switch in a panel heading stays small and on one line */
.panel-head .seg button { flex: none; padding: 4px 10px; font-size: 13px; white-space: nowrap; }

/* ---------- Econxvis: the colours of the regression figures in the handouts ----------
   Everything above is identical to shared/style.css of Microvis; keep it that way (copy it over when Microvis changes)
   and put Econxvis additions here. Slide "Geometry: It is a simple projection": y black, y_hat blue, residual / RSS red,
   mean green, deviation from the mean / TSS yellow, explained part / ESS purple. */

:root {
  --fig-y: #111318;
  --fig-yhat: #2f7fd8;
  --fig-resid: #d0021b;
  --fig-ybar: #2b8452;
  --fig-ebar: #e09a00;
  --fig-ess: #8b3fb8;
  --fig-plane: rgba(35, 97, 163, 0.10);
  --fig-plane-edge: #9aa1ad;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fig-y: #e9ecf1;
    --fig-yhat: #6fa8e6;
    --fig-resid: #ff4d5e;
    --fig-ybar: #5cc08a;
    --fig-ebar: #f5c542;
    --fig-ess: #c58af0;
    --fig-plane: rgba(111, 168, 230, 0.12);
    --fig-plane-edge: #5d6370;
  }
}
:root[data-theme="dark"] {
  --fig-y: #e9ecf1;
  --fig-yhat: #6fa8e6;
  --fig-resid: #ff4d5e;
  --fig-ybar: #5cc08a;
  --fig-ebar: #f5c542;
  --fig-ess: #c58af0;
  --fig-plane: rgba(111, 168, 230, 0.12);
  --fig-plane-edge: #5d6370;
}
.c-y { color: var(--fig-y); }
.c-yhat { color: var(--fig-yhat); }
.c-resid { color: var(--fig-resid); }
.c-ybar { color: var(--fig-ybar); }
.c-ebar { color: var(--fig-ebar); }
.c-ess { color: var(--fig-ess); }
