﻿:root {
  --bg: #080a0d;
  --surface: rgba(14, 18, 24, 0.86);
  --surface-solid: #10151c;
  --border: rgba(154, 184, 200, 0.18);
  --text: #dce6ec;
  --muted: #8496a3;
  --accent-node: #62d8cf;
  --accent-edge: #e7b564;
  --danger: #e06c75;
  --font-mono: "JetBrains Mono", "Cascadia Code", "Consolas", monospace;
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --ui-scale: 1;
}

html {
  font-size: calc(16px * var(--ui-scale, 1));
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Top HUD */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.25rem;
  background: var(--surface-solid);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-width: 0;
}

.badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 0.32rem 0.65rem;
  border-radius: 4px;
  border: 1px solid currentColor;
  flex-shrink: 0;
}

.badge--node {
  color: var(--accent-node);
  background: rgba(98, 216, 207, 0.1);
}

.badge--edge {
  color: var(--accent-edge);
  background: rgba(231, 181, 100, 0.1);
}

.title-block {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.space-subtitle {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.space-title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.65rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.stat-label {
  color: var(--muted);
}

.stat-value {
  color: var(--text);
  font-weight: 600;
}

.stat-pill--btn {
  cursor: pointer;
  color: inherit;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.stat-pill--btn:hover {
  border-color: rgba(216, 180, 254, 0.65);
  background: rgba(216, 180, 254, 0.1);
}

.stat-pill--btn.has-relics .stat-value {
  color: #e9d5ff;
}

.space-subtitle-link {
  background: none;
  border: 0;
  padding: 0;
  color: #c4b5fd;
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
  text-decoration: underline dotted rgba(196, 181, 253, 0.55);
  text-underline-offset: 2px;
}

.space-subtitle-link:hover {
  color: #f3e8ff;
}

.hud-btn {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.36rem 0.75rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.hud-btn:hover {
  color: var(--text);
  border-color: rgba(154, 184, 200, 0.45);
}

.hud-btn.is-active {
  color: var(--accent-node);
  border-color: rgba(98, 216, 207, 0.5);
  background: rgba(98, 216, 207, 0.09);
}

.hud-btn--map {
  display: none;
}

/* Main stage */
.stage-wrapper {
  position: relative;
  min-height: 0;
  background: #050608;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  user-select: none;
}

.scene-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 1024 / 600;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
}

.scene-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  opacity: 0;
  transition: opacity 0.55s ease-in-out;
  filter: contrast(1.03) saturate(0.92);
}

.scene-img.is-visible {
  opacity: 1;
}

/* VHS / vignette overlays */
.overlay-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    transparent 48%,
    rgba(4, 6, 9, 0.65) 100%
  );
  z-index: 2;
}

.overlay-scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.14;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.06) 0px,
    rgba(255, 255, 255, 0.06) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 3;
}

/* Hotspots layer */
.hotspots-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
}

.hotspots-layer.is-hidden .hotspot-marker {
  opacity: 0.18;
}

.hotspots-layer.is-hidden .hotspot-marker:hover {
  opacity: 1;
}

.hotspot-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.4rem;
  transition: opacity 0.25s ease, transform 0.2s ease;
}

.hotspot-marker:hover {
  transform: translate(-50%, -50%) scale(1.06);
}

.hotspot-reticle {
  position: relative;
  width: calc(42px * var(--ui-scale, 1));
  height: calc(42px * var(--ui-scale, 1));
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.72);
  background: rgba(10, 14, 20, 0.45);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  box-shadow: 0 0 18px rgba(0, 0, 0, 0.55);
}

.hotspot-reticle::before {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 1px solid rgba(98, 216, 207, 0.45);
  animation: pulse-ring 2.4s infinite ease-out;
}

.hotspot-marker--edge .hotspot-reticle::before {
  border-color: rgba(231, 181, 100, 0.55);
}

.hotspot-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent-node);
  box-shadow: 0 0 10px var(--accent-node);
}

.hotspot-marker--edge .hotspot-dot {
  background: var(--accent-edge);
  box-shadow: 0 0 10px var(--accent-edge);
}

