:root {
  --bg: #02030a;
  --node-size: clamp(50px, 9.5vh, 100px);
  --ink: #eae6dd;
  --muted: #85847f;
  --radius: clamp(14px, 3.6vw, 20px);
  --pad-x: clamp(16px, 5vw, 48px);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

html {
  overflow: hidden;
  background: var(--bg);
}

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(120% 80% at 50% 0%, #0a1024 0%, transparent 58%),
    var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   Pantalla principal
   -------------------------------------------------------------------------- */

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding:
    max(14px, env(safe-area-inset-top))
    max(var(--pad-x), env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(var(--pad-x), env(safe-area-inset-left));
}

.menu-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.menu-shade {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(4, 2, 14, 0.5) 0%, transparent 20%, transparent 78%, rgba(3, 2, 12, 0.62) 100%),
    radial-gradient(ellipse at 50% 46%, transparent 48%, rgba(2, 0, 10, 0.45) 100%);
}

/* Grano muy fino para dar textura al cielo. */
.menu-shade::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.06;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 0 0 auto;
  padding-top: clamp(4px, 1.2vh, 10px);
  color: inherit;
  text-decoration: none;
  border-radius: 8px;
}

.brand:focus-visible {
  outline: 2px solid rgba(232, 222, 255, 0.7);
  outline-offset: 6px;
}

.brand__sigil {
  position: relative;
  width: 14px;
  height: 14px;
  border: 1px solid rgba(232, 222, 255, 0.55);
  border-radius: 50%;
  box-shadow: 0 0 14px rgba(197, 139, 255, 0.45);
  animation: sigil-breathe 7s ease-in-out infinite;
}

.brand__sigil::after {
  content: "";
  position: absolute;
  inset: 4.5px;
  border-radius: 50%;
  background: #f4f1ff;
  box-shadow: 0 0 8px #e0b8ff;
}

