@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap");

/*
  app.css - the Lecture Hall design system
  --------------------------------------------
  ONE source of truth for every colour, type and spacing decision on the
  site. Simulations must not carry inline <style> blocks and must not use
  hex literals - if a simulation needs a colour it does not have, add a
  token here rather than a literal there. That rule is the whole point of
  this file: the system used to exist in eleven copies.

  Structure
    1. Primitives (--p-*)   raw palette. THE ONLY THING THAT CHANGES BETWEEN
                            THEMES. Never referenced by components directly.
    2. Semantics            surfaces / text / lines, built from primitives.
    3. Canvas (--c-*)       every colour a <canvas> may need. Mirrored by
                            CANVAS_TOKENS in theme.js and read at draw time
                            via PhysSim.palette(). Adding one means adding it
                            in both places.
    4. Legacy aliases       the --color-* names the content pages already
                            use. Kept so those pages inherit theming for
                            free; they resolve lazily, so they need
                            defining only once.
    5. Base + components

  Theming: dark is the default identity and is defined on bare :root, so the
  site is correct even with JavaScript disabled. theme.js stamps
  data-theme="light" when the viewer opts in. (To follow the OS instead, add
  a @media (prefers-color-scheme: light) block repeating the light
  primitives - nothing else would need to change.)
*/

:root {
  /* --- 1. primitives - dark ------------------------------------- */
  --p-ground:    #0e1117;
  --p-surface:   #161b23;
  --p-surface-2: #1d232d;
  --p-sunken:    #0a0d12;
  --p-line:      #2a323e;
  --p-line-2:    #3a4553;
  --p-ink:       #eef2f7;
  --p-ink-2:     #9aa7b8;
  --p-ink-3:     #63707f;
  --p-grid:      #1b222c;
  --p-axis:      #4e5c6c;

  --p-cyan:      #3ad8ff;
  --p-cyan-2:    #1d6d85;
  --p-on-cyan:   #04121a;
  --p-amber:     #ffc14d;
  --p-pink:      #ff5c8a;
  --p-lime:      #8ce86a;
  --p-violet:    #a98bff;
  --p-rust:      #ff8a5b;
  --p-contrast:  #ffffff;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .34);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .40);
  --shadow-lg: 0 14px 38px rgba(0, 0, 0, .52);

  /* --- 2. semantics --------------------------------------------- */
  --bg:          var(--p-ground);
  --surface:     var(--p-surface);
  --surface-2:   var(--p-surface-2);
  --sunken:      var(--p-sunken);
  --line:        var(--p-line);
  --line-strong: var(--p-line-2);
  --fg:          var(--p-ink);
  --fg-2:        var(--p-ink-2);
  --fg-3:        var(--p-ink-3);
  --accent:      var(--p-cyan);
  --accent-ink:  var(--p-on-cyan);
  --accent-wash: color-mix(in srgb, var(--p-cyan) 14%, transparent);
  --ok:          var(--p-lime);
  --warn:        var(--p-amber);
  --danger:      var(--p-pink);

  /* --- 3. canvas tokens - mirrored in theme.js CANVAS_TOKENS ----- */
  --c-bg:        var(--p-sunken);    /* the drawing ground            */
  --c-panel:     var(--p-surface-2); /* inset panels inside a canvas  */
  --c-grid:      var(--p-grid);
  --c-line:      var(--p-line);
  --c-axis:      var(--p-axis);      /* axes, ground, container walls */
  --c-fg:        var(--p-ink);       /* labels on canvas              */
  --c-fg-dim:    var(--p-ink-2);
  --c-fg-mute:   var(--p-ink-3);

  --c-object:    var(--p-amber);     /* the body under study          */
  --c-trace:     var(--p-cyan);      /* path history / trajectory     */
  --c-marker:    var(--p-lime);      /* apex, nodes, points of note   */
  --c-vec-x:     var(--p-violet);    /* horizontal component - ALWAYS */
  --c-vec-y:     var(--p-pink);      /* vertical component   - ALWAYS */
  --c-resultant: var(--p-contrast);  /* the resultant vector          */
  --c-accel:     var(--p-rust);      /* acceleration / applied force  */
  --c-input:     var(--p-cyan);      /* you-can-drag-this handles     */
  --c-wave:      var(--p-cyan);      /* primary wave / ray / field    */
  --c-wave-2:    var(--p-violet);    /* reflected / refracted / 2nd   */
  --c-energy-k:  var(--p-cyan);      /* kinetic                       */
  --c-energy-p:  var(--p-amber);     /* potential                     */
  --c-energy-t:  var(--p-rust);      /* thermal / dissipated          */
  --c-danger:    var(--p-pink);      /* TIR, overload, failure        */

  /* --- 4. legacy aliases (content pages) ------------------------ */
  --color-bg:            var(--bg);
  --color-surface:       var(--surface);
  --color-text:          var(--fg);
  --color-accent:        var(--accent);
  --color-accent-2:      var(--p-pink);
  --color-divider:       var(--line);
  --color-neutral-100:   var(--surface-2);
  --color-neutral-800:   var(--fg-2);
  --color-accent-100:    var(--accent-wash);
  --color-accent-600:    color-mix(in srgb, var(--accent) 82%, var(--bg));
  --color-accent-700:    color-mix(in srgb, var(--accent) 64%, var(--bg));
  --color-accent-800:    var(--accent);
  --color-accent-2-100:  color-mix(in srgb, var(--p-pink) 14%, transparent);
  --color-accent-2-800:  var(--p-pink);
  --color-embed-bg:      var(--sunken);
  --color-embed-panel:   var(--surface);
  --color-embed-line:    var(--line);

  /* --- type, space, radius -------------------------------------- */
  --font-heading: "Inter", system-ui, -apple-system, sans-serif;
  --font-body:    "Inter", system-ui, -apple-system, sans-serif;
  --font-mono:    "JetBrains Mono", ui-monospace, Menlo, monospace;
  --font-heading-weight: 600;

  --space-1: 5px;  --space-2: 10px; --space-3: 15px;
  --space-4: 20px; --space-6: 30px; --space-8: 40px;
  --radius-sm: 7px; --radius-md: 10px; --radius-lg: 14px;
}

