/* ============================================================
   TVS // ORGANISM — the site as a living neural substrate
   Objects are neurons. Edges are synapses. Layout is the
   network's state. It perceives attention, associates,
   learns you (Hebbian) and rests. On-device, no API.
   ============================================================ */
:root {
  --font-head: 'Chakra Petch', sans-serif;
  --font-body: 'Space Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --bg:    oklch(0.155 0.032 270);
  --bg-2:  oklch(0.125 0.028 272);
  --ink:   oklch(0.97 0.012 250);
  --muted: oklch(0.72 0.03 268);
  --faint: oklch(0.56 0.028 268);
  --line:  oklch(1 0 0 / 0.10);
  --c1: oklch(0.83 0.15 196);
  --c2: oklch(0.70 0.20 292);
  --grad: linear-gradient(110deg, var(--c1), var(--c2));
  --glass: oklch(0.155 0.032 270 / 0.66);
  --ok: oklch(0.80 0.17 150);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background:
    radial-gradient(60% 50% at 50% 40%, oklch(0.19 0.04 272), var(--bg)) fixed;
  color: var(--ink); font-family: var(--font-body);
  overflow: hidden; -webkit-font-smoothing: antialiased;
}
::selection { background: oklch(0.83 0.15 196 / 0.3); }
a { color: inherit; }
button { font: inherit; cursor: pointer; }

#field { position: fixed; inset: 0; z-index: 1; display: block; }
.labels { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
.lab {
  position: absolute; transform: translate(-50%,-50%);
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.02em;
  white-space: nowrap; color: var(--ink); text-shadow: 0 1px 8px oklch(0.1 0.03 270 / 0.9);
  will-change: transform, opacity;
}

/* ---------- top bar ---------- */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; padding: 16px 22px;
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; }
.brand .mk { width: 30px; height: 30px; border-radius: 9px; background: var(--grad); color: #04121a; display: grid; place-items: center; font-weight: 700; font-size: 12px; font-family: var(--font-mono); box-shadow: 0 0 18px oklch(0.83 0.15 196 / 0.5); }
.brand .bt { font-family: var(--font-mono); font-size: 13px; }
.brand .bt b { font-weight: 700; } .brand .bt span { color: var(--faint); }
.top .obj { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--faint); padding: 5px 11px; border: 1px solid var(--line); border-radius: 999px; }
.top .sp { flex: 1; }
.lang-switch { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; font-family: var(--font-mono); font-size: 12px; background: var(--glass); backdrop-filter: blur(10px); }
.lang-switch button { border: 0; background: transparent; color: var(--muted); padding: 6px 11px; }
.lang-switch button.active { background: var(--grad); color: #04121a; font-weight: 700; }
.tbtn { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink); background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; text-decoration: none; display: inline-flex; align-items: center; gap: 7px; backdrop-filter: blur(10px); transition: border-color .2s, color .2s, background .2s; }
.tbtn:hover { border-color: var(--c1); color: var(--c1); }

/* ---------- focus card (most-active node) ---------- */
.focus {
  position: fixed; left: 26px; bottom: 26px; z-index: 8; width: min(380px, 78vw);
  border: 1px solid var(--line); border-radius: 16px; background: var(--glass);
  backdrop-filter: blur(16px); box-shadow: 0 30px 70px -44px oklch(0.04 0.04 270 / 0.95);
  padding: 20px 22px; overflow: hidden;
  transition: opacity .35s, transform .35s;
}
.focus::before { content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1px; background: var(--grad); -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; opacity: 0.5; pointer-events: none; }
.focus .fid { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; color: var(--c1); margin-bottom: 9px; display: flex; align-items: center; gap: 8px; }
.focus .fid .a { margin-left: auto; color: var(--faint); }
.focus .ftitle { font-family: var(--font-head); font-weight: 600; font-size: 19px; line-height: 1.15; margin-bottom: 8px; }
.focus .fbody { color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.focus .fbody .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.focus .fbody .chips span { font-family: var(--font-mono); font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; color: var(--ink); }
.swap { animation: swap .4s ease; }
@keyframes swap { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- telemetry (live network state) ---------- */
.tele {
  position: fixed; right: 22px; top: 70px; z-index: 8; width: 260px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--glass);
  backdrop-filter: blur(14px); padding: 16px; font-family: var(--font-mono);
}
.tele h4 { margin: 0 0 12px; font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--c1); display: flex; align-items: center; gap: 8px; font-weight: 500; }
.tele h4 .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); animation: bl 2s infinite; }
@keyframes bl { 0%,100%{opacity:1;} 50%{opacity:.4;} }
.actrow { display: grid; grid-template-columns: 1fr; gap: 6px; margin-bottom: 12px; }
.act { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; font-size: 10.5px; color: var(--muted); }
.act .bar { grid-column: 1 / -1; height: 3px; background: oklch(1 0 0 / 0.08); border-radius: 3px; overflow: hidden; }
.act .bar i { display: block; height: 100%; background: var(--grad); width: 0; }
.act .v { color: var(--c1); }
.tstat { display: flex; justify-content: space-between; font-size: 10px; color: var(--faint); padding-top: 10px; border-top: 1px solid var(--line); letter-spacing: 0.08em; }
.tstat b { color: var(--ink); }
.tlog { margin-top: 10px; font-size: 9.5px; color: var(--faint); line-height: 1.6; min-height: 30px; }
.tlog .syn { color: var(--c2); }
.tele .reset { margin-top: 12px; width: 100%; text-align: center; font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 7px; transition: border-color .2s, color .2s; }
.tele .reset:hover { border-color: var(--c2); color: var(--c2); }

