:root {
  --ink: #12233f;
  --blue: #1268f4;
  --blue-dark: #0748b6;
  --cyan: #12cbe8;
  --yellow: #ffd21f;
  --line: #dce6f3;
  --soft: #f3f7fc;
  --green: #19a967;
  --muted: #66778f;
  --danger: #d92e3b;
  font-family: "Nunito Sans","Segoe UI",Arial,sans-serif;
  color: var(--ink);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--soft);
  font-size: 13px;
}

button,input,select,textarea {
  font: inherit;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  border-radius: 5px;
  min-height: 32px;
  padding: 6px 9px;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

button:hover {
  background: #edf5ff;
  color: var(--blue);
}

button:disabled {
  opacity: .36;
  cursor: not-allowed;
}

button:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible,[tabindex]:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

input,select,textarea {
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  padding: 7px 9px;
  min-width: 0;
}

svg.icon {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

[data-icon] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.app-header {
  height: 61px;
  flex: none;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: none;
}

.brand strong {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -1px;
}

.brand strong span {
  font-size: 15px;
  color: var(--muted);
  letter-spacing: -.5px;
  margin-left: 5px;
}

.local-tag {
  font-size: 8px;
  letter-spacing: 1px;
  font-weight: 900;
  background: var(--soft);
  color: var(--muted);
  padding: 4px 5px;
  border-radius: 3px;
}

.project-heading {
  display: grid;
  gap: 2px;
  padding-left: 20px;
  border-left: 1px solid var(--line);
  min-width: 140px;
  flex: 1;
}

.project-heading input {
  border: 1px solid transparent;
  background: none;
  font-weight: 800;
  font-size: 14px;
  padding: 1px 4px;
  width: 100%;
  max-width: 400px;
}

.project-heading input:hover {
  border-color: var(--line);
}

#document-state {
  font-size: 10px;
  color: var(--muted);
  padding-left: 5px;
}

.project-actions {
  display: flex;
  gap: 4px;
}

.save-button {
  color: var(--blue);
  background: #edf5ff;
  border: 1px solid #d2e3fd;
}

.simulate {
  background: var(--yellow);
  border: 1px solid #e9bd0d;
  min-width: 106px;
  height: 35px;
}

.simulate:hover {
  background: #ffdf5c;
  color: var(--ink);
}

.simulate.running {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 45px;
  flex: none;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 5px 14px;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-right: 10px;
  border-right: 1px solid var(--line);
}

.toolbar button {
  min-height: 30px;
  padding: 5px 8px;
}

.toolbar .active {
  background: #e7f0ff;
  color: var(--blue);
  border-color: #c7dbff;
}

.tool-label {
  font-size: 12px;
}

.representation {
  margin-left: 3px;
}

.representation button {
  font-size: 11px;
  padding: 5px 10px;
}

.toolbar-spacer {
  flex: 1;
}

.snap-control {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  white-space: nowrap;
}

.snap-control input {
  accent-color: var(--blue);
}

.zoom-group {
  border: none;
  padding-right: 0;
}

.zoom-group output {
  font-size: 11px;
  min-width: 38px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.panel-toggle {
  display: none;
}

.editor-layout {
  display: grid;
  grid-template-columns: 216px minmax(0,1fr) 226px;
  min-height: 0;
  flex: 1;
}

.library,.inspector {
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.library {
  border-right: 1px solid var(--line);
}

.inspector {
  border-left: 1px solid var(--line);
}

.panel-heading {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex: none;
}

.panel-heading h1,.panel-heading h2 {
  font-size: 13px;
  margin: 0;
  font-weight: 800;
}

.panel-heading>span {
  color: var(--muted);
  font-size: 10px;
}

#library-count {
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 6px;
}

.library-search {
  display: flex;
  align-items: center;
  margin: 0 12px 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 8px;
  color: var(--muted);
}

.library-search input {
  border: 0;
  padding: 8px 5px;
  width: 100%;
  font-size: 11px;
}

.library-search .icon {
  width: 14px;
  height: 14px;
}

.library>select {
  margin: 0 12px 10px;
  font-size: 11px;
  width: calc(100% - 24px);
  padding: 7px;
}

#component-library {
  overflow: auto;
  flex: 1;
  padding: 0 9px 8px;
}

.category-label {
  font-size: 9px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--muted);
  margin: 13px 7px 5px;
}