/* --- 1b. primitives - light. The ONLY per-theme block. ---------- */
:root[data-theme="light"] {
  --p-ground:    #f3f5f9;
  --p-surface:   #ffffff;
  --p-surface-2: #f7f9fc;
  --p-sunken:    #ffffff;
  --p-line:      #dee3ec;
  --p-line-2:    #c6cedb;
  --p-ink:       #101620;
  --p-ink-2:     #4f5c70;
  --p-ink-3:     #7d8899;
  --p-grid:      #e9edf4;
  --p-axis:      #8e9bad;

  --p-cyan:      #0a7d9c;
  --p-cyan-2:    #6fc0d5;
  --p-on-cyan:   #ffffff;
  --p-amber:     #a06a00;
  --p-pink:      #c62753;
  --p-lime:      #2c8a3d;
  --p-violet:    #6b4fbb;
  --p-rust:      #c2410c;
  --p-contrast:  #101620;

  --shadow-sm: 0 1px 2px rgba(16, 22, 32, .10);
  --shadow-md: 0 4px 14px rgba(16, 22, 32, .10);
  --shadow-lg: 0 14px 38px rgba(16, 22, 32, .14);
}

/* --- 5. base ---------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  line-height: 1.15;
  letter-spacing: -0.018em;
  text-wrap: balance;
  margin: 0 0 var(--space-2);
}
p { margin: 0 0 var(--space-3); }
a { color: var(--accent); text-underline-offset: 3px; }
img { display: block; max-width: 100%; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: var(--sunken); }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 6px; }

/* Every readout that animates. Stops digits jittering on a projector. */
.num, .tile-value, .readout, td.num { font-variant-numeric: tabular-nums; }

