:root {
  color-scheme: dark;
  --bg: #07080d;
  --bg-veil: rgba(7, 8, 13, 0.68);
  --bg-panel: rgba(8, 10, 17, 0.54);
  --bg-panel-strong: rgba(10, 12, 20, 0.82);
  --fg: #f3f4f8;
  --fg-dim: rgba(243, 244, 248, 0.7);
  --fg-muted: rgba(243, 244, 248, 0.48);
  --line: rgba(243, 244, 248, 0.18);
  --line-strong: rgba(243, 244, 248, 0.32);
  --accent: #b8c5ff;
  --accent-soft: rgba(184, 197, 255, 0.18);
  --accent-secondary: #eef2ff;
  --shadow: 0 32px 80px rgba(0, 0, 0, 0.35);
  --hero-dip-x: 0px;
  --hero-dip-y: 0px;
  --hero-dip-x-soft: 0px;
  --hero-dip-y-soft: 0px;
  --hero-dip-x-reverse: 0px;
  --hero-dip-y-reverse: 0px;
  --panel-blur: 18px;
  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  --font-ui: "SF Mono", "IBM Plex Mono", "Roboto Mono", "Menlo", monospace;
  --font-body: "Avenir Next", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at 18% 16%, rgba(255, 255, 255, 0.04), transparent 28%),
    radial-gradient(circle at 84% 74%, rgba(255, 255, 255, 0.03), transparent 32%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 18%),
    var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  overflow-x: hidden;
  overflow-y: auto;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 22%),
    linear-gradient(0deg, rgba(255, 255, 255, 0.018), transparent 18%),
    repeating-linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0.02) 0,
      rgba(255, 255, 255, 0.02) 1px,
      transparent 2px,
      transparent 5px
    );
  mix-blend-mode: screen;
  opacity: 0.42;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.world-shell {
  position: relative;
  min-height: 100vh;
}

.world-canvas,
.overlay-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.world-canvas {
  z-index: 0;
  cursor: grab;
  touch-action: none;
}

.world-canvas.is-dragging {
  cursor: grabbing;
}

.overlay-canvas {
  z-index: 1;
  pointer-events: none;
}

.geo-hud {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 4;
  display: flex;
  flex-direction: row;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 9px;
  line-height: 1.5;
  opacity: 0.34;
  pointer-events: none;
  user-select: none;
  color: var(--fg);
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(5, 8, 13, 0.26);
  backdrop-filter: blur(6px);
  transition: opacity 300ms ease, background-color 300ms ease, border-color 300ms ease;
}

.geo-hud:hover {
  opacity: 0.62;
  background: rgba(5, 8, 13, 0.34);
  border-color: rgba(255, 255, 255, 0.12);
}

.geo-col {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.geo-row {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.geo-label {
  color: var(--fg-muted);
  min-width: 1em;
  text-align: right;
}

.geo-val {
  min-width: 4.5em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.atmo-val {
  transition: color 600ms ease, opacity 600ms ease;
}

.shell {
  position: relative;
  z-index: 3;
  min-height: 100vh;
  padding: 18px;
  display: grid;
  grid-template-columns: minmax(320px, 520px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  pointer-events: none;
}

.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg-panel);
  backdrop-filter: blur(var(--panel-blur));
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.panel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(130deg, rgba(255, 255, 255, 0.08), transparent 34%),
    radial-gradient(circle at 100% 0%, var(--accent-soft), transparent 42%);
  opacity: 0.7;
}

.hero {
  align-self: start;
  padding: 18px;
  min-height: 0;
  width: min(520px, calc(100vw - 36px));
}

.hero-tree {
  display: grid;
  gap: 0;
}

.tree-root {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(2.8rem, 7vw, 6.8rem);
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: 0.04em;
  color: var(--fg);
  margin-bottom: 20px;
  transition: color 180ms ease;
}

.tree-root:hover,
.tree-root:focus-visible {
  color: var(--accent);
}

.tree-root-hex {
  opacity: 0.36;
  font-weight: 300;
}

.tree-root-d,
.tree-root-a {
  display: inline-block;
  transition: transform 400ms ease;
}

/* Hover D1 → flip D2 vertically (X axis) */
.tree-root-d1:hover ~ .tree-root-d2 {
  transform: scaleY(-1);
}

/* Hover D2 → flip D1 vertically (X axis) */
.tree-root:has(.tree-root-d2:hover) .tree-root-d1 {
  transform: scaleY(-1);
}

/* A: Y-axis rotation controlled by JS */
.tree-root-a {
  transform-style: preserve-3d;
}

.tree-root-four {
  display: inline-block;
  position: relative;
  color: var(--accent);
}

.tree-root-four-base {
  display: inline-block;
  transition: transform 360ms ease, font-size 360ms ease;
}

.tree-root-four:hover .tree-root-four-base {
  transform: translate(-0.06em, 0.08em) scale(0.78);
}

.tree-root-four:has(.is-left):hover .tree-root-four-base {
  transform: translate(0.06em, 0.08em) scale(0.78);
}

.tree-root-four-sup {
  position: absolute;
  top: 0.08em;
  right: -0.08em;
  left: auto;
  font-size: 0.38em;
  font-weight: 300;
  opacity: 0;
  color: var(--accent);
  transition: opacity 360ms ease, transform 360ms ease, left 360ms ease, right 360ms ease;
  transform: translateY(0.3em);
  pointer-events: none;
}

.tree-root-four-sup.is-left {
  right: auto;
  left: -0.08em;
}

.tree-root-four:hover .tree-root-four-sup {
  opacity: 0.8;
  transform: translateY(0);
}

.tree-subtitle {
  display: flex;
  align-items: center;
  min-height: 1.6em;
  margin-bottom: 12px;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: lowercase;
  color: var(--fg-dim);
}

.tree-subtitle-text {
  white-space: nowrap;
}

.tree-subtitle-text b {
  font-weight: 600;
  color: var(--fg);
}

.tree-cursor {
  display: inline-block;
  margin-left: 1px;
  font-weight: 300;
  color: var(--accent);
  animation: blink-cursor 1s step-end infinite;
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.tree-branches {
  display: grid;
  gap: 4px;
}

.tree-node {
  display: block;
  padding: 8px 0 2px;
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-muted);
  transition: color 180ms ease;
}

.tree-node b {
  font-weight: 700;
  color: var(--fg);
}

.tree-node.is-active {
  color: var(--accent);
}

.tree-node.is-active b {
  color: var(--accent-secondary);
}

.tree-leaves {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 8px;
}

.tree-leaf {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg);
  cursor: pointer;
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms ease;
}

.tree-leaf:hover,
.tree-leaf:focus-visible {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
}

.tree-leaf.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 12px 24px rgba(0, 0, 0, 0.18);
}

