:root {
  color-scheme: light;
  --bg: #edf3f8;
  --surface: #ffffff;
  --surface-soft: #f6f9fc;
  --surface-strong: #e5eef5;
  --ink: #14202b;
  --muted: #667684;
  --line: #cbd8e3;
  --line-soft: #e2eaf1;
  --accent: #0f6b7a;
  --accent-strong: #0a4f5c;
  --accent-soft: #dff2f5;
  --danger: #b42318;
  --danger-soft: #fff2f0;
  --ok: #19703d;
  --warning: #b54708;
  --lamp: #f5c542;
  --shadow: 0 10px 28px rgba(32, 54, 71, 0.12);
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  max-width: 100vw;
  background: var(--bg);
  color: var(--ink);
}

button,
.import-button,
summary {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

button:hover,
.import-button:hover,
summary:hover {
  border-color: var(--accent);
  background: var(--surface-soft);
}

button:focus-visible,
input:focus-visible,
summary:focus-visible,
label:focus-within {
  outline: 3px solid #8fd3df;
  outline-offset: 2px;
}

.app-shell {
  height: 100vh;
  min-width: 320px;
  max-width: 100vw;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr) clamp(300px, 22vw, 360px);
  grid-template-rows: 64px minmax(0, 1fr) 42px;
  grid-template-areas:
    "top top top"
    "left main right"
    "status status status";
}

.app-shell.library-collapsed {
  grid-template-columns: 0 minmax(0, 1fr) clamp(300px, 22vw, 360px);
}

.app-shell.properties-collapsed {
  grid-template-columns: 236px minmax(0, 1fr) 0;
}

.app-shell.library-collapsed.properties-collapsed {
  grid-template-columns: 0 minmax(0, 1fr) 0;
}

.app-shell.presentation-mode {
  grid-template-columns: 0 minmax(0, 1fr) 0;
}

.app-shell.presentation-mode .library,
.app-shell.presentation-mode .properties {
  display: none;
}

.topbar {
  grid-area: top;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(0, auto) auto;
  gap: 8px;
  align-items: center;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 220px;
  gap: 9px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.brand-mark svg {
  width: 24px;
  height: 24px;
  min-height: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linejoin: round;
}

h1,
h2,
h3,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 1.08rem;
  line-height: 1.1;
  white-space: nowrap;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

h2 {
  font-size: 0.98rem;
}

h3 {
  font-size: 0.86rem;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  flex-wrap: nowrap;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 6px;
  border-right: 1px solid var(--line-soft);
}

.tool-button,
.icon-button,
.import-button,
.more-actions summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 9px;
  white-space: nowrap;
  line-height: 1;
}

.tool-button svg,
.icon-button svg,
.more-actions svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.tool-button.primary:hover {
  background: var(--accent-strong);
}

.demo-button {
  border-color: #93c5d0;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 650;
}

.organize-button,
.presentation-button {
  border-color: #cbd8e3;
  background: #ffffff;
}

.icon-button {
  width: 42px;
  padding: 0;
}

.icon-button span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.more-actions {
  position: relative;
}

.more-actions summary {
  list-style: none;
}

.more-actions summary::-webkit-details-marker {
  display: none;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 230px;
  max-width: min(320px, calc(100vw - 24px));
  max-height: calc(100vh - 96px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  z-index: 20;
}

.menu-panel button,
.menu-panel .import-button {
  justify-content: flex-start;
  width: 100%;
}

.menu-panel h3 {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.menu-section {
  display: grid;
  gap: 6px;
}

.import-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.danger-soft {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #f1b8b2;
}

.view-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  margin: 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-strong);
}

.view-switch legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.view-switch label {
  display: grid;
  place-items: center;
  min-height: 34px;
  min-width: 66px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
}

.view-switch input {
  position: absolute;
  opacity: 0;
}

.view-switch label:has(input:checked) {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: 0 1px 4px rgba(32, 54, 71, 0.12);
  font-weight: 650;
}

.side-panel {
  min-width: 0;
  padding: 14px;
  background: var(--surface);
  overflow-x: hidden;
  overflow-y: auto;
  overflow-wrap: anywhere;
  word-break: normal;
}

