/* ============================================
   FX: Micro-interactions, ambience & motion
   ============================================ */

/* Animated aurora blobs */
.aurora {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.aurora::before,
.aurora::after {
    content: '';
    position: absolute;
    width: 46vmax;
    height: 46vmax;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.32;
    will-change: transform;
}

.aurora::before {
    top: -14vmax;
    left: -12vmax;
    background: radial-gradient(circle, color-mix(in srgb, var(--accent-primary) 55%, transparent), transparent 70%);
    animation: aurora-a 26s ease-in-out infinite alternate;
}

.aurora::after {
    bottom: -16vmax;
    right: -14vmax;
    background: radial-gradient(circle, color-mix(in srgb, var(--accent-secondary) 45%, transparent), transparent 70%);
    animation: aurora-b 32s ease-in-out infinite alternate;
}

@keyframes aurora-a {
    100% { transform: translate(9vmax, 6vmax) scale(1.16); }
}

@keyframes aurora-b {
    100% { transform: translate(-8vmax, -5vmax) scale(1.12); }
}

/* Scroll progress bar */
.scroll-progress {
    position: fixed;
    inset: 0 0 auto 0;
    height: 3px;
    z-index: 1001;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary), var(--accent-tertiary));
    transform-origin: 0 50%;
    transform: scaleX(0);
    will-change: transform;
}

/* Custom cursor */
body.fx-cursor * {
    cursor: none !important;
}

.cursor-dot,
.cursor-ring {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100000;
    border-radius: 50%;
    pointer-events: none;
    transform: translate(-50%, -50%);
    will-change: transform;
}

.cursor-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-primary);
}

