/* ── Reset & Tokens ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ── Background layers ── */
  --bg:        #0d1117;
  --surface:   #161b27;
  --surface2:  #1f2535;
  --border:    #2a3050;

  /* ── Accent — Steam Engine (polished brass) ── */
  --accent:    #d9a441;
  --accent-lo: rgba(217,164,65,.22);

  /* ── Semantic colours — DO NOT CHANGE ── */
  --green:     #3ddc84;
  --red:       #ff5555;
  --gold:      #f5c842;

  /* ── Typography ── */
  --text:      #dde3f0;
  --text-dim:  #6b7a99;
  --font:      'Segoe UI', system-ui, sans-serif;
  --mono:      'Courier New', monospace;

  /* ── Layout ── */
  --radius:    12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  padding: 0 16px;
}

#app { max-width: 1060px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* ── Header ─── */
header { text-align: center; padding: 4px 0; }
header h1 {
  font-size: 1.8rem; font-weight: 700;
  background: linear-gradient(120deg, #e53935 0%, #ff7043 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.subtitle { color: var(--text-dim); font-size: 0.85rem; margin-top: 3px; }

/* ── Controls bar ─── */
.controls-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.ctrl-group  { display: flex; align-items: center; gap: 8px; }
.ctrl-label  { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); white-space: nowrap; }
.ctrl-value  { font-size: 0.82rem; color: var(--accent); font-weight: 600; min-width: 40px; }

/* ── Pill tabs ─── */
.pill-tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 2px; }
.pill {
  padding: 5px 13px; border: none; background: transparent; color: var(--text-dim);
  border-radius: 6px; cursor: pointer; font-size: 0.81rem;
  transition: background .18s, color .18s, box-shadow .18s;
}
.pill.active { background: var(--accent); color: #fff; box-shadow: 0 0 12px var(--accent-lo); }
.pill:hover:not(.active) { background: var(--surface2); color: var(--text); }

/* ── Buttons ─── */
.btn { padding: 8px 18px; border: none; border-radius: 8px; cursor: pointer; font-size: 0.84rem; font-weight: 600; transition: filter .18s, box-shadow .18s, opacity .18s; }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { filter: brightness(1.12); box-shadow: 0 0 12px var(--accent-lo); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }

/* ── Sliders ─── */
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 120px; height: 6px;
  background: var(--surface2); border-radius: 3px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  box-shadow: 0 0 6px var(--accent-lo);
}

/* ── Canvas card ─── */
.canvas-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px;
  overflow-x: clip;
}
.canvas-card canvas { display: block; width: 100%; height: auto; touch-action: pan-y; }

/* ── Readout panel ─── */
.readout-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}
.readout-cell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.readout-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.readout-value { font-size: 1.05rem; font-weight: 700; color: var(--text); font-family: var(--mono); }

/* ── Explore panel ─── */
.explore-tabs {
  display: flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 2px;
  flex-wrap: wrap; margin-bottom: 12px;
}
.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.concept-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  transition: border-color .2s;
}
.concept-card:hover { border-color: var(--accent); }
.concept-card h3 { font-size: 0.95rem; color: var(--accent); margin-bottom: 4px; }
.concept-card .cc-formula {
  font-family: var(--mono); font-size: 0.82rem;
  background: var(--surface2); padding: 6px 10px; border-radius: 6px;
  margin: 8px 0; color: var(--gold);
}
.concept-card .cc-desc { font-size: 0.82rem; color: var(--text-dim); line-height: 1.45; }
.concept-card .cc-example {
  margin-top: 10px; padding: 10px; background: var(--bg);
  border-radius: 8px; border-left: 3px solid var(--accent);
}
.concept-card .cc-example-title { font-size: 0.72rem; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.concept-card .cc-example p { font-size: 0.8rem; color: var(--text-dim); margin: 2px 0; }

/* ── Practice panel ─── */
.practice-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.practice-prompt { font-size: 0.9rem; flex: 1 1 100%; margin-bottom: 4px; line-height: 1.5; }
.practice-input-group { display: flex; align-items: center; gap: 6px; }
.practice-input-group input {
  width: 120px; padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 0.9rem; font-family: var(--mono);
}
.practice-unit { font-size: 0.82rem; color: var(--text-dim); }
.pbar-score { font-size: 0.84rem; color: var(--text-dim); margin-left: auto; }
.pbar-score span { color: var(--text); font-weight: 700; }
.feedback { margin-top: 6px; padding: 0 16px; min-height: 22px; }
.feedback.ok  { color: var(--green); font-size: 0.88rem; font-weight: 600; }
.feedback.err { color: var(--red);   font-size: 0.88rem; font-weight: 600; }
.solution-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px;
  font-size: 0.85rem; line-height: 1.6; color: var(--text-dim);
}
.solution-panel .step { margin: 4px 0; }
.solution-panel .step-num { color: var(--accent); font-weight: 600; }

/* ── Quiz panel ─── */
.quiz-bar {
  padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.quiz-counter { font-size: 0.78rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em; }
.quiz-prompt { display: block; font-size: 0.95rem; margin: 10px 0; line-height: 1.5; }
.quiz-options { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.quiz-opt {
  padding: 10px 14px; border-radius: 8px; cursor: pointer;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); font-size: 0.88rem; transition: border-color .2s;
  text-align: left;
}
.quiz-opt:hover { border-color: var(--accent); }
.quiz-opt.selected { border-color: var(--accent); background: var(--accent-lo); }
.quiz-opt.correct { border-color: var(--green); background: rgba(61,220,132,.15); }
.quiz-opt.wrong { border-color: var(--red); background: rgba(255,85,85,.15); }
.quiz-input-group { display: flex; align-items: center; gap: 6px; margin: 8px 0; }
.quiz-input-group input {
  width: 140px; padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 0.9rem; font-family: var(--mono);
}
.quiz-unit { font-size: 0.82rem; color: var(--text-dim); }
.quiz-actions { display: flex; gap: 10px; margin-top: 10px; }

/* ── Quiz result ─── */
.quiz-result {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px;
}
.qr-header { text-align: center; margin-bottom: 16px; }
.qr-score { font-size: 2rem; font-weight: 700; }
.qr-score.perfect { color: var(--gold); }
.qr-score.good    { color: var(--green); }
.qr-score.poor    { color: var(--red); }
.qr-stars { font-size: 1.4rem; margin-top: 4px; }
.qr-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.qr-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: 8px; background: var(--surface2);
  font-size: 0.84rem;
}
.qr-row.ok  { border-left: 3px solid var(--green); }
.qr-row.err { border-left: 3px solid var(--red); }
.qr-row .qr-q { flex: 1; color: var(--text-dim); }
.qr-row .qr-a { color: var(--text); font-weight: 600; margin: 0 10px; }
.qr-row .qr-icon { font-size: 1rem; }
.qr-retry { text-align: center; margin-top: 14px; }