svg[data-ic] {
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  display: inline-block; flex: none; vertical-align: middle;
}

.eyebrow {
  font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  letter-spacing: 0.15em; text-transform: uppercase; color: var(--fg-3);
}

/* --- buttons ---------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  cursor: pointer; text-decoration: none;
  font-family: var(--font-body); font-weight: 600; font-size: 13.5px;
  line-height: 1.2; color: var(--fg-2);
  background: var(--surface-2); border: 1px solid var(--line-strong);
  padding: 0 14px; height: 36px; border-radius: var(--radius-md);
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.btn:hover { color: var(--fg); border-color: var(--fg-3); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { display: block; width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 86%, var(--p-contrast)); color: var(--accent-ink); }
.btn-secondary { background: transparent; }
.btn-icon { width: 36px; padding: 0; }
.btn-block { width: 100%; }

/* --- theme + language switches ---------------------------------- */
.theme-switch {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  height: 34px; padding: 0 12px; border-radius: var(--radius-md);
  background: var(--surface-2); border: 1px solid var(--line-strong);
  color: var(--fg-2); font-family: var(--font-body);
  font-size: 13px; font-weight: 500;
}
.theme-switch:hover { color: var(--fg); }
.theme-switch svg { display: block; }

.lang-switch {
  display: inline-flex; gap: 3px; padding: 3px;
  background: var(--sunken); border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.lang-switch-btn {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  letter-spacing: 0.04em; padding: 5px 9px; border: 0;
  border-radius: var(--radius-sm); background: transparent;
  color: var(--fg-3); cursor: pointer;
}
.lang-switch-btn:hover { color: var(--fg); }
.lang-switch-btn.active { background: var(--surface-2); color: var(--fg); }

/* --- cards + panels --------------------------------------------- */
.card {
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-3); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.card-kicker { font-family: var(--font-mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--fg-3); }
.card-title { font-family: var(--font-heading); font-weight: 600; font-size: 17px; line-height: 1.2; }
.card-body { margin: 0; font-size: 13.5px; color: var(--fg-2); flex: 1; }
.elev-sm { box-shadow: var(--shadow-sm); }
.elev-md { box-shadow: var(--shadow-md); }
.elev-lg { box-shadow: var(--shadow-lg); }

/* --- tags + chips ----------------------------------------------- */
.tag {
  display: inline-flex; align-items: center; font-size: 11px;
  font-weight: 600; letter-spacing: .02em;
  padding: 3px 10px; border-radius: var(--radius-sm);
}
.tag-accent   { background: var(--accent-wash); color: var(--accent); }
.tag-accent-2 { background: var(--color-accent-2-100); color: var(--color-accent-2-800); }
.tag-neutral  { background: var(--surface-2); color: var(--fg-2); }

.chip {
  font-size: 12.5px; font-weight: 600; padding: 7px 11px; cursor: pointer;
  border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid var(--line-strong); color: var(--fg-2);
}
.chip:hover { color: var(--fg); }
.chip.active { background: var(--accent-wash); border-color: var(--accent); color: var(--accent); }

/* --- fields + native range slider ------------------------------- */
.field { display: block; }
.field-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.field-row label { font-size: 13.5px; font-weight: 500; color: var(--fg-2); }
.field-row .value { font-family: var(--font-mono); font-size: 14px; font-weight: 700; color: var(--fg); font-variant-numeric: tabular-nums; }

.input {
  min-height: 36px; padding: 6px 10px; font: inherit; font-size: 14px;
  color: var(--fg); caret-color: var(--accent); background: var(--sunken);
  border: 1px solid var(--line-strong); border-radius: var(--radius-md);
}
.input::placeholder { color: var(--fg-3); opacity: 1; }
.input:hover { border-color: var(--fg-3); }
.input:focus-visible { border-color: var(--accent); outline-offset: 0; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 8px; margin: 6px 0; padding: 0;
  background: var(--sunken); border: 1px solid var(--line);
  border-radius: 5px; outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--fg); border: 3px solid var(--accent);
  box-shadow: var(--shadow-sm); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; box-sizing: border-box;
  background: var(--fg); border: 3px solid var(--accent);
  box-shadow: var(--shadow-sm); cursor: pointer;
}
input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="range"]:disabled { opacity: .45; cursor: not-allowed; }

