:root {
  --bg: #05070d;
  --bg-2: #0a0f1d;
  --panel: rgba(10, 15, 29, 0.72);
  --line: rgba(140, 170, 255, 0.16);
  --text: #e8ecf8;
  --muted: #9aa5c4;
  --cyan: #4cc9f0;
  --violet: #7b61ff;
  --green: #2ee6a6;
  --pink: #f72585;
  --amber: #ffb703;
  --accent: var(--cyan);
  --radius: 18px;
  --font-display: "Space Grotesk", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--cyan); }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; border-radius: 999px; }

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene.is-dragging { cursor: grabbing; }
#scene.is-hover { cursor: pointer; }

/* ---------- Topbar ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  background: linear-gradient(to bottom, rgba(5, 7, 13, 0.85), rgba(5, 7, 13, 0));
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.18em;
  font-size: 15px;
}
.nav { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: color .2s, border-color .2s, background .2s;
}
.nav a:hover, .nav a[aria-current="true"] { color: var(--text); border-color: var(--line); background: rgba(255,255,255,0.04); }
.nav a.nav-cta { color: var(--bg); background: var(--cyan); }
.nav a.nav-cta:hover, .nav a.nav-cta[aria-current="true"] { background: #7fdaf5; color: var(--bg); }

/* ---------- Panels (modo 3D) ---------- */
.panel {
  position: fixed;
  z-index: 10;
  top: 50%;
  right: clamp(16px, 4vw, 56px);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 160px);
  max-height: calc(100dvh - 160px);
  overflow-y: auto;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  opacity: 0;
  visibility: hidden;
  transform: translate(24px, -50%);
  transition: opacity .5s ease, transform .6s cubic-bezier(.2,.8,.2,1), visibility 0s linear .6s;
}
.panel.is-active {
  opacity: 1;
  visibility: visible;
  transform: translate(0, -50%);
  transition: opacity .6s ease .25s, transform .7s cubic-bezier(.2,.8,.2,1) .2s, visibility 0s;
}
.panel--hero {
  left: clamp(16px, 6vw, 80px);
  right: auto;
  top: auto;
  bottom: clamp(56px, 10vh, 110px);
  width: min(620px, calc(100vw - 32px));
  background: none;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  padding: 0;
  transform: translateY(24px);
}
.panel--hero.is-active { transform: translateY(0); }

