:root {
  --bg: #050816;
  --bg-elevated: #0b1020;
  --bg-elevated-soft: #10172f;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.1);
  --accent-strong: #0ea5e9;
  --danger: #fb7185;
  --text: #e5e7eb;
  --text-soft: #9ca3af;
  --grid-line: rgba(148, 163, 184, 0.25);
  --pin: #facc15;
  --component-body: #1f2937;
  --wire: #e5e7eb;
  --wire-active: #38bdf8;
  --led-off: #1f2937;
  --led-on: #22c55e;
  --bulb-on: #facc15;
  --transition-fast: 150ms ease-out;
  --transition-med: 220ms ease-out;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 999px;
  --shadow-soft: 0 18px 40px rgba(15, 23, 42, 0.9);
  --shadow-subtle: 0 10px 25px rgba(15, 23, 42, 0.8);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #0f172a 0, var(--bg) 55%, #020617 100%);
}

body {
  display: flex;
}

.app-root {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  grid-template-rows: 1fr;
  width: 100%;
  height: 100vh;
  max-width: none;
  margin: 0;
  padding: 12px;
  gap: 12px;
  min-height: 0;
}

@media (max-width: 900px) {
  .app-root {
    grid-template-columns: 1fr;
  }
}

.palette {
  background: linear-gradient(145deg, #020617, #020617 45%, #020617 100%);
  border-radius: var(--radius-lg);
  padding: 20px 18px 18px;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  overflow-x: hidden;
}

.palette-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.help-button {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #0b1120;
  border: none;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast), background var(--transition-fast);
}
.help-button:hover {
  background: var(--accent-strong);
  transform: scale(1.08);
}

.app-title {
  margin: 0;
  font-size: 1.4rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #e5e7eb;
}

.app-subtitle {
  margin: 4px 0 0;
  font-size: 0.82rem;
  color: var(--text-soft);
}

.palette-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.palette-section-small {
  padding-top: 10px;
}

.palette-hint {
  margin: 4px 0 8px;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.demo-select {
  width: 100%;
  appearance: none;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
  background: rgba(15, 23, 42, 0.95);
  color: var(--text);
  cursor: pointer;
  margin-top: 4px;
}

.demo-select:hover {
  border-color: rgba(56, 189, 248, 0.6);
}

.demo-select:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.demo-hint {
  margin: 6px 0 0;
  font-size: 0.7rem;
  color: var(--text-soft);
  opacity: 0.85;
  line-height: 1.35;
}

.demo-hint code {
  font-size: 0.65rem;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(15, 23, 42, 0.6);
}

.palette-heading {
  margin: 0 0 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.palette-details {
  margin-top: 10px;
  border: none;
}

.palette-details:first-of-type {
  margin-top: 0;
}

.palette-summary {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  padding: 6px 0;
  user-select: none;
}

.palette-summary::-webkit-details-marker {
  display: none;
}

.palette-summary::before {
  content: "▸ ";
  opacity: 0.7;
}

.palette-details[open] .palette-summary::before {
  content: "▾ ";
}

.palette-subheading {
  font-size: 0.75rem;
  color: var(--text-soft);
  margin: 8px 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.palette-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
  align-items: center;
}

.palette-section-label {
  width: 100%;
  flex-basis: 100%;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 6px;
  margin-bottom: 2px;
}

.palette-section-label:first-child {
  margin-top: 0;
}

.palette-item,
.secondary-button {
  appearance: none;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.85rem;
  background: rgba(15, 23, 42, 0.9);
  color: var(--text);
  cursor: pointer;
  margin: 2px 4px 4px 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    color var(--transition-fast);
}

.palette-item:hover,
.secondary-button:hover {
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.3);
  transform: translateY(-1px);
}

.palette-item:active,
.secondary-button:active {
  transform: translateY(0);
  box-shadow: none;
}

.palette-item-disabled,
.palette-item-disabled:hover,
.palette-item-disabled:active {
  opacity: 0.4;
  cursor: default;
  transform: none;
  box-shadow: none;
  background: rgba(15, 23, 42, 0.9);
  border-color: var(--border-subtle);
}

.palette-item[data-active="true"] {
  background: var(--accent-strong);
  border-color: transparent;
  color: #0b1120;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.6), 0 12px 30px rgba(56, 189, 248, 0.45);
}

.secondary-button {
  width: 100%;
  justify-content: center;
  background: rgba(15, 23, 42, 0.95);
}

.board-container {
  background: rgba(15, 23, 42, 0.9);
  border-radius: var(--radius-lg);
  padding: 14px 14px 12px;
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 10px;
}

.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px 4px;
}

