:root {
  --bg: #11100e;
  --panel: #1a1916;
  --panel-2: #22211d;
  --line: #33312c;
  --text: #f3eee3;
  --muted: #9c9689;
  --accent: #e8b84a;
  --accent-dim: rgba(232, 184, 74, 0.22);
  --installed: #3d8b74;
  --installed-dim: rgba(61, 139, 116, 0.38);
  --find: #5ec8e8;
  --find-dim: rgba(94, 200, 232, 0.35);
  --danger: #d36b5a;
  --nav-w: 320px;
  --radius: 10px;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", "Consolas", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

.app {
  display: grid;
  grid-template-columns: var(--nav-w) 6px 1fr;
  grid-template-rows: auto 1fr;
  height: 100%;
}
.app.solo-nav { grid-template-columns: 1fr 0 0; }
.app.solo-nav .workspace,
.app.solo-nav [data-split="nav"] { display: none; }

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 58px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: #0d0c0b;
}
.nav-toggle {
  display: none;
  width: 38px;
  height: 38px;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}
.nav-toggle span {
  display: block;
  height: 2px;
  margin: 5px 0;
  background: var(--text);
}
.brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}
.brand strong { font-size: 15px; letter-spacing: 0.04em; text-transform: uppercase; }
.brand span { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand:hover strong { color: var(--accent); }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.label-short { display: none; }

.midi-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.find-wrap { position: relative; width: min(280px, 36vw); }
.find-wrap input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}
.find-status {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: min(420px, 90vw);
  margin: 0;
  padding: 6px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  z-index: 5;
}
.find-hit {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--find);
  border-radius: 99px;
  padding: 2px 8px;
  font: 11px var(--mono);
  cursor: pointer;
}
.find-hit:hover { border-color: var(--find); }
.find-status[hidden] { display: none !important; }

