/* ==========================================================================
   Interactive Multimeter Lab — Phase 1 stylesheet
   --------------------------------------------------------------------------
   1. Design tokens
   2. Base & accessibility helpers
   3. Header & controls
   4. Layout (desktop split / mobile docked HUD)
   5. Multimeter SVG: holster, faceplate, display, LCD, buttons, dial, jacks
   6. Workbench SVG: mat, PCB, pads, probes
   7. Test-lead overlay & plugs
   8. Readout chips, notes, toast
   9. Motion preferences
  10. Phase 2: scenario tabs & controls, hazard banner, scenario art, LED glow
   ========================================================================== */

/* 1. Design tokens ======================================================= */
:root {
  /* Surfaces */
  --bg: #12141a;
  --bg-raised: #181b22;
  --bg-sunken: #0c0e12;
  --line: #262b35;
  --line-strong: #353c4a;

  /* Text */
  --text: #eef1f6;
  --text-muted: #a3acbd;
  --text-faint: #7c8598;

  /* Accents */
  --accent: #ffc928;            /* holster yellow */
  --accent-ink: #1d1600;
  --focus: #6cc4ff;
  --ok: #3ddc97;
  --warn: #ffb547;
  --danger: #ff6b6b;
  --probe-red: #e23b3b;
  --probe-black: #3a3f49;

  /* LCD (overridden on #meter-svg.is-off) */
  --lcd-top: #c3ecdf;
  --lcd-bottom: #8fcbbb;
  --lcd-ink: #0c1e1a;
  --lcd-ghost: rgba(12, 30, 26, 0.075);
  --lcd-glow: rgba(150, 235, 215, 0.35);

  /* Type */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-lcd: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
  --fs-xs: clamp(0.74rem, 0.7rem + 0.15vw, 0.8rem);
  --fs-sm: clamp(0.84rem, 0.8rem + 0.2vw, 0.93rem);
  --fs-md: clamp(0.95rem, 0.9rem + 0.25vw, 1.05rem);
  --fs-lg: clamp(1.05rem, 0.85rem + 0.9vw, 1.55rem);

  /* Geometry */
  --tap: 44px;                  /* minimum touch target */
  --radius: 14px;
  --gutter: clamp(16px, 2.4vw, 32px);

  color-scheme: dark;
}

/* 2. Base & accessibility helpers ======================================= */
*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;   /* dynamic viewport: no jump as mobile browser bars show/hide */
  background:
    radial-gradient(1200px 600px at 75% -10%, rgba(108, 196, 255, 0.06), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

/* SVG elements draw their own focus rings (strokes) — see component rules. */
svg :focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip-link {
  position: absolute;
  left: 16px;
  top: -100px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* 3. Header & controls ================================================== */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  padding: 12px var(--gutter);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #161920, var(--bg));
}

.app-header__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.app-header__logo { width: 34px; height: 34px; flex: none; }

.app-title {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.app-title__sub {
  display: inline-block;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72em;
}

.app-header__controls { display: flex; align-items: center; gap: 10px; }

/* Home link back to the FlareForge hub (left of the logo) */
.meter-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: #1a1e27;
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.meter-nav-btn .arrow {
  color: #f59e0b;
  font-size: 13px;
}

.meter-nav-btn:hover {
  background: #252a37;
  border-color: #f59e0b;
  color: #ffffff;
}

@media (max-width: 768px) {
  .meter-nav-btn {
    padding: 5px 8px;
    font-size: 12px;
  }
}

/* Segmented control (Sandbox | Missions) */
.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--bg-sunken);
}
.segmented__btn {
  min-width: var(--tap);
  min-height: var(--tap);
  padding: 0 16px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.segmented__btn:hover { color: var(--text); }
.segmented__btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* Generic buttons */
.btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);
  min-height: var(--tap);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg-raised);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.btn { padding: 0 16px; }
.btn:hover,
.icon-btn:hover { background: #20242d; border-color: #4a5263; }
.btn[aria-pressed="true"] { border-color: var(--warn); color: var(--warn); }

.icon-btn { width: var(--tap); padding: 0; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn__mute { display: none; }
.icon-btn[aria-pressed="false"] .icon-btn__waves { display: none; }
.icon-btn[aria-pressed="false"] .icon-btn__mute { display: inline; }
.icon-btn[aria-pressed="false"] { color: var(--text-faint); }

/* 4. Layout ============================================================== */
.lab {
  display: grid;
  grid-template-columns: minmax(290px, 410px) minmax(0, 1fr);
  align-items: start;
  gap: var(--gutter);
  max-width: 1640px;
  margin: 0 auto;
  padding: var(--gutter);
}

.pane--meter {
  position: sticky;
  top: var(--gutter);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 20;
}

.meter-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(100vh - 7.5rem);
  max-height: calc(100dvh - 7.5rem);
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.45));
  user-select: none;
  -webkit-user-select: none;
}

