/* ===== Tree of Life Explorer — dark, cosmic, poster-inspired ===== */
:root {
  --bg: #18383a;
  --bg2: #21484a;
  --ink: #f1f3ee;
  --ink-dim: #b0beb9;
  --ink-faint: #718985;
  --line: rgba(196, 220, 210, 0.15);
  --panel-bg: rgba(13, 28, 30, 0.96);
  --card-bg: rgba(18, 39, 41, 0.99);
  --accent: #8ed9bf;
  --gold: #ffd68a;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --serif: "Arial Narrow", "Segoe UI", system-ui, sans-serif;
  --topbar-h: 52px;
  --crumb-h: 36px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font);
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; }

#starfield {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(255,255,255,0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.014) 1px, transparent 1px);
  background-size: 38px 38px;
}
#map {
  position: fixed; inset: 0; z-index: 1; width: 100vw; height: 100vh;
  touch-action: none; user-select: none; -webkit-user-select: none;
}

/* ---- SVG links ---- */
.link-halo {
  fill: none;
  stroke: var(--bg);
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.link { fill: none; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; filter: saturate(1.08); }
.link.ghost { stroke-dasharray: 3 7; }

/* ---- SVG nodes ---- */
.node { cursor: pointer; }
.node .cutout {
  fill: var(--bg);
  stroke: rgba(8, 24, 25, 0.92);
  stroke-width: 2px;
  pointer-events: none;
}
.node .disc { transition: fill 0.3s; }
.node .photo { opacity: 0; transition: opacity 0.45s ease; pointer-events: none; filter: saturate(1.08) contrast(1.04); }
.node .photo.loaded { opacity: 1; }
.node .ring { fill: none; transition: stroke-width 0.2s; }
.node .initial { text-anchor: middle; font-family: var(--serif); fill: rgba(255,255,255,0.82); pointer-events: none; }
.node .n-name {
  text-anchor: middle; fill: #f5f5ef; font-weight: 650; letter-spacing: 0;
  paint-order: stroke; stroke: rgba(3,6,12,0.72); stroke-width: 3px; pointer-events: none;
}
.node .n-common {
  text-anchor: middle; fill: var(--ink-dim); font-size: 11px; font-style: italic;
  paint-order: stroke; stroke: rgba(3,6,12,0.6); stroke-width: 2.4px; pointer-events: none;
}
.node .n-diverged {
  text-anchor: middle; fill: var(--gold); font-size: 10px; font-variant-numeric: tabular-nums;
  opacity: 0.9; paint-order: stroke; stroke: rgba(3,6,12,0.7); stroke-width: 2.6px; pointer-events: none;
}
.node .n-dagger { text-anchor: middle; fill: #ff9a9a; font-size: 14px; pointer-events: none; }
.node .n-badge-bg { opacity: 0.92; }
.node .n-badge { text-anchor: middle; fill: #0a1018; font-size: 10px; font-weight: 700; pointer-events: none; }

.node:hover .ring { filter: brightness(1.4); }
.node.has-photo .disc { fill: rgba(5, 9, 14, 0.96); }
.node.has-photo .ring { stroke-width: 2.8px; }
.node.is-focus .n-name { font-family: var(--serif); }
.node.is-tip .n-name { font-weight: 500; }
.node.is-selected .ring { filter: drop-shadow(0 0 7px currentColor); }
.node.is-extinct .disc { filter: grayscale(0.5) brightness(0.8); }
.node.is-extinct .n-name { fill: #c9b6b6; }
.node.is-ghost { cursor: pointer; }
.node.is-ghost .cutout { opacity: 0.65; }
.node.is-ghost .n-name { font-weight: 500; fill: #9dafaa; }
.node.is-visited .ring { stroke-dasharray: none; }
.node.is-bud .disc { stroke: currentColor; }
.node.is-bud .initial { font-family: var(--font); font-weight: 600; }

/* ---- top bar ---- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 20;
  display: flex; align-items: center; gap: 14px; padding: 0 14px;
  background: rgba(14, 34, 36, 0.93);
  border-bottom: 1px solid rgba(210, 226, 217, 0.12);
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
#brand { display: flex; align-items: baseline; gap: 10px; flex-shrink: 0; }
#brand h1 {
  font-family: var(--serif); font-size: 22px; font-weight: 800; letter-spacing: 0;
  color: #f4f2e9; white-space: nowrap; text-transform: uppercase;
}
#progress-counter { font-size: 11px; color: var(--ink-faint); white-space: nowrap; }
#searchbox { position: relative; flex: 1; max-width: 340px; }
#search {
  width: 100%; padding: 7px 12px; background: rgba(18, 26, 42, 0.82);
  border: 1px solid rgba(120, 150, 200, 0.22); border-radius: 17px;
  color: var(--ink); font-size: 13px; outline: none; transition: border-color 0.2s, background 0.2s;
}
#search:focus { border-color: rgba(130, 200, 175, 0.55); background: rgba(20, 30, 50, 0.95); }
#search::placeholder { color: var(--ink-faint); }
#search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--card-bg);
  border: 1px solid rgba(120, 150, 200, 0.25); border-radius: 10px; overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6); max-height: 62vh; overflow-y: auto;
}
.search-item { display: flex; align-items: baseline; gap: 9px; padding: 8px 12px; cursor: pointer; font-size: 13px; }
.search-item .si-cat { font-size: 9px; padding: 1px 6px; border-radius: 8px; flex-shrink: 0; text-transform: uppercase; font-weight: 700; color: #08101c; letter-spacing: 0.04em; }
.search-item .si-name { color: var(--ink); }
.search-item .si-sci { margin-left: auto; color: var(--ink-faint); font-size: 11px; font-style: italic; white-space: nowrap; }
.search-item:hover, .search-item.active { background: rgba(90, 160, 140, 0.16); }

#topbar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-shrink: 0; }
.tool {
  padding: 7px 12px; background: rgba(18, 26, 42, 0.82); border: 1px solid rgba(120, 150, 200, 0.22);
  border-radius: 15px; color: var(--ink-dim); font-size: 12.5px; white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.tool:hover { color: #fff; border-color: rgba(130, 200, 175, 0.5); }
#about-btn { width: 32px; padding: 7px 0; text-align: center; }

/* ---- breadcrumb ---- */
#breadcrumb {
  position: fixed; top: var(--topbar-h); left: 0; right: 0; height: var(--crumb-h); z-index: 18;
  display: flex; align-items: center; gap: 2px; padding: 0 14px; overflow-x: auto; overflow-y: hidden;
  white-space: nowrap; scrollbar-width: none;
  background: linear-gradient(to bottom, rgba(6,10,16,0.7), transparent);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 24px, #000 calc(100% - 24px), transparent);
}
#breadcrumb::-webkit-scrollbar { display: none; }
.crumb {
  --cc: #9fb0c9; flex-shrink: 0; padding: 3px 9px; border-radius: 12px; font-size: 12px;
  color: var(--ink-dim); background: transparent; border: 1px solid transparent; transition: all 0.15s;
}
.crumb::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--cc); margin-right: 6px; vertical-align: middle; opacity: 0.85; }
.crumb:hover { color: #fff; background: rgba(255,255,255,0.05); }
.crumb.current { color: #fff; background: color-mix(in srgb, var(--cc) 16%, transparent); border-color: color-mix(in srgb, var(--cc) 42%, transparent); }
.crumb.lit { box-shadow: 0 0 10px color-mix(in srgb, var(--cc) 45%, transparent); }
.crumb-sep { color: var(--ink-faint); font-size: 12px; flex-shrink: 0; }

/* ---- rank legend ---- */
#legend {
  position: fixed; left: 14px; bottom: 12px; z-index: 12; display: flex; flex-direction: column;
  gap: 3px; padding: 10px 12px; background: rgba(10, 16, 26, 0.6); border: 1px solid var(--line);
  border-radius: 10px; pointer-events: none; backdrop-filter: blur(4px);
}
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 10.5px; color: var(--ink-dim); }
.legend-dot { border-radius: 50%; background: rgba(160, 180, 220, 0.7); flex-shrink: 0; }

/* ---- panel ---- */
#panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(412px, 92vw); z-index: 30;
  background: var(--panel-bg); backdrop-filter: blur(14px); border-left: 1px solid rgba(120, 150, 200, 0.2);
  transform: translateX(105%); transition: transform 0.34s cubic-bezier(0.22, 0.9, 0.3, 1);
  display: flex; flex-direction: column;
}
#panel.open { transform: translateX(0); }
#panel-close {
  position: absolute; top: 10px; right: 12px; z-index: 2; width: 30px; height: 30px; border-radius: 50%;
  background: rgba(9, 12, 24, 0.72); border: 1px solid rgba(120,150,200,0.25); color: var(--ink-dim); font-size: 17px;
}
#panel-close:hover { color: #fff; }
#panel-scroll { overflow-y: auto; padding: 0 0 24px; height: 100%; }
#panel-image { width: 100%; height: 210px; background-size: cover; background-position: center 30%; position: relative; touch-action: pan-y; transition: background-image 0.15s; }
#panel-image::after { content: ""; position: absolute; inset: 0; z-index: 0; background: linear-gradient(to bottom, transparent 45%, var(--panel-bg)); pointer-events: none; }
.img-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; width: 32px; height: 32px; border-radius: 50%; background: rgba(7, 9, 20, 0.62); border: 1px solid rgba(150, 165, 215, 0.3); color: #dde4f5; font-size: 19px; line-height: 1; opacity: 0.65; transition: opacity 0.15s, background 0.15s; }
.img-nav:hover { opacity: 1; background: rgba(7, 9, 20, 0.85); }
#img-prev { left: 10px; } #img-next { right: 10px; }
#img-count { position: absolute; left: 12px; bottom: 12px; z-index: 2; font-size: 10.5px; color: #dde4f5; font-variant-numeric: tabular-nums; background: rgba(7, 9, 20, 0.62); border-radius: 9px; padding: 2px 8px; }
#panel-head { padding: 18px 22px 0; }
#panel-rank { display: inline-block; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; padding: 2px 9px; border-radius: 9px; border: 1px solid currentColor; color: var(--accent); }
#panel-title { font-family: var(--serif); font-size: 25px; font-weight: 500; margin: 11px 0 2px; line-height: 1.15; }
#panel-common { color: var(--ink); font-size: 14px; font-style: italic; margin-bottom: 3px; }
#panel-domain { color: var(--ink-dim); font-size: 12px; letter-spacing: 0.04em; margin-top: 3px; }
#panel-date { color: var(--gold); font-size: 12.5px; font-variant-numeric: tabular-nums; margin-top: 5px; }
#panel-species { color: #9ec9bc; font-size: 11.5px; line-height: 1.4; margin-top: 5px; }
#panel-blurb { padding: 14px 22px 4px; font-size: 14.5px; line-height: 1.62; color: #d6dcee; }
#panel-actions { display: flex; flex-wrap: wrap; gap: 7px; padding: 10px 22px 2px; }
.panel-action {
  padding: 6px 12px; font-size: 12.5px; background: rgba(90, 160, 140, 0.14);
  border: 1px solid rgba(120, 200, 175, 0.34); border-radius: 13px; color: #bfe8d8; transition: all 0.15s;
}
.panel-action:hover { background: rgba(90, 170, 145, 0.28); color: #fff; }
#panel-related-wrap { padding: 16px 22px 0; }
#panel-related-wrap h3 { font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 9px; font-weight: 600; }
#panel-related { display: flex; flex-wrap: wrap; gap: 7px; }
.related-chip { padding: 5px 11px; font-size: 12.5px; background: rgba(30, 42, 66, 0.5); border: 1px solid rgba(120, 150, 235, 0.3); border-radius: 14px; color: #bcd0f7; transition: all 0.15s; }
.related-chip:hover { background: rgba(60, 80, 120, 0.5); color: #fff; filter: brightness(1.2); }
#panel-wiki { display: inline-block; margin: 18px 22px 0; color: var(--accent); font-size: 13px; text-decoration: none; border-bottom: 1px solid rgba(127, 191, 176, 0.35); padding-bottom: 1px; }
#panel-wiki:hover { border-bottom-color: var(--accent); }

/* ---- tours ---- */
#tour-menu { position: fixed; inset: 0; z-index: 50; background: rgba(3, 5, 10, 0.62); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; }
#tour-menu-card { width: min(500px, 92vw); max-height: 84vh; overflow-y: auto; background: var(--card-bg); border: 1px solid rgba(120, 150, 200, 0.28); border-radius: 14px; padding: 22px; box-shadow: 0 24px 80px rgba(0,0,0,0.7); }
#tour-menu-card h2 { font-family: var(--serif); font-weight: 500; margin-bottom: 14px; }
.tour-option { display: block; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 8px; background: rgba(90, 150, 135, 0.09); border: 1px solid rgba(120, 200, 175, 0.22); border-radius: 10px; color: var(--ink); transition: all 0.15s; }
.tour-option:hover { background: rgba(90, 160, 140, 0.2); }
.tour-option b { display: block; font-size: 14.5px; margin-bottom: 3px; }
.tour-option span { display: block; font-size: 12.5px; color: var(--ink-dim); }
.tour-option .tour-stops { font-size: 11px; color: var(--ink-faint); margin-top: 3px; }
#tour-menu-close { margin-top: 6px; padding: 7px 16px; background: none; border: 1px solid rgba(120,150,200,0.3); border-radius: 14px; color: var(--ink-dim); }
#tour-hud { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 35; width: min(560px, 92vw); background: var(--card-bg); border: 1px solid rgba(130, 200, 175, 0.35); border-radius: 14px; padding: 14px 18px 12px; box-shadow: 0 12px 50px rgba(40, 120, 100, 0.2), 0 12px 50px rgba(0,0,0,0.5); }
#tour-note { font-size: 13.5px; line-height: 1.5; color: #d6ecdf; margin-bottom: 10px; }
#tour-controls { display: flex; align-items: center; gap: 10px; }
#tour-controls button { padding: 6px 14px; background: rgba(90, 160, 140, 0.16); border: 1px solid rgba(120, 200, 175, 0.35); border-radius: 13px; color: #cdeede; font-size: 12.5px; }
#tour-controls button:hover:not(:disabled) { background: rgba(90, 170, 145, 0.3); color: #fff; }
#tour-controls button:disabled { opacity: 0.35; cursor: default; }
#tour-progress { font-size: 12px; color: var(--ink-dim); margin: 0 auto; }
#tour-exit { margin-left: auto; }

/* ---- toast ---- */
#toast { position: fixed; top: calc(var(--topbar-h) + var(--crumb-h) + 8px); left: 50%; transform: translateX(-50%); z-index: 45; display: flex; align-items: flex-start; gap: 10px; max-width: min(560px, 92vw); background: var(--card-bg); border: 1px solid rgba(130, 200, 175, 0.32); border-radius: 12px; padding: 11px 16px; font-size: 13px; line-height: 1.5; color: #dceee6; box-shadow: 0 10px 40px rgba(0,0,0,0.55); animation: toast-in 0.5s cubic-bezier(0.22, 0.9, 0.3, 1); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -12px); } }
#toast button { background: none; border: none; color: var(--ink-dim); font-size: 16px; flex-shrink: 0; }
#toast-text b { color: #9fe6cc; }

/* ---- about ---- */
#about { position: fixed; inset: 0; z-index: 50; background: rgba(3, 4, 10, 0.66); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; }
#about-card { width: min(600px, 92vw); max-height: 86vh; overflow-y: auto; background: var(--card-bg); border: 1px solid rgba(120, 150, 200, 0.28); border-radius: 14px; padding: 26px; }
#about-card h2 { font-family: var(--serif); font-weight: 500; margin-bottom: 14px; }
#about-card p { font-size: 13.5px; line-height: 1.66; color: #cfd6ea; margin-bottom: 12px; }
#about-card kbd { background: rgba(120, 150, 200, 0.18); border: 1px solid rgba(120,150,200,0.3); border-radius: 4px; padding: 0 5px; font-size: 12px; font-family: inherit; }
.about-fine { font-size: 12px !important; color: var(--ink-faint) !important; }
#about-close { padding: 7px 18px; background: rgba(90, 160, 140, 0.16); border: 1px solid rgba(120, 200, 175, 0.35); border-radius: 14px; color: #cdeede; }

/* ---- intro hint ---- */
#intro-hint { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 15; font-size: 12.5px; color: var(--ink-dim); background: rgba(10, 16, 26, 0.82); padding: 8px 18px; border-radius: 16px; border: 1px solid var(--line); pointer-events: none; transition: opacity 1s; }
#intro-hint.fade { opacity: 0; }

/* ---- mobile ---- */
@media (max-width: 720px) {
  :root { --topbar-h: 90px; }
  #topbar { flex-wrap: wrap; padding: 6px 10px; gap: 8px; height: var(--topbar-h); }
  #brand h1 { font-size: 17px; }
  #progress-counter { display: none; }
  #searchbox { order: 3; flex-basis: 100%; max-width: none; }
  .tool { padding: 6px 9px; font-size: 12px; }
  #legend { display: none; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 62vh; height: auto; border-left: none; border-top: 1px solid rgba(120, 150, 200, 0.25); border-radius: 16px 16px 0 0; transform: translateY(110%); }
  #panel.open { transform: translateY(0); }
  #panel-image { height: 150px; }
  #tour-hud { width: 94vw; bottom: 10px; }
}