.board-title-group {
  display: flex;
  flex-direction: column;
}

.board-title {
  margin: 0;
  font-size: 1.05rem;
}

.board-hint {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.board-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.board-controls-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.board-tool-btn {
  padding: 6px 10px;
  font-size: 0.75rem;
  white-space: nowrap;
}

.board-tool-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.board-tool-btn[data-active="true"] {
  background: var(--accent-strong);
  border-color: transparent;
  color: white;
}

/* Power toggle switch with indicator light */
.power-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 8px;
  background: var(--bg-elevated-soft);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-soft);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.power-toggle:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.power-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.power-toggle-track {
  position: relative;
  width: 44px;
  height: 22px;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.power-toggle[aria-checked="true"] .power-toggle-track {
  background: rgba(34, 197, 94, 0.2);
  border-color: var(--led-on);
}
.power-toggle-light {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--component-body);
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}
.power-toggle[aria-checked="true"] .power-toggle-light {
  background: var(--led-on);
  box-shadow: 0 0 8px var(--led-on), 0 0 16px rgba(34, 197, 94, 0.4);
}
.power-toggle-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: linear-gradient(180deg, #374151 0%, #1f2937 100%);
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.3);
  transition: transform var(--transition-fast);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.power-toggle[aria-checked="true"] .power-toggle-knob {
  transform: translateX(22px);
}
.power-toggle-labels {
  display: flex;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}
.power-label-off {
  color: var(--text-soft);
}
.power-label-on {
  color: var(--text-soft);
}
.power-toggle[aria-checked="false"] .power-label-off {
  color: var(--danger);
  font-weight: 700;
}
.power-toggle[aria-checked="true"] .power-label-on {
  color: var(--led-on);
  font-weight: 700;
}

.board-zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.board-zoom-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

.chip {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.95);
  color: var(--text-soft);
}

.board-wrapper {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: radial-gradient(circle at top left, #020617 0, #020617 40%, #020617 100%);
}

.board-staging {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  display: flex;
  min-width: 200px;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

/* When board is on, let clicks pass through staging so components can be selected */
.board-wrapper[data-power-on="true"] .board-staging {
  pointer-events: none;
}

.board-staging-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.board-staging-combine {
  display: none;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.board-staging-combine.visible {
  display: flex;
}

.board-staging-combine-label {
  font-size: 0.7rem;
  color: var(--text-soft);
  margin-right: 2px;
}

.staging-combine-btn {
  padding: 4px 8px;
  font-size: 0.7rem;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  background: var(--bg-elevated-soft);
  color: var(--text);
  cursor: pointer;
}

.staging-combine-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.staging-combine-add {
  display: none;
}

.board-staging-combine.add-mode .staging-combine-add {
  display: inline-block;
}

.board-staging-combine.add-mode .staging-combine-btn[data-combine-mode] {
  display: none;
}

.staging-slot-combined-badge {
  position: absolute;
  top: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(15, 23, 42, 0.95);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(56, 189, 248, 0.4);
  z-index: 2;
  pointer-events: none;
}

.staging-slot-combined-badge[data-mode="parallel"]::before {
  content: "‖ ";
}

.staging-slot-combined-badge[data-mode="series"]::before {
  content: "⊟ ";
}

.board-staging-slots {
  display: flex;
  gap: 8px;
}

.staging-slot {
  position: relative;
  width: 88px;
  min-height: 64px;
  border: 2px dashed rgba(148, 163, 184, 0.4);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--text-soft);
  background: rgba(15, 23, 42, 0.6);
  transition: border-color 0.15s, background 0.15s;
}

.staging-slot[data-type] {
  min-height: 100px;
}

.staging-slot:empty::after,
.staging-slot[data-empty="true"]::after {
  content: "—";
  color: rgba(148, 163, 184, 0.5);
}

.staging-slot[data-type] {
  border-style: solid;
  border-color: rgba(56, 189, 248, 0.5);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text);
  cursor: grab;
  font-weight: 600;
}

.staging-slot[data-type]:active {
  cursor: grabbing;
}

.staging-slot-inner {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
  pointer-events: none;
}

.staging-slot-preview {
  width: 100%;
  height: 72px;
  display: block;
  flex-shrink: 0;
  pointer-events: none;
}

.staging-slot-preview .pin-label {
  font-size: 10px;
  fill: var(--text-soft);
}

.staging-slot-actions {
  display: flex;
  gap: 2px;
  padding: 2px 2px 0;
  flex-shrink: 0;
  pointer-events: auto;
}

.staging-slot-delete,
.staging-slot-rotate {
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-soft);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.staging-slot-delete:hover,
.staging-slot-rotate:hover {
  background: rgba(56, 189, 248, 0.25);
  color: var(--text);
}

.staging-slot-delete:focus-visible,
.staging-slot-rotate:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.staging-slot-delete {
  color: #f87171;
}

.staging-slot-delete:hover {
  background: rgba(248, 113, 113, 0.2);
}

.board-svg {
  display: block;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at top, #020617 0, #020617 55%, #020617 100%);
  touch-action: none;
  cursor: default;
}

/* Tool-specific cursors over the board */
.board-wrapper[data-active-tool="move"] .board-svg {
  cursor: grab;
}
.board-wrapper[data-active-tool="move"].panning .board-svg {
  cursor: grabbing;
}
.board-wrapper[data-active-tool="wire"] .board-svg {
  cursor: crosshair;
}
.board-wrapper[data-active-tool="erase"] .board-svg {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Crect fill='white' stroke='%23374151' stroke-width='1.5' x='5' y='11' width='14' height='9' rx='1'/%3E%3Cpath fill='%23374151' d='M7 11 L12 4 L19 11 Z'/%3E%3C/svg%3E") 6 20, auto;
}

.io-panel {
  margin-top: 4px;
}

.io-panel details {
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-subtle);
}