/* ── SEO article ─── */
.seo-article {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 24px; line-height: 1.7;
}
.seo-article h2 { font-size: 1.3rem; color: var(--accent); margin-bottom: 12px; }
.seo-article h3 { font-size: 1.05rem; color: var(--text); margin: 18px 0 8px; }
.seo-article p { font-size: 0.92rem; color: var(--text-dim); margin-bottom: 10px; }
.seo-article a { color: var(--accent); text-decoration: none; }
.seo-article a:hover { text-decoration: underline; }

/* ── Responsive ──────────────────────────────────────────────── */

@media (max-width: 768px) {
  .readout-panel { grid-template-columns: repeat(3, 1fr); }
  .controls-bar { gap: 10px; }
  input[type="range"] { width: 90px; }
  .concept-grid { grid-template-columns: 1fr; }
}

@media (max-width: 500px) {
  header h1 { font-size: 1.4rem; }
  .subtitle  { font-size: 0.78rem; }
  .controls-bar { padding: 10px 12px; gap: 8px; }
  .pill { padding: 5px 10px; font-size: 0.76rem; }
  .readout-panel { grid-template-columns: repeat(2, 1fr); }
  input[type="range"] { width: 70px; }
  .practice-bar { flex-direction: column; align-items: stretch; }
  .pbar-score { margin-left: 0; }
}

/* INTERLINK-START  header quick-links */
.head-actions{display:flex;align-items:center;gap:8px;margin-left:auto;flex-wrap:wrap;justify-content:flex-end;}
.btn-link{display:inline-flex;align-items:center;gap:7px;padding:5px 12px;border-radius:8px;font-size:.82rem;font-weight:700;text-decoration:none;cursor:pointer;background:var(--surface2,#1f2535);color:var(--text,#dde3f0);border:1.5px solid var(--border,#2a3050);white-space:nowrap;transition:border-color .18s,background .18s,color .18s;}
.btn-link:hover{border-color:var(--accent,#4fc3f7);background:var(--accent-lo,rgba(79,195,247,.18));color:#fff;}
.btn-link img{width:20px;height:20px;border-radius:4px;flex:none;}
.btn-link .lbl{line-height:1;}
@media(max-width:560px){.btn-link .lbl{display:none;}.btn-link{padding:5px 9px;}}
/* With a third quick-link (Gearbox) the row overflowed by ~17 px and
   wrapped under the mode tabs — at every width, since #app caps the bar.
   Share keeps its icon and word; only the trailing "your setup" goes, as
   site.css already does below 640 px. */
.head-actions .btn-share-ext { display: none; }
/* ...and on a 1024-1100 px window it still did not fit, so the quick-links
   go icon-only there (title + aria-label keep the name), as they already
   do below 560 px. Wider than 1100 px the labels return. */
@media (max-width: 1100px) { .btn-link .lbl { display: none; } .btn-link { padding: 5px 9px; } }
/* INTERLINK-END */

/* ═══════════════════════════════════════════════════════════════════
   UPGRADE v3 — parameter grid, advanced panel, display controls,
   calculation modal, learning panels, context menu.
   ═══════════════════════════════════════════════════════════════════ */

/* The canvas card anchors both the display-controls overlay and the
   calculation FAB, so it has to establish a positioning context. */
.canvas-card { position: relative; }

/* The simulate panel stacks: diagram selector, canvas, warnings, then the
   parameters that drive it. A tighter gap than the page default keeps the
   canvas and its controls reading as one unit. */
#sim-panel { display: flex; flex-direction: column; gap: 10px; }

/* ── Preset dropdown ── */
.sel-preset {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; min-height: 36px;
  font-family: var(--font); font-size: 0.82rem; font-weight: 600;
  cursor: pointer;
}
.sel-preset:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.ctrl-actions { gap: 8px; flex-wrap: wrap; }
/* Run controls read as the primary action group: a divider separates them
   from the configuration controls that follow on the same bar. */
.sim-controls .ctrl-actions {
  padding-right: 14px; margin-right: 2px;
  border-right: 1px solid var(--border);
}
.sim-controls { gap: 9px 12px; padding: 8px 12px; }
.sim-controls .btn { padding: 7px 14px; font-size: 0.81rem; min-height: 36px; }
.sim-controls .ctrl-label { font-size: 0.68rem; }
.sim-controls .sel-preset { padding: 6px 8px; font-size: 0.79rem; min-height: 34px; }
.sim-controls .pill { padding: 5px 11px; font-size: 0.78rem; }

.load-note {
  margin: 0 2px; font-size: 0.76rem; line-height: 1.45; color: var(--text-dim);
}
.load-note strong { color: var(--text); }

/* ── Parameter grid: slider + companion number input ── */
.param-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(212px, 1fr));
  gap: 9px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
}
/* Caption above, control row below. The caption is the flexible part and
   the control row is pinned to the bottom of the cell, so every slider in
   a grid row lands on the same baseline no matter how many lines its
   caption wraps to — a two-line minimum alone was not enough, because a
   long name plus a hint can still run to three. */
.param { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.param > label {
  flex: 1 0 auto;
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-dim); font-weight: 700; line-height: 1.3;
  display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap;
  min-height: 2.6em; align-content: flex-start;
}
.param > .p-row { flex: 0 0 auto; }
.param > label em { font-style: italic; text-transform: none; color: var(--text); }
.p-hint {
  font-weight: 500; text-transform: none; letter-spacing: 0;
  font-size: 0.64rem; color: var(--text-dim); opacity: .8;
}
.p-row { display: flex; align-items: center; gap: 8px; min-width: 0; }

/* ── Sliders + steppers — the Titration Simulator design, tightened so a
   label/slider/stepper row still fits four to a line on a desktop. ── */
input[type="range"].sim-slider {
  flex: 1 1 auto; min-width: 56px; width: auto;
  -webkit-appearance: none; appearance: none; height: 6px;
  background: rgba(255,255,255,.12); border-radius: 3px; outline: none;
  border: 1px solid rgba(255,255,255,.1); cursor: pointer;
}
input[type="range"].sim-slider::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--accent-lo), rgba(255,255,255,.12));
}
input[type="range"].sim-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 17px; height: 17px; margin-top: -6px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
  box-shadow: 0 0 8px var(--accent-lo); border: 2px solid rgba(255,255,255,.2);
}
input[type="range"].sim-slider::-moz-range-track {
  height: 6px; border-radius: 3px; border: none;
  background: linear-gradient(to right, var(--accent-lo), rgba(255,255,255,.12));
}
input[type="range"].sim-slider::-moz-range-thumb {
  width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.2);
  border-radius: 50%; background: var(--accent); cursor: pointer;
}
input[type="range"].sim-slider:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