/* ---------- hint ---------- */
.hint {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 7;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--faint); text-align: center; pointer-events: none; transition: opacity .5s;
}
.hint b { color: var(--c1); }
.hint.gone { opacity: 0; }

/* ---------- need palette (no typing) ---------- */
.needbar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 9;
  width: min(780px, 94vw); padding: 13px 16px;
  border: 1px solid var(--line); border-radius: 18px; background: var(--glass);
  backdrop-filter: blur(16px); box-shadow: 0 24px 56px -36px oklch(0.04 0.04 270 / 0.92);
  transition: opacity .35s, transform .35s;
}
body.reading .needbar { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(22px); }
.need-h { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); margin-bottom: 11px; text-align: center; }
.need-tokens { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; }
.ntok {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--muted);
  background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px;
  transition: color .18s, background .18s, border-color .18s, box-shadow .18s;
}
.ntok.con { border-style: dashed; }
.ntok:hover { color: var(--ink); border-color: var(--c1); }
.ntok.on { color: #04121a; background: var(--grad); border-color: transparent; font-weight: 600; box-shadow: 0 0 18px -5px var(--c1); }
.need-foot { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding-top: 11px; border-top: 1px solid oklch(1 0 0 / 0.06); }
.collective { flex: 1; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.04em; color: var(--faint); }
.collective b { color: var(--c1); }
.fit-meter { display: flex; align-items: center; gap: 7px; background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 5px 13px; cursor: pointer; transition: border-color .18s; }
.fit-meter:hover { border-color: var(--c1); }
.fit-v { font-family: var(--font-head); font-weight: 700; font-size: 15px; color: var(--faint); min-width: 18px; text-align: center; }
.fit-v.on { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.fit-l { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); }
.fit-go { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--c1); background: oklch(0.83 0.15 196 / 0.12); border: 1px solid oklch(0.83 0.15 196 / 0.4); border-radius: 999px; padding: 8px 15px; transition: box-shadow .18s, background .18s; }
.fit-go:hover { background: oklch(0.83 0.15 196 / 0.2); box-shadow: 0 0 18px -4px var(--c1); }