.component-card {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  gap: 9px;
  text-align: left;
  padding: 5px 8px;
  min-height: 55px;
  margin: 2px 0;
  cursor: grab;
  touch-action: none;
}

.component-card:hover,.component-card.placing {
  background: var(--soft);
  border-color: var(--line);
  color: var(--ink);
}

.component-card:active {
  cursor: grabbing;
}

.component-card .thumbnail {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 45px;
  height: 42px;
  flex: none;
}

.component-card .thumbnail svg {
  width: 45px;
  height: 42px;
}

.component-card .card-text {
  min-width: 0;
  display: grid;
  gap: 3px;
  white-space: normal;
}

.component-card strong {
  font-size: 11px;
  line-height: 1.25;
}

.component-card small {
  font-size: 9px;
  color: var(--muted);
  font-weight: 500;
}

.component-card .grip {
  margin-left: auto;
  color: #aab9cd;
}

.library-foot {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  flex: none;
}

.library-foot p {
  margin: 0;
  font-size: 10px;
  line-height: 1.6;
}

.library-foot .icon {
  width: 15px;
}

.bench-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.bench-top {
  height: 35px;
  flex: none;
  background: #fafcff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 10px;
}

.bench-top>div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bench-top strong {
  font-size: 11px;
}

.bench-top .icon {
  width: 13px;
  height: 13px;
  color: var(--blue);
}

.sheet-type {
  color: var(--muted);
  padding-left: 7px;
  border-left: 1px solid var(--line);
}

#mode-badge {
  font-size: 9px;
  letter-spacing: .08em;
  color: var(--muted);
  font-weight: 900;
}

#mode-badge.running {
  color: var(--green);
}

#board {
  position: relative;
  flex: 1;
  overflow: hidden;
  background-color: #fff;
  background-image: radial-gradient(var(--line) 1px,transparent 1px);
  background-size: 20px 20px;
  touch-action: none;
  outline: none;
  isolation: isolate;
}

#board.tool-wire {
  cursor: crosshair;
}

#board.tool-pan {
  cursor: grab;
}

#board.dragging {
  cursor: grabbing;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.component-symbol {
  cursor: move;
  outline: none;
}

.simulating .component-symbol {
  cursor: default;
}

.simulating .component-symbol[data-kind^="button"],.simulating .component-symbol[data-kind="supply"] {
  cursor: pointer;
}

.selection-box {
  fill: #1268f408;
  stroke: var(--blue);
  stroke-width: 1.2;
  stroke-dasharray: 4 3;
  pointer-events: none;
}

.terminal {
  cursor: crosshair;
  fill: #fff;
  stroke: var(--blue);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.terminal:hover,.terminal.target {
  fill: var(--yellow);
  stroke-width: 3;
  filter: drop-shadow(0 0 3px #1268f470);
}

.simulating .terminal {
  pointer-events: none;
}

.wire-hit {
  stroke: transparent;
  stroke-width: 14;
  fill: none;
  cursor: pointer;
  vector-effect: non-scaling-stroke;
}

.wire-visible {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.wire-selection {
  fill: none;
  stroke: #1268f440;
  stroke-width: 9;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.wire-preview {
  fill: none;
  stroke: var(--blue);
  stroke-width: 2;
  stroke-dasharray: 6 4;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.wire-handle {
  fill: #fff;
  stroke: var(--blue);
  stroke-width: 2;
  cursor: move;
  vector-effect: non-scaling-stroke;
}

.wire-handle:hover {
  fill: var(--yellow);
}

#empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  color: var(--muted);
  padding-bottom: 40px;
}

#empty-state [data-icon] .icon {
  width: 58px;
  height: 58px;
  color: #a2b9da;
  stroke-width: 1.1;
}

#empty-state h2 {
  font-size: 18px;
  font-weight: 700;
  color: #657c9b;
  margin: 15px 0 8px;
}

#empty-state p {
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
  margin: 0;
}

#empty-state>span:last-child {
  font-size: 9px;
  margin-top: 20px;
  color: #8a9bb4;
}

#canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: #fffdf2;
  border: 1px solid #ede3b3;
  border-radius: 6px;
  box-shadow: 0 2px 8px #12233f06;
  padding: 7px 12px;
  font-size: 10px;
  max-width: 90%;
  text-align: center;
  pointer-events: none;
}

