:root {
  --bg: #14161a;
  --panel: #1d2026;
  --line: #2c313a;
  --grid-line: #262b33;
  --text: #e6e8eb;
  --muted: #8b929c;
  --accent: #4c8bf5;
  --danger: #e5484d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.4 system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

h1 { font-size: 16px; margin: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

button, .file-label {
  background: #262b33;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
button:hover, .file-label:hover { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: default; border-color: var(--line); }

.file-label { position: relative; }
.file-label input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-label:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.file-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.file-actions > * { display: flex; align-items: center; justify-content: center; text-align: center; }

main {
  display: flex;
  align-items: stretch;
  gap: 20px;
  padding: 20px;
  height: calc(100vh - 60px);
}

.panel {
  width: 300px;
  flex: 0 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  max-height: 100%;
  overflow: auto;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  flex: 1 1 auto;
  min-width: 0;
  background-color: #0f1115;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 48px 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  touch-action: none;
}

.zoom-level {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 10;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(15, 17, 21, .8);
  border: 1px solid var(--line);
  color: var(--muted);
  font: 11px/1.2 ui-monospace, monospace;
  pointer-events: none;
}

.palette { display: flex; flex-wrap: wrap; gap: 8px; }

.palette button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: calc((100% - 16px) / 3);
  min-height: 94px;
  padding: 8px 4px;
}

.palette-icon {
  display: block;
  width: 80px;
  height: 56px;
  max-width: 100%;
}

.palette-icon .art {
  display: block;
  width: 100%;
  height: 100%;
}

.palette .name { font-size: 12px; }
.palette button.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.hint { color: var(--muted); font-size: 12px; }

.grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  will-change: transform;
  outline: none;
}

.wire {
  position: absolute;
  z-index: 3;
  border-radius: 2px;
  background: #2a6b78;
  cursor: pointer;
}
.wire.selected {
  box-shadow: 0 0 0 2px #fff;
}
.wire.on {
  background: #7ff0ff;
  box-shadow: 0 0 6px #7ff0ff;
}
.wire.off {
  background: #2a6b78;
}
.wire.on.selected {
  box-shadow: 0 0 0 2px #fff, 0 0 6px #7ff0ff;
}
.wire.invalid {
  background: rgba(229, 72, 77, .5);
}

.wire-preview {
  position: absolute;
  z-index: 5;
  border-radius: 2px;
  pointer-events: none;
}
.wire-preview.valid { background: rgba(127, 240, 255, .55); }
.wire-preview.invalid { background: rgba(229, 72, 77, .45); }
.wire-preview.remove { background: rgba(229, 72, 77, .7); }
.wire-anchor {
  position: absolute;
  z-index: 6;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border: 2px solid #7ff0ff;
  border-radius: 50%;
  background: #122d36;
  pointer-events: none;
}

.pin {
  position: absolute;
  z-index: 4;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: #ffd76a;
  border: 1px solid rgba(0, 0, 0, .45);
  pointer-events: none;
}
.pin.in { background: #cfe1ff; }
.pin.out { background: #ffd76a; }

.toolbar button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  color: #cfe1ff;
}

.comp {
  position: absolute;
  z-index: 2;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, .25);
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 11px/1 ui-monospace, monospace;
  color: rgba(0, 0, 0, .65);
  user-select: none;
  transition: box-shadow .08s;
}
.comp.shaped {
  border-color: transparent;
  background: transparent;
  border-radius: 0;
}
.comp .art {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.comp .led-body { transition: fill .12s, stroke .12s; }
.comp.lit .led-body { fill: #ff4136; stroke: #ffb0aa; filter: drop-shadow(0 0 6px #ff4136); }

.comp.selected { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.comp.invalid { box-shadow: 0 0 0 2px var(--danger); }
.comp:active { cursor: grabbing; }

.canvas-wrap.placing { cursor: crosshair; }
.canvas-wrap.wire-mode { cursor: crosshair; }
.canvas-wrap.pan { cursor: grab; }
.canvas-wrap.panning { cursor: grabbing; }
.canvas-wrap.select-mode { cursor: crosshair; }
.canvas-wrap.select-mode .comp { cursor: pointer; }
.selection-box { position: absolute; z-index: 7; border: 1px solid var(--accent); background: rgba(76, 139, 245, .18); pointer-events: none; }

.property { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0; font-size: 12px; }
.property[hidden] { display: none; }
.property input { width: 65px; padding: 5px; color: var(--text); background: #0f1115; border: 1px solid var(--line); border-radius: 5px; }
.property select { padding: 5px; color: var(--text); background: #0f1115; border: 1px solid var(--line); border-radius: 5px; }
#bus-status.error { color: #ff777b; }

.bus-value-row { align-items: flex-start; }
#selected-value { max-width: 180px; text-align: right; overflow-wrap: anywhere; font: 12px/1.4 ui-monospace, monospace; color: #9fe8b0; }