/* --- toggle rows -------------------------------------------------
   A switch carries the colour of the thing it controls, passed in as
   --sw-color, so a legend and its curve always agree. */
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.toggle-row + .toggle-row { border-top: 1px solid var(--line); }
.toggle-label { display: flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--fg-2); }
.switch {
  --sw-color: var(--accent);
  position: relative; flex: none; width: 38px; height: 22px; cursor: pointer;
  background: var(--sunken); border: 1px solid var(--line-strong); border-radius: 99px;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: var(--fg-3);
  transition: left .16s ease, background .16s ease;
}
.switch.on { background: color-mix(in srgb, var(--sw-color) 22%, transparent); border-color: var(--sw-color); }
.switch.on::after { left: 18px; background: var(--sw-color); }
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- simulation stage + heads-up readouts ----------------------- */
.stage {
  position: relative; display: block; min-height: 0; padding: 0;
  background: var(--c-bg); border: 1px solid var(--line);
  border-radius: var(--radius-lg); overflow: hidden;
}
/* The canvas is absolutely positioned and given an explicit size. A canvas
   is a replaced element, so `width: auto` resolves to its intrinsic 300x150
   rather than to the insets, and a percentage height collapses to zero
   whenever an ancestor lacks a definite height. Both fail silently and look
   like a drawing bug, so pin all four sides AND state the size. */
.stage canvas {
  position: absolute; inset: 0;
  display: block; width: 100%; height: 100%; touch-action: none;
}

.tiles { position: absolute; left: 18px; top: 18px; display: flex; gap: 10px; }
.tile {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--line-strong); border-radius: var(--radius-md);
  padding: 9px 14px; min-width: 104px;
}
.tile-key { font-family: var(--font-mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-3); }
.tile-value {
  font-family: var(--font-mono); font-size: 26px; font-weight: 700;
  line-height: 1.15; letter-spacing: -.02em; color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.tile-value .unit { font-size: 12px; color: var(--fg-3); font-weight: 500; margin-left: 3px; }

/* --- transport dock --------------------------------------------- */
.dock {
  display: flex; align-items: center; gap: 14px; flex: none;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 11px 14px;
}
.transport-btn {
  width: 46px; height: 46px; flex: none; cursor: pointer;
  border-radius: 12px; background: var(--surface-2);
  border: 1px solid var(--line-strong); color: var(--fg-2);
  display: grid; place-items: center;
}
.transport-btn:hover { color: var(--fg); border-color: var(--fg-3); }
.transport-btn svg { display: block; width: 20px; height: 20px; }
.transport-btn.play { width: 60px; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.scrub { flex: 1; display: flex; flex-direction: column; gap: 7px; }
.scrub-ticks {
  display: flex; justify-content: space-between;
  font-family: var(--font-mono); font-size: 10.5px; color: var(--fg-3);
  font-variant-numeric: tabular-nums;
}

.segmented { display: flex; background: var(--sunken); border: 1px solid var(--line); border-radius: var(--radius-md); padding: 3px; }
.segmented button {
  padding: 7px 11px; border: 0; border-radius: var(--radius-sm); cursor: pointer;
  background: transparent; font-family: var(--font-mono); font-size: 12px;
  font-weight: 600; color: var(--fg-3);
}
.segmented button:hover { color: var(--fg); }
.segmented button.active { background: var(--surface-2); color: var(--fg); }

/* --- data table -------------------------------------------------- */
.readout { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 12.5px; }
.readout th {
  text-align: left; font-size: 10px; font-weight: 500; letter-spacing: .12em;
  text-transform: uppercase; color: var(--fg-3);
  padding-bottom: 9px; border-bottom: 1px solid var(--line);
}
.readout td { padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--fg-2); }
.readout tr:last-child td { border-bottom: 0; }
.readout td.num { text-align: right; color: var(--fg); font-weight: 700; font-variant-numeric: tabular-nums; }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 8px; vertical-align: 1px; }