.io-panel summary {
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text-soft);
}

.io-panel-body {
  padding: 0 10px 10px;
}

.io-panel-hint {
  margin: 0 0 8px;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.io-panel-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.io-panel-buttons .secondary-button {
  flex: 1;
}

.component-info {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--border-subtle);
  height: 320px;
  min-height: 320px;
  max-height: 320px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.component-info-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.component-info-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-soft);
}

.component-info-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-soft);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
}
.component-info-close:hover {
  background: var(--border-subtle);
  opacity: 1;
}

.component-info-body {
  font-size: 0.8rem;
  color: var(--text-soft);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.component-info-empty {
  margin: 2px 0 0;
}

.component-info-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  margin: 4px 0;
  line-height: 1.4;
}

.component-info-row .component-info-label {
  flex: 0 0 auto;
  min-width: 10em;
  opacity: 0.85;
}

.component-info-row strong {
  font-weight: 600;
  flex: 0 1 auto;
}

/* When label class not used, keep span and strong together */
.component-info-row span:first-child {
  opacity: 0.85;
}

.component-info-slider {
  align-items: center;
}

.component-info-range {
  width: 100px;
  accent-color: var(--accent);
}

.component-info-select {
  min-width: 120px;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.8rem;
  accent-color: var(--accent);
}

/* Shared 3-panel layout (kids training simulator) */
.info-panels {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0 6px;
  margin: 8px 0;
}

.info-panel {
  flex: 1 1 0;
  min-width: 90px;
  padding: 10px 8px;
  border-radius: 12px;
  text-align: center;
  position: relative;
  overflow: hidden;
  animation: info-panel-glow 3s ease-in-out infinite;
}

.info-panel-input {
  background: linear-gradient(145deg, rgba(34, 197, 94, 0.15), rgba(22, 163, 74, 0.08));
  border: 1px solid rgba(34, 197, 94, 0.4);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.15);
}

.info-panel-usage {
  background: linear-gradient(145deg, rgba(251, 191, 36, 0.15), rgba(245, 158, 11, 0.08));
  border: 1px solid rgba(251, 191, 36, 0.4);
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.15);
}

.info-panel-output {
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.15), rgba(14, 165, 233, 0.08));
  border: 1px solid rgba(56, 189, 248, 0.4);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.15);
}

.info-panel-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  opacity: 0.95;
}

