/* ── KIER Low-Humidity HVAC — derivation ontology tower ──
   심야 기계실 팔레트. 계측 시안 / 가정 앰버 / KPI 웜화이트. */
:root {
  --bg: #0a0d13;
  --ink: #e8ecf4;
  --ink-dim: #8b94a7;
  --ink-faint: #545c6e;
  --panel: rgba(16, 20, 30, 0.82);
  --panel-line: rgba(140, 160, 200, 0.14);
  --tag: #4fa3c7;      /* 계측 시안 */
  --assume: #c9a45c;   /* 가정 앰버 */
  --elec: #e0b64f;
  --air: #6fcab8;
  --psy: #7c9bf0;
  --thermal: #e0725e;
  --kpi: #f2ede0;
  --accent: #6fcab8;
  font-size: 15px;
}

/* ── 라이트 테마 (site A SCADA 계통도 문법: 밝은 캔버스 + 블루그리드 + 잉크 라인) ── */
:root.theme-light {
  --bg: #f5f8fb;
  --ink: #17222e;
  --ink-dim: #46586c;
  --ink-faint: #7d90a5;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-line: rgba(23, 44, 66, 0.16);
  --kpi: #2b3950;          /* 정점 노드: 흰 배경에선 잉크색이 '무게'를 가짐 */
  --accent: #0e8a72;
}
:root.theme-light body {
  background:
    linear-gradient(rgba(59, 86, 110, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59, 86, 110, 0.045) 1px, transparent 1px),
    var(--bg);
  background-size: 24px 24px, 24px 24px, auto;
}
:root.theme-light .node-label {
  color: var(--ink-dim);
  text-shadow: 0 1px 4px rgba(255, 255, 255, 0.95), 0 0 2px rgba(255, 255, 255, 0.9);
}
:root.theme-light .node-label.is-bind { color: #4a6478; }
:root.theme-light .node-label.is-plant { color: #3d5268; }
:root.theme-light .node-label.is-plant.is-heat { color: #b0562e; }
:root.theme-light .ring-label { text-shadow: 0 1px 4px rgba(255, 255, 255, 0.95); border-left-color: rgba(23, 44, 66, 0.3); }
:root.theme-light #fold-btn {
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 20px rgba(23, 44, 66, 0.14), 0 0 14px rgba(14, 138, 114, 0.08);
  border-color: rgba(14, 138, 114, 0.4);
}
:root.theme-light .rail-level .lv-bar {
  background: linear-gradient(90deg, rgba(14, 138, 114, 0.75), rgba(74, 111, 216, 0.55));
  box-shadow: none;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans KR", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: "IBM Plex Mono", monospace; }

#stage, #labels { position: fixed; inset: 0; }
#stage { cursor: grab; }
#stage.dragging { cursor: grabbing; }
#stage.node-hover { cursor: pointer; }
#labels { pointer-events: none; }

/* ── 노드 라벨 (CSS2D) ── */
.node-label {
  pointer-events: none;
  font-size: 11px;
  letter-spacing: 0.01em;
  color: var(--ink-dim);
  text-shadow: 0 1px 6px rgba(4, 6, 10, 0.95), 0 0 2px rgba(4, 6, 10, 0.9);
  white-space: nowrap;
  transform: translateY(-4px);
  transition: opacity 0.25s ease, color 0.25s ease;
}
.node-label.is-kpi { font-size: 13px; font-weight: 600; color: var(--kpi); }
.node-label.is-bind { font-family: "IBM Plex Mono", monospace; font-size: 9.5px; letter-spacing: 0.08em; color: #5a7d94; }
.node-label.is-plant { font-size: 11.5px; font-weight: 600; color: #9db2c9; letter-spacing: 0.02em; }
.node-label.is-plant.is-heat { color: #d08a66; }
/* 접힘 상태: 계통도 요소 외 라벨 전부 숨김 */
#labels.is-folded .node-label:not(.is-plant) { opacity: 0; }
#labels.is-folded .ring-label:not(.is-plant-rl) { opacity: 0; }
.node-label.is-lit { color: var(--ink); }
.node-label.is-ghost { opacity: 0; }

/* ── 층 링 레이블 ── */
.ring-label {
  pointer-events: none;
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px; letter-spacing: 0.12em;
  color: var(--ink-faint); white-space: nowrap;
  text-shadow: 0 1px 6px rgba(4, 6, 10, 0.95);
  padding-left: 10px;
  border-left: 1px solid rgba(140, 160, 200, 0.35);
  transition: opacity 0.25s ease, color 0.25s ease;
}
.ring-label b { color: var(--ink-dim); font-weight: 500; }
.ring-label.is-active { color: var(--ink-dim); }
.ring-label.is-active b { color: var(--ink); }
.ring-label.is-ghost { opacity: 0.12; }

/* ── 마스트헤드 ── */
#masthead {
  position: fixed; top: 28px; left: 96px; z-index: 10;
  pointer-events: none; user-select: none;
}
#site-nav { pointer-events: auto; display: flex; gap: 8px; margin-bottom: 12px; }
#site-nav a {
  font-size: 11px; letter-spacing: 0.06em; text-decoration: none;
  color: var(--ink-dim); border: 1px solid var(--panel-line);
  padding: 4px 11px; border-radius: 14px; transition: color 0.15s, border-color 0.15s;
}
#site-nav a:hover { color: var(--ink); border-color: rgba(111, 202, 184, 0.5); }
#site-nav a.is-current { color: var(--accent); border-color: rgba(111, 202, 184, 0.55); background: rgba(111, 202, 184, 0.07); }
#site-nav .nav-gallery { color: var(--ink-faint); }
.eyebrow {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10.5px; letter-spacing: 0.22em;
  color: var(--ink-faint); margin-bottom: 8px;
}
#masthead h1 {
  font-size: 27px; font-weight: 700; letter-spacing: -0.01em;
  color: var(--ink);
}
#masthead .sub { margin-top: 6px; font-size: 12.5px; color: var(--ink-dim); }
#masthead .sub .mono { font-size: 11px; color: var(--ink-faint); }

/* ── depth gauge 레일 (시그니처) ── */
#depth-rail {
  position: fixed; left: 24px; top: 50%; transform: translateY(-50%);
  z-index: 10; display: flex; flex-direction: column; gap: 6px;
  width: 200px;
}
#depth-rail button {
  appearance: none; border: 1px solid transparent; background: transparent;
  color: var(--ink-dim); text-align: left; cursor: pointer;
  font-family: inherit; border-radius: 8px; padding: 8px 10px;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
#depth-rail button:hover { background: rgba(140, 160, 200, 0.08); color: var(--ink); }
#depth-rail button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#depth-rail button.is-active {
  background: var(--panel); border-color: var(--panel-line); color: var(--ink);
}
#depth-rail .rail-all {
  font-size: 12.5px; font-weight: 600; letter-spacing: 0.06em;
  margin-bottom: 10px; display: flex; align-items: baseline; gap: 8px;
}
#depth-rail .rail-all span { font-size: 10.5px; font-weight: 400; color: var(--ink-faint); }
.rail-level .lv-name {
  display: block; font-family: "IBM Plex Mono", monospace;
  font-size: 10px; letter-spacing: 0.1em; color: var(--ink-faint);
  margin-bottom: 5px;
}
.rail-level.is-active .lv-name { color: var(--ink-dim); }
.rail-level .lv-row { display: flex; align-items: center; gap: 8px; }
.rail-level .lv-bar {
  height: 5px; border-radius: 3px;
  background: linear-gradient(90deg, rgba(111, 202, 184, 0.85), rgba(124, 155, 240, 0.6));
  box-shadow: 0 0 8px rgba(111, 202, 184, 0.25);
  transition: filter 0.2s;
}
.rail-level:hover .lv-bar { filter: brightness(1.25); }
.rail-level .lv-count {
  font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--ink-dim);
}