/* ── Stepper: type an exact value, or nudge it by one step ── */
.stepper-wrap {
  display: flex; align-items: center; gap: 0; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 7px; overflow: hidden;
  background: var(--bg); height: 30px;
}
.stepper-btn {
  width: 26px; height: 30px; border: none; cursor: pointer; padding: 0;
  font-family: var(--font); font-size: 0.95rem; font-weight: 700; color: var(--text-dim);
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s; flex-shrink: 0;
}
.stepper-btn:hover { background: var(--accent-lo); color: var(--accent); }
.stepper-btn:active { background: var(--accent); color: #fff; }
.stepper-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.stepper-input {
  width: 56px; border: none; text-align: center; height: 100%;
  font-family: var(--mono); font-size: 0.78rem; font-weight: 700;
  color: var(--accent); background: var(--bg); outline: none;
  padding: 2px 1px; -moz-appearance: textfield; appearance: textfield;
}
.stepper-input:focus { background: var(--surface2); }
.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.p-unit {
  flex: 0 0 auto; font-size: 0.66rem; font-weight: 700;
  color: var(--accent); text-transform: none; letter-spacing: 0;
}
/* Greek must opt out of the label's uppercase transform: it turns η into
   Η — a capital eta indistinguishable from a Latin H — which defeats the
   point of naming the quantity with its symbol at all. */
.param > label .sym { text-transform: none; font-style: italic; font-weight: 700; color: var(--text); }
.param > label em { font-style: italic; text-transform: none; color: var(--text); }

/* ── Advanced parameters ── */
.adv-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.adv-panel > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px; min-height: 44px;
  font-size: 0.8rem; font-weight: 700; color: var(--text);
  transition: background .15s;
}
.adv-panel > summary::-webkit-details-marker { display: none; }
.adv-panel > summary::marker { content: ''; }
.adv-panel > summary:hover { background: var(--accent-lo); }
.adv-panel > summary:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.adv-panel > summary::after {
  content: '\25BE'; margin-left: auto; color: var(--text-dim);
  font-size: 0.8rem; transition: transform .2s;
}
.adv-panel[open] > summary::after { transform: rotate(180deg); color: var(--accent); }
.adv-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--accent-lo); color: var(--accent); font-size: 0.95rem; flex-shrink: 0;
}
.adv-body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 9px; }
.adv-group-title {
  font-size: 0.62rem; font-weight: 800; letter-spacing: .09em;
  text-transform: uppercase; color: var(--accent);
  padding-bottom: 2px; border-bottom: 1px solid var(--border);
}
.adv-body .param-grid { background: transparent; border: none; padding: 0; }
.adv-note { font-size: 0.74rem; line-height: 1.5; color: var(--text-dim); margin: 0; }

/* ── Diagram selector + export row ── */
.export-group { margin-left: auto; gap: 6px; flex-wrap: nowrap; }
.export-group .btn-exp {
  font-size: 0.74rem; padding: 6px 10px; min-height: 34px;
  white-space: nowrap;
}


/* ── Warning strip ── */
.sim-warn {
  background: rgba(245,200,66,.10); border: 1px solid rgba(245,200,66,.42);
  border-left-width: 4px; border-radius: 8px;
  padding: 10px 14px; font-size: 0.83rem; line-height: 1.55; color: var(--gold);
}
.sim-warn strong { color: var(--text); }

/* ── Performance readout row reads a little quieter than the live one ── */
.readout-perf .readout-value { font-size: 0.95rem; }

