:root {
  color-scheme: light;
  --ink: #172b35;
  --muted: #526974;
  --panel: #f7fafb;
  --line: #d4e0e5;
  --paper: #fcfeff;
  --teal: #0b7165;
  --mint: #a7ead9;
  --blue: #166f92;
  --red: #ac443a;
  --orange: #835611;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  font: 16px/1.45 var(--sans);
  color: var(--ink);
  background: var(--panel);
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button, summary { touch-action: manipulation; }
button, .popover summary {
  min-height: 36px;
  padding: .35rem .75rem;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  font-size: .875rem;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .popover summary:hover { background: #e7eff2; }
button:disabled { opacity: .42; cursor: default; }
button:focus-visible, input:focus-visible, summary:focus-visible, .viewport:focus-visible {
  outline: 2px solid #008d7b;
  outline-offset: 2px;
}
input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  padding: .5rem .65rem;
  font-size: .875rem;
}
h1, h2, h3, p { margin: 0; }
h2 { font-size: .94rem; }
h3 { font-size: .875rem; }
.app {
  height: 100vh;
  height: 100dvh;
  min-height: 360px;
  display: grid;
  grid-template-rows: 60px 49px minmax(0, 1fr) auto;
  overflow: hidden;
}
.masthead, .tools, .status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: 12px;
  padding: 0 18px;
}
.masthead { background: var(--ink); color: #edf7fa; border-bottom: 1px solid #294550; }
.brand { display: flex; align-items: center; gap: .6rem; flex-shrink: 0; }
.brand h1 { font-size: 1.15rem; font-weight: 670; letter-spacing: -.035em; }
.brand-icon {
  padding: 3px 5px;
  background: var(--mint);
  color: var(--ink);
  border-radius: 4px;
  font: 750 .92rem/1.35 var(--mono);
  letter-spacing: -.08em;
}
.brand-icon span { opacity: .72; }
.project-name {
  min-width: 0;
  width: min(33vw, 290px);
  background: #233d48;
  border-color: #40616c;
  color: #f1fafc;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-actions, .tool-group { display: flex; align-items: center; gap: 4px; }
.masthead .file-actions > button:hover, .masthead summary:hover { background: #294853; }
.masthead .popover[open] summary { background: #294853; }
.tools { background: #fff; border-bottom: 1px solid var(--line); }
.tools button[aria-pressed="true"] { background: #d9f0e9; color: #07594e; }
.flow-mark { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border: 1px solid currentColor; border-radius: 50%; }
[aria-pressed="true"] .flow-mark { background: #168c78; }
#undo, #redo { min-width: 34px; padding-inline: 7px; font-size: 1.2rem; line-height: 1; }
.mobile-panel { display: none; }
.popover { position: relative; z-index: 5; }
.popover summary { display: flex; align-items: center; gap: 8px; list-style: none; }
.popover summary::-webkit-details-marker { display: none; }
.popover summary::after { content: ""; width: 6px; height: 6px; border-right: 1px solid; border-bottom: 1px solid; transform: rotate(45deg); margin-bottom: 3px; }
.menu {
  position: absolute;
  top: calc(100% + 7px);
  left: 0;
  padding: 5px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 12px 28px #172b3526;
}
#export-menu .menu { left: auto; right: 0; }
#templates-menu .menu { width: max-content; max-width: min(16rem, calc(100vw - 110px)); }
#templates-menu .menu button { white-space: normal; }
.menu button { display: block; width: 100%; text-align: left; }
.editor { min-height: 0; position: relative; display: grid; grid-template-columns: 228px minmax(0, 1fr) 280px; }
.library, .inspector { min-width: 0; overflow: auto; scrollbar-width: thin; background: var(--panel); }
.library { border-right: 1px solid var(--line); padding: 14px 12px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 0 2px 10px; }
.quiet, .small { color: var(--muted); font-size: .8125rem; }
#components { padding-block: 8px; }
.component-group { margin-block-start: 10px; }
.component-group h3 { padding: 2px 5px 4px; color: #495f69; }
.component-add {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  min-height: 39px;
  padding-inline: 4px 8px;
  text-align: left;
  font-weight: 550;
  white-space: normal;
}
.component-add:hover { border-color: #bed3dc; }
.component-add .symbol { flex: 0 0 28px; min-height: 26px; }
.symbol {
  display: grid;
  place-items: center;
  min-width: 28px;
  min-height: 28px;
  padding: 0 3px;
  background: #e0eff4;
  color: #12536b;
  border-radius: 4px;
  font: 750 .73rem var(--mono);
}
[data-role="source"] .symbol { background: #daf0e9; color: #156550; }
.symbol { flex-shrink: 0; }
.symbol svg { width: 20px; height: 20px; display: block; pointer-events: none; }
[data-role="charge"] .symbol { background: #f7ecda; color: #855613; }
[data-protective] .symbol { background: #f8e7da; color: #934730; }
.sheet { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #eef5f8; }
.viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; }
.viewport.is-moving { cursor: grabbing; }
.viewport.is-wiring { cursor: crosshair; }
.world, .node-layer { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
.wire-layer, .wire-label-layer { position: absolute; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.wire { cursor: pointer; }
.wire-target { fill: none; stroke: transparent; stroke-width: 18px; pointer-events: stroke; }
.wire-line, .wire-energy { fill: none; stroke-width: 2.3px; pointer-events: none; }
.wire[data-polarity="+"] { --wire: #b6584e; }
.wire[data-polarity="-"] { --wire: #376d89; }
.wire-line { stroke: var(--wire); }
.wire.is-selected .wire-line { stroke: #008978; stroke-width: 4px; }
.wire-energy { stroke: #f7fffc; stroke-dasharray: 3 11; animation: flow 1.1s linear infinite; }
.wire[data-reverse] .wire-energy { animation-direction: reverse; }
.wire-text {
  fill: var(--ink);
  font: 650 12px var(--mono);
  paint-order: stroke;
  stroke: #eef5f8;
  stroke-width: 4px;
  stroke-linejoin: round;
  pointer-events: none;
}
.wire-label-handle { cursor: grab; }
.wire-label-handle.is-dragging { cursor: grabbing; }
.wire-label-handle.is-muted { opacity: .48; }
.wire-label-hit { fill: transparent; pointer-events: all; }
.viewport.is-wiring .wire-label-hit { pointer-events: none; }
.wire-label-handle:is(:focus, :hover, .is-dragging) { outline: none; opacity: 1; }
.wire-label-handle:is(:focus, :hover, .is-dragging) .wire-label-hit { fill: #edf9f6; stroke: #60a99d; stroke-width: 1px; }
.wire-label-leader { stroke: var(--wire); stroke-width: 1.15px; stroke-dasharray: 3 2; opacity: .75; pointer-events: none; }
.wire.is-selected .wire-label-leader { stroke: #008978; }
.wire-preview { stroke: #008978; stroke-width: 2.5px; stroke-dasharray: 5 5; fill: none; pointer-events: none; }
@keyframes flow { to { stroke-dashoffset: -14; } }
.node {
  position: absolute;
  width: 176px;
  border: 1px solid #a7bdc8;
  border-radius: 7px;
  background: var(--paper);
  box-shadow: 0 3px 9px #142e4012;
  user-select: none;
  cursor: grab;
}
.node.is-selected { outline: 2px solid #008978; outline-offset: 1px; }
.node-heading { display: flex; align-items: center; height: 46px; gap: 8px; padding: 0 9px; border-bottom: 1px solid #dfe8ec; }
.node-heading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.node-meta { overflow: hidden; padding: 4px 9px; color: var(--muted); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }
.port {
  position: absolute;
  width: 30px;
  height: 22px;
  min-height: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  cursor: crosshair;
  transform: translate(-50%, -50%);
}
.port:hover, .port[aria-pressed="true"] { background: #a3e3d6a1; }
.port::after { content: ""; display: block; margin: auto; width: 9px; height: 9px; border-radius: 50%; background: #fff; border: 2px solid var(--wire); }
.port[data-wire-occupied]::after { background: var(--wire); }
.port[data-polarity="+"] { --wire: #aa473d; }
.port[data-polarity="-"] { --wire: #226b91; }
.port-label { position: absolute; color: var(--wire); top: 50%; transform: translateY(-50%); font: 650 11px var(--mono); pointer-events: none; white-space: nowrap; }
.port[data-side="left"] .port-label { left: 24px; }
.port[data-side="right"] .port-label { right: 24px; }
.canvas-caption, .zoom { position: absolute; display: flex; align-items: center; }
.canvas-caption { top: 12px; left: 12px; flex-wrap: wrap; gap: 6px; pointer-events: none; }
.canvas-caption span:not(:empty), .zoom { border: 1px solid #becfd7; background: #fcfeffe8; border-radius: 5px; }
.canvas-caption span:not(:empty) { padding: 5px 8px; font: 650 .75rem/1.2 var(--mono); }
#wire-prompt { color: var(--teal); }
.zoom { right: 12px; bottom: 12px; box-shadow: 0 2px 7px #0f22341a; }
.zoom button { min-width: 36px; border-radius: 0; }
.zoom button + button { border-left-color: var(--line); }
.empty-board { position: absolute; inset: 45% 0 auto; text-align: center; color: var(--muted); }
.empty-board button { background: #daecea; margin-top: 8px; color: var(--teal); }
.inspector { border-left: 1px solid var(--line); }
.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 9px 0;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.tabs button { flex: 1; border-radius: 3px 3px 0 0; border-bottom-width: 2px; }
.tabs [aria-pressed="true"] { border-bottom-color: var(--teal); color: #075e53; }
#issue-count { color: var(--muted); font: 600 .75rem var(--mono); margin-left: 4px; }
#detail-panel, #checks-panel { padding: 14px; }
.panel-title { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.panel-title h2 { overflow-wrap: anywhere; }
.fields { display: grid; gap: 10px; }
.fields label, .setting-row label { display: grid; gap: 4px; font-size: .875rem; font-weight: 600; }
.fields input { min-width: 0; font-weight: 400; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.inspector-rule { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.readouts { display: grid; gap: 7px; }
.readout { display: flex; justify-content: space-between; gap: 9px; font-size: .875rem; }
.readout strong { font-family: var(--mono); text-align: right; }
.readout .accent { color: var(--teal); }
.check-field { display: flex !important; align-items: center; gap: 8px; font-size: .875rem; font-weight: 550; }
.check-field input { width: auto; accent-color: var(--teal); }
.secondary { border-color: #bed2d9; }
.connection-list { display: grid; gap: 3px; margin-block: 8px 16px; }
.connection-list h3 { margin-bottom: 3px; }
.trace-link { text-align: left; white-space: normal; overflow-wrap: anywhere; padding: 5px 7px; border-left: 2px solid #92bcb5; border-radius: 0 4px 4px 0; }
.trace-link span { display: block; color: var(--muted); font-size: .8rem; font-weight: 450; }
.terminal-markings, .branch-controls { margin-top: 16px; }
.terminal-markings summary { cursor: pointer; font-size: .875rem; font-weight: 650; }
.terminal-markings .fields { margin-top: 8px; }
.branch-controls { display: grid; gap: 6px; }
.branch-control { display: grid; gap: 4px; padding-block: 5px; border-bottom: 1px solid var(--line); }
.branch-control label { display: flex; align-items: center; justify-content: space-between; gap: 4px; font-size: .875rem; }
.branch-control label input[type=number] { width: 74px; }
.branch-control .check-field { justify-content: start; }
.branch-control small { color: var(--muted); }
.size-reviews { margin-bottom: 18px; display: grid; gap: 8px; }
.size-review { display: grid; gap: 4px 8px; grid-template-columns: auto 1fr; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.size-review .secondary, .size-review p, .size-review small { grid-column: 1 / -1; }
.size-review small { color: var(--muted); }
.size-review .secondary { justify-self: start; }
.review-target { text-align: left; padding: 0; color: #075e53; text-decoration: underline; white-space: normal; }
#issue-count.has-errors { color: #a1302b; }
.node.has-sizing-issue .node-heading::after { content: "!"; margin-left: auto; border: 1px solid #a65c13; border-radius: 50%; font: 700 11px/15px var(--mono); text-align: center; width: 15px; color: #86460a; background: #fff1d4; flex-shrink: 0; }
.wire-label-handle.has-sizing-issue .wire-text { fill: #8a400a; text-decoration: underline dotted; }
.wire.has-sizing-issue .wire-line { stroke-dasharray: 6 2.5; }
.sizing-issue { padding: 7px 9px; border-left: 3px solid #bc7321; color: #72420c; background: #fff4de; font-size: .82rem; }
.danger { color: #a1302b; margin-top: 12px; }
.primary { background: var(--ink); color: #fff; }
.primary:hover { background: #264957; }
.issue {
  display: block;
  width: 100%;
  padding: 8px 9px;
  margin: 0 0 6px;
  white-space: normal;
  text-align: left;
  border: 1px solid var(--line);
  border-left: 3px solid #508690;
  background: #fff;
}
.issue[data-level="warning"] { border-left-color: #ba7b22; }
.issue[data-level="error"] { border-left-color: var(--red); }
.issue small { display: block; font-size: .75rem; color: var(--muted); }
.status { min-height: 42px; border-top: 1px solid var(--line); background: #fff; color: var(--muted); font-size: .78rem; }
.totals { display: flex; gap: clamp(8px, 2.2vw, 32px); flex-wrap: wrap; }
.totals strong { font: 680 .85rem var(--mono); color: var(--ink); margin-right: 3px; }
#save-status { white-space: nowrap; }
dialog { width: min(560px, calc(100vw - 24px)); max-height: 85dvh; overflow: auto; padding: 18px; border: 1px solid #a9bec9; border-radius: 9px; color: var(--ink); background: var(--paper); }
dialog::backdrop { background: #0f283b57; }
dialog header, dialog footer, .cable-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
dialog header h2 { font-size: 1.15rem; }
dialog footer { justify-content: flex-end; margin-top: 16px; }
dialog p { font-size: .875rem; }
dialog header button { font-size: 1.2rem; }
.setting-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-block: 12px 18px; }
.settings-environment { margin-top: 12px; }
.project-type-options { display: grid; gap: 8px; margin: 10px 0 12px; padding: 0; min-width: 0; border: 0; }
.project-type-options legend { margin: 0 0 7px; padding: 0; color: var(--muted); font-size: .875rem; font-weight: 650; }
.project-type-option { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 5px; cursor: pointer; }
.project-type-option:has(input:checked) { border-color: var(--teal); background: #e5f4f0; }
.project-type-option input { width: auto; flex-shrink: 0; margin: 0; accent-color: var(--teal); }
.project-type-option strong, .project-type-option small { display: block; }
.project-type-option strong { font-size: .94rem; }
.project-type-option small { color: var(--muted); font-size: .8125rem; }
.table-scroll { overflow-x: auto; margin: 8px 0 12px; }
table { width: 100%; border-collapse: collapse; font-size: .8125rem; text-align: left; }
td, th { padding: 3px 3px; }
td input { min-width: 74px; }
.error-text { color: var(--red); margin-top: 6px; }
.notice { position: fixed; padding: 8px 12px; max-width: calc(100vw - 32px); bottom: 55px; left: 50%; transform: translateX(-50%); z-index: 10; background: var(--ink); color: white; border-radius: 6px; font-size: .875rem; }
@media (max-width: 1050px) {
  .editor { grid-template-columns: 190px minmax(0, 1fr) 236px; }
}
@media (max-width: 820px) {
  .mobile-panel { display: block; }
  .editor { display: block; }
  .sheet { height: 100%; }
  .library, .inspector {
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 3;
    width: min(290px, 78vw);
    box-shadow: 0 8px 20px #172b3542;
  }
  .library { left: 0; }
  .inspector { right: 0; }
  .editor[data-panel="library"] .library, .editor[data-panel="inspector"] .inspector { display: block; }
}
@media (max-width: 515px) {
  .app { grid-template-rows: 88px 44px minmax(0, 1fr) auto; }
  .masthead { display: grid; grid-template-columns: 1fr auto; grid-template-rows: 43px 37px; gap: 0 7px; padding: 4px 8px; }
  .brand h1 { font-size: .98rem; }
  .brand { gap: 5px; }
  .project-name { grid-column: 1 / -1; grid-row: 2; width: 100%; text-align: left; }
  .file-actions { grid-column: 2; grid-row: 1; }
  .file-actions button, .file-actions summary, .tools button, .tools summary { padding-inline: 6px; }
  .tools, .status { padding-inline: 8px; gap: 4px; }
  .tool-group { gap: 2px; }
  #undo, #redo { min-width: 26px; padding-inline: 3px; }
  .status { min-height: 45px; }
  .totals { gap: 2px 8px; }
  .totals span { white-space: nowrap; }
  #save-status { display: none; }
}
@media (max-width: 435px) {
  .app { grid-template-rows: 88px 75px minmax(0, 1fr) auto; }
  .tools { display: grid; grid-template-columns: 1fr; align-content: center; gap: 0; position: relative; z-index: 4; }
  .tools .tool-group:last-child { justify-content: flex-end; }
  #templates-menu { position: static; }
  #templates-menu .menu { top: calc(100% + 2px); left: 8px; max-width: calc(100vw - 16px); }
}
@media (prefers-reduced-motion: reduce) {
  .wire-energy { animation: none; }
}

/* Connection feedback stays visible at every canvas zoom. */
.is-wiring .port:not([aria-pressed="true"]) { background: transparent; }
.node.is-wire-end:not(.is-selected) { border-color: #68a99e; }
.port[data-wire-linked]::after { box-shadow: 0 0 0 var(--wire-target-ring, 2px) #9fc8c3; }
.port[data-wire-ready]::after { box-shadow: 0 0 0 var(--wire-target-ring, 2px) #9de1d5; }
.port[data-wire-snap]::after {
  background: #008978;
  border-color: #008978;
  box-shadow: 0 0 0 var(--wire-snap-ring, 4px) #76ccba;
}
.wire[data-polarity="signal"], .port[data-polarity="signal"] { --wire: #92723b; }
.port-label { max-width: 72px; overflow: hidden; text-overflow: ellipsis; }
.wire-underlay { fill: none; stroke: #eef5f8; stroke-width: 5.8px; pointer-events: none; }
.wire.is-linked .wire-line { stroke-width: 3.2px; }
.wire.is-muted { opacity: .48; }
.wire.is-muted:hover, .wire.is-muted:focus-within { opacity: 1; }

a.brand{color:inherit;text-decoration:none}
a.brand:focus-visible{outline:2px solid currentColor;outline-offset:3px}
.brand .edition{font:600 11px/1.3 var(--mono);color:#c2d5cc}