.hotspot-lucide {
  width: calc(20px * var(--ui-scale, 1));
  height: calc(20px * var(--ui-scale, 1));
  stroke-width: 2.2;
  color: var(--cluster-accent, var(--accent-node));
  filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.75));
}

.hotspot-marker--edge .hotspot-lucide {
  color: var(--cluster-accent, var(--accent-edge));
}

.hotspot-marker.has-cluster-icon .hotspot-reticle {
  border-color: var(--cluster-accent, rgba(255, 255, 255, 0.72));
}

.hotspot-marker.is-gateway .hotspot-reticle::before {
  border-color: var(--cluster-accent, rgba(231, 181, 100, 0.65));
}

.hotspot-cluster-tag {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.08rem 0.34rem;
  border-radius: 3px;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #070b10;
  background: var(--cluster-accent, var(--accent-edge));
  vertical-align: middle;
}

/* Bottom-center rectangular button for behind-camera transitions */
.behind-camera-dock {
  position: absolute;
  bottom: calc(14px * var(--ui-scale, 1));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem;
  max-width: min(92%, 720px);
  z-index: 5;
  pointer-events: auto;
}

.behind-camera-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: calc(0.42rem * var(--ui-scale, 1)) calc(0.75rem * var(--ui-scale, 1));
  border-radius: 6px;
  border: 1px solid var(--cluster-accent, rgba(231, 181, 100, 0.55));
  background: rgba(8, 11, 15, 0.88);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-family: var(--font-mono);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.behind-camera-btn:hover {
  transform: translateY(-2px);
  background: rgba(16, 22, 30, 0.95);
  border-color: var(--cluster-accent, var(--accent-edge));
}

.behind-camera-btn.is-origin {
  opacity: 0.46;
  filter: grayscale(0.88);
  border-style: dashed;
  border-color: rgba(132, 150, 163, 0.45);
}

.behind-camera-btn.is-origin:hover {
  opacity: 0.85;
  filter: grayscale(0.3);
}

.behind-camera-arrow {
  display: grid;
  place-items: center;
  width: calc(28px * var(--ui-scale, 1));
  height: calc(28px * var(--ui-scale, 1));
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  flex-shrink: 0;
}

.behind-arrow-lucide {
  width: calc(16px * var(--ui-scale, 1));
  height: calc(16px * var(--ui-scale, 1));
  stroke-width: 2.3;
  color: var(--cluster-accent, var(--accent-edge));
}

.behind-camera-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  line-height: 1.2;
}

.behind-camera-title {
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  font-size: calc(0.75rem * var(--ui-scale, 1));
  font-weight: 600;
  white-space: nowrap;
}

.behind-cluster-lucide {
  width: calc(13px * var(--ui-scale, 1));
  height: calc(13px * var(--ui-scale, 1));
  stroke-width: 2.2;
  color: var(--cluster-accent, var(--accent-node));
  flex-shrink: 0;
}

.behind-camera-hint {
  font-size: calc(0.62rem * var(--ui-scale, 1));
  color: var(--muted);
  margin-top: 0.12rem;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Environmental lore / inspect markers (smaller diamond, inherits location theme color) */
.hotspot-marker--inspect {
  z-index: 3;
}

.hotspot-marker--inspect .hotspot-reticle {
  width: calc(30px * var(--ui-scale, 1));
  height: calc(30px * var(--ui-scale, 1));
  padding: 0;
  border-radius: 6px;
  transform: rotate(45deg);
  border-color: var(--cluster-accent, var(--accent-node));
  background: rgba(10, 14, 20, 0.62);
  cursor: pointer;
}

.hotspot-marker--inspect .hotspot-reticle::before {
  display: none;
}

.hotspot-marker--inspect .hotspot-dot {
  width: 6px;
  height: 6px;
  border-radius: 2px;
  background: var(--cluster-accent, var(--accent-node));
  box-shadow: 0 0 8px var(--cluster-accent, var(--accent-node));
}

.hotspot-marker--inspect .hotspot-lucide {
  width: calc(15px * var(--ui-scale, 1));
  height: calc(15px * var(--ui-scale, 1));
  transform: rotate(-45deg);
  color: var(--cluster-accent, var(--accent-node));
}

.hotspot-marker--inspect .hotspot-label {
  font-size: 0.7rem;
  padding: 0.34rem 0.56rem;
  border-color: var(--cluster-accent, var(--border));
}

.hotspot-marker--inspect:not(.is-revealed) .inspect-card {
  display: none;
}

.hotspot-marker--inspect.is-revealed {
  z-index: 7;
}

.inspect-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.22rem;
}

