:root {
  color-scheme: light;
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-soft: #f6f8f8;
  --surface-raised: #ffffff;
  --ink: #172126;
  --muted: #657279;
  --line: #d8e0e3;
  --accent: #0f766e;
  --accent-strong: #0b5f58;
  --danger: #b42318;
  --wire: #1f2937;
  --grid-major: #d7e1e4;
  --grid-minor: #edf2f3;
  --selected: #eab308;
  --part-fill: #ffffff;
  --part-stroke: #25323a;
  --pin-fill: #ffffff;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body.dark {
  color-scheme: dark;
  --bg: #101619;
  --surface: #151e22;
  --surface-soft: #1c282d;
  --surface-raised: #202d33;
  --ink: #edf4f5;
  --muted: #9fb0b6;
  --line: #304148;
  --accent: #2dd4bf;
  --accent-strong: #14b8a6;
  --danger: #fb7185;
  --wire: #d8e7ea;
  --grid-major: #293940;
  --grid-minor: #1d2a2f;
  --selected: #facc15;
  --part-fill: #18242a;
  --part-stroke: #d5e4e7;
  --pin-fill: #111a1e;
}

* {
  box-sizing: border-box;
}

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

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

button,
input {
  font: inherit;
}

button,
.import-btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 0 12px;
}

button:hover:not(:disabled),
.import-btn:hover {
  border-color: var(--accent);
  background: var(--surface-raised);
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 180ms ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.sidebar {
  display: flex;
  overflow: hidden;
  flex-direction: column;
  gap: 16px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  min-width: 0;
  padding: 18px;
}

.app-shell.sidebar-collapsed .sidebar {
  padding-right: 0;
  padding-left: 0;
  border-right: 0;
}

.brand {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-width: 284px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 2px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: 24px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

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

.panel {
  display: flex;
  min-width: 284px;
  flex-direction: column;
  gap: 10px;
}

.library-panel {
  min-height: 0;
  flex: 1;
}

.properties-panel {
  flex: 0 0 auto;
}

.panel-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.palette {
  display: grid;
  gap: 9px;
  overflow: auto;
  padding-right: 4px;
}

.palette-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 8px;
  text-align: left;
}

.palette-visual {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 34%, var(--line));
  border-radius: 8px;
  background: var(--surface);
}

.palette-visual svg {
  width: 48px;
  height: 48px;
}

.palette-name,
.palette-value {
  overflow-wrap: anywhere;
}

.palette-name {
  display: block;
  font-size: 14px;
  font-weight: 750;
}

.palette-value {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.field {
  display: grid;
  gap: 5px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-raised);
  color: var(--ink);
  padding: 0 10px;
}

.property-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 34px;
  min-width: 0;
  min-height: 100vh;
}

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

.toolbar-left,
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.icon-btn {
  width: 38px;
  padding: 0;
  font-size: 18px;
}

.mode-group {
  display: inline-flex;
  overflow: hidden;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.mode-btn {
  border: 0;
  border-radius: 0;
  background: var(--surface);
  min-width: 82px;
}

.mode-btn + .mode-btn {
  border-left: 1px solid var(--line);
}

.mode-btn.active {
  background: var(--accent);
  color: #06211e;
  font-weight: 750;
}

.zoom-label {
  min-width: 46px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.import-btn {
  display: inline-grid;
  place-items: center;
}

.import-btn input {
  display: none;
}

.canvas-wrap {
  position: relative;
  overflow: auto;
  touch-action: none;
  background:
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid-minor) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-minor) 1px, transparent 1px);
  background-color: var(--bg);
  background-size: 80px 80px, 80px 80px, 20px 20px, 20px 20px;
}

.schematic-canvas {
  display: block;
  width: 2200px;
  height: 1500px;
  transform-origin: 0 0;
}

.wire-path {
  fill: none;
  stroke: var(--wire);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wire-path.selected {
  stroke: var(--selected);
  stroke-width: 4;
}

.wire-preview {
  fill: none;
  stroke: var(--accent);
  stroke-dasharray: 7 6;
  stroke-width: 3;
}

.component {
  cursor: move;
}

.component text {
  user-select: none;
}

.component-shell {
  fill: var(--part-fill);
  stroke: var(--part-stroke);
  stroke-width: 2;
  filter: drop-shadow(0 8px 14px rgb(15 23 42 / 0.12));
}

.component-board {
  fill: #0f766e;
  stroke: #064e48;
}

body.dark .component-board {
  fill: #115e59;
  stroke: #5eead4;
}

.component.selected .component-shell {
  stroke: var(--selected);
  stroke-width: 3;
}

.pin {
  fill: var(--pin-fill);
  stroke: var(--part-stroke);
  stroke-width: 2;
  cursor: crosshair;
}

.pin:hover,
.pin.active {
  fill: #ccfbf1;
  stroke: var(--accent);
  stroke-width: 3;
}

.component-symbol {
  fill: none;
  stroke: var(--part-stroke);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.component-chip {
  fill: color-mix(in srgb, var(--part-stroke) 10%, var(--part-fill));
  stroke: var(--part-stroke);
  stroke-width: 2;
}

.component-led-fill {
  fill: #ef4444;
  stroke: #7f1d1d;
}

.component-label {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 800;
  text-anchor: middle;
}

.component-value {
  fill: var(--muted);
  font-size: 12px;
  text-anchor: middle;
}

.pin-label {
  fill: var(--muted);
  font-size: 10px;
}

.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  padding: 0 14px;
}

@media (max-width: 900px) {
  .app-shell,
  .app-shell.sidebar-collapsed {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    z-index: 5;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(88vw, 330px);
    border-right: 1px solid var(--line);
    box-shadow: 0 16px 48px rgb(15 23 42 / 0.24);
    transform: translateX(0);
    transition: transform 180ms ease;
  }

  .app-shell.sidebar-collapsed .sidebar {
    padding: 18px;
    border-right: 1px solid var(--line);
    transform: translateX(-105%);
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-left {
    justify-content: space-between;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    justify-content: stretch;
  }

  .toolbar-actions button,
  .toolbar-actions .import-btn {
    min-width: 0;
    padding-right: 8px;
    padding-left: 8px;
    font-size: 13px;
  }

  #themeToggle,
  #exportBtn,
  .import-btn,
  #clearBtn {
    grid-column: span 2;
  }

  .statusbar {
    align-items: flex-start;
    flex-direction: column;
    height: auto;
    min-height: 42px;
    justify-content: center;
    padding: 6px 12px;
  }
}

@media (max-width: 520px) {
  .mode-btn {
    min-width: 72px;
    padding: 0 8px;
  }

  .toolbar-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #themeToggle,
  #exportBtn,
  .import-btn,
  #clearBtn {
    grid-column: span 3;
  }
}