/* 접지층 토글 (cut in 버튼과 구분되는 스위치 성격) */
.rail-bind {
  margin-top: 10px; border-top: 1px dashed rgba(140, 160, 200, 0.18);
  padding-top: 10px; border-radius: 0 0 8px 8px;
}
.rail-bind .lv-bar.bind-bar {
  background: linear-gradient(90deg, rgba(90, 125, 148, 0.8), rgba(90, 125, 148, 0.3));
  box-shadow: none;
}
.rail-bind .bind-state {
  margin-left: auto; font-size: 10px; letter-spacing: 0.08em;
  color: var(--ink-faint); border: 1px solid var(--panel-line);
  padding: 2px 7px; border-radius: 10px;
}
.rail-bind.is-on .bind-state { color: var(--air); border-color: rgba(111, 202, 184, 0.45); }

/* ── 검색 ── */
#searchbox { position: fixed; top: 28px; right: 28px; z-index: 12; width: 260px; }
#search {
  width: 100%; padding: 9px 12px;
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 9px; color: var(--ink);
  font-family: inherit; font-size: 13px;
  backdrop-filter: blur(12px);
}
#search::placeholder { color: var(--ink-faint); }
#search:focus { outline: none; border-color: rgba(111, 202, 184, 0.5); }
#search-results {
  list-style: none; margin-top: 6px; max-height: 300px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 9px; backdrop-filter: blur(12px);
}
#search-results li {
  padding: 8px 12px; cursor: pointer; font-size: 12.5px;
  display: flex; align-items: center; gap: 8px;
}
#search-results li:hover, #search-results li.is-focus { background: rgba(140, 160, 200, 0.1); }
#search-results .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
#search-results .lv { margin-left: auto; font-family: "IBM Plex Mono", monospace; font-size: 10px; color: var(--ink-faint); }

