:root {
  color-scheme: dark;
  --bg: #090b10;
  --fg: #d7d9d4;
  --muted: #848a8f;
  --line: rgba(215, 217, 212, 0.09);
  --accent: #96a86f;
  --accent-dim: #5f7867;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  position: relative;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: "JetBrains Mono", ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  font-weight: 400;
}

#back-link {
  position: absolute;
  z-index: 20;
  top: 12px;
  left: 12px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
}

.hud {
  position: absolute;
  z-index: 20;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  text-align: center;
  width: min(720px, calc(100vw - 120px));
}

.hud-kicker,
.hud-subtitle,
.hud-instructions {
  margin: 0;
}

.hud-kicker {
  color: var(--fg);
  font-size: clamp(16px, 3.4vw, 24px);
  font-weight: 300;
  letter-spacing: 0.46em;
  padding-left: 0.46em;
}

.hud-subtitle {
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: 0.05em;
}

.hud-instructions {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: 0.02em;
  opacity: 0.8;
}

/* ---- stage & world ---- */

#stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-image: radial-gradient(circle, rgba(215, 217, 212, 0.055) 1px, transparent 1.6px);
  background-size: 26px 26px;
  cursor: grab;
  touch-action: none;
}

body.panning,
body.panning #stage,
body.panning .node {
  cursor: grabbing;
}

#field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#stage::before,
#stage::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 110px;
  z-index: 5;
  pointer-events: none;
}

#stage::before {
  left: 0;
  background: linear-gradient(to right, var(--bg), transparent);
}

#stage::after {
  right: 0;
  background: linear-gradient(to left, var(--bg), transparent);
}

#world {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
}

#wires {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
}

#wires path {
  fill: none;
  stroke: var(--line);
  stroke-width: 1;
  transition: stroke 0.5s ease;
}

#wires path.on-path {
  stroke: rgba(150, 168, 111, 0.5);
}

#wires path.candidate {
  stroke: rgba(215, 217, 212, 0.2);
}

#wires path.ghost {
  stroke: rgba(215, 217, 212, 0.06);
}

/* ---- nodes ---- */

.node {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--node-w, 300px);
  padding: 8px 10px;
  border-radius: 2px;
  transition: opacity 0.6s ease, background 0.25s ease;
  will-change: transform;
}

.node-text {
  font-size: 12.5px;
  line-height: 1.6;
  font-weight: 300;
  letter-spacing: 0.01em;
  color: var(--fg);
  min-height: 1.6em;
  outline: none;
}

.node-text span {
  transition: opacity 0.3s ease;
}

.node.head .node-text {
  color: #eceee9;
  font-weight: 400;
}

.node-meta {
  margin-top: 6px;
  font-size: 9.5px;
  letter-spacing: 0.14em;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.4s ease;
  text-transform: uppercase;
}

.node.candidate .node-meta,
.node.seed-editable .node-meta {
  opacity: 0.75;
}

.node-badge {
  position: absolute;
  left: -24px;
  top: 8px;
  font-size: 10px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.node.candidate .node-badge {
  opacity: 0.9;
}

.node.candidate {
  cursor: pointer;
}

.node.candidate:hover {
  background: rgba(150, 168, 111, 0.07);
}

.node.candidate:hover .node-badge {
  color: var(--accent);
}

.node.ghost {
  opacity: 0.18;
  cursor: pointer;
}

.node.ghost:hover {
  opacity: 0.45;
}

.node.on-path:not(.head) {
  opacity: 0.62;
  cursor: pointer;
}

.node.on-path:not(.head):hover {
  opacity: 0.85;
}

.node.seed-editable .node-text {
  cursor: text;
  border-bottom: 1px dashed rgba(215, 217, 212, 0.18);
  padding-bottom: 4px;
}

.node.streaming .node-text::after {
  content: "\258C";
  margin-left: 2px;
  color: var(--accent);
  animation: blink 0.9s steps(2, start) infinite;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

/* The leaf: deepest reachable node. A quiet caption marks the dead-end so it
   reads as the bottom of the tree rather than a disabled control. */
.node.leaf.head::after {
  /* Double space after each \-escape: the first space terminates the escape,
     the second is the literal separator we actually want. */
  content: "leaf \00B7  \2190  to walk back";
  position: absolute;
  left: 10px;
  top: calc(100% - 4px);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-dim);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  animation: leaf-rise 0.6s ease 0.05s forwards;
}

@keyframes leaf-rise {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }
  to {
    opacity: 0.7;
    transform: translateY(0);
  }
}

/* ---- chrome ---- */

#minimap {
  position: absolute;
  z-index: 20;
  left: 16px;
  bottom: 16px;
  width: 160px;
  height: 90px;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

#minimap.visible {
  opacity: 0.85;
}

#minimap circle {
  fill: rgba(215, 217, 212, 0.25);
}

#minimap circle.on-path {
  fill: var(--accent-dim);
}

#minimap circle.head {
  fill: var(--accent);
}

#minimap path {
  fill: none;
  stroke: rgba(215, 217, 212, 0.12);
  stroke-width: 1;
  stroke-linecap: round;
  transition: stroke 0.5s ease;
}

#minimap path.on-path {
  stroke: rgba(150, 168, 111, 0.55);
  stroke-width: 1.3;
}

#status {
  position: absolute;
  z-index: 20;
  right: 16px;
  bottom: 16px;
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--muted);
  opacity: 0.8;
  pointer-events: none;
}

#controls {
  position: absolute;
  z-index: 20;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
}

#branch-btn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.12em;
  padding: 7px 16px;
  cursor: pointer;
  transition: color 0.25s ease, border-color 0.25s ease;
}

#branch-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: rgba(150, 168, 111, 0.4);
}

#branch-btn:disabled {
  cursor: default;
  opacity: 0.55;
}

/* ---- mobile ---- */

@media (max-width: 700px) {
  .hud {
    width: calc(100vw - 24px);
  }

  .hud-kicker {
    font-size: 14px;
  }

  .hud-subtitle {
    display: none;
  }

  .hud-instructions {
    font-size: 9px;
  }

  .node-text {
    font-size: 12px;
  }

  #minimap {
    width: 120px;
    height: 68px;
    left: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  #status {
    font-size: 9px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  #controls {
    bottom: calc(14px + env(safe-area-inset-bottom));
  }
}

/* ---- embed mode ---- */

body.is-embed #back-link {
  display: none;
}

body.is-embed .hud-kicker {
  font-size: 15px;
}

body.is-embed .hud-subtitle {
  display: none;
}
