:root {
  --bg: #01030a;
  --ink: #e8eefc;
  --muted: #8ea0c4;
  --panel: rgba(8, 14, 30, 0.82);
  --edge: rgba(120, 160, 230, 0.18);
  --accent: #38bdf8;
  --measured: #38bdf8;
  --modelled: #fbbf24;
  --hypothesis: #a78bfa;
  --notScience: #fb7185;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

#scene { position: fixed; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------- loading ---------- */
#loadOverlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 45%, #071227 0%, #01030a 70%);
  transition: opacity .7s ease, visibility .7s ease;
}
#loadOverlay.done { opacity: 0; visibility: hidden; }
.load-box { text-align: center; width: min(420px, 82vw); }
.load-box h1 {
  margin: 0 0 .5rem; font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 300; letter-spacing: .12em; text-transform: uppercase;
}
.load-box p { margin: 0 0 1.1rem; color: var(--muted); font-size: .86rem; }
.load-bar { height: 2px; background: rgba(255,255,255,.09); border-radius: 2px; overflow: hidden; }
#loadFill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--hypothesis));
  transition: width .35s ease;
}

/* ---------- top bar ---------- */
#hud {
  position: fixed; z-index: 20; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .85rem 1.1rem;
  background: linear-gradient(180deg, rgba(1,3,10,.86), rgba(1,3,10,0));
  pointer-events: none;
}
#hud > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: .7rem; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto;
  background: radial-gradient(circle at 50% 50%, var(--accent) 0 22%, transparent 24%);
  box-shadow: 0 0 0 1.5px var(--hypothesis) inset, 0 0 18px rgba(56,189,248,.4);
}
.brand-name { font-size: .95rem; letter-spacing: .09em; text-transform: uppercase; font-weight: 500; }
.brand-sub { font-size: .7rem; color: var(--muted); margin-top: .1rem; }

.hud-actions { display: flex; gap: .5rem; align-items: center; }
#searchInput, #chatInput {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--edge); border-radius: 999px;
  padding: .5rem .95rem; font: inherit; font-size: .82rem; outline: none;
  min-width: 240px;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
#searchInput::placeholder, #chatInput::placeholder { color: var(--muted); }
#searchInput:focus, #chatInput:focus { border-color: rgba(56,189,248,.55); }

#chatToggle, #chatSend {
  background: rgba(56,189,248,.12); color: var(--accent);
  border: 1px solid rgba(56,189,248,.4); border-radius: 999px;
  padding: .5rem 1rem; font: inherit; font-size: .82rem; cursor: pointer;
  transition: background .2s ease;
  white-space: nowrap;
}
#chatToggle:hover, #chatSend:hover:not(:disabled) { background: rgba(56,189,248,.22); }
#chatSend:disabled { opacity: .45; cursor: default; }

/* ---------- the ladder ---------- */
#ladder {
  position: fixed; z-index: 20; left: 1.1rem; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 0;
}
.rung {
  display: flex; align-items: center; gap: .6rem;
  background: none; border: 0; padding: .3rem 0; cursor: pointer;
  color: var(--muted); font: inherit; font-size: .76rem; text-align: left;
  opacity: .55; transition: opacity .2s ease, color .2s ease;
}
.rung:hover { opacity: .9; }
.rung.active { opacity: 1; color: var(--ink); }
.rung-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto;
  border: 1.5px solid currentColor; background: transparent;
  transition: background .2s ease, box-shadow .2s ease;
}
.rung.active .rung-dot { background: currentColor; box-shadow: 0 0 12px currentColor; }
.rung-name { white-space: nowrap; }
.rung.ev-measured   { color: var(--measured); }
.rung.ev-modelled   { color: var(--modelled); }
.rung.ev-hypothesis { color: var(--hypothesis); }
.rung.ev-notScience { color: var(--notScience); }
.rung:not(.active) .rung-name { color: var(--muted); }

/* ---------- scale readout ---------- */
#readout {
  position: fixed; z-index: 20; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  text-align: center; pointer-events: none;
}
#readoutName {
  font-size: clamp(1.1rem, 3vw, 1.6rem); font-weight: 300;
  letter-spacing: .14em; text-transform: uppercase;
}
#readoutScale { font-size: .8rem; color: var(--muted); margin-top: .2rem; font-variant-numeric: tabular-nums; }
#readoutEvidence {
  margin-top: .5rem; display: inline-flex; align-items: center; gap: .4rem;
  font-size: .66rem; letter-spacing: .14em; text-transform: uppercase;
}
#readoutEvidence .pill { width: 7px; height: 7px; border-radius: 50%; background: var(--measured); }
#readoutEvidence .pill-label { color: var(--muted); }

#zoomHint {
  position: fixed; z-index: 20; left: 50%; bottom: .45rem; transform: translateX(-50%);
  font-size: .64rem; color: rgba(142,160,196,.5); letter-spacing: .05em;
  pointer-events: none; transition: opacity .5s ease;
}
#zoomHint.gone { opacity: 0; }
kbd {
  font: inherit; font-size: .6rem; border: 1px solid var(--edge);
  border-radius: 3px; padding: 0 .22rem; margin: 0 .05rem;
}