.inspect-card-title {
  font-weight: 600;
  color: var(--text);
}

.inspect-closeup-btn {
  margin-top: 0.18rem;
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
  padding: 0.24rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--cluster-accent, var(--accent-node));
  background: rgba(255, 255, 255, 0.08);
  color: var(--cluster-accent, var(--accent-node));
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.14s ease, transform 0.14s ease;
}

.inspect-closeup-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}

.inspect-closeup-lucide {
  width: 12px;
  height: 12px;
  stroke-width: 2.2;
}

.hotspot-marker--inspect.has-closeup .hotspot-reticle {
  box-shadow: 0 0 14px color-mix(in srgb, var(--cluster-accent, #62d8cf) 55%, transparent);
}

.hotspot-marker--inspect.is-found .hotspot-reticle {
  background: color-mix(in srgb, var(--cluster-accent, #62d8cf) 20%, rgba(10, 14, 20, 0.78));
  box-shadow: 0 0 16px color-mix(in srgb, var(--cluster-accent, #62d8cf) 45%, transparent);
}

/* Inspect Close-Up Modal */
.inspect-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgba(5, 8, 12, 0.84);
  backdrop-filter: blur(10px);
}

.inspect-modal[hidden] {
  display: none;
}

.inspect-modal-card {
  width: min(680px, 94vw);
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.95rem 1.1rem;
  background: rgba(12, 16, 23, 0.96);
  border: 1px solid rgba(216, 180, 254, 0.45);
  border-radius: 10px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.8);
}

.inspect-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.inspect-modal-meta {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.badge--inspect {
  background: rgba(216, 180, 254, 0.16);
  color: #e9d5ff;
  border: 1px solid rgba(216, 180, 254, 0.45);
}

.inspect-modal-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.inspect-modal-close {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
}

.inspect-modal-close:hover {
  background: rgba(216, 180, 254, 0.18);
  border-color: #d8b4fe;
}

.inspect-modal-media {
  position: relative;
  width: min(66vh, 88vw, 620px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  overflow: hidden;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #06090d;
}

.inspect-modal-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.inspect-modal-desc {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: #f3e8ff;
}

.narrative-text.is-inspect-lore {
  color: #f3e8ff;
}

.hotspot-label {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  padding: 0.28rem 0.58rem;
  border-radius: 4px;
  background: rgba(8, 11, 15, 0.86);
  border: 1px solid var(--border);
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
}

.hotspot-hint {
  display: block;
  font-size: 0.64rem;
  color: var(--muted);
  margin-top: 0.1rem;
}

@keyframes pulse-ring {
  0% {
    transform: scale(0.9);
    opacity: 0.85;
  }
  100% {
    transform: scale(1.45);
    opacity: 0;
  }
}

/* K3 graph minimap */
.graph-map-panel {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: calc(245px * var(--ui-scale, 1));
  padding: 0.7rem 0.8rem;
  background: var(--surface);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 6;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  transition: width 0.2s ease, padding 0.2s ease;
}

.graph-map-panel.is-expanded {
  width: min(calc(480px * var(--ui-scale, 1)), calc(100% - 2rem));
  padding: 0.85rem 1rem;
  background: rgba(10, 15, 22, 0.94);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.75);
}

.graph-map-panel.is-expanded .map-cluster-name {
  max-width: 220px;
}

.graph-map-panel.is-minimized {
  width: auto;
  padding: 0.42rem 0.65rem;
  cursor: pointer;
}

.graph-map-panel.is-minimized .graph-map-header {
  margin-bottom: 0;
}

.graph-map-panel.is-minimized #graph-map,
.graph-map-panel.is-minimized .graph-legend,
.graph-map-panel.is-minimized .map-view-switch {
  display: none;
}

.graph-map-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.4rem;
  cursor: pointer;
  user-select: none;
}

.map-expand-btn,
.map-minimize-btn {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease;
}

.map-expand-btn:hover,
.map-minimize-btn:hover {
  background: rgba(98, 216, 207, 0.16);
  border-color: var(--accent-node);
}

.map-min-lucide {
  width: 13px;
  height: 13px;
  stroke-width: 2.2;
}

.map-cluster-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 105px;
}

.map-header-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.map-view-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.map-view-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.56rem;
  letter-spacing: 0.05em;
  padding: 0.14rem 0.34rem;
  cursor: pointer;
}

.map-view-btn.is-active {
  background: rgba(98, 216, 207, 0.18);
  color: var(--accent-node);
}

.map-mode {
  color: var(--accent-node);
  font-weight: 700;
}

.map-mode.is-edge {
  color: var(--accent-edge);
}

#graph-map {
  width: 100%;
  height: auto;
  display: block;
}

.graph-edge-line {
  stroke: rgba(132, 150, 163, 0.35);
  stroke-width: 2;
  transition: stroke 0.3s, stroke-width 0.3s;
}

.graph-edge-line.is-visited {
  stroke: rgba(231, 181, 100, 0.55);
}

.graph-edge-line.is-active {
  stroke: var(--accent-edge);
  stroke-width: 3.5;
  filter: drop-shadow(0 0 6px rgba(231, 181, 100, 0.7));
}

.graph-edge-pill {
  fill: #131922;
  stroke: rgba(132, 150, 163, 0.45);
  stroke-width: 1.5;
  cursor: pointer;
  transition: fill 0.25s, stroke 0.25s;
}

.graph-edge-pill.is-active {
  fill: rgba(231, 181, 100, 0.22);
  stroke: var(--accent-edge);
  stroke-width: 2;
}

.graph-node-circle {
  fill: #111720;
  stroke: rgba(132, 150, 163, 0.55);
  stroke-width: 2;
  cursor: pointer;
  transition: fill 0.25s, stroke 0.25s, r 0.25s;
}

.graph-node-circle.is-visited {
  stroke: rgba(98, 216, 207, 0.65);
}

.graph-node-circle.is-active {
  fill: rgba(98, 216, 207, 0.22);
  stroke: var(--accent-node);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 8px rgba(98, 216, 207, 0.75));
}

