/**
 * PathwayAI Pro — Premium Motion Layer (Phase 2)
 * ADDITIVE ONLY — extends quality.css, micro_interactions.js, global gold standard.
 * No new page-enter keyframes (reuses pageFadeIn / cardRise / pathwayGold*).
 * GPU: transform + opacity only. Respects pathway-reduced-motion.
 */

:root {
    --pm-ease: cubic-bezier(0.16, 1, 0.3, 1);
    --pm-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --pm-ease-soft: cubic-bezier(0.33, 1, 0.68, 1);
    --pm-dur-fast: 0.2s;
    --pm-dur-med: 0.36s;
    --pm-dur-slow: 0.56s;
    --pm-lift: -3px;
    --pm-press: 0.982;
    --pm-glow: rgba(59, 130, 246, 0.2);
    --pm-glow-soft: rgba(59, 130, 246, 0.1);
    --pm-shimmer: rgba(255, 255, 255, 0.38);
    --pm-wave-dur: 1.05s;
}

/* ── Extend existing page-enter stagger (no duplicate keyframes) ── */
@media (prefers-reduced-motion: no-preference) {
    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .hero .container > * {
        animation-delay: calc(var(--pm-stagger, 0) * 1ms);
    }

    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .hero .container > *:nth-child(1) {
        --pm-stagger: 0;
    }

    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .hero .container > *:nth-child(2) {
        --pm-stagger: 48;
    }

    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .hero .container > *:nth-child(3) {
        --pm-stagger: 96;
    }

    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .hero .container > *:nth-child(4) {
        --pm-stagger: 144;
    }

    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .hero .container > *:nth-child(n + 5) {
        --pm-stagger: 192;
    }

    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .os-page-header__title,
    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .os-page-header__kicker,
    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .os-page-lead {
        animation: pageFadeIn var(--pm-dur-slow) var(--pm-ease) both;
    }

    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .os-page-header__kicker {
        animation-delay: 0.04s;
    }

    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .os-page-header__title {
        animation-delay: 0.1s;
    }

    html:not(.pathway-reduced-motion) body.page-enter.page-os-shell .os-page-lead {
        animation-delay: 0.16s;
    }
}

/* ── Buttons: soft press + glow (extends gold / design-system hover) ── */
@media (prefers-reduced-motion: no-preference) {
    html:not(.pathway-reduced-motion) body.page-os-shell .btn {
        transition:
            transform var(--pm-dur-fast) var(--pm-ease),
            box-shadow var(--pm-dur-med) var(--pm-ease-out),
            border-color var(--pm-dur-fast) ease,
            background-color var(--pm-dur-fast) ease,
            opacity var(--pm-dur-fast) ease !important;
    }

    html:not(.pathway-reduced-motion) body.page-os-shell .btn.btn-primary:not(:disabled):focus-visible {
        box-shadow:
            0 0 0 3px rgba(99, 102, 241, 0.35),
            0 8px 22px rgba(37, 99, 235, 0.28) !important;
    }

    html:not(.pathway-reduced-motion) body.page-os-shell .btn:active:not(:disabled),
    html:not(.pathway-reduced-motion) body.page-os-shell .btn.btn-pressed {
        transform: scale(var(--pm-press)) !important;
        transition-duration: 0.08s !important;
    }
}

/* ── Student panel: professional surface wave (JS fixed overlay) ── */
@keyframes pmSurfaceWaveSweep {
    from {
        transform: translate3d(-105%, 0, 0);
        opacity: 0;
    }
    10% {
        opacity: 0.55;
    }
    45% {
        opacity: 0.7;
    }
    100% {
        /* Beam ~38% of host → ~270% clears the far edge cleanly */
        transform: translate3d(270%, 0, 0);
        opacity: 0;
    }
}

