/* Humanity Knowledge Project. Mobile-first, uncluttered. */
:root{
  color-scheme:dark;
  --bg:#0b0f1a; --bg2:#0e1424; --bg-glow:#12203b;
  --ink:#eaf0ff; --muted:#9fb0d0; --faint:#6b7ba0;
  --accent:#6ea8fe; --accent2:#7ee7c7;
  --card:#141b2e; --card-brd:#243149;
  --chip-bg:rgba(17,24,42,.88); --chip-ink:#c9d5ef;
  --chip-from-bg:rgba(20,32,42,.88);
  --chip-shadow:0 4px 14px rgba(0,0,0,.35);
  --center-bg1:#19223a; --center-bg2:#101627;
  --center-brd:rgba(110,168,254,.24);
  --card-shadow:0 18px 50px rgba(0,0,0,.5);
  --btn-bg:rgba(20,27,46,.6);
  --grip:#33405d;
  --line:rgba(255,255,255,.06);
  --scrim:rgba(4,7,14,.55);
  --shadow:0 10px 40px rgba(0,0,0,.45);
  --safe-t:env(safe-area-inset-top,0px);
  --safe-b:env(safe-area-inset-bottom,0px);
}
:root[data-theme="light"]{
  color-scheme:light;
  --bg:#f3f6fc; --bg2:#e9eff9; --bg-glow:#dde8fa;
  --ink:#1a2540; --muted:#4d5e80; --faint:#8592ad;
  --accent:#2f6fe4; --accent2:#0c9573;
  --card:#ffffff; --card-brd:#d3dcec;
  --chip-bg:rgba(255,255,255,.92); --chip-ink:#33445f;
  --chip-from-bg:rgba(230,247,240,.95);
  --chip-shadow:0 4px 14px rgba(40,60,100,.14);
  --center-bg1:#ffffff; --center-bg2:#f1f5fc;
  --center-brd:rgba(47,111,228,.28);
  --card-shadow:0 18px 50px rgba(40,60,100,.18);
  --btn-bg:rgba(255,255,255,.75);
  --grip:#c2cdde;
  --line:rgba(20,35,60,.08);
  --scrim:rgba(28,38,58,.35);
  --shadow:0 10px 40px rgba(40,60,100,.16);
}
[data-theme="light"] #edges path.edge{stroke:url(#edgeGradLight)}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{height:100%;margin:0}
body{
  background:radial-gradient(1200px 800px at 50% 12%, var(--bg-glow) 0%, var(--bg) 60%) fixed;
  color:var(--ink);
  font:15px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  overflow:hidden; overscroll-behavior:none; touch-action:none;
  -webkit-font-smoothing:antialiased;
}
/* ---- ?fs scroll experiment (off by default; see index.html) ----
   Everything visible is pinned via #stage{position:fixed}, so making the
   document a few px taller than the viewport doesn't move any content — it
   only gives a real swipe somewhere to go, in case that's what makes an
   in-app browser's chrome collapse. Scoped entirely under .fs-scroll. */
html.fs-scroll,html.fs-scroll body{height:calc(100% + 32px)}
html.fs-scroll body{overflow-y:auto; overscroll-behavior-y:auto; touch-action:pan-y}
button{font:inherit;color:inherit;border:0;background:none;cursor:pointer}

/* ---- stage / graph ---- */
#stage{position:fixed;inset:0;overflow:hidden}
#edges{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}
#edges path.edge{fill:none;stroke:url(#edgeGrad);stroke-linecap:round}
#nodes{position:absolute;inset:0;pointer-events:none}

.node{
  position:absolute;top:0;left:0;pointer-events:auto;
  transform:translate(-50%,-50%);
  will-change:transform,opacity; user-select:none;
}
/* neighbour = small chip; its background is what keeps edge lines from
   running through the text (edges are drawn in a layer underneath) */