.graph-map-panel.is-dev {
  border-color: rgba(231, 181, 100, 0.7);
  box-shadow: 0 0 0 1px rgba(231, 181, 100, 0.25), 0 10px 30px rgba(0, 0, 0, 0.55);
}

.graph-map-panel.is-dev .graph-node-circle:hover,
.graph-map-panel.is-dev .graph-edge-pill:hover {
  stroke: #ffffff;
  stroke-width: 2.5;
}

.graph-map-panel.is-dev .graph-edge-line {
  cursor: pointer;
}

.graph-map-panel.is-dev .graph-edge-line:hover {
  stroke: rgba(231, 181, 100, 0.9);
  stroke-width: 3.5;
}

.graph-label,
.graph-sub-label {
  pointer-events: none;
}

.graph-edge-line.is-gateway {
  stroke-dasharray: 4 3;
  stroke-width: 1.8;
}

.graph-gateway-pill {
  fill: #131922;
  stroke-width: 1.6;
  cursor: pointer;
  transition: fill 0.2s, stroke 0.2s;
}

.graph-gateway-pill.is-active {
  fill: rgba(231, 181, 100, 0.22);
}

.graph-cluster-circle {
  fill: #111720;
  stroke-width: 2.2;
  cursor: pointer;
  transition: fill 0.25s, stroke 0.25s, r 0.25s;
}

