/* Theme tokens. The pre-paint script in index.html always stamps
   data-theme="light"|"dark" on <html> (resolving the "auto" mode itself via
   matchMedia), so CSS only needs one dark override block — no duplicated
   prefers-color-scheme media query. No-JS fallback is the light theme.

   Node-class colors: light values mirror STYLE in build.py so the static SVG
   and the viewer agree. Dark values are re-stepped per class in OKLCH (hue
   kept, fill L 0.48-0.58, label >= 4.5:1 WCAG on its fill) and validated for
   CVD/normal-vision adjacent-pair separation against the dark canvas —
   strictly wider separation than the light palette's own worst pairs. Two
   deliberate deviations: raw stays near-neutral gray (mirrors #dddddd), and
   dark gold (consumable/raked) sits at the sRGB chroma gamut ceiling. */
:root {
  color-scheme: light;

  --canvas-bg: #fafafa;
  --panel-bg: #fff;
  --surface-2: #f6f6f6;
  --text: #1a1a1a;
  --muted: #666;
  --faint: #808080;
  --border: #ddd;
  --control-border: #bbb;
  --hover: #eef2ff;
  --link: #1d4ed8;
  --danger: #a00;
  --select: #d40000;
  --swatch-border: #0003;
  --overlay-shadow: #0004;

  --node-stroke: #666;
  --node-sub: #444;
  --edge: #999;
  --edge-back: #555; /* darker: dots read lighter than a solid line */
  --edge-label: #555;
  --junction: #333;

  --node-arrow-bg: #e8a33d;        --node-arrow-fg: #5c3800;
  --node-spell-bg: #7ecdc3;        --node-spell-fg: #0b4a40;
  --node-potion-bg: #c3a8e0;       --node-potion-fg: #3d1a66;
  --node-food-bg: #9ccb7d;         --node-food-fg: #1e4d12;
  --node-consumable-bg: #dccb92;   --node-consumable-fg: #5c4a12;
  --node-inter-bg: #a5c8dc;        --node-inter-fg: #12384d;
  --node-animal-bg: #dd94b6;       --node-animal-fg: #42102b;
  --node-raw-bg: #dddddd;          --node-raw-fg: #444444;
  --node-raw_farmable-bg: #f2c4a0; --node-raw_farmable-fg: #5c2e0d;
  --node-raw_ranched-bg: #edb8c8;  --node-raw_ranched-fg: #5c1a33;
  --node-raw_raked-bg: #c7a17a;    --node-raw_raked-fg: #42280a;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --canvas-bg: #1b1c1f;
  --panel-bg: #212227;
  --surface-2: #2a2c31;
  --text: #e4e5e9;
  --muted: #a2a4ad;
  --faint: #8b8d96;
  --border: #37393f;
  --control-border: #4a4d55;
  --hover: #2c3040;
  --link: #8ab4f8;
  --danger: #ff8585;
  --select: #ff5c5c;
  --swatch-border: #ffffff40;
  --overlay-shadow: #000c;

  --node-stroke: #878b94;
  --node-sub: #fff;
  --edge: #71747c;
  --edge-back: #b0b3bc; /* lighter on dark bg = same contrast boost */
  --edge-label: #9fa2ab;
  --junction: #b8bbc3;

  --node-arrow-bg: #9a6504;        --node-arrow-fg: #fff7ee;
  --node-spell-bg: #02836d;        --node-spell-fg: #eefff9;
  --node-potion-bg: #7b53a1;       --node-potion-fg: #eedfff;
  --node-food-bg: #4b7728;         --node-food-fg: #e3f6d7;
  --node-consumable-bg: #7a5900;   --node-consumable-fg: #e9d9ba;
  --node-inter-bg: #0a729b;        --node-inter-fg: #d9f1ff;
  --node-animal-bg: #7d3f9d;       --node-animal-fg: #e0ceec;
  --node-raw-bg: #657383;          --node-raw-fg: #f7fafe;
  --node-raw_farmable-bg: #96512c; --node-raw_farmable-fg: #fddbca;
  --node-raw_ranched-bg: #ac5a71;  --node-raw_ranched-fg: #fff8fa;
  --node-raw_raked-bg: #7d5500;    --node-raw_raked-fg: #ead6b9;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, "Helvetica Neue", Arial, sans-serif; }
body { color: var(--text); background: var(--canvas-bg); }

#graph {
  position: fixed; right: 0; top: 0;
  width: calc(100% - 340px); height: 100%;
  background: var(--canvas-bg); cursor: grab;
}
#graph:active { cursor: grabbing; }