/* ── Display Controls — collapsible overlay pinned to the canvas ── */
.canvas-toggles {
  position: absolute; top: 16px; left: 16px; z-index: 4;
  background: rgba(13,17,23,0.88);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  max-width: calc(100% - 32px);
}
.canvas-toggles > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; justify-content: center; gap: 0;
  padding: 0; white-space: nowrap;
  width: 34px; height: 34px;
  font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text); border-radius: 9px; transition: background .12s, color .12s;
}
.canvas-toggles > summary .cvt-title,
.canvas-toggles > summary .cvt-caret { display: none; }
.canvas-toggles .cvt-ico { width: 17px; height: 17px; }
/* Opened, it earns its caption back — the user has chosen to cover the canvas. */
.canvas-toggles[open] > summary {
  width: auto; height: auto; min-height: 30px;
  padding: 6px 10px; gap: 7px; justify-content: flex-start;
}
.canvas-toggles[open] > summary .cvt-title { display: inline; }
.canvas-toggles[open] > summary .cvt-caret { display: inline; }
.canvas-toggles > summary::-webkit-details-marker { display: none; }
.canvas-toggles > summary::marker { content: ''; }
.canvas-toggles > summary:hover { background: var(--accent-lo); color: var(--accent); }
.canvas-toggles > summary:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.canvas-toggles .cvt-ico { flex-shrink: 0; color: var(--accent); }
.canvas-toggles .cvt-caret {
  margin-left: auto; padding-left: 4px; color: var(--text-dim);
  font-size: 0.7rem; transition: transform .2s;
}
.canvas-toggles[open] > summary .cvt-caret { transform: rotate(180deg); color: var(--accent); }
.canvas-toggles[open] > summary {
  border-bottom: 1px solid var(--border); border-radius: 9px 9px 0 0;
}
.canvas-toggles .cvt-body {
  display: flex; flex-direction: column; gap: 5px;
  padding: 8px 11px 10px; max-height: 60vh; overflow-y: auto;
}
.canvas-toggles .cvt-group {
  font-size: 0.58rem; font-weight: 800; letter-spacing: .09em;
  text-transform: uppercase; color: var(--accent);
  margin-top: 4px; padding-bottom: 2px; border-bottom: 1px solid var(--border);
}
.canvas-toggles .cvt-group:first-child { margin-top: 0; }
.canvas-toggles .cvt-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.72rem; color: var(--text-dim); cursor: pointer;
  white-space: nowrap; transition: color .12s;
}
.canvas-toggles .cvt-item:hover { color: var(--text); }
.canvas-toggles .cvt-item input[type="checkbox"] {
  accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; flex-shrink: 0;
}
.canvas-toggles .cvt-reset {
  margin-top: 7px; padding: 5px 9px; min-height: 28px;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-dim); font-size: 0.66rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; cursor: pointer;
  transition: border-color .12s, color .12s;
}
.canvas-toggles .cvt-reset:hover { border-color: var(--accent); color: var(--accent); }
.canvas-toggles .cvt-reset:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ── Diagram selector — overlay on the top-left of the diagram pane ──
   Same translucent chrome as the Display Controls chip on the engine
   side, so the canvas reads as having two consistent in-canvas controls.
   JS sets left/top from the pane rectangle; everything else is here. */
.pane-toggle {
  position: absolute; z-index: 4;
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 4px 10px;
  background: rgba(13,17,23,0.88);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}
.pane-toggle .pt-label {
  font-size: 0.58rem; font-weight: 800; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-dim); white-space: nowrap;
}
.pane-toggle .pt-tabs {
  display: flex; gap: 2px; padding: 2px;
  background: var(--bg); border-radius: 7px;
}
.pane-toggle .pt-pill {
  padding: 4px 9px; min-height: 26px;
  background: transparent; border: none; border-radius: 5px;
  color: var(--text-dim); font-family: var(--font);
  font-size: 0.7rem; font-weight: 700; white-space: nowrap; cursor: pointer;
  transition: background .12s, color .12s;
}
.pane-toggle .pt-pill:hover:not(.active) { background: var(--surface2); color: var(--text); }
.pane-toggle .pt-pill.active { background: var(--accent); color: #fff; box-shadow: 0 0 10px var(--accent-lo); }
.pane-toggle .pt-pill:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

/* On a phone the pane is narrow: drop the "Diagram" caption and let the
   three pills use the full width of the overlay. */
@media (max-width: 640px) {
  .pane-toggle { padding: 4px; gap: 0; }
  .pane-toggle .pt-label { display: none; }
  .pane-toggle .pt-pill { padding: 5px 10px; min-height: 30px; font-size: 0.68rem; }
}

/* ── Show-Calculations: a compact icon in the toolbar under the canvas.
   It used to be a floating action button over the plot, which cost the
   diagram its bottom-right corner on every layout. ── */
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: 0 0 auto; padding: 0;
  background: linear-gradient(180deg, #ef5350, #c62828);
  color: #fff; border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; cursor: pointer;
  transition: filter .15s, box-shadow .15s;
}
.btn-icon:hover { filter: brightness(1.12); box-shadow: 0 0 10px var(--accent-lo); }
.btn-icon:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ── Calculation modal ── */
.calc-modal {
  display: none; position: fixed; inset: 0; z-index: 1200;
  background: rgba(0,0,0,0.72); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  align-items: flex-start; justify-content: center; padding: 24px 16px; overflow-y: auto;
}
.calc-modal.active { display: flex; }
.calc-modal-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  width: 100%; max-width: 780px; display: flex; flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  max-height: calc(100vh - 48px); overflow: hidden;
}
.calc-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface2); flex-shrink: 0;
}
.calc-modal-title { font-size: 1rem; font-weight: 800; color: var(--text); }
.calc-modal-close {
  width: 34px; height: 34px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text-dim);
  font-size: 1.4rem; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.calc-modal-close:hover { border-color: var(--accent); color: var(--text); background: var(--surface2); }
.calc-modal-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

