/* ============================================================
   experience.css — Experiencia de scroll 3D de servicios
   Progresivo: el layout base (sin clase en <html>) es la versión
   estática completa. html.svc-3d activa el modo experiencia.
   html.svc-static es la señal explícita de fallback (reduced
   motion o sin WebGL) y comparte el layout base.
   ============================================================ */

/* ── Grano sutil sobre todo el sitio (SVG generado, sin assets) ── */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 80;
    pointer-events: none;
    opacity: 0.05;
    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");
    background-size: 160px 160px;
}

html:not(.dark) body::after {
    opacity: 0.035;
}

/* ── Tinte ambiental por sección (lo anima experience.js) ── */
#ambient-tint {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background: radial-gradient(52% 44% at var(--ax, 70%) 46%,
            rgb(var(--ambient, 6 249 148) / 0.14), transparent 70%);
}

html:not(.dark) #ambient-tint {
    background: radial-gradient(52% 44% at var(--ax, 70%) 46%,
            rgb(var(--ambient, 6 249 148) / 0.10), transparent 70%);
}

/* ── Canvas 3D fijo detrás del contenido ── */
#svc-canvas {
    position: fixed;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
}

/* ── Ticker infinito de servicios ── */
.svc-ticker {
    overflow: hidden;
    padding: 1rem 0;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    user-select: none;
}

html.dark .svc-ticker {
    border-top-color: rgba(255, 255, 255, 0.06);
    border-bottom-color: rgba(255, 255, 255, 0.06);
}

.svc-ticker-track {
    display: flex;
    width: max-content;
    will-change: transform;
    animation: svc-marquee 30s linear infinite;
}

.svc-ticker-track span {
    margin-right: 2.75rem;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    white-space: nowrap;
    color: #475569;
}

html.dark .svc-ticker-track span {
    color: #94a3b8;
}

.svc-ticker-track .tick-sep {
    color: rgb(var(--color-primary));
}

@keyframes svc-marquee {
    to {
        transform: translateX(-50%);
    }
}

/* ── Mundos de servicio ──────────────────────────────────────
   Base (estático / sin JS): bloques alternados texto + SVG. */
.svc-world {
    position: relative;
    padding: clamp(3.5rem, 9vh, 6.5rem) 1.5rem;
}

.svc-inner {
    position: relative;
    z-index: 3;
    max-width: 80rem;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    gap: clamp(2rem, 5vw, 5rem);
}

/* Alternancia: el texto va al lado que indica data-side */
.svc-world[data-side="right"] .svc-panel {
    order: 2;
}

.svc-world[data-side="right"] .svc-visual {
    order: 1;
}

.svc-panel {
    max-width: 34rem;
}

.svc-meta {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin-bottom: 1.4rem;
}

.svc-index {
    font-family: ui-monospace, 'SFMono-Regular', monospace;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.22em;
    color: rgb(var(--svc));
}

.svc-rule {
    display: block;
    width: 3.5rem;
    height: 1px;
    background: rgb(var(--svc) / 0.55);
}

.svc-count {
    font-family: ui-monospace, 'SFMono-Regular', monospace;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.22em;
    color: #64748b;
}

.svc-title {
    font-size: clamp(2rem, 5.2vw, 4.25rem);
    font-weight: 900;
    line-height: 0.95;
    letter-spacing: -0.03em;
    text-transform: uppercase;
    text-wrap: balance;
    margin-bottom: 1.25rem;
}

.svc-desc {
    font-size: clamp(1rem, 1.4vw, 1.15rem);
    font-weight: 300;
    line-height: 1.65;
    max-width: 42ch;
    color: #334155;
    margin-bottom: 2rem;
}

html.dark .svc-desc {
    color: #b6c2d4;
}

.svc-link {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.9rem 1.6rem;
    border: 1px solid rgb(var(--svc) / 0.45);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: rgb(var(--svc));
    transition: background-color 0.35s ease, color 0.35s ease, box-shadow 0.35s ease;
}

.svc-link:hover {
    background: rgb(var(--svc));
    color: #0B101A;
    box-shadow: 0 0 28px rgb(var(--svc) / 0.45);
}

.svc-link .material-symbols-outlined {
    font-size: 18px;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.svc-link:hover .material-symbols-outlined {
    transform: translate(2px, -2px);
}

/* Visual SVG (versión estática) */
.svc-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgb(var(--svc));
}

.svc-visual svg {
    width: min(100%, 22rem);
    height: auto;
    filter: drop-shadow(0 0 22px rgb(var(--svc) / 0.35));
}

/* ── Modo 3D: cada mundo ocupa una pantalla; el visual lo pone el canvas ── */
html.svc-3d .svc-world {
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    align-items: center;
    padding-top: 0;
    padding-bottom: 0;
}

html.svc-3d .svc-visual {
    display: none;
}

