:root {
  --bg: #0a0f14;
  --bg2: #0f1720;
  --line: #1e2a37;
  --line2: #2a3a4b;
  --text: #dbe7f3;
  --dim: #7d8fa3;
  --acc: #2ee6a6;
  --acc-ink: #04130d;
  --panel: #0d141c;
  --font: -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font-family: var(--font); overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
a { color: var(--acc); }

/* ---------- 顶栏 ---------- */
.topbar {
  flex: none; min-height: 64px;
  display: flex; align-items: center; gap: 18px; padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #101a25, #0b1118);
  position: relative; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 210px; }
.logo {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  color: var(--acc); background: #0f2a22; border: 1px solid #1d4c3c;
  box-shadow: 0 0 18px rgba(46, 230, 166, .18);
}
.brand h1 { font-size: 18px; margin: 0; letter-spacing: 2px; }
.brand small { color: var(--dim); font-size: 11px; }
.atlas-nav { display: flex; gap: 5px; margin-left: 6px; }
.atlas-switch {
  padding: 5px 9px; border-radius: 8px; font-size: 12px;
  text-decoration: none; color: var(--acc); background: rgba(46, 230, 166, .08);
  border: 1px solid rgba(46, 230, 166, .3); white-space: nowrap; transition: .2s;
}
.atlas-switch:hover { background: var(--acc); color: var(--acc-ink); font-weight: 600; }
body.comp-theme { --acc: #38bdf8; --acc-ink: #04131d; }
body.comp-theme .logo { background: #0d2233; border-color: #1c4c6e; box-shadow: 0 0 18px rgba(56, 189, 248, .2); }
body.comp-theme .atlas-switch { background: rgba(56, 189, 248, .1); border-color: rgba(56, 189, 248, .35); }
body.comp-theme .node.sel rect { fill: #0e2c3e; }
body.pcb-theme { --acc: #fbbf24; --acc-ink: #1a1203; }
body.pcb-theme .logo { background: #2b2108; border-color: #6b4f12; box-shadow: 0 0 18px rgba(251, 191, 36, .2); }
body.pcb-theme .atlas-switch { background: rgba(251, 191, 36, .1); border-color: rgba(251, 191, 36, .35); }
body.pcb-theme .node.sel rect { fill: #332508; }

.search-wrap { position: relative; flex: 1; max-width: 560px; }
#search {
  width: 100%; height: 38px; border-radius: 10px;
  border: 1px solid var(--line2); background: #0a1219 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237d8fa3' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l4 4'/%3E%3C/svg%3E") no-repeat 12px center;
  color: var(--text); padding: 0 14px 0 36px; font-size: 14px; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
#search:focus { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(46, 230, 166, .12); }
.results {
  position: absolute; top: 44px; left: 0; right: 0; display: none;
  background: #0f1822; border: 1px solid var(--line2); border-radius: 12px;
  max-height: 62vh; overflow: auto; box-shadow: 0 16px 48px rgba(0, 0, 0, .55);
}
.results.show { display: block; }
.r-item { padding: 9px 14px; cursor: pointer; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid #15202b; }
.r-item:last-child { border-bottom: none; }
.r-item:hover, .r-item.active { background: #15232f; }
.r-item .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.r-item .r-main { flex: 1; min-width: 0; }
.r-item b { font-weight: 600; font-size: 14px; }
.r-item small { display: block; color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-item .yr { color: var(--dim); font-size: 12px; }
.r-empty { padding: 14px; color: var(--dim); font-size: 13px; }

.modes { display: flex; gap: 3px; background: #0a1219; border: 1px solid var(--line2); border-radius: 10px; padding: 3px; flex: none; }
.modes button {
  border: none; background: transparent; color: var(--dim); padding: 7px 12px;
  border-radius: 7px; cursor: pointer; font-size: 13px; white-space: nowrap; transition: .2s;
}
.modes button:hover { color: var(--text); background: #142130; }
.modes button.active { background: var(--acc); color: var(--acc-ink); font-weight: 600; }

/* ---------- 主区域 ---------- */
main { flex: 1; min-height: 0; display: flex; }
#stage {
  flex: 1; position: relative; overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(circle, #18232f 1px, transparent 1.2px);
  background-size: 22px 22px;
}
#tree { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
#tree.dragging { cursor: grabbing; }

.node { cursor: pointer; }
.node rect { fill: #111b25; stroke: var(--line2); stroke-width: 1; transition: fill .2s, stroke .2s; }
.node:hover rect { stroke: var(--acc); fill: #142330; }
.node text { fill: var(--text); font-size: 13px; font-family: var(--font); pointer-events: none; }
.node.group .lbl { font-weight: 600; }
.node .yr, .node .cnt { fill: var(--dim); font-size: 11px; }
.node .star { fill: #ffd54f; font-size: 11px; }
.node .tg { fill: var(--acc); font-size: 15px; font-weight: 700; text-anchor: middle; }
.node.group rect { fill: #122030; }
.node.open rect { stroke: #3d5a70; }
.node.root rect { fill: var(--acc); stroke: none; }
.node.root text, .node.root .cnt, .node.root .tg { fill: var(--acc-ink); font-weight: 700; }
.node.sel rect { stroke: var(--acc); stroke-width: 2; fill: #0f3427; }
.node.flash rect { animation: flash 1.2s ease 2; }
@keyframes flash { 50% { stroke: #ffd54f; stroke-width: 3; } }
.link { fill: none; stroke: #2a3b4d; stroke-width: 1.4; }

.toolbar { position: absolute; left: 14px; top: 14px; display: flex; gap: 6px; flex-wrap: wrap; right: 14px; pointer-events: none; }
.toolbar > * { pointer-events: auto; }
.toolbar button, .chk {
  background: rgba(15, 24, 34, .85); border: 1px solid var(--line2); color: var(--text);
  height: 32px; padding: 0 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px; backdrop-filter: blur(6px); transition: .2s;
}
.toolbar button:hover, .chk:hover { border-color: var(--acc); }
.chk input { accent-color: var(--acc); margin: 0; }

.legend {
  position: absolute; left: 14px; bottom: 14px; display: flex; flex-wrap: wrap; gap: 6px 14px;
  background: rgba(15, 24, 34, .85); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  font-size: 12px; color: var(--dim); max-width: calc(100% - 28px); backdrop-filter: blur(6px);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.stats { position: absolute; right: 14px; top: 58px; color: var(--dim); font-size: 12px; text-align: right; }
.hint { position: absolute; right: 14px; bottom: 16px; color: #4e6072; font-size: 12px; }

/* ---------- 详情面板 ---------- */
#panel {
  width: 430px; flex: none; border-left: 1px solid var(--line); background: var(--panel);
  overflow-y: auto; padding: 24px 26px 48px; position: relative;
}
#panel::-webkit-scrollbar, .results::-webkit-scrollbar { width: 8px; }
#panel::-webkit-scrollbar-thumb, .results::-webkit-scrollbar-thumb { background: #223142; border-radius: 4px; }
.close-panel { display: none; position: absolute; right: 14px; top: 10px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line2); background: #121c26; color: var(--text); font-size: 20px; cursor: pointer; }

.kicker { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 3px 9px; border-radius: 20px; background: #15212d; border: 1px solid var(--line2); color: var(--dim); }
.chip.hot { color: #ffd54f; border-color: #5a4a17; background: #241e0b; }
.chip i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
#panel h2 { font-size: 23px; margin: 4px 0 4px; line-height: 1.3; word-break: break-word; }
.sub { color: var(--dim); font-size: 13px; margin-bottom: 18px; }
.kv { display: grid; grid-template-columns: 78px 1fr; gap: 8px 12px; font-size: 13px; background: #101a24; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 18px; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; color: var(--text); word-break: break-word; }
.desc { font-size: 14px; line-height: 1.85; color: #c7d4e0; margin: 0 0 18px; }
#panel h3 { font-size: 13px; color: var(--acc); letter-spacing: 1px; margin: 22px 0 10px; text-transform: uppercase; }
.pros { list-style: none; padding: 0; margin: 0; }
.pros li { position: relative; padding: 6px 0 6px 24px; font-size: 14px; line-height: 1.6; color: #c7d4e0; }
.pros li::before { content: ""; position: absolute; left: 4px; top: 13px; width: 8px; height: 8px; border-radius: 2px; background: var(--acc); transform: rotate(45deg); }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.btns a { text-decoration: none; font-size: 13px; padding: 8px 13px; border-radius: 9px; border: 1px solid var(--line2); color: var(--text); background: #121c26; transition: .2s; }
.btns a:hover { border-color: var(--acc); color: var(--acc); }
.btns a.primary { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); font-weight: 600; }
.btns a.primary:hover { filter: brightness(1.1); color: var(--acc-ink); }
.rel { display: flex; flex-wrap: wrap; gap: 6px; }
.rel button, .list button {
  font-size: 12.5px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line2);
  background: #111b25; color: var(--text); cursor: pointer; transition: .2s; text-align: left;
}
.rel button:hover, .list button:hover { border-color: var(--acc); }
.list { display: flex; flex-direction: column; gap: 6px; }
.list button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 12px; font-size: 13px; }
.list button i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.list button span { flex: 1; }
.list button em { color: var(--dim); font-style: normal; font-size: 12px; }
.welcome p { color: #c7d4e0; line-height: 1.85; font-size: 14px; }
.welcome .big { font-size: 34px; font-weight: 800; color: var(--acc); line-height: 1; }
.numbers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.numbers div { background: #101a24; border: 1px solid var(--line); border-radius: 12px; padding: 14px 12px; }
.numbers small { color: var(--dim); font-size: 12px; }
.note { font-size: 12px; color: var(--dim); line-height: 1.7; border-top: 1px dashed var(--line2); margin-top: 24px; padding-top: 14px; }

/* ---------- 元器件图文卡片 ---------- */
.visual-card {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 16px;
}
.visual-box {
  background: linear-gradient(180deg, #0f1b27, #0b131c);
  border: 1px solid var(--line2); border-radius: 12px; padding: 10px 10px 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  min-height: 124px; position: relative; overflow: hidden;
}
.visual-box svg { width: 100%; height: 84px; display: block; }
.visual-box span { font-size: 11px; color: var(--dim); margin-top: 4px; letter-spacing: .5px; }
.pitfalls { list-style: none; padding: 0; margin: 0; }
.pitfalls li { position: relative; padding: 5px 0 5px 22px; font-size: 13.5px; line-height: 1.6; color: #e2c9a6; }
.pitfalls li::before { content: "!"; position: absolute; left: 3px; top: 7px; width: 14px; height: 14px; line-height: 14px; text-align: center; border-radius: 50%; background: #3b2a12; color: #ffb74d; font-size: 10px; font-weight: 700; border: 1px solid #6b4c1d; }

/* ---------- PCB 原理图与布局卡片 ---------- */
.pcb-stack { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 16px; }
.pcb-box {
  background: linear-gradient(180deg, #0f1b27, #0b131c);
  border: 1px solid var(--line2); border-radius: 12px; padding: 10px 12px 8px;
}
.pcb-box.board-view { background: linear-gradient(180deg, #0d2219, #091712); border-color: #1e4d38; }
.pcb-box svg { width: 100%; height: auto; display: block; }
.pcb-box .cap { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--dim); margin-top: 6px; }
.formula-box {
  background: #131c26; border-left: 3px solid var(--acc); border-radius: 0 8px 8px 0;
  padding: 10px 14px; margin: 12px 0 16px; font-family: ui-monospace, Consolas, monospace;
  font-size: 13px; color: #fde68a; line-height: 1.7;
}
.bom-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.bom-tag {
  font-size: 12px; padding: 4px 9px; border-radius: 7px;
  background: #131e2a; border: 1px solid var(--line2); color: #cbd5e1;
}

/* ---------- 实物图卡片与点击放大灯箱 ---------- */
.photo-card {
  margin: 12px 0 16px; border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line2); background: #0b131c; cursor: zoom-in;
}
.photo-card img {
  width: 100%; max-height: 220px; object-fit: contain; display: block;
  background: #080e15;
}
.photo-card .cap {
  display: flex; justify-content: space-between; padding: 6px 12px;
  font-size: 11px; color: var(--dim); border-top: 1px solid var(--line);
}
.lightbox {
  position: fixed; inset: 0; z-index: 99; background: rgba(4, 8, 13, .88);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  cursor: zoom-out; backdrop-filter: blur(4px);
}
.lightbox img {
  max-width: 92vw; max-height: 90vh; border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .7); border: 1px solid var(--line2);
}

/* ---------- 移动端 ---------- */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 12px; }
  .brand { min-width: 0; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
  .modes { order: 4; flex-basis: 100%; overflow-x: auto; }
  .hint, .stats { display: none; }
  .legend { display: none; }
  #panel {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; height: 62vh; z-index: 30;
    border-left: none; border-top: 1px solid var(--line2); border-radius: 18px 18px 0 0;
    transform: translateY(105%); transition: transform .3s ease; box-shadow: 0 -12px 40px rgba(0, 0, 0, .6);
  }
  #panel.open { transform: none; }
  .close-panel { display: block; }
}
