/* LJZ-STAMP v1.1 | © 2026 李俊泽 Li Junze · 清华大学 水木书院 · LJZ-20261024-26d7e9 */
/* 本文件由 李俊泽 创作，含指纹 LJZ-20261024-26d7e9；转载/复用请署名 */

/* ============================================================
 * 电路工作台 · 样式（浅色主题）
 * ============================================================ */
:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --line: #e3e8ef;
  --line-strong: #cbd5e1;
  --text: #0f172a;
  --text-dim: #64748b;
  --text-mute: #94a3b8;
  --brand: #2563eb;
  --brand-soft: #eff6ff;
  --ok: #059669;
  --warn: #d97706;
  --err: #dc2626;
  --grid-line: #eef2f7;
  --grid-major: #e2e8f0;

  --sym-line: #1f2937;
  --sym-fill: #ffffff;
  --lbl-name: #0f172a;
  --lbl-val: #64748b;

  --wire: #2563eb;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- 布局 ---------- */
#app { display: grid; grid-template-rows: 52px 1fr; height: 100vh; }

header {
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; letter-spacing: .2px; }
.logo .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
header .spacer { flex: 1; }
#docTitle {
  border: 1px solid transparent; background: transparent;
  padding: 5px 9px; border-radius: 7px; font-weight: 600; font-size: 13px;
  min-width: 140px; max-width: 260px;
}
#docTitle:hover { border-color: var(--line); }
#docTitle:focus { outline: none; border-color: var(--brand); background: #fff; }

main { display: grid; grid-template-columns: 196px 1fr 372px; min-height: 0; }

/* ---------- 左：元件库 ---------- */
#palette {
  background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 10px 8px 40px;
}
.sec-title {
  font-size: 11px; font-weight: 700; color: var(--text-mute);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 8px 6px 6px;
}
.pal-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: 8px; border: 1px solid transparent;
  cursor: grab; user-select: none; transition: .12s;
}
.pal-item:hover { background: var(--brand-soft); border-color: #dbeafe; }
.pal-item:active { cursor: grabbing; }
.pal-item .ico { width: 38px; height: 26px; flex: 0 0 auto; display: grid; place-items: center; }
.pal-item .ico svg { width: 100%; height: 100%; overflow: visible; }
.pal-item .nm { font-size: 12.5px; font-weight: 600; }

/* ---------- 中：画布 ---------- */
#canvasWrap { position: relative; overflow: hidden; background: var(--bg); }
#canvas { width: 100%; height: 100%; display: block; cursor: default; touch-action: none; }
#canvas .grid-bg { pointer-events: none; }

#canvas .comp { cursor: move; }
#canvas .comp .comp-hit { fill: transparent; }
#canvas .comp.selected { filter: drop-shadow(0 0 0 rgba(0,0,0,0)); }
#canvas .selbox { stroke: var(--brand); stroke-width: 1.6; stroke-dasharray: 5 4; }
#canvas .pin { cursor: crosshair; transition: .1s; }
#canvas .pin:hover, #canvas .pin.hover {
  fill: rgba(37, 99, 235, .28) !important; stroke: var(--brand); stroke-width: 1.6;
}
#canvas .pin.active { fill: rgba(37, 99, 235, .5) !important; stroke: var(--brand); }
#canvas .wire-hit { cursor: pointer; }
#canvas .wire:hover .wire-line { stroke: #dc2626; }
#canvas .wire-line { stroke: var(--wire); transition: stroke .1s; }
#canvas .wire-dot { fill: var(--wire); }
#canvas .junction { fill: var(--wire); }
#canvas .ghost-wire { stroke: var(--brand); opacity: .7; }
#canvas .ghost-pulse { fill: none; stroke: var(--brand); stroke-width: 2; opacity: .8; animation: pulse 1s infinite; }
@keyframes pulse { 0% { r: 6; opacity: .9 } 100% { r: 14; opacity: 0 } }

/* 悬浮工具条 */
#floatbar {
  position: absolute; left: 12px; top: 12px;
  display: flex; gap: 4px; align-items: center;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; padding: 4px; box-shadow: var(--shadow);
  z-index: 10;
}
.tbtn {
  display: flex; align-items: center; gap: 5px;
  border: 1px solid transparent; background: transparent;
  padding: 6px 9px; border-radius: 6px; font-size: 12px; font-weight: 600;
  color: var(--text-dim); transition: .12s; white-space: nowrap;
}
.tbtn:hover { background: #f1f5f9; color: var(--text); }
.tbtn.on { background: var(--brand); color: #fff; }
.tbtn svg { width: 14px; height: 14px; }
.divider { width: 1px; height: 20px; background: var(--line); margin: 0 3px; }

#hint {
  position: absolute; left: 12px; bottom: 12px;
  background: rgba(255,255,255,.92); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 11px; font-size: 11.5px; color: var(--text-dim);
  backdrop-filter: blur(6px); max-width: 520px; line-height: 1.55;
}
#hint kbd {
  background: #f1f5f9; border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 4px; font-family: ui-monospace, monospace;
  font-size: 10.5px; color: var(--text);
}
#zoomBadge {
  position: absolute; right: 12px; bottom: 12px;
  background: rgba(255,255,255,.92); border: 1px solid var(--line);
  border-radius: 7px; padding: 4px 9px; font-size: 11px; color: var(--text-dim);
  font-family: ui-monospace, monospace;
}

