/* ------------------------------------------------------------------ */
/* Tokens                                                             */
/* ------------------------------------------------------------------ */
:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --text: #1b1d1a;
  --muted: #5c615a;
  --faint: #8a8f87;
  --border: #e1e4dd;
  --guide: #d5d9d0;
  --hover: #eef1ea;
  --accent: #2b7349;
  --accent-strong: #1f5b38;
  --accent-soft: #e3f1e8;
  --accent-ring: rgba(43, 115, 73, 0.35);
  --badge-bg: #eef1ea;
  --badge-fg: #3d5a47;
  --shadow: 0 1px 2px rgba(20, 30, 20, 0.06), 0 1px 1px rgba(20, 30, 20, 0.04);

  --radius: 10px;
  --radius-sm: 6px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --indent: 1.25rem;
  --dur: 220ms;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111311;
    --surface: #181b18;
    --text: #e6e9e3;
    --muted: #a0a69d;
    --faint: #767c73;
    --border: #2a2e29;
    --guide: #313630;
    --hover: #1f231f;
    --accent: #6cc48f;
    --accent-strong: #8fd6aa;
    --accent-soft: #1b2c21;
    --accent-ring: rgba(108, 196, 143, 0.4);
    --badge-bg: #202620;
    --badge-fg: #9fcdb0;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111311;
  --surface: #181b18;
  --text: #e6e9e3;
  --muted: #a0a69d;
  --faint: #767c73;
  --border: #2a2e29;
  --guide: #313630;
  --hover: #1f231f;
  --accent: #6cc48f;
  --accent-strong: #8fd6aa;
  --accent-soft: #1b2c21;
  --accent-ring: rgba(108, 196, 143, 0.4);
  --badge-bg: #202620;
  --badge-fg: #9fcdb0;
  --shadow: none;
}

/* ------------------------------------------------------------------ */
/* Base                                                               */
/* ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }

code, kbd { font-family: var(--mono); font-size: 0.875em; }
kbd {
  display: inline-block;
  padding: 0 0.35em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  line-height: 1.5;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 1rem; top: -3rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  z-index: 10;
}
.skip-link:focus { top: 1rem; }

.wrap {
  width: 100%;
  max-width: 96rem;
  margin: 0 auto;
  padding: 0 16px;
}

/* ------------------------------------------------------------------ */
/* Header                                                             */
/* ------------------------------------------------------------------ */
.site-header { padding: 1.5rem 0 0.5rem; }

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  text-decoration: none;
}
.brand:hover { color: var(--text); }
.brand-logo { display: block; }
.brand-name {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text); background: var(--hover); }
.theme-icon { display: inline-flex; }

.tagline {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  text-wrap: balance;
}
.tagline em { font-style: normal; color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------------ */
/* Search + legend                                                    */
/* ------------------------------------------------------------------ */
.search-section { padding: 1.25rem 0 0.5rem; max-width: 46rem; }

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 0.85rem;
  display: inline-flex;
  color: var(--faint);
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 0.8rem 2.75rem 0.8rem 2.6rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-appearance: none;
  appearance: none;
}
#search::placeholder { color: var(--faint); }
#search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
#search::-webkit-search-cancel-button { cursor: pointer; }
.search-kbd {
  position: absolute;
  right: 0.8rem;
  pointer-events: none;
}
#search:focus ~ .search-kbd,
#search:not(:placeholder-shown) ~ .search-kbd { display: none; }
@media (hover: none) {
  .search-kbd { display: none; }
  #search { padding-right: 1rem; }
}

.search-status {
  min-height: 1.4em;
  margin: 0.5rem 0.25rem 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
  gap: 0.35rem 1rem;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
}
.legend-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}
.legend-text strong { display: block; color: var(--text); font-weight: 600; }

/* ------------------------------------------------------------------ */
/* Badges                                                             */
/* ------------------------------------------------------------------ */
.badges { display: inline-flex; gap: 0.25rem; flex-shrink: 0; }
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: var(--radius-sm);
  background: var(--badge-bg);
  color: var(--badge-fg);
  flex-shrink: 0;
}

/* ------------------------------------------------------------------ */
/* Tree (horizontal node-link, SVG)                                   */
/* ------------------------------------------------------------------ */
.tree-section { padding: 1rem 0 2.5rem; }

.explorer {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 62rem) {
  .explorer { grid-template-columns: minmax(0, 1fr) 20rem; }
}