.pane--workbench {
  min-width: 0;
  padding: clamp(14px, 2vw, 24px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-raised);
}
.pane--workbench:focus { outline: none; }

/* Mobile: compact meter HUD docked to the top; circuit scrolls beneath. */
@media (max-width: 767px) {
  .app-header { padding: 10px 16px; }
  .app-title__sub { display: block; }

  .lab { display: block; padding: 0; }

  .pane--meter {
    top: 0;
    gap: 2px;
    padding: 6px 16px 6px;
    border-bottom: 1px solid var(--line);
    background: rgba(18, 20, 26, 0.94);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }

  .meter-svg {
    max-height: 36vh;
    max-height: 36dvh;
    filter: none;
  }

  .pane--workbench {
    margin: 16px;
    padding: 14px;
  }
}

/* 5. Multimeter SVG ===================================================== */

/* Layout variant switching (class set by LayoutManager) */
.meter-svg:not(.is-compact) #holster-compact,
.meter-svg.is-compact #holster-full { display: none; }

/* Holster: rugged rubberised yellow */
.holster__rubber { fill: url(#grad-rubber); stroke: #7d5b00; stroke-width: 2; }
.holster__lip { fill: none; stroke: rgba(120, 85, 0, 0.55); stroke-width: 3; }
.holster__grip { fill: url(#pat-grip); }

/* Faceplate: matte grey */
.faceplate { fill: url(#grad-face); stroke: #15171b; stroke-width: 2; }
.faceplate__brand,
.faceplate__rating {
  font-family: var(--font-ui);
  text-anchor: middle;
}
.faceplate__brand { fill: #dfe4ec; font-size: 11px; font-weight: 800; letter-spacing: 0.2em; }
.faceplate__rating { fill: #a1aab9; font-size: 9px; font-weight: 700; letter-spacing: 0.16em; }

/* Display bezel */
.bezel { fill: url(#grad-bezel); stroke: #0a0b0e; stroke-width: 2; }

/* LCD panel with backlight */
.lcd-stop-top { stop-color: var(--lcd-top); transition: stop-color 0.35s; }
.lcd-stop-bottom { stop-color: var(--lcd-bottom); transition: stop-color 0.35s; }
.lcd {
  fill: url(#grad-lcd);
  stroke: #07080a;
  stroke-width: 2;
  filter: drop-shadow(0 0 7px var(--lcd-glow));
}
.lcd__shade { fill: url(#grad-lcd-shade); pointer-events: none; }

/* Annunciators: ghost by default, darken when lit. Icons use currentColor. */
.lcd-ann { color: var(--lcd-ghost); fill: currentColor; transition: color 0.08s; }
.lcd-ann.is-lit { color: var(--lcd-ink); }
.lcd-ann--text {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

/* Seven-segment readout (monospace + skew = classic LCD feel) */
.lcd-digits {
  font-family: var(--font-lcd);
  font-size: 56px;
  font-weight: 700;
  text-anchor: end;
  transform: skewX(-6deg);
  transform-box: fill-box;
  transform-origin: 50% 100%;
}
.lcd-digits--ghost { fill: var(--lcd-ghost); }
.lcd-digits--value { fill: var(--lcd-ink); }
.lcd-digits--value .is-blank { fill: transparent; }

.lcd-unit {
  fill: var(--lcd-ink);
  font-family: var(--font-ui);
  font-size: 20px;
  font-weight: 800;
  text-anchor: end;
}
.lcd-range {
  fill: var(--lcd-ink);
  opacity: 0.7;
  font-family: var(--font-ui);
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

/* Meter switched OFF: backlight dims, segments vanish, ghosts stay faint. */
.meter-svg.is-off {
  --lcd-top: #75837d;
  --lcd-bottom: #5d6964;
  --lcd-ink: transparent;
  --lcd-ghost: rgba(12, 30, 26, 0.05);
  --lcd-glow: transparent;
}

/* Front-panel buttons */
.meter-btn { cursor: pointer; }
.meter-btn__hit { fill: transparent; }
.meter-btn__cap {
  fill: #23262c;
  stroke: #0e0f12;
  stroke-width: 2;
  transition: fill 0.15s, transform 0.08s;
}
.meter-btn__label {
  fill: #e3e7ee;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-anchor: middle;
  pointer-events: none;
}
.meter-btn:hover .meter-btn__cap { fill: #2d3139; }
.meter-btn:active .meter-btn__cap { transform: translateY(1.5px); }
.meter-btn.is-active .meter-btn__cap { fill: var(--accent); }
.meter-btn.is-active .meter-btn__label { fill: var(--accent-ink); }
.meter-btn:focus-visible .meter-btn__cap { stroke: var(--focus); stroke-width: 3; }

/* Rotary dial */
.dial__plate { fill: #262a31; stroke: #17191d; stroke-width: 2; }
.dial__ring { fill: none; stroke: rgba(255, 255, 255, 0.06); stroke-width: 1.5; }

.dial__tick { stroke: #7d8696; stroke-width: 2.5; stroke-linecap: round; transition: stroke 0.15s; }
.dial__tick.is-active { stroke: var(--accent); }

.dial__label { cursor: pointer; }
.dial__label-hit { fill: transparent; }
.dial__glyph {
  fill: #e9edf3;
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 800;
  text-anchor: middle;
  transition: fill 0.15s;
}
.dial__sym { fill: none; stroke: #e9edf3; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: stroke 0.15s, fill 0.15s; }
.dial__sym--fill { fill: #e9edf3; stroke: none; }
.dial__sub {
  fill: #9aa3b3;
  font-family: var(--font-ui);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-anchor: middle;
}
.dial__label--10A .dial__glyph,
.dial__label--10A .dial__sub { fill: #ff8a8a; }
.dial__label:hover .dial__glyph { fill: #fff; }
.dial__label.is-active .dial__glyph { fill: var(--accent); }
.dial__label.is-active .dial__sym { stroke: var(--accent); }
.dial__label.is-active .dial__sym--fill { fill: var(--accent); stroke: none; }

.dial__knob { cursor: grab; touch-action: none; }
.dial__knob.is-dragging { cursor: grabbing; }
.dial__hit { fill: transparent; }
.dial__knob:focus-visible .dial__hit { stroke: var(--focus); stroke-width: 3; }
.dial__skirt { fill: #15171b; }
.dial__knurl { fill: none; stroke: #3c414a; stroke-width: 7; stroke-dasharray: 3 4.2; }
.dial__cap { fill: url(#grad-knob); stroke: #111317; stroke-width: 2; }
.dial__bar { fill: #2b2f36; stroke: #4d535d; stroke-width: 1.5; }
.dial__line { stroke: #f5f7fa; stroke-width: 4; stroke-linecap: round; }
.dial__pointer { fill: #f5f7fa; }

/* Jacks */
.jack { cursor: pointer; }
.jack__hit { fill: transparent; transition: fill 0.15s; }
.jack:hover .jack__hit { fill: rgba(255, 255, 255, 0.06); }
.jack:focus-visible .jack__hit { fill: rgba(255, 255, 255, 0.06); stroke: var(--focus); stroke-width: 2.5; }
.jack.is-target .jack__hit {
  fill: rgba(108, 196, 255, 0.1);
  stroke: var(--focus);
  stroke-width: 2;
  stroke-dasharray: 5 5;
  animation: march 1s linear infinite;
}
.jack__label {
  fill: #eef1f6;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-anchor: middle;
}
.jack__sub {
  fill: #9aa3b3;
  font-family: var(--font-ui);
  font-size: 7.5px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-anchor: middle;
}
.jack__sub--danger { fill: #ff8a8a; }
.jack__ring--red { fill: #b3262b; stroke: #6d1216; stroke-width: 2; }
.jack__ring--black { fill: #1b1d21; stroke: #5b616c; stroke-width: 2; }
.jack__socket { fill: url(#grad-socket); }
.jack__pin { fill: #b9a06a; }

/* 6. Workbench SVG ====================================================== */
.bench-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 16px;
  margin-bottom: 14px;
}
.bench-title { margin: 0; font-size: var(--fs-lg); font-weight: 800; }
.bench-hint { margin: 2px 0 0; color: var(--text-muted); font-size: var(--fs-sm); max-width: 60ch; }
.bench-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Swap the hint wording by input type */
.hint-coarse { display: none; }
@media (pointer: coarse) {
  .hint-fine { display: none; }
  .hint-coarse { display: inline; }
}

.bench-stage {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  overflow: hidden;
  background: #1a2531;
}
.bench-svg {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-select: none;
}

.bench-mat { fill: #1a2531; }

/* Silkscreen-style annotation text on scenery */
.silk {
  fill: #eef0e4;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  opacity: 0.88;
}
.silk--mid { text-anchor: middle; }
.silk--end { text-anchor: end; }

.component-lead { fill: none; stroke: #b9bec6; stroke-width: 4; stroke-linecap: round; }
.resistor__body { fill: url(#grad-resistor); stroke: #6f5a35; stroke-width: 1.5; }

/* Test pads */
.pad { cursor: pointer; }
.pad__hit { fill: transparent; transition: fill 0.15s; }
.pad__ring { fill: none; stroke: var(--ring, #eef0e4); stroke-width: 2; opacity: 0.8; transition: stroke 0.15s; }
.pad__copper { fill: url(#grad-pad); stroke: #7d5813; stroke-width: 1.5; }
.pad__label {
  fill: #eef0e4;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-anchor: middle;
  pointer-events: none;
}
.pad:hover .pad__hit { fill: rgba(255, 255, 255, 0.06); }
.pad:focus-visible .pad__hit { fill: rgba(108, 196, 255, 0.1); stroke: var(--focus); stroke-width: 3; }
.pad.is-probed-red .pad__ring { stroke: #ff6b6b; opacity: 1; stroke-width: 3; }
.pad.is-probed-black .pad__ring { stroke: #c6ccd6; opacity: 1; stroke-width: 3; }

/* While a probe is selected, every pad advertises itself as a drop target. */
.bench-svg.has-selection .pad__hit {
  fill: rgba(108, 196, 255, 0.1);
  stroke: var(--focus);
  stroke-width: 2;
  stroke-dasharray: 6 6;
  animation: march 1s linear infinite;
}

.probe-rest__tray { fill: rgba(0, 0, 0, 0.22); stroke: #3a4757; stroke-width: 2; stroke-dasharray: 8 6; }
.probe-rest__label {
  fill: #7f8ea3;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-anchor: end;
}

/* Probes */
.probe { cursor: grab; touch-action: none; }
.probe.is-dragging { cursor: grabbing; }
.probe__hit { fill: transparent; }
.probe__halo {
  fill: rgba(108, 196, 255, 0.1);
  stroke: var(--focus);
  stroke-width: 2.5;
  stroke-dasharray: 6 6;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.probe:focus-visible .probe__halo { opacity: 0.6; }
.probe.is-selected .probe__halo { opacity: 1; animation: march 1s linear infinite; }

.probe__tip { fill: #dfe3e9; stroke: #7f8691; stroke-width: 1; }
.probe__guard { stroke: rgba(0, 0, 0, 0.6); stroke-width: 1.5; }
.probe__handle { stroke: rgba(0, 0, 0, 0.6); stroke-width: 1.5; }
.probe__grip { fill: none; stroke: rgba(0, 0, 0, 0.35); stroke-width: 2; }
.probe__shine { fill: rgba(255, 255, 255, 0.28); pointer-events: none; }
.probe__boot { stroke: rgba(0, 0, 0, 0.6); stroke-width: 1.5; }

.probe--red .probe__handle { fill: url(#grad-probe-red); }
.probe--red .probe__guard,
.probe--red .probe__boot { fill: #a51d1d; }
.probe--black .probe__handle { fill: url(#grad-probe-black); }
.probe--black .probe__guard,
.probe--black .probe__boot { fill: #1c1e22; stroke: #4a505b; }

.probe__contact {
  fill: none;
  stroke: var(--ok);
  stroke-width: 3;
  opacity: 0;
  transition: opacity 0.12s;
  pointer-events: none;
}
.probe.is-contact .probe__contact { opacity: 1; }

/* 7. Test-lead overlay & plugs ========================================== */
.lead-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 30;
}

.lead__shadow,
.lead__outline,
.lead__core,
.lead__shine { fill: none; stroke-linecap: round; }
.lead__shadow { stroke: rgba(0, 0, 0, 0.32); stroke-width: 10; }
.lead__outline { stroke-width: 9; }
.lead__core { stroke-width: 6; }
.lead__shine { stroke: rgba(255, 255, 255, 0.28); stroke-width: 1.5; }

.lead--red .lead__outline { stroke: #4a0b0b; }
.lead--red .lead__core { stroke: #d22d2d; }
.lead--black .lead__outline { stroke: #5a616e; }
.lead--black .lead__core { stroke: #1d2025; }

.plug { pointer-events: none; }
.plug__halo { fill: transparent; }
.plug__collar { stroke: rgba(0, 0, 0, 0.65); stroke-width: 2; }
.plug__cap { fill: rgba(255, 255, 255, 0.16); }
.plug__pin { fill: #c9ccd2; display: none; }
.lead--red .plug__collar { fill: #c92a2a; }
.lead--black .plug__collar { fill: #24272d; stroke: #5d6470; }

.plug.is-unplugged { pointer-events: auto; cursor: pointer; }
.plug.is-unplugged .plug__pin { display: inline; }
.plug.is-carrying .plug__halo {
  fill: rgba(108, 196, 255, 0.15);
  stroke: var(--focus);
  stroke-width: 2.5;
  stroke-dasharray: 6 5;
  animation: march 1s linear infinite;
}

/* 8. Readout chips, status, notes, toast ================================ */
.meter-status {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 1.5em;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.note { display: block; }
.note--info { color: var(--text); font-weight: 700; }
.note--ok { color: var(--ok); font-weight: 700; }
.note--tip { color: var(--text-muted); }
.note--warn { color: var(--warn); font-weight: 700; }

@media (max-width: 767px) {
  /* Single line in the docked HUD: most important note first, rest truncated. */
  .meter-status { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--fs-xs); }
  .note { display: inline; }
  .note + .note::before { content: " · "; color: var(--text-faint); }
}

.bench-readout { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 6px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--bg-sunken);
  font-size: var(--fs-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chip__dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.chip--red .chip__dot { background: var(--probe-red); }
.chip--black .chip__dot { background: #2a2d33; box-shadow: inset 0 0 0 2px #6b7280; }
.chip__name { font-weight: 800; }
.chip__value { color: var(--text-muted); }
.chip.is-selected { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(108, 196, 255, 0.2); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  max-width: min(92vw, 520px);
  padding: 12px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(24, 27, 34, 0.96);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@keyframes march { to { stroke-dashoffset: -24; } }

/* 9. Motion preferences ================================================= */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* 10. Phase 2 ============================================================ */

/* Scenario tab strip — scrolls sideways on narrow screens instead of the page */
.scenario-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 14px;
  padding-bottom: 2px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.scenario-tab {
  flex: none;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.scenario-tab:hover { color: var(--text); border-color: #4a5263; }
.scenario-tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Scenario brief + controls */
.scenario-brief { margin: 0 0 12px; color: var(--text-muted); font-size: var(--fs-sm); }
.scenario-brief p { margin: 4px 0 0; max-width: 75ch; }
.scenario-brief strong { color: var(--text); }
.scenario-brief code { font-family: var(--font-lcd); color: var(--text); }
.scenario-brief__title { margin: 0; color: var(--text); font-size: var(--fs-md); font-weight: 800; }
.brief-warn { color: var(--warn); font-weight: 700; }

.scenario-controls { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-bottom: 12px; }
.scenario-control { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.scenario-control__label { color: var(--text-muted); font-size: var(--fs-sm); font-weight: 700; }
.segmented--small .segmented__btn { padding: 0 12px; }
.scenario-range { width: min(220px, 60vw); min-height: var(--tap); accent-color: var(--accent); }

/* Safety hazard / blown-fuse banner */
.hazard-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 16px;
  margin: 0 0 14px;
  padding: 14px 16px;
  border: 2px solid var(--danger);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(255, 107, 107, 0.16), rgba(255, 181, 71, 0.08));
  animation: hazard-flash 0.5s ease-out 2;
}
.hazard-banner[hidden] { display: none; }
.hazard-banner__icon { width: 40px; height: 40px; flex: none; }
.hazard-banner__body { flex: 1 1 260px; min-width: 0; font-size: var(--fs-sm); }
.hazard-banner__body p { margin: 0 0 6px; }
.hazard-banner__title { color: var(--danger); font-size: var(--fs-md); font-weight: 900; letter-spacing: 0.01em; }
.hazard-banner__why { color: var(--text-muted); }
.btn--danger { border-color: var(--danger); background: rgba(255, 107, 107, 0.15); color: #ffd9d9; }
.btn--danger:hover { background: rgba(255, 107, 107, 0.28); border-color: var(--danger); }
@keyframes hazard-flash { 0% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.7); } 100% { box-shadow: 0 0 0 18px rgba(255, 107, 107, 0); } }

/* Pads on light scenery (socket plate, breadboard) need dark labels */
.scenario--light .pad__label { fill: #1b1e24; }
.pad__label { paint-order: stroke; stroke: rgba(0, 0, 0, 0.45); stroke-width: 3px; stroke-linejoin: round; }
.scenario--light .pad__label { stroke: rgba(255, 255, 255, 0.7); }

/* Clickable in-SVG switches */
[data-toggle] { cursor: pointer; }
[data-toggle]:focus-visible { outline: none; filter: drop-shadow(0 0 4px var(--focus)); }

/* 10.1 Mains socket */
.socket__shadow { fill: rgba(0, 0, 0, 0.35); }
.socket__plate { fill: #f6f5f0; stroke: #c9c6bb; stroke-width: 2; }
.socket__recess { fill: #eeede6; stroke: #d9d6cb; stroke-width: 2; }
.socket__slot { fill: #1f2125; }
.socket__screw { fill: #d9dbe0; stroke: #8f949c; stroke-width: 1.5; }
.socket__slot-line { stroke: #6b7078; stroke-width: 2; }
.socket__print { fill: #8a8779; font-family: var(--font-ui); font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-anchor: middle; }
.rocker__frame { fill: #e7e5dd; stroke: #bdb9ad; stroke-width: 2; }
.rocker__paddle { fill: #fbfaf6; stroke: #cfccc1; stroke-width: 1.5; transition: transform 0.12s; transform-box: fill-box; transform-origin: center; }
.rocker__on { fill: #d62d2d; opacity: 0; transition: opacity 0.12s; }
.rocker__label { fill: #8a8779; font-family: var(--font-ui); font-size: 10px; font-weight: 800; text-anchor: middle; }
.rocker.is-on .rocker__on { opacity: 1; }
.rocker.is-on .rocker__paddle { transform: scaleY(0.94); }
.mcb-status { fill: var(--ok); font-family: var(--font-ui); font-size: 13px; font-weight: 800; letter-spacing: 0.08em; text-anchor: middle; }
.mcb-status.is-tripped { fill: var(--danger); }

/* 10.2 Plug & fuse */
.plug__shell { fill: #1c1e22; stroke: #3a3f49; stroke-width: 2; }
.plug__cavity { fill: #30343c; }
.plug__brass { fill: #c9a24a; stroke: #7d6420; stroke-width: 1.5; }
.plug__tag { fill: #1d1600; font-family: var(--font-ui); font-size: 14px; font-weight: 900; text-anchor: middle; }
.plug__wire { fill: none; stroke-width: 9; stroke-linecap: round; }
.plug__wire--stripe { stroke: #e3c61b; stroke-dasharray: 10 10; }
.plug__clip { fill: #b7bcc4; stroke: #6f747c; stroke-width: 1.5; }
.plug__grip { fill: #4a4f58; }
.plug__cable { fill: #e8e6df; }
.fuse__body { fill: #f3efe6; stroke: #b9b2a2; stroke-width: 1.5; }
.fuse__cap { fill: #d4d8de; stroke: #7d838c; stroke-width: 1.5; }
.fuse__text { fill: #7a2020; font-family: var(--font-ui); font-size: 11px; font-weight: 800; text-anchor: middle; dominant-baseline: middle; }
.fuse__scorch,
.fuse__crack { opacity: 0; transition: opacity 0.2s; }
.fuse__scorch { fill: #3b2b1c; }
.fuse__crack { fill: none; stroke: #111; stroke-width: 2; }
.fuse.is-blown .fuse__scorch,
.fuse.is-blown .fuse__crack { opacity: 1; }

/* 10.3 Breadboard */
.bb__board { fill: #f3f1ea; stroke: #d6d2c4; stroke-width: 2; }
.bb__rail { fill: none; stroke-width: 3; }
.bb__rail--pos { stroke: #d33030; }
.bb__rail--neg { stroke: #2f6fd6; }
.bb__railtext { font-family: var(--font-ui); font-size: 22px; font-weight: 900; }
.bb__jumper { fill: none; stroke-width: 6; stroke-linecap: round; }
.bb__label { fill: #3c4048; font-family: var(--font-ui); font-size: 13px; font-weight: 800; text-anchor: middle; }
.pot__body { fill: #2f6fd1; stroke: #1c4790; stroke-width: 2; }
.psu__body { fill: #23262c; stroke: #4a505b; stroke-width: 1.5; }
.psu__text { fill: #e3e7ee; font-family: var(--font-ui); font-size: 13px; font-weight: 800; letter-spacing: 0.08em; }
.psu__led { fill: #3a2020; transition: fill 0.15s; }
.psu.is-on .psu__led { fill: #ff4b3e; filter: drop-shadow(0 0 4px #ff4b3e); }

/* LED glow: --glow (0–1) is set from the solved LED current by circuits.js */
.led__dome { fill: rgba(200, 30, 30, 0.75); stroke: #8c1414; stroke-width: 1.5; transition: fill 0.12s; }
.led__dome.is-lit { fill: #ff4a3d; }
.led__flange { fill: #b32020; }
.led__glow {
  --glow: 0;
  opacity: var(--glow);
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
  transition: opacity 0.15s;
}
.led__glow { animation: led-shimmer 1.6s ease-in-out infinite; }
@keyframes led-shimmer { 50% { transform: scale(1.06); } }

/* 10.4 Batteries */
.aa__body { fill: #1d1d20; stroke: #000; stroke-width: 1.5; }
.aa__band { fill: #d9a43a; }
.aa__cap { fill: #d4d8de; stroke: #7d838c; stroke-width: 1.5; }
.aa__text { fill: #f1f2f4; font-family: var(--font-ui); font-size: 18px; font-weight: 900; text-anchor: middle; }
.aa__small { fill: #a3acbd; font-family: var(--font-ui); font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-anchor: middle; }
.aa__sign { fill: #f1f2f4; font-family: var(--font-ui); font-size: 24px; font-weight: 900; text-anchor: middle; }
.aa__sign--dark { fill: #1d1d20; }
.pp3__body { fill: #1f3f7a; stroke: #0e2147; stroke-width: 2; }
.pp3__top { fill: #2a2d33; }
.pp3__big { fill: #f1f2f4; font-family: var(--font-ui); font-size: 56px; font-weight: 900; text-anchor: middle; }
.pp3__small { fill: #b8c4dc; font-family: var(--font-ui); font-size: 13px; font-weight: 800; letter-spacing: 0.1em; text-anchor: middle; }
.battery-state { fill: var(--accent); font-family: var(--font-ui); font-size: 14px; font-weight: 900; letter-spacing: 0.2em; text-anchor: middle; }

/* Keep the hazard banner clear of the docked mobile HUD when scrolled into view. */
@media (max-width: 767px) {
  .hazard-banner { scroll-margin-top: 40vh; }
}

/* ==========================================================================
   11. MISSION ACADEMY (Phase 3 — missions.js)
   ========================================================================== */

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.btn--small { padding: 0 12px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--bg-raised); border-color: var(--line-strong); }
.btn--go { border-color: var(--ok); background: rgba(61, 220, 151, 0.16); color: #c9ffe6; }
.btn--go:hover { background: rgba(61, 220, 151, 0.28); border-color: var(--ok); }

.mission-hud {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #1c2029, var(--bg-raised));
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  scroll-margin-top: 12px;
}
.mission-hud[hidden] { display: none; }

.mission-hud__bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.mission-hud__picker { flex: 1 1 220px; min-width: 0; }
.mission-hud__picker select {
  width: 100%;
  min-height: var(--tap);
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg-sunken);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 700;
}
.mission-hud__score { margin-left: auto; color: var(--text-muted); font-size: var(--fs-xs); font-weight: 700; }

.mission-hud__title { margin: 0; font-size: var(--fs-md); font-weight: 800; }
.mission-hud__intro { margin: 0; color: var(--text-muted); font-size: var(--fs-sm); max-width: 75ch; }
.mission-hud__away { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--warn); font-size: var(--fs-sm); font-weight: 700; }
.mission-hud__away[hidden] { display: none; }
.mission-hud__actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Checklist */
.mission-steps { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.mission-step {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text-faint);
  font-size: var(--fs-sm);
  transition: background-color 0.25s, color 0.25s;
}
.mission-step__box { flex: none; font-family: var(--font-lcd); font-weight: 700; }
.mission-step.is-current { background: rgba(255, 201, 40, 0.1); color: var(--text); font-weight: 700; }
.mission-step.is-current .mission-step__box { color: var(--accent); }
.mission-step.is-done { color: var(--ok); }
.mission-step.is-done .mission-step__box { animation: step-tick 0.4s ease-out; }
@keyframes step-tick {
  0% { transform: scale(1.6); }
  100% { transform: scale(1); }
}

/* Why this matters */
.mission-why { border: 1px solid var(--line); border-radius: 10px; background: var(--bg-sunken); }
.mission-why summary {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--focus);
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
}
.mission-why > div { padding: 0 12px 10px; color: var(--text-muted); font-size: var(--fs-sm); }
.mission-why p { margin: 6px 0 0; max-width: 75ch; }
.mission-why strong { color: var(--text); }

/* Completion banner */
.mission-done {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--ok);
  border-radius: 12px;
  background: rgba(61, 220, 151, 0.1);
  animation: done-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.mission-done[hidden] { display: none; }
.mission-done > div { flex: 1 1 200px; }
.mission-done__badge {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--ok);
  color: #04281a;
  font-size: 1.3rem;
  font-weight: 900;
}
.mission-done__title { margin: 0; color: var(--ok); font-weight: 800; }
.mission-done__text { margin: 2px 0 0; color: var(--text); font-size: var(--fs-sm); }
@keyframes done-in {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

/* Hint pulses — stroke/opacity only, so SVG transform attributes are left alone */
@keyframes hint-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
.pad.is-hint .pad__hit,
.jack.is-hint .jack__hit,
.dial__label.is-hint .dial__label-hit {
  stroke: var(--accent);
  stroke-width: 4;
  fill: rgba(255, 201, 40, 0.18);
  animation: hint-pulse 0.8s ease-in-out infinite;
}
#bench-svg [data-toggle].is-hint { filter: drop-shadow(0 0 8px var(--accent)); animation: hint-pulse 0.8s ease-in-out infinite; }
.btn.is-hint,
.segmented__btn.is-hint,
.scenario-range.is-hint {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  animation: hint-pulse 0.8s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .mission-step.is-done .mission-step__box,
  .mission-done,
  .is-hint,
  .is-hint .pad__hit,
  .is-hint .jack__hit,
  .is-hint .dial__label-hit { animation: none !important; }
}

@media (max-width: 767px) {
  .mission-hud { padding: 12px; gap: 8px; scroll-margin-top: 40vh; }
  .mission-hud__score { margin-left: 0; flex-basis: 100%; }
  .mission-hud__picker { order: -1; flex-basis: 100%; }
  .mission-hud__bar .btn { flex: 1 1 0; }
}

/* ==========================================================================
   12. TOUCH & VIEWPORT POLISH (Phase 4)
   ========================================================================== */

/* No double-tap-to-zoom delay. touch-action is not inherited and scroll
   containers reset the chain, so interactive elements get it explicitly. */
html,
:where(a, button, input, select, summary, label, [role="button"], [role="tab"], [tabindex]) {
  touch-action: manipulation;
}

/* Drag surfaces own the gesture: no page scroll or pull-to-refresh mid-drag. */
.probe,
.probe__handle,
.dial,
.dial__knob,
.dial__label { touch-action: none; }
#bench-svg, #meter-svg { overscroll-behavior: contain; }

/* Probe "in hand" (tap-selected): pulsing glow on the handle + ring, matching chip badge. */
.probe--red { --probe-glow: rgba(255, 92, 92, 0.95); }
.probe--black { --probe-glow: rgba(108, 196, 255, 0.95); }
.probe.is-selected .probe__halo {
  animation: march 1s linear infinite, halo-pulse 1.1s ease-in-out infinite;
}
.probe.is-selected .probe__handle,
.probe.is-selected .probe__boot {
  animation: handle-glow 1.1s ease-in-out infinite;
}
@keyframes halo-pulse {
  0%, 100% { fill: rgba(108, 196, 255, 0.06); stroke-width: 2.5; }
  50% { fill: rgba(108, 196, 255, 0.22); stroke-width: 4.5; }
}
@keyframes handle-glow {
  0%, 100% { filter: drop-shadow(0 0 2px var(--probe-glow)); }
  50% { filter: drop-shadow(0 0 12px var(--probe-glow)); }
}
.chip.is-selected { animation: chip-ring 1.1s ease-in-out infinite; }
.chip--red.is-selected { border-color: var(--probe-red); --chip-ring: rgba(255, 92, 92, 0.45); }
.chip--black.is-selected { --chip-ring: rgba(108, 196, 255, 0.45); }
@keyframes chip-ring {
  0%, 100% { box-shadow: 0 0 0 2px var(--chip-ring, rgba(108, 196, 255, 0.3)); }
  50% { box-shadow: 0 0 0 7px transparent; }
}

/* Compact Mission HUD on phones (iPhone SE 375px and up): the checklist
   scrolls internally so the bench and its pads stay close below. */
@media (max-width: 767px) {
  .mission-hud { padding: 10px 12px; gap: 6px; margin-bottom: 12px; }
  .mission-hud__bar { flex-wrap: nowrap; gap: 6px; }
  .mission-hud__bar .btn { flex: none; padding: 0 12px; }
  .mission-hud__picker { order: 0; flex: 1 1 auto; }
  .mission-hud__bar .btn__label { display: none; }
  .mission-hud__score { display: none; }
  .mission-hud__intro {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    font-size: var(--fs-xs);
  }
  .mission-steps {
    position: relative;   /* offsetTop reference for missions.js auto-scroll */
    max-height: 8.6rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    padding-right: 2px;
    gap: 2px;
  }
  .mission-step { padding: 5px 8px; gap: 8px; font-size: var(--fs-xs); line-height: 1.35; }
  .mission-hud__actions .btn { flex: 1 1 0; }
  .mission-why summary { min-height: 40px; }
  .mission-done { padding: 8px 10px; gap: 8px; }
  .mission-done__badge { width: 32px; height: 32px; font-size: 1.05rem; }
  .mission-done .btn { flex: 1 1 100%; }
}