#loading {
  position: fixed; left: calc(50% + 170px); top: 45%; transform: translate(-50%, -50%);
  font-size: 15px; color: var(--muted); background: var(--panel-bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 14px 20px; max-width: 28em;
}

#panel {
  position: fixed; left: 0; top: 0; width: 340px; height: 100%;
  overflow-y: auto; background: var(--panel-bg); border-right: 1px solid var(--border);
  padding: 12px 14px; font-size: 13px;
  display: flex; flex-direction: column;
}
#panel > :not(#detail) { flex: none; }
#titlebar { display: flex; align-items: flex-start; gap: 8px; }
#titlebar h1 { flex: 1; }
#panel h1 { font-size: 16px; margin: 0 0 10px; }
#panel h2 { font-size: 13px; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.note { color: var(--faint); font-size: 11px; line-height: 1.4; }

#theme-toggle {
  flex: none; width: 28px; height: 28px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--control-border); border-radius: 6px;
  background: none; color: var(--muted); cursor: pointer;
}
#theme-toggle:hover { background: var(--hover); color: var(--text); }
#theme-toggle svg { width: 16px; height: 16px; }

/* search */
#searchbox { position: relative; }
#search {
  width: 100%; padding: 6px 8px; font-size: 13px; border: 1px solid var(--control-border);
  border-radius: 4px; background: var(--panel-bg); color: var(--text);
}
#search-results {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 10;
  background: var(--panel-bg); border: 1px solid var(--control-border); border-top: none;
  max-height: 320px; overflow-y: auto;
}
#search-results:empty { display: none; }
.result { padding: 5px 8px; cursor: pointer; display: flex; align-items: center; gap: 6px; }
.result.active, .result:hover { background: var(--hover); }
.result-more { padding: 5px 8px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--border); }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid var(--swatch-border); flex: none; }

#clear { margin: 8px 0 4px; padding: 4px 10px; font-size: 12px; cursor: pointer; }

/* detail cards. #detail is the selected node's card: it fills the leftover
   panel height in flow, and collapses entirely when hidden so the sections
   below move back up on clear. #detail-hover is the hover-preview card: it
   always floats over the panel (never takes flow space), so mouseover can't
   reflow anything. */
