:root {
  --bg: #0c1017;
  --bg-2: #121826;
  --panel: rgba(14, 20, 30, 0.88);
  --panel-border: rgba(214, 196, 158, 0.14);
  --text: #ece6da;
  --muted: #9aa3b0;
  --faint: #6d7684;
  --gold: #e8b84a;
  --gold-dim: #b8892c;
  --bone: #e4d5bc;
  --muscle: #c45c5c;
  --joint: #4ec4c8;
  --landmark: #f0c35a;
  --theory: #8fa4d4;
  --accent: #d6c49e;
  --danger: #d37a6a;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font: "Noto Sans CJK SC", "Source Han Sans SC", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", "WenQuanYi Micro Hei", sans-serif;
  --mono: "Noto Sans Mono CJK SC", "SFMono-Regular", Menlo, Consolas, monospace;
  --left: 332px;
  --right: 356px;
  --top: 64px;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
button, input { font-family: inherit; }
button { cursor: pointer; }
#app {
  height: 100%;
  display: grid;
  grid-template-columns: var(--left) 1fr var(--right);
  grid-template-rows: var(--top) 1fr;
  grid-template-areas:
    "top top top"
    "left view right";
}
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  background: linear-gradient(180deg, rgba(18, 24, 34, 0.96), rgba(12, 16, 23, 0.9));
  border-bottom: 1px solid var(--panel-border);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background:
    radial-gradient(circle at 50% 30%, #f0c35a 0 3px, transparent 4px),
    linear-gradient(180deg, #efe0c4, #c4ae86);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2);
}
.brand h1 { font-size: 16px; margin: 0; letter-spacing: 0.06em; font-weight: 700; }
.brand p { margin: 2px 0 0; font-size: 11px; color: var(--muted); }
.layers { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--panel-border);
  font-size: 12px; color: var(--text);
  user-select: none;
}
.chip input { accent-color: var(--gold); }
.slider-chip input[type=range] { width: 80px; }
.top-actions { display: flex; gap: 8px; }
.ghost {
  background: transparent; color: var(--accent);
  border: 1px solid var(--panel-border);
  border-radius: 8px; padding: 6px 12px; font-size: 12px;
}
.ghost:hover { background: rgba(214, 196, 158, 0.08); }
.side {
  background: var(--panel);
  border-color: var(--panel-border);
  backdrop-filter: blur(16px);
  display: flex; flex-direction: column;
  min-height: 0;
}
.left { grid-area: left; border-right: 1px solid var(--panel-border); }
.right { grid-area: right; border-left: 1px solid var(--panel-border); }
.search-box { padding: 12px 12px 8px; }
.search-box input {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: #0b0f16; color: var(--text); font-size: 13px;
  outline: none;
}
.search-box input:focus { border-color: var(--gold-dim); }
.filters { padding: 0 12px 8px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
.filter-btn {
  border: 1px solid var(--panel-border); background: transparent;
  color: var(--muted); border-radius: 999px; padding: 3px 9px; font-size: 11px;
}
.filter-btn.active { color: #1a1408; background: var(--gold); border-color: var(--gold); font-weight: 650; }
.exam-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--gold); }
.exam-toggle input { accent-color: var(--gold); }
.list-meta { padding: 0 14px 6px; font-size: 11px; color: var(--faint); }
.list { flex: 1; overflow: auto; padding: 0 8px 16px; }
.group-label {
  position: sticky; top: 0;
  background: rgba(12, 16, 23, 0.94);
  color: var(--muted); font-size: 11px; letter-spacing: 0.08em;
  padding: 8px 8px 4px; text-transform: none;
}
.row {
  display: grid;
  grid-template-columns: 14px 14px 1fr;
  gap: 8px; align-items: center;
  padding: 7px 8px; border-radius: 8px;
  cursor: pointer; font-size: 13px;
}
.row:hover, .row.active { background: rgba(232, 184, 74, 0.12); }
.row .pip { width: 8px; height: 8px; border-radius: 50%; justify-self: center; }
.row .star { color: var(--gold); font-size: 11px; text-align: center; }
.row .star.empty { color: transparent; }
.row .names small { display: block; color: var(--faint); font-size: 10px; font-style: italic; }
.viewport { grid-area: view; position: relative; overflow: hidden; background: radial-gradient(ellipse at 50% 30%, #1a2333 0%, #0c1017 70%); }
#canvas { width: 100%; height: 100%; display: block; }
.hover-label {
  position: absolute; pointer-events: none;
  background: rgba(10, 14, 20, 0.86);
  border: 1px solid var(--panel-border);
  color: var(--text); font-size: 12px;
  padding: 4px 8px; border-radius: 6px;
  transform: translate(12px, 8px); white-space: nowrap;
  z-index: 3;
}
.hover-label .tag { color: var(--gold); margin-left: 6px; font-size: 10px; }
.view-presets {
  position: absolute; left: 50%; bottom: 36px; transform: translateX(-50%);
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
  max-width: 90%; z-index: 3;
}
.view-presets button {
  background: rgba(12, 16, 23, 0.72);
  border: 1px solid var(--panel-border);
  color: var(--text); border-radius: 999px;
  padding: 5px 11px; font-size: 12px;
}
.view-presets button:hover { border-color: var(--gold-dim); color: var(--gold); }
.hint {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  font-size: 11px; color: var(--faint); white-space: nowrap; z-index: 2;
}
.detail { height: 100%; overflow: auto; padding: 18px 18px 28px; }
.detail .empty h2 { font-size: 18px; margin: 8px 0 10px; }
.detail .empty p, .detail .empty li { color: var(--muted); font-size: 13px; line-height: 1.65; }
.detail .empty ul { padding-left: 18px; }
.kicker { font-size: 11px; letter-spacing: 0.12em; color: var(--gold); margin: 0 0 6px; }
.detail h2 { font-size: 24px; margin: 0 0 4px; line-height: 1.25; }
.latin { margin: 0 0 10px; color: var(--muted); font-style: italic; font-size: 13px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.badge {
  font-size: 11px; border-radius: 999px; padding: 3px 8px;
  border: 1px solid var(--panel-border); color: var(--muted);
}
.badge.exam { color: #1a1408; background: var(--gold); border-color: var(--gold); font-weight: 650; }
.badge.bone { color: var(--bone); border-color: rgba(228,213,188,0.35); }
.badge.muscle { color: var(--muscle); border-color: rgba(196,92,92,0.4); }
.badge.joint { color: var(--joint); border-color: rgba(78,196,200,0.4); }
.badge.landmark { color: var(--landmark); border-color: rgba(240,195,90,0.4); }
.badge.theory { color: var(--theory); }
.side-note { font-size: 12px; color: var(--muted); background: rgba(255,255,255,0.03);
  border-left: 2px solid var(--gold-dim); padding: 8px 10px; margin: 0 0 14px; }
.block { margin: 0 0 14px; }
.block h3 {
  margin: 0 0 6px; font-size: 12px; letter-spacing: 0.1em;
  color: var(--accent); font-weight: 650;
}
.block p, .block li { font-size: 13px; line-height: 1.7; color: var(--text); }
.block ul { margin: 0; padding-left: 18px; }
.kv { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv th {
  text-align: left; width: 72px; color: var(--muted);
  font-weight: 500; padding: 4px 8px 4px 0; vertical-align: top;
}
.kv td { padding: 4px 0; line-height: 1.6; }
.related { display: flex; flex-wrap: wrap; gap: 6px; }
.related button {
  background: rgba(255,255,255,0.04); border: 1px solid var(--panel-border);
  color: var(--text); border-radius: 999px; padding: 4px 10px; font-size: 12px;
}
.related button:hover { border-color: var(--gold-dim); color: var(--gold); }
.loader {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: #0c1017; z-index: 20;
}
.loader.fade { opacity: 0; pointer-events: none; transition: opacity .4s ease; }
.loader-card { text-align: center; width: 320px; }
.loader-card h2 { margin: 14px 0 6px; font-size: 18px; }
.loader-card p { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.spinner {
  width: 36px; height: 36px; margin: 0 auto;
  border: 3px solid rgba(232,184,74,0.15);
  border-top-color: var(--gold);
  border-radius: 50%; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 4px; background: #1c2430; border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 8%; background: linear-gradient(90deg, var(--gold-dim), var(--gold)); transition: width .2s; }
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 30; padding: 24px;
}
.modal[hidden] { display: none; }
.modal-card {
  background: #141b27; border: 1px solid var(--panel-border);
  border-radius: 16px; max-width: 680px; max-height: 86vh;
  overflow: auto; padding: 28px 32px; position: relative;
  box-shadow: var(--shadow);
}
.modal-card h2 { margin-top: 0; }
.modal-card h3 { color: var(--gold); font-size: 14px; }
.modal-card p, .modal-card li { color: var(--muted); font-size: 13px; line-height: 1.7; }
.modal-card blockquote {
  margin: 0 0 12px; padding: 10px 12px;
  background: rgba(232,184,74,0.07); border-left: 3px solid var(--gold);
  color: var(--text); font-size: 12px; line-height: 1.6;
}
.modal-card .close {
  position: absolute; top: 10px; right: 14px;
  border: 0; background: transparent; color: var(--muted); font-size: 24px;
}
@media (max-width: 1100px) {
  :root { --left: 280px; --right: 300px; }
}
@media (max-width: 860px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--top) 48vh auto auto;
    grid-template-areas: "top" "view" "left" "right";
  }
  .side { height: auto; max-height: 50vh; }
}
/* Small screens: preserve usable controls rather than covering the model. */
@media (max-width:860px) {
  #app {grid-template-rows:auto 60vh auto auto;height:auto;min-height:100%;}
  .topbar {min-height:100px;gap:8px;flex-wrap:wrap;padding:10px 12px;}
  .brand {min-width:200px;flex:1;}
  .brand p {font-size:10px;}
  .layers {order:3;width:100%;flex-basis:100%;}
  .top-actions {gap:4px;}
  .top-actions button {padding:5px 7px;font-size:10px;}
  .view-presets {flex-wrap:nowrap;overflow:auto;justify-content:flex-start;width:96%;max-width:96%;bottom:34px;}
  .view-presets button {flex:none;}
  .hint {font-size:9px;max-width:96%;white-space:normal;}
  .side {max-height:55vh;}
}
