/* Flexia — pantalla de formateo (cristal 3D + distorsión de fondo) */
:root {
    --fmt-bg-0: #04060d;
    --fmt-bg-1: #0a1020;
    --fmt-accent: #38bdf8;
    --fmt-accent-2: #a78bfa;
    --fmt-glass: rgba(255, 255, 255, 0.08);
    --fmt-glass-border: rgba(255, 255, 255, 0.22);
    --fmt-text: #e8f4ff;
    --fmt-muted: rgba(232, 244, 255, 0.72);
}

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

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

body.flexia-format-load {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    color: var(--fmt-text);
    background: var(--fmt-bg-0);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.flexia-format-load__viewport {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(1rem, 4vw, 2.5rem);
    perspective: 1200px;
}

/* Fondo animado + capa distorsionada */
.flexia-format-load__bg {
    position: fixed;
    inset: -12%;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 90% 60% at 20% 10%, rgba(56, 189, 248, 0.35), transparent 55%),
        radial-gradient(ellipse 70% 50% at 85% 20%, rgba(167, 139, 250, 0.28), transparent 50%),
        radial-gradient(ellipse 80% 55% at 50% 100%, rgba(14, 165, 233, 0.2), transparent 52%),
        linear-gradient(155deg, var(--fmt-bg-0) 0%, var(--fmt-bg-1) 42%, #0f172a 100%);
    animation: fmt-bg-drift 18s ease-in-out infinite alternate;
}

.flexia-format-load__bg-warp {
    position: fixed;
    inset: -8%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.55;
    filter: url(#fmt-displace) blur(0.4px);
    background:
        conic-gradient(from 210deg at 50% 50%, rgba(56, 189, 248, 0.15), rgba(167, 139, 250, 0.22), rgba(14, 165, 233, 0.12), rgba(56, 189, 248, 0.15));
    animation: fmt-warp-spin 24s linear infinite;
}

@keyframes fmt-bg-drift {
    0% { transform: scale(1) translate(0, 0); }
    100% { transform: scale(1.06) translate(-2%, 1.5%); }
}

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

.flexia-format-load__grain {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0.045;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Prisma cristal 3D */
.flexia-format-load__crystal-scene {
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(420px, 70vw);
    height: min(420px, 70vw);
    transform: translate(-50%, -58%);
    transform-style: preserve-3d;
    pointer-events: none;
    z-index: 2;
    opacity: 0.42;
}

.flexia-format-load__crystal {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 140px;
    height: 140px;
    transform-style: preserve-3d;
    animation: fmt-crystal-spin 14s linear infinite;
}

.flexia-format-load__crystal-face {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.22), rgba(56, 189, 248, 0.08) 40%, rgba(167, 139, 250, 0.12));
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow:
        0 0 40px rgba(56, 189, 248, 0.25),
        inset 0 0 24px rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.flexia-format-load__crystal-face:nth-child(1) { transform: rotateY(0deg) translateZ(50px); }
.flexia-format-load__crystal-face:nth-child(2) { transform: rotateY(90deg) translateZ(50px); }
.flexia-format-load__crystal-face:nth-child(3) { transform: rotateY(180deg) translateZ(50px); }
.flexia-format-load__crystal-face:nth-child(4) { transform: rotateY(-90deg) translateZ(50px); }
.flexia-format-load__crystal-face:nth-child(5) { transform: rotateX(90deg) translateZ(50px); }
.flexia-format-load__crystal-face:nth-child(6) { transform: rotateX(-90deg) translateZ(50px); }

@keyframes fmt-crystal-spin {
    0% { transform: rotateX(-18deg) rotateY(0deg); }
    100% { transform: rotateX(-18deg) rotateY(360deg); }
}

/* Panel cristal principal */
.flexia-format-load__panel {
    position: relative;
    z-index: 10;
    width: min(28rem, 100%);
    padding: 2rem 1.85rem 1.75rem;
    border-radius: 28px;
    background: linear-gradient(
        145deg,
        rgba(255, 255, 255, 0.14) 0%,
        rgba(255, 255, 255, 0.04) 38%,
        rgba(15, 23, 42, 0.35) 100%
    );
    border: 1px solid var(--fmt-glass-border);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.06) inset,
        0 32px 64px -16px rgba(0, 0, 0, 0.55),
        0 0 100px -24px rgba(56, 189, 248, 0.35);
    backdrop-filter: blur(28px) saturate(1.65);
    -webkit-backdrop-filter: blur(28px) saturate(1.65);
    transform: rotateX(var(--fmt-tilt-x, 0deg)) rotateY(var(--fmt-tilt-y, 0deg));
    transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    animation: fmt-panel-in 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes fmt-panel-in {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.flexia-format-load__brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    font-size: 0.72rem;
    letter-spacing: 0.28em;
    text-transform: uppercase;
    color: var(--fmt-muted);
}

.flexia-format-load__title {
    margin: 0 0 0.25rem;
    font-size: 1.35rem;
    font-weight: 600;
    text-align: center;
    letter-spacing: -0.02em;
}

.flexia-format-load__subtitle {
    margin: 0 0 1.5rem;
    font-size: 0.88rem;
    line-height: 1.45;
    text-align: center;
    color: var(--fmt-muted);
}

/* Anillo de progreso */
.flexia-format-load__ring-wrap {
    position: relative;
    width: 9.5rem;
    height: 9.5rem;
    margin: 0 auto 1.25rem;
}

.flexia-format-load__ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.flexia-format-load__ring-track {
    fill: none;
    stroke: rgba(255, 255, 255, 0.08);
    stroke-width: 6;
}

.flexia-format-load__ring-progress {
    fill: none;
    stroke: url(#fmt-ring-gradient);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.65));
}

.flexia-format-load__pct {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1rem;
}

.flexia-format-load__pct-value {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.04em;
    background: linear-gradient(180deg, #fff 0%, rgba(186, 230, 253, 0.9) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.flexia-format-load__pct-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--fmt-muted);
}

.flexia-format-load__phase {
    min-height: 2.6em;
    margin: 0 0 0.85rem;
    font-size: 0.9rem;
    line-height: 1.4;
    text-align: center;
    color: rgba(232, 244, 255, 0.9);
    transition: opacity 0.4s ease;
}

.flexia-format-load__phase.is-fading {
    opacity: 0.35;
}

.flexia-format-load__bar-track {
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.flexia-format-load__bar-fill {
    height: 100%;
    width: 0%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--fmt-accent), var(--fmt-accent-2));
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.6);
    transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.flexia-format-load__meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--fmt-muted);
    font-variant-numeric: tabular-nums;
}

.flexia-format-load__error {
    display: none;
    margin-top: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(248, 113, 113, 0.35);
    font-size: 0.85rem;
    line-height: 1.4;
    text-align: center;
}

.flexia-format-load__error.is-visible {
    display: block;
}

.flexia-format-load__back {
    display: none;
    margin: 1rem auto 0;
    padding: 0.55rem 1.25rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--fmt-text);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.flexia-format-load__back.is-visible {
    display: block;
}

.flexia-format-load__back:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.35);
}

.flexia-format-load.is-complete .flexia-format-load__panel {
    box-shadow:
        0 0 0 1px rgba(125, 211, 252, 0.2) inset,
        0 32px 64px -16px rgba(0, 0, 0, 0.55),
        0 0 120px -16px rgba(52, 211, 153, 0.45);
}

@media (prefers-reduced-motion: reduce) {
    .flexia-format-load__bg,
    .flexia-format-load__bg-warp,
    .flexia-format-load__crystal {
        animation: none;
    }
    .flexia-format-load__panel {
        transition: none;
    }
}