/* fit report (in reader) */
.fit-report { margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.fit-pct { font-family: var(--font-head); font-weight: 700; font-size: 48px; line-height: 1; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.fit-verd { font-family: var(--font-head); font-weight: 600; font-size: 18px; margin-top: 5px; }
.fit-need { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); margin-top: 9px; line-height: 1.5; }
.fit-gap { font-family: var(--font-mono); font-size: 11px; color: oklch(0.80 0.13 75); margin-top: 8px; }

@media (max-width: 600px) { .needbar { bottom: 12px; padding: 10px; } .need-foot { flex-wrap: wrap; } .collective { flex-basis: 100%; order: 3; text-align: center; } }

/* ---------- query bar (direct stimulus-queries) ---------- */
.qbar {
  position: fixed; left: 50%; bottom: 52px; transform: translateX(-50%); z-index: 9;
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; max-width: 90vw;
  padding: 8px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--glass); backdrop-filter: blur(14px);
  box-shadow: 0 20px 50px -34px oklch(0.04 0.04 270 / 0.9);
  transition: opacity .35s, transform .35s;
}
.qbtn {
  font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 0.02em;
  color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 999px;
  padding: 8px 14px; transition: color .18s, background .18s, border-color .18s;
}
.qbtn:hover { color: var(--ink); background: oklch(1 0 0 / 0.05); }
.qbtn.active { color: #04121a; background: var(--grad); font-weight: 600; }
body.reading .qbar { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(20px); }
body.reading .tele { opacity: 0; pointer-events: none; }
body.reading .hint { opacity: 0; }

/* ---------- reader (the cluster, made readable) ---------- */
.reader {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; width: min(480px, 92vw);
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, oklch(0.17 0.03 270 / 0.92), oklch(0.14 0.028 272 / 0.96));
  border-left: 1px solid var(--line); backdrop-filter: blur(18px);
  box-shadow: -40px 0 90px -50px oklch(0.03 0.04 270 / 0.95);
  transform: translateX(100%); transition: transform .5s cubic-bezier(.45,.05,.2,1);
}
.reader.open { transform: none; }
.reader-head { display: flex; align-items: center; gap: 12px; padding: 20px 24px 14px; border-bottom: 1px solid var(--line); }
.reader-head .rid { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; color: var(--c1); text-transform: uppercase; }
.reader-head .rttl { font-family: var(--font-head); font-weight: 700; font-size: 19px; text-transform: uppercase; letter-spacing: 0.01em; }
.reader-head .rclose { margin-left: auto; width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--line); background: transparent; color: var(--ink); font-size: 14px; display: grid; place-items: center; transition: border-color .18s, color .18s; }
.reader-head .rclose:hover { border-color: var(--c2); color: var(--c2); }
.reader-sub { padding: 12px 24px 0; font-family: var(--font-head); font-size: 14.5px; color: var(--muted); line-height: 1.45; }
.reader-sub:empty { display: none; }
.reader-body { flex: 1; overflow-y: auto; padding: 18px 24px 24px; }
.reader-body::-webkit-scrollbar { width: 7px; } .reader-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 7px; }
.rb { padding: 16px 0; border-bottom: 1px solid var(--line); }
.rb:first-child { padding-top: 6px; } .rb:last-child { border-bottom: 0; }
.rb-id { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: 0.1em; margin-bottom: 7px; }
.rb h3 { font-family: var(--font-head); font-weight: 600; font-size: 17px; margin-bottom: 8px; }
.rb-body { color: var(--muted); font-size: 14px; line-height: 1.58; }
.rb-body p { margin: 0 0 9px; } .rb-body p:last-child { margin-bottom: 0; }
.rb-body a { color: var(--c1); text-decoration: none; font-family: var(--font-mono); font-size: 13px; margin-right: 12px; }
.rb-body a:hover { text-decoration: underline; }
.rb-body ul { margin: 8px 0 0; padding-left: 17px; display: grid; gap: 6px; }
.rb-body ul li::marker { color: var(--c1); }
.rb-org { font-family: var(--font-mono); font-size: 12px; color: var(--c1); margin-bottom: 7px; }
.rb-body .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.rb-body .chips span { font-family: var(--font-mono); font-size: 11px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; color: var(--ink); }
.rb-metrics { display: grid; grid-template-columns: repeat(2,1fr); gap: 8px; margin: 10px 0; }
.rb-metrics .m { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
.rb-metrics .m .v { font-family: var(--font-head); font-weight: 700; font-size: 16px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.rb-metrics .m .k { font-family: var(--font-mono); font-size: 9px; color: var(--faint); margin-top: 3px; }
.reader-nav { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px; border-top: 1px solid var(--line); font-family: var(--font-mono); font-size: 11px; color: var(--faint); }
.reader-nav button { font: inherit; color: var(--c1); background: transparent; border: 0; cursor: pointer; letter-spacing: 0.06em; text-transform: uppercase; }

.readbtn {
  margin-top: 14px; width: 100%; font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--c1); background: oklch(0.83 0.15 196 / 0.12); border: 1px solid oklch(0.83 0.15 196 / 0.4); border-radius: 9px; padding: 9px;
  transition: background .18s, box-shadow .18s;
}
.readbtn:hover { background: oklch(0.83 0.15 196 / 0.2); box-shadow: 0 0 20px -4px var(--c1); }

@media (max-width: 820px) {
  .tele { display: none; }
  .focus { left: 14px; right: 14px; bottom: 14px; width: auto; }
  .top { padding: 12px 14px; gap: 10px; }
  .brand .bt span, .top .obj { display: none; }
}