.nav {
  overflow: auto;
  background: var(--panel);
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.nav #nav-list { overflow: auto; flex: 1; }
.progress {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 14px 14px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.progress-track { height: 6px; background: #2a2823; border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); }
.progress span { display: block; margin-top: 8px; color: var(--muted); font-size: 12px; }
.text-btn {
  margin-top: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
}

.section {
  border-bottom: 1px solid var(--line);
}
.section > button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-weight: 600;
}
.section > button small { color: var(--muted); font-weight: 400; }
.section.collapsed .step-list { display: none; }

.step-list { list-style: none; margin: 0; padding: 0 8px 10px; }
.step-list li { margin: 0; }
.step-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 6px;
  align-items: start;
  border-radius: 6px;
}
.step-row:hover { background: var(--panel-2); }
.step-row.current { background: var(--accent-dim); }
.step-check {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin: 9px 0 0 6px;
  border: 1px solid #7a7468;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
}
.step-check:hover { border-color: var(--text); }
.step-check:checked {
  background: var(--installed);
  border-color: var(--installed);
}
.step-link {
  width: 100%;
  display: block;
  padding: 7px 8px 7px 2px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}
.step-link.done { color: #c8d6cf; }
.step-link .opt { color: var(--muted); font-size: 11px; }

.workspace {
  display: grid;
  grid-template-rows: var(--board-pct, 58%) 6px 1fr;
  min-width: 0;
  min-height: 0;
}
.workspace.solo-board {
  grid-template-rows: minmax(0, 1fr);
}
.workspace.solo-board .workspace-lower,
.workspace.solo-board [data-split="board"] { display: none; }
.workspace.solo-lower {
  grid-template-rows: minmax(0, 1fr);
}
.workspace.solo-lower .board-pane,
.workspace.solo-lower [data-split="board"] { display: none; }
.workspace.solo-lower .workspace-lower { height: 100%; }

.workspace-lower {
  display: grid;
  grid-template-columns: var(--comp-pct, 40%) 6px 1fr;
  min-width: 0;
  min-height: 0;
}
.workspace-lower.solo-component {
  grid-template-columns: minmax(0, 1fr);
}
.workspace-lower.solo-component .step-pane,
.workspace-lower.solo-component [data-split="comp"] { display: none; }
.workspace-lower.solo-component .component-pane { max-height: none; height: 100%; }
.workspace-lower.solo-component .comp-card { max-width: 720px; }
.workspace-lower.solo-component .comp-visuals { grid-template-columns: 140px 1fr; }
.workspace-lower.solo-component .resistor-svg { max-width: 480px; }
.workspace-lower.solo-step {
  grid-template-columns: minmax(0, 1fr);
}
.workspace-lower.solo-step .component-pane,
.workspace-lower.solo-step [data-split="comp"] { display: none; }
.workspace-lower.solo-step .step-pane { height: 100%; }

.splitter {
  background: var(--line);
  z-index: 3;
}
.splitter.col { cursor: col-resize; }
.splitter.row { cursor: row-resize; }
.splitter:hover,
.splitter.active { background: var(--accent); }

.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pane-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  background: #141310;
  flex: 0 0 auto;
}
.pane-bar span {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.pane-tools { display: flex; align-items: center; gap: 8px; }
.pane-btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
}
.pane-btn[aria-pressed="true"] {
  background: var(--accent);
  color: #1a1406;
  border-color: var(--accent);
}
.pane-body { overflow: auto; flex: 1; min-height: 0; }

.board-pane { background: #0a0908; }
.board-caption { color: var(--muted); }
.zoom-btns { display: flex; gap: 6px; }
.zoom-btns button, .pdf-panel header button, .step-actions button, .ghost, .primary {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 7px;
  padding: 6px 10px;
  cursor: pointer;
}
.primary {
  background: var(--accent);
  color: #1a1406;
  border-color: var(--accent);
  font-weight: 700;
}
#step-done {
  padding: 5px 10px;
  font-size: 12px;
  white-space: nowrap;
}
.board-viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
  cursor: grab;
}
.board-viewport.dragging { cursor: grabbing; }
.board-world {
  position: absolute;
  width: 1100px;
  line-height: 0;
  transform-origin: 0 0;
  user-select: none;
}
.board-world img {
  display: block;
  width: 1100px;
  height: auto;
  background: #fff;
}
.board-overlays {
  position: absolute;
  top: 0;
  left: 0;
  width: 1100px;
  height: 100%;
}
button.hotspot,
.hotspot {
  all: unset;
  position: absolute;
  display: block;
  box-sizing: border-box;
  border: 1.5px solid transparent;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
}
.hotspot.current {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 1px rgba(232, 184, 74, 0.35);
  animation: pulse 1.4s ease-in-out infinite;
}
.hotspot.installed {
  border-color: rgba(61, 139, 116, 0.8);
  background: var(--installed-dim);
}
.hotspot.find {
  border-color: var(--find);
  background: var(--find-dim);
}
.hotspot.current.installed { background: color-mix(in srgb, var(--accent) 28%, var(--installed) 35%); }
.hotspot:not(.current):not(.installed):not(.find):hover {
  border-color: rgba(243, 238, 227, 0.4);
  background: rgba(243, 238, 227, 0.08);
}
.tooltip {
  position: absolute;
  transform: translate(-50%, -130%);
  padding: 4px 7px;
  background: #000;
  color: #fff;
  border-radius: 4px;
  font: 12px var(--mono);
  pointer-events: none;
  white-space: nowrap;
  z-index: 3;
}
@keyframes pulse {
  50% { box-shadow: 0 0 0 6px rgba(232, 184, 74, 0.12); }
}
.legend {
  display: flex;
  gap: 14px;
  align-items: center;
  margin: 0;
  padding: 6px 12px 8px;
  color: var(--muted);
  font-size: 12px;
}
.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 4px;
  border-radius: 2px;
  vertical-align: -1px;
}
.swatch.current { background: var(--accent); }
.swatch.installed { background: var(--installed); }
.swatch.find { background: var(--find); }