.info-panel-input .info-panel-header { color: #4ade80; }
.info-panel-usage .info-panel-header { color: #fbbf24; }
.info-panel-output .info-panel-header { color: #38bdf8; }

.info-panel-values {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.info-panel-big {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
}

.info-panel-number {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
}

.info-panel-unit {
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.85;
  color: var(--text-soft);
}

.info-panel-labels {
  font-size: 0.65rem;
  margin-top: 4px;
  opacity: 0.7;
  color: var(--text-soft);
}

.info-panel-flow {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0 2px;
}

.info-panel-flow-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.6;
  animation: info-flow-bounce 1.2s ease-in-out infinite;
}

.info-panel-flow-dot:nth-child(1) { animation-delay: 0s; }
.info-panel-flow-dot:nth-child(2) { animation-delay: 0.2s; }
.info-panel-flow-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes info-panel-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.92; }
}

@keyframes info-flow-bounce {
  0%, 100% { transform: scale(0.8); opacity: 0.4; }
  50% { transform: scale(1.2); opacity: 0.9; }
}

/* Regulator 3-panel layout (kids training simulator) */
.regulator-panels {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0 6px;
  margin: 8px 0;
}

.regulator-panel {
  flex: 1 1 0;
  min-width: 90px;
  padding: 10px 8px;
  border-radius: 12px;
  text-align: center;
  position: relative;
  overflow: hidden;
  animation: regulator-panel-glow 3s ease-in-out infinite;
}

.regulator-panel-input {
  background: linear-gradient(145deg, rgba(34, 197, 94, 0.15), rgba(22, 163, 74, 0.08));
  border: 1px solid rgba(34, 197, 94, 0.4);
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.15);
}

.regulator-panel-usage {
  background: linear-gradient(145deg, rgba(251, 191, 36, 0.15), rgba(245, 158, 11, 0.08));
  border: 1px solid rgba(251, 191, 36, 0.4);
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.15);
}

.regulator-panel-output {
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.15), rgba(14, 165, 233, 0.08));
  border: 1px solid rgba(56, 189, 248, 0.4);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.15);
}

@keyframes regulator-panel-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.92; }
}

.regulator-panel-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  opacity: 0.95;
}

.regulator-panel-input .regulator-panel-header { color: #4ade80; }
.regulator-panel-usage .regulator-panel-header { color: #fbbf24; }
.regulator-panel-output .regulator-panel-header { color: #38bdf8; }

.regulator-panel-values {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.regulator-big-value {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
}

.regulator-number {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
}

.regulator-unit {
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.85;
  color: var(--text-soft);
}

.regulator-panel-labels {
  font-size: 0.65rem;
  margin-top: 4px;
  opacity: 0.7;
  color: var(--text-soft);
}

.regulator-flow {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0 2px;
}

.regulator-flow-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.6;
  animation: regulator-flow-bounce 1.2s ease-in-out infinite;
}

.regulator-flow-dot:nth-child(1) { animation-delay: 0s; }
.regulator-flow-dot:nth-child(2) { animation-delay: 0.2s; }
.regulator-flow-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes regulator-flow-bounce {
  0%, 100% { transform: scale(0.8); opacity: 0.4; }
  50% { transform: scale(1.2); opacity: 0.9; }
}

.regulator-efficiency-wrap {
  position: relative;
  width: 100%;
  max-width: 72px;
  height: 18px;
  margin-top: 4px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 9px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.regulator-efficiency-bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  border-radius: 9px;
  background: linear-gradient(90deg, #22c55e, #fbbf24);
  transition: width 0.3s ease;
}

.regulator-efficiency-pct {
  position: relative;
  z-index: 1;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.8), 0 1px 0 rgba(0, 0, 0, 0.5);
}

#json-textarea {
  width: 100%;
  min-height: 120px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: #020617;
  color: var(--text-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.8rem;
  padding: 8px;
  resize: vertical;
}

#json-textarea:focus {
  outline: none;
  border-color: rgba(56, 189, 248, 0.7);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.5);
}

.pin-hit-target {
  cursor: crosshair;
}

.pin-label {
  font-size: 11px;
  fill: var(--text-soft);
  pointer-events: none;
  user-select: none;
}

/* Battery text inside the body: larger so it's readable (not overridden by .pin-label) */
.battery-label {
  font-size: 26px !important;
  pointer-events: none;
  user-select: none;
}
.battery-label-pct {
  font-size: 32px !important;
}
.battery-label-volt,
.battery-label-amp {
  font-size: 24px !important;
}

.junction-blob {
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.5));
}

.component-hit-target {
  cursor: grab;
}

.component-hit-target:active {
  cursor: grabbing;
}

.component-selected {
  filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.8));
}

.component-combined-badge {
  font-size: 10px;
  font-weight: 700;
  fill: var(--accent);
  pointer-events: none;
  user-select: none;
}