.tree-leaf.is-active::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.contact-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

.contact-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
  transition:
    border-color 180ms ease,
    background-color 180ms ease;
}

.contact-pill:hover {
  border-color: var(--accent);
}

.contact-pill-copy {
  display: inline-block;
  max-width: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--fg-dim);
  font-family: var(--font-ui);
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  opacity: 0;
  transition:
    max-width 320ms ease,
    padding 320ms ease,
    opacity 240ms ease,
    color 180ms ease;
}

.contact-pill:hover .contact-pill-copy {
  max-width: 8em;
  padding: 0 12px 0 12px;
  opacity: 1;
}

.contact-pill-copy:hover {
  color: var(--fg);
}

.contact-pill-divider {
  display: inline-block;
  width: 1px;
  height: 12px;
  background: var(--line);
  opacity: 0;
  overflow: hidden;
  max-width: 0;
  vertical-align: middle;
  transition: max-width 320ms ease, opacity 240ms ease;
}

.contact-pill:hover .contact-pill-divider {
  max-width: 1px;
  opacity: 1;
}

.contact-pill-mailto {
  padding: 9px 12px;
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.08em;
  text-decoration: none;
  white-space: nowrap;
  transition: color 180ms ease;
}

.contact-pill-mailto:hover {
  color: var(--accent);
}

.contact-pill-proto {
  display: inline;
  opacity: 0;
  letter-spacing: -0.5em;
  font-size: 0;
  transition: opacity 240ms ease, letter-spacing 320ms ease, font-size 320ms ease;
}

.contact-pill:hover .contact-pill-proto {
  opacity: 1;
  letter-spacing: inherit;
  font-size: inherit;
}

.advanced-controls {
  margin-top: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.advanced-controls summary {
  cursor: pointer;
  list-style: none;
  padding: 12px 14px;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-dim);
  user-select: none;
}

.advanced-controls summary::-webkit-details-marker {
  display: none;
}

.advanced-controls[open] summary {
  border-bottom: 1px solid var(--line);
  color: var(--fg);
}

.advanced-controls-body {
  padding: 14px;
  display: grid;
  gap: 14px;
}

.mode-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.mode-group {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.mode-row,
.secondary-controls,
.alpha-modes,
.renderer-modes {
  display: grid;
  gap: 8px;
}

.mode-row {
  grid-template-columns: 1fr 1fr;
}

.secondary-controls {
  grid-template-columns: 1fr 1fr;
}

.alpha-modes,
.renderer-modes {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mode-control,
.alpha-mode,
.renderer-mode,
.secondary-controls button {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--fg);
  padding: 10px 12px;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    border-color 180ms ease,
    background-color 180ms ease;
}

.mode-control:hover,
.mode-control:focus-visible,
.alpha-mode:hover,
.alpha-mode:focus-visible,
.renderer-mode:hover,
.renderer-mode:focus-visible,
.secondary-controls button:hover,
.secondary-controls button:focus-visible {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
}

.alpha-mode[aria-pressed="true"],
.renderer-mode[aria-pressed="true"] {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.1);
}

