/* Knowledge Map Engine — shared visual system v2
   Hero treemap fills the first screen; explanatory copy is hover-revealed
   or pushed to an appendix below the fold. Refined palette, depth, motion. */

:root {
  --bg: #f6f4ef;
  --bg-2: #eef0ee;
  --panel: #ffffff;
  --ink: #14161b;
  --ink-soft: #4a5160;
  --ink-faint: #8b909c;
  --line: #e7e3da;
  --line-strong: #d6d1c6;
  --accent: #4338ca;
  --accent-soft: #ecebfb;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-1: 0 1px 2px rgba(20, 22, 27, 0.05), 0 2px 8px rgba(20, 22, 27, 0.04);
  --shadow-2: 0 10px 34px rgba(20, 22, 27, 0.13);
  --shadow-pop: 0 16px 48px rgba(20, 22, 27, 0.18);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --font: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background:
    radial-gradient(1200px 600px at 85% -10%, #fbfaf7 0%, rgba(251, 250, 247, 0) 60%),
    radial-gradient(900px 500px at 0% 0%, #eef1f4 0%, rgba(238, 241, 244, 0) 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
}

/* ===================== HERO (first screen) ===================== */
.hero {
  height: 100svh;
  min-height: 600px;
  display: flex;
  flex-direction: column;
  padding: clamp(14px, 1.6vw, 26px) clamp(16px, 2.4vw, 40px) clamp(12px, 1.2vw, 18px);
  gap: 12px;
}

.topbar { display: flex; flex-direction: column; gap: 11px; flex: none; }

.topline { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }

.brand { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
h1 {
  font-size: clamp(1.28rem, 0.9rem + 1.5vw, 2.05rem);
  line-height: 1.08;
  letter-spacing: -0.022em;
  margin: 0;
  font-weight: 780;
  background: linear-gradient(92deg, var(--ink) 0%, #3a3f4d 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.sub { color: var(--ink-soft); margin: 0; font-size: clamp(0.8rem, 0.74rem + 0.3vw, 0.95rem); max-width: 64ch; }

.langtoggle {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  overflow: hidden;
  flex: none;
  background: var(--panel);
  box-shadow: var(--shadow-1);
}
.langtoggle button {
  border: 0; background: transparent; padding: 7px 15px;
  font: inherit; font-size: 0.82rem; font-weight: 640; color: var(--ink-faint);
  cursor: pointer; transition: background 0.18s, color 0.18s;
}
.langtoggle button.active { background: var(--ink); color: #fff; }

/* tool row: layer toggles + count + about chip */
.toolrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }

.layers { display: inline-flex; flex-wrap: wrap; gap: 7px; padding: 4px; background: rgba(255,255,255,0.6); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow-1); }
.layers button {
  position: relative;
  border: 0; background: transparent; border-radius: 999px;
  padding: 7px 15px; font: inherit; font-size: 0.84rem; font-weight: 580;
  color: var(--ink-soft); cursor: pointer; white-space: nowrap;
  transition: color 0.18s, background 0.18s, box-shadow 0.18s;
}
.layers button:hover { color: var(--ink); background: rgba(67,56,202,0.07); }
.layers button.active { background: var(--accent); color: #fff; box-shadow: 0 4px 14px rgba(67,56,202,0.32); }

.count { color: var(--ink-faint); font-size: 0.82rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.count b { color: var(--ink); font-weight: 700; }

.infochip { position: relative; }
.infochip > .chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--panel);
  border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 0.82rem;
  font-weight: 580; color: var(--ink-soft); cursor: help; box-shadow: var(--shadow-1);
  transition: border-color 0.18s, color 0.18s, transform 0.18s;
}
.infochip:hover > .chip-btn { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.infochip .pop {
  position: absolute; right: 0; top: calc(100% + 10px);
  width: min(440px, 86vw); background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); padding: 16px 18px; z-index: 40;
  opacity: 0; visibility: hidden; transform: translateY(-8px) scale(0.99);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease), visibility 0.2s;
  font-size: 0.85rem; color: var(--ink-soft); line-height: 1.55;
}
.infochip:hover .pop, .infochip:focus-within .pop { opacity: 1; visibility: visible; transform: none; }
.infochip .pop::before {
  content: ""; position: absolute; top: -6px; right: 22px; width: 11px; height: 11px;
  background: var(--panel); border-left: 1px solid var(--line); border-top: 1px solid var(--line);
  transform: rotate(45deg);
}
.infochip .pop p { margin: 0 0 10px; }
.infochip .pop p:last-child { margin-bottom: 0; }
.infochip .pop b { color: var(--ink); font-weight: 660; }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 5px 15px; font-size: 0.78rem; color: var(--ink-soft); min-height: 18px; align-items: center; }
.legend .lg { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 13px; height: 13px; border-radius: 4px; border: 1px solid rgba(0,0,0,0.1); flex: none; box-shadow: inset 0 1px 1px rgba(255,255,255,0.4); }
.legend .sw.hatch { background-image: repeating-linear-gradient(45deg, #d7d4cc 0 3px, #efece5 3px 6px); }

/* ===================== TREEMAP ===================== */
.treemap {
  position: relative; flex: 1 1 auto; width: 100%; min-height: 320px;
  background: linear-gradient(180deg, #fcfbf9, #f7f5f0);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-1);
}

.domain {
  position: absolute; overflow: hidden; border-radius: 9px;
  background: rgba(20,22,27,0.018);
  border: 1px solid rgba(20,22,27,0.07);
  transition: box-shadow 0.2s var(--ease);
  pointer-events: none; /* decorative only — let tiles beneath receive hover/click */
}
.domain-hd {
  position: absolute; left: 0; top: 0; right: 0; height: 23px;
  display: flex; align-items: center; padding: 0 9px;
  font-size: 0.73rem; font-weight: 750; letter-spacing: 0.01em; color: var(--ink);
  background: linear-gradient(180deg, rgba(255,255,255,0.95), rgba(255,255,255,0.78));
  backdrop-filter: blur(2px);
  border-bottom: 1px solid rgba(20,22,27,0.06);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  z-index: 3; pointer-events: none;
}
.comp-lbl {
  position: absolute; font-size: 0.63rem; font-weight: 680; color: var(--ink-soft);
  display: inline-flex; align-items: center; height: 15px; padding: 0 6px;
  background: rgba(255,255,255,0.66); backdrop-filter: blur(1.5px);
  border-radius: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  z-index: 2; pointer-events: none; max-width: calc(100% - 4px);
}

.tile {
  position: absolute; overflow: hidden; cursor: pointer;
  border-radius: 4px; transform-origin: center;
  box-shadow: inset 0 0 0 1px rgba(20,22,27,0.06);
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease),
    filter 0.18s var(--ease), background-color 0.45s var(--ease);
  will-change: transform;
}
.treemap.animate .tile { animation: tileIn 0.52s var(--ease) both; }
@keyframes tileIn { from { opacity: 0; transform: scale(0.86); } to { opacity: 1; transform: none; } }

.tile:hover {
  transform: translateY(-2px) scale(1.018);
  box-shadow: var(--shadow-2), inset 0 0 0 1px rgba(255,255,255,0.35);
  filter: saturate(1.08) brightness(1.05);
  z-index: 6;
}
.tile.sel { outline: 2.5px solid var(--ink); outline-offset: -2px; z-index: 7; box-shadow: var(--shadow-2); }
.tile .lbl {
  padding: 4px 6px; font-size: 0.71rem; font-weight: 560; line-height: 1.16;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
  text-shadow: 0 1px 1px rgba(0,0,0,0.06);
}

/* ===================== TOOLTIP ===================== */
.tooltip {
  position: fixed; z-index: 80; max-width: 330px;
  background: rgba(22,24,30,0.97); color: #f3f4f6;
  border-radius: 11px; padding: 12px 14px; font-size: 0.8rem; line-height: 1.5;
  box-shadow: var(--shadow-pop); pointer-events: none;
  border: 1px solid rgba(255,255,255,0.08);
  opacity: 0; transform: translateY(4px); transition: opacity 0.13s, transform 0.13s;
}
.tooltip.show { opacity: 1; transform: none; }
.tooltip .tt-name { font-weight: 720; font-size: 0.88rem; margin-bottom: 3px; }
.tooltip .tt-path { color: #a8b0bf; font-size: 0.72rem; margin-bottom: 8px; }
.tooltip .tt-note { color: #dadee6; margin-bottom: 9px; }
.tooltip .tt-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tooltip .tt-tag { font-size: 0.66rem; padding: 2px 7px; border-radius: 6px; background: rgba(255,255,255,0.1); color: #e7eaf0; }
.tooltip .tt-hint { margin-top: 9px; color: #868d9d; font-size: 0.7rem; }

/* ===================== DETAIL PANEL ===================== */
.detail {
  position: fixed; top: 0; right: 0; width: 400px; max-width: 94vw; height: 100svh;
  background: var(--panel); border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop); z-index: 90; padding: 26px 26px 44px;
  overflow-y: auto; transform: translateX(0);
  transition: transform 0.3s var(--ease);
}
.detail[hidden] { display: block; transform: translateX(103%); }
.detail .accent { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; }
.detail .close {
  position: absolute; top: 16px; right: 16px; border: 1px solid var(--line);
  background: var(--panel); width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
  font-size: 1rem; color: var(--ink-soft); line-height: 1; transition: background 0.16s, transform 0.16s;
}
.detail .close:hover { background: var(--bg); transform: rotate(90deg); }
.detail .d-path { font-size: 0.78rem; color: var(--accent); font-weight: 640; margin-bottom: 7px; }
.detail h3 { margin: 0 0 3px; font-size: 1.22rem; letter-spacing: -0.012em; line-height: 1.2; }
.detail .d-alt { color: var(--ink-faint); font-size: 0.9rem; margin-bottom: 16px; }
.detail .d-note { color: var(--ink-soft); font-size: 0.92rem; margin: 0 0 18px; }
.detail .d-section-t { font-size: 0.71rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-faint); margin: 20px 0 9px; font-weight: 700; }
.detail .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.detail .chip { font-size: 0.74rem; padding: 4px 10px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--ink-soft); }
.detail .chip b { color: var(--ink); font-weight: 660; }
.detail .resource-links { margin: 0; padding: 0; list-style: none; display: grid; gap: 7px; }
.detail .resource-links a {
  display: block; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px;
  color: var(--accent); background: var(--bg); text-decoration: none; font-size: 0.82rem;
  transition: border-color 0.16s, background 0.16s, transform 0.16s;
}
.detail .resource-links a:hover { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.rate { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.rate button {
  border: 1px solid var(--line-strong); background: var(--panel); border-radius: 8px;
  width: 40px; height: 38px; cursor: pointer; font: inherit; font-weight: 680; font-size: 0.84rem;
  color: var(--ink-soft); transition: all 0.15s var(--ease);
}
.rate button:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.rate button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.rate .clear { width: auto; padding: 0 13px; font-size: 0.76rem; font-weight: 560; }
.gapnote { font-size: 0.82rem; margin-top: 12px; padding: 10px 12px; border-radius: 9px; }
.gapnote.gap { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.gapnote.ok { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.gapnote.none { background: var(--bg); color: var(--ink-faint); border: 1px solid var(--line); }

/* ===================== APPENDIX (below the fold) ===================== */
.appendix {
  max-width: 1180px; margin: 0 auto; padding: 40px clamp(16px, 2.4vw, 40px) 90px;
}
.appendix .scrollcue { text-align: center; color: var(--ink-faint); font-size: 0.78rem; margin: 0 0 30px; letter-spacing: 0.04em; }
.rubricWrap h3 { font-size: 1.1rem; margin: 0 0 4px; letter-spacing: -0.01em; }
.rubricWrap .rsub { color: var(--ink-faint); font-size: 0.84rem; margin: 0 0 14px; }
#rubricBody { font-size: 0.86rem; color: var(--ink-soft); columns: 2; column-gap: 36px; }
#rubricBody .rgroup { break-inside: avoid; margin-bottom: 18px; }
#rubricBody h4 { margin: 0 0 7px; color: var(--ink); font-size: 0.9rem; }
#rubricBody .anchor { font-family: var(--mono); font-size: 0.79rem; }
#rubricBody .swatch-inline { display: inline-block; width: 11px; height: 11px; border-radius: 3px; vertical-align: middle; margin-right: 7px; border: 1px solid rgba(0,0,0,0.12); }
#rubricBody ul { margin: 0; padding-left: 2px; list-style: none; }
#rubricBody li { margin: 4px 0; line-height: 1.45; }

.caveat { margin: 30px 0 0; padding: 18px 20px; background: linear-gradient(180deg, #fffdf5, #fefcf3); border: 1px solid #efe6cd; border-radius: var(--radius); font-size: 0.87rem; color: #6b5e3a; }
.caveat b { color: #5a4d2a; }
footer { margin-top: 30px; border-top: 1px solid var(--line); padding-top: 20px; }
.src h4 { margin: 0 0 10px; font-size: 0.73rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-faint); }
.src ul { margin: 0; padding: 0; list-style: none; columns: 2; column-gap: 30px; font-size: 0.8rem; }
.src li { margin: 0 0 6px; break-inside: avoid; }
.src a, .credit a, .infochip a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
.src a:hover, .credit a:hover, .infochip a:hover { border-bottom-color: var(--accent); }
.credit { font-size: 0.78rem; color: var(--ink-faint); margin-top: 18px; }

/* ===================== Responsive ===================== */
@media (max-width: 760px) {
  .hero { height: auto; min-height: 100svh; }
  .treemap { min-height: 64svh; }
  .topline { flex-direction: row; }
  h1 { font-size: 1.25rem; }
  .sub { display: none; }
  .infochip .pop { right: auto; left: 0; }
  .infochip .pop::before { right: auto; left: 22px; }
  #rubricBody, .src ul { columns: 1; }
  .detail { width: 100%; height: 80svh; top: auto; bottom: 0; border-left: 0; border-top: 1px solid var(--line-strong); border-radius: 18px 18px 0 0; }
  .detail[hidden] { transform: translateY(103%); }
}

@media (prefers-reduced-motion: reduce) {
  .treemap.animate .tile { animation: none; }
  .tile, .detail, .infochip .pop, .tooltip { transition-duration: 0.01ms; }
}