.bench-bottom {
  height: 27px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: #fafcff;
  border-top: 1px solid var(--line);
  font-size: 9px;
  color: var(--muted);
  gap: 8px;
  flex: none;
}

.legend {
  display: flex;
  gap: 10px;
}

.legend>span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: block;
}

.legend .voltage {
  background: var(--yellow);
  border: 1px solid #cba700;
}

.legend .return {
  background: var(--blue);
}

#coordinates {
  min-width: 72px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#properties {
  padding: 4px 16px 18px;
  overflow: auto;
  flex: 1;
}

.selection-empty {
  padding: 28px 3px;
  text-align: center;
  color: var(--muted);
}

.selection-empty .icon {
  width: 28px;
  height: 28px;
  margin: auto;
  color: #a2b9da;
}

.selection-empty h3 {
  font-size: 12px;
  font-weight: 700;
  color: #718198;
  margin: 14px 0 7px;
}

.selection-empty p {
  font-size: 11px;
  line-height: 1.65;
  margin: 0;
}

.prop-kind {
  font-size: 9px;
  letter-spacing: .1em;
  color: var(--blue);
  text-transform: uppercase;
  font-weight: 900;
  margin: 9px 0 8px;
}

.prop-id {
  font-size: 23px;
  letter-spacing: -.7px;
  margin: 0 0 18px;
}

.property {
  display: grid;
  gap: 6px;
  margin: 0 0 14px;
}

.property label,.property>span {
  font-size: 10px;
  color: var(--muted);
  font-weight: 700;
}

.property input,.property select {
  font-size: 12px;
  width: 100%;
  padding: 8px;
}

.property input[type=color] {
  height: 34px;
  padding: 3px;
}

.property.readonly strong {
  font-size: 12px;
  font-weight: 600;
}

.property-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.prop-divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

.terminal-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.terminal-list span {
  font: 10px Consolas,monospace;
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 4px;
  padding: 5px 8px;
}

.prop-note {
  font-size: 10px;
  line-height: 1.6;
  color: var(--muted);
}

.state-pill {
  display: inline-block;
  background: var(--soft);
  border: 1px solid var(--line);
  font-size: 10px;
  font-weight: 800;
  padding: 6px 9px;
  border-radius: 5px;
  margin-top: 6px;
}

.state-pill.on {
  color: #107246;
  background: #edf9f3;
  border-color: #bfe6d5;
}

.inspector-foot {
  border-top: 1px solid var(--line);
  padding: 15px 16px;
  flex: none;
}

.model-badge {
  font-size: 8px;
  letter-spacing: .12em;
  font-weight: 800;
  color: var(--muted);
}

.inspector-foot p {
  font-size: 10px;
  line-height: 1.7;
  color: var(--muted);
  margin: 7px 0;
}

.inspector-foot button {
  font-size: 10px;
  padding: 3px 0;
  min-height: 22px;
  color: var(--blue);
}

.statusbar {
  height: 27px;
  background: var(--ink);
  color: #d5e2f6;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 0 13px;
  flex: none;
}

.statusbar>span:last-child {
  white-space: nowrap;
  color: #91a9cb;
}

.statusbar b {
  margin-left: 7px;
  color: var(--yellow);
}

#status-message {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.statusbar.error {
  background: #9b2433;
  color: #fff;
}

#simulation-controls {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 3px 12px #12233f10;
}

#simulation-controls button {
  font-size: 11px;
  background: var(--soft);
  border-color: var(--line);
}

#simulation-controls button[aria-pressed=true] {
  background: #fff7cf;
  border-color: var(--yellow);
}

#simulation-state {
  font-size: 10px;
  padding-right: 7px;
  color: var(--muted);
}

#drag-preview {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  width: 100px;
  height: 100px;
  opacity: .8;
  transform: translate(-50%,-50%);
  filter: drop-shadow(0 4px 5px #12233f30);
}

#drag-preview svg {
  width: 100%;
  height: 100%;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  max-width: 570px;
  width: calc(100% - 30px);
  color: var(--ink);
  box-shadow: 0 15px 70px #12233f35;
}

dialog::backdrop {
  background: #12233f55;
  backdrop-filter: blur(2px);
}

.dialog-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
}

.dialog-top h2 {
  font-size: 20px;
  margin: 0;
}

.dialog-top button {
  font-size: 23px;
  padding: 0;
  min-width: 30px;
}

dialog p {
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
}