.brand__mark {
  padding-left: 0.62em;
  font-size: clamp(17px, 2.4vmin, 23px);
  font-weight: 300;
  letter-spacing: 0.62em;
  line-height: 1;
  text-transform: lowercase;
  background: linear-gradient(90deg, #cdb8ff, #ffffff 40%, #ffc9e8 60%, #b7f3ea);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(200, 160, 255, 0.35));
  animation: shimmer 18s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@keyframes sigil-breathe {
  0%, 100% { transform: scale(1); opacity: 0.75; }
  50% { transform: scale(1.18); opacity: 1; }
}

.constellation {
  position: relative;
  flex: 1 1 auto;
  width: min(100%, 980px);
  max-height: 780px;
  min-height: 0;
  margin: auto;
  transform: translate(calc(var(--px, 0) * -7px), calc(var(--py, 0) * -7px));
  transition: transform 1.2s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.constellation__lines {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  transition: opacity 600ms ease;
}

.constellation__lines path {
  fill: none;
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.constellation__lines .connection {
  stroke: url(#line-gradient);
  stroke-width: 1;
  opacity: 0.5;
  filter: drop-shadow(0 0 5px rgba(197, 139, 255, 0.45));
}

.constellation__lines .connection-glow {
  stroke: url(#line-gradient);
  stroke-width: 9;
  opacity: 0.06;
  filter: blur(4px);
}

/* Luz que recorre la constelación. */
.constellation__lines .connection-flow {
  stroke: #fff4ff;
  stroke-width: 2;
  stroke-dasharray: 0.6 99.4;
  opacity: 0.85;
  filter: drop-shadow(0 0 4px #ffd1f3) drop-shadow(0 0 10px #c58bff);
  animation: flow 26s linear infinite;
}

@keyframes flow {
  from { stroke-dashoffset: 100; }
  to { stroke-dashoffset: 0; }
}

.nodes {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.node {
  --scale: 1;
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  display: grid;
  place-items: center;
  width: var(--node-size);
  height: var(--node-size);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, var(--accent-soft) 0%, transparent 58%),
    radial-gradient(circle at 50% 50%, rgba(8, 4, 22, 0.78) 0%, rgba(8, 4, 22, 0.35) 70%, transparent 72%);
  color: var(--accent);
  cursor: pointer;
  transform: translate(-50%, -50%) scale(var(--scale));
  transition:
    transform 600ms cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 600ms ease,
    filter 600ms ease;
  animation: node-in 700ms cubic-bezier(0.22, 0.61, 0.36, 1) backwards;
  animation-delay: calc(var(--i) * 30ms + 80ms);
}

/* Halo que respira. */
.node__halo {
  position: absolute;
  inset: -40%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 62%);
  opacity: 0.55;
  pointer-events: none;
  animation: halo 6s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.73s);
}

@keyframes halo {
  0%, 100% { opacity: 0.35; transform: scale(0.92); }
  50% { opacity: 0.8; transform: scale(1.06); }
}

/* Anillo de sigilo que gira despacio. */
.node__ring {
  position: absolute;
  inset: 0;
  pointer-events: none;
  animation: spin var(--spin, 90s) linear infinite;
  animation-direction: var(--dir, normal);
  transition: filter 400ms ease;
}

.node__ring svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: none;
  stroke: currentColor;
}

.node__ring .r-orbit {
  stroke-width: 0.6;
  opacity: 0.45;
}

.node__ring .r-ticks {
  stroke-width: 0.8;
  opacity: 0.55;
}

.node__ring .r-arc {
  stroke-width: 1.4;
  opacity: 0.8;
  stroke-linecap: round;
}

.node__ring .r-gem {
  fill: currentColor;
  stroke: none;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.node__icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 52%;
  height: 52%;
  filter: drop-shadow(0 0 6px var(--accent-glow)) drop-shadow(0 0 2px var(--accent-line));
  transition: transform 500ms cubic-bezier(0.2, 0.8, 0.2, 1), filter 400ms ease;
}

.node__icon svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.05;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.node__icon svg :is(path, circle, ellipse) {
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
  animation: draw 750ms cubic-bezier(0.6, 0, 0.2, 1) backwards;
  animation-delay: calc(var(--i) * 30ms + 140ms);
}

@keyframes draw {
  from { stroke-dashoffset: 1; }
  to { stroke-dashoffset: 0; }
}

.node__icon svg .i-two {
  fill: currentColor;
  fill-opacity: 0.1;
}

.node__icon svg .i-solid,
.node__icon svg .i-dot {
  fill: currentColor;
  stroke: none;
}

.node__icon svg .i-faint {
  stroke-width: 0.6;
  opacity: 0.32;
}

.node:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 6px;
}

@media (hover: hover) and (pointer: fine) {
  .node:hover {
    --scale: 1.08;
  }

  .node:hover .node__ring {
    animation-duration: 12s;
    filter: drop-shadow(0 0 4px var(--accent));
  }

  .node:hover .node__icon {
    transform: scale(1.08);
    filter: drop-shadow(0 0 10px var(--accent)) drop-shadow(0 0 2px var(--accent));
  }

  .node:hover .node__icon svg :is(path, circle, ellipse) {
    animation: draw 1.1s cubic-bezier(0.6, 0, 0.2, 1);
  }

  .node:hover .node__halo {
    opacity: 1;
  }
}

.node:active {
  --scale: 0.96;
}

/* Invocación: el nodo elegido arde y el resto se pliega hacia él. */
.app.is-invoking .node:not(.is-chosen) {
  --scale: 0.4;
  opacity: 0;
  filter: blur(6px);
  left: calc((var(--x) + (var(--ox) - var(--x)) * 0.6) * 1%);
  top: calc((var(--y) + (var(--oy) - var(--y)) * 0.6) * 1%);
  transition:
    transform 900ms cubic-bezier(0.7, 0, 0.3, 1),
    left 900ms cubic-bezier(0.7, 0, 0.3, 1),
    top 900ms cubic-bezier(0.7, 0, 0.3, 1),
    opacity 800ms ease,
    filter 800ms ease;
}

.app.is-invoking .constellation__lines {
  opacity: 0;
}

.app.is-invoking .brand,
.app.is-invoking .foot {
  opacity: 0;
  transition: opacity 600ms ease;
}

.node.is-chosen {
  z-index: 3;
  --scale: 1.35;
}

.node.is-chosen .node__ring {
  animation-duration: 2.4s;
  filter: drop-shadow(0 0 8px var(--accent));
}

.node.is-chosen .node__halo {
  opacity: 1;
  animation: halo-burst 1s ease-out forwards;
}

.node.is-chosen .node__icon {
  filter: drop-shadow(0 0 12px var(--accent)) drop-shadow(0 0 3px #fff);
}

@keyframes halo-burst {
  from { transform: scale(1); }
  to { transform: scale(2.4); opacity: 0; }
}

/* Portal de luz desde el nodo elegido. */
.portal {
  position: fixed;
  inset: 0;
  z-index: 20;
  overflow: hidden;
  pointer-events: none;
}

.portal.is-fading {
  opacity: 0;
  transition: opacity 900ms ease;
}

/* Velo que oscurece el menú mientras crece la luz. */
.portal::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--ox) var(--oy), color-mix(in srgb, var(--accent) 22%, #06030f) 0%, #030209 70%);
  opacity: 0;
  animation: veil 800ms ease-in 300ms forwards;
}

@keyframes veil {
  to { opacity: 1; }
}

.portal__light {
  position: absolute;
  left: var(--ox);
  top: var(--oy);
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    color-mix(in srgb, color-mix(in srgb, var(--accent) 70%, #fff) 80%, transparent) 0%,
    color-mix(in srgb, var(--accent) 60%, transparent) 10%,
    color-mix(in srgb, var(--accent) 26%, transparent) 26%,
    color-mix(in srgb, var(--accent) 9%, transparent) 46%,
    transparent 68%
  );
  transform: scale(0);
  animation: portal-grow 1100ms cubic-bezier(0.75, 0, 0.25, 1) 280ms forwards;
}

@keyframes portal-grow {
  to { transform: scale(var(--cover, 300)); }
}

.portal__ring {
  position: absolute;
  left: var(--ox);
  top: var(--oy);
  width: 60px;
  height: 60px;
  margin: -30px 0 0 -30px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 18px var(--accent), inset 0 0 12px var(--accent);
  opacity: 0;
  animation: ripple 1300ms cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

.portal__ring:nth-child(2) {
  animation-delay: 160ms;
}

.portal__ring:nth-child(3) {
  animation-delay: 320ms;
}

@keyframes ripple {
  0% { opacity: 0.9; transform: scale(0.6); }
  100% { opacity: 0; transform: scale(9); }
}

.foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0 2px;
}

.foot__duration {
  padding: 4px 10px;
  border: 0;
  border-bottom: 1px solid rgba(214, 190, 255, 0.28);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 180ms ease, border-color 180ms ease;
}

.foot__duration:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.foot__duration:focus-visible {
  outline: 2px solid var(--accent, #e9e4da);
  outline-offset: 4px;
}

.duration-pop {
  position: fixed;
  left: 50%;
  bottom: calc(max(16px, env(safe-area-inset-bottom)) + 44px);
  z-index: 6;
  width: min(calc(100vw - 32px), 360px);
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  background: rgba(8, 11, 20, 0.88);
  box-shadow:
    0 24px 70px -30px rgba(0, 0, 0, 0.95),
    0 0 40px -28px rgba(160, 185, 255, 0.35);
  backdrop-filter: blur(24px) saturate(125%);
  -webkit-backdrop-filter: blur(24px) saturate(125%);
  transform: translateX(-50%);
  animation: duration-in 180ms ease;
}

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

.duration-chip {
  min-height: 38px;
  padding: 0 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.duration-chip:hover {
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.22);
}

.duration-chip[aria-pressed="true"] {
  border-color: rgba(143, 189, 255, 0.65);
  background: rgba(143, 189, 255, 0.14);
  color: #e9f0ff;
}

@keyframes duration-in {
  from {
    opacity: 0;
    transform: translate(-50%, 6px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}


.noscript {
  position: fixed;
  inset: auto 20px 24px;
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

@keyframes node-in {
  from {
    opacity: 0;
    filter: blur(10px);
    scale: 0.6;
  }
  to {
    opacity: 1;
    filter: blur(0);
    scale: 1;
  }
}

@keyframes stage-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
   Sesión a pantalla completa
   -------------------------------------------------------------------------- */

.stage {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  background: #000;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  opacity: 1;
  animation: stage-in 700ms ease;
  transition: opacity 420ms ease;
  touch-action: none;
}

.stage.is-leaving {
  opacity: 0;
  pointer-events: none;
}

/* Mientras dura la invocación, el escenario espera oculto. */
.stage.is-awaiting {
  opacity: 0;
  animation: none;
}

.stage:focus {
  outline: none;
}

.stage__canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.stage__vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 50%, transparent 52%, rgba(0, 0, 0, 0.36) 100%);
  pointer-events: none;
}

.stage__progress {
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: rgba(255, 255, 255, 0.06);
  pointer-events: none;
}

.stage__progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent, #e9e4da);
  box-shadow: 0 0 10px var(--accent, transparent);
}

.stage__dim {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  will-change: opacity;
}

.stage__hud {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  pointer-events: none;
  transition: opacity 420ms ease;
}

.stage__track,
.stage__close {
  appearance: none;
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.46);
  font: inherit;
  cursor: pointer;
  pointer-events: auto;
  transition: color 180ms ease, opacity 180ms ease;
}

.stage__track {
  margin: -10px 0 0 -12px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.16em;
  font-variant-numeric: tabular-nums;
}

.stage__close {
  margin: -8px -10px 0 0;
  font-size: 20px;
  line-height: 1;
}

.stage__track:hover,
.stage__close:hover {
  color: rgba(255, 255, 255, 0.86);
}

.stage__track:focus-visible,
.stage__close:focus-visible {
  border-radius: 2px;
  outline: 1px solid rgba(255, 255, 255, 0.5);
  outline-offset: 4px;
}

.stage__track:disabled {
  opacity: 0.55;
  cursor: default;
}

.stage__track[hidden] {
  display: none;
}

.stage.is-ending .stage__hud {
  opacity: 0;
  pointer-events: none;
}


/* --------------------------------------------------------------------------
   Aviso de audio
   -------------------------------------------------------------------------- */

.stage__note {
  position: absolute;
  left: 50%;
  bottom: calc(max(20px, env(safe-area-inset-bottom)) + 12px);
  z-index: 3;
  margin: 0;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  color: rgba(255, 255, 255, 0.62);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  transform: translateX(-50%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Preferencia de movimiento reducido
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .node,
  .node__halo,
  .node__ring,
  .node__icon svg :is(path, circle, ellipse),
  .brand__sigil,
  .brand__mark,
  .constellation__lines .connection-flow {
    animation: none !important;
  }

  .constellation {
    transform: none;
  }

  .stage {
    animation: none;
  }

  .node,
  .node__icon {
    transition: none;
  }

  .node:hover {
    transform: translate(-50%, -50%);
  }

  .duration-pop {
    animation: none;
  }
}

@media (max-height: 500px) {
  :root {
    --node-size: 44px;
  }
}

/* En pantallas muy bajas (móvil en horizontal) se gana espacio. */
@media (max-height: 460px) {
  .brand {
    padding-top: 0;
  }

  .app {
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
}
