/* ===========================================================================
   Obedience ellipse — visual style
   A minimal, crisp, "paper figure" aesthetic in the spirit of Tufte and
   distill.pub: warm off-white ground, a framed white plot, restrained colour,
   a serif for prose/maths and a clean sans for the controls.
   =========================================================================== */

:root {
  /* Ground & ink */
  --paper:      #fbfaf7;   /* page ground (a hair warm) */
  --figure:     #ffffff;   /* the plot surface */
  --ink:        #1f2227;   /* primary text */
  --muted:      #6d7178;   /* secondary text, captions */
  --faint:      #9aa0a6;   /* axes, hairlines on the plot */
  --line:       #e7e3da;   /* UI hairlines */
  --track:      #e2ded4;   /* slider track */

  /* Accents (used sparingly, with consistent meaning) */
  --accent:     #2f6f9f;   /* the ellipse / primary */
  --accent-50:  rgba(47, 111, 159, 0.07);
  --accent-soft:#eef4f8;
  --red:        #c0503e;   /* not-IC region & no-transfer chord */
  --green:      #2f7d5f;   /* stationarity curve & firms-optimal F */
  --rev:        #c77f2a;   /* revenue stationarity curve & revenue-optimal R */

  --serif: "Spectral", Georgia, "Times New Roman", serif;
  --sans:  "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius: 7px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main {
  display: flex;
  height: 100vh;
}

/* ----- plot ---------------------------------------------------------------- */
#plot-panel {
  flex: 1 1 auto;
  min-width: 0;
  padding: 28px;
  background: var(--paper);
}

#plot {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--figure);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(31, 34, 39, 0.04),
              0 8px 24px rgba(31, 34, 39, 0.05);
  cursor: grab;
  touch-action: none; /* let pointer drag pan instead of scrolling */
}
#plot.grabbing { cursor: grabbing; }

/* Plot geometry. Axes are deliberately faint (high data-ink ratio). */
.axis        { stroke: var(--faint); stroke-width: 1; }
.ellipse     { fill: var(--accent-50); stroke: var(--accent); stroke-width: 1.6; }
.rect        { fill: none; stroke: var(--faint); stroke-width: 1; stroke-dasharray: 1 4; stroke-linecap: round; }
.no-transfer { stroke: var(--red); stroke-width: 3; stroke-linecap: round; }
.stationarity{ fill: none; stroke: var(--green); stroke-width: 2; }
.stationarity-rev { fill: none; stroke: var(--rev); stroke-width: 2; }

.point        { fill: var(--ink);   stroke: var(--figure); stroke-width: 1.5; }
.point.center { fill: var(--faint); stroke: none; }
.point.opt    { fill: var(--green); stroke: var(--figure); stroke-width: 1.5; }
.point.rev    { fill: var(--rev);   stroke: var(--figure); stroke-width: 1.5; }

/* SVG text labels: plain <text> nodes inside the plot, positioned and anchored
   in app.js (text-anchor / dominant-baseline). They are non-interactive so the
   drag/zoom gestures pass through to the SVG underneath. */
.axis-label, .point-label, .center-label {
  font-family: var(--serif);
  pointer-events: none;
  user-select: none;
}
.axis-label   { fill: var(--muted); font-size: 13px; font-style: italic; }
.point-label  { fill: var(--ink);   font-size: 15px; }
.center-label { fill: var(--faint); font-size: 12px; }
.opt-label    { fill: var(--green); font-style: italic; }
.rev-label    { fill: var(--rev);   font-style: italic; }

/* ----- controls panel ------------------------------------------------------ */
#controls {
  flex: 0 0 332px;
  padding: 32px 30px 36px;
  background: var(--figure);
  border-left: 1px solid var(--line);
  overflow-y: auto;
}

.panel-head { margin-bottom: 30px; }

.eyebrow {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
}

#controls h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 27px;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 0 0 12px;
}

.ref {
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
  margin: 0;
}
.ref em { font-style: italic; }
.ref code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ----- collapsible parameter section --------------------------------------- */
.params {
  margin-bottom: 8px;
}
.params > summary {
  display: flex;
  align-items: center;
  gap: 9px;
  list-style: none;          /* hide default disclosure marker */
  cursor: pointer;
  margin-bottom: 22px;
  user-select: none;
}
.params > summary::-webkit-details-marker { display: none; }
.params > summary .eyebrow { margin: 0; }
.params > summary::before {
  content: "";
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-right: 1.6px solid var(--accent);
  border-bottom: 1.6px solid var(--accent);
  transform: rotate(45deg);   /* points down when open */
  transition: transform .15s ease;
}
.params:not([open]) > summary::before { transform: rotate(-45deg); }
.params > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 3px;
}
.params > .control:last-child { margin-bottom: 0; }

/* ----- sliders ------------------------------------------------------------- */
.control { margin-bottom: 22px; }
.control label {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 10px;
  color: var(--ink);
}
.control label em { font-family: var(--serif); font-style: italic; font-weight: 400; }
.control .row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.control .slider { flex: 1 1 auto; min-width: 0; }
.control .num {
  flex: 0 0 62px;
  width: 62px;
  font-family: var(--sans);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--ink);
  padding: 5px 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.control .num:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-50);
}
.control small {
  display: block;
  margin-top: 9px;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}
