:root {
  color-scheme: dark;
  --bg: #171a16;
  --surface: rgba(17, 20, 17, 0.78);
  --surface-strong: rgba(9, 11, 9, 0.86);
  --line: rgba(237, 229, 199, 0.2);
  --text: #f3f0e5;
  --muted: #c8c1ad;
  --book: #d6c36a;
  --author: #d6c7ff;
  --shared: #ffffff;
  --accent: #fff0a6;
  --warm: #d99a64;
  --shadow: 0 22px 54px rgba(0, 0, 0, 0.42);
  --glass: linear-gradient(180deg, rgba(17, 20, 17, 0.72), rgba(9, 11, 9, 0.58));
}

@font-face {
  font-family: "SF Gothican";
  src: url("../assets/font/SF-Gothican.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before,
body::after {
  position: fixed;
  inset: 0;
  content: "";
  pointer-events: none;
}

body::before {
  z-index: -2;
  background: url("../assets/img/background.jpg") center / cover no-repeat;
}

body::after {
  z-index: -1;
  background:
    linear-gradient(90deg, rgba(10, 12, 10, 0.68), rgba(10, 12, 10, 0.3)),
    radial-gradient(circle at 24% 26%, rgba(214, 195, 106, 0.12), transparent 34%),
    radial-gradient(circle at 74% 58%, rgba(217, 154, 100, 0.08), transparent 32%),
    linear-gradient(180deg, rgba(5, 6, 5, 0.18), rgba(5, 6, 5, 0.62));
}

button,
input {
  font: inherit;
}

.app {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  width: 100vw;
  height: 100vh;
}

.viewport {
  position: relative;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(ellipse at 22% 72%, rgba(86, 180, 233, 0.12), transparent 25rem),
    radial-gradient(ellipse at 78% 26%, rgba(204, 121, 167, 0.1), transparent 28rem),
    radial-gradient(circle at 45% 48%, rgba(214, 195, 106, 0.08), transparent 33rem),
    radial-gradient(circle at 65% 20%, rgba(217, 154, 100, 0.11), transparent 25rem),
    rgba(5, 7, 5, 0.66);
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#scene:active {
  cursor: grabbing;
}

.hud {
  position: absolute;
  left: 22px;
  bottom: 22px;
  max-width: calc(100% - 44px);
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  backdrop-filter: blur(10px);
  color: var(--muted);
  font-size: 13px;
  box-shadow: var(--shadow);
}

.hud-content {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.hud[data-collapsed="true"] .hud-content {
  display: none;
}

.legend-toggle,
.mobile-panel-toggle,
.back-selection,
.zoom-dock button,
.list-switch button {
  border: 1px solid var(--line);
  background: rgba(17, 20, 17, 0.78);
  color: var(--text);
  cursor: pointer;
}

.legend-toggle {
  min-height: 30px;
  padding: 4px 9px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.hud.authors-hidden .author-legend {
  opacity: 0.38;
}

.hud-group {
  display: contents;
}

.hud span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 1px solid rgba(237, 229, 199, 0.14);
  border-radius: 8px;
  background: rgba(17, 20, 17, 0.54);
}

.dot {
  width: 9px;
  height: 9px;
  display: inline-block;
  border-radius: 50%;
}

.dot.author {
  background: var(--author);
}

.dot.shared {
  border: 1px solid var(--shared);
  background: var(--author);
}

.zoom-dock {
  position: absolute;
  left: 22px;
  bottom: 78px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: bottom 180ms ease;
}

.viewport:has(.hud[data-collapsed="false"]) .zoom-dock {
  bottom: 176px;
}

.back-selection {
  position: absolute;
  top: 22px;
  left: 22px;
  z-index: 6;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  color: var(--accent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.back-selection[hidden] {
  display: none;
}

.back-selection svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.9;
}

.zoom-actions {
  display: flex;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translateX(-8px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.zoom-dock[data-open="true"] .zoom-actions {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transform: translateX(0);
}

.zoom-dock button {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  color: var(--accent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.zoom-toggle {
  position: relative;
  z-index: 2;
}

.zoom-dock svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.zoom-dock button:hover,
.zoom-dock button:focus-visible,
.back-selection:hover,
.back-selection:focus-visible,
.legend-toggle:hover,
.legend-toggle:focus-visible,
.mobile-panel-toggle:hover,
.mobile-panel-toggle:focus-visible,
.list-switch button:hover,
.list-switch button:focus-visible {
  border-color: rgba(214, 195, 106, 0.58);
  background: rgba(24, 28, 23, 0.9);
  outline: none;
}

.mobile-panel-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 7;
  display: none;
  min-height: 38px;
  padding: 7px 12px;
  color: var(--accent);
  font-weight: 800;
}

.inspector {
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: 100vh;
  padding: 24px;
  border-left: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(17, 20, 17, 0.9), rgba(9, 11, 9, 0.88)),
    url("../assets/img/background.jpg") center / cover no-repeat;
  box-shadow: -18px 0 54px rgba(0, 0, 0, 0.34);
  overflow: auto;
}

header p,
.selected p {
  margin: 0 0 7px;
  color: var(--warm);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 9px;
  margin-bottom: 18px;
}

.crumbs a,
.crumbs span {
  color: var(--text);
  font-family: "SF Gothican", "Cooper Black", Georgia, serif;
  font-synthesis: weight;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1;
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
  text-shadow:
    0 3px 4px rgba(0, 0, 0, 0.48),
    0 0 1px rgba(255, 255, 255, 0.35);
}

.crumbs a {
  text-decoration-line: none;
}

.crumbs a:hover,
.crumbs a:focus-visible {
  color: var(--accent);
  outline: none;
  text-decoration-line: underline;
}

.crumbs span {
  opacity: 0.72;
}

header h1,
.selected h2,
.browser h2 {
  margin: 0;
  letter-spacing: 0;
}

header h1 {
  font-size: 28px;
  line-height: 1.05;
}

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

.metric-grid article,
.selected {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

.metric-grid article {
  padding: 12px;
}

.metric-grid strong {
  display: block;
  font-size: 24px;
  line-height: 1;
}

.metric-grid span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.search,
.filters label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.search input,
.filters select {
  min-height: 43px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: rgba(17, 20, 17, 0.84);
  color: var(--text);
}

.search input:focus,
.filters select:focus {
  border-color: rgba(214, 195, 106, 0.72);
  box-shadow: 0 0 0 3px rgba(214, 195, 106, 0.14);
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.actions button,
.node-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.08;
  text-align: center;
  overflow-wrap: normal;
  white-space: normal;
}

.actions button:hover,
.actions button:focus-visible,
.node-button:hover,
.node-button:focus-visible {
  border-color: rgba(214, 195, 106, 0.58);
  background: rgba(24, 28, 23, 0.88);
  box-shadow: var(--shadow);
  outline: none;
}

.actions button[aria-pressed="true"] {
  border-color: rgba(255, 240, 166, 0.66);
  background: rgba(214, 195, 106, 0.18);
  color: var(--accent);
}

.actions button.is-active,
.list-switch button[aria-pressed="true"] {
  border-color: rgba(255, 240, 166, 0.66);
  background: rgba(214, 195, 106, 0.18);
  color: var(--accent);
}

.selected {
  position: absolute;
  top: 24px;
  right: 404px;
  z-index: 4;
  width: min(360px, calc(100vw - 448px));
  padding: 16px;
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  pointer-events: auto;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.selected.is-empty {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translateY(-6px);
}

.selected h2 {
  font-size: 22px;
  line-height: 1.16;
  overflow-wrap: anywhere;
}

.selected > span {
  display: block;
  margin-top: 10px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

#selected-list {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

.tag,
.detail-link {
  width: fit-content;
  max-width: 100%;
  min-height: 30px;
  padding: 6px 9px;
  border: 1px solid rgba(214, 195, 106, 0.18);
  border-radius: 8px;
  background: rgba(214, 195, 106, 0.12);
  color: var(--accent);
  font-size: 13px;
  overflow-wrap: anywhere;
}

button.tag {
  cursor: pointer;
  text-align: left;
}

.detail-link {
  display: inline-flex;
  align-items: center;
  margin-top: 14px;
  font-weight: 800;
  text-decoration: none;
}

.detail-link[hidden] {
  display: none;
}

.browser-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.browser h2 {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 15px;
}

.browser-head h2 {
  margin: 0;
}

.list-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.list-switch button {
  min-height: 32px;
  padding: 5px 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.visible-count {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

#node-list {
  display: grid;
  gap: 8px;
}

.node-button {
  width: 100%;
  padding: 11px 12px;
  border-color: color-mix(in srgb, var(--node-accent, var(--line)) 36%, var(--line));
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--node-accent, transparent) 16%, transparent), transparent 64%),
    var(--surface);
  text-align: left;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease,
    background 160ms ease;
}

.node-button:hover,
.node-button:focus-visible {
  border-color: color-mix(in srgb, var(--node-accent, var(--accent)) 56%, rgba(214, 195, 106, 0.58));
  outline: none;
  transform: translateY(-2px);
}

.node-button strong {
  display: block;
  font-size: 14px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.node-button span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

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

  .app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .viewport {
    height: 58vh;
    min-height: 420px;
  }

  .mobile-panel-toggle {
    display: inline-flex;
    align-items: center;
  }

  .zoom-dock {
    bottom: 70px;
    transform: scale(0.86);
    transform-origin: bottom left;
  }

  .inspector {
    height: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .selected {
    top: 72px;
    right: 16px;
    width: min(340px, calc(100vw - 32px));
  }

  body.inspector-collapsed .inspector {
    display: none;
  }

  body.inspector-collapsed .viewport {
    height: 100vh;
    min-height: 420px;
  }
}

@media (max-width: 520px) {
  .inspector {
    padding: 18px;
  }

  header h1 {
    font-size: 25px;
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .hud {
    right: auto;
    left: 14px;
    bottom: 14px;
    max-width: calc(100% - 28px);
    font-size: 11px;
  }

  .hud-content {
    max-height: 118px;
    overflow: auto;
  }

  .hud span {
    padding: 3px 5px;
  }

  .zoom-dock {
    left: 14px;
    bottom: 64px;
  }

  .viewport:has(.hud[data-collapsed="false"]) .zoom-dock {
    bottom: 156px;
  }
}

/* Anchored site menu replacing the old breadcrumb. */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 90;
  display: flex;
  width: 100vw;
  pointer-events: none;
}

.site-menu {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px clamp(14px, 2vw, 24px);
  width: 100%;
  max-width: 100%;
  padding: 10px clamp(20px, 4vw, 48px);
  border-bottom: 1px solid rgba(237, 229, 199, 0.08);
  background: linear-gradient(180deg, rgba(17, 20, 17, 0.5), rgba(8, 10, 8, 0.18));
  box-shadow: none;
  pointer-events: auto;
  backdrop-filter: blur(14px);
}

.brand,
.brand-submenu a {
  color: var(--text);
  font-family: "SF Gothican", "Cooper Black", Georgia, serif;
  font-synthesis: weight;
  font-size: 1.32rem;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
  text-shadow:
    0 3px 4px rgba(0, 0, 0, 0.48),
    0 0 1px rgba(255, 255, 255, 0.35);
  white-space: nowrap;
}

.brand:hover,
.brand:focus-visible,
.brand-submenu a:hover,
.brand-submenu a:focus-visible {
  color: var(--accent);
  outline: none;
  text-decoration-line: underline;
}

.brand-menu-item {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.brand-menu-item::after {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  height: 12px;
  content: "";
}

.brand-submenu {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 100;
  display: grid;
  gap: 4px;
  min-width: 178px;
  padding: 10px;
  border: 1px solid rgba(237, 229, 199, 0.18);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(17, 20, 17, 0.9), rgba(8, 10, 8, 0.82));
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 160ms ease, transform 160ms ease;
  backdrop-filter: blur(14px);
}

.brand-menu-item:hover .brand-submenu,
.brand-menu-item:focus-within .brand-submenu {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transform: translateY(0);
}

@media (max-width: 760px) {
  .site-header {
    top: 0;
    left: 0;
    right: 0;
    width: 100vw;
  }

  .site-menu {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: visible;
    scrollbar-width: thin;
  }

  .brand,
  .brand-submenu a {
    font-size: 1.22rem;
  }
}

/* Constelación always uses the collapsible menu. */
.menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 38px;
  border: 1px solid rgba(237, 229, 199, 0.18);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(17, 20, 17, 0.72), rgba(8, 10, 8, 0.52));
  color: var(--text);
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.menu-toggle span {
  display: block;
  width: 19px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 6px 0 currentColor, 0 -6px 0 currentColor;
}

.menu-toggle span + span {
  display: none;
}

.site-header {
  width: auto;
  right: auto;
}

.site-menu {
  display: grid;
  justify-items: start;
  gap: 0;
  width: auto;
  max-width: min(360px, calc(100vw - 28px));
  padding: 10px;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.site-menu > :not(.menu-toggle) {
  display: none;
}

.site-menu.is-open {
  gap: 10px;
  border: 1px solid rgba(237, 229, 199, 0.16);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(17, 20, 17, 0.9), rgba(8, 10, 8, 0.78));
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
}

.site-menu.is-open > .brand {
  display: block;
}

.site-menu.is-open > .brand-menu-item {
  display: grid;
  gap: 4px;
}

.site-menu.is-open .brand-menu-item::after {
  content: none;
}

.site-menu.is-open .brand-submenu {
  position: static;
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 0 0 2px 18px;
  border: 0;
  background: transparent;
  box-shadow: none;
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transform: none;
  backdrop-filter: none;
}

.site-menu.is-open .brand-submenu a {
  font-size: 1.12rem;
  opacity: 0.86;
}

/* Keep constellation controls separated from the hamburger menu. */
.back-selection {
  top: 76px;
}

.site-header {
  min-height: 58px;
  background: linear-gradient(180deg, rgba(12, 14, 12, 0.54), rgba(12, 14, 12, 0.2));
}

.site-menu {
  position: absolute;
  top: 10px;
  left: 14px;
  z-index: 95;
}

.site-menu.is-open {
  width: min(360px, calc(100vw - 28px));
}

