:root {
  color-scheme: dark;
  --bg: #070c12;
  --ink: #e9f2f6;
  --quiet: #93a8b5;
  --faint: #6a8090;
  --line: rgba(145, 176, 194, 0.15);
  --mint: #7cf5c8;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "Cascadia Mono", monospace;
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
}

body { color: var(--ink); }

::selection { background: var(--mint); color: #04110c; }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 3px; }
button, a { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- stage ---------- */

.stage {
  position: relative;
  height: 100svh;
  min-height: 540px;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(120% 80% at 50% 0%, #0e1a24 0%, #080e15 46%, #05090d 100%);
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(4, 8, 12, 0.55), transparent 14%),
    linear-gradient(0deg, rgba(4, 8, 12, 0.5), transparent 16%);
}

.scene {
  position: absolute;
  inset: 0;
  z-index: 1;
  touch-action: none;
}

.scene canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  cursor: grab;
}

.scene canvas:active { cursor: grabbing; }

.label-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

/* ---------- masthead ---------- */

.masthead {
  position: absolute;
  z-index: 4;
  top: clamp(22px, 3.4vw, 40px);
  left: clamp(22px, 3.4vw, 46px);
  max-width: min(430px, 80vw);
  pointer-events: none;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  font: 600 0.62rem/1.2 var(--mono);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--mint);
}

.eyebrow .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 12px var(--mint);
}

h1 {
  margin: 0.34rem 0 0;
  font-size: clamp(2.5rem, 4.4vw, 3.8rem);
  font-weight: 640;
  line-height: 0.96;
  letter-spacing: -0.045em;
  background: linear-gradient(135deg, #ffffff 24%, #c7f5e3 68%, #7cf5c8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 8px 34px rgba(124, 245, 200, 0.14));
}

.subtitle {
  max-width: 37ch;
  margin: 0.7rem 0 0;
  color: var(--quiet);
  font-size: clamp(0.86rem, 1.1vw, 0.95rem);
  line-height: 1.55;
  text-wrap: pretty;
}

.touch-hint {
  display: none;
  margin: 0.45rem 0 0;
  color: var(--faint);
  font: 600 0.56rem/1.4 var(--mono);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* ---------- view controls ---------- */

.view-controls {
  position: absolute;
  z-index: 4;
  top: clamp(22px, 3.4vw, 40px);
  right: clamp(22px, 3.4vw, 46px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.65rem;
}

.ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.82rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(9, 16, 22, 0.72);
  color: #cfe0e6;
  font-size: 0.76rem;
  letter-spacing: 0.01em;
  backdrop-filter: blur(12px);
  transition: border-color 0.18s, color 0.18s, background 0.18s;
}

.ghost:hover {
  border-color: rgba(124, 245, 200, 0.5);
  color: var(--mint);
  background: rgba(10, 20, 26, 0.9);
}

.ghost span { font-size: 0.95rem; line-height: 1; }

.hint {
  margin: 0;
  font: 0.58rem/1.5 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  text-align: right;
}

/* ---------- component labels (CSS2D) ---------- */

.tag {
  --brand: #7cf5c8;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 2px 7px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: #c8d8e1;
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: 0.012em;
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(2, 7, 11, 0.95), 0 0 12px rgba(2, 7, 11, 0.55);
  pointer-events: none;
  user-select: none;
  transition: opacity 0.18s ease, background 0.18s ease, border-color 0.18s ease,
    color 0.18s ease, box-shadow 0.18s ease;
}

.tag span { display: block; }

.tag strong {
  color: #ecf5f8;
  font-size: 11px;
  font-weight: 620;
  letter-spacing: 0.005em;
}

.tag small {
  color: #93a9b7;
  font: 500 9px/1.2 var(--mono);
  letter-spacing: 0.02em;
  text-shadow: none;
}

.tag.node {
  gap: 2px;
  padding: 3px 9px;
  background: rgba(7, 13, 19, 0.55);
  border-color: rgba(148, 176, 194, 0.13);
  backdrop-filter: blur(5px);
}

.tag.external { color: #b7c8d3; }

.tag.is-dim { opacity: 0.22; }

.tag.is-hot {
  background: rgba(7, 14, 20, 0.94);
  border-color: color-mix(in srgb, var(--brand) 66%, transparent);
  color: #f0f8fb;
  text-shadow: none;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--brand) 24%, transparent),
    0 12px 28px rgba(0, 0, 0, 0.5);
}

.tag.node.is-hot strong { color: #ffffff; }

/* zone captions, printed just below each layer outline */
.zone-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font: 600 8.5px/1 var(--mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0.85;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  user-select: none;
}

.zone-label::before {
  content: "";
  width: 12px;
  height: 1px;
  background: currentColor;
  opacity: 0.85;
}

/* ---------- details panel ---------- */

.panel {
  --brand: #7cf5c8;
  position: absolute;
  z-index: 6;
  top: clamp(112px, 15vh, 168px);
  right: clamp(22px, 3.4vw, 46px);
  width: min(352px, calc(100vw - 2.5rem));
  max-height: min(64vh, 590px);
  overflow-y: auto;
  padding: 1.05rem 1.1rem 1.05rem;
  border: 1px solid color-mix(in srgb, var(--brand) 24%, var(--line));
  border-radius: 16px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--brand) 5%, rgba(12, 20, 28, 0.95)), rgba(6, 11, 16, 0.96));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.62), 0 0 0 1px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(18px);
  opacity: 0;
  transform: translateY(-7px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  scrollbar-width: thin;
}

.panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.panel-close {
  position: absolute;
  top: 0.55rem;
  right: 0.6rem;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--faint);
  font-size: 1.1rem;
  line-height: 1;
}

.panel-close:hover { color: var(--ink); background: rgba(255, 255, 255, 0.06); }

.panel-head {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding-right: 1.6rem;
}

.panel-logo-wrap {
  width: 56px;
  height: 56px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 13px;
  border: 1px solid color-mix(in srgb, var(--brand) 42%, transparent);
  background: #eef4f8;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 8px 20px rgba(0, 0, 0, 0.28);
  transition: background 0.2s ease;
}

.panel-logo-wrap.is-light-logo {
  background: #18242e;
  border-color: rgba(190, 214, 230, 0.22);
}

.panel-logo-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  display: block;
}

.panel-logo-text {
  display: block;
  font: 700 0.92rem/1 var(--mono);
  letter-spacing: 0.02em;
  color: color-mix(in srgb, var(--brand) 70%, #101820);
}

.panel-logo-wrap.is-light-logo .panel-logo-text { color: #dbe9f2; }

.panel-titles { min-width: 0; }

.panel-layer {
  margin: 0;
  font: 600 0.57rem/1.3 var(--mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brand);
}

.panel h2 {
  margin: 0.14rem 0 0;
  font-size: 1.16rem;
  font-weight: 640;
  line-height: 1.2;
  letter-spacing: -0.022em;
}

.panel-sub {
  margin: 0.2rem 0 0;
  color: var(--faint);
  font: 0.62rem/1.3 var(--mono);
  letter-spacing: 0.03em;
}

.panel-sub[hidden] { display: none; }

.panel-what {
  margin: 0.9rem 0 0;
  color: #b7c9d1;
  font-size: 0.83rem;
  line-height: 1.55;
}

.panel-purpose {
  margin-top: 0.85rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--line);
}

.panel-label {
  margin: 0 0 0.28rem;
  font: 600 0.56rem/1.2 var(--mono);
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--faint);
}

.panel-purpose p:last-child {
  margin: 0;
  color: #d4e2e7;
  font-size: 0.83rem;
  line-height: 1.55;
}

.panel-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.95rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  width: 100%;
  color: var(--mint);
  font: 0.71rem/1.4 var(--mono);
  text-decoration: none;
}

.panel-link:hover { text-decoration: underline; text-underline-offset: 0.22em; }

/* ---------- layer bar ---------- */

.layerbar {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: clamp(14px, 2.4vw, 26px);
  transform: translateX(-50%);
  display: flex;
  gap: 0.12rem;
  max-width: calc(100vw - 2rem);
  padding: 0.34rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(8, 14, 20, 0.86);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(16px);
  overflow-x: auto;
  scrollbar-width: none;
}

.layerbar::-webkit-scrollbar { display: none; }

.layer {
  --c: #7cf5c8;
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.42rem 0.72rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: #9cb0bb;
  font-size: 0.72rem;
  white-space: nowrap;
  transition: color 0.16s, background 0.16s, opacity 0.16s;
}

.layer i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 9px var(--c);
}

.layer:hover { color: var(--ink); }

.layer[aria-pressed="true"] {
  color: #ecf4f7;
  background: rgba(255, 255, 255, 0.065);
  border-color: rgba(255, 255, 255, 0.09);
}