.control small em { font-family: var(--serif); font-style: italic; }

/* Range input — custom, minimal: thin track + crisp ringed thumb. */
.slider {
  -webkit-appearance: none;
  appearance: none;
  height: 16px;
  background: transparent;
  cursor: pointer;
}
.slider::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 3px;
  background: var(--track);
}
.slider::-moz-range-track {
  height: 3px;
  border-radius: 3px;
  background: var(--track);
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2.5px solid var(--figure);
  box-shadow: 0 0 0 1px var(--accent), 0 1px 2px rgba(31,34,39,.2);
  transition: transform .12s ease;
}
.slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2.5px solid var(--figure);
  box-shadow: 0 0 0 1px var(--accent), 0 1px 2px rgba(31,34,39,.2);
  transition: transform .12s ease;
}
.slider:hover::-webkit-slider-thumb  { transform: scale(1.15); }
.slider:hover::-moz-range-thumb      { transform: scale(1.15); }
.slider:active::-webkit-slider-thumb { transform: scale(1.0); }
.slider:active::-moz-range-thumb     { transform: scale(1.0); }
.slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px var(--accent-50);
}
.slider:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px var(--accent-50);
}
.slider:focus { outline: none; }

/* ----- section headings (Legend / View) ----------------------------------- */
.legends, #readout { position: relative; }
h2.eyebrow {
  margin: 30px 0 14px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

/* ----- legend --------------------------------------------------------------
   Hanging marker: the swatch is absolutely positioned in a left gutter so the
   caption text (with its inline maths) flows and wraps as ordinary prose. */
.legend {
  position: relative;
  padding-left: 34px;
  margin: 0 0 14px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
}
.legend:last-child { margin-bottom: 0; }
.legend em { font-family: var(--serif); font-style: italic; }
.legend .swatch {
  position: absolute;
  left: 0;
  top: 3px;
  width: 22px;
  height: 14px;
  border-radius: 3px;
  border: 1.5px solid var(--red);
  background-image: repeating-linear-gradient(
    45deg, var(--red), var(--red) 1px, transparent 1px, transparent 5px);
}
.legend .swatch.ellipse {
  border: 1.6px solid var(--accent);
  border-radius: 7px / 5px;
  background-image: none;
  background-color: var(--accent-50);
}
.legend .swatch.line {
  height: 0;
  top: 9px;
  border: none;
  border-radius: 0;
  background: none;
  border-top: 3px solid var(--red);
}
.legend .swatch.curve {
  height: 0;
  top: 9px;
  border: none;
  border-radius: 0;
  background: none;
  border-top: 2px solid var(--green);
}
.legend .swatch.curve-rev {
  height: 0;
  top: 9px;
  border: none;
  border-radius: 0;
  background: none;
  border-top: 2px solid var(--rev);
}

/* ----- toggle switch (view fit) -------------------------------------------- */
.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  user-select: none;
}
.toggle input {
  position: absolute;       /* visually hidden but still focusable */
  width: 1px; height: 1px;
  opacity: 0;
  margin: 0;
}
.toggle .track {
  position: relative;
  flex: 0 0 auto;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--track);
  transition: background .15s ease;
}
.toggle .thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--figure);
  box-shadow: 0 1px 2px rgba(31, 34, 39, .25);
  transition: transform .15s ease;
}
/* Status icon inside the thumb: ✕ when off, ✓ when on. Decorative, so it is a
   pseudo-element (ignored by assistive tech). Icons are inline SVGs whose stroke
   colour matches the surrounding ink. */
.toggle .thumb::before {
  content: "";
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 9px 9px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236d7178' stroke-width='3.5' stroke-linecap='round'%3E%3Cpath d='M6 6 18 18M18 6 6 18'/%3E%3C/svg%3E");
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track .thumb { transform: translateX(16px); }
.toggle input:checked + .track .thumb::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232f6f9f' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5 10 17.5 19 7'/%3E%3C/svg%3E");
}
.toggle input:focus-visible + .track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.toggle .toggle-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
}

.hint {
  display: block;
  margin-top: 10px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* ----- readout ------------------------------------------------------------- */
#readout {
  margin-top: 30px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
#readout dt {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.04em;
  margin-bottom: 3px;
}
#readout dd {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--ink);
}
#readout dd:last-child { margin-bottom: 0; }

/* ----- download button ----------------------------------------------------- */
#download-svg {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 28px;
  padding: 11px 8px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  background: var(--figure);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: color .15s ease, background .15s ease, border-color .15s ease;
}
#download-svg:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}
#download-svg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ----- responsive: stack on narrow viewports ------------------------------- */
@media (max-width: 760px) {
  main { flex-direction: column; height: auto; min-height: 100vh; }
  #plot-panel { height: 62vh; padding: 16px 16px 0; }
  #controls {
    flex: 1 1 auto;
    border-left: none;
    border-top: 1px solid var(--line);
  }
}