.graph-cluster-circle.is-active {
  fill: rgba(98, 216, 207, 0.18);
  filter: drop-shadow(0 0 8px rgba(98, 216, 207, 0.5));
}

.graph-cluster-sub {
  font-family: var(--font-mono);
  font-size: 7.5px;
  fill: var(--muted);
  text-anchor: middle;
  pointer-events: none;
}

.graph-label {
  font-family: var(--font-mono);
  font-size: 9px;
  fill: var(--text);
  text-anchor: middle;
  pointer-events: none;
}

.graph-sub-label {
  font-family: var(--font-mono);
  font-size: 7.5px;
  fill: var(--muted);
  text-anchor: middle;
  pointer-events: none;
}

.graph-legend {
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--muted);
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 4px;
}

.dot--node {
  background: var(--accent-node);
}

.dot--edge {
  background: var(--accent-edge);
}

/* Bottom narrative bar */
.narrative-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.6rem;
  padding: 0.75rem 1.25rem 0.85rem;
  background: var(--surface-solid);
  border-top: 1px solid var(--border);
  z-index: 10;
}

.narrative-text {
  font-size: 0.9rem;
  line-height: 1.48;
  color: #cbd7df;
  max-width: 105ch;
}

.quick-actions {
  display: flex;
  align-items: stretch;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.action-btn {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  padding: 0.5rem 0.9rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}

.action-btn:hover {
  border-color: var(--accent-node);
  background: rgba(98, 216, 207, 0.1);
  transform: translateY(-1px);
}

.action-btn--edge:hover {
  border-color: var(--accent-edge);
  background: rgba(231, 181, 100, 0.12);
}


/* --- Shared: action cards, section labels, icon buttons --- */
.btn-icon {
  display: none;
}

.actions-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-shrink: 0;
}

.section-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.mobile-map-slot {
  display: none;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-align: left;
}

.action-btn.is-right {
  text-align: right;
}

.action-arrow {
  font-size: 1.05rem;
  line-height: 1;
  color: var(--accent-edge);
  flex-shrink: 0;
}

.action-btn--node .action-arrow {
  color: var(--accent-node);
}

.action-btn--back {
  border-color: rgba(148, 163, 184, 0.5);
  background: rgba(148, 163, 184, 0.1);
}

.action-btn--back .action-arrow {
  color: #e2e8f0;
  font-size: 1.15rem;
}

.action-btn--back:hover {
  border-color: #e2e8f0;
  background: rgba(148, 163, 184, 0.18);
}

.action-body {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  min-width: 0;
}

.action-title {
  font-weight: 600;
  color: var(--text);
}

.action-sub {
  font-size: 0.66rem;
  color: var(--muted);
  font-family: var(--font-sans);
}

/* --- Tablet --- */
@media (max-width: 820px) {
  .graph-map-panel {
    width: 190px;
    top: 0.6rem;
    right: 0.6rem;
    padding: 0.5rem;
  }

  .narrative-bar {
    flex-direction: column;
    align-items: stretch;
  }
}

