﻿: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;
}

* {
  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;
}

.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: 42px;
  height: 42px;
  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-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: 245px;
  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);
}

.graph-map-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);
  margin-bottom: 0.4rem;
}

.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-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;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 0.85rem 1.25rem;
  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: 82ch;
}

.quick-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
  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-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;
  }
}