.step-pane { background: var(--panel); }
#step-pane { padding: 16px 20px 28px; }
.step-kicker { color: var(--accent); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; margin: 0 0 4px; }
.step-pane h1 { margin: 0 0 10px; font-size: 26px; }
.step-meta { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.chip {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 99px;
  background: #2a261c;
  color: var(--accent);
  font: 12px var(--mono);
}
.chip.midi { background: #2a2230; color: #d2b4e8; }
.component-pane { background: #14120f; }
#component-body { padding: 12px 14px 20px; }
.comp-empty { color: var(--muted); margin: 12px 0; }
.comp-card {
  margin: 0 0 14px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.comp-visuals {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 12px;
  align-items: center;
}
.comp-symbol {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  background: #0d0c0b;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.comp-symbol svg { width: 80px; height: 48px; }
.comp-symbol span { color: var(--muted); font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; }
.comp-ident { min-width: 0; }
.comp-ident img {
  display: block;
  width: 100%;
  max-height: 140px;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
}
.comp-ident.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.comp-ident.pair img { max-height: 110px; }
.resistor-svg { width: 100%; height: auto; background: #0d0c0b; border-radius: 8px; }
.comp-bands { margin: 6px 0 0; color: var(--muted); font: 11px var(--mono); }
.comp-meta { margin-top: 10px; }
.comp-meta strong { display: block; margin-bottom: 6px; }
.comp-note {
  margin: 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: #2a2518;
  color: #ddd6c8;
  font-size: 13px;
}
.step-body { line-height: 1.55; color: #ddd6c8; }
.step-body p { margin: 0 0 10px; }
.note {
  margin: 12px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: #2a2518;
}
.warn {
  margin: 12px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--danger);
  background: #2a1c19;
}
.photos {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 16px 0;
}
.photos figure { margin: 0; }
.photos img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: zoom-in;
}
.photos figcaption { color: var(--muted); font-size: 12px; margin-top: 4px; }
.step-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 0 auto;
  align-items: center;
}
.step-actions button { padding: 5px 9px; font-size: 12px; }
.step-actions button:disabled { opacity: 0.4; cursor: default; }
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 24px;
}
.lightbox img { max-width: 100%; max-height: 100%; }

.pdf-overlay[hidden],
.backdrop[hidden] {
  display: none !important;
}
.pdf-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  z-index: 30;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 20px;
}
.pdf-panel {
  width: min(920px, 100%);
  max-height: calc(100vh - 40px);
  background: #111;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pdf-panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.pdf-panel header div { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pdf-panel a { color: var(--accent); }
.pdf-canvas-wrap {
  position: relative;
  overflow: auto;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2a2a2a;
}
.pdf-canvas-wrap img {
  max-width: 100%;
  max-height: calc(100vh - 120px);
  height: auto;
  display: block;
  background: #fff;
}
.page-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 76px;
  border: 0;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  font-size: 40px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
.page-arrow.prev { left: 10px; }
.page-arrow.next { right: 10px; }
.page-arrow:hover { background: rgba(0, 0, 0, 0.78); }
.page-arrow:disabled { opacity: 0.25; cursor: default; }
.pdf-fallback { color: #fff; padding: 24px; }

.editor-panel {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: 280px;
  max-height: 45vh;
  overflow: auto;
  background: #161410;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px;
  z-index: 20;
  font-size: 12px;
}
.editor-panel textarea { width: 100%; height: 120px; }

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 8;
}

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .app [data-split="nav"] { display: none; }
  .topbar {
    gap: 8px;
    padding: 8px 10px;
    flex-wrap: wrap;
  }
  .step-actions { margin-left: 0; }
  .label-full { display: none; }
  .label-short { display: inline; }
  .find-wrap {
    width: 100%;
    order: 5;
  }
  .midi-toggle { margin-left: auto; }
  .nav {
    position: fixed;
    inset: 58px auto 0 0;
    width: min(88vw, 340px);
    z-index: 9;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .nav.open { transform: none; }
  .nav-toggle { display: block; }
  .workspace { grid-template-rows: 42vh 6px 1fr; }
  .workspace-lower { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .workspace-lower [data-split="comp"] { display: none; }
  .component-pane { max-height: 34vh; }
  .comp-visuals { grid-template-columns: 72px 1fr; }
  .brand span { display: none; }
}
