:root {
  color-scheme: light;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  color: #17263a;
  background: #edf1f5;
  --line: #d5dde6;
  --muted: #4f6074;
  --accent: #00766e;
}
* { box-sizing: border-box; }
body { margin: 0; }
button { font: inherit; }
button:focus-visible { outline: 3px solid #007d75; outline-offset: 3px; }
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px clamp(16px, 3vw, 42px);
  background: #152639;
  color: #fff;
}
.mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #a7efcd;
  color: #153a36;
  font: bold 29px system-ui;
}
h1, h2, p { margin: 0; }
.topbar p { font-size: .8125rem; color: #c6d5e4; }
h1 { font-size: 1.3rem; }
h2 { font-size: 1rem; }
.workbench {
  display: grid;
  grid-template-columns: minmax(210px, 252px) minmax(0, 1fr);
  gap: 16px;
  max-width: 1560px;
  margin: auto;
  padding: 16px;
  align-items: start;
}
.panel, .stage { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.panel { background: #fff; padding: 16px; }
.hint { margin-top: 6px; color: var(--muted); font-size: .875rem; line-height: 1.55; }
.catalog-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px; }
.catalog-header .button { padding: 5px 7px; font-size: .8125rem; }
.catalog-list { display: grid; gap: 8px; margin-top: 14px; }
.catalog-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  min-height: 58px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  background: #fff;
  cursor: pointer;
}
.catalog-item:hover { background: #f3f7fa; }
.catalog-item[aria-pressed="true"] { background: #e8f7f1; border-color: var(--accent); }
.thumb { width: 40px; height: 40px; flex: none; padding: 3px; }
.catalog-item strong, .catalog-item small { display: block; }
.catalog-item strong { font-size: .9375rem; }
.catalog-item small { margin-top: 4px; color: var(--muted); font-size: .8125rem; }
.stage { background: #e0e7ee; }
.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.button {
  background: #fff;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 11px;
  font-size: .875rem;
  cursor: pointer;
}
.button:hover:not(:disabled) { background: #eef4f8; }
.button:disabled { color: #59697c; background: #f1f4f7; cursor: default; }
.button[aria-pressed="true"] { background: #e8f7f1; border-color: var(--accent); color: #005c55; }
.wire-tools {
  display: grid;
  gap: 8px;
  padding: 8px 16px;
  background: #f9fbfd;
  border-bottom: 1px solid var(--line);
}
.wire-tools > .tool-row { flex-wrap: nowrap; white-space: nowrap; overflow-x: auto; }
.tool-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.wire-color { display: flex; align-items: center; gap: 6px; font-size: .875rem; }
.wire-color select {
  font: inherit;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px;
}
.danger:not(:disabled) { color: #a02230; border-color: #e3b3b9; }
.zoom-tools { padding: 8px 16px; background: #f9fbfd; border-bottom: 1px solid var(--line); }
.zoom-step { min-width: 36px; }
#zoom-level { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
.workspace-view { position: relative; }
.workspace-watermark {
  position: absolute;
  inset-inline-end: 26px;
  inset-block-end: 24px;
  color: #46546280;
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: .14em;
  line-height: 1.15;
  text-align: end;
  pointer-events: none;
  user-select: none;
}
.workspace-watermark span {
  display: block;
  margin-top: 3px;
  font-size: .6875rem;
  font-weight: 500;
  letter-spacing: .08em;
}
.board-space {
  overflow: auto;
  overflow-anchor: none;
  height: max(340px, calc(100dvh - 268px));
  padding: 20px 12px;
}
.board-space.pan-ready, .board-space.pan-ready * { cursor: grab; }
.board-space.panning, .board-space.panning * { cursor: grabbing; user-select: none; }
.board-assembly {
  position: relative;
  width: calc(min(100%, clamp(680px, calc((100dvh - 175px) * 2.15), 1450px)) * var(--inspection-growth, 1) * var(--workspace-zoom, 1));
  margin-inline: auto;
}
.board-assembly::before, .board-assembly::after {
  content: '';
  display: block;
  aspect-ratio: var(--inspection-margin-ratio);
}
.board-frame {
  position: relative;
  width: var(--board-share, 100%);
  margin-inline: auto;
}
.board {
  display: block;
  overflow: visible;
  width: 100%;
  height: auto;
  aspect-ratio: 20 / 21;
  background: #efd9b2;
  outline: 1px solid #ab8a60;
  box-shadow: 0 7px 18px #17263a20;
  user-select: none;
}
.board.placing { cursor: crosshair; }
.placement-overlay, .placement-guides { pointer-events: none; }
.ghost-collision { display: none; fill: #e24141; fill-opacity: .64; stroke: #a01929; stroke-width: 2; }
#placement-ghost.collision .ghost-collision { display: block; }
.placement-guides { display: none; }
.board-frame:has(#placement-measure[visibility="visible"]) .placement-guides,
.board-frame:has(#placement-measure[visibility="visible"]) .board-dimensions { display: block; }
.board-dimensions { display: none; position: absolute; z-index: 1; right: 100%; top: 0; width: 13%; height: 100%; pointer-events: none; overflow: visible; }
.board-dimensions path { fill: none; stroke: #66502e; stroke-width: .8; }
.board-dimensions text { fill: #66502e; font-size: 12px; dominant-baseline: middle; }
#terminal-toast {
  position: fixed;
  z-index: 2;
  pointer-events: none;
  max-width: calc(100vw - 16px);
  background: #263748;
  color: white;
  border-radius: 5px;
  padding: 7px 10px;
  font-size: 13px;
}
.placement-guides path {
  fill: none;
  stroke: #66502e;
  stroke-opacity: .55;
  stroke-width: .7;
  stroke-dasharray: 3 3;
}
#placement-measure rect { fill: #263748; fill-opacity: .94; }
#placement-measure text { fill: white; font-size: 9px; font-variant-numeric: tabular-nums; }
.board.placing .device { cursor: grab; }
.board.placing .device:active { cursor: grabbing; }
.board.wiring .device { cursor: default; }
.terminal-target { pointer-events: none; }
.wiring .terminal-target, .magnet-mode .terminal-target { pointer-events: all; cursor: crosshair; }
.terminal-magnet { pointer-events: visiblePainted; }
.clear-confirm { padding: 20px; border: 1px solid #a6b5c2; border-radius: 9px; color: inherit; }
.clear-confirm .tool-row { justify-content: flex-end; margin-top: 14px; }
.wiring .terminal:hover .terminal-target, .terminal.origin .terminal-target {
  stroke: #00e5a9;
  stroke-width: 1.5;
}
.wire-hit { pointer-events: none; }
.wiring .wire-hit { pointer-events: stroke; cursor: pointer; }
.device { cursor: grab; touch-action: none; }
.device:active { cursor: grabbing; }
.device .selection { display: none; pointer-events: none; }
.device.selected .selection, .device:focus-visible .selection { display: block; }
.masking-tape, .masking-text { pointer-events: none; }
.terminal-label-guide {
  fill: #fff8e4; fill-opacity: .25;
  stroke: #806539; stroke-opacity: .58; stroke-width: .8; stroke-dasharray: 2.8 1.8;
  pointer-events: none;
}
.terminal-label-strip:hover .terminal-label-guide { fill-opacity: .47; stroke-opacity: .91; }
.masking-text {
  fill: #26221b;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  font-weight: 650;
}
.device-label-target { cursor: text; touch-action: none; }
.device-label-target:focus-visible { stroke: #00766e; stroke-width: .8; }
.board:is(.wiring, .magnet-mode, .placing) .device-label-target { visibility: hidden; }
.device-label-editor input {
  display: block; width: 100%; height: 100%; padding: 0 2px;
  border: 0; border-radius: 1px; outline: 1px solid #8f784c; outline-offset: -1px;
  color: #26221b; background: #fff0c6; text-align: center; font: 7px system-ui, sans-serif;
}
.board-status {
  padding: 14px 18px;
  background: #fff;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .9375rem;
  line-height: 1.5;
}
#inspection-surface {
  position: absolute; inset: var(--inspection-margin-inset, 0%) 0; width: 100%;
  height: calc(100% - 2 * var(--inspection-margin-inset, 0%));
  pointer-events: none; user-select: none; overflow: visible;
}
.inspection-terminal-target { pointer-events: none; }
.inspection-wiring .inspection-rear .inspection-terminal-target { pointer-events: all; cursor: crosshair; }
.inspection-wiring .inspection-terminal:hover .inspection-terminal-target,
.inspection-terminal.origin .inspection-terminal-target { stroke: #00e5a9; stroke-width: 1.5; }
.inspection-rail { fill: none; stroke: none; }
.inspection-placing .inspection-rail {
  pointer-events: all; touch-action: none; cursor: crosshair;
  fill: #00766e0d; stroke: #548780; stroke-dasharray: 5 4;
}
#inspection-boxes > g { pointer-events: auto; touch-action: none; cursor: grab; }
#inspection-boxes > g:active { cursor: grabbing; }
#inspection-boxes [data-box-action] { cursor: pointer; }
#inspection-boxes [data-box-action]:focus-visible { outline: 2px solid #00766e; outline-offset: 2px; }
#inspection-ghost { pointer-events: none; opacity: .48; }
.inspection-invalid { opacity: .62; filter: sepia(.65) saturate(3); }
.inspection-lid { transition: transform 180ms ease; }
.inspection-open .inspection-lid { transform: translateX(calc(-1 * var(--lid-travel))); }
.inspection-open[data-side="right"] .inspection-lid { transform: translateX(var(--lid-travel)); }
.inspection-rear, .inspection-open .inspection-front { visibility: hidden; opacity: 0; }
.inspection-open .inspection-rear { visibility: visible; opacity: 1; }
.inspection-front, .inspection-rear { transition: opacity 140ms ease; }
.inspection-option-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.inspection-option-row + .inspection-option-row { margin-top: 8px; }
#inspection-options { margin-top: 14px; max-width: 520px; }
.inspection-option { display: grid; justify-items: center; align-content: start; gap: 4px; padding: 7px 4px; }
.inspection-option svg { display: block; width: 34px; height: 34px; }
@media (prefers-reduced-motion: reduce) {
  .inspection-lid, .inspection-front, .inspection-rear { transition: none; }
}
@media (max-width: 960px) {
  .workbench { grid-template-columns: minmax(190px, 225px) minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .workbench { grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 10px; }
  .catalog-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