.layer[aria-pressed="false"] { opacity: 0.4; }
.layer[aria-pressed="false"] i { background: #3c4e59; box-shadow: none; }

/* ---------- misc overlays ---------- */

.boot {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  background: #070c12;
  color: #7f96a1;
  font: 0.62rem/1.4 var(--mono);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  transition: opacity 0.5s ease;
}

.boot.is-gone { opacity: 0; pointer-events: none; }

.boot-ring {
  width: 13px;
  height: 13px;
  border: 1.5px solid rgba(124, 245, 200, 0.25);
  border-top-color: var(--mint);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.boot.is-error { letter-spacing: 0.05em; text-transform: none; font-size: 0.8rem; color: #ffb4a8; }

@keyframes spin { to { transform: rotate(360deg); } }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .hint { display: none; }
  .panel { width: min(326px, calc(100vw - 2.5rem)); }
}

@media (max-width: 720px) {
  .stage { min-height: 100svh; }
  .masthead { top: 18px; left: 18px; max-width: min(330px, 86vw); }
  h1 { font-size: clamp(2.2rem, 11vw, 3rem); }
  .subtitle { max-width: 28ch; font-size: 0.82rem; }
  .view-controls { top: 18px; right: 16px; }
  .ghost { padding: 0.4rem 0.64rem; font-size: 0.7rem; }
  .touch-hint { display: block; }

  /* the compact layer bar doubles as the zone legend on small screens */
  .zone-label { display: none; }

  .panel {
    top: auto;
    bottom: 106px;
    left: 12px;
    right: 12px;
    width: auto;
    max-height: 48svh;
    transform: translateY(8px);
  }

  .layerbar {
    bottom: 12px;
    left: 50%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: calc(100vw - 1rem);
    gap: 0.14rem;
    padding: 0.32rem;
    border-radius: 16px;
  }

  .layer { justify-content: center; padding: 0.36rem 0.14rem; font-size: 0.57rem; gap: 0.24rem; border-radius: 9px; }
  .layer i { width: 5px; height: 5px; }

  /* Keep the three node names; tile names appear on tap. */
  .tag.node { padding: 1px 4px; background: transparent; border-color: transparent; backdrop-filter: none; }
  .tag.node strong { font-size: 9.5px; }
  .tag.node small { display: none; }
  .tag:not(.node) { font-size: 10px; }
}

@media (max-width: 420px) {
  .layer i { display: none; }
  .layer { padding: 0.34rem 0.4rem; font-size: 0.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .tag { transition: none; }
  .boot-ring { animation: none; border-top-color: var(--mint); }
}

/* Guided flow caption: names the one story that is lit right now. */
.flow {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: calc(clamp(14px, 2.4vw, 26px) + 56px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: min(560px, calc(100vw - 2rem));
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(8, 14, 20, 0.86);
  backdrop-filter: blur(16px);
}
.flow[hidden] { display: none; }
.flow-body { flex: 1; min-width: 0; }
.flow-head { margin: 0; display: flex; gap: 0.5rem; align-items: baseline; font-size: 0.9rem; color: #eef4f8; }
.flow-head span { font: 0.68rem ui-monospace, monospace; color: #7cf5c8; }
.flow-text { margin: 0.15rem 0 0; font-size: 0.78rem; line-height: 1.4; color: #a9b8c3; }
.flow-btn {
  flex: none; width: 30px; height: 30px; border-radius: 9px;
  border: 1px solid var(--line); background: transparent; color: #dce6ee;
  font-size: 1.1rem; cursor: pointer;
}
.flow-btn:hover, .flow-btn:focus-visible { background: rgba(124, 245, 200, 0.12); }
@media (max-width: 640px) {
  .flow { bottom: 104px; width: calc(100vw - 1rem); }
}

.map-tools {
  position: absolute;
  z-index: 6;
  top: clamp(66px, 9vw, 100px);
  right: clamp(16px, 2.4vw, 28px);
  display: grid;
  justify-items: end;
  gap: .55rem;
}
.map-tools[hidden], .layerbar[hidden] { display: none; }
.map-tools label, .flow-jump { color: #c4d1db; font-size: .72rem; }
.map-tools label:not([hidden]), .flow-jump { display: grid; gap: .22rem; }
.map-tools select, .flow-jump select {
  color: #edf5f8;
  color-scheme: dark;
  background: #131e29;
  border: 1px solid #50616e;
  border-radius: 6px;
  padding: .28rem .45rem;
  max-width: 100%;
  font: inherit;
}
.flow {
  bottom: clamp(14px, 2.4vw, 26px);
  width: min(660px, calc(100vw - 2rem));
}
.flow-head { font-size: 1rem; }
.flow-text { color: #d5e1eb; font-size: .85rem; margin-top: .45rem; }
.flow-jump { margin-top: .35rem; width: fit-content; }
.flow-btn { min-width: 34px; min-height: 36px; }
#flow-play { flex: none; min-height: 36px; }
@media (max-width: 720px) {
  .map-tools { top: 55px; right: 16px; }
  .flow { width: calc(100vw - 1rem); }
  .flow-text { font-size: .77rem; }
}
.tag.node.is-offline small { display: block; color: #ffc0b9; }

.vip-badge {
  display: inline-block;
  padding: .3rem .48rem;
  border: 1px solid #7de6c2;
  border-radius: 5px;
  background: #102b2b;
  color: #b7ffe7;
  font: 650 .72rem system-ui, sans-serif;
  white-space: nowrap;
  pointer-events: none;
}
.failover-status {
  margin-top: .45rem;
  color: #b7ffe7;
  font-size: .77rem;
  font-weight: 650;
}
#failover-replay[hidden] { display: none; }
#failover-replay:not([hidden]) { margin-top: .35rem; }

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f8fbfc;
  --ink: #10252e;
  --quiet: #365460;
  --faint: #496571;
  --line: #bdcfd6;
  --mint: #086650;
  --paper: #ffffff;
  --wash: #e9f4f4;
  --elevation: 0 12px 32px rgb(35 73 89 / 14%);
}
:root[data-theme="light"] ::selection { color: white; }
:root[data-theme="light"] .stage { background: var(--bg); }
:root[data-theme="light"] .stage::before { background: none; }
:root[data-theme="light"] h1 {
  background: none;
  color: var(--ink);
  text-shadow: none;
}
:root[data-theme="light"] :is(.ghost, .flow, .layerbar, .panel) {
  color: var(--ink);
  background: var(--paper);
  border-color: var(--line);
  box-shadow: var(--elevation);
}
:root[data-theme="light"] :is(.ghost:hover, .flow-btn:hover, .panel-close:hover, .layer[aria-pressed="true"]) {
  color: var(--mint);
  background: var(--wash);
  border-color: var(--line);
}
:root[data-theme="light"] :is(.flow-head, .flow-btn, .tag strong, .tag.node.is-hot strong) { color: var(--ink); }
:root[data-theme="light"] :is(.flow-text, .map-tools label, .flow-jump, .layer, .tag small, .panel-purpose p:last-child, .panel-what) {
  color: var(--quiet);
}
:root[data-theme="light"] :is(.flow-head span, .failover-status, .panel-layer) { color: var(--mint); }
:root[data-theme="light"] :is(.map-tools select, .flow-jump select) {
  color: var(--ink);
  color-scheme: light;
  background: var(--bg);
  border-color: var(--line);
}
:root[data-theme="light"] :is(.tag, .tag.external, .tag.is-hot) {
  color: var(--ink);
  background: var(--paper);
  border-color: var(--line);
  text-shadow: none;
  box-shadow: none;
}
:root[data-theme="light"] .zone-label {
  color: var(--quiet) !important;
  text-shadow: none;
}
:root[data-theme="light"] .tag.node.is-offline small,
:root[data-theme="light"] .boot.is-error { color: #9a3027; }
:root[data-theme="light"] .boot { color: var(--quiet); background: var(--bg); }
:root[data-theme="light"] .vip-badge {
  color: var(--mint);
  background: #e2f4ed;
  border-color: #77aa9a;
}

:root[data-presentation="scroll"] .stage { min-height: 0; }
:root[data-presentation="scroll"] :is(.masthead, #flow, #map-mode) { display: none; }
:root[data-presentation="scroll"]:not([data-exploring="true"]) :is(.view-controls, .map-tools) { display: none; }
:root[data-presentation="scroll"] .view-controls { right: auto; left: 1rem; top: 1rem; }
:root[data-presentation="scroll"] .map-tools { right: auto; left: 1rem; top: 4rem; justify-items: start; }
:root[data-presentation="scroll"] .hint { display: none; }

/* Embedded scroll tour: let the portfolio page background and grid show through. */
:root[data-presentation="scroll"],
:root[data-presentation="scroll"] body,
:root[data-presentation="scroll"] .stage {
  background: transparent !important;
}
:root[data-presentation="scroll"] .stage::before { display: none; }
:root[data-presentation="scroll"] .boot { background: transparent !important; }

@media (max-width: 700px) {
  :root[data-presentation="scroll"] .tag {
    padding: 2px 5px;
    font-size: 11.5px;
    line-height: 1.2;
  }

  :root[data-presentation="scroll"] .tag.node strong { font-size: inherit; }

  :root[data-presentation="scroll"][data-theme="dark"] .tag {
    background: #0e1b26;
    border-color: #3b505e;
    color: #e9f2f6;
    text-shadow: none;
    backdrop-filter: none;
  }

  :root[data-presentation="scroll"] .vip-badge {
    padding: 0.18rem 0.4rem;
    translate: 0 -6px;
  }

  :root[data-presentation="scroll"][data-theme="dark"] .tag.is-hot {
    border-color: color-mix(in srgb, var(--brand) 66%, #3b505e);
  }
}
