:root {
  --bg: #f4efe4;
  --surface: #fffaf0;
  --surface-2: #ebe3d3;
  --border: #d4c8b2;
  --text: #2b2620;
  --muted: #7a6f60;
  --accent: #b5561b;
  --accent-soft: rgba(181, 86, 27, 0.14);
  --done: #3f7d3a;
  --done-soft: rgba(63, 125, 58, 0.14);
  --anc: #b5561b;
  --desc: #2f6f9f;
  --edge: rgba(80, 66, 48, 0.28);
  --edge-dim: rgba(80, 66, 48, 0.08);
  --shadow: 0 1px 2px rgba(40, 30, 20, 0.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17150f;
    --surface: #221f18;
    --surface-2: #2c2820;
    --border: #3d372c;
    --text: #ece4d4;
    --muted: #9c9180;
    --accent: #f0913f;
    --accent-soft: rgba(240, 145, 63, 0.16);
    --done: #7cc271;
    --done-soft: rgba(124, 194, 113, 0.14);
    --anc: #f0913f;
    --desc: #6cb4e8;
    --edge: rgba(220, 205, 180, 0.22);
    --edge-dim: rgba(220, 205, 180, 0.06);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --dim: 0.4;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17150f;
  --surface: #221f18;
  --surface-2: #2c2820;
  --border: #3d372c;
  --text: #ece4d4;
  --muted: #9c9180;
  --accent: #f0913f;
  --accent-soft: rgba(240, 145, 63, 0.16);
  --done: #7cc271;
  --done-soft: rgba(124, 194, 113, 0.14);
  --anc: #f0913f;
  --desc: #6cb4e8;
  --edge: rgba(220, 205, 180, 0.22);
  --edge-dim: rgba(220, 205, 180, 0.06);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --dim: 0.4;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---- top bar ---- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: 0.01em; }
.progress { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.search { position: relative; flex: 1 1 220px; max-width: 380px; }
.search input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  max-height: 60vh; overflow: auto; z-index: 20;
}
.results li button {
  display: flex; justify-content: space-between; gap: 8px; width: 100%;
  text-align: left; border: 0; background: none; padding: 6px 8px; border-radius: 4px;
}
.results li button:hover, .results li button.active { background: var(--accent-soft); }
.results .r-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.results .empty { padding: 6px 8px; color: var(--muted); }

.controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-left: auto; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-weight: 550; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 36px; height: 20px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid var(--border); position: relative; transition: background 0.15s;
}
.switch .thumb {
  position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .track { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .track .thumb { transform: translateX(16px); background: var(--accent); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.zoom { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.zoom button { border: 0; background: var(--surface); padding: 5px 10px; min-width: 32px; }
.zoom button + button { border-left: 1px solid var(--border); }
.zoom button:hover { background: var(--surface-2); }
.ghost {
  border: 1px solid var(--border); background: transparent; border-radius: 6px; padding: 5px 10px;
}
.ghost:hover { background: var(--surface-2); }
.ghost.small { padding: 2px 8px; font-size: 12px; }
.primary {
  border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 6px;
  padding: 6px 12px; font-weight: 600;
}
.primary:hover { filter: brightness(1.08); }

.focusbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 16px; background: var(--accent-soft); border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.focusbar[hidden] { display: none; }

/* ---- main layout ---- */
.layout { flex: 1; display: flex; min-height: 0; }
.viewport {
  flex: 1; overflow: hidden; position: relative; outline: none;
  background-image: radial-gradient(var(--border) 1px, transparent 1px);
  background-size: 22px 22px;
}
.viewport.dragging { cursor: grabbing; user-select: none; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.loading.error { color: var(--accent); padding: 16px; text-align: center; }

/* ---- the node web ---- */
svg.web { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
svg.web:active { cursor: grabbing; }
.rings { display: none; }
.rings circle { fill: none; stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 6; }
.rings text {
  fill: var(--muted); font-size: calc(11px * min(var(--inv, 1), 4)); font-weight: 650; letter-spacing: 0.08em; text-transform: uppercase;
  text-anchor: middle; opacity: 0.8;
}
.links line { stroke: var(--edge); stroke-width: 1.2; transition: stroke 0.15s, opacity 0.15s; }
.arrow { fill: var(--edge); }
.arrow.anc { fill: var(--anc); }
.arrow.desc { fill: var(--desc); }
.node { cursor: pointer; }
.node .dot {
  fill: var(--dot, #a08060); stroke: var(--surface); stroke-width: 1.5;
  transition: opacity 0.15s;
}
.node .halo { fill: none; stroke: transparent; stroke-width: 3; }
.node.done .halo { stroke: var(--done); }
.node.open .halo { stroke: var(--accent); stroke-dasharray: 3 3; }
.node.mystery .dot { fill: var(--surface-2); stroke: var(--muted); stroke-dasharray: 2 2; }
.node .mark { fill: #fff; font-size: 10px; font-weight: 700; text-anchor: middle; pointer-events: none; }
.node.mystery .mark { fill: var(--muted); }
.node .label {
  fill: var(--text); font-size: calc(11px * min(var(--inv, 1), 3)); text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round;
  display: none;
}
/* labels: the bigger hubs from mid zoom, all of them up close, and whatever is lit up */
svg.web:not(.far) .node.big .label, svg.web.near .node .label,
.node.sel .label, .node.anc .label, .node.kid .label, .node:hover .label { display: block; }
.node:hover .halo { stroke: var(--accent); }
.node.fresh .dot { animation: pop 0.6s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes pop { 0% { transform: scale(0.2); } 70% { transform: scale(1.25); } 100% { transform: scale(1); } }
svg.web.has-sel .node { opacity: var(--dim, 0.25); }
svg.web.has-sel .node.sel, svg.web.has-sel .node.anc, svg.web.has-sel .node.desc { opacity: 1; }
svg.web.has-sel .links line { opacity: var(--dim, 0.25); }
svg.web.has-sel .links line.hl-anc { stroke: var(--anc); stroke-width: 2.2; opacity: 1; }
svg.web.has-sel .links line.hl-desc { stroke: var(--desc); stroke-width: 2.2; opacity: 1; stroke-dasharray: 6 4; }
.node.sel .halo { stroke: var(--accent); stroke-width: 4; stroke-dasharray: none; }
.node.sel .label { font-weight: 700; font-size: calc(13px * min(var(--inv, 1), 3)); }

/* ---- details panel ---- */
.details {
  width: 360px; flex: none; overflow: auto;
  background: var(--surface); border-left: 1px solid var(--border);
  padding: 16px 18px 28px;
}
.details h2 { font-size: 18px; margin: 0 0 4px; line-height: 1.25; }
.details h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  margin: 20px 0 6px; font-weight: 650;
}
.details p { margin: 6px 0; }
.details .sub { color: var(--muted); font-size: 12px; }
.details .sub a { color: inherit; }
.details .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.details .close { display: none; }
.details ul { margin: 0; padding: 0; list-style: none; }
.pill {
  display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); margin-right: 4px; vertical-align: 1px;
}
.pill.done { background: var(--done-soft); color: var(--done); }
.pill.open { background: var(--accent-soft); color: var(--accent); }
.req-key { padding: 8px 0; border-top: 1px solid var(--border); }
.req-key:first-child { border-top: 0; }
.req-key .k { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.req-key .note { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kind { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; }
.providers { margin-top: 4px !important; padding-left: 10px !important; border-left: 2px solid var(--border) !important; }
.nlink {
  border: 0; background: none; padding: 2px 0; text-align: left; color: var(--text);
  display: flex; gap: 6px; align-items: baseline; width: 100%;
}
.nlink:hover .nt { text-decoration: underline; color: var(--accent); }
.nlink .ic { width: 14px; flex: none; text-align: center; color: var(--muted); }
.nlink.done .ic { color: var(--done); }
.nlink.open .ic { color: var(--accent); }
.nlink.locked { color: var(--muted); cursor: default; }
.nlink[disabled] .nt { text-decoration: none; color: var(--muted); }
.op { font-weight: 650; color: var(--accent); }
.legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.swatch { width: 14px; height: 14px; margin: 0 6px; border-radius: 50%; background: hsl(30, 42%, 52%); flex: none; }
.swatch.done { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--done); }
.swatch.open { outline: 2px dashed var(--accent); outline-offset: 2px; }
.swatch.locked { background: var(--surface-2); border: 1px dashed var(--muted); }
.line { width: 26px; height: 0; border-top: 2px solid; flex: none; }
.line.anc { border-color: var(--anc); }
.line.desc { border-top-style: dashed; border-color: var(--desc); }
.meta-list li { padding: 2px 0; color: var(--muted); font-size: 12px; }
.details a { color: var(--accent); }

@media (max-width: 760px) {
  .brand h1 { font-size: 15px; }
  .search { max-width: none; order: 3; flex-basis: 100%; }
  .controls { margin-left: 0; gap: 10px; }
  .details {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 55vh;
    border-left: 0; border-top: 1px solid var(--border);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.25); z-index: 10;
    border-radius: 12px 12px 0 0; padding: 14px 16px 24px;
  }
  .details.collapsed { display: none; }
  .details .close { display: inline-block; float: right; }
}

/* ---- tree switch, mod filter ---- */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 12px; font-weight: 550; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-selected="true"] { background: var(--accent); color: #fff; }
#modFilter {
  max-width: 180px; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
.count {
  display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; text-align: center;
}
.count[hidden] { display: none; }
.linkish { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; }

/* ---- recipe ways in the panel ---- */
.way { border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; margin: 8px 0; background: var(--bg); }
.way.ok { border-color: var(--done); }
.way-label { font-weight: 650; font-size: 13px; margin-bottom: 2px; }
.way-always { padding: 2px 0; }
.way .req-key:first-of-type { border-top: 0; }
.met { color: var(--done); }
.more summary { cursor: pointer; color: var(--muted); font-size: 12px; padding: 2px 0 2px 12px; }
.providers.flat { padding-left: 0 !important; border-left: 0 !important; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips code { background: var(--surface-2); border-radius: 4px; padding: 1px 6px; }

/* ---- mods drawer ---- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 30;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.25); overflow: auto; padding: 14px 18px 28px;
}
.drawer[hidden] { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer h2 { margin: 0; font-size: 18px; }
.drawer h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  margin: 20px 0 6px; font-weight: 650;
}
.drawer .sub { color: var(--muted); font-size: 12px; }
.status { margin-top: 10px; padding: 8px 10px; border-radius: 6px; background: var(--surface-2); font-size: 13px; }
.status.ok { background: var(--done-soft); }
.status.warn, .status.error { background: var(--accent-soft); }
.status code, .err code { font-size: 11px; word-break: break-word; }
.mod-list { list-style: none; margin: 0; padding: 0; }
.mod-list li { padding: 8px 0; border-top: 1px solid var(--border); }
.mod-list li:first-child { border-top: 0; }
.mod-list .empty { color: var(--muted); }
.mod-row { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.mod-row a { color: var(--text); text-decoration: none; }
.mod-row a:hover strong { color: var(--accent); text-decoration: underline; }
.err { margin-top: 4px; font-size: 12px; color: var(--accent); }
.cdb-form { display: flex; gap: 6px; }
.cdb-form input {
  flex: 1; padding: 6px 9px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit;
}
.drop {
  display: block; border: 2px dashed var(--border); border-radius: 8px; padding: 18px; text-align: center;
  color: var(--muted); cursor: pointer;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }
.spin {
  display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: -1px;
  border: 2px solid var(--muted); border-top-color: transparent; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 760px) {
  .seg { order: 2; }
  #modFilter { max-width: 130px; }
}

#cvd {
  max-width: 230px; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
@media (max-width: 760px) { #cvd { max-width: 150px; } }