.eyebrow {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}
h1, h2, h3 { font-family: var(--font-display); margin: 0; line-height: 1.1; }
h1 { font-size: clamp(36px, 6vw, 68px); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: clamp(28px, 3.4vw, 38px); font-weight: 600; margin-bottom: 14px; }
h3 { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.grad {
  background: linear-gradient(90deg, var(--cyan), var(--violet) 70%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.lead { color: var(--muted); font-size: 17px; margin: 14px 0 22px; max-width: 54ch; }
.hint { color: var(--muted); font-size: 13px; opacity: .7; margin-top: 22px; }

.actions { display: flex; gap: 12px; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  padding: 12px 22px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 15px;
  text-decoration: none;
  transition: transform .2s, background .2s, border-color .2s;
}
.btn:hover { transform: translateY(-2px); }
.btn--primary { background: var(--cyan); color: var(--bg); }
.btn--primary:hover { background: #7fdaf5; }
.btn--os { background: var(--amber); color: var(--bg); }
.btn--os:hover { background: #ffc93c; }
.nav a.nav-os { color: var(--amber); }
.nav a.nav-os:hover, .nav a.nav-os[aria-current="true"] { border-color: rgba(255,183,3,0.45); }
.btn--ghost { color: var(--text); border: 1px solid var(--line); background: rgba(255,255,255,0.03); }
.btn--ghost:hover { border-color: var(--cyan); }

.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 10px; }
.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
  transition: border-color .25s, background .25s;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 55%, transparent); background: rgba(255,255,255,0.045); }
.card p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

.principles { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.principles li {
  padding: 14px 16px 14px 20px;
  border-left: 2px solid var(--accent);
  background: rgba(255,255,255,0.025);
  border-radius: 0 12px 12px 0;
  color: var(--muted);
}
.principles strong { color: var(--text); font-family: var(--font-display); font-weight: 600; }

.contact-mail {
  display: inline-block;
  font-family: var(--font-display);
  font-size: clamp(22px, 3vw, 30px);
  color: var(--text);
  text-decoration: none;
  border-bottom: 2px solid var(--accent);
  margin-bottom: 24px;
  word-break: break-all;
}

/* color por sección */
#servicios { --accent: var(--cyan); }
#nosotros  { --accent: var(--violet); }
#gobierno  { --accent: var(--green); }
#contacto  { --accent: var(--pink); }
#os        { --accent: var(--amber); }

/* ---------- Etiquetas de nodos ---------- */
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.node-label {
  position: absolute;
  top: 0; left: 0;
  pointer-events: auto;
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text);
  background: rgba(5, 7, 13, 0.6);
  border: 1px solid var(--line);
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
  transition: opacity .3s, border-color .2s;
  will-change: transform;
}
.node-label:hover, .node-label.is-hover { border-color: var(--c, var(--cyan)); }
.node-label.is-hidden { opacity: 0; pointer-events: none; }

.footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 15;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}
.footer a { color: var(--muted); pointer-events: auto; }

/* ---------- Móvil ---------- */
@media (max-width: 767px) {
  .topbar {
    padding: max(12px, env(safe-area-inset-top)) 0 10px;
    flex-direction: column; align-items: stretch; gap: 8px;
    background: linear-gradient(to bottom, rgba(5,7,13,.95), rgba(5,7,13,0));
  }
  .brand { padding: 0 16px; }
  /* Menú en una sola fila deslizable */
  .nav {
    flex-wrap: nowrap; justify-content: flex-start; gap: 6px;
    overflow-x: auto; padding: 0 16px 4px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 8px 14px; font-size: 14px; white-space: nowrap; flex: 0 0 auto; scroll-snap-align: start; border-color: var(--line); }
  .panel {
    top: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    right: 12px;
    left: 12px;
    width: auto;
    max-height: 56dvh;
    padding: 20px;
    transform: translateY(24px);
    /* El desenfoque de fondo es muy costoso en móviles: fondo sólido */
    background: rgba(10, 15, 29, 0.94);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
  }
  .panel.is-active { transform: translateY(0); }
  .panel--hero { bottom: max(40px, calc(env(safe-area-inset-bottom) + 24px)); left: 16px; right: 16px; width: auto; max-height: none; background: none; box-shadow: none; }
  .cards { grid-template-columns: 1fr; }
  .card:hover { background: rgba(255,255,255,0.025); }
  .btn { padding: 13px 22px; }
  .btn:hover { transform: none; }
  .node-label { font-size: 12px; padding: 6px 12px; }
  .hint { display: none; }
  .footer { display: none; }
  .swipe-hint { display: block; }
}
.swipe-hint { display: none; margin: 14px 0 0; font-size: 12px; color: var(--muted); opacity: .7; text-align: center; }

/* ---------- Modo clásico (sin WebGL / sin JS 3D) ---------- */
.no-3d #scene, .no-3d #labels, .no-3d .hint--3d { display: none; }
.no-3d body {
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(123, 97, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 20%, rgba(76, 201, 240, 0.14), transparent 60%),
    var(--bg);
}
.no-3d main { padding: 140px clamp(16px, 6vw, 80px) 40px; display: grid; gap: 28px; max-width: 980px; margin: 0 auto; }
.no-3d .panel, .no-3d .panel--hero {
  position: static;
  opacity: 1;
  visibility: visible;
  transform: none;
  width: auto;
  max-height: none;
  overflow: visible;
}
.no-3d .panel--hero { padding: 40px 0 20px; }
.no-3d .footer { position: static; pointer-events: auto; }
.no-3d .panel { scroll-margin-top: 110px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}
.actions--spaced { margin-top: 20px; }

/* Durante la transformación las tarjetas viajan fuera del panel */
.panel.is-morphing { overflow: visible; }
.panel.is-leaving {
  opacity: 1;
  visibility: visible;
  transition: background .5s ease, border-color .5s ease, box-shadow .5s ease;
}
.panel.is-leaving.panel--hero { transform: translateY(0); }
.panel.is-leaving:not(.panel--hero) {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* ---------- Misión y visión ---------- */
.mv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 4px 0 18px; }
.mv-card {
  --mv: var(--violet);
  position: relative;
  padding: 18px 16px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    radial-gradient(120% 80% at 0% 0%, color-mix(in srgb, var(--mv) 16%, transparent), transparent 60%),
    rgba(255, 255, 255, 0.025);
  overflow: hidden;
}
.mv-card--mision { --mv: var(--cyan); }
.mv-card--vision { --mv: var(--violet); }
.mv-card::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 2px;
  background: linear-gradient(to bottom, var(--mv), transparent);
}
.mv-icon {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; margin-bottom: 10px;
  border-radius: 10px; color: var(--mv);
  background: color-mix(in srgb, var(--mv) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--mv) 35%, transparent);
}
.mv-icon svg { width: 22px; height: 22px; }
.mv-card h3 { font-size: 13px; letter-spacing: .18em; text-transform: uppercase; color: var(--mv); margin-bottom: 8px; }
.mv-card p { margin: 0; color: var(--text); font-size: 14px; line-height: 1.55; opacity: .9; }
@media (max-width: 767px) {
  .mv-grid { grid-template-columns: 1fr; }
}