dialog input[type=file] {
  width: 100%;
  padding: 13px;
  background: var(--soft);
}

dialog h3 {
  font-size: 13px;
  margin: 23px 0 8px;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 22px;
}

.help-grid p {
  margin: 4px 0;
}

.help-grid b {
  display: block;
  color: var(--ink);
  margin-bottom: 4px;
}

dialog details {
  margin-top: 18px;
  font-size: 12px;
}

dialog summary {
  cursor: pointer;
  color: var(--blue);
  font-weight: 700;
}

dialog textarea {
  margin: 12px 0;
  width: 100%;
  height: 150px;
  font: 11px/1.4 Consolas,monospace;
}

#import-message {
  color: var(--danger);
}

[hidden] {
  display: none!important;
}

@media (prefers-reduced-motion:no-preference) {
  .component-symbol [data-moving] {
    transition: transform .12s ease;
  }
  .component-symbol [data-glow] {
    transition: opacity .15s ease;
  }
}

@media (max-width:1100px) {
  .editor-layout {
    grid-template-columns: 194px minmax(0,1fr) 200px;
  }
  .toolbar {
    gap: 4px;
    padding: 5px 8px;
  }
  .tool-group {
    padding-right: 5px;
  }
  .app-header {
    gap: 13px;
    padding: 0 12px;
  }
  .tool-label,.sheet-type,.local-tag {
    display: none;
  }
  .legend {
    gap: 6px;
  }
  .bench-bottom #coordinates {
    display: none;
  }
}

@media (max-width:900px) {
  .toolbar {
    flex-wrap: wrap;
  }
  .editor-layout {
    grid-template-columns: 194px minmax(0,1fr);
  }
  .inspector {
    position: fixed;
    right: 0;
    top: var(--panel-top, 106px);
    bottom: 27px;
    width: 230px;
    z-index: 20;
    box-shadow: -5px 0 15px #12233f12;
    display: none;
  }
  .inspector.open {
    display: flex;
  }
  #inspector-toggle {
    display: inline-flex;
  }
  .project-heading {
    padding-left: 10px;
  }
  .project-actions button span:last-child {
    display: none;
  }
  .representation button {
    padding: 5px 7px;
  }
  .snap-control>span {
    display: none;
  }
}

@media (max-width:800px) {
  .app-header {
    height: 55px;
    gap: 10px;
  }
  .brand strong {
    font-size: 19px;
  }
  .brand strong span {
    display: none;
  }
  .brand img {
    width: 26px;
    height: 26px;
  }
  .project-heading {
    min-width: 85px;
    padding-left: 8px;
  }
  .project-heading input {
    font-size: 12px;
  }
  .project-heading>span {
    font-size: 8px;
  }
  .project-actions {
    gap: 0;
  }
  .project-actions button {
    padding: 5px;
  }
  .simulate {
    min-width: 35px;
    width: 35px;
    padding: 7px;
  }
  #simulate-label {
    display: none;
  }
  .toolbar {
    min-height: 80px;
    flex-wrap: wrap;
    align-content: center;
    gap: 5px 3px;
    padding: 5px 8px;
  }
  .toolbar-spacer {
    display: none;
  }
  .toolbar .representation {
    margin-left: 0;
  }
  .toolbar .representation button {
    font-size: 10px;
  }
  .toolbar .tool-group {
    padding-right: 4px;
  }
  .toolbar button {
    padding: 5px 7px;
  }
  .editor-layout {
    grid-template-columns: minmax(0,1fr);
  }
  .library {
    position: fixed;
    left: 0;
    top: var(--panel-top, 106px);
    bottom: 27px;
    width: 216px;
    z-index: 21;
    box-shadow: 5px 0 15px #12233f15;
    display: none;
  }
  .library.open {
    display: flex;
  }
  .inspector {
    top: var(--panel-top, 106px);
  }
  .panel-toggle {
    display: inline-flex;
  }
  .bench-top {
    padding: 0 12px;
  }
  .legend>span:last-child {
    display: none;
  }
  #canvas-hint {
    font-size: 9px;
    padding: 6px 8px;
    bottom: 12px;
  }
  .statusbar>span:last-child {
    display: none;
  }
  #simulation-controls {
    gap: 5px;
    left: 8px;
    top: 8px;
  }
  #simulation-state {
    font-size: 9px;
  }
  .help-grid {
    grid-template-columns: 1fr;
  }
}