html.svc-3d .svc-inner {
    width: 100%;
}

/* En 3D solo queda el panel en el grid: hay que fijar su columna
   (order no basta con un único ítem) para que alterne de lado. */
html.svc-3d .svc-world[data-side="left"] .svc-panel {
    grid-column: 1;
}

html.svc-3d .svc-world[data-side="right"] .svc-panel {
    grid-column: 2;
    justify-self: end;
}

/* ── Responsive ── */
@media (max-width: 899px) {
    .svc-inner {
        grid-template-columns: 1fr;
    }

    .svc-world[data-side="right"] .svc-panel {
        order: 0;
    }

    .svc-world[data-side="right"] .svc-visual {
        order: 1;
    }

    .svc-visual svg {
        width: min(70%, 16rem);
    }

    /* En 3D móvil: la escena vive arriba, el texto abajo sobre un velo */
    html.svc-3d .svc-inner {
        align-content: end;
        padding-bottom: clamp(4rem, 12vh, 7rem);
    }

    html.svc-3d .svc-panel {
        padding: 1.4rem 1.5rem 0;
        margin: 0 -0.25rem;
        border-radius: 18px;
        background: linear-gradient(180deg, rgb(248 250 252 / 0), rgb(248 250 252 / 0.78) 26%);
    }

    html.dark.svc-3d .svc-panel {
        background: linear-gradient(180deg, rgb(11 16 26 / 0), rgb(11 16 26 / 0.78) 26%);
    }
}

/* ── Escena 3D del hero (solo escritorio + modo svc-3d) ──
   Cubre TODO el header y se dibuja POR ENCIMA del texto (z-20).
   No captura clicks (pointer-events:none): el cambio de forma lo
   escucha el <header> completo desde experience.js. */
#hero-3d {
    display: none;
}

@media (min-width: 1024px) {
    html.svc-3d #hero-3d {
        display: block;
        position: absolute;
        inset: 0;
        z-index: 20;
        pointer-events: none;
    }
}

#hero-3d canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* Con la escena 3D activa, el emblema CSS del hero de escritorio se oculta */
html.svc-3d .hero-emblem-css {
    display: none;
}

/* ── Divisor inmersivo 3D→2D del catálogo ──────────────────
   Un cubo wireframe gira en 3D y, al entrar en pantalla, se
   "aplana" de frente y SE QUEDA en 2D: la metáfora del cambio
   de render al grid plano. Sin texto: la animación lo dice todo. */
.dim-divider {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin: 3.5rem 0 4rem;
    user-select: none;
}

.dim-line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgb(var(--color-primary) / 0.5), transparent);
}

.dim-cube-wrap {
    width: 52px;
    height: 52px;
    perspective: 420px;
    flex-shrink: 0;
}

.dim-cube {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transform: rotateX(-24deg) rotateY(20deg);
}

/* experience.js añade .dim-play cuando el divisor entra en pantalla */
.dim-divider.dim-play .dim-cube {
    animation: dim-loop 4.5s cubic-bezier(0.45, 0, 0.2, 1) 1 forwards;
}

.dim-face {
    position: absolute;
    inset: 0;
    border: 1.5px solid rgb(var(--color-primary) / 0.85);
    background: rgb(var(--color-primary) / 0.06);
}

.dim-f1 { transform: translateZ(26px); }
.dim-f2 { transform: rotateY(180deg) translateZ(26px); }
.dim-f3 { transform: rotateY(90deg) translateZ(26px); }
.dim-f4 { transform: rotateY(-90deg) translateZ(26px); }
.dim-f5 { transform: rotateX(90deg) translateZ(26px); }
.dim-f6 { transform: rotateX(-90deg) translateZ(26px); }

/* Gira en isométrico (3D) → frena de frente y se queda plano (2D) */
@keyframes dim-loop {
    0% { transform: rotateX(-24deg) rotateY(20deg); }
    70% { transform: rotateX(-20deg) rotateY(600deg); }
    100% { transform: rotateX(0deg) rotateY(720deg); }
}

/* Con el efecto especial (rainbow) el divisor también cicla color */
body.rainbow-active .dim-divider {
    animation: dim-hue 2.5s linear infinite;
}

@keyframes dim-hue {
    to { filter: hue-rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
    .dim-cube {
        animation: none;
        transform: rotateX(0) rotateY(0);
    }

    body.rainbow-active .dim-divider {
        animation: none;
    }
}

/* ── Botones magnéticos: solo transform, JS los mueve ── */
.magnetic {
    will-change: transform;
}

/* ── Reduced motion: sin marquee, sin nada que se mueva ── */
@media (prefers-reduced-motion: reduce) {

    .svc-ticker-track {
        animation: none;
        flex-wrap: wrap;
        width: auto;
    }

    .svc-link .material-symbols-outlined,
    .svc-link {
        transition: none;
    }
}
