:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  --bg: #18201a;
  --panel: #222d24;
  --inset: #141d17;
  --edge: #43563f;
  --text: #edf4e8;
  --muted: #b0c3ad;
  --green: #b8f477;
  --signal: #ffca6c;
  --power: #ff8a7d;
  --ground: #82cffa;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
.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;
}
body { display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh; height: 100dvh; margin: 0; background: var(--bg); color: var(--text); overflow: hidden; }
button, select, input { font: inherit; min-width: 0; touch-action: manipulation; color: var(--text); background: var(--inset); border: 1px solid var(--edge); border-radius: 4px; }
button { cursor: pointer; transition: border-color .14s ease, background-color .14s ease; }
button:disabled { opacity: .5; cursor: default; }
button:not(:disabled):hover, input:focus, select:focus { border-color: var(--green); }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }
a { color: var(--green); }

/* Single compact top bar (no secondary HUD header bar) */
.topbar {
  position: relative; z-index: 10; display: flex; align-items: center; gap: 8px;
  min-height: 44px; padding: max(5px, env(safe-area-inset-top)) clamp(10px, 2.5vw, 22px) 5px;
  background: #1b251d; border-bottom: 1px solid #2e4031;
}
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; white-space: nowrap; font-size: .82rem; padding: 5px 8px; border-radius: 4px; }
.back:hover { color: var(--text); background: #ffffff0c; }
.project-picker { position: relative; flex: 0 1 250px; min-width: 0; margin-right: auto; }
.project-trigger {
  width: 100%; height: 32px; padding: 0 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: .84rem; font-weight: 500; text-align: left;
  background: var(--inset); color: var(--text); border: 1px solid var(--edge); border-radius: 5px;
}
.project-trigger[aria-expanded="true"] { border-color: var(--green); }
#missionLabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.project-caret { flex: 0 0 auto; color: var(--muted); font-size: .78rem; transition: transform .15s ease; }
.project-trigger[aria-expanded="true"] .project-caret { transform: rotate(180deg); color: var(--green); }
.project-menu {
  position: absolute; left: 0; top: calc(100% + 6px); z-index: 25;
  width: max(100%, 290px); max-width: min(360px, calc(100vw - 16px));
  max-height: min(64dvh, 460px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 8px;
  box-shadow: 0 14px 36px #070e09d8; overflow: hidden;
  animation: blockPop .14s cubic-bezier(.22, 1, .36, 1);
}
.project-menu-head { padding: 8px; border-bottom: 1px solid #304231; background: #1c261e; }
.project-menu-head input { width: 100%; height: 32px; padding: 0 9px; font-size: .82rem; }
.project-list { overflow-y: auto; padding: 6px; display: grid; gap: 3px; -webkit-overflow-scrolling: touch; }
.project-group-label {
  padding: 6px 8px 3px; font-size: .68rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.project-option {
  width: 100%; min-height: 38px; padding: 7px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  text-align: left; background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--text); font-size: .83rem;
}
.project-option:hover, .project-option:focus-visible { background: #29392c; border-color: #4b6748; }
.project-option.active { background: #283f2c; border-color: #6b995d; }
.project-option-main { display: grid; gap: 2px; min-width: 0; }
.project-option-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.project-option-meta { font-size: .72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-option-check { flex: 0 0 auto; color: var(--green); font-size: .85rem; font-weight: 700; }
.project-empty { padding: 14px 10px; text-align: center; font-size: .8rem; color: var(--muted); }
.controls { display: flex; align-items: center; gap: 6px; min-width: 0; }
.controls > button { height: 32px; padding-inline: 9px; font-size: .82rem; }
#aiSettings.ready { color: var(--green); border-color: #5c8a4a; }

.popover { position: static; }
.popover summary {
  list-style: none; display: inline-flex; align-items: center; height: 32px;
  padding-inline: 10px; font-size: .8rem; color: var(--muted);
  background: var(--inset); border: 1px solid var(--edge); border-radius: 4px;
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: border-color .14s ease, color .14s ease;
}
.popover summary::-webkit-details-marker { display: none; }
.popover summary:hover, .popover[open] summary { color: var(--text); border-color: var(--green); }
.popover-panel {
  position: absolute; right: clamp(10px, 2.5vw, 22px); top: calc(100% + 6px); z-index: 20;
  width: min(390px, calc(100vw - 20px)); max-height: min(60dvh, 480px); overflow: auto;
  padding: 14px; background: var(--panel); border: 1px solid var(--edge); border-radius: 8px;
  box-shadow: 0 12px 32px #080f0acc; font-size: .85rem; color: var(--muted);
}
.eda-badge {
  display: inline-grid; place-items: center; min-width: 16px; height: 16px; padding: 0 4px;
  margin-left: 4px; border-radius: 999px; font: 700 .64rem/1 ui-monospace, monospace;
  background: #2b4428; color: #d5ff9d; border: 1px solid #598a4f;
}
.eda-badge.warn { background: #4a3a18; color: #ffd978; border-color: #9e7a2c; }
.eda-badge.err { background: #4b1f1e; color: #ffaaa3; border-color: #a64642; }
.eda-panel { display: grid; gap: 12px; }
.eda-section { display: grid; gap: 7px; }
.eda-heading {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  font: 700 .68rem/1.2 ui-monospace, monospace; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted);
}
.eda-seg {
  display: inline-grid; grid-template-columns: 1fr 1fr; width: 100%; padding: 2px;
  background: #121a14; border: 1px solid var(--edge); border-radius: 6px; gap: 2px;
}
.eda-seg button {
  height: 28px; padding: 0 8px; border: 1px solid transparent; border-radius: 4px;
  background: transparent; color: var(--muted); font-size: .78rem; font-weight: 600;
}
.eda-seg button.active { background: #294028; border-color: #5d8d54; color: #eaffd4; }
.eda-toggles { display: flex; flex-wrap: wrap; gap: 10px 14px; }
.eda-check {
  display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--text); cursor: pointer;
}
.eda-check input { width: 15px; height: 15px; margin: 0; accent-color: var(--green); }
.eda-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.eda-actions button {
  height: 30px; padding: 0 6px; font-size: .76rem; font-weight: 600; white-space: nowrap;
  background: #202e23; border-color: #466144;
}
.eda-actions button:hover { background: #2b3f2f; border-color: var(--green); }
.erc-summary { font-size: .68rem; color: var(--green); }
.erc-summary.warn { color: #ffd978; }
.erc-summary.err { color: #ff9c94; }
.erc-list { display: grid; gap: 5px; }
.erc-ok {
  padding: 7px 9px; border-radius: 5px; background: #1d2e20; border: 1px solid #3c603c;
  color: #c8f59d; font-size: .78rem;
}
.erc-item {
  width: 100%; height: auto; padding: 7px 9px; border-radius: 5px; text-align: left;
  display: grid; gap: 2px; background: #262018; border: 1px solid #6b5324; color: var(--text);
  white-space: normal; overflow-wrap: anywhere;
}
.erc-item.error { background: #2b1919; border-color: #7d3633; }
.erc-item strong { font-size: .78rem; color: #ffe399; line-height: 1.3; }
.erc-item.error strong { color: #ffb2ab; }
.erc-item span { font-size: .72rem; color: var(--muted); line-height: 1.35; }
#detail p, #detail li, #useExamples p { margin-block: 7px; line-height: 1.45; overflow-wrap: anywhere; }
#detail h3 { color: var(--text); font-size: .95rem; margin-bottom: 4px; overflow-wrap: anywhere; }
#detail ul { margin: .6rem 0; padding-left: 1.4rem; }
#detail a { display: inline-block; margin-right: 9px; }
#detail button:not(.wire-remove) {
  height: auto; min-height: 32px; padding: 6px 10px; margin-top: 6px;
  font-size: .8rem; line-height: 1.3; white-space: normal; text-align: left; overflow-wrap: anywhere;
}
#detail select, #detail input { width: 100%; max-width: 100%; padding: 6px 8px; margin-top: 4px; font-size: .82rem; }
#useExamples figure { margin: 0; }
#useExamples img { display: block; width: 100%; height: auto; background: var(--inset); border-radius: 4px; }
#useExamples figcaption { margin-top: 6px; font-size: .75rem; }
#generateUseImage { padding: 6px 10px; }

#lab { min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.stage { position: relative; min-height: 0; overflow: hidden; background-color: #192b20; }

/* Subtle floating status pill over the canvas instead of a full-width header bar */
#progress {
  position: absolute; top: 12px; left: 12px; z-index: 4;
  max-width: min(460px, calc(100% - 24px));
  padding: 5px 12px; border-radius: 999px;
  background: #142118cc; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid #3c563f80; color: var(--muted);
  font-size: .78rem; line-height: 1.35; overflow-wrap: anywhere;
  pointer-events: none; transition: opacity .2s ease;
}
#progress:empty { opacity: 0; }
#progress.complete { color: var(--green); border-color: #6ea75a99; }

/* Floating zoom pill */
.zoom-controls {
  position: absolute; right: 12px; bottom: 12px; z-index: 4;
  display: inline-flex; align-items: center; gap: 2px; padding: 3px;
  background: #142118cc; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid #3c563f80; border-radius: 999px;
}
.zoom-controls button {
  height: 28px; min-width: 28px; padding-inline: 7px;
  background: transparent; border: 0; border-radius: 999px;
  color: var(--muted); font: 600 .76rem ui-monospace, monospace;
}
.zoom-controls button:hover { color: var(--text); background: #ffffff14; }
#zoomReset { min-width: 46px; }

#viewport {
  position: relative; width: 100%; height: 100%; overflow: auto;
  background-color: #192b20;
  overscroll-behavior: contain; touch-action: pan-x pan-y; cursor: grab;
  -webkit-overflow-scrolling: touch;
}
#viewport.panning { cursor: grabbing; user-select: none; }
#viewport.wire-hover:not(.panning) { cursor: pointer; }
.scene-sizer { position: relative; min-width: 100%; min-height: 100%; }
.block { cursor: default; }

/* Spacious workbench surface */
.scene {
  --lane: clamp(64px, 14vw, 180px);
  --outer-pad: clamp(40px, 8vw, 128px);
  --left-space: max(var(--outer-pad), var(--wire-left, 0px));
  --middle-space: max(var(--lane), var(--wire-middle, 0px));
  --right-space: max(var(--outer-pad), var(--wire-right, 0px));
  --pan-edge: clamp(180px, 30vw, 440px);
  --board-width: max(var(--viewport-width, 100vw), calc(var(--left-space) + var(--middle-space) + var(--right-space) + 260px));
  position: relative; isolation: isolate;
  min-height: max(var(--viewport-height, 600px), var(--scene-min-height, 780px));
  width: calc(var(--board-width) + 2 * var(--pan-edge));
  transform-origin: 0 0;
  background-color: #192b20;
  background-image:
    radial-gradient(#a7d89f24 1px, transparent 1px),
    linear-gradient(#a2d4990c 1px, transparent 1px),
    linear-gradient(90deg, #a2d4990c 1px, transparent 1px);
  background-size: 24px 24px, 120px 120px, 120px 120px;
}
#wires { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.blocks {
  display: grid; grid-template-columns: repeat(2, minmax(0, 326px)); justify-content: center;
  width: var(--board-width); margin-inline: var(--pan-edge);
  column-gap: var(--middle-space);
  padding: calc(clamp(68px, 11vh, 130px) + var(--wire-top, 0px)) var(--right-space) clamp(150px, 24vh, 280px) var(--left-space);
  position: relative; z-index: 1;
}
.centered-board {
  --part-column: clamp(168px, 26vw, 276px);
  --controller-column: clamp(200px, 29vw, 330px);
  --column-gap: clamp(76px, 11vw, 156px);
  --board-width: max(var(--viewport-width, 100vw), calc(2 * var(--part-column) + var(--controller-column) + 2 * var(--column-gap) + var(--left-space) + var(--right-space)));
}
.centered-board .blocks {
  grid-template-columns: var(--part-column) var(--controller-column) var(--part-column);
  column-gap: var(--column-gap);
}
.bank { display: grid; align-content: start; gap: 44px; min-width: 0; }
.block {
  min-width: 0; position: relative; background: #233429; border: 1.5px solid #4c6d49; border-radius: 6px;
  box-shadow: 0 6px 18px #0a140d88;
  transition: border-color .14s ease, box-shadow .16s ease;
}
.block.block-enter { animation: blockPop .18s cubic-bezier(.22, 1, .36, 1); }
@keyframes blockPop {
  from { opacity: 0; }
  to { opacity: 1; }
}
.block.selected { border-color: var(--green); box-shadow: 0 0 0 1px #b8f47755, 0 8px 22px #09130ca6; }
.block.moved { z-index: 1; }
.block.dragging {
  z-index: 3; border-color: var(--green);
  box-shadow: 0 16px 34px #060e08c8;
  will-change: transform;
  transition: none;
}
.block.menu-open { z-index: 6; border-color: var(--green); }
.block-menu {
  position: absolute; top: -20px; left: 50%; transform: translateX(-50%); z-index: 12;
  display: inline-flex; align-items: center; gap: 5px; padding: 4px;
  background: #121c15f0; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid #5f8659; border-radius: 999px;
  box-shadow: 0 8px 22px #050b07cc;
  animation: blockPop .14s cubic-bezier(.22, 1, .36, 1);
}
.block-menu > button {
  display: grid; place-items: center; width: 32px; height: 32px; padding: 0;
  border-radius: 999px; border: 1px solid transparent; background: #1e2d22;
  color: var(--text); touch-action: manipulation;
}
.block-menu > button svg { width: 16px; height: 16px; display: block; pointer-events: none; }
.block-menu > button.info-btn { color: var(--green); }
.block-menu > button.info-btn:hover { background: #2c4331; border-color: var(--green); }
.block-menu > button.replace-btn { color: var(--ground); }
.block-menu > button.replace-btn:hover { background: #203642; border-color: var(--ground); }
.block-menu > button.delete-btn { color: var(--power); }
.block-menu > button.delete-btn:hover { background: #432422; border-color: var(--power); }
.replace-picker {
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 15;
  width: min(260px, 78vw); max-height: 230px; overflow: auto;
  padding: 6px; display: grid; gap: 4px;
  background: #17231af5; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid #5f8659; border-radius: 8px;
  box-shadow: 0 12px 28px #050b07d8;
}
.replace-picker-title { font-size: .7rem; color: var(--muted); padding: 2px 4px; }
.replace-option {
  display: flex; align-items: center; gap: 8px; width: 100%; height: auto; padding: 5px 7px;
  border-radius: 5px; border: 1px solid #354b35; background: #223227;
  color: var(--text); font-size: .75rem; text-align: left;
  touch-action: manipulation;
}
.replace-option:hover { border-color: var(--ground); background: #263e38; }
.replace-option .block-art { width: 32px; height: 26px; flex: 0 0 32px; }
.replace-option > span:last-child { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
@media (pointer: coarse) {
  .block-menu > button { width: 38px; height: 38px; }
  .block-menu > button svg { width: 18px; height: 18px; }
}
.block.movable .block-title { cursor: grab; touch-action: none; user-select: none; }
.block.movable .block-title::before { content: '⠿'; color: var(--muted); margin-right: 6px; opacity: .75; }
.block-main { cursor: grab; touch-action: none; user-select: none; }
.block.dragging .block-title, .block.dragging .block-main { cursor: grabbing; }
.block.staged { border-style: dashed; border-color: #ffd374; }
.block-title {
  display: block; width: 100%; padding: 7px 10px;
  border: 0; border-radius: 5px 5px 0 0; color: inherit; background: #ffffff08;
  font-size: clamp(.74rem, 2vw, .9rem); font-weight: 700;
  text-align: center; overflow-wrap: anywhere;
}
.block-main {
  align-self: center; display: grid; place-items: center; padding: 0;
  width: 100%; border: 1px solid transparent; border-radius: 4px; background: #17251d;
}
.block-main .block-art { width: 100%; height: clamp(82px, 16vw, 154px); }
.block-main .glyph { transform: scale(1.5); }
.block-art {
  position: relative; display: grid; place-items: center;
  flex: 0 0 auto; width: 53px; height: 44px;
}
.part-photo {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: contain; padding: 2px;
  background: #f3f6ef; border: 1px solid #64755d; border-radius: 3px;
  opacity: 0; pointer-events: none; transition: opacity .15s ease;
}
.photo-ready .part-photo { opacity: 1; }
.photo-ready .glyph { visibility: hidden; }
.glyph {
  --accent: #84ce76;
  display: block; width: 21px; height: 19px; background: var(--accent); border: 3px solid #17251c;
  box-shadow: inset 0 3px #ffffff55, inset -3px -3px #0004, 0 0 0 1px #ffffff25;
}
[data-shape="led"] .glyph { --accent: #f28b79; clip-path: polygon(25% 0, 75% 0, 75% 17%, 100% 17%, 100% 72%, 75% 72%, 75% 100%, 25% 100%, 25% 72%, 0 72%, 0 17%, 25% 17%); }
[data-shape="resistor"] .glyph { --accent: #efc585; background: repeating-linear-gradient(90deg, #dfb977 0 4px, #8b5840 4px 6px, #efc585 6px 9px); height: 12px; }
[data-shape="servo"] .glyph, [data-shape="motor"] .glyph { --accent: #8fc1ee; }
[data-shape="battery"] .glyph { --accent: #f0ba63; }
[data-shape="ultrasonic"] .glyph { --accent: #8fc7d9; background: linear-gradient(90deg, #a9d8df 40%, #36536a 40% 60%, #a9d8df 60%); }
.rails {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 48%) minmax(0, 1fr);
  align-items: center; gap: 4px;
  min-height: 104px; padding-block: 6px 8px;
}
.rail { min-width: 0; }
.pin { display: flex; align-items: center; gap: 4px; width: 100%; background: transparent; border: 0; border-radius: 3px; padding: 1px 3px; min-height: 21px; font: .7rem ui-monospace, monospace; text-align: left; color: var(--muted); white-space: nowrap; }
.pin:not(.reserved):not(:disabled) { cursor: crosshair; touch-action: none; user-select: none; }
.pin:hover, .pin.active { color: var(--text); background: #aec9b01f; }
.pin.reserved { color: #a1aa9e; }
.pin.wire-source { color: var(--text); background: #b8f47729; box-shadow: inset 0 0 0 1px var(--wire, var(--green)); }
.pin.wire-source i { background: var(--wire, var(--green)); box-shadow: 0 0 8px var(--wire, var(--green)); }
.pin.wire-compatible { color: var(--text); background: #b8f47717; box-shadow: inset 0 0 0 1px #b8f47766; }
.pin.wire-compatible i { background: var(--wire, var(--green)); box-shadow: 0 0 6px var(--wire, var(--green)); }
.pin.wire-target { color: #fff; background: #b8f47740; box-shadow: inset 0 0 0 1.5px var(--green), 0 0 10px #b8f47755; }
.pin.wire-target i { background: var(--green); box-shadow: 0 0 10px var(--green); }
.pin.wire-invalid { color: #ffb3ad; background: #ff6b6b24; box-shadow: inset 0 0 0 1px #ff6b6b99; }
#viewport.wire-dragging, #viewport.wire-dragging * { cursor: crosshair !important; }
.wire-item-row { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-width: 0; }
.wire-item-row > span { min-width: 0; overflow-wrap: anywhere; }
.wire-remove { flex: 0 0 auto; width: 24px; height: 24px; padding: 0; line-height: 1; font-size: .9rem; color: var(--power); background: #2c1e1d; border-color: #6f403c; border-radius: 4px; }
.wire-remove:hover { background: #4a2623; border-color: var(--power); }
.pin-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail.right .pin { flex-direction: row-reverse; text-align: right; }
.pin i { flex: 0 0 7px; height: 7px; border-radius: 1px; background: #84937a; box-shadow: inset 0 -2px #0005; }
.pin.wired i { background: var(--wire); box-shadow: 0 0 6px var(--wire); }
.pin.signal, .signal { --wire: var(--signal); } .pin.power, .power { --wire: var(--power); } .pin.ground, .ground { --wire: var(--ground); }
#detail li::marker { color: var(--wire, var(--muted)); }

/* Simple bottom bar: IC/header pin-formed omni-bar above clean component blocks */
.dock {
  z-index: 2; min-width: 0; border-top: 1px solid #2b3c2e; background: #151e17;
  padding: 9px clamp(10px, 2vw, 22px) max(6px, env(safe-area-inset-bottom));
  display: grid; gap: 7px;
}
.omni-bar {
  display: flex; align-items: center; justify-content: center;
  width: min(680px, 100%); margin-inline: auto;
  padding: 4px 2px;
  --pin-metal: #87987e;
  --pin-gold: #c9b574;
  --pin-glow: transparent;
}
/* Side header pin legs + square solder pads forming the left/right edges */
.omni-pins {
  flex: 0 0 auto; display: grid; gap: 5px; padding-block: 3px;
}
.omni-pins i {
  position: relative; display: block; width: 14px; height: 3px;
  background: linear-gradient(180deg, #b8c6ae 0%, var(--pin-metal) 55%, #56634f 100%);
  border-radius: 1px;
  transition: background .18s ease, box-shadow .18s ease, width .18s ease;
}
.omni-pins.left i { border-radius: 2px 0 0 2px; }
.omni-pins.right i { border-radius: 0 2px 2px 0; }
.omni-pins i::before {
  content: ''; position: absolute; top: 50%; width: 5px; height: 5px;
  transform: translateY(-50%); border-radius: 1px;
  background: #9eb094; box-shadow: inset 0 -1px #0006;
  transition: background .18s ease, box-shadow .18s ease;
}
.omni-pins.left i::before { left: -2px; }
.omni-pins.right i::before { right: -2px; }

/* Main PCB/IC housing framed top & bottom by DIP header pin combs */
.omni-core {
  position: relative; flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; gap: 7px;
  padding: 4px 6px 4px 10px;
  background: linear-gradient(180deg, #1b291f 0%, #111a13 100%);
  border: 1.5px solid #445e43; border-radius: 5px;
  box-shadow: inset 0 1px 0 #ffffff10, inset 0 0 0 1px #0a110c, 0 4px 14px #060b0788;
  transition: border-color .18s ease, box-shadow .18s ease;
}
/* IC pin-1 orientation semicircle notch on the left silkscreen edge */
.omni-core::marker { content: none; }
/* Top & bottom metallic header-pin combs forming the input frame */
.omni-core::before,
.omni-core::after {
  content: ''; position: absolute; left: 14px; right: 14px; height: 5px; pointer-events: none;
  background: repeating-linear-gradient(
    90deg,
    var(--pin-metal) 0 4px,
    transparent 4px 12px
  );
  opacity: .72;
  transition: opacity .18s ease, filter .18s ease, background .18s ease;
}
.omni-core::before {
  top: -6px;
  mask-image: linear-gradient(180deg, #000 0%, #000 100%);
  border-radius: 2px 2px 0 0;
}
.omni-core::after {
  bottom: -6px;
  border-radius: 0 0 2px 2px;
}

/* Energized states: pins light up on focus, URL paste, or API key detection */
.omni-bar:focus-within .omni-core {
  border-color: var(--green);
  box-shadow: inset 0 1px 0 #ffffff18, inset 0 0 0 1px #0a110c, 0 0 0 2px #b8f47724, 0 6px 18px #060b07a8;
}
.omni-bar:focus-within .omni-core::before,
.omni-bar:focus-within .omni-core::after {
  background: repeating-linear-gradient(90deg, var(--pin-gold) 0 4px, transparent 4px 12px);
  opacity: 1;
  filter: drop-shadow(0 0 3px #f6d57a66);
}
.omni-bar:focus-within .omni-pins i.p-pwr { background: var(--power); box-shadow: 0 0 6px #ff7d7377; }
.omni-bar:focus-within .omni-pins i.p-pwr::before { background: var(--power); box-shadow: 0 0 6px var(--power); }
.omni-bar:focus-within .omni-pins i.p-sig { background: var(--green); box-shadow: 0 0 6px #b8f47777; }
.omni-bar:focus-within .omni-pins i.p-sig::before { background: var(--green); box-shadow: 0 0 6px var(--green); }
.omni-bar:focus-within .omni-pins i.p-gnd { background: var(--ground); box-shadow: 0 0 6px #76d4ff77; }
.omni-bar:focus-within .omni-pins i.p-gnd::before { background: var(--ground); box-shadow: 0 0 6px var(--ground); }

.omni-bar[data-mode="url"] .omni-core {
  border-color: var(--ground);
  box-shadow: inset 0 1px 0 #ffffff18, 0 0 0 2px #76d4ff24, 0 6px 18px #060b07a8;
}
.omni-bar[data-mode="url"] .omni-core::before,
.omni-bar[data-mode="url"] .omni-core::after {
  background: repeating-linear-gradient(90deg, var(--ground) 0 4px, transparent 4px 12px);
  opacity: .95;
  filter: drop-shadow(0 0 3px #76d4ff77);
}
.omni-bar[data-mode="url"] .omni-pins i,
.omni-bar[data-mode="url"] .omni-pins i::before {
  background: var(--ground); box-shadow: 0 0 7px #76d4ff88;
}

.omni-bar[data-mode="key"] .omni-core {
  border-color: var(--green);
  box-shadow: inset 0 1px 0 #ffffff18, 0 0 0 2px #b8f4772e, 0 6px 18px #060b07a8;
}
.omni-bar[data-mode="key"] .omni-core::before,
.omni-bar[data-mode="key"] .omni-core::after {
  background: repeating-linear-gradient(90deg, var(--green) 0 4px, transparent 4px 12px);
  opacity: 1;
  filter: drop-shadow(0 0 4px #b8f47788);
}
.omni-bar[data-mode="key"] .omni-pins i,
.omni-bar[data-mode="key"] .omni-pins i::before {
  background: var(--green); box-shadow: 0 0 7px #b8f47799;
}

.omni-badge {
  position: relative; flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 7px; border-radius: 4px;
  font: 700 .64rem/1.3 ui-monospace, monospace; letter-spacing: .05em; text-transform: uppercase;
  color: #b4c7ad; background: #101812; border: 1px solid #304532;
  user-select: none; white-space: nowrap;
}
.omni-badge::before {
  content: ''; width: 5px; height: 5px; border-radius: 50%;
  background: #5b7158; box-shadow: inset 0 -1px #0006;
  transition: background .18s ease, box-shadow .18s ease;
}
.omni-bar[data-ai="ready"] .omni-badge::before {
  background: var(--green); box-shadow: 0 0 6px var(--green);
}
.omni-badge[data-mode="url"] { color: #a7e4ff; background: #122630; border-color: #3d7591; }
.omni-badge[data-mode="url"]::before { background: var(--ground); box-shadow: 0 0 6px var(--ground); }
.omni-badge[data-mode="key"] { color: #dcffae; background: #1c331a; border-color: #5c9148; }
.omni-badge[data-mode="key"]::before { background: var(--green); box-shadow: 0 0 7px var(--green); }

#partSearch {
  flex: 1 1 auto; min-width: 0; height: 28px; padding: 0 4px;
  border: 0; background: transparent; color: var(--text); font-size: .82rem;
  outline: none; box-shadow: none;
}
#partSearch::placeholder { color: #7f957f; }
.omni-action {
  flex: 0 0 auto; height: 26px; padding: 0 10px; border-radius: 4px;
  font: 700 .72rem/1 ui-monospace, monospace; letter-spacing: .03em; text-transform: uppercase; white-space: nowrap;
  background: #274025; border: 1px solid #639457; color: #e9ffd1;
  box-shadow: inset 0 1px 0 #ffffff1a;
}
.omni-bar[data-mode="url"] .omni-action { background: #193544; border-color: #5395b6; color: #daf4ff; }
#supplierSearch {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 5px 10px;
  font-size: .75rem; color: var(--muted);
}
.supplier-recommendation { overflow-wrap: anywhere; }
.supplier-recommendation strong { color: var(--text); }
#missingReason { color: var(--muted); }
#missingReason::before { content: ' · '; }
.supplier-links { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.supplier-links a {
  padding: 2px 7px; white-space: nowrap; border: 1px solid var(--edge); border-radius: 5px;
  text-decoration: none; font-size: .72rem; background: #1d2a20;
}
#hotbar {
  display: flex; gap: 6px; overflow-x: auto; padding: 1px 1px 2px;
  scrollbar-color: #4f664b #161f18; min-height: 62px;
  -webkit-overflow-scrolling: touch;
}
.slot {
  flex: 0 0 72px; min-height: 58px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 3px;
  padding: 4px 3px; background: #223025; border: 1px solid #3c523b; border-radius: 6px;
  font: 600 .64rem/1.15 system-ui, sans-serif; color: var(--text);
  transition: border-color .14s ease, background-color .14s ease, transform .12s ease;
}
.slot:hover { background: #2a3c2d; border-color: #6b8d63; transform: translateY(-1px); }
.slot > span:last-child {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  overflow: hidden; overflow-wrap: anywhere; text-align: center; width: 100%;
}
.slot .block-art { width: 38px; height: 26px; }
.slot.selected { border-color: var(--green); background: #263b28; }
.slot.recommended { background: #4a3f26; border-color: #ffd374; color: #fff0b7; }
.slot small { font: 700 .56rem ui-monospace, monospace; color: #ffd374; letter-spacing: .03em; }

dialog { width: min(420px, calc(100% - 24px)); background: var(--panel); color: var(--text); border: 1px solid var(--edge); border-radius: 8px; padding: 15px; }
dialog::backdrop { background: #070c09ba; }
#aiForm { display: grid; gap: 10px; }
#aiForm p, #aiForm label { color: var(--muted); font-size: .84rem; line-height: 1.4; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.llm-settings { display: grid; gap: 8px; }
.llm-field { display: grid; gap: 3px; }
.llm-field span { font-size: .74rem; color: var(--muted); }
.llm-field input, .llm-field select { width: 100%; padding: 6px 8px; font-size: .84rem; }
.llm-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
#aiForm button { padding: 7px 10px; }
#saveLlmKey { background: #344f30; border-color: #629356; color: #eaffd4; }
#clearLlmKey { background: #3b2321; border-color: #7c4540; color: #ffc6c0; }
#connect { background: #243327; }

@media (max-width: 680px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 6px;
    column-gap: 6px;
    padding: max(6px, env(safe-area-inset-top)) 8px 6px;
  }
  .back {
    height: 36px;
    padding-inline: 9px;
    background: var(--inset);
    border: 1px solid var(--edge);
    font-size: .8rem;
  }
  .project-picker {
    position: static;
    flex: 1 1 140px;
    margin-right: 0;
  }
  .project-trigger {
    height: 36px;
    font-size: .84rem;
    padding-inline: 9px;
  }
  .project-menu {
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    top: calc(100% + 4px);
    max-height: min(62dvh, 440px);
  }
  .project-option {
    min-height: 44px;
    padding: 8px 10px;
  }
  .controls {
    flex: 1 0 100%;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 3px;
  }
  .controls .popover {
    display: flex;
    min-width: 0;
  }
  .controls > button, .controls > .popover > summary {
    width: 100%;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding-inline: 1px;
    font-size: .69rem;
    white-space: nowrap;
    overflow: hidden;
  }
  .eda-badge {
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    margin-left: 2px;
    font-size: .58rem;
  }
  .popover-panel {
    left: 8px;
    right: 8px;
    width: auto;
    top: calc(100% + 4px);
    max-height: min(55dvh, 420px);
  }
}

@media (max-width: 360px) {
  .back span { display: none; }
  .controls > button, .controls > .popover > summary { font-size: .68rem; padding-inline: 1px; }
}

@media (max-width: 560px) {
  #progress { top: 8px; left: 8px; max-width: calc(100% - 16px); font-size: .72rem; padding: 4px 10px; }
  .zoom-controls { right: 8px; bottom: 8px; }
  .scene { --lane: clamp(44px, 12vw, 84px); --pan-edge: clamp(120px, 26vw, 220px); }
  .centered-board { --column-gap: clamp(54px, 11vw, 96px); }
  .bank { gap: 34px; }
  .pin { gap: 2px; font-size: .63rem; }
  .rails { gap: 1px; grid-template-columns: minmax(0, 1fr) minmax(0, 44%) minmax(0, 1fr); }
  .block-main .block-art { height: clamp(66px, 20vw, 106px); }
  .omni-pins i { width: 9px; }
  .omni-core { padding: 3px 5px 3px 7px; gap: 5px; }
  .omni-core::before, .omni-core::after { left: 10px; right: 10px; }
  .slot .block-art { width: 34px; height: 24px; }
  .slot { flex-basis: 66px; min-height: 54px; }
  #partSearch { font-size: .8rem; }
}

@media (pointer: coarse) {
  .block-title { min-height: 36px; }
  .pin { min-height: 27px; }
}

.share-svg-view {
  position: fixed; inset: 0; z-index: 40;
  display: grid; grid-template-rows: auto minmax(0, 1fr);
  background: #131c15;
}
.share-svg-view[hidden] { display: none; }
.share-svg-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  background: #1b251d; border-bottom: 1px solid #304332;
}
.share-svg-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; min-width: 0; }
.share-svg-title strong { font-size: .92rem; color: var(--text); }
.share-svg-title span { font: 600 .72rem ui-monospace, monospace; color: var(--muted); }
.share-svg-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.share-svg-actions button { height: 32px; padding: 0 10px; font-size: .78rem; font-weight: 600; }
.share-svg-actions button.primary { background: #2c4629; border-color: #629457; color: #eaffd4; }
.share-svg-stage {
  overflow: auto; padding: 14px; display: grid; place-items: center;
  background: #142119; -webkit-overflow-scrolling: touch;
}
.share-svg-stage svg {
  display: block; max-width: 100%; height: auto;
  border: 1px solid #354b35; border-radius: 8px;
  box-shadow: 0 14px 36px #060b07b8;
}