.wire {
  stroke: var(--wire);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Invisible wide hit area for easier wire clicking (layer is on top of components) */
.wire-hit {
  stroke: transparent;
  stroke-width: 32;
  fill: none;
  pointer-events: stroke;
}

.wire-hot {
  stroke: var(--wire-active);
}

.wire-selected {
  stroke-width: 4;
  stroke-dasharray: 6 4;
}

.wire-pos {
  stroke: #ef4444; /* red for positive */
}

.wire-neg {
  stroke: #3b82f6; /* blue for negative */
}

.wire-live.wire-pos {
  filter: drop-shadow(0 0 6px rgba(239, 68, 68, 0.9));
  stroke-width: 5;
}

.wire-live.wire-neg {
  filter: drop-shadow(0 0 6px rgba(59, 130, 246, 0.9));
  stroke-width: 5;
}

/* LED fill/stroke/filter set in JS per ledColor (white, red, blue, green, yellow) */
.led-shape {
  stroke-width: 1.6;
  transition:
    fill var(--transition-med),
    stroke var(--transition-med),
    filter var(--transition-med);
}

.led-broken {
  fill: #1c1917;
  stroke: #ef4444;
  stroke-width: 3;
  filter: drop-shadow(0 0 12px rgba(239, 68, 68, 0.9));
  animation: broken-pulse 0.8s ease-in-out infinite;
}

.broken-x {
  stroke: #ef4444;
  stroke-width: 3;
  stroke-linecap: round;
  fill: none;
  animation: broken-flicker 0.5s ease-in-out infinite;
}

@keyframes broken-pulse {
  0%, 100% { opacity: 1; filter: drop-shadow(0 0 12px rgba(239, 68, 68, 0.9)); }
  50% { opacity: 0.85; filter: drop-shadow(0 0 18px rgba(239, 68, 68, 1)); }
}

@keyframes broken-flicker {
  0%, 100% { opacity: 1; stroke: #ef4444; }
  50% { opacity: 0.7; stroke: #f87171; }
}

/* Motor fan – rotation handled by SVG animateTransform (no CSS animation) */
.motor-fan-wrap {
  overflow: visible;
}

.bulb-shape {
  fill: #020617;
  stroke: #6b7280;
  stroke-width: 1.5;
  transition:
    fill var(--transition-med),
    stroke var(--transition-med),
    filter var(--transition-med);
}

.bulb-on {
  fill: var(--bulb-on);
  stroke: #fed7aa;
  filter: drop-shadow(0 0 10px rgba(250, 204, 21, 0.95));
}

.bulb-broken {
  fill: #1c1917;
  stroke: #ef4444;
  stroke-width: 2.5;
  filter: drop-shadow(0 0 12px rgba(239, 68, 68, 0.9));
  animation: broken-pulse 0.8s ease-in-out infinite;
}

.bulb-broken + .broken-x,
.led-broken + .broken-x {
  /* X overlay follows broken shape */
}

.capacitor-broken {
  animation: broken-pulse 0.8s ease-in-out infinite;
}

.smoke {
  fill: rgba(148, 163, 184, 0.5);
  filter: blur(2px);
  animation: smoke-drift 2s ease-in-out infinite;
}

@keyframes smoke-drift {
  0%, 100% { opacity: 0.6; transform: translateY(0); }
  50% { opacity: 0.9; transform: translateY(-3px); }
}

.switch-lever {
  transform-origin: center;
  transition: transform var(--transition-med);
}

/* Arcade button switch – button cap floats above, presses down onto switch */
.switch-arcade-cap {
  transform-origin: center;
  transform: translateY(-12px);
  transition: transform 0.06s ease-out;
}

.switch-arcade-cap.switch-arcade-pressed {
  transform: translateY(8px);
}

/* Plunger/actuator – sits between button and microswitch, moves with press */
.switch-arcade-plunger {
  transform-origin: center;
  transform: translateY(-6px);
  transition: transform 0.06s ease-out;
}

.switch-arcade-plunger.switch-plunger-pressed {
  transform: translateY(6px);
}

.battery-body-live {
  stroke: #38bdf8;
  filter: drop-shadow(0 0 12px rgba(56, 189, 248, 0.9));
}

.battery-body-depleted {
  stroke: #6b7280;
  opacity: 0.7;
}

.capacitor-fill {
  transition: y 0.25s ease-out, height 0.25s ease-out, fill 0.2s ease;
}

/* Help modal */
.help-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.help-modal[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
}
.help-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}
.help-modal-content {
  position: relative;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #0f172a 0%, #020617 100%);
  border-radius: var(--radius-lg);
  border: 2px solid var(--accent);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  padding: 0;
}
.help-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: rgba(56, 189, 248, 0.15);
  border-bottom: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.help-modal-title {
  margin: 0;
  font-size: 1.2rem;
  color: var(--text);
}
.help-modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}
.help-modal-close:hover {
  background: rgba(248, 113, 113, 0.3);
}
.help-modal-body {
  padding: 20px;
  font-size: 0.95rem;
  line-height: 1.6;
}
.help-intro {
  margin: 0 0 20px;
  color: var(--text);
}
.help-section {
  margin-bottom: 18px;
  padding: 14px 16px;
  border-radius: 12px;
  border-left: 4px solid;
}
.help-section-yellow {
  background: rgba(250, 204, 21, 0.12);
  border-left-color: #facc15;
}
.help-section-blue {
  background: rgba(56, 189, 248, 0.12);
  border-left-color: #38bdf8;
}
.help-section-green {
  background: rgba(34, 197, 94, 0.12);
  border-left-color: #22c55e;
}
.help-section-purple {
  background: rgba(167, 139, 250, 0.15);
  border-left-color: #a78bfa;
}
.help-section-tools {
  background: rgba(148, 163, 184, 0.1);
  border-left-color: #94a3b8;
}
.help-section-note {
  background: rgba(251, 113, 133, 0.1);
  border-left-color: #fb7185;
}
.help-section h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}
.help-section p, .help-section ul {
  margin: 0 0 8px;
  color: var(--text-soft);
}
.help-section ul {
  padding-left: 20px;
}
.help-section li {
  margin-bottom: 4px;
}