.library {
  grid-area: left;
  border-right: 1px solid var(--line);
}

.properties {
  grid-area: right;
  border-left: 1px solid var(--line);
  max-width: 100%;
  box-sizing: border-box;
}

.properties,
.properties * {
  min-width: 0;
}

#properties-content {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-wrap: anywhere;
  word-break: normal;
}

.app-shell.library-collapsed .library,
.app-shell.properties-collapsed .properties {
  display: none;
}

.side-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.collapse-button {
  min-height: 32px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.component-list {
  display: grid;
  gap: 10px;
}

.component-category-title {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.component-card {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  min-height: 82px;
  padding: 10px;
  text-align: left;
  background: linear-gradient(180deg, #ffffff, #f8fbfd);
  overflow: hidden;
}

.component-card img {
  width: 76px;
  max-width: 100%;
  height: 52px;
  object-fit: contain;
}

.component-card span {
  min-width: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: normal;
}

.pack-value {
  fill: #14202b;
  font-size: 13px;
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 4px;
}

.power-supply-display {
  fill: #8ff0b2;
  font-size: 22px;
  font-weight: 700;
}

.lamp-brightness-halo {
  fill: var(--lamp);
  pointer-events: none;
}

.brightness-very-dim .lamp-bulb { fill: #fff0b0; opacity: 0.7; }
.brightness-dim .lamp-bulb { fill: #f8d96b; }
.brightness-normal .lamp-bulb { fill: #f5c542; }
.brightness-bright .lamp-bulb { fill: #ffd83d; }
.brightness-overdriven .lamp-bulb { fill: #ffe56b; stroke: #d24a2f; }
.brightness-unknown .lamp-bulb { fill: #f5c542; }

.lamp-overdrive-warning {
  fill: none;
  stroke: #d24a2f;
  stroke-width: 4px;
  stroke-dasharray: 6 4;
}

.led-light-halo {
  pointer-events: none;
  filter: drop-shadow(0 0 8px currentColor);
}

.led-color {
  pointer-events: none;
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 1.5px;
}

.polarized-terminal-label {
  fill: #26323d;
  font-size: 10px;
  font-weight: 800;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 3px;
  pointer-events: none;
}

.measurement-display {
  fill: #b8f7d0;
  font: 800 16px Arial, sans-serif;
  paint-order: stroke;
  stroke: #10281f;
  stroke-width: 2.5px;
}

.schematic-polarity-unknown {
  fill: #111820;
  font-size: 18px;
  font-weight: 800;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 4px;
}

.motor-direction-arc {
  fill: none;
  stroke: #fff;
  stroke-width: 7px;
  stroke-linecap: round;
  paint-order: stroke;
  filter: drop-shadow(0 0 1px #126c49);
}

.motor-direction-head {
  fill: #fff;
  stroke: #126c49;
  stroke-width: 2.5px;
  stroke-linejoin: round;
}

.motor-direction-unknown {
  fill: #fff;
  font-size: 24px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #8b5a12;
  stroke-width: 3px;
}

.hint,
.muted {
  color: var(--muted);
  line-height: 1.45;
}

.hint {
  margin-top: 14px;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 0.88rem;
}

.pack-note {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

.pack-note strong {
  color: var(--accent-strong);
}

.workspace {
  grid-area: main;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(31, 54, 74, 0.08);
}

.panel-chip {
  position: absolute;
  top: 10px;
  left: 12px;
  z-index: 3;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
}

.zoom-controls {
  position: absolute;
  right: 12px;
  top: 10px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 6px 18px rgba(32, 54, 71, 0.1);
}

.zoom-controls button {
  min-width: 32px;
  min-height: 32px;
  padding: 0 7px;
  white-space: nowrap;
}

.zoom-controls output {
  min-width: 44px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.schematic-zoom {
  top: 44px;
}

.schematic-info {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  z-index: 4;
  min-height: 30px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.95);
  color: #374151;
  font-size: 0.88rem;
  font-weight: 700;
  overflow: hidden;
  white-space: normal;
  line-height: 1.25;
  max-height: 46px;
}

svg {
  width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
}

.schematic-panel {
  display: none;
}

.workspace[data-view="schematic"] .real-panel {
  display: none;
}

.workspace[data-view="schematic"] .schematic-panel,
.workspace[data-view="split"] .schematic-panel {
  display: block;
}

.workspace[data-view="split"] {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.app-shell:has(.workspace[data-view="split"]) {
  grid-template-columns: 168px minmax(0, 1fr) clamp(260px, 20vw, 320px);
}

.app-shell:has(.workspace[data-view="split"]) .side-panel {
  padding: 10px;
}

.app-shell:has(.workspace[data-view="split"]) .component-card {
  grid-template-columns: 1fr;
  justify-items: center;
  gap: 6px;
  min-height: 84px;
  padding: 8px;
  text-align: center;
}

.app-shell:has(.workspace[data-view="split"]) .component-card img {
  width: 62px;
  height: 44px;
}

.statusbar {
  grid-area: status;
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
  padding: 6px 14px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
}

.statusbar [data-status-label] {
  color: var(--accent-strong);
  white-space: nowrap;
}

.statusbar [data-status-detail] {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.statusbar[data-state="closed"] [data-status-label] {
  color: var(--ok);
}

.statusbar[data-state="short-circuit"] [data-status-label] {
  color: var(--danger);
}

.statusbar[data-status-level="success"] [data-status-label] {
  color: var(--ok);
}

.statusbar[data-status-level="info"] [data-status-label] {
  color: var(--accent-strong);
}

.statusbar[data-status-level="warning"] [data-status-label] {
  color: var(--warning);
}

.statusbar[data-status-level="error"] [data-status-label] {
  color: var(--danger);
}

.statusbar[data-status-level="error"] {
  background: #fff7f6;
}

.property-group {
  display: grid;
  gap: 14px;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  align-content: start;
  overflow-x: hidden;
}

.property-group > * {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.selection-card,
.empty-help {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: var(--surface-soft);
  overflow-wrap: anywhere;
  word-break: normal;
}

.type-pill {
  justify-self: start;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
}

.property-row {
  display: grid;
  gap: 6px;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.property-row input[type="text"],
.property-row input[type="number"],
.property-row textarea,
.property-row select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  background: var(--surface);
  font: inherit;
  font-weight: 400;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
}

.switch-row input {
  width: 22px;
  height: 22px;
}

.connection-list {
  display: grid;
  gap: 7px;
  padding: 0;
  margin: 8px 0 0;
  list-style: none;
}

.connection-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
}

.connection-list strong {
  color: var(--ink);
  font-weight: 650;
}

.danger {
  color: var(--danger);
  border-color: #efb5ad;
  background: #fff8f7;
}

.grid-line {
  fill: none;
  stroke: #dce8f0;
  stroke-width: 1;
}

.wire {
  stroke: var(--wire-color, #263847);
  stroke-width: 5.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  cursor: pointer;
  filter: drop-shadow(0 1.5px 1.5px rgba(32, 54, 71, 0.2));
}

.wire-hit {
  stroke: transparent;
  stroke-width: 18;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  cursor: pointer;
}

.wire:hover,
.wire.selected {
  stroke-width: 7;
  filter: drop-shadow(0 0 0.28rem rgba(15, 107, 122, 0.5));
}

.wire.selected {
  stroke: var(--accent);
}

.wire-control {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 3;
  cursor: grab;
  filter: drop-shadow(0 1px 3px rgba(32, 54, 71, 0.22));
}

.wire-control:active {
  cursor: grabbing;
}

.wire-junction {
  fill: #26323d;
  stroke: #ffffff;
  stroke-width: 2;
  pointer-events: none;
}

.component {
  cursor: grab;
}

.component:active {
  cursor: grabbing;
}

.component-selection {
  fill: transparent;
  stroke: transparent;
  stroke-width: 3;
  pointer-events: all;
}

.component.selected .component-selection {
  stroke: var(--accent);
  stroke-width: 3;
  filter: drop-shadow(0 0 0.35rem rgba(15, 107, 122, 0.45));
}

.schematic-component.selected .schematic-selection {
  stroke: #0f6b7a;
}

.device-shadow {
  fill: rgba(39, 52, 65, 0.12);
  stroke: none;
}

.battery-body,
.switch-base,
.lamp-base {
  fill: #fbfdff;
  stroke: #5c6f7f;
  stroke-width: 2;
}

.battery-cell.plus {
  fill: #eff9fb;
  stroke: #2c7a89;
  stroke-width: 2;
}

.battery-cell.minus {
  fill: #f4f6f8;
  stroke: #7b8794;
  stroke-width: 2;
}

.symbol-line,
.schematic-symbol {
  stroke: #182736;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.symbol-line.soft {
  stroke-width: 2.2;
  opacity: 0.72;
}

.heavy {
  stroke-width: 6;
}

.switch-blade {
  stroke: #182736;
  stroke-width: 7;
  stroke-linecap: round;
  transition: d 120ms ease, transform 120ms ease;
}

.label,
.terminal-label,
.state-label,
.schematic-label {
  fill: var(--ink);
  font-size: 18px;
  font-weight: 750;
  letter-spacing: 0;
}

.schematic-letter {
  fill: #111820;
  font-size: 22px;
  font-weight: 700;
}

.schematic-polarity {
  fill: #111820;
  font-size: 14px;
  font-weight: 700;
}

.schematic-value {
  fill: #111820;
  font-size: 14px;
  font-weight: 700;
}

.component.motor.running .component-asset {
  filter: drop-shadow(0 0 5px rgba(35, 130, 90, 0.35));
}

@media (prefers-reduced-motion: no-preference) {
  .component.motor.running.rotation-clockwise .motor-rotor {
    transform-box: fill-box;
    transform-origin: center;
    animation: motor-spin-clockwise 1s linear infinite;
  }

  .component.motor.running.rotation-counterclockwise .motor-rotor {
    transform-box: fill-box;
    transform-origin: center;
    animation: motor-spin-counterclockwise 1s linear infinite;
  }
}

@keyframes motor-spin-clockwise { to { transform: rotate(360deg); } }
@keyframes motor-spin-counterclockwise { to { transform: rotate(-360deg); } }

@media (prefers-reduced-motion: reduce) {
  .component.motor .motor-rotor { animation: none !important; }
}

.terminal-label {
  font-size: 18px;
}

.plus-label {
  fill: var(--accent-strong);
}

.minus-label {
  fill: #4b5563;
}

.state-label {
  fill: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.terminal-hit {
  cursor: crosshair;
  pointer-events: all;
}

.terminal-touch {
  fill: transparent;
  stroke: transparent;
  pointer-events: all;
}

.terminal-ring {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 4;
  filter: drop-shadow(0 2px 3px rgba(32, 54, 71, 0.2));
  pointer-events: all;
}

.terminal-hit:hover .terminal-ring,
.terminal-hit.pending .terminal-ring {
  fill: #ccebf0;
  stroke-width: 5;
}

.pack-label {
  fill: var(--ink);
  font-size: 17px;
  font-weight: 750;
  letter-spacing: 0;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.86);
  stroke-width: 5;
}

.component-asset {
  pointer-events: none;
  overflow: visible;
}

.component-fallback {
  fill: #fff8f7;
  stroke: var(--danger);
  stroke-width: 2;
}

.pack-picker {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 0 8px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
}

.pack-picker legend {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.pack-picker label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--ink);
}

.export-picker {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 8px 0;
  border: 0;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
}

.export-picker legend {
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.contact,
.schematic-contact {
  fill: #ffffff;
  stroke: #17212b;
  stroke-width: 3;
}

.lamp-halo {
  fill: rgba(245, 197, 66, 0.2);
  stroke: none;
  transition: opacity 120ms ease;
}

.lamp-glass {
  fill: #fff8dc;
  stroke: #17212b;
  stroke-width: 4;
}

.lamp-glow {
  fill: var(--lamp);
  stroke: #17212b;
  stroke-width: 4;
}

.filament {
  fill: none;
  stroke: #7a4b00;
  stroke-width: 3;
  stroke-linecap: round;
}

.schematic-bg {
  fill: #ffffff;
}

.schematic-wire {
  stroke: #111820;
  stroke-width: 4;
  stroke-linecap: butt;
  stroke-linejoin: miter;
  fill: none;
}

.schematic-notice {
  fill: #ffffff;
  stroke: #d8e2ea;
  stroke-width: 1.5;
}

.schematic-symbol {
  stroke: #111820;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.schematic-symbol.heavy {
  stroke-width: 5;
}

.schematic-contact {
  fill: #ffffff;
  stroke: #111820;
  stroke-width: 3;
}

.schematic-lamp {
  fill: none;
  stroke: #111820;
  stroke-width: 4;
}

.schematic-junction {
  fill: #111820;
  stroke: none;
}

.schematic-label {
  fill: #111820;
  font-size: 20px;
  font-weight: 700;
}

.schematic-hit {
  fill: transparent;
  stroke: transparent;
  pointer-events: all;
}

.schematic-selection {
  fill: none;
  stroke: transparent;
  stroke-width: 1.5;
  stroke-dasharray: 6 5;
  pointer-events: none;
}

.schematic-message {
  fill: var(--muted);
  font-size: 20px;
}

.schematic-summary,
.schematic-section-title,
.schematic-state {
  fill: #374151;
  font-size: 13px;
  font-weight: 700;
}

.schematic-warning {
  fill: #92400e;
  font-size: 13px;
  font-weight: 700;
}

.empty-state rect {
  fill: rgba(255, 255, 255, 0.86);
  stroke: var(--line);
  stroke-width: 1.5;
}

.empty-title {
  fill: var(--ink);
  font-size: 24px;
  font-weight: 750;
}

.empty-text {
  fill: var(--muted);
  font-size: 17px;
}

@media (prefers-reduced-motion: no-preference) {
  .panel,
  .side-panel,
  .lamp-glow,
  .wire,
  button {
    transition: border-color 120ms ease, background-color 120ms ease, filter 120ms ease, opacity 120ms ease;
  }
}

@media (max-width: 1320px) {
  .topbar {
    grid-template-columns: minmax(220px, 1fr) minmax(0, auto) auto;
  }

  .brand {
    min-width: 220px;
  }

  .history-actions {
    border-right: 0;
    padding-right: 0;
  }

  .brand p {
    display: none;
  }

  .secondary-action {
    display: none;
  }

  .tool-button span {
    font-size: 0.88rem;
  }

  .view-switch label {
    min-width: 58px;
    font-size: 0.86rem;
  }
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 190px minmax(0, 1fr) 220px;
  }

  .app-shell.library-collapsed {
    grid-template-columns: 0 minmax(0, 1fr) 220px;
  }

  .app-shell.properties-collapsed {
    grid-template-columns: 190px minmax(0, 1fr) 0;
  }

  .actions {
    gap: 5px;
  }

  .tool-button,
  .more-actions summary {
    padding: 0 7px;
  }

  .workspace[data-view="split"] {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "top"
      "left"
      "main"
      "right"
      "status";
  }

  .app-shell.library-collapsed,
  .app-shell.properties-collapsed,
  .app-shell.library-collapsed.properties-collapsed {
    grid-template-columns: 1fr;
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px;
  }

  .brand {
    min-width: 0;
  }

  .actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .view-switch {
    justify-self: stretch;
  }

  .library,
  .properties {
    max-height: 148px;
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  .properties {
    border-top: 1px solid var(--line);
  }

  .component-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .component-card {
    grid-template-columns: 1fr;
    justify-items: center;
    min-height: 86px;
    text-align: center;
  }

  .component-card img {
    width: 70px;
  }

  .hint {
    margin-top: 8px;
  }

  .workspace {
    padding: 8px;
  }

  .zoom-controls {
    top: auto;
    bottom: 10px;
  }

  .statusbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
    min-height: 48px;
  }

  .statusbar [data-status-detail] {
    white-space: normal;
  }
}

@media (max-width: 620px) {
  .primary-actions,
  .history-actions {
    border-right: 0;
    padding-right: 0;
  }

  .tool-button span,
  .demo-button span,
  .more-actions span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .tool-button,
  .demo-button,
  .more-actions summary {
    width: 42px;
    padding: 0;
  }

  .view-switch label {
    min-width: 0;
    font-size: 0.84rem;
  }
}

.rotation-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 6px;
  align-items: center;
}

.rotation-controls button {
  min-height: 38px;
  white-space: nowrap;
}

.rotation-value {
  min-width: 48px;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.diagnostics-panel {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: normal;
}

.calculation-panel,
.circuit-summary-panel,
.calculation-help {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fbff;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-wrap: anywhere;
  word-break: normal;
}

.circuit-summary-panel {
  margin-bottom: 10px;
  background: #fffdf7;
}

.calculation-help {
  margin-top: 10px;
  background: #fbfdff;
}

.calculation-help summary {
  cursor: pointer;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.calculation-help p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.calculation-panel h3,
.circuit-summary-panel h3 {
  margin: 0 0 8px;
}

.calculation-duration {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, auto);
  gap: 8px;
  align-items: center;
  min-width: 0;
  margin-bottom: 8px;
  color: var(--muted);
  font-weight: 650;
  overflow-wrap: anywhere;
}

.calculation-duration span {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  min-width: 0;
}

.calculation-duration input {
  width: 74px;
  max-width: 100%;
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 8px;
  font: inherit;
}

.calculation-grid {
  display: grid;
  gap: 6px;
  margin: 0;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

.calculation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, auto);
  gap: 10px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid var(--line-soft);
  min-width: 0;
  max-width: 100%;
}

.calculation-row dt,
.calculation-row dd {
  min-width: 0;
  margin: 0;
}

.calculation-row dt {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.calculation-row dd {
  color: var(--ink);
  font-weight: 750;
  text-align: right;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
}

.calculation-explanation {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: normal;
}

.calculation-effect {
  margin: 7px 0 0;
  line-height: 1.3;
  overflow-wrap: anywhere;
  word-break: normal;
}

.calculation-effect-info {
  color: var(--muted);
}

.calculation-effect-warning {
  color: var(--warning);
  font-weight: 700;
}

.polarity-debug-panel {
  margin-top: 4px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fbfdff;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: normal;
}

.polarity-debug-panel h3 {
  margin: 0 0 8px;
}

.polarity-debug-panel dl {
  display: grid;
  gap: 5px;
  margin: 0;
}

.polarity-debug-panel div {
  display: grid;
  grid-template-columns: minmax(116px, 0.9fr) minmax(0, 1.1fr);
  gap: 8px;
  align-items: baseline;
}

.polarity-debug-panel dt {
  color: var(--muted);
  font-size: 0.78rem;
}

.polarity-debug-panel dd {
  margin: 0;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
}

.diagnostics-panel h3 {
  margin: 0 0 8px;
}

.diagnostics-panel ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: min(42vh, 360px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.diagnostic-item button {
  width: 100%;
  min-height: auto;
  display: grid;
  gap: 3px;
  padding: 8px 9px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  text-align: left;
  line-height: 1.25;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: normal;
}

.diagnostic-item button:disabled {
  cursor: default;
  opacity: 0.9;
}

.diagnostic-title {
  font-weight: 800;
}

.diagnostic-item span:not(.diagnostic-title) {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.diagnostic-item small {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  color: var(--muted);
}

.diagnostic-danger button {
  border-color: #d84b3d;
  background: #fff0ee;
}

.diagnostic-warning button {
  border-color: #d99a18;
  background: #fff7e6;
}

.diagnostic-unknown button {
  border-color: #7c6bd8;
  background: #f1efff;
}

.diagnostic-success button {
  border-color: #2f9d67;
  background: #ecfff5;
}

.diagnostic-info button {
  border-color: #8aa0b2;
  background: #f7fbff;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 14mm;
  }

  body {
    overflow: visible;
    background: #ffffff;
    color: #000000;
  }

  .topbar,
  .library,
  .properties,
  .statusbar,
  .zoom-controls,
  .schematic-info,
  .panel-chip {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .panel {
    display: block;
    height: auto;
    overflow: visible;
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .panel {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 12mm;
  }

  svg {
    width: 100%;
    height: auto;
    max-height: 260mm;
    background: #ffffff;
  }
}