.node.neighbor{
  max-width:120px;padding:7px 11px 8px;text-align:center;cursor:pointer;
  background:var(--chip-bg);border:1px solid var(--card-brd);border-radius:12px;
  box-shadow:var(--chip-shadow);
  transition:border-color .15s ease;
}
.node.neighbor .lbl{
  font-size:12px;color:var(--chip-ink);line-height:1.25;font-weight:500;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
}
.node.neighbor .rel{font-size:10px;color:var(--faint);letter-spacing:.02em;margin-top:2px;
  display:-webkit-box;-webkit-line-clamp:1;-webkit-box-orient:vertical;overflow:hidden}
.node.neighbor:active{border-color:var(--accent)}
@media (hover:hover){ .node.neighbor:hover{border-color:rgba(110,168,254,.55)} .node.neighbor:hover .lbl{color:var(--ink)} }

/* the idea we just travelled from: visible, but quiet */
.node.neighbor.from{border-color:rgba(126,231,199,.38);background:var(--chip-from-bg)}
.node.neighbor.from .back{width:11px;height:11px;stroke:var(--accent2);stroke-width:2.2;fill:none;stroke-linecap:round;stroke-linejoin:round;margin-right:4px;vertical-align:-1px}

/* centre = the current idea: a real card, so edges never cross its text */
.node.center{
  width:min(76vw,340px);padding:16px 18px 15px;text-align:center;cursor:pointer;
  background:linear-gradient(180deg, var(--center-bg1), var(--center-bg2));
  border:1px solid var(--center-brd);border-radius:20px;
  box-shadow:var(--card-shadow), 0 0 0 5px rgba(110,168,254,.05);
}
.node.center h1{
  margin:0 0 6px;font-size:20px;line-height:1.15;font-weight:700;letter-spacing:-.01em;
}
.node.center p{
  margin:0 auto;max-width:300px;color:var(--muted);font-size:12.5px;line-height:1.45;
  overflow-wrap:break-word;
}
.node.center .more{
  display:inline;margin:0;padding:0;
  color:var(--accent2);font-size:12.5px;font-weight:600;cursor:pointer;white-space:nowrap;
}
@media (hover:hover){ .node.center .more:hover{text-decoration:underline} }

/* ---- node icon (default-on; ?img=0 opts out) ----
   Floats to the LEFT of the centre card, mostly outside its disc, barely
   overlapping it. It's an absolutely-positioned CHILD of .node.center (which is
   itself `position:absolute` — see .node above — so it's already a valid
   containing block), sized purely from the card's OWN box: top:0/bottom:0
   stretches its height to match the card's rendered height exactly, and
   aspect-ratio:1/1 derives its width from that (icons are square 1024px PNGs,
   so no crop/distort). Because it's a child of the card, every transform the
   JS applies to the card (pan, scale, idle bob) carries the icon along for
   free — no separate viewport-relative position is ever computed for it, and
   it never shifts mid-transition or on a resize/relayout.
   layoutFor() in app.js widens the centre's keep-out box on the card's LEFT
   side to match (see `cardHW`) so a ring chip can never land under it. */
.node.center .cicon{
  position:absolute;top:0;bottom:0;left:0;
  aspect-ratio:1/1;width:auto;max-width:34vw;
  transform:translateX(-84%);
  /* tappable: as a child of the card, a tap bubbles to the card's onclick (go deeper) */
  pointer-events:auto;cursor:pointer;
  filter:drop-shadow(0 10px 22px rgba(0,0,0,.45));
}
[data-theme="light"] .node.center .cicon{filter:drop-shadow(0 8px 18px rgba(40,60,100,.25))}
.node.center .cicon img{display:block;width:100%;height:100%;object-fit:contain;-webkit-touch-callout:none}

/* ---- ?img=3d prototype: an animated scene banner across the TOP of the card
   (old, untouched design) instead of the floating icon above. Fixed-height
   slot so the canvas can never shift layout mid-transition. ---- */
