:root {
  --bg: #0b0f17;
  --panel: rgba(17, 22, 33, 0.82);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #e8ecf3;
  --muted: #9aa5b8;
  --accent: #7fb2ff;
  --s1: #4fc3a1;
  --s2: #e69422;
  /* Active-system wash: translucent tint applied to page and panels. */
  --tint: 79, 195, 161;
  --tint-strength: 0.10;
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
}

body[data-system="system1"] { --tint: 79, 195, 161; }
body[data-system="system2"] { --tint: 230, 148, 34; }

#viewport { position: fixed; inset: 0; }
#viewport canvas { display: block; }

/* Translucent colour wash over the 3D view, strongest at the edges so the brain stays readable. */
#viewport::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(var(--tint), 0) 35%, rgba(var(--tint), calc(var(--tint-strength) * 1.6)) 100%),
    linear-gradient(180deg, rgba(var(--tint), calc(var(--tint-strength) * 0.6)), rgba(var(--tint), 0) 40%, rgba(var(--tint), calc(var(--tint-strength) * 0.8)));
  transition: background 1s ease;
}

.panel {
  background:
    linear-gradient(rgba(var(--tint), var(--tint-strength)), rgba(var(--tint), var(--tint-strength))),
    var(--panel);
  border: 1px solid rgba(var(--tint), 0.28);
  transition: background 1s ease, border-color 1s ease;
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.hidden { display: none !important; }

/* Top bar */
#topbar {
  position: fixed; top: 16px; left: 16px; right: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.brand { text-align: center; }
.brand h1 {
  margin: 0; font-size: 34px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15;
  text-shadow: 0 2px 18px rgba(0,0,0,.55);
}
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.mode-switch {
  display: flex; gap: 4px; padding: 4px;
  background:
    linear-gradient(rgba(var(--tint), var(--tint-strength)), rgba(var(--tint), var(--tint-strength))),
    var(--panel);
  border: 1px solid rgba(var(--tint), 0.28); border-radius: 999px;
  backdrop-filter: blur(14px);
  transition: background 1s ease, border-color 1s ease;
}
.mode {
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 8px 16px; border: 0; border-radius: 999px; cursor: pointer;
  background: transparent; color: var(--muted); font: inherit; text-align: left;
  transition: background .2s, color .2s;
}
.mode .mode-name { font-weight: 600; font-size: 14px; color: inherit; }
.mode .mode-sub { font-size: 11px; opacity: .8; }
.mode.active { color: #0b0f17; }
.mode.active[data-system="system1"] { background: var(--s1); }
.mode.active[data-system="system2"] { background: var(--s2); }
.mode:not(.active):hover { color: var(--text); background: rgba(255,255,255,.06); }

/* Left scenario panel */
#scenario {
  position: fixed; left: 16px; top: 150px; width: 320px; max-height: calc(100vh - 150px - 215px);
  overflow: auto; padding: 16px 18px;
}
.eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
#scenario h2 { margin: 4px 0 8px; font-size: 18px; font-weight: 600; }
#scenario h3 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
#scenario p { margin: 0; color: var(--text); }
#scenario ul { margin: 0; padding-left: 18px; color: var(--text); }
#scenario li { margin: 4px 0; }
#scenario details { margin-top: 12px; }
#scenario summary { cursor: pointer; color: var(--accent); font-size: 13px; }
#scenario details ul { margin-top: 6px; font-size: 13px; color: var(--muted); }
#explainer section h3 { margin: 10px 0 4px; font-size: 12px; text-transform: none; letter-spacing: 0; color: var(--text); }
#explainer section p { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.noscript { position: fixed; inset: 0; z-index: 30; padding: 40px; background: var(--bg); color: var(--text); max-width: 720px; margin: 0 auto; }
.caveat { margin-top: 14px !important; padding-top: 10px; border-top: 1px solid var(--panel-border); font-size: 12px; color: var(--muted) !important; }

/* Right inspector */
#inspector {
  position: fixed; right: 16px; top: 150px; width: 340px; padding: 16px 18px;
}
#inspector h2 { margin: 4px 28px 8px 0; font-size: 17px; font-weight: 600; }
#inspector .role { margin: 0 0 8px; }
#inspector-image {
  display: block; width: 100%; aspect-ratio: 3 / 2; object-fit: cover;
  border-radius: 8px; margin: 4px 0 12px; border: 1px solid rgba(var(--tint), .3);
}
.stimulus-label { transform: translate(-50%, -100%); }
#inspector .note { margin: 0; color: var(--muted); font-size: 13px; }
#inspector-close { position: absolute; top: 10px; right: 10px; }
.tc-wrap { margin-top: 14px; }
.tc-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
#inspector-tc { width: 100%; height: 90px; display: block; border-radius: 6px; background: rgba(255,255,255,.03); }
.hint { margin: 10px 0 0; font-size: 11px; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12px; }

