:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-soft: #f9faf7;
  --ink: #172026;
  --muted: #5b6770;
  --line: #d5d9d2;
  --line-strong: #aeb7ad;
  --accent: #0f766e;
  --accent-soft: #e6f4f1;
  --warn: #b45309;
  --danger: #b91c1c;
  --hole: #7c8780;
  --pitch: 22px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

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

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
.back-link {
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 7px 11px;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.back-link:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

input,
select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 6px 9px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 244, .94);
  padding: 12px 18px;
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 260px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.planner-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 340px;
  gap: 14px;
  height: calc(100vh - 72px);
  min-height: 620px;
  padding: 14px;
}

.library-panel,
.board-panel,
.inspector-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.library-panel,
.inspector-panel {
  display: grid;
  align-content: start;
  overflow: hidden;
}

.board-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head.compact {
  padding: 12px 14px;
}

.panel-head h2 {
  margin: 2px 0 0;
  font-size: 18px;
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

#moduleSearch {
  width: 120px;
}

.category-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.category-tabs button {
  flex: none;
  min-height: 30px;
  padding: 5px 9px;
  font-size: 13px;
}

.category-tabs button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.module-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 196px);
  overflow: auto;
  padding: 12px;
}

.module-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.module-item[draggable="true"] {
  cursor: grab;
}

.module-item.is-disabled {
  opacity: .62;
}

.module-main {
  min-width: 0;
}

.module-main strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.35;
}

.module-main span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.tool-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tool-group label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

#boardCols,
#boardRows {
  width: 72px;
}

.dimension-x {
  color: var(--muted);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
}

.board-wrap {
  position: relative;
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, .07) 1px, transparent 1px),
    linear-gradient(rgba(15, 118, 110, .07) 1px, transparent 1px),
    #fbfcf8;
  background-size: var(--pitch) var(--pitch);
}

.board-wrap.is-drop-target {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

#boardSvg {
  display: block;
  min-width: 100%;
  min-height: 100%;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  padding: 8px 12px;
  color: var(--muted);
  font-size: 12px;
}

.inspector-panel {
  overflow: auto;
}

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

.selection-details,
.net-editor,
.wire-hint,
.wiring-list {
  padding: 12px 14px;
}

.empty-state {
  color: var(--muted);
}

.selection-card {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.selection-card strong {
  color: var(--ink);
  font-size: 15px;
}

.pin-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.pin-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
}

.net-editor {
  display: flex;
  gap: 8px;
}

.net-editor input {
  min-width: 0;
  flex: 1;
}

.wire-hint {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.wire-hint.is-active {
  color: var(--accent);
  font-weight: 800;
}

.wiring-section {
  min-height: 240px;
}

.wiring-list {
  display: grid;
  gap: 8px;
}

.wire-row {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: start;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: var(--panel-soft);
}

.wire-color {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  margin-top: 5px;
}

.wire-row input {
  width: 100%;
  min-height: 30px;
  margin-bottom: 6px;
}

.wire-row p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.wire-row button {
  min-height: 30px;
  padding: 4px 8px;
  color: var(--danger);
}

.board-hole {
  fill: #fff;
  stroke: var(--hole);
  stroke-width: 1;
}

.board-outline {
  fill: rgba(255, 255, 255, .56);
  stroke: var(--line-strong);
  stroke-width: 1.4;
}

.module-body {
  cursor: move;
  fill: rgba(255, 255, 255, .08);
  stroke: #0f766e;
  stroke-width: 1.4;
  stroke-dasharray: 5 4;
}

.module-body.is-selected {
  stroke: var(--accent);
  stroke-width: 2.4;
  stroke-dasharray: none;
}

.pin-rail {
  fill: rgba(15, 118, 110, .12);
  stroke: rgba(15, 118, 110, .45);
  stroke-width: 1;
  pointer-events: none;
}

.module-title {
  fill: var(--ink);
  font-size: 12px;
  font-weight: 800;
  pointer-events: none;
}

.module-meta {
  fill: var(--muted);
  font-size: 10px;
  pointer-events: none;
}

.pin-dot {
  cursor: crosshair;
  fill: #fff;
  stroke: #111827;
  stroke-width: 1.5;
}

.pin-dot.power {
  fill: #fee2e2;
  stroke: #dc2626;
}

.pin-dot.ground {
  fill: #e5e7eb;
  stroke: #374151;
}

.pin-dot.signal {
  fill: #e0f2fe;
  stroke: #0369a1;
}

.pin-dot.is-active {
  fill: #fef3c7;
  stroke: var(--warn);
  stroke-width: 2.4;
}

.pin-label {
  fill: #263238;
  font-size: 9px;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, .9);
  stroke-width: 3px;
  pointer-events: none;
}

.wire-line {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: .88;
}

.collision {
  pointer-events: none;
  fill: rgba(185, 28, 28, .16);
  stroke: var(--danger);
  stroke-width: 2;
}

@media (max-width: 1120px) {
  .planner-shell {
    grid-template-columns: 280px minmax(0, 1fr);
    grid-template-rows: minmax(620px, 1fr) auto;
    height: auto;
  }

  .inspector-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-content: stretch;
  }

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

@media (max-width: 760px) {
  .app-header,
  .brand,
  .header-actions,
  .toolbar {
    align-items: stretch;
  }

  .app-header {
    position: static;
    display: grid;
  }

  .header-actions,
  .toolbar,
  .tool-group {
    justify-content: flex-start;
  }

  .planner-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .library-panel,
  .board-panel,
  .inspector-panel {
    min-height: 420px;
  }

  .inspector-panel {
    grid-template-columns: 1fr;
  }
}