/* ── 인스펙터 ── */
#inspector {
  position: fixed; top: 84px; right: 28px; bottom: 84px; z-index: 11;
  width: 330px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: 14px; padding: 20px 20px 24px;
  backdrop-filter: blur(16px);
  animation: insp-in 0.25s ease;
}
@keyframes insp-in { from { opacity: 0; transform: translateX(12px); } }
#inspector-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--ink-faint);
  font-size: 20px; cursor: pointer; line-height: 1;
}
#inspector-close:hover { color: var(--ink); }
.insp-kind {
  font-family: "IBM Plex Mono", monospace; font-size: 10px;
  letter-spacing: 0.18em; color: var(--ink-faint); margin-bottom: 6px;
}
#insp-title { font-size: 17px; font-weight: 600; line-height: 1.35; }
.insp-id { font-size: 11px; color: var(--ink-faint); margin: 4px 0 14px; }
.insp-section { margin-top: 16px; }
.insp-section h3 {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.14em;
  color: var(--ink-faint); margin-bottom: 8px; text-transform: uppercase;
}
.formula {
  font-family: "IBM Plex Mono", monospace; font-size: 11.5px; line-height: 1.6;
  color: var(--ink); background: rgba(6, 9, 14, 0.6);
  border: 1px solid var(--panel-line); border-radius: 8px;
  padding: 10px 12px; white-space: pre-wrap; word-break: break-all;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 11px; padding: 4px 9px; border-radius: 20px;
  border: 1px solid var(--panel-line); color: var(--ink-dim);
  cursor: pointer; background: none; font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip .u { font-family: "IBM Plex Mono", monospace; font-size: 10px; margin-left: 4px; }
.chip.st-verified { border-color: rgba(111, 202, 184, 0.55); color: var(--air); }
.chip.st-hypothesis_supported { border-color: rgba(224, 182, 79, 0.55); color: var(--elec); }
.chip.st-assumed { border-color: rgba(201, 164, 92, 0.4); color: var(--assume); }
.insp-note { font-size: 12.5px; line-height: 1.65; color: var(--ink-dim); }
.insp-note b { color: var(--ink); font-weight: 600; }
.unlock-callout {
  margin-top: 14px; padding: 12px 14px; border-radius: 10px;
  background: rgba(201, 164, 92, 0.08); border: 1px solid rgba(201, 164, 92, 0.3);
  font-size: 12.5px; line-height: 1.6; color: var(--ink-dim);
}
.unlock-callout b { color: var(--assume); }

/* ── 접기/펼치기 버튼 (주 전환 컨트롤) ── */
#fold-btn {
  position: fixed; bottom: 64px; left: 50%; transform: translateX(-50%);
  z-index: 12; cursor: pointer;
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  color: var(--ink);
  background: rgba(24, 32, 46, 0.92); border: 1px solid rgba(111, 202, 184, 0.35);
  padding: 11px 22px; border-radius: 24px; backdrop-filter: blur(12px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45), 0 0 18px rgba(111, 202, 184, 0.12);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}
#fold-btn:hover { border-color: rgba(111, 202, 184, 0.7); transform: translateX(-50%) translateY(-1px); }
#fold-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#fold-btn span { font-size: 11px; font-weight: 400; color: var(--ink-dim); margin-left: 8px; }
#fold-btn.is-unfolded { border-color: var(--panel-line); box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45); }

#depth-rail.is-disabled { opacity: 0.3; pointer-events: none; }
#depth-rail { transition: opacity 0.4s; }

/* ── 힌트 바 ── */
#hints {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 10; display: flex; gap: 18px;
  font-size: 11.5px; color: var(--ink-faint);
  background: var(--panel); border: 1px solid var(--panel-line);
  padding: 8px 18px; border-radius: 20px; backdrop-filter: blur(12px);
  user-select: none; white-space: nowrap;
}
#hints b { color: var(--ink-dim); font-weight: 600; }

/* ── 반응형 ── */
@media (max-width: 900px) {
  #masthead { left: 20px; top: 18px; }
  #masthead h1 { font-size: 20px; }
  #depth-rail { left: 12px; width: 150px; }
  #inspector { left: 12px; right: 12px; width: auto; top: auto; bottom: 12px; max-height: 46vh; }
  #searchbox { width: 180px; top: 18px; right: 16px; }
  #hints { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  #inspector { animation: none; }
  * { transition-duration: 0.01ms !important; }
}
