:root {
  --bg: #071019;
  --bg-soft: #0b151f;
  --panel: #101b27;
  --panel-2: #142232;
  --panel-3: #1a2a3b;
  --line: #2a4055;
  --line-soft: #203447;
  --text: #f5f8fb;
  --muted: #9fb1c5;
  --accent: #38a9ff;
  --accent-strong: #168fe8;
  --success: #44d27d;
  --warning: #ffc857;
  --danger: #ff6370;
  --ink: #06111b;
  --radius: 18px;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% -10%, rgba(56, 169, 255, 0.14), transparent 32%),
    linear-gradient(150deg, #061019, #0c1722 55%, #071019);
}

button, select, textarea, input { font: inherit; }
button, select, textarea {
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
button { cursor: pointer; }
button:focus-visible, select:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 3px solid rgba(56, 169, 255, 0.5);
  outline-offset: 2px;
}
select, textarea { width: 100%; padding: 0.8rem; }
textarea { resize: vertical; min-height: 120px; }
label { color: var(--muted); }

.topbar {
  min-height: 80px;
  padding: 12px clamp(16px, 4vw, 30px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(6, 16, 25, 0.94);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand-title { margin: 0; font-weight: 800; line-height: 1.15; font-size: clamp(1rem, 2.5vw, 1.2rem); }
.brand-subtitle { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.92rem; }

.app-shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: calc(100vh - 80px); }
.main-nav {
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(7, 16, 25, 0.72);
}
.nav-button {
  padding: 0.9rem 1rem;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}
.nav-button:hover { border-color: var(--line); color: var(--text); }
.nav-button.active { color: var(--ink); background: var(--accent); border-color: var(--accent); }

.main-content { width: 100%; max-width: 1500px; margin: 0 auto; padding: 24px; }
.view { display: none; animation: fadeIn 0.18s ease-out; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.card {
  background: linear-gradient(180deg, rgba(17, 29, 41, 0.98), rgba(11, 22, 32, 0.98));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(18px, 3vw, 28px);
  box-shadow: var(--shadow);
}
.card h1, .card h2, .card h3 { margin-top: 0; }
.hero-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 32px; }
.hero-card h1 { margin: 0.45rem 0 0.9rem; max-width: 900px; font-size: clamp(2rem, 5vw, 3.6rem); line-height: 1.05; }
.hero-badge {
  min-width: 170px;
  min-height: 170px;
  border-radius: 28px;
  border: 1px solid var(--line);
  background: linear-gradient(150deg, var(--panel-3), #0c1722);
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
}
.hero-badge span, .hero-badge small { color: var(--muted); }
.hero-badge strong { font-size: 4.5rem; line-height: 0.95; color: var(--accent); }

.eyebrow { color: var(--accent); font-size: 0.76rem; letter-spacing: 0.16em; font-weight: 900; margin: 0 0 0.45rem; }
.muted { color: var(--muted); }
.large-copy { font-size: 1.08rem; line-height: 1.65; }
.page-heading { margin-bottom: 18px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.section-heading h1, .section-heading h2 { margin: 0.25rem 0 0; }

.button-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.button { padding: 0.85rem 1.1rem; font-weight: 800; transition: transform 0.12s ease, filter 0.12s ease; }
.button:hover { filter: brightness(1.08); }
.button:active { transform: translateY(1px); }
.button-primary { background: var(--accent); color: var(--ink); border-color: var(--accent); }
.button-secondary { background: var(--panel-2); border-color: var(--line); }
.button-danger { background: var(--danger); color: var(--ink); border-color: var(--danger); }
.button.compact { padding: 0.7rem 0.9rem; }
.full-width { width: 100%; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 16px 0; }
.stat-card span { display: block; color: var(--muted); margin-bottom: 0.4rem; }
.stat-card strong { font-size: clamp(2rem, 4vw, 3rem); line-height: 1; }
.two-column { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.9fr); gap: 16px; }
.dashboard-grid { align-items: start; }
.status-pill { display: inline-flex; align-items: center; justify-content: center; padding: 0.45rem 0.7rem; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.status-pill.complete { border-color: rgba(68, 210, 125, 0.5); color: var(--success); }
.status-pill.in-progress { border-color: rgba(56, 169, 255, 0.5); color: var(--accent); }
.progress-track { height: 12px; border-radius: 999px; overflow: hidden; background: #07111a; border: 1px solid var(--line-soft); margin-top: 20px; }
.progress-track span { display: block; width: 0%; height: 100%; background: linear-gradient(90deg, var(--accent-strong), var(--success)); transition: width 0.25s ease; }
.progress-copy { color: var(--muted); margin: 8px 0 18px; }
.mini-path { margin: 0; padding-left: 1.4rem; color: var(--muted); }
.mini-path li { padding: 0.35rem 0; }
.mini-path li.complete { color: var(--success); }
.roadmap-list { display: grid; gap: 10px; }
.roadmap-item { display: grid; grid-template-columns: 42px 1fr; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line-soft); border-radius: 14px; opacity: 0.72; }
.roadmap-item > span { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; background: var(--panel-3); font-weight: 900; }
.roadmap-item strong, .roadmap-item small { display: block; }
.roadmap-item small { color: var(--muted); margin-top: 3px; line-height: 1.35; }
.roadmap-item.active { opacity: 1; border-color: rgba(56, 169, 255, 0.65); }
.roadmap-item.active > span { background: var(--accent); color: var(--ink); }

.lesson-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.lesson-sidebar { position: sticky; top: 105px; display: grid; gap: 8px; }
.stage-button { width: 100%; display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 10px; padding: 0.8rem; text-align: left; color: var(--muted); background: transparent; border-color: transparent; }
.stage-button span { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: var(--panel-3); font-weight: 900; }
.stage-button.active { color: var(--text); border-color: var(--line); background: var(--panel-2); }
.stage-button.complete { color: var(--success); }
.stage-button.complete span { background: rgba(68, 210, 125, 0.15); color: var(--success); }
.lesson-stage { display: none; }
.lesson-stage.active { display: block; }
.lesson-stage h2 { font-size: clamp(1.7rem, 4vw, 2.5rem); margin-bottom: 0.65rem; }
.checklist { display: grid; gap: 10px; margin: 20px 0; }
.checklist label { display: flex; flex-direction: row; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid var(--line-soft); border-radius: 12px; background: rgba(20, 34, 50, 0.55); color: var(--text); }
.checklist input { margin-top: 0.2rem; accent-color: var(--accent); }
.instruction-box, .result-box { margin: 18px 0; padding: 14px; border-radius: 12px; border-left: 4px solid var(--accent); background: var(--panel-2); }
.instruction-box p { margin: 0.4rem 0 0; color: var(--muted); }
.inline-message { min-height: 1.5em; color: var(--muted); }
.inline-message.success { color: var(--success); }
.inline-message.error { color: var(--danger); }
.target-reading { margin: 18px 0; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-2); }
.target-reading span, .target-reading small { display: block; color: var(--muted); }
.target-reading strong { display: block; font-size: 1.05rem; margin: 5px 0; }
.target-reading.complete { border-color: rgba(68, 210, 125, 0.65); box-shadow: inset 0 0 0 1px rgba(68, 210, 125, 0.2); }
.required-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.circuit-path { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
.circuit-path button { padding: 0.7rem 0.8rem; font-weight: 800; }
.circuit-path i { color: var(--accent); font-style: normal; font-weight: 900; }
.field-label { display: block; margin-bottom: 7px; }

.cabinet-layout { grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.75fr); }
.cabinet {
  min-height: 620px;
  border: 3px solid #53687b;
  border-radius: 14px;
  padding: 24px;
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-template-rows: 85px 110px 140px 120px 85px;
  gap: 10px;
  background: repeating-linear-gradient(90deg, #111d29 0 30px, #172735 30px 32px);
}
.device { position: relative; overflow: hidden; min-width: 0; display: grid; place-items: center; color: #071019; background: #dfe8ee; border: 2px solid #8396a7; border-radius: 4px; }
.device:hover { filter: brightness(1.04); }
.device.selected { outline: 4px solid var(--accent); outline-offset: 2px; }
.device label { position: absolute; bottom: 3px; max-width: 100%; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; font-size: 0.62rem; font-weight: 900; color: #071019; white-space: nowrap; }
.cabinet.labels-hidden .device label { display: none; }
.terminals { grid-column: 1 / 13; }
.breakers { grid-column: 1 / 4; }
.fuses { grid-column: 4 / 8; }
.psu { grid-column: 8 / 13; }
.plc { grid-column: 1 / 5; }
.di { grid-column: 5 / 8; }
.do { grid-column: 8 / 11; }
.network { grid-column: 11 / 13; }
.relays { grid-column: 1 / 13; }
.outputs { grid-column: 1 / 8; }
.ground { grid-column: 8 / 13; }
.device-shape { min-width: 66%; padding: 17px 8px; text-align: center; font-weight: 900; border: 2px solid #607487; background: #f2f6f8; }
.terminal-strip { width: 94%; height: 45px; background: repeating-linear-gradient(90deg, #eff4f7 0 35px, #607487 35px 38px); }
.relay-bank { display: flex; gap: 8px; width: 94%; }
.relay-bank i { flex: 1; padding: 20px 0; border: 1px solid #607487; background: #f3f6f7; font-style: normal; font-weight: 800; }
.relay-bank i.active { background: #b9ffd0; }
.indicator { position: absolute; top: 8px; right: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--danger); }
.indicator.on { background: var(--success); box-shadow: 0 0 12px var(--success); }
.device-preview { min-height: 145px; margin-bottom: 16px; display: grid; place-items: center; text-align: center; border: 1px dashed var(--line); border-radius: 14px; background: var(--panel-2); font-weight: 900; font-size: 1.3rem; }
dl { margin: 0; }
dt { margin-top: 15px; color: var(--accent); font-size: 0.78rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.08em; }
dd { margin: 4px 0 0; color: var(--muted); line-height: 1.5; }

.meter-layout { align-items: start; }
.meter-controls { margin-bottom: 14px; }
.control-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.control-grid label { display: flex; flex-direction: column; gap: 6px; }
.switch-field span:last-child { min-height: 47px; display: flex; align-items: center; gap: 8px; padding: 0.75rem; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); color: var(--text); }
.meter-safety-strip { margin: 14px 0; padding: 12px; border: 1px solid var(--line-soft); border-radius: 12px; background: rgba(255, 200, 87, 0.06); }
.meter-safety-strip label { display: flex; gap: 9px; align-items: flex-start; color: var(--text); }
.meter-body { background: linear-gradient(180deg, #dbe1e6, #bec8d0); color: #08111a; }
.meter-screen { min-height: 120px; display: flex; align-items: end; justify-content: end; gap: 10px; padding: 18px; background: #b8d1af; border: 9px solid #29343d; border-radius: 10px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.meter-screen span { font-size: clamp(3rem, 9vw, 5rem); line-height: 1; }
.meter-screen small { padding-bottom: 0.45rem; font-size: 1rem; }
.lead-display { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.lead-card { min-height: 80px; padding: 14px; border: 3px solid; border-radius: 12px; display: flex; flex-direction: column; gap: 6px; }
.black-lead { color: #0b0f13; background: #eef1f3; border-color: #111; }
.red-lead { color: #4a0c12; background: #ffe6e8; border-color: #a51e29; }
.instructor-panel h3 { margin: 18px 0 5px; font-size: 0.92rem; }
.history-card { margin-top: 16px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line-soft); text-align: left; }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.07em; }
.useful { color: var(--success); }
.low-value { color: var(--warning); }
.unsafe { color: var(--danger); }

.trouble-ticket { margin-bottom: 14px; }
.trouble-ticket h2 { font-size: clamp(1.7rem, 4vw, 2.5rem); }
.diagnosis-card { margin-top: 14px; }
.diagnosis-card > label { display: flex; flex-direction: column; gap: 6px; max-width: 700px; }
.diagnosis-checks { grid-template-columns: 1fr 1fr; }
.result-box:empty { display: none; }
.result-box.success { border-left-color: var(--success); }
.result-box.error { border-left-color: var(--danger); }
.quality-list { color: var(--muted); line-height: 1.8; }
.evidence-list-card { margin-top: 14px; }
.evidence-entry { padding: 14px; border-left: 4px solid var(--accent); background: var(--panel-2); border-radius: 10px; margin-bottom: 10px; }
.evidence-entry:last-child { margin-bottom: 0; }
.evidence-entry strong { display: block; margin-bottom: 5px; }
.site-footer { padding: 18px 24px calc(18px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--muted); text-align: center; font-size: 0.83rem; }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 1fr; }
  .main-nav {
    position: sticky;
    top: 80px;
    z-index: 15;
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    background: rgba(7, 16, 25, 0.96);
    scrollbar-width: thin;
  }
  .nav-button { text-align: center; }
  .lesson-layout { grid-template-columns: 1fr; }
  .lesson-sidebar { position: static; display: flex; overflow-x: auto; }
  .stage-button { min-width: 190px; }
}

@media (max-width: 800px) {
  .main-content { padding: 14px; }
  .hero-card { grid-template-columns: 1fr; }
  .hero-badge { min-width: 0; min-height: 120px; grid-auto-flow: column; gap: 12px; }
  .hero-badge strong { font-size: 3rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .two-column, .cabinet-layout { grid-template-columns: 1fr; }
  .required-grid, .diagnosis-checks { grid-template-columns: 1fr; }
  .cabinet { min-height: 540px; padding: 15px; gap: 7px; grid-template-rows: 75px 96px 126px 108px 76px; }
}

@media (max-width: 560px) {
  .topbar { align-items: flex-start; }
  .brand-subtitle { font-size: 0.8rem; }
  .button.compact { padding: 0.65rem 0.72rem; }
  .stats-grid { gap: 10px; }
  .stat-card { padding: 16px; }
  .stat-card strong { font-size: 2.25rem; }
  .control-grid, .lead-display { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; }
  .section-heading.page-heading { flex-direction: column; }
  .cabinet { min-height: 500px; padding: 10px; gap: 6px; }
  .device label { font-size: 0.54rem; }
  .device-shape { min-width: 76%; padding: 13px 5px; font-size: 0.75rem; }
  .relay-bank { gap: 4px; }
  .relay-bank i { padding: 17px 0; font-size: 0.72rem; }
  .terminal-strip { height: 36px; }
}


/* --- Step 2: Schematic tracing --- */
.button-row.wrap { flex-wrap: wrap; }
.compact-heading { gap: 16px; }
.trace-overview-card { margin-bottom: 16px; }
.trace-path-buttons .button.active-path { background: var(--accent); color: var(--ink); border-color: rgba(56, 169, 255, 0.65); }
.trace-layout { align-items: start; }
.trace-schematic { display: grid; gap: 14px; }
.trace-row { display: none; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 8px; align-items: center; padding: 12px; border-radius: 14px; border: 1px solid var(--line-soft); background: rgba(20, 34, 50, 0.42); opacity: 0.52; transition: opacity 160ms ease, border-color 160ms ease, transform 160ms ease; }
.trace-row.active { display: grid; opacity: 1; border-color: var(--line); background: rgba(20, 34, 50, 0.78); transform: translateY(-1px); }
.trace-row.complete { box-shadow: inset 0 0 0 1px rgba(68, 210, 125, 0.28); }
.trace-node { width: 100%; min-height: 86px; padding: 10px 8px; display: grid; place-items: center; text-align: center; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(180deg, rgba(22, 37, 54, 0.97), rgba(14, 24, 37, 0.95)); color: var(--text); font-size: 0.88rem; font-weight: 800; line-height: 1.25; }
.trace-node:hover { border-color: rgba(56, 169, 255, 0.55); }
.trace-node.selected { border-color: rgba(56, 169, 255, 0.75); box-shadow: 0 0 0 2px rgba(56, 169, 255, 0.2); }
.trace-node.complete { border-color: rgba(68, 210, 125, 0.7); background: linear-gradient(180deg, rgba(22, 52, 40, 0.95), rgba(16, 39, 31, 0.95)); }
.trace-link { height: 6px; border-radius: 999px; background: rgba(101, 122, 143, 0.38); }
.trace-link.active { background: linear-gradient(90deg, rgba(56, 169, 255, 0.9), rgba(68, 210, 125, 0.9)); box-shadow: 0 0 12px rgba(56, 169, 255, 0.25); }
.top-gap { margin-top: 16px; }
#traceHint.success, #traceMessage.success { color: var(--success); }
#traceHint.error, #traceMessage.error { color: var(--danger); }
.mini-path li.complete { color: var(--success); }
.mini-path li.current { color: var(--text); font-weight: 900; }
@media (max-width: 1100px) {
  .trace-row { grid-template-columns: 1fr; }
  .trace-link { width: 6px; height: 22px; justify-self: center; }
  .trace-node { min-height: 64px; }
}


/* V3.1 hotfix: reliable touch targets and active-path-only rendering */
.trace-node { touch-action: manipulation; -webkit-tap-highlight-color: rgba(56, 169, 255, 0.22); cursor: pointer; }
.trace-path-buttons .button { touch-action: manipulation; }
@media (max-width: 1100px) {
  .trace-row.active { display: grid; grid-template-columns: 1fr; }
  .trace-node { min-height: 66px; font-size: 1rem; }
}


/* --- Step 3: randomized hidden-fault engine --- */
.hidden, .visually-hidden { display: none !important; }
.roadmap-item.complete { opacity: 0.9; border-color: rgba(68, 210, 125, 0.45); }
.roadmap-item.complete > span { background: rgba(68, 210, 125, 0.18); color: var(--success); }
.dashboard-challenge-card { margin-bottom: 16px; }
.challenge-mini-stats { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.challenge-mini-stats span { padding: 10px 12px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--panel-2); color: var(--muted); }
.challenge-mini-stats strong { color: var(--text); }
.challenge-control-card { margin-bottom: 14px; }
.challenge-session-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.challenge-session-grid > div, .condition-grid > div { min-width: 0; padding: 14px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--panel-2); }
.challenge-session-grid span, .condition-grid span { display: block; color: var(--muted); font-size: 0.8rem; }
.challenge-session-grid strong { display: block; margin-top: 4px; font-size: 1.45rem; }
.condition-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin-top: 18px; }
.condition-grid strong { display: block; margin-top: 4px; font-size: 1rem; }
.condition-grid strong.on-state { color: var(--success); }
.condition-grid strong.off-state { color: var(--warning); }
.challenge-work-layout { align-items: stretch; margin-bottom: 14px; }
.challenge-coach-card { height: 100%; }
.compact-list { margin-bottom: 18px; }
.challenge-safety-line { display: flex !important; flex-direction: row !important; align-items: flex-start; gap: 10px; padding: 12px; margin-bottom: 16px; border: 1px solid var(--line-soft); border-radius: 12px; background: rgba(255, 200, 87, 0.06); }
.challenge-readings-card { margin-top: 14px; }
.challenge-reading { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
.challenge-reading:last-child { border-bottom: 0; }
.challenge-reading-index { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: var(--panel-3); font-weight: 900; }
.challenge-reading small { display: block; margin-top: 4px; color: var(--muted); }
.challenge-reading .reading-grade { font-size: 0.8rem; font-weight: 900; white-space: nowrap; }
.challenge-reading .reading-grade.useful { color: var(--success); }
.challenge-reading .reading-grade.penalty { color: var(--warning); }
.challenge-reading .reading-grade.unsafe { color: var(--danger); }
.meter-heading-actions { align-items: center; }
@media (max-width: 800px) {
  .challenge-session-grid { grid-template-columns: 1fr 1fr; }
  .condition-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .challenge-session-grid, .condition-grid { grid-template-columns: 1fr 1fr; }
  .challenge-session-grid strong { font-size: 1.2rem; }
  .challenge-reading { grid-template-columns: auto 1fr; }
  .challenge-reading .reading-grade { grid-column: 2; }
}


/* --- Step 4: integrated tap-to-probe meter --- */
.live-bench-card { margin: 14px 0; }
.probe-bench-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr); gap: 16px; align-items: start; }
.probe-map { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: repeating-linear-gradient(90deg, rgba(17,29,41,.97) 0 30px, rgba(23,39,53,.97) 30px 32px); }
.probe-map-header { display: flex; justify-content: space-between; gap: 12px; align-items: start; margin-bottom: 12px; }
.probe-map-header span { max-width: 520px; color: var(--muted); font-size: .82rem; text-align: right; }
.probe-zone { margin-top: 10px; padding: 12px; border: 1px solid rgba(115,142,166,.35); border-radius: 14px; background: rgba(7,16,25,.58); }
.probe-zone > p { margin: 0 0 10px; color: var(--accent); font-size: .72rem; font-weight: 900; letter-spacing: .12em; }
.probe-points-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 9px; }
.probe-point { position: relative; min-height: 88px; padding: 10px 8px; display: grid; place-items: center; gap: 2px; text-align: center; color: var(--text); border: 2px solid var(--line); border-radius: 13px; background: linear-gradient(180deg, rgba(28,45,62,.98), rgba(14,25,38,.98)); }
.probe-point span { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; color: #08111a; background: #dce7ee; font-size: .72rem; font-weight: 1000; }
.probe-point strong { font-size: .79rem; line-height: 1.2; }
.probe-point small { color: var(--muted); font-size: .65rem; }
.probe-point.reference-point { border-style: dashed; }
.probe-point.black-probe { box-shadow: 0 0 0 4px rgba(240,244,247,.18), inset 0 0 0 3px #111; }
.probe-point.black-probe::before { content: 'BLACK'; position: absolute; top: 4px; left: 5px; padding: 2px 5px; border-radius: 999px; color: #fff; background: #080b0f; font-size: .52rem; font-weight: 900; }
.probe-point.red-probe { box-shadow: 0 0 0 4px rgba(255,84,96,.18), inset 0 0 0 3px #d42b37; }
.probe-point.red-probe::after { content: 'RED'; position: absolute; top: 4px; right: 5px; padding: 2px 5px; border-radius: 999px; color: #fff; background: #b51f2b; font-size: .52rem; font-weight: 900; }
.probe-point:active { transform: scale(.98); }
.integrated-meter { position: sticky; top: 105px; padding: 16px; border-radius: 20px; color: #08111a; background: linear-gradient(180deg, #dce2e7, #aebac4); border: 3px solid #667783; box-shadow: 0 18px 40px rgba(0,0,0,.25); }
.meter-function-bank { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-bottom: 12px; }
.meter-dial-button { min-height: 48px; padding: 7px; color: #16222c; background: #eef3f6; border-color: #8496a4; font-weight: 1000; }
.meter-dial-button.active { color: #06111a; background: #38a9ff; border-color: #157dc5; box-shadow: inset 0 0 0 2px rgba(255,255,255,.45); }
.integrated-meter-screen { min-height: 145px; display: grid; grid-template-columns: 1fr auto; align-content: end; gap: 5px 10px; padding: 16px; border: 9px solid #27343e; border-radius: 12px; background: #b7d0ad; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.integrated-meter-screen span { font-size: clamp(3.1rem, 8vw, 5rem); line-height: .9; text-align: right; }
.integrated-meter-screen small { align-self: end; padding-bottom: 5px; font-weight: 900; }
.integrated-meter-screen em { grid-column: 1 / -1; color: #293d2a; font-family: inherit; font-size: .78rem; font-style: normal; text-align: right; }
.live-lead-selector { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 12px; }
.live-lead-button { min-height: 85px; padding: 10px; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; border-width: 3px; }
.live-lead-button span { font-weight: 1000; }
.live-lead-button small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-lead-button.black { color: #111820; background: #f1f4f6; border-color: #111; }
.live-lead-button.red { color: #5f0a12; background: #ffe9eb; border-color: #b6212d; }
.live-lead-button.active { outline: 4px solid #38a9ff; outline-offset: 2px; }
.live-power-toggle { display: flex; flex-direction: row !important; align-items: center; gap: 8px; margin: 12px 0; padding: 10px; border: 1px solid #72828e; border-radius: 10px; color: #111820; background: rgba(255,255,255,.4); }
.live-meter-actions { margin-top: 4px; }
.live-meter-actions .button { flex: 1 1 135px; }
.live-meter-coach { margin-top: 12px; padding: 12px; border-left: 4px solid #157dc5; border-radius: 10px; background: rgba(255,255,255,.46); }
.live-meter-coach p { margin: 5px 0 0; color: #364650; }
@media (max-width: 980px) {
  .probe-bench-layout { grid-template-columns: 1fr; }
  .integrated-meter { position: static; }
}
@media (max-width: 560px) {
  .probe-map { padding: 10px; }
  .probe-map-header { flex-direction: column; }
  .probe-map-header span { text-align: left; }
  .probe-points-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .probe-point { min-height: 82px; }
  .integrated-meter-screen { min-height: 125px; }
  .integrated-meter-screen span { font-size: 3.2rem; }
}

/* Keep horizontal navigation scroll isolated from the page on mobile. */
html, body { max-width: 100%; overflow-x: hidden; }
.app-shell, .main-content, .main-nav, .view, .card { min-width: 0; }
@media (max-width: 1050px) {
  .app-shell, .main-nav, .main-content { width: 100%; max-width: 100%; }
  .main-nav { min-width: 0; }
}
@media (max-width: 980px) {
  .probe-bench-layout { grid-template-columns: minmax(0, 1fr); }
  .probe-map, .integrated-meter { width: 100%; max-width: 100%; min-width: 0; }
  .integrated-meter { overflow: hidden; }
}


/* --- Step 5: unified live circuit engine --- */
.engine-toolbar-card { margin-bottom: 16px; }
.engine-summary-grid, .engine-state-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.engine-summary-grid > div, .engine-state-grid > div { padding: 13px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--panel-2); }
.engine-summary-grid span, .engine-state-grid span { display: block; color: var(--muted); font-size: .77rem; }
.engine-summary-grid strong, .engine-state-grid strong { display: block; margin-top: 4px; }
.engine-main-layout { grid-template-columns: minmax(0, 1.55fr) minmax(310px, .65fr); align-items: start; }
.engine-diagram-card { overflow: hidden; }
.engine-path-group { margin-top: 12px; padding: 12px; border: 1px solid var(--line-soft); border-radius: 14px; background: rgba(10, 22, 34, .55); }
.engine-path-group > p { margin: 0 0 9px; color: var(--accent); font-size: .68rem; font-weight: 900; letter-spacing: .12em; }
.engine-flow-row { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 7px; align-items: center; }
.engine-node, .engine-component, .engine-end-state { min-width: 0; min-height: 92px; padding: 10px 7px; display: grid; place-items: center; align-content: center; gap: 4px; text-align: center; color: var(--text); border: 1px solid var(--line); border-radius: 12px; background: linear-gradient(180deg, rgba(26,43,60,.98), rgba(13,24,36,.98)); }
.engine-node small, .engine-component small, .engine-end-state small { color: var(--muted); font-size: .59rem; font-weight: 900; letter-spacing: .06em; }
.engine-node strong, .engine-component strong, .engine-end-state strong { font-size: .78rem; line-height: 1.18; }
.engine-node em, .engine-component em { color: var(--muted); font-size: .64rem; font-style: normal; font-weight: 900; }
.engine-node.energized, .engine-component.energized { border-color: rgba(68,210,125,.72); background: linear-gradient(180deg, rgba(25,65,47,.96), rgba(14,40,30,.98)); box-shadow: inset 0 0 0 1px rgba(68,210,125,.16); }
.engine-node.faulted, .engine-component.faulted { border-color: rgba(255,98,110,.75); background: linear-gradient(180deg, rgba(79,30,38,.95), rgba(45,18,25,.98)); }
.engine-node.selected, .engine-reference.black-probe, .engine-reference.red-probe { outline: 3px solid var(--accent); outline-offset: 2px; }
.engine-wire { min-width: 18px; height: 6px; border-radius: 999px; background: rgba(105,125,145,.3); }
.engine-wire.energized { background: linear-gradient(90deg, #36a8ff, #44d27d); box-shadow: 0 0 10px rgba(68,210,125,.28); }
.engine-reference-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin-top: 12px; }
.engine-reference { min-height: 70px; padding: 10px; border: 1px dashed var(--line); border-radius: 12px; color: var(--text); background: var(--panel-2); }
.engine-reference strong, .engine-reference small { display: block; }
.engine-reference small { margin-top: 3px; color: var(--muted); }
.engine-toggle-grid { display: grid; gap: 8px; margin-top: 14px; }
.engine-toggle-grid label { display: flex; gap: 9px; align-items: flex-start; padding: 10px; border: 1px solid var(--line-soft); border-radius: 10px; background: var(--panel-2); color: var(--text); }
.engine-toggle-grid input { margin-top: .15rem; accent-color: var(--accent); }
.engine-tip-box { margin-bottom: 0; }
.engine-lower-layout { margin-top: 16px; }
.engine-event-log { max-height: 340px; overflow: auto; }
.engine-log-entry { padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.engine-log-entry:last-child { border-bottom: 0; }
.engine-log-entry strong { display: block; }
.engine-log-entry small { color: var(--muted); }

/* Shared meter dock */
.global-meter-dock { position: fixed; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 80; width: min(390px, calc(100vw - 28px)); border: 1px solid var(--line); border-radius: 18px; background: rgba(8,17,26,.98); box-shadow: 0 18px 50px rgba(0,0,0,.42); overflow: hidden; }
.global-meter-tab { width: 100%; min-height: 52px; padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; color: var(--text); background: linear-gradient(90deg, #122235, #172d43); border: 0; border-radius: 0; }
.global-meter-tab span { color: var(--accent); font-size: .72rem; font-weight: 1000; letter-spacing: .14em; }
.global-meter-tab strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.1rem; }
.global-meter-panel { padding: 13px; }
.global-meter-dock.collapsed .global-meter-panel { display: none; }
.global-meter-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.global-meter-head p { margin-bottom: 3px; }
.dock-mode-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 12px; }
.dock-screen { min-height: 92px; margin-top: 10px; padding: 12px; display: grid; grid-template-columns: 1fr auto; align-items: end; border: 7px solid #29343d; border-radius: 10px; color: #08111a; background: #b8d1af; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.dock-screen span { font-size: 2.65rem; line-height: 1; }
.dock-screen small { padding-bottom: .3rem; }
.dock-screen em { grid-column: 1 / -1; margin-top: 5px; font-size: .67rem; font-style: normal; }
.dock-leads { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.dock-safety { display: flex; gap: 8px; align-items: flex-start; margin-top: 10px; color: var(--muted); font-size: .76rem; }
.dock-actions { margin-top: 10px; }
.dock-actions .button { flex: 1 1 115px; }
[data-probe-point] { touch-action: manipulation; -webkit-tap-highlight-color: rgba(56,169,255,.22); }
[data-probe-point].black-probe { box-shadow: 0 0 0 3px rgba(255,255,255,.2), inset 0 0 0 3px #0a0d11; }
[data-probe-point].red-probe { box-shadow: 0 0 0 3px rgba(255,80,90,.18), inset 0 0 0 3px #d42b37; }

@media (max-width: 1150px) {
  .engine-main-layout { grid-template-columns: 1fr; }
  .engine-flow-row { grid-template-columns: 1fr; }
  .engine-wire { width: 6px; height: 20px; justify-self: center; }
  .engine-node, .engine-component, .engine-end-state { min-height: 66px; }
}
@media (max-width: 800px) {
  .engine-summary-grid, .engine-state-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .engine-summary-grid, .engine-state-grid, .engine-reference-row { grid-template-columns: 1fr; }
  .global-meter-dock { right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); width: calc(100vw - 16px); }
  .dock-screen span { font-size: 2.15rem; }
}