/* --- Phone, portrait: HUD / full-width 1024:600 scene / scrolling info panel --- */
@media (max-width: 640px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  /* Compact HUD: title row + one slim stats/controls row */
  .hud-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
    padding: 0.55rem 0.8rem 0.5rem;
    flex-shrink: 0;
  }

  .hud-left {
    gap: 0.6rem;
  }

  .badge {
    font-size: 0.6rem;
    padding: 0.24rem 0.45rem;
  }

  .space-subtitle {
    font-size: 0.58rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .space-title {
    font-size: 1rem;
  }

  .hud-right {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.35rem;
    align-items: stretch;
  }

  .stat-pill {
    flex: 1 1 0;
    min-width: 0;
    justify-content: space-between;
    padding: 0.3rem 0.5rem;
    font-size: 0.64rem;
    white-space: nowrap;
  }

  .stat-label {
    font-size: 0.56rem;
    letter-spacing: 0.08em;
  }

  .hud-btn {
    flex: 0 0 auto;
    width: 36px;
    min-height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .hud-btn .btn-text {
    display: none;
  }

  .hud-btn .btn-icon {
    display: inline;
    font-size: 0.95rem;
    line-height: 1;
  }

  /* Scene: exact 1024:600 frame, full width, never cropped */
  .stage-wrapper {
    flex: 0 0 auto;
    width: 100%;
    aspect-ratio: 1024 / 600;
    border-bottom: 1px solid var(--border);
  }

  .stage {
    width: 100%;
    height: 100%;
  }

  .overlay-vignette {
    background: radial-gradient(ellipse at center, transparent 60%, rgba(4, 6, 9, 0.5) 100%);
  }

  /* Markers: compact reticle, short label, large tap area */
  .hotspot-marker {
    padding: 0.6rem;
    gap: 0.18rem;
  }

  .hotspot-reticle {
    width: 26px;
    height: 26px;
    border-width: 1.5px;
  }

  .hotspot-reticle::before {
    inset: -5px;
  }

  .hotspot-dot {
    width: 7px;
    height: 7px;
  }

  .hotspot-label {
    font-size: 0.56rem;
    padding: 0.12rem 0.34rem;
    border-radius: 3px;
    max-width: 34vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .hotspot-hint {
    display: none;
  }

  /* Keep labels of edge markers inside the frame */
  .hotspot-marker.near-right .hotspot-label {
    transform: translateX(-28%);
  }

  .hotspot-marker.near-left .hotspot-label {
    transform: translateX(28%);
  }

  /* Info panel fills the remaining height and scrolls */
  .narrative-bar {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 0.9rem;
    padding: 0.85rem 0.85rem calc(0.9rem + env(safe-area-inset-bottom));
    overflow-y: auto;
    border-top: none;
  }

  .narrative-text {
    font-size: 0.84rem;
    line-height: 1.5;
    color: #b9c7d1;
    max-width: none;
  }

  .actions-block {
    gap: 0.45rem;
  }

  .quick-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .action-btn {
    width: 100%;
    min-height: 58px;
    padding: 0.55rem 0.65rem;
    font-size: 0.74rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.035);
    align-items: center;
  }

  .action-btn--edge {
    border-color: rgba(231, 181, 100, 0.32);
  }

  .action-btn--node {
    border-color: rgba(98, 216, 207, 0.32);
  }

  .action-btn.is-right {
    justify-content: flex-end;
  }

  .action-arrow {
    font-size: 1.15rem;
  }

  .action-title {
    font-size: 0.74rem;
    line-height: 1.25;
  }

  .action-sub {
    font-size: 0.64rem;
    line-height: 1.25;
  }

  /* Minimap lives inline below the exits */
  .mobile-map-slot {
    display: block;
  }

  .mobile-map-slot .graph-map-panel {
    position: static;
    width: 100%;
    max-width: 340px;
    margin: 0 auto;
    padding: 0.6rem 0.75rem;
    background: rgba(255, 255, 255, 0.025);
    backdrop-filter: none;
    box-shadow: none;
  }

  .mobile-map-slot #graph-map {
    max-height: 170px;
  }
}

/* --- Phone, landscape: scene fills the screen, HUD + exits overlay it --- */
@media (max-height: 500px) and (orientation: landscape) {
  .app-shell {
    position: relative;
    display: block;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .stage-wrapper {
    position: absolute;
    inset: 0;
    aspect-ratio: auto;
    border: none;
  }

  .hud-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem calc(0.7rem + env(safe-area-inset-right)) 0.4rem calc(0.7rem + env(safe-area-inset-left));
    background: linear-gradient(to bottom, rgba(8, 10, 13, 0.85), rgba(8, 10, 13, 0));
    border-bottom: none;
    z-index: 15;
  }

  .space-subtitle {
    display: none;
  }

  .space-title {
    font-size: 0.9rem;
  }

  .hud-right {
    display: flex;
    gap: 0.3rem;
  }

  .stat-pill {
    padding: 0.22rem 0.45rem;
    font-size: 0.62rem;
  }

  .hud-btn {
    width: 32px;
    min-height: 28px;
    padding: 0;
  }

  .hud-btn .btn-text {
    display: none;
  }

  .hud-btn .btn-icon {
    display: inline;
  }

  .graph-map-panel {
    display: none;
  }

  .narrative-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    flex-direction: row;
    align-items: flex-end;
    padding: 0.5rem calc(0.7rem + env(safe-area-inset-right)) calc(0.5rem + env(safe-area-inset-bottom)) calc(0.7rem + env(safe-area-inset-left));
    background: linear-gradient(to top, rgba(8, 10, 13, 0.9), rgba(8, 10, 13, 0));
    border-top: none;
    z-index: 15;
    overflow: visible;
  }

  .narrative-text,
  .section-label,
  .mobile-map-slot {
    display: none;
  }

  .actions-block {
    width: 100%;
  }

  .quick-actions {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
  }

  .action-btn {
    min-height: 40px;
    padding: 0.4rem 0.65rem;
    font-size: 0.7rem;
    background: rgba(8, 11, 15, 0.8);
  }

  .action-sub {
    display: none;
  }
}

