:root {
  --bg: #11151c;
  --panel: #171d27;
  --panel-2: #1d2531;
  --line: #2a3442;
  --text: #e6eaf0;
  --muted: #8b97a8;
  --accent: #4fb3ff;
  --accent-2: #ffb547;
  --danger: #ff6b6b;
  --canvas: #1b2230;
  --fg: #e8ecf1;           /* CAD colour 7 (white) inside drawings */
  --radius: 10px;
  --top-h: 56px;
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  height: 56px; padding: 0 16px;
  background: rgba(17, 21, 28, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #2a6fd6); font-weight: 700; color: #fff;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42vw; }
.search { flex: 1; max-width: 560px; margin-left: auto; }
.search input {
  width: 100%; height: 36px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-size: 14px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; white-space: nowrap; cursor: pointer; }
.icon-btn {
  display: inline-grid; place-items: center; min-width: 32px; height: 32px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); cursor: pointer; font-size: 15px;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.on { background: var(--accent); color: #06121f; border-color: var(--accent); }
#navToggle { display: none; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 280px 1fr; height: calc(100% - var(--top-h)); height: calc(100dvh - var(--top-h)); }
.side { overflow: auto; border-right: 1px solid var(--line); background: var(--panel); padding: 10px 8px 40px; }
main { overflow: auto; min-width: 0; }

.side details { margin: 2px 0; }
.side summary {
  list-style: none; cursor: pointer; padding: 7px 10px; border-radius: 8px;
  display: flex; align-items: center; gap: 8px; font-size: 14px;
}
.side summary::-webkit-details-marker { display: none; }
.side summary::before { content: "▸"; color: var(--muted); transition: transform .15s; font-size: 11px; }
.side details[open] > summary::before { transform: rotate(90deg); }
.side summary:hover { background: var(--panel-2); }
.side .cat > summary { font-weight: 700; }
.side .cat > summary .n { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 12px; }
.side .sub { margin-left: 12px; }
.side .sub > summary { font-size: 13px; color: #c8d0db; }
.side .item {
  display: flex; gap: 8px; align-items: baseline; margin-left: 30px; padding: 5px 10px; border-radius: 7px;
  font-size: 13px; color: #c9d2de;
}
.side .item code { color: var(--accent); font-family: Consolas, monospace; font-size: 12px; flex: none; }
.side .item:hover { background: var(--panel-2); }
.side .item.active { background: rgba(79, 179, 255, .15); color: #fff; }
.side .item.crossed { opacity: .5; text-decoration: line-through; }
.side .item.tbl { color: var(--muted); font-style: italic; }

/* ---------- home grid ---------- */
.home { padding: 20px 24px 60px; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; min-width: 130px; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 12px; }
.cat-sec { margin: 26px 0 8px; }
.cat-sec h2 { font-size: 18px; margin: 0 0 4px; display: flex; gap: 10px; align-items: baseline; }
.cat-sec h2 small { color: var(--muted); font-weight: 400; font-size: 13px; }
.sub-h { color: var(--muted); font-size: 13px; margin: 14px 0 8px; border-bottom: 1px dashed var(--line); padding-bottom: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column; transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card .thumb { aspect-ratio: 4/3; background: var(--canvas); position: relative; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .thumb .badge {
  position: absolute; top: 8px; right: 8px; font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: rgba(0, 0, 0, .6); border: 1px solid var(--line);
}
.card .thumb .badge.x { left: 8px; right: auto; color: var(--danger); border-color: var(--danger); }
.card .body { padding: 10px 12px 12px; }
.card .code { color: var(--accent); font-family: Consolas, monospace; font-size: 12px; }
.card .name { font-size: 14px; margin-top: 2px; }
.card.crossed .name { text-decoration: line-through; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chip { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: #c7d0dc; font-family: Consolas, monospace; }
.empty { color: var(--muted); padding: 40px; text-align: center; }
mark { background: rgba(255, 181, 71, .35); color: inherit; border-radius: 3px; }

/* ---------- detail ---------- */
.detail { padding: 14px 18px 40px; display: flex; flex-direction: column; gap: 12px; }
.detail-head .back { color: var(--muted); font-size: 13px; }
.crumbs { color: var(--muted); font-size: 12px; margin-top: 6px; }
.pname { margin: 4px 0 0; font-size: 22px; display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.pname code { color: var(--accent); font-size: 16px; }
.pname .x { color: var(--danger); font-size: 13px; border: 1px solid var(--danger); border-radius: 999px; padding: 1px 8px; }
.panes { display: grid; grid-template-columns: 1.25fr 1fr; gap: 12px; min-height: 560px; }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.pane-bar { display: flex; align-items: center; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); font-size: 13px; }
.pane-bar .spacer { flex: 1; }
.dims3d { color: var(--accent-2); font-family: Consolas, monospace; font-size: 12px; margin-left: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--accent); color: #06121f; }
.svg-stage, .gl-stage { position: relative; flex: 1; min-height: 480px; background: var(--canvas); overflow: hidden; }
.svg-stage { cursor: grab; touch-action: none; -webkit-user-select: none; user-select: none; }
.hint .touch { display: none; }
.scrim { display: none; }
.svg-stage.drag { cursor: grabbing; }
.svg-stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.svg-stage text { user-select: none; }
.gl-stage canvas { display: block; width: 100%; height: 100%; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.hint { font-size: 11px; color: var(--muted); padding: 6px 10px; border-top: 1px solid var(--line); }
.info { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; }
.info .shared { grid-column: 1 / -1; }
.card-block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.card-block h3 { margin: 0 0 8px; font-size: 14px; }
.card-block h3 small { color: var(--muted); font-weight: 400; }
.tfilter { width: 100%; height: 30px; padding: 0 10px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; font-size: 13px; margin-bottom: 8px; }
.texts { margin: 0; padding-left: 0; list-style: none; max-height: 340px; overflow: auto; columns: 2 280px; column-gap: 20px; font-size: 13px; }
.texts li { break-inside: avoid; padding: 3px 0; border-bottom: 1px dotted #263040; color: #cfd6e0; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .panes { grid-template-columns: 1fr; }
  .info { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  :root { --top-h: 104px; }
  .top { height: auto; flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px; }
  .brand { flex: 1; }
  .search { order: 3; flex: 1 0 100%; max-width: none; margin: 0; }
  .search input { height: 40px; font-size: 16px; } /* 16px stops iOS zoom-on-focus */
  .toggle { font-size: 12px; }
  .toggle input { width: 18px; height: 18px; }
  #navToggle { display: inline-grid; min-width: 40px; height: 40px; }
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; top: var(--top-h); bottom: 0; left: 0; width: min(86vw, 320px); z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .side summary { padding: 10px 10px; }
  .side .item { padding: 9px 10px; margin-left: 20px; }
  body.nav-open .side { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .6); }
  body.nav-open .scrim { display: block; position: fixed; inset: var(--top-h) 0 0 0; background: rgba(0, 0, 0, .5); z-index: 25; }
  .brand-text small { display: none; }
  .brand-text b { font-size: 14px; }
  .home { padding: 12px 12px 40px; }
  .stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 8px; }
  .stat { min-width: 0; padding: 8px 4px; text-align: center; }
  .stat b { font-size: 18px; }
  .stat span { font-size: 11px; }
  .cat-sec { margin-top: 18px; }
  .cat-sec h2 { font-size: 16px; flex-wrap: wrap; gap: 4px 8px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card .body { padding: 8px 9px 10px; }
  .card .name { font-size: 13px; line-height: 1.35; }
  .card .chips .chip:nth-child(n+3) { display: none; }
  .detail { padding: 10px 10px 30px; gap: 10px; }
  .pname { font-size: 19px; gap: 8px; }
  .pane-bar { flex-wrap: wrap; gap: 5px; padding: 6px; }
  .seg button { padding: 7px 10px; white-space: nowrap; }
  .icon-btn { min-width: 36px; height: 36px; }
  .dims3d { flex-basis: 100%; order: 5; margin: 0; }
  .svg-stage { min-height: 0; height: 62vh; flex: none; }
  .gl-stage { min-height: 0; height: 58vh; flex: none; }
  .panes { min-height: 0; }
  .hint .mouse { display: none; }
  .hint .touch { display: inline; }
  .texts { columns: 1; max-height: 50vh; }
}
@media (max-width: 380px) {
  .stat span { font-size: 10px; }
  .grid { gap: 8px; }
}