/* ---------- info panel ---------- */
#infoPanel {
  position: fixed; z-index: 25; right: 1.1rem; top: 50%; transform: translateY(-50%);
  width: min(340px, 84vw); max-height: 70vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 14px;
  padding: 1.1rem 1.2rem;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  transition: opacity .3s ease, transform .3s ease;
}
#infoPanel.hidden { opacity: 0; pointer-events: none; transform: translateY(-50%) translateX(14px); }
#closeInfo {
  position: absolute; top: .5rem; right: .6rem;
  background: none; border: 0; color: var(--muted); font-size: 1.2rem;
  cursor: pointer; line-height: 1; padding: .2rem;
}
#closeInfo:hover { color: var(--ink); }
#infoKind {
  font-size: .64rem; letter-spacing: .16em; text-transform: uppercase;
  color: var(--accent); margin-bottom: .35rem;
}
#infoPanel h2 { margin: 0 0 .5rem; font-size: 1.1rem; font-weight: 500; padding-right: 1rem; }
#infoBody { margin: 0 0 .8rem; font-size: .84rem; line-height: 1.55; color: #c8d5ef; }
#infoFacts { margin: 0 0 .8rem; padding: 0; list-style: none; }
#infoFacts li {
  font-size: .78rem; color: var(--muted); padding: .22rem 0 .22rem .8rem;
  position: relative; font-variant-numeric: tabular-nums;
}
#infoFacts li::before { content: ""; position: absolute; left: 0; top: .62rem; width: 4px; height: 4px; border-radius: 50%; background: var(--edge); }
#infoSource { font-size: .68rem; color: rgba(142,160,196,.7); border-top: 1px solid var(--edge); padding-top: .55rem; line-height: 1.45; }
#infoSource a { color: var(--accent); text-decoration: none; }

.ev-tag {
  display: inline-block; font-size: .6rem; letter-spacing: .12em;
  text-transform: uppercase; padding: .15rem .45rem; border-radius: 4px;
  margin-bottom: .5rem;
}
.ev-tag.measured   { background: rgba(56,189,248,.14);  color: var(--measured); }
.ev-tag.modelled   { background: rgba(251,191,36,.14);  color: var(--modelled); }
.ev-tag.hypothesis { background: rgba(167,139,250,.16); color: var(--hypothesis); }
.ev-tag.notScience { background: rgba(251,113,133,.16); color: var(--notScience); }

/* ---------- chat ---------- */
#chatPanel {
  position: fixed; z-index: 30; right: 1.1rem; bottom: 1.1rem;
  width: min(380px, 90vw); height: min(480px, 72vh);
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 14px;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  overflow: hidden;
  transition: opacity .3s ease, transform .3s ease;
}
#chatPanel.hidden { opacity: 0; pointer-events: none; transform: translateY(14px); }
#chatHeader {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem .9rem; border-bottom: 1px solid var(--edge);
  font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
}
#chatClose { background: none; border: 0; color: var(--muted); font-size: 1.15rem; cursor: pointer; line-height: 1; }
#chatClose:hover { color: var(--ink); }
#chatMessages { flex: 1; overflow-y: auto; padding: .8rem .9rem; display: flex; flex-direction: column; gap: .55rem; }
.chat-msg { font-size: .83rem; line-height: 1.5; padding: .5rem .7rem; border-radius: 10px; max-width: 92%; white-space: pre-wrap; }
.chat-msg.user { align-self: flex-end; background: rgba(56,189,248,.14); color: #d8ecff; }
.chat-msg.ai { align-self: flex-start; background: rgba(255,255,255,.05); color: #d4dff5; }
.chat-msg.system {
  align-self: center; background: none; color: rgba(142,160,196,.75);
  font-size: .68rem; letter-spacing: .04em; text-align: center; padding: .2rem 0;
}
.chat-msg.data {
  align-self: flex-start; background: rgba(56,189,248,.07);
  border-left: 2px solid rgba(56,189,248,.5); border-radius: 0 8px 8px 0;
  font-size: .72rem; color: #9fc4e8; font-variant-numeric: tabular-nums;
}
#chatStatus { font-size: .68rem; color: var(--muted); padding: 0 .9rem .4rem; min-height: 1rem; }
#chatForm { display: flex; gap: .45rem; padding: .7rem .9rem; border-top: 1px solid var(--edge); }
#chatForm #chatInput { flex: 1; min-width: 0; }

#searchStatus {
  position: fixed; z-index: 20; left: 50%; top: 4.1rem; transform: translateX(-50%);
  font-size: .74rem; color: var(--muted); background: var(--panel);
  border: 1px solid var(--edge); border-radius: 999px; padding: .3rem .85rem;
  opacity: 0; transition: opacity .3s ease; pointer-events: none; white-space: nowrap;
}
#searchStatus.show { opacity: 1; }

.label-layer { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.obj-label {
  font-size: .68rem; color: rgba(232,238,252,.82); letter-spacing: .04em;
  text-shadow: 0 0 8px rgba(0,0,0,.9); white-space: nowrap; pointer-events: none;
}

@media (max-width: 760px) {
  /* At 390px the wordmark, search field and chat button cannot share one row:
     the mark alone carries the identity here. */
  .brand-sub, .brand-name { display: none; }
  #hud { padding: .6rem .55rem; gap: .4rem; }
  .hud-actions { gap: .35rem; flex: 1; min-width: 0; }
  #searchInput { min-width: 0; flex: 1; }
  #chatToggle { font-size: .74rem; padding: .45rem .7rem; }
  #ladder { left: .5rem; gap: 0; }
  .rung-name { display: none; }
  .rung { padding: .6rem 0; min-height: 34px; }
  /* The panel sits above the ladder in z-order, so it must leave the ladder
     column clear or the rungs become untappable. */
  #infoPanel { right: .5rem; left: 2.9rem; width: auto; top: auto; bottom: 5.5rem; transform: none; max-height: 46vh; }
  #infoPanel.hidden { transform: translateY(14px); }
  #chatPanel { right: .5rem; left: .5rem; width: auto; }
  #zoomHint { font-size: .68rem; bottom: .6rem; }
}