.cs-inputs {
  background: var(--accent-lo); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.cs-badge {
  display: inline-block; padding: 3px 12px; border-radius: 20px;
  background: rgba(229,57,53,.28); color: #ffcdd2;
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; align-self: flex-start;
}
.cs-given { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.cs-given span { font-family: var(--mono); font-size: 0.82rem; color: var(--text); }
.cs-si-note { font-size: 0.74rem; color: var(--text-dim); margin: 0; line-height: 1.5; }
.cs-step {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 7px;
}
.cs-step-hd { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.cs-num {
  font-size: 0.64rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  color: #ffcdd2; background: rgba(229,57,53,.28);
  padding: 2px 8px; border-radius: 20px; white-space: nowrap;
}
.cs-title { font-size: 0.9rem; font-weight: 700; color: var(--text); }
.cs-formula {
  font-size: 0.9rem; color: var(--text);
  background: var(--surface2); border-radius: 6px;
  padding: 8px 12px; border-left: 3px solid var(--accent);
  overflow-x: auto;
}
.cs-calc { font-size: 0.86rem; color: var(--text); line-height: 1.9; overflow-x: auto; }
.cs-result { font-size: 0.86rem; color: var(--text-dim); margin-top: 2px; }
.cs-result strong { font-family: var(--mono); font-size: 0.92rem; color: var(--green); }

/* ── Learning panels ── */
.learn-panels {
  padding: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.learn-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 12px;
}
.learn-head-title { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.learn-head-actions { display: flex; gap: 8px; }
.learn-toggle-all {
  padding: 6px 12px; min-height: 32px;
  background: var(--accent-lo); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px;
  font-family: var(--font); font-size: 0.78rem; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.learn-toggle-all:hover { background: var(--surface2); border-color: var(--accent); }
.learn-toggle-all:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.learn-card {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); margin-bottom: 10px; overflow: hidden;
  transition: border-color .2s;
}
.learn-card:last-child { margin-bottom: 0; }
.learn-card[open] { border-color: var(--accent); }
.learn-card > summary {
  list-style: none; cursor: pointer;
  padding: 11px 14px; min-height: 44px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 0.88rem; font-weight: 700; color: var(--text);
  user-select: none; transition: background .15s;
}
.learn-card > summary::-webkit-details-marker { display: none; }
.learn-card > summary::marker { content: ''; }
.learn-card > summary:hover { background: var(--accent-lo); }
.learn-card > summary:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.learn-card > summary::after {
  content: '\25BE'; margin-left: auto; color: var(--text-dim);
  font-size: 0.78rem; transition: transform .2s;
}
.learn-card[open] > summary::after { transform: rotate(180deg); color: var(--accent); }
.lp-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--accent-lo); font-size: 0.9rem; flex-shrink: 0;
}
.lp-sub { color: var(--text-dim); font-weight: 500; font-size: 0.78rem; }
.learn-body { padding: 12px 14px 14px; }
.eq-line { margin: 8px 0; overflow-x: auto; overflow-y: hidden; font-size: 0.95rem; }
.lp-note { font-size: 0.8rem; line-height: 1.6; color: var(--text-dim); margin: 10px 0 0; }
.lp-note strong { color: var(--text); }

/* Cycle state table — explicit cell colours so it never inherits the
   dark surface and disappears (audit C18). */
.tbl-wrap { overflow-x: auto; max-width: 100%; }
.state-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.state-table th {
  background: var(--surface2); color: var(--text);
  text-align: left; padding: 7px 10px; white-space: nowrap;
  border-bottom: 1px solid var(--border); font-weight: 700;
}
.state-table td {
  padding: 7px 10px; color: var(--text); font-family: var(--mono);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.state-table td:nth-child(2) { font-family: var(--font); color: var(--text-dim); white-space: normal; min-width: 150px; }
.state-table tbody tr:nth-child(even) td { background: rgba(255,255,255,.03); }
.state-table .st-n { color: var(--gold); font-weight: 800; }

/* Efficiency bars */
.perf-row { margin-bottom: 10px; }
.perf-lbl {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 0.78rem; color: var(--text-dim); margin-bottom: 4px;
}
.perf-val { font-family: var(--mono); font-weight: 700; color: var(--text); }
.perf-track { height: 9px; background: var(--surface2); border-radius: 5px; overflow: hidden; }
.perf-fill { height: 100%; border-radius: 5px; transition: width .25s ease; }

.coach-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 9px; }
.coach-list li { font-size: 0.83rem; line-height: 1.6; color: var(--text-dim); }

/* ── Explore card body (now prose with KaTeX, not the old cc-* blocks) ── */
.concept-card p { font-size: 0.84rem; color: var(--text-dim); line-height: 1.6; }
.concept-card p strong { color: var(--text); }
.concept-card .katex-display { margin: 10px 0; overflow-x: auto; overflow-y: hidden; }

/* ── Practice / quiz feedback states not already defined ── */
.feedback.bad  { color: var(--red);  font-size: 0.88rem; font-weight: 600; }
.feedback.warn { color: var(--gold); font-size: 0.88rem; font-weight: 600; }
.solution-panel pre {
  white-space: pre-wrap; font-family: var(--mono); font-size: 0.82rem;
  color: var(--text); margin-top: 6px; line-height: 1.7;
}
.qr-pct { text-align: center; font-size: 1.1rem; color: var(--text-dim); margin-top: 2px; }
.qr-msg { text-align: center; font-size: 0.88rem; color: var(--text-dim); margin-top: 10px; line-height: 1.6; }
.quiz-result { text-align: center; }

/* ── Canvas context menu ── */
.ctx-menu {
  position: fixed; z-index: 1300; min-width: 210px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 10px 26px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 2px;
}
.ctx-item {
  text-align: left; padding: 8px 11px; min-height: 38px;
  background: transparent; border: none; border-radius: 6px;
  color: var(--text); font-family: var(--font); font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: background .12s;
}
.ctx-item:hover { background: var(--surface2); }
.ctx-item:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.ctx-sep { height: 1px; background: var(--border); margin: 3px 6px; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sim-controls .ctrl-actions {
    padding-right: 0; margin-right: 0; border-right: none;
    padding-bottom: 9px; margin-bottom: 1px;
    border-bottom: 1px solid var(--border); width: 100%;
  }
  /* Touch targets: the run buttons inherit the site's 36px .btn height,
     which is under the project's 44px minimum. */
  .sim-controls .ctrl-actions .btn { flex: 1 1 auto; min-height: 44px; }
  .sim-controls .sel-preset { min-height: 44px; }
  .sim-controls .pill { min-height: 40px; }
  .export-group { margin-left: 0; }
  .param-grid { grid-template-columns: 1fr; gap: 12px; padding: 12px; }
  .param > label { min-height: 0; }
  /* Touch: the stepper grows to the 44px minimum and the row has the
     width to spare because the grid is one column here. */
  .stepper-wrap { height: 44px; }
  .stepper-btn { width: 40px; height: 44px; font-size: 1.05rem; }
  .stepper-input { width: 70px; font-size: 0.86rem; }
  .readout-perf { grid-template-columns: repeat(2, 1fr); }
  .ctrl-actions { margin-left: 0; width: 100%; }
  .export-group { margin-left: 0; }

  /* ── Tap targets. The run buttons, the preset and the toolbar pills were
     sized above; these four were not, and they are the ones a student
     actually reaches for first. Measured at 375 / 500 / 768 px:
       #mode-tabs .pill      24 px      (Simulate / Explore / Practice / Quiz)
       #explore-tabs .pill   24 px
       .pane-toggle .pt-pill 26 px      (P–V / T–s / Valves)
       .sim-slider            6 px      — all seventeen of them
     The slider is the worst of them and the least obvious: the ELEMENT is
     6 px tall because the track height was put on the input itself, and a
     finger hits the element, not the 17 px thumb drawn overflowing it. Give
     the input real height and let the pseudo-element keep the 6 px track. ── */
  #mode-tabs .pill,
  #explore-tabs .pill { min-height: 34px; display: inline-flex; align-items: center; justify-content: center; }
  .pane-toggle .pt-pill { min-height: 30px; display: inline-flex; align-items: center; justify-content: center; }
  input[type="range"].sim-slider {
    height: 30px; background: transparent; border: none; border-radius: 0;
  }
  input[type="range"].sim-slider::-webkit-slider-runnable-track {
    height: 6px; border-radius: 3px; border: 1px solid rgba(255,255,255,.1);
  }
  input[type="range"].sim-slider::-moz-range-track {
    height: 6px; border-radius: 3px; border: 1px solid rgba(255,255,255,.1);
  }
}

@media (max-width: 500px) {
  .learn-panels { padding: 10px; }
  .learn-card > summary { padding: 11px 12px; font-size: 0.82rem; }
  .lp-sub { display: none; }
  .learn-body { padding: 10px 12px 12px; }
  .learn-head-title { font-size: 0.85rem; }
  .calc-modal { padding: 12px 8px; }
  .calc-modal-box { max-height: calc(100vh - 24px); }
  .calc-modal-body { padding: 12px; }
  .cs-step { padding: 10px; }
  .btn-icon { width: 44px; height: 44px; }
  .export-group .btn-exp { min-width: 44px; min-height: 44px; }
  .canvas-toggles { top: 10px; left: 10px; }
  .canvas-toggles .cvt-body { padding: 6px 9px 8px; gap: 4px; }
  .canvas-toggles .cvt-item { font-size: 0.66rem; gap: 5px; }
}

/* ═══ Diagram toggle — phones only (the button is hidden on a wide screen) ═══ */
.diagram-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%;
  margin-top: 8px; padding: 10px 14px; min-height: 44px;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: .84rem; font-weight: 600; cursor: pointer; touch-action: manipulation;
}
.diagram-toggle[hidden] { display: none; }
.diagram-toggle .dt-ico { color: var(--accent); flex: none; }
.diagram-toggle .dt-sub { color: var(--text-muted, #8b9dc3); font-weight: 500; font-size: .74rem; }
.diagram-toggle .dt-caret { margin-left: auto; transition: transform .18s; }
.diagram-toggle.open .dt-caret { transform: rotate(180deg); }
.diagram-toggle:hover { border-color: var(--accent); }
.diagram-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .diagram-toggle .dt-caret { transition: none; } }

/* ═══ Explain — the guided lesson ═══════════════════════════════════
   The button sits with Play / Step / Reset; the transport is a strip
   UNDER the canvas (never over it — the lesson writes on every part of
   the picture), with a scrubber whose dots are the chapters. */
.btn-explain {
  background: rgba(255, 213, 74, .10); color: #ffd54a;
  border: 1px solid rgba(255, 213, 74, .55);
}
.btn-explain:hover { background: rgba(255, 213, 74, .2); border-color: #ffd54a; }
.btn-explain.active { background: #ffd54a; color: #14161c; border-color: #ffd54a; }
.btn-explain:focus-visible { outline: 2px solid #ffd54a; outline-offset: 2px; }
.btn-explain .ex-cap { font-size: .95em; }

.canvas-card.explaining .canvas-toggles,
.canvas-card.explaining .pane-toggle { display: none; }

.explain-bar {
  margin-top: 8px; padding: 6px 8px 8px;
  background: rgba(13, 17, 23, .82);
  border: 1px solid rgba(255, 213, 74, .35); border-radius: 12px;
}
.explain-bar[hidden] { display: none; }
.ex-row { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.ex-step {
  color: #ffd54a; font-weight: 700; font-size: .76rem; min-width: 38px;
  text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.ex-btn {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent; color: var(--text);
  font-size: .82rem; cursor: pointer; touch-action: manipulation;
}
.ex-btn.ex-play { background: #ffd54a; color: #14161c; font-size: .74rem; letter-spacing: -1px; }
.ex-btn:focus-visible, .ex-chip:focus-visible, .ex-dot:focus-visible { outline: 2px solid #ffd54a; outline-offset: 1px; }
.ex-btn:active, .ex-chip:active { transform: scale(.93); }
@media (hover: hover) {
  .ex-btn:not(.ex-play):hover { background: rgba(255, 213, 74, .14); border-color: rgba(255, 213, 74, .4); }
  .ex-chip:hover { border-color: #ffd54a; }
}
.ex-chip {
  height: 30px; padding: 0 10px; border-radius: 15px; flex: none;
  background: rgba(255, 255, 255, .04); color: #e8ebf2;
  border: 1px solid rgba(255, 213, 74, .3);
  font-size: .74rem; font-weight: 600; cursor: pointer; white-space: nowrap;
  font-variant-numeric: tabular-nums; touch-action: manipulation;
}
.ex-chip[aria-pressed="true"] { background: rgba(255, 213, 74, .16); color: #ffd54a; }
/* the scrubber, with the chapters as dots on its track */
.ex-track { position: relative; flex: 1 1 160px; min-width: 120px; height: 34px; margin: 0 6px; }
.ex-scrub {
  --ex-p: 0%;
  -webkit-appearance: none; appearance: none;
  position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
  width: 100%; height: 6px; margin: 0; border-radius: 3px; cursor: pointer;
  background: linear-gradient(90deg, #ffd54a var(--ex-p), rgba(255, 255, 255, .14) var(--ex-p));
}
.ex-scrub::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 2px solid #ffd54a; box-shadow: 0 0 8px rgba(255, 213, 74, .6);
  position: relative; z-index: 2;
}
.ex-scrub::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 2px solid #ffd54a; box-shadow: 0 0 8px rgba(255, 213, 74, .6);
}
/* Two classes, so it outranks the generic input[type="range"] rule (and its
   90 px / 70 px phone widths): that rule used to win, leaving the scrubber
   120 px long at the left of a 688 px track while the chapter dots ran the
   whole width. The input fills the track's HEIGHT so a finger can hit it;
   the 6 px bar is its background clipped to the content box. */
.ex-track .ex-scrub {
  width: 100%; height: 34px; padding: 14px 0; box-sizing: border-box;
  background-clip: content-box;
}
.ex-scrub:focus-visible { outline: 2px solid #ffd54a; outline-offset: 4px; }
.ex-dots { position: absolute; left: 0; right: 0; top: 50%; height: 0; pointer-events: none; }
.ex-dot {
  position: absolute; top: 0; width: 18px; height: 18px; margin: -9px 0 0 -9px;
  padding: 0; border: 0; background: transparent; cursor: pointer; pointer-events: auto;
}
.ex-dot::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px;
  border-radius: 50%; background: #2a3042; border: 1.5px solid rgba(255, 213, 74, .6);
}
.ex-dot.done::after { background: #ffd54a; }
.ex-dot.now::after { background: #fff; border-color: #ffd54a; box-shadow: 0 0 0 3px rgba(255, 213, 74, .3); }
.ex-sub {
  margin: 6px 6px 0; color: #cfd6e6; font-size: .84rem; line-height: 1.45;
  min-height: 2.9em;
}
.ex-sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
@media (pointer: coarse) {
  .ex-btn { width: 44px; height: 44px; }
  .ex-chip { height: 40px; }
  .ex-track { height: 44px; }
  .ex-track .ex-scrub { height: 44px; padding: 19px 0; }
  .ex-dot { width: 28px; height: 28px; margin: -14px 0 0 -14px; }
}
@media (max-width: 560px) {
  .ex-row { gap: 2px; justify-content: space-between; }
  .ex-cam-lbl { display: none; }
  .ex-step { min-width: 0; margin-right: 2px; }
  .ex-chip { padding: 0 8px; min-width: 38px; }
  .ex-track { order: 10; flex-basis: 100%; margin: 2px 4px 0; }
  .ex-sub { font-size: .8rem; }
}
@media (prefers-reduced-motion: reduce) { .ex-btn:active, .ex-chip:active { transform: none; } }

/* ═══ Touch: the collapsed chip grows to the 44px minimum. Must stay LAST
   so it wins over the .canvas-toggles rules above. ═══ */
@media (max-width: 768px) {
  .canvas-toggles > summary { width: 44px; height: 44px; }
  .canvas-toggles .cvt-ico { width: 18px; height: 18px; }
  .canvas-toggles[open] > summary { width: auto; height: auto; padding: 7px 10px; }
}

/* ── Rev it ── */
.btn-revit { background: rgba(61, 220, 132, .1); border: 1px solid rgba(61, 220, 132, .55); color: #3ddc84; }
.btn-revit:hover { background: rgba(61, 220, 132, .2); }
.btn-revit.active { background: #3ddc84; color: #10141c; border-color: #3ddc84; }
.btn-revit:focus-visible { outline: 2px solid #3ddc84; outline-offset: 2px; }
.rev-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 10px 0; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.rev-panel[hidden], .dyno-card[hidden] { display: none; }
.rev-thr { display: flex; align-items: center; gap: 10px; flex: 1 1 320px; min-width: 0; }
.rev-thr-lbl { font-weight: 600; font-size: .85rem; }
.rev-thr input.rev-slider { flex: 1; width: auto; min-width: 0; height: 44px; padding: 19px 0; box-sizing: border-box; background-clip: content-box; cursor: pointer; touch-action: none; }
.rev-thr input.rev-slider::-webkit-slider-thumb { width: 24px; height: 24px; background: #3ddc84; }
.rev-thr-val { min-width: 3.4em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.rev-mute { min-height: 36px; }
.rev-note { flex: 1 1 100%; margin: 0; font-size: .8rem; color: var(--text-muted, #9aa4bf); line-height: 1.45; }
.rev-warn { color: #ffb84a; }
.dyno-card { margin: 10px 0; padding: 8px 14px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); overflow-x: clip; }
.dyno-card summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
#dyno-canvas { display: block; width: 100%; height: 240px; }
.dyno-live { margin: 6px 0 2px; font-size: .9rem; font-variant-numeric: tabular-nums; }
.dyno-note { margin: 4px 0 0; font-size: .78rem; color: var(--text-muted, #9aa4bf); line-height: 1.45; }
@media (max-width: 500px) {
  .rev-thr { flex-basis: 100%; }
  #dyno-canvas { height: 210px; }
}
.btn-revit { display: inline-flex; align-items: center; }
.btn-revit .rev-ico { vertical-align: -3px; }
.btn-revit .rev-snd { margin-left: 5px; opacity: .85; }
.rev-rpm-val { min-width: 6.5em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; color: #ffb84a; }

/* ── Engine view: 1 cylinder | Multi-cylinder, plus the cylinder count ──
   A header strip ABOVE the canvas, inside the card. The Display Controls
   chip (absolute, top-left of the card) sits in its left padding, so the
   strip covers nothing that is drawn. */
.view-toggle {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px;
  min-height: 40px; padding: 0 0 8px 46px; margin-bottom: 2px;
  border-bottom: 1px solid var(--border);
}
.view-toggle .vt-label {
  font-size: 0.6rem; font-weight: 800; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-dim); white-space: nowrap;
}
.view-toggle .vt-count { display: flex; align-items: center; gap: 8px; }
.view-toggle .vt-count[hidden] { display: none; }
.view-toggle .vt-tabs {
  display: flex; gap: 2px; padding: 3px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
.view-toggle .vt-pill {
  padding: 5px 12px; min-height: 30px; min-width: 34px;
  background: transparent; border: none; border-radius: 6px;
  color: var(--text); opacity: .72; font-family: var(--font);
  font-size: 0.76rem; font-weight: 700; white-space: nowrap; cursor: pointer;
  transition: background .12s, color .12s, opacity .12s;
}
.view-toggle .vt-pill:hover:not(.active) { background: var(--surface2); opacity: 1; }
.view-toggle .vt-pill.active { background: var(--accent); color: #fff; opacity: 1; box-shadow: 0 0 10px var(--accent-lo); }
.view-toggle .vt-pill:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.view-toggle .vt-count .vt-pill.active { background: var(--gold); color: #0d1117; box-shadow: none; }
.canvas-card.explaining .view-toggle { opacity: .45; pointer-events: none; }
@media (max-width: 640px) {
  .view-toggle { gap: 6px 10px; }
  .view-toggle > .vt-label { display: none; }
  .view-toggle .vt-pill { padding: 5px 10px; font-size: 0.72rem; }
}

/* ── 3D view (engine3d.js) ──
   The stage replaces the canvas in the card; the 2D overlays (Display
   Controls, the diagram selector, Show diagram) belong to the section and
   step aside. Controls sit in one bar along the bottom of the stage. */
.view-toggle .vt-3d { display: inline-flex; align-items: center; gap: 5px; }
.view-toggle .vt-3d svg { flex: none; }
.canvas-card.view-3d .canvas-toggles,
.canvas-card.view-3d .pane-toggle,
.canvas-card.view-3d .diagram-toggle { display: none !important; }
.e3d-stage { position: relative; width: 100%; }
.e3d-view {
  position: relative; width: 100%; aspect-ratio: 16 / 10; max-height: 82vh;
  border-radius: 8px; overflow: hidden; background: #0b0d12;
  user-select: none; -webkit-user-select: none;
}
.e3d-stage[hidden] { display: none; }
.e3d-stage .e3d-gl, .e3d-stage .e3d-hud {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
}
.e3d-stage .e3d-gl { cursor: grab; outline: none; }
.e3d-stage .e3d-gl.grabbing { cursor: grabbing; }
.e3d-stage .e3d-gl:focus-visible { box-shadow: inset 0 0 0 2px var(--gold); }
.e3d-stage .e3d-hud { pointer-events: none; }
.e3d-bar {
  position: absolute; left: 10px; right: 10px; bottom: 10px;  /* over the view's foot on a wide screen */
  display: flex; flex-wrap: wrap; gap: 6px 8px; justify-content: center; pointer-events: none;
}
.e3d-seg {
  display: flex; gap: 2px; padding: 3px; pointer-events: auto;
  background: rgba(10, 13, 22, 0.82); border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 9px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.e3d-seg button {
  min-height: 30px; min-width: 32px; padding: 4px 10px; border: none; border-radius: 6px;
  background: transparent; color: #dfe5f2; font: 700 0.74rem var(--font); cursor: pointer; opacity: .8;
}
.e3d-seg button:hover { background: rgba(255, 255, 255, 0.08); opacity: 1; }
.e3d-seg button.on { background: var(--accent); color: #fff; opacity: 1; }
.e3d-seg button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.e3d-info {
  position: absolute; right: 10px; bottom: 56px; width: min(320px, calc(100% - 20px));
  padding: 12px 14px 12px; border-radius: 10px;
  background: rgba(10, 13, 22, 0.9); border: 1px solid rgba(255, 190, 90, 0.45);
  color: #e8ecf6; font-size: 0.8rem; line-height: 1.45; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.e3d-info[hidden] { display: none; }
.e3d-ititle { font-weight: 800; color: #ffbe5a; font-size: 0.9rem; margin: 0 22px 4px 0; }
.e3d-ilive { margin-top: 6px; color: #9fc4ff; font-variant-numeric: tabular-nums; }
.e3d-ilive:empty { display: none; }
.e3d-x {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border: none; border-radius: 6px;
  background: transparent; color: #cfd6e6; font-size: 1.1rem; cursor: pointer;
}
.e3d-x:hover { background: rgba(255, 255, 255, 0.1); }
.e3d-hint {
  position: absolute; left: 50%; bottom: 52px; transform: translateX(-50%);
  padding: 4px 10px; border-radius: 999px; background: rgba(10, 13, 22, 0.6);
  color: #b7c0d6; font-size: 0.7rem; white-space: nowrap; pointer-events: none; transition: color .2s, background .2s;
}
.e3d-hint.flash { color: #141414; background: #ffbe5a; }
.e3d-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center; color: #e8ecf6; font-size: 0.9rem; background: #0b0d12;
}
.e3d-msg[hidden] { display: none; }
/* On a phone the bar is a row UNDER the view, so it never covers the engine */
@media (max-width: 640px) {
  .e3d-view { aspect-ratio: 4 / 5; max-height: 74vh; }
  .e3d-bar { position: static; margin-top: 8px; justify-content: flex-start; gap: 6px; }
  .e3d-seg button { padding: 4px 8px; font-size: 0.72rem; min-height: 34px; }
  .e3d-hint { display: none; }
  .e3d-info { bottom: 10px; left: 10px; right: 10px; width: auto; }
}

/* ── Steam engine: turning the flywheel by hand ── */
#se-canvas { touch-action: pan-y; }
#se-canvas.grabbing { cursor: grabbing; }
.rev-panel .opt-chip { display: inline-flex; align-items: center; gap: 6px; }