.hidden {
  display: none !important;
}

/* ── MCU Code Editor Modal ──────────────────────────────────────────────────── */
.mcu-editor-content {
  max-width: 680px;
  width: 95vw;
  max-height: 90vh;
}
.mcu-editor-body {
  padding: 14px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mcu-editor-top {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.mcu-editor-pins {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1 1 200px;
}
.mcu-pin-mode-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 5px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: rgba(15,23,42,0.9);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.mcu-pin-mode-btn:hover {
  background: rgba(56,189,248,0.1);
  border-color: rgba(56,189,248,0.4);
}
.mcu-pin-mode-btn.active {
  background: rgba(34,197,94,0.15);
  border-color: rgba(34,197,94,0.5);
}
.mcu-pin-name {
  font-size: 0.75rem;
  font-weight: 700;
  color: #e2e8f0;
}
.mcu-pin-mode {
  font-size: 0.6rem;
  color: #64748b;
  letter-spacing: 0.05em;
}
.mcu-pin-mode-btn.active .mcu-pin-mode {
  color: #4ade80;
}
.mcu-editor-examples {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.mcu-label {
  font-size: 0.72rem;
  color: var(--text-soft);
  font-weight: 600;
}
.mcu-select {
  background: rgba(15,23,42,0.95);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.82rem;
  padding: 6px 10px;
  cursor: pointer;
}
.mcu-editor-api-hint {
  font-size: 0.72rem;
  color: #64748b;
  background: rgba(15,23,42,0.6);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 6px 10px;
  line-height: 1.5;
}
.mcu-editor-api-hint code {
  color: #38bdf8;
  font-size: 0.8em;
}
.mcu-code-area {
  width: 100%;
  min-height: 220px;
  background: #0a0f1e;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: #e2e8f0;
  font-family: "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  padding: 12px 14px;
  resize: vertical;
  box-sizing: border-box;
  tab-size: 2;
}
.mcu-code-area:focus {
  outline: none;
  border-color: rgba(56,189,248,0.5);
  box-shadow: 0 0 0 2px rgba(56,189,248,0.15);
}
.mcu-code-error {
  background: rgba(69,10,10,0.8);
  border: 1px solid #ef4444;
  border-radius: 6px;
  color: #fca5a5;
  font-size: 0.78rem;
  font-family: monospace;
  padding: 8px 12px;
  white-space: pre-wrap;
}
.mcu-editor-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.mcu-btn-apply {
  appearance: none;
  background: rgba(34,197,94,0.2);
  border: 1px solid rgba(34,197,94,0.5);
  border-radius: 8px;
  color: #4ade80;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 20px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.mcu-btn-apply:hover {
  background: rgba(34,197,94,0.35);
  border-color: #4ade80;
}
.mcu-editor-hint {
  font-size: 0.72rem;
  color: #475569;
  flex: 1;
}