.pm-wave-overlay {
    position: fixed;
    overflow: hidden;
    pointer-events: none;
    z-index: 60;
    border-radius: inherit;
    contain: layout style paint;
    /* Soft vignette so the beam never looks hard-edged */
    -webkit-mask-image: linear-gradient(90deg, transparent 0%, #000 6%, #000 94%, transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0%, #000 6%, #000 94%, transparent 100%);
}

.pm-wave-beam {
    position: absolute;
    top: 0;
    left: 0;
    width: 38%;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(186, 230, 253, 0.06) 18%,
        rgba(255, 255, 255, 0.28) 48%,
        rgba(147, 197, 253, 0.14) 62%,
        transparent 100%
    );
    mix-blend-mode: soft-light;
    transform: translate3d(-105%, 0, 0);
    will-change: transform, opacity;
}

@media (prefers-reduced-motion: no-preference) {
    html:not(.pathway-reduced-motion) .pm-wave-beam.is-running {
        animation: pmSurfaceWaveSweep var(--pm-wave-dur) var(--pm-ease-soft) 1;
    }
}

/* Dark surfaces: slightly brighter beam for readability */
body.dark .pm-wave-beam,
body.pathway-dark-global .pm-wave-beam {
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(147, 197, 253, 0.08) 16%,
        rgba(255, 255, 255, 0.34) 50%,
        rgba(96, 165, 250, 0.12) 68%,
        transparent 100%
    );
}

/* JS owns the wave — disable legacy card ::after shimmer (avoids double + ::after clashes) */
html.pathway-premium-motion body.page-os-shell #mainContent .card::after,
html.pathway-premium-motion body.page-os-shell .admin-main .card::after,
html.pathway-premium-motion body.page-os-shell .form-card::after {
    display: none !important;
    animation: none !important;
}

/* ── Professional panel interactions (GPU: transform / opacity / shadow) ── */
@media (prefers-reduced-motion: no-preference) {
    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell #mainContent :is(
        .card,
        .form-card,
        .living-card,
        .feature-box,
        .stat-card,
        .comp-card,
        .dashboard-cmd-tile,
        .dashboard-snapshot-cell,
        .outcome-stat,
        .today-task-card,
        .ai-tutor-box
    ) {
        transition:
            transform var(--pm-dur-med) var(--pm-ease),
            box-shadow var(--pm-dur-med) var(--pm-ease-out),
            border-color var(--pm-dur-fast) ease !important;
    }

    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell #mainContent :is(
        .card,
        .form-card,
        .living-card
    ):hover {
        transform: translate3d(0, var(--pm-lift), 0);
    }

    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell #mainContent .btn:not(:disabled):hover {
        transform: translate3d(0, -1px, 0);
    }

    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell #mainContent a.btn:not(:disabled):active,
    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell #mainContent .btn:not(:disabled):active {
        transform: scale(var(--pm-press));
    }

    /* Nested pieces stay visually quiet — parent surface owns the lift */
    html.pathway-premium-motion body.page-os-shell #mainContent .card :is(
        .dashboard-learning-loop-grid > div,
        .dashboard-snapshot-cell,
        .dashboard-cmd-tile,
        .feature-box,
        .outcome-stat
    ):hover {
        transform: none !important;
    }
}

/* ── Statistics / outcome tiles (extends reveal-on-load) ── */
@media (prefers-reduced-motion: no-preference) {
    html:not(.pathway-reduced-motion) .reveal-on-load.outcome-stat strong,
    html:not(.pathway-reduced-motion) .reveal-on-load .trust-institute-grid article strong {
        display: inline-block;
        animation: pmStatPop 0.55s var(--pm-ease) both;
    }

    html:not(.pathway-reduced-motion) .reveal-on-load.outcome-stat:nth-child(2) strong,
    html:not(.pathway-reduced-motion) .reveal-on-load .trust-institute-grid article:nth-child(2) strong {
        animation-delay: 0.06s;
    }

    html:not(.pathway-reduced-motion) .reveal-on-load.outcome-stat:nth-child(3) strong,
    html:not(.pathway-reduced-motion) .reveal-on-load .trust-institute-grid article:nth-child(3) strong {
        animation-delay: 0.12s;
    }

    html:not(.pathway-reduced-motion) .reveal-on-load.outcome-stat:nth-child(4) strong,
    html:not(.pathway-reduced-motion) .reveal-on-load .trust-institute-grid article:nth-child(4) strong {
        animation-delay: 0.18s;
    }
}