.cursor-ring {
    width: 36px;
    height: 36px;
    border: 2px solid color-mix(in srgb, var(--accent-primary) 72%, transparent);
    transition: width 0.2s ease, height 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.cursor-ring.is-hovering {
    width: 56px;
    height: 56px;
    border-color: var(--accent-secondary);
    background: color-mix(in srgb, var(--accent-secondary) 14%, transparent);
}

/* Hero name gradient shine */
.hero-name {
    background: linear-gradient(110deg, var(--accent-primary), var(--accent-secondary), var(--accent-tertiary), var(--accent-primary));
    background-size: 300% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    animation: hero-name-shine 8s linear infinite;
}

@keyframes hero-name-shine {
    to { background-position: -300% 0; }
}

/* Hero entrance timeline: blur-rise cascade */
.portfolio-hero .fade-in {
    animation: hero-rise 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes hero-rise {
    from {
        opacity: 0;
        transform: translateY(26px);
        filter: blur(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0);
    }
}

/* Project card 3D tilt */
.project-card.is-tilting {
    transform-style: preserve-3d;
    will-change: transform;
    transition: transform 0.16s ease-out;
}

.project-card.is-tilting:hover {
    transition: transform 0.08s ease-out;
}

/* Skill proficiency meter */
.skill-meter {
    width: 100%;
    height: 5px;
    margin-top: 0.4rem;
    border-radius: 999px;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.skill-meter-fill {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Staggered group reveal (hidden only when JS + no reduced-motion) */
html.js [data-stagger]:not(.done) > * {
    opacity: 0;
}

[data-stagger].revealed > * {
    animation: stagger-pop 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

[data-stagger].revealed > *:nth-child(1) { animation-delay: 0.04s; }
[data-stagger].revealed > *:nth-child(2) { animation-delay: 0.1s; }
[data-stagger].revealed > *:nth-child(3) { animation-delay: 0.16s; }
[data-stagger].revealed > *:nth-child(4) { animation-delay: 0.22s; }
[data-stagger].revealed > *:nth-child(5) { animation-delay: 0.28s; }
[data-stagger].revealed > *:nth-child(6) { animation-delay: 0.34s; }
[data-stagger].revealed > *:nth-child(7) { animation-delay: 0.4s; }
[data-stagger].revealed > *:nth-child(8) { animation-delay: 0.46s; }
[data-stagger].revealed > *:nth-child(9) { animation-delay: 0.52s; }
[data-stagger].revealed > *:nth-child(n + 10) { animation-delay: 0.58s; }

[data-stagger].done > * {
    opacity: 1;
    transform: none;
    animation: none;
}

@keyframes stagger-pop {
    from {
        opacity: 0;
        transform: translateY(22px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Page content fade-in on load */
body.init > #main-content {
    animation: page-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes page-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   INTERACTIVE TERMINAL
   ============================================ */

.terminal {
    max-width: 760px;
    margin: 0 auto;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-lg);
    background: #0a0e13;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    cursor: text;
}

.terminal-bar {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 2.5rem;
    padding: 0 1rem;
    background: #11161c;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.terminal-dot {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}

.terminal-dot.dot-red { background: #ff5f56; }
.terminal-dot.dot-yellow { background: #ffbd2e; }
.terminal-dot.dot-green { background: #27c93f; }

.terminal-title {
    flex: 1;
    min-width: 0;
    margin-left: 0.35rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #8b98a5;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.02em;
}

.terminal-tag {
    flex-shrink: 0;
    padding: 0.18rem 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    color: #6e7c87;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.04em;
}

.terminal-body {
    position: relative;
    padding: 1rem 1.1rem 1.4rem;
    font-family: var(--font-mono);
    font-size: clamp(0.78rem, 1.6vw, 0.92rem);
    color: #c9d4dd;
    line-height: 1.6;
}

.terminal-log {
    max-height: 380px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.term-line {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.term-muted { color: #7c8b96; }
.term-cmd { color: #2dd4bf; font-weight: 700; }
.term-prefix { color: #3ddc97; font-weight: 700; margin-right: 0.4rem; }
.term-input { color: #e7ecf1; font-weight: 700; }

.term-cursor {
    display: inline-block;
    width: 0.55em;
    height: 1.1em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: #2dd4bf;
    animation: term-blink 1s steps(1) infinite;
}

@keyframes term-blink { 50% { opacity: 0; } }

.terminal-input {
    position: absolute;
    left: -9999px;
    opacity: 0;
    pointer-events: none;
}

/* ============================================
   CASE STUDY / RAIL
   ============================================ */

.case-study-layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: var(--spacing-2xl);
    align-items: start;
}

.case-rail {
    position: sticky;
    top: 6.5rem;
    display: grid;
    gap: 0.35rem;
}

.case-rail-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.8rem;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 800;
    transition: all var(--transition-fast);
}

.case-rail-link span {
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    font-size: 0.78rem;
}

.case-rail-link:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.case-rail-link.active {
    color: var(--accent-primary);
    background: var(--surface);
    border-color: var(--border-color);
}

.case-body {
    display: grid;
    gap: var(--spacing-3xl);
}

.case-chapter {
    padding-top: var(--spacing-sm);
    scroll-margin-top: 6.5rem;
}

.case-step {
    margin-bottom: var(--spacing-sm);
    color: var(--accent-secondary);
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 900;
}

.case-chapter h3 {
    font-size: 1.6rem;
    margin-bottom: var(--spacing-md);
}

.case-chapter .rich-text p {
    max-width: 68ch;
    font-size: 1.06rem;
}

/* Animated impact stat */
.impact-stat {
    margin: 0;
    font-size: clamp(1.5rem, 2.4vw, 2rem);
    font-weight: 800;
    line-height: 1.2;
    color: var(--text-primary);
    overflow-wrap: break-word;
}

.impact-num {
    background: linear-gradient(110deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* ============================================
   LIGHTBOX
   ============================================ */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.lightbox[hidden] {
    display: none;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.74);
    backdrop-filter: blur(6px);
}

.lightbox-image {
    position: relative;
    max-width: min(1080px, 92vw);
    max-height: 84vh;
    object-fit: contain;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    animation: scaleIn 0.25s ease;
}

.lightbox-close {
    position: absolute;
    top: 1.25rem;
    right: 1.25rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--surface-strong);
    color: var(--text-primary);
    padding: 0.6rem 0.9rem;
    font-weight: 800;
    cursor: pointer;
}

/* ============================================
   TECH MARQUEE
   ============================================ */

.marquee {
    overflow: hidden;
    border-block: 1px solid var(--border-color);
    background: var(--surface);
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
    mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
}

.marquee-track {
    display: flex;
    align-items: center;
    width: max-content;
    padding: 1.1rem 0;
    animation: marquee-scroll 30s linear infinite;
}

.marquee:hover .marquee-track {
    animation-play-state: paused;
}

.marquee-item {
    display: inline-flex;
    align-items: center;
    margin-right: 2.75rem;
    white-space: nowrap;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 800;
}

.marquee-item::after {
    content: '';
    width: 0.4rem;
    height: 0.4rem;
    margin-left: 2.75rem;
    border-radius: 50%;
    background: var(--accent-secondary);
}

@keyframes marquee-scroll {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
}

/* ============================================
   PAGE TRANSITIONS (View Transitions API)
   ============================================ */

@view-transition {
    navigation: auto;
}

#main-content {
    view-transition-name: page-content;
}

::view-transition-group(page-content) {
    animation-duration: 0.32s;
}

::view-transition-new(page-content) {
    animation: vt-in 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

::view-transition-old(page-content) {
    animation: vt-out 0.2s ease;
}

@keyframes vt-in {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes vt-out {
    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

@media (max-width: 900px) {
    .case-study-layout {
        grid-template-columns: 1fr;
    }

    .case-rail {
        position: static;
        grid-template-columns: repeat(3, 1fr);
    }

    .case-rail-link {
        justify-content: center;
    }
}

/* Reduced motion: kill everything */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }

    .term-cursor {
        animation: none;
        opacity: 0.6;
    }
}