.tree-canvas {
  position: relative;
  height: clamp(480px, 80vh, 920px);
  background:
    radial-gradient(circle, var(--guide) 1px, transparent 1.2px) 0 0 / 22px 22px,
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.tree-canvas.is-panning { cursor: grabbing; }
.tree-loading, .tree-error { margin: 0; padding: 1rem; color: var(--muted); }

.tree-svg { display: block; width: 100%; height: 100%; }
.tree-svg text { font-family: var(--font); }

.link {
  fill: none;
  stroke: var(--guide);
  stroke-width: 1.5px;
  transition: stroke 150ms;
}
.link.is-match { stroke: var(--accent); stroke-width: 1.75px; }
.link.is-dim { stroke: var(--border); }

.node { cursor: pointer; }
.node .inner { outline: none; }
.node .hit { fill: transparent; stroke: transparent; stroke-width: 2px; transition: fill 120ms; }
.node .inner:hover .hit { fill: var(--hover); }
.node .inner:focus-visible .hit { stroke: var(--accent); fill: var(--hover); }

.node circle {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 2px;
  transition: fill 150ms;
}
.node.root circle,
.node.folder.is-collapsed circle { fill: var(--accent); }
.node.tool circle { stroke: var(--faint); stroke-width: 1.75px; }
.node.tool .inner:hover circle { stroke: var(--accent); }

.label {
  font-size: 14px;
  fill: var(--text);
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 4px;
  stroke-linejoin: round;
  dominant-baseline: auto;
}
.node .inner:hover .label,
.node .inner:focus-visible .label { stroke: var(--hover); }
.node.root .label { font-size: 16px; font-weight: 700; }
.node.folder .label { font-weight: 600; }
.node.folder .count { font-size: 12px; font-weight: 500; fill: var(--faint); }
.node.tool .inner:hover .label { fill: var(--accent); text-decoration: underline; }

.badge-icon { color: var(--badge-fg); }

.node.is-selected .hit { fill: var(--hover); }
.node.is-selected .label { stroke: var(--hover); }

/* Search states */
.node.is-dim .inner { opacity: 0.35; }
.node.is-dim .inner:hover,
.node.is-dim .inner:focus-visible { opacity: 1; }
.node.is-match .hit { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1px; }
.node.is-match .label { fill: var(--accent-strong); font-weight: 600; stroke: var(--accent-soft); }
.node.is-match circle { fill: var(--accent); stroke: var(--accent); }
.node.has-match .label { fill: var(--accent-strong); }

.node.is-exiting { pointer-events: none; }

/* Controls */
.tree-controls {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.tree-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}
.tree-controls button + button { border-top: 1px solid var(--border); }
.tree-controls button:hover { color: var(--text); background: var(--hover); }
.tree-controls button:focus-visible { outline-offset: -2px; }

.tree-canvas-hint {
  position: absolute;
  left: 0.75rem;
  bottom: 0.5rem;
  margin: 0;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  color: var(--faint);
  background: var(--surface);
  border-radius: var(--radius-sm);
  pointer-events: none;
}

/* Details panel */
.panel {
  align-self: start;
  padding: 1rem 1.1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}
@media (min-width: 62rem) {
  .panel { position: sticky; top: 1rem; max-height: clamp(480px, 80vh, 920px); overflow: auto; }
}
.panel-empty { margin: 0; color: var(--muted); }
.panel-path { margin: 0 0 0.2rem; font-size: 0.78rem; color: var(--faint); }
.panel-title { margin: 0 0 0.6rem; font-size: 1.2rem; letter-spacing: -0.01em; }
.panel-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  margin: 0 0 0.75rem;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  color: var(--muted);
}
.panel-badges li { display: inline-flex; align-items: center; gap: 0.35rem; }
.panel-badges .badge { width: 1.35rem; height: 1.35rem; }
.panel-desc { margin: 0 0 0.9rem; color: var(--text); line-height: 1.5; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.8rem; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.8rem;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.btn:hover { background: var(--hover); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--surface); }
.panel-date { margin: 0.6rem 0 0; font-size: 0.75rem; color: var(--faint); }

.verify { font-size: 0.8rem; }
.verify summary { cursor: pointer; color: var(--muted); }
.verify summary:hover { color: var(--accent); }
.verify p {
  margin: 0.4rem 0 0;
  padding: 0.55rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  line-height: 1.45;
}

/* ------------------------------------------------------------------ */
/* Footer                                                             */
/* ------------------------------------------------------------------ */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 2rem 0 3rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.footer-grid {
  max-width: 60rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1.5rem 2.5rem;
}
.site-footer h2 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--text);
}
.site-footer p { margin: 0 0 0.6rem; }
.criteria { margin: 0 0 0.6rem; padding-left: 1.1rem; }
.criteria li { margin-bottom: 0.25rem; }
.criteria strong { color: var(--text); }
.footnote { font-size: 0.8rem; color: var(--faint); }

/* ------------------------------------------------------------------ */
/* Small screens + motion                                             */
/* ------------------------------------------------------------------ */
@media (max-width: 30rem) {
  :root { --indent: 0.85rem; }
  .brand-name { font-size: 1.2rem; }
  .theme-label { display: none; }
  .tree-canvas { height: 62vh; }
}

@media (prefers-reduced-motion: reduce) {
  .link, .node .hit, .node circle { transition: none !important; }
}