.node.center .cimg{
  display:block;width:calc(100% + 36px);height:104px;margin:-16px -18px 12px;
  object-fit:cover;border-radius:19px 19px 0 0;
  border-bottom:1px solid var(--center-brd);
  pointer-events:none;
}
/* legacy ?img=3d prototype: a small circular canvas inside the chip (untouched)
   instead of the floating badge below. */
.node.neighbor .nimg{
  display:block;width:30px;height:30px;margin:1px auto 5px;
  object-fit:cover;border-radius:50%;
  border:1px solid var(--card-brd);
  pointer-events:none;
}
/* ---- neighbour icon (default view) ----
   Floats to the LEFT of the chip, mirroring .node.center .cicon above: mostly
   outside the chip with a slight overlap, sized to the chip's own height. Same
   containing-block trick — an absolutely positioned child of `.node.neighbor`
   (already `position:absolute` via the shared `.node` rule above), top:0/bottom:0
   matching the chip's rendered height, aspect-ratio:1/1 for width. Unlike the
   centre card (always at a fixed spot, scale 1), every chip sits at its own ring
   position and steady-state scale (up to ~1.16x for a strongly-weighted edge), so
   sizeNeighborIcon() in app.js — called once per chip, right after this markup is
   painted — clamps each one individually against the viewport's left edge rather
   than relying on a single shared measurement like the centre gets away with. */
.node.neighbor .nicon{
  position:absolute;top:0;bottom:0;left:0;
  aspect-ratio:1/1;width:auto;max-width:22vw;
  transform:translateX(-84%);
  /* tappable: bubbles to the chip's onclick (navigate to this neighbour) */
  pointer-events:auto;cursor:pointer;
  filter:drop-shadow(0 3px 9px rgba(0,0,0,.4));
}
[data-theme="light"] .node.neighbor .nicon{filter:drop-shadow(0 2px 7px rgba(40,60,100,.22))}
.node.neighbor .nicon img{display:block;width:100%;height:100%;object-fit:contain;-webkit-touch-callout:none}

/* ---- topbar ---- */
#topbar{
  position:fixed;top:calc(var(--safe-t) + 10px);left:12px;right:12px;
  display:flex;gap:10px;align-items:center;z-index:30;pointer-events:none;
}
#topbar .spacer{flex:1}
.iconbtn{
  pointer-events:auto;cursor:pointer;width:42px;height:42px;border-radius:50%;
  display:grid;place-items:center;
  background:var(--btn-bg);border:1px solid var(--card-brd);
  backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);
  transition:transform .12s ease, background .2s ease;
}
.iconbtn:active{transform:scale(.92)}
.iconbtn.pill{
  width:auto;height:42px;border-radius:21px;padding:0 15px;
  font-size:12.5px;font-weight:600;letter-spacing:.02em;white-space:nowrap;color:var(--ink);
}
#themeBtn .moon{display:none}
[data-theme="light"] #themeBtn .sun{display:none}
[data-theme="light"] #themeBtn .moon{display:block}
.iconbtn svg{width:20px;height:20px;stroke:var(--ink);stroke-width:2;fill:none;stroke-linecap:round;stroke-linejoin:round}
.iconbtn.fab{position:fixed;right:calc(env(safe-area-inset-right,0px) + 14px);bottom:calc(var(--safe-b) + 16px);z-index:35}
#toast{position:fixed;left:50%;bottom:calc(var(--safe-b) + 74px);transform:translateX(-50%);z-index:80;
  background:var(--card);border:1px solid var(--card-brd);color:var(--ink);
  font-size:13px;padding:8px 14px;border-radius:999px;box-shadow:var(--shadow);
  opacity:0;transition:opacity .2s ease;pointer-events:none;white-space:nowrap}
#toast[hidden]{display:none}
#toast.show{opacity:1}