/* --- Origin ("came from here") visual distinction --- */
.hotspot-marker.is-origin {
  opacity: 0.44;
  filter: grayscale(0.9);
  transition: opacity 0.15s ease, filter 0.15s ease, transform 0.15s ease;
}

.hotspot-marker.is-origin:hover {
  opacity: 0.82;
  filter: grayscale(0.35);
}

.hotspot-marker.is-origin .hotspot-reticle {
  border-style: dashed;
  border-color: rgba(132, 150, 163, 0.65);
  background: rgba(10, 14, 20, 0.35);
}

.hotspot-marker.is-origin .hotspot-reticle::before {
  animation: none;
  border-color: rgba(132, 150, 163, 0.3);
}

.hotspot-marker.is-origin .hotspot-dot {
  background: var(--muted);
  box-shadow: none;
}

.hotspot-marker.is-origin .hotspot-lucide {
  color: var(--muted);
  filter: none;
}

.hotspot-marker.is-origin .hotspot-cluster-tag {
  background: rgba(132, 150, 163, 0.75);
}

.hotspot-marker.is-origin .hotspot-label {
  border-style: dashed;
  color: var(--muted);
}

.action-btn.is-origin {
  opacity: 0.45;
  filter: grayscale(0.85);
  border-style: dashed;
  border-color: rgba(132, 150, 163, 0.4);
}

.action-btn.is-origin:hover {
  opacity: 0.82;
  filter: grayscale(0.3);
}

.action-btn.is-origin .action-arrow {
  color: var(--muted);
}

/* Interface Settings & Maximize / Zen modes */
.app-shell.is-header-hidden .hud-bar {
  display: none;
}

.app-shell.is-footer-hidden .narrative-bar {
  display: none;
}

.floating-restore-btn {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 35;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0.68;
  transition: opacity 0.2s, border-color 0.2s;
}

.floating-restore-btn[hidden] {
  display: none;
}

.floating-restore-btn:hover {
  opacity: 1;
  border-color: var(--accent-node);
}