#detail, #detail-hover {
  border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px;
  background: var(--panel-bg); overflow-y: auto;
}
#detail { margin-top: 10px; flex: 1 1 auto; min-height: 200px; }
#detail-hover {
  position: absolute; left: 14px; right: 14px; z-index: 20;
  max-height: 60vh; box-shadow: 0 4px 16px var(--overlay-shadow);
}
:is(#detail, #detail-hover) h2 { margin: 0 0 6px; font-size: 15px; text-transform: none; letter-spacing: 0; color: var(--text); }
:is(#detail, #detail-hover) h2 img.icon { width: 64px; height: 64px; vertical-align: middle; margin-right: 8px; }
.chip {
  display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 9px;
  border: 1px solid var(--swatch-border); margin: 0 4px 8px 0;
}
/* Wiki-catalog subcategory chip: a real button (it selects the subcategory's
   members) kept visually neutral — subcategories have no color of their own. */
.subchip {
  font: inherit; font-size: 11px; cursor: pointer;
  background: var(--surface-2); color: var(--muted);
}
.subchip:hover, .subchip:focus-visible { background: var(--hover); color: var(--text); }
:is(#detail, #detail-hover) table { border-collapse: collapse; margin: 4px 0; }
:is(#detail, #detail-hover) td { padding: 1px 8px 1px 0; vertical-align: top; }
:is(#detail, #detail-hover) td:first-child { color: var(--muted); white-space: nowrap; }
:is(#detail, #detail-hover) ul { margin: 4px 0; padding-left: 18px; }
.recipe { margin: 6px 0; padding: 6px 8px; background: var(--surface-2); border-radius: 4px; }
.recipe .station { color: var(--muted); font-size: 12px; }
.ingredient-link { border: none; background: none; padding: 0; color: var(--link); cursor: pointer; font-size: 13px; text-decoration: underline; }
.addgroup { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.addgroup select, .addgroup input { font-size: 12px; padding: 3px; max-width: 150px; }

/* groups */
#groups { list-style: none; margin: 0; padding: 0; }
#groups > li { margin: 4px 0; }
.group-row { display: flex; align-items: center; gap: 6px; }
.group-head {
  flex: 1; text-align: left; padding: 4px 8px; cursor: pointer; border: 1px solid var(--control-border);
  border-radius: 4px; background: var(--surface-2); color: var(--text); font-size: 13px;
}
.group-head:hover { background: var(--hover); }
.group-del { border: none; background: none; color: var(--danger); cursor: pointer; font-size: 11px; }
#groups details { margin: 2px 0 2px 8px; }
#groups summary { cursor: pointer; color: var(--muted); font-size: 11px; }
#groups details ul { list-style: none; margin: 2px 0; padding-left: 10px; }
#groups details li { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
#groups .gone { color: var(--faint); text-decoration: line-through; }
.member-del { border: none; background: none; color: var(--danger); cursor: pointer; padding: 0 3px; }

/* legend */
#legend ul { list-style: none; margin: 0; padding: 0; }
#legend li { display: flex; align-items: center; gap: 7px; padding: 2px 0; cursor: pointer; }
#legend li:hover, #legend li:focus-visible { background: var(--hover); }
.swatch { width: 16px; height: 12px; border-radius: 3px; border: 1px solid var(--swatch-border); flex: none; }
#subcategories { margin: 6px 0 2px; }
#subcategories summary { cursor: pointer; color: var(--muted); font-size: 11px; }
#subcategories ul { margin: 2px 0; padding-left: 10px; }
.subcat-count { color: var(--faint); font-size: 11px; }

#meta { margin-top: 14px; color: var(--faint); font-size: 11px; line-height: 1.4; }
#meta p { margin: 0 0 6px; }
#meta .copyright { border-top: 1px solid var(--border); padding-top: 8px; }
#meta a { color: var(--muted); }

/* graph elements */
.node { cursor: pointer; }
.node rect { stroke: var(--node-stroke); stroke-width: 1; }
.node.selected rect { stroke: var(--select); stroke-width: 3; }
.node text { pointer-events: none; }
.node text.name { font: 600 12px system-ui, Arial, sans-serif; text-anchor: middle; }
.node text.sub { font: 10px system-ui, Arial, sans-serif; text-anchor: middle; fill: var(--node-sub); }
.node circle { fill: var(--junction); }
.node text.jlabel { font: 9px system-ui, Arial, sans-serif; fill: var(--edge-label); }
.edge { fill: none; stroke: var(--edge); stroke-width: 1; }
.edge.junction-out { stroke-dasharray: 4 3; }
/* Slaughter drops are bonus yields, not live-collect production. */
.edge.slaughtered { stroke-dasharray: 4 3; }
/* Thicker + darker stroke compensates dots reading fainter than solid lines;
   the #arrow-back marker is pre-shrunk so the arrowhead stays the same size,
   and its fill stays var(--edge) so the arrowhead is untouched. */
.edge.backward { stroke-dasharray: 0 3.5; stroke-linecap: round; stroke-width: 1.4; stroke: var(--edge-back); }
.edge.bold { stroke: var(--select); stroke-width: 1.8; }
#arrow path, #arrow-back path { fill: var(--edge); }
#arrow-bold path { fill: var(--select); }
/* Hidden-edge stubs: same stroke width as .edge so the shared arrowhead
   marker renders at the same size; the fade gradient picks up the theme's
   edge color here. */
.cue line.cue-stub { stroke-width: 1; }
#stub-fade stop { stop-color: var(--edge); }
.edge-label { font: 9px system-ui, Arial, sans-serif; fill: var(--edge-label); paint-order: stroke; stroke: var(--canvas-bg); stroke-width: 3; }