/* ---- in-app browser escape pill ----
   Nowhere on this screen is fully free: the topbar's own row can't fit a
   text pill (the left gap before the "Knowledge Map" button is only ~60px,
   and the icon cluster packs the right side edge to edge), the bottom-left
   corner belongs to the connection rotator (shown on most nodes with more
   than a handful of links), and the neighbour ring itself is only clamped
   by CENTRE, not edge, so a tall chip can reach close to either bound.
   Sitting just under the topbar, pinned left and kept narrow, clears every
   fixed control and the ring on ordinary nodes; on a hub node with a lot of
   neighbours (e.g. "physics") a top chip's corner can still tuck a few px
   under it, which is cosmetic (the pill paints on top; the chip stays
   tappable everywhere else) rather than a functional collision. */
.inapp-pill{
  position:fixed;top:calc(var(--safe-t) + 54px);left:12px;
  z-index:32;display:inline-flex;align-items:stretch;gap:1px;
  border-radius:999px;overflow:hidden;box-shadow:var(--chip-shadow);
  background:var(--btn-bg);border:1px solid var(--card-brd);
  backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);
}
.inapp-pill[hidden]{display:none}
.inapp-open{
  padding:0 13px;height:34px;font-size:12px;font-weight:600;letter-spacing:.02em;
  color:var(--ink);white-space:nowrap;cursor:pointer;
  display:inline-flex;align-items:center;gap:6px;
}
.inapp-open svg{width:12px;height:12px;flex:none;stroke:currentColor;stroke-width:2;fill:none;stroke-linecap:round;stroke-linejoin:round}
.inapp-x{
  width:32px;height:34px;display:grid;place-items:center;
  color:var(--faint);font-size:11px;cursor:pointer;border-left:1px solid var(--card-brd);
}
.inapp-x svg{width:11px;height:11px;stroke:currentColor;stroke-width:2;fill:none;stroke-linecap:round;stroke-linejoin:round}
.inapp-pill button:active{background:rgba(127,127,127,.14)}

/* ---- connection rotator (cycle through a hub's other links) ---- */
.rotator{
  position:fixed;
  left:12px;
  bottom:calc(var(--safe-b) + 20px);
  /* transform:translateY(-50%); */
  /* transform:translateX(-50%); */
  z-index:30;pointer-events:auto;cursor:pointer;
  display:inline-flex;align-items:center;gap:7px;height:34px;padding:0 13px;
  border-radius:999px;background:var(--btn-bg);border:1px solid var(--card-brd);
  backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);
  color:var(--muted);font-size:12px;font-weight:600;letter-spacing:.02em;
  box-shadow:var(--chip-shadow);
  transition:transform .12s ease, color .2s ease, border-color .2s ease;
}
.rotator[hidden]{display:none}
.rotator svg{width:15px;height:15px;fill:none;stroke:var(--accent);stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.rotator:active{transform:scale(.94)} /*translateX(0%) */
.rotator.spin svg{animation:rotSpin .5s ease}
@keyframes rotSpin{from{transform:rotate(0)}to{transform:rotate(360deg)}}
@media (hover:hover){ .rotator:hover{color:var(--ink);border-color:rgba(110,168,254,.5)} }

/* ---- search ---- */
.panel{position:fixed;top:0;left:0;right:0;z-index:40;padding:calc(var(--safe-t) + 10px) 12px 10px;
  background:linear-gradient(var(--bg) 60%, transparent);animation:slideDown .22s ease}
@keyframes slideDown{from{transform:translateY(-16px);opacity:0}to{transform:none;opacity:1}}
.searchbar{display:flex;align-items:center;gap:8px;
  background:var(--card);border:1px solid var(--card-brd);border-radius:14px;padding:10px 12px;box-shadow:var(--shadow)}
.searchbar .si{width:18px;height:18px;stroke:var(--muted);stroke-width:2;fill:none;flex:none}
#searchInput{flex:1;background:none;border:0;outline:0;color:var(--ink);font-size:16px}
.textbtn{color:var(--accent);font-size:14px;padding:4px 6px;cursor:pointer}
#searchResults{list-style:none;margin:8px 0 0;padding:0;max-height:60vh;max-height:60dvh;overflow:auto;-webkit-overflow-scrolling:touch}
#searchResults:not(:empty){padding:4px;background:var(--bg);border:1px solid var(--card-brd);border-radius:14px;box-shadow:var(--shadow)}
#searchResults li{padding:12px 14px;border-radius:12px;color:var(--ink);font-size:15.5px;display:flex;align-items:center;gap:10px;cursor:pointer}
#searchResults li:active,#searchResults li.sel{background:var(--card)}
#searchResults li .rdot{width:8px;height:8px;border-radius:50%;background:var(--accent);flex:none;opacity:.8}
#searchResults .empty{color:var(--faint);padding:14px;font-size:14px}

/* ---- detail sheet ---- */
#sheetScrim{position:fixed;inset:0;z-index:50;background:var(--scrim);
  backdrop-filter:blur(2px);animation:fade .2s ease}