/* 属性浮窗（画布内选中元件时） */
#props {
  position: absolute; right: 12px; top: 12px;
  width: 208px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px; box-shadow: var(--shadow); z-index: 12;
  display: none;
}
#props.show { display: block; }
#props .row { display: flex; align-items: center; gap: 7px; margin-bottom: 7px; }
#props label { font-size: 11px; color: var(--text-mute); width: 34px; flex: 0 0 auto; }
#props input { flex: 1; border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; min-width: 0; }
#props input:focus { outline: none; border-color: var(--brand); }

/* ---------- 右：结果面板 ---------- */
#side {
  background: var(--panel); border-left: 1px solid var(--line);
  display: grid; grid-template-rows: 40px 1fr; min-height: 0;
}
#tabs { display: flex; gap: 2px; padding: 6px 8px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  border: none; background: transparent; padding: 6px 10px; border-radius: 6px;
  font-size: 12px; font-weight: 600; color: var(--text-dim); white-space: nowrap;
}
.tab:hover { background: #f1f5f9; }
.tab.on { background: var(--brand-soft); color: var(--brand); }

#panes { overflow-y: auto; padding: 12px; }
.pane { display: none; }
.pane.on { display: block; }

.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 6px 10px; border-radius: 7px; font-size: 12px; font-weight: 600;
  transition: .12s;
}
.btn:hover { border-color: var(--line-strong); background: #f8fafc; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-dim); }
.btn.ghost:hover { background: #f1f5f9; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

pre.code {
  margin: 0; padding: 10px 11px; background: #0f172a; color: #e2e8f0;
  border-radius: 8px; font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 11.5px; line-height: 1.6; overflow: auto; max-height: 340px;
  white-space: pre; tab-size: 2;
}
.md-body { font-size: 12.5px; line-height: 1.72; color: var(--text); word-break: break-word; }
.md-body h1 { font-size: 16px; margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.md-body h2 { font-size: 13px; margin: 14px 0 7px; color: var(--brand); }
.md-body p { margin: 6px 0; }
.md-body ul { margin: 6px 0; padding-left: 18px; }
.md-body li { margin: 3px 0; }
.md-body table { border-collapse: collapse; width: 100%; font-size: 11.5px; margin: 8px 0; }
.md-body th, .md-body td { border: 1px solid var(--line); padding: 4px 7px; text-align: left; }
.md-body th { background: #f8fafc; font-weight: 700; }
.md-body code { background: #f1f5f9; padding: 1px 4px; border-radius: 3px; font-size: 11px; font-family: ui-monospace, monospace; }
.md-body strong { color: var(--text); }

.chk-item {
  display: flex; gap: 7px; align-items: flex-start;
  padding: 7px 9px; border-radius: 7px; margin-bottom: 5px; font-size: 12px; line-height: 1.5;
}
.chk-item.err { background: #fef2f2; color: #991b1b; }
.chk-item.warn { background: #fffbeb; color: #92400e; }
.chk-item.ok { background: #ecfdf5; color: #065f46; }
.chk-item .badge { font-weight: 700; flex: 0 0 auto; }

.net-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 6px 8px; border-bottom: 1px dashed var(--line); font-size: 12px;
}
.net-row:last-child { border-bottom: none; }
.net-name {
  font-family: ui-monospace, monospace; font-weight: 700; color: var(--brand);
  flex: 0 0 auto; min-width: 52px;
}
.net-pins { color: var(--text-dim); font-family: ui-monospace, monospace; font-size: 11.5px; }

.stat { display: flex; gap: 14px; padding: 8px 10px; background: #f8fafc; border-radius: 8px; margin-bottom: 10px; }
.stat div { font-size: 11px; color: var(--text-mute); }
.stat b { display: block; font-size: 16px; color: var(--text); font-family: ui-monospace, monospace; }

#previewBox {
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
  padding: 8px; margin-bottom: 10px; overflow: hidden;
}
#previewBox img { width: 100%; height: auto; display: block; }

table.comp-tbl { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.comp-tbl th, table.comp-tbl td { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; }
table.comp-tbl th { color: var(--text-mute); font-weight: 600; font-size: 10.5px; text-transform: uppercase; }
table.comp-tbl tr:hover td { background: #f8fafc; cursor: pointer; }
table.comp-tbl input {
  width: 100%; border: 1px solid transparent; background: transparent;
  padding: 2px 4px; border-radius: 4px; font-family: ui-monospace, monospace; font-size: 11.5px;
}
table.comp-tbl input:hover { border-color: var(--line); }
table.comp-tbl input:focus { outline: none; border-color: var(--brand); background: #fff; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: #0f172a; color: #fff; padding: 9px 16px; border-radius: 8px;
  font-size: 12.5px; opacity: 0; pointer-events: none; transition: .22s; z-index: 999;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 窄屏 */
@media (max-width: 1100px) {
  main { grid-template-columns: 150px 1fr 300px; }
}
@media (max-width: 860px) {
  main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #palette { display: none; }
  #side { border-left: none; border-top: 1px solid var(--line); max-height: 42vh; }
}