.mode-label {
  color: var(--fg-muted);
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
}

.arrival-detail {
  padding: 18px;
  position: fixed;
  z-index: 6;
  right: 18px;
  bottom: 18px;
  width: min(360px, calc(100vw - 36px));
  border: 1px solid var(--line);
  background: var(--bg-panel-strong);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  pointer-events: auto;
  opacity: 0;
  transition:
    opacity 220ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.arrival-detail.visible {
  opacity: 1;
}

.arrival-detail.is-route-detail {
  border-color: var(--line-strong);
}

.arrival-detail.is-node-detail {
  border-color: var(--accent);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.05),
    0 0 0 10px rgba(255, 255, 255, 0.015),
    var(--shadow);
}

.detail-source {
  margin-bottom: 10px;
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-secondary);
}

.arrival-detail h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.4rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.arrival-detail p {
  margin: 10px 0 0;
  color: var(--fg-dim);
  font-size: 0.92rem;
  line-height: 1.55;
}

.detail-destinations {
  margin-top: 16px;
  display: grid;
  gap: 10px;
}

.detail-section {
  display: grid;
  gap: 10px;
  padding-top: 2px;
}

.detail-section + .detail-section {
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.detail-section-heading {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg);
}

.detail-section-copy {
  margin: 0;
  color: var(--fg-dim);
  font-size: 0.82rem;
  line-height: 1.45;
}

.detail-section-destinations {
  display: grid;
  gap: 10px;
}

.detail-destination {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  transition:
    border-color 180ms ease,
    background-color 180ms ease;
}

.detail-destination:hover,
.detail-destination:focus-visible {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
}

.detail-destination-title,
.detail-destination-label,
.detail-destination-note {
  display: block;
}

.detail-destination-title {
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.detail-destination-label {
  color: var(--fg);
  font-size: 0.95rem;
}

.detail-destination-note {
  color: var(--fg-dim);
  font-size: 0.82rem;
  line-height: 1.45;
}

.detail-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.detail-actions button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--fg);
  padding: 10px 14px;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

body.is-hero-transition .panel.hero {
  transform: translate3d(var(--hero-dip-x-soft), var(--hero-dip-y-soft), 0);
  animation: hero-panel-dip 320ms cubic-bezier(0.22, 0.78, 0.16, 1);
}

body.is-hero-transition .arrival-detail {
  transform: translate3d(var(--hero-dip-x-soft), var(--hero-dip-y-soft), 0);
  animation: hero-detail-pulse 320ms cubic-bezier(0.22, 0.78, 0.16, 1);
}

body.is-hero-transition .world-canvas,
body.is-hero-transition .overlay-canvas {
  transform: translate3d(var(--hero-dip-x), var(--hero-dip-y), 0);
  animation: hero-world-surge 320ms cubic-bezier(0.22, 0.78, 0.16, 1);
}

body.is-hero-transition .tree-leaf.is-active {
  animation: hero-pill-lock 320ms cubic-bezier(0.22, 0.78, 0.16, 1);
}

@keyframes hero-panel-dip {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
    opacity: 1;
    filter: blur(0);
  }
  38% {
    transform: translate3d(var(--hero-dip-x-soft), var(--hero-dip-y-soft), 0) scale(0.982);
    opacity: 0.74;
    filter: blur(1.5px);
  }
  100% {
    transform: translate3d(0, 0, 0) scale(1);
    opacity: 1;
    filter: blur(0);
  }
}

@keyframes hero-detail-pulse {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  36% {
    transform: translate3d(var(--hero-dip-x-reverse), var(--hero-dip-y-reverse), 0) scale(1.018);
  }
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes hero-world-surge {
  0% {
    transform: translate3d(var(--hero-dip-x), var(--hero-dip-y), 0) scale(1);
    filter: saturate(1) brightness(1);
  }
  44% {
    transform: translate3d(var(--hero-dip-x), var(--hero-dip-y), 0) scale(1.026);
    filter: saturate(1.2) brightness(1.12) contrast(1.04);
  }
  100% {
    transform: translate3d(var(--hero-dip-x), var(--hero-dip-y), 0) scale(1);
    filter: saturate(1) brightness(1);
  }
}

@keyframes hero-pill-lock {
  0% {
    transform: translateY(0) scale(1);
  }
  38% {
    transform: translateY(-2px) scale(1.04);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

.shell-fallback {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 5;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.42);
  color: var(--fg-muted);
  font-family: var(--font-ui);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.shell-fallback[hidden] {
  display: none;
}

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

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .mode-controls,
  .alpha-modes,
  .secondary-controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 800px) {
  body {
    overflow: auto;
  }

  .world-canvas,
  .overlay-canvas {
    position: absolute;
    min-height: 100vh;
  }

  .shell {
    min-height: 100vh;
    padding: 12px;
    gap: 12px;
  }

  .arrival-detail {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }

  .shell-fallback {
    right: 12px;
    bottom: 12px;
  }
}