/* --- present mode -------------------------------------------------
   The state a teacher puts a simulation into before turning to the class:
   site chrome gone, readouts and controls at projector size. All of it is
   CSS keyed off data-present on <html>; assets/js/present.js owns only the
   state and the fullscreen call.

   The masthead is slimmed rather than removed, because in some sims it
   carries the scenario tabs — and because a chromeless page needs a visible
   way back. */
.present-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
.present-label { display: none; }

:root[data-present] .app-head { height: 44px; }
:root[data-present] .brand,
:root[data-present] .crumb,
:root[data-present] .instrument-id { display: none; }

:root[data-present] .app-body { padding: 10px; gap: 10px; }
:root[data-present] .col-main { gap: 10px; }

/* Readouts are the point of present mode: they must carry to the back row. */
:root[data-present] .tile { min-width: 130px; padding: 11px 18px; }
:root[data-present] .tile-key { font-size: 12px; letter-spacing: .16em; }
:root[data-present] .tile-value { font-size: 46px; }
:root[data-present] .tile-value .unit { font-size: 18px; margin-left: 5px; }
:root[data-present] .tiles { gap: 12px; left: 22px; top: 22px; }

/* Prose the class cannot read from a projector is dropped; the claim stays. */
:root[data-present] .dock-hint,
:root[data-present] .claim-sub,
:root[data-present] .note { display: none; }
:root[data-present] .claim { font-size: 19px; }

/* Bigger hit targets for someone standing at a laptop mid-sentence. */
:root[data-present] .dock { padding: 13px 16px; gap: 16px; }
:root[data-present] .transport-btn { width: 58px; height: 58px; border-radius: 15px; }
:root[data-present] .transport-btn.play { width: 76px; }
:root[data-present] .transport-btn svg { width: 26px; height: 26px; }

:root[data-present] .field-row label { font-size: 15px; }
:root[data-present] .field-row .value { font-size: 16px; }
:root[data-present] input[type="range"] { height: 12px; }
:root[data-present] input[type="range"]::-webkit-slider-thumb { width: 26px; height: 26px; }
:root[data-present] input[type="range"]::-moz-range-thumb { width: 26px; height: 26px; }
:root[data-present] .chip { font-size: 14px; padding: 9px 14px; }

/* The exit control has to be findable without hunting. */
:root[data-present] .fs-btn {
  width: auto; height: 40px; padding: 0 14px;
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
  font-family: var(--font-body); font-size: 13.5px; font-weight: 700;
}
:root[data-present] .present-label { display: inline; }

/* --- card thumbnails ---------------------------------------------
   The little 280x120 SVGs in sims-data.js. Their colours are classes
   rather than attributes so they retheme with the page and need no
   re-render — an SVG presentation attribute cannot hold a var(). */
.tf-bg     { fill: var(--c-bg); }
.tf-obj    { fill: var(--c-object); }
.tf-trace  { fill: var(--c-trace); }
.tf-marker { fill: var(--c-marker); }
.tf-accel  { fill: var(--c-accel); }
.tf-mute   { fill: var(--c-fg-mute); }
.ts-obj    { stroke: var(--c-object); }
.ts-trace  { stroke: var(--c-trace); }
.ts-marker { stroke: var(--c-marker); }
.ts-accel  { stroke: var(--c-accel); }
.ts-mute   { stroke: var(--c-fg-mute); }
.ts-axis   { stroke: var(--c-axis); }
.ts-grid   { stroke: var(--c-grid); }

/* --- embedded simulation frame ----------------------------------- */
.embed-frame {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 4px; overflow: hidden;
}
.embed-frame iframe {
  display: block; width: 100%; height: 900px; border: 0;
  border-radius: var(--radius-md); background: var(--c-bg);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