/* Tooltip following the pointer */
#tooltip {
  position: fixed; z-index: 10; pointer-events: none; max-width: 260px;
  padding: 8px 10px; border-radius: 8px;
  background: linear-gradient(rgba(var(--tint), .12), rgba(var(--tint), .12)), rgba(10, 13, 20, .92);
  border: 1px solid rgba(var(--tint), .3);
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.tt-name { font-weight: 600; font-size: 13px; }
.tt-net { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin-top: 2px; }
.tt-role { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* 3D-anchored labels (CSS2DRenderer) */
.region-label {
  pointer-events: none; white-space: nowrap;
  font-family: var(--mono); font-size: 11px; color: rgba(232,236,243,.75);
  text-shadow: 0 1px 3px rgba(0,0,0,.9);
  transform: translate(-50%, -140%);
  transition: color .15s, font-size .15s;
}
.region-label.hot { color: #fff; font-size: 13px; font-weight: 500; }

/* Bottom controls */
#controls {
  position: fixed; left: 16px; right: 16px; bottom: 16px;
  padding: 12px 16px; display: flex; flex-direction: column; gap: 10px;
}

/* Credit tab, bottom-right corner of the control bar */
#credit {
  position: absolute; right: 12px; bottom: 8px;
  font-size: 11px; color: var(--muted); letter-spacing: .02em;
}
#credit a {
  color: rgb(var(--tint)); text-decoration: none;
  border-bottom: 1px dotted rgba(var(--tint), .6);
  transition: color 1s ease, border-color 1s ease;
}
#credit a:hover { color: var(--text); border-bottom-style: solid; }
.row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.playback { gap: 12px; }
#scrub { flex: 1; min-width: 160px; accent-color: var(--accent); }
#clock { min-width: 110px; color: var(--muted); }
.icon-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--panel-border);
  background: rgba(255,255,255,.06); color: var(--text); cursor: pointer; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }
.settings { font-size: 13px; color: var(--muted); }
.slider { display: flex; align-items: center; gap: 8px; }
.slider input { width: 140px; accent-color: var(--accent); }
.slider #demand-readout { min-width: 84px; color: var(--text); }
.slider.disabled { opacity: .45; }
.slider.disabled #demand-readout { color: var(--muted); font-size: 11px; }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: var(--accent); }

.legend { gap: 10px 16px; font-size: 12px; color: var(--muted); }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-item .swatch { width: 12px; height: 12px; border-radius: 3px; box-shadow: 0 0 8px currentColor; }
.legend-note { margin-left: auto; font-size: 11px; }

.key-hint {
  justify-content: center; gap: 0; font-size: 11px; color: var(--muted); opacity: .75;
  letter-spacing: .02em; padding-top: 2px;
}
.key-hint kbd {
  font-family: var(--mono); font-size: 10px; margin: 0 4px; padding: 1px 6px;
  border: 1px solid rgba(255,255,255,.18); border-bottom-width: 2px; border-radius: 4px;
  background: rgba(255,255,255,.05); color: var(--text);
}

#loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px; background: var(--bg); z-index: 20;
  transition: opacity .4s;
}
#loading.done { opacity: 0; pointer-events: none; }

@media (max-width: 900px) {
  #scenario { width: calc(100vw - 32px); max-height: 30vh; top: 170px; }
  #inspector { width: calc(100vw - 32px); top: auto; bottom: 190px; }
  .brand h1 { font-size: 24px; }
  .legend-note { margin-left: 0; }
}