@keyframes fade{from{opacity:0}to{opacity:1}}
.sheet[hidden]{display:none}
.sheet{
  position:fixed;left:0;right:0;bottom:0;z-index:60;
  max-height:86vh;max-height:86dvh;display:flex;flex-direction:column;
  background:linear-gradient(var(--bg2),var(--bg));
  border-top-left-radius:22px;border-top-right-radius:22px;
  border-top:1px solid var(--card-brd);box-shadow:0 -12px 50px rgba(0,0,0,.5);
  padding:8px 20px calc(var(--safe-b) + 20px);
  transform:translateY(0);animation:slideUp .28s cubic-bezier(.16,1,.3,1);
  transition:height .32s cubic-bezier(.16,1,.3,1);
}
@keyframes slideUp{from{transform:translateY(100%)}to{transform:none}}
.sheet.closing{animation:slideDownSheet .22s ease forwards}
@keyframes slideDownSheet{to{transform:translateY(100%)}}
.sheet-grip{width:40px;height:4px;border-radius:2px;background:var(--grip);margin:6px auto 4px}
.sheet-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin:2px 0 6px}
.sheet-head h2{margin:0;font-size:20px;font-weight:700}
.levels{overflow:auto;-webkit-overflow-scrolling:touch;padding-right:2px}
.level{padding:14px 0;border-top:1px solid var(--line)}
.level:first-child{border-top:0}
.level .lh{display:flex;align-items:center;gap:8px;margin-bottom:6px}
.level .lh .n{font-size:11px;font-weight:700;color:var(--bg);background:var(--accent2);
  border-radius:6px;padding:2px 7px;letter-spacing:.03em}
.level .lh h3{margin:0;font-size:14px;color:var(--accent2);font-weight:600;letter-spacing:.02em}
.level p{margin:0;color:var(--ink);font-size:15.5px;line-height:1.62}
.level.enter{animation:levelIn .32s ease}
@keyframes levelIn{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
.deeper{width:100%;margin-top:14px;padding:13px;border-radius:14px;font-weight:600;font-size:14.5px;cursor:pointer;
  background:rgba(110,168,254,.12);border:1px solid rgba(110,168,254,.3);color:var(--accent)}
.deeper:active{transform:scale(.99)}

/* ---- about overlay (reuses .sheet visuals) ---- */
#aboutScrim{position:fixed;inset:0;z-index:50;background:var(--scrim);
  backdrop-filter:blur(2px);animation:fade .2s ease}
.about-body{overflow:auto;-webkit-overflow-scrolling:touch;padding-bottom:4px}
.about-body p{margin:0 0 12px;color:var(--muted);font-size:15.5px;line-height:1.62}
.about-body p:last-child{margin-bottom:0}
.about-body strong{color:var(--ink);font-weight:700}
.about-foot{margin-top:16px;padding-top:12px;border-top:1px solid var(--line);
  color:var(--faint);font-size:13px;line-height:1.55}
.about-foot a{color:var(--accent);text-decoration:none;font-weight:600}
.about-foot a:active,.about-foot a:hover{text-decoration:underline}