@keyframes pmStatPop {
    from {
        opacity: 1;
        transform: translateY(8px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ── Table row polish (hover only — never hide rows) ── */
@media (prefers-reduced-motion: no-preference) {
    html:not(.pathway-reduced-motion) .reveal-on-load .admin-table tbody tr:hover,
    html:not(.pathway-reduced-motion) .reveal-on-load table tbody tr:hover {
        background: rgba(59, 130, 246, 0.06);
        transition: background-color var(--pm-dur-fast) ease;
    }
}

/* ── Navigation: premium underline indicator ── */
@media (prefers-reduced-motion: no-preference) {
    html:not(.pathway-reduced-motion) .topbar .nav a,
    html:not(.pathway-reduced-motion) .admin-topbar-nav a {
        position: relative;
    }

    html:not(.pathway-reduced-motion) .topbar .nav a::after,
    html:not(.pathway-reduced-motion) .admin-topbar-nav a:not(.admin-topbar-logout)::after {
        content: "";
        position: absolute;
        left: 12%;
        right: 12%;
        bottom: 4px;
        height: 2px;
        border-radius: 999px;
        background: linear-gradient(90deg, #56ccf2, #2563eb);
        transform: scaleX(0);
        transform-origin: center;
        opacity: 0;
        transition:
            transform var(--pm-dur-med) var(--pm-ease),
            opacity var(--pm-dur-fast) ease;
    }

    html:not(.pathway-reduced-motion) .topbar .nav a:hover::after,
    html:not(.pathway-reduced-motion) .topbar .nav a.active::after,
    html:not(.pathway-reduced-motion) .admin-topbar-nav a:hover::after,
    html:not(.pathway-reduced-motion) .admin-topbar-nav a.active::after {
        transform: scaleX(1);
        opacity: 1;
    }
}

/* ── Forms: focus glow ── */
@media (prefers-reduced-motion: no-preference) {
    html:not(.pathway-reduced-motion) body.page-os-shell input:focus,
    html:not(.pathway-reduced-motion) body.page-os-shell select:focus,
    html:not(.pathway-reduced-motion) body.page-os-shell textarea:focus {
        transition:
            border-color var(--pm-dur-fast) ease,
            box-shadow var(--pm-dur-med) var(--pm-ease) !important;
    }

    html:not(.pathway-reduced-motion) body.page-os-shell .alert.success {
        animation: pmAlertIn 0.4s var(--pm-ease) both;
    }

    html:not(.pathway-reduced-motion) body.page-os-shell .alert.error {
        animation: pmAlertIn 0.4s var(--pm-ease) both;
    }
}

@keyframes pmAlertIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Modals / overlays (reuse existing classes) ── */
@media (prefers-reduced-motion: no-preference) {
    html:not(.pathway-reduced-motion) .pathway-celeb-overlay,
    html:not(.pathway-reduced-motion) .pathway-product-tour-overlay {
        animation: pmOverlayIn 0.35s var(--pm-ease) both;
    }

    html:not(.pathway-reduced-motion) .pathway-celeb-sheet,
    html:not(.pathway-reduced-motion) .pathway-product-tour-card {
        animation: pmSheetIn 0.45s var(--pm-ease) both;
    }

    html:not(.pathway-reduced-motion) .nav-dropdown__panel {
        transform-origin: top center;
        animation: pmDropIn 0.28s var(--pm-ease) both;
    }

    html:not(.pathway-reduced-motion) .os-secondary-drawer[open] > :not(summary) {
        animation: pmDrawerIn 0.32s var(--pm-ease) both;
    }
}

@keyframes pmOverlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes pmSheetIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes pmDropIn {
    from {
        opacity: 0;
        transform: translateY(-6px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes pmDrawerIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Learning World UI only (not #lw3dMount / canvas) ── */
@media (prefers-reduced-motion: no-preference) {
    html:not(.pathway-reduced-motion) .learning-world-page .lw-gate-panel,
    html:not(.pathway-reduced-motion) .learning-world-page .lw-zone,
    html:not(.pathway-reduced-motion) .learning-world-page .lw-hologram-card,
    html:not(.pathway-reduced-motion) .learning-world-page #lwQuestPopup {
        transition:
            transform var(--pm-dur-med) var(--pm-ease),
            box-shadow var(--pm-dur-med) var(--pm-ease),
            border-color var(--pm-dur-fast) ease,
            opacity var(--pm-dur-med) ease !important;
    }

    html:not(.pathway-reduced-motion) .learning-world-page .lw-gate-panel:not(.pathway-no-surface-hover):hover,
    html:not(.pathway-reduced-motion) .learning-world-page .lw-zone:not(.pathway-no-surface-hover):hover {
        transform: translateY(var(--pm-lift));
    }

    html:not(.pathway-reduced-motion) .learning-world-page #lwPathwayLoading {
        transition: opacity 0.5s var(--pm-ease), visibility 0.5s ease;
    }

    html:not(.pathway-reduced-motion) .learning-world-page .lw-film-subtitles:not([hidden]) {
        animation: pmSheetIn 0.4s var(--pm-ease) both;
    }
}

@media (prefers-reduced-motion: reduce) {
    html.pathway-reduced-motion body.page-os-shell #mainContent .card::after,
    html.pathway-reduced-motion body.page-os-shell .admin-main .card::after {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Phase 3 — Unified orchestration (transform + opacity only)
   Requires html.pathway-premium-motion (set by pathway_premium_motion.js)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: no-preference) {
    /* De-dupe: IO scroll reveal replaces immediate gold card stagger (gold CSS rule kept) */
    html:not(.pathway-reduced-motion) body.page-os-shell:not(.page-dashboard) #mainContent .card {
        animation: none !important;
    }

    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell:not(.page-dashboard) #mainContent .card {
        animation: none !important;
    }

    /* De-dupe: single page enter (no stacked blur from quality.css) */
    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell.page-enter:not(.page-dashboard) #mainContent,
    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell.page-enter:not(.page-dashboard) .hero,
    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-enter.page-os-shell main {
        animation: pathwayGoldPageIn 0.55s var(--pm-ease) both !important;
        filter: none !important;
    }

    /* GPU-only scroll reveal (replaces cardRise filter blur) */
    html.pathway-premium-motion:not(.pathway-reduced-motion) .reveal-on-load {
        animation: pmCardRise 0.72s var(--pm-ease) both !important;
        filter: none !important;
    }

    html.pathway-premium-motion:not(.pathway-reduced-motion) .reveal-on-load:nth-child(2) { animation-delay: 0.05s !important; }
    html.pathway-premium-motion:not(.pathway-reduced-motion) .reveal-on-load:nth-child(3) { animation-delay: 0.1s !important; }
    html.pathway-premium-motion:not(.pathway-reduced-motion) .reveal-on-load:nth-child(4) { animation-delay: 0.15s !important; }
    html.pathway-premium-motion:not(.pathway-reduced-motion) .reveal-on-load:nth-child(5) { animation-delay: 0.2s !important; }

    /* Section + text reveal (class toggled once by IO) */
    html.pathway-premium-motion:not(.pathway-reduced-motion) .pm-section-in {
        animation: pmSectionIn 0.62s var(--pm-ease) both;
    }

    html.pathway-premium-motion:not(.pathway-reduced-motion) .pm-text-in {
        animation: pmTextIn 0.52s var(--pm-ease) both;
    }

    html.pathway-premium-motion:not(.pathway-reduced-motion) .pm-text-in:nth-child(2) { animation-delay: 0.06s; }
    html.pathway-premium-motion:not(.pathway-reduced-motion) .pm-text-in:nth-child(3) { animation-delay: 0.12s; }

    /* Button hover lift (transform only — rest state unchanged) */
    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell:not(.home-cinematic) .btn:not(:disabled):not(.btn-ghost):hover,
    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell:not(.home-cinematic) a.btn:hover {
        transform: translate3d(0, -2px, 0);
    }

    /* Card hover lift where not locked by home-cinematic */
    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell:not(.home-cinematic) #mainContent .card:hover,
    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell:not(.home-cinematic) .admin-main .card:hover,
    html.pathway-premium-motion:not(.pathway-reduced-motion) body.page-os-shell:not(.home-cinematic) .form-card:hover {
        transform: translate3d(0, var(--pm-lift), 0);
    }

    /* Soft ambient gradient — GPU transform only (extends styles.css body::after) */
    html.pathway-premium-motion:not(.pathway-reduced-motion):not(.pathway-motion-lite) body.page-os-shell:not(.home-cinematic)::after {
        will-change: transform;
    }

    /* Progress bars / rings — one-shot fill on IO */
    html.pathway-premium-motion:not(.pathway-reduced-motion) .pm-progress-in progress::-webkit-progress-value,
    html.pathway-premium-motion:not(.pathway-reduced-motion) .pm-progress-in .progress-bar > span,
    html.pathway-premium-motion:not(.pathway-reduced-motion) .pm-progress-in .lw-pathway-loading-bar-fill {
        animation: pmProgressIn 0.9s var(--pm-ease) both;
        transform-origin: left center;
    }

    /* Toast / notification entrance */
    html.pathway-premium-motion:not(.pathway-reduced-motion) .pathway-xp-toast--in {
        animation: pmToastIn 0.42s var(--pm-ease) both;
    }

    html.pathway-premium-motion:not(.pathway-reduced-motion) .pathway-xp-toast--out {
        animation: pmToastOut 0.38s var(--pm-ease) both;
    }

    /* Loading submit state (auth + forms) */
    html.pathway-premium-motion:not(.pathway-reduced-motion) .pathway-auth-form.is-loading .pathway-auth-spinner,
    html.pathway-premium-motion:not(.pathway-reduced-motion) form.is-loading .pathway-auth-spinner {
        animation: pmSpin 0.65s linear infinite;
    }

    /* Nav active transition */
    html.pathway-premium-motion:not(.pathway-reduced-motion) .topbar .nav a.active,
    html.pathway-premium-motion:not(.pathway-reduced-motion) .admin-topbar-nav a.active {
        transition: color var(--pm-dur-fast) ease, opacity var(--pm-dur-fast) ease;
    }

    /* Auth floating shield — reuse existing keyframes, ensure GPU layer */
    html.pathway-premium-motion:not(.pathway-reduced-motion) .pathway-auth-visual__shield {
        will-change: transform;
    }

    /* Dashboard stat cards */
    html.pathway-premium-motion:not(.pathway-reduced-motion) .stat-card.reveal-on-load,
    html.pathway-premium-motion:not(.pathway-reduced-motion) .pilot-school-card.reveal-on-load {
        animation: pmCardRise 0.68s var(--pm-ease) both !important;
    }

    html.pathway-premium-motion:not(.pathway-reduced-motion) .pm-alert-in,
    html.pathway-premium-motion:not(.pathway-reduced-motion) .alert.error {
        animation: pmAlertIn 0.4s var(--pm-ease) both;
    }
}

/* Lite mode — essential motion only (low-end devices) */
@media (prefers-reduced-motion: no-preference) {
    html.pathway-premium-motion.pathway-motion-lite:not(.pathway-reduced-motion) .reveal-on-load {
        animation: pmCardRise 0.45s var(--pm-ease) both !important;
    }

    html.pathway-premium-motion.pathway-motion-lite:not(.pathway-reduced-motion) body.page-os-shell #mainContent .card::after,
    html.pathway-premium-motion.pathway-motion-lite:not(.pathway-reduced-motion) .admin-main .card::after {
        display: none !important;
    }
}

@keyframes pmCardRise {
    from {
        opacity: 0;
        transform: translate3d(0, 22px, 0) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

@keyframes pmSectionIn {
    from {
        opacity: 0;
        transform: translate3d(0, 16px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes pmTextIn {
    from {
        opacity: 0;
        transform: translate3d(0, 10px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

@keyframes pmProgressIn {
    from {
        opacity: 0.6;
        transform: scaleX(0);
    }
    to {
        opacity: 1;
        transform: scaleX(1);
    }
}

@keyframes pmToastIn {
    from {
        opacity: 0;
        transform: translate3d(0, 12px, 0) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
}

@keyframes pmToastOut {
    from {
        opacity: 1;
        transform: translate3d(0, 0, 0) scale(1);
    }
    to {
        opacity: 0;
        transform: translate3d(0, 8px, 0) scale(0.98);
    }
}

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