.settings-popover {
  position: fixed;
  top: 3.35rem;
  right: 1rem;
  width: min(290px, calc(100vw - 2rem));
  padding: 0.85rem 0.95rem;
  background: rgba(14, 18, 24, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 40;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.settings-popover[hidden] {
  display: none;
}

.app-shell.is-header-hidden .settings-popover {
  top: 3.25rem;
  left: 0.75rem;
  right: auto;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.settings-close {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.1rem 0.25rem;
}

.settings-close:hover {
  color: var(--text);
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.settings-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.scale-pills {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.3rem;
}

.scale-pill {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 0.32rem 0.2rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  cursor: pointer;
}

.scale-pill.is-active {
  color: var(--accent-node);
  border-color: rgba(98, 216, 207, 0.55);
  background: rgba(98, 216, 207, 0.14);
}

.settings-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
}

.settings-toggle input {
  accent-color: var(--accent-node);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.settings-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  padding-top: 0.2rem;
}

.settings-action-btn {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 0.42rem 0.65rem;
  border-radius: 5px;
  border: 1px solid rgba(98, 216, 207, 0.45);
  background: rgba(98, 216, 207, 0.12);
  color: var(--accent-node);
  cursor: pointer;
}

.settings-action-btn--ghost {
  border-color: var(--border);
  background: transparent;
  color: var(--muted);
}

/* --- Hierarchical sublocations & direct node transitions --- */
.badge--subnode {
  border-color: rgba(167, 139, 250, 0.55);
  background: rgba(167, 139, 250, 0.14);
  color: #c4b5fd;
}

.hotspot-marker--zoom .hotspot-reticle {
  border-color: rgba(167, 139, 250, 0.8);
  background: rgba(20, 18, 36, 0.72);
}

.hotspot-marker--zoom .hotspot-reticle::before {
  border-color: rgba(167, 139, 250, 0.55);
}

.hotspot-marker--zoom .hotspot-lucide {
  color: var(--cluster-accent, #c4b5fd);
}

.action-btn--zoom {
  border-color: rgba(167, 139, 250, 0.35);
}

.action-btn--zoom:hover {
  border-color: rgba(167, 139, 250, 0.75);
  background: rgba(167, 139, 250, 0.12);
}

.action-btn--zoom .action-arrow {
  color: #c4b5fd;
}

/* Empty map overlay (v2 shell before assets are generated) */
.empty-map-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: radial-gradient(circle at center, rgba(16, 24, 36, 0.85) 0%, rgba(6, 9, 13, 0.96) 100%);
}

.empty-map-overlay[hidden] {
  display: none;
}

.empty-map-card {
  max-width: min(520px, 92%);
  padding: 1.25rem 1.4rem;
  border-radius: 10px;
  border: 1px solid rgba(98, 216, 207, 0.32);
  background: rgba(10, 14, 20, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}

.empty-map-title {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  color: var(--accent-node);
}

.empty-map-text {
  font-size: 0.85rem;
  line-height: 1.5;
  color: #cbd7df;
}

.empty-map-clusters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

.empty-cluster-chip {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 0.2rem 0.48rem;
  border-radius: 4px;
  border: 1px solid var(--chip-accent, var(--border));
  color: var(--chip-accent, var(--text));
  background: rgba(255, 255, 255, 0.03);
}

/* Discovery Codex Modal */
.codex-modal-card {
  width: min(820px, 95vw);
  max-height: 90vh;
}

.badge--codex {
  background: rgba(98, 216, 207, 0.14);
  color: var(--accent-node);
  border: 1px solid rgba(98, 216, 207, 0.45);
}

.codex-summary {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.codex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 0.75rem;
  overflow-y: auto;
  padding-right: 0.25rem;
  max-height: 64vh;
}

.codex-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  text-align: left;
  color: var(--text);
}

.codex-card.is-found {
  border-color: var(--card-accent, rgba(98, 216, 207, 0.45));
  background: rgba(255, 255, 255, 0.05);
}

.codex-card.is-locked {
  opacity: 0.55;
  border-style: dashed;
}

.codex-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.codex-card-cluster {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--card-accent, var(--muted));
}

.codex-card-type {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  color: #e9d5ff;
}

.codex-card-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #06090d;
  display: grid;
  place-items: center;
}

.codex-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.codex-card-title {
  font-size: 0.82rem;
  font-weight: 600;
}

.codex-card-loc {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--muted);
}

.codex-card-btn {
  margin-top: auto;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--card-accent, var(--accent-node));
  background: rgba(255, 255, 255, 0.06);
  color: var(--card-accent, var(--accent-node));
  font-family: var(--font-mono);
  font-size: 0.66rem;
  cursor: pointer;
}

.codex-card-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.graph-edge-line.is-direct {
  stroke-dasharray: 3 3;
}

.graph-subcount-bg {
  fill: #1b2434;
  stroke: rgba(167, 139, 250, 0.85);
  stroke-width: 1.5;
  pointer-events: none;
}

.graph-subcount-text {
  fill: #e9d5ff;
  font-family: var(--font-mono);
  font-size: 8.5px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}