/* ---- misc ---- */
.hint{position:fixed;left:0;right:0;bottom:calc(var(--safe-b) + 5px);text-align:center;
  color:var(--faint);font-size:12px;z-index:10;pointer-events:none;
  transition:opacity .5s ease;padding:0 20px}
.hint.gone{opacity:0}
#tapcue{position:fixed;left:0;top:0;z-index:20;pointer-events:none;transform:translate(-50%,-50%);transition:opacity .45s ease}
#tapcue[hidden]{display:none}
#tapcue.gone{opacity:0}
.tc-ring{position:absolute;left:50%;top:50%;width:44px;height:44px;margin:-22px 0 0 -22px;border-radius:50%;border:2px solid var(--accent);opacity:0;animation:tcRing 1.8s ease-out infinite}
@keyframes tcRing{0%{transform:scale(.4);opacity:.6}12%{opacity:.6}70%{opacity:0}100%{transform:scale(1.8);opacity:0}}
.tc-cursor{position:absolute;left:50%;top:50%;width:30px;height:30px;margin:-6px 0 0 -12px;fill:none;stroke:var(--ink);stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;filter:drop-shadow(0 1px 4px rgba(0,0,0,.65)) drop-shadow(0 0 1px var(--bg));animation:tcTap 1.8s ease-in-out infinite;transform-origin:40% 18%}
@keyframes tcTap{0%,100%{transform:translate(0,0) scale(1)}40%{transform:translate(1px,3px) scale(.9)}58%{transform:translate(0,0) scale(1)}}
/* Demo tap ripple — gated by the ?tapfx (or ?demo) URL param in app.js. Flashes a
   clear pulse at each tap point so a screen recording shows what's being tapped.
   A zero-size fixed anchor at the touch point; the ring and dot are pseudo-elements
   centred on it via margins, so their scale animation stays centred on the tap.
   --tapfx-dur (set per-ripple by app.js) drives the lifetime: 1s at normal speed,
   scaled up by slow-mo recorders whose clock CSS animations don't follow. */
.tapfx-ripple{position:fixed;z-index:200;pointer-events:none;left:0;top:0;width:0;height:0}
.tapfx-ripple::before,.tapfx-ripple::after{content:"";position:absolute;left:0;top:0;border-radius:50%}
.tapfx-ripple::before{width:30px;height:30px;margin:-15px 0 0 -15px;border:2.5px solid var(--accent);animation:tapfxRing var(--tapfx-dur,1s) ease-out forwards}
.tapfx-ripple::after{width:16px;height:16px;margin:-8px 0 0 -8px;background:var(--accent);box-shadow:0 0 10px var(--accent);animation:tapfxDot var(--tapfx-dur,1s) ease-out forwards}
@keyframes tapfxRing{0%{opacity:.95;transform:scale(.35)}35%{opacity:.75}100%{opacity:0;transform:scale(2.6)}}
@keyframes tapfxDot{0%{opacity:.95;transform:scale(1)}70%{opacity:.55}100%{opacity:0;transform:scale(.3)}}
.loader{position:fixed;top:calc(var(--safe-t) + 16px);left:50%;transform:translateX(-50%);z-index:70;
  width:22px;height:22px;border-radius:50%;border:2.5px solid rgba(255,255,255,.2);
  border-top-color:var(--accent);animation:spin .7s linear infinite}
@keyframes spin{to{transform:translateX(-50%) rotate(360deg)}}

@media (min-width:820px){
  .node.center h1{font-size:23px}
  .node.center p{font-size:13.5px}
  .node.neighbor{max-width:136px}
  .node.neighbor .lbl{font-size:13px}
  .node.neighbor .rel{font-size:11px}
  .hint{font-size:13px}
}
@media (prefers-reduced-motion:reduce){
  *{animation-duration:.01ms !important}
  /* keep the opt-in demo ripple intact — it exists only to be seen on a recording */
  .tapfx-ripple::before,.tapfx-ripple::after{animation-duration:var(--tapfx-dur,1s) !important}
}
