/* ── Loader ─────────────────────────────────────────────────────────────── */
.loader-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f8fafc;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

/* ── Spinning ring + initials ───────────────────────────────────────────── */
.loader-brand {
    position: relative;
    width: 110px;
    height: 110px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid #e2e8f0;
    border-top-color: #06b6d4;
    border-right-color: #3b82f6;
    animation: loaderSpin 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}

.loader-initials {
    position: relative;
    z-index: 2;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    background: linear-gradient(135deg, #06b6d4, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
}

/* ── Progress bar + status ──────────────────────────────────────────────── */
.loader-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    width: 180px;
}

.loader-bar {
    width: 100%;
    height: 3px;
    background: #e2e8f0;
    border-radius: 2px;
    overflow: hidden;
}

.loader-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #06b6d4, #3b82f6);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.loader-status {
    font-size: 0.72rem;
    font-weight: 600;
    color: #94a3b8;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    margin: 0;
}

.loader-dots span {
    opacity: 0;
    animation: loaderDotFade 1.4s ease-in-out infinite;
}

.loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.loader-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ── Keyframes ──────────────────────────────────────────────────────────── */
@keyframes loaderSpin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes loaderDotFade {
    0%, 20%  { opacity: 0; }
    50%      { opacity: 1; }
    80%, 100% { opacity: 0; }
}

.latest-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.home-articles-title {
    font-size: 38px;
    font-weight: 800;
    color: var(--primary-color);
    margin: 0;
}

.home-articles-title::after {
    content: "";
    display: block;
    width: 50px;
    height: 3px;
    background: linear-gradient(135deg, #06b6d4, #3b82f6);
    border-radius: 2px;
    margin: 8px auto 16px;
}

.view-all-link {
    font-weight: 600;
    font-size: 0.95rem;
    display: inline-block;
}

.home-articles {
    padding-top: 60px;
    padding-bottom: 80px;
    margin-top: 0;
}

.home-articles .view-all-link {
    color: #0284c7;
    font-size: 14px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    margin-top: 4px;
    transition: color 0.2s ease, transform 0.2s ease;
}

.home-articles .view-all-link:hover {
    color: #06b6d4;
    transform: translateX(3px);
}

.home-articles .insight-grid {
    gap: 24px;
    align-items: stretch;
}

.home-articles .insight-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    transition: box-shadow 0.25s ease, border-color 0.25s ease, transform 0.25s ease;
}

.home-articles .insight-card:hover {
    box-shadow: 0 8px 24px rgba(6, 182, 212, 0.12);
    border-color: #bae6fd;
    transform: translateY(-4px);
}

.home-articles .insight-image {
    height: 200px;
    object-fit: cover;
    width: 100%;
    opacity: 0.9;
    transition: opacity 0.25s ease;
}

.home-articles .insight-card:hover .insight-image {
    opacity: 1;
}

.home-articles .insight-content {
    padding: 16px 20px;
    background: #fff;
}

.home-articles .insight-meta {
    font-size: 11px;
    color: #94a3b8;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 0;
}

.home-articles .insight-title {
    font-size: 17px;
    font-weight: 700;
    margin-top: 6px;
    margin-bottom: 8px;
    line-height: 1.4;
}

.home-articles .insight-title a {
    color: #0284c7;
}

.home-articles .insight-title a:hover {
    color: #06b6d4;
}

.home-articles .insight-content p {
    font-size: 14px;
    color: #64748b;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 0;
}

.home-articles .card-author {
    font-size: 13px;
    color: #94a3b8;
    margin-top: 10px;
}

.home-articles .card-author strong {
    color: #374151;
    font-weight: 600;
}

.insight-image-placeholder {
    background-color: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
}

@media (prefers-reduced-motion: reduce) {
    .loader-ring {
        animation: none !important;
    }
    .loader-dots span {
        animation: none !important;
        opacity: 1 !important;
    }
}

/* ── Staggered reveal for insight cards ──────────────────────────────────── */
@keyframes insightCardReveal {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: no-preference) {
    .home-articles.is-visible .insight-card:nth-child(1) { animation: insightCardReveal 0.6s ease 0.1s  backwards; }
    .home-articles.is-visible .insight-card:nth-child(2) { animation: insightCardReveal 0.6s ease 0.22s backwards; }
    .home-articles.is-visible .insight-card:nth-child(3) { animation: insightCardReveal 0.6s ease 0.34s backwards; }
}

@media (max-width: 1024px) {
    .home-articles .insight-grid {
        gap: 16px;
    }
}

@media (max-width: 768px) {
    .home-articles {
        margin-top: 0;
        padding: 40px 0 60px;
    }

    .home-articles .insight-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .home-articles .latest-header {
        flex-direction: column;
        gap: 8px;
    }

    /* Mobile-only: let the browser skip layout + paint for every below-fold
       section until it approaches the viewport, then render each one
       incrementally as the user scrolls past. This spreads the first-scroll
       paint cost across many small frames (~2-5ms per section) instead of
       one huge spike at the hero→content transition, which was the lag the
       user was feeling.

       Three sections are intentionally excluded — the upper part of the page
       that the user reaches before building scroll inertia:
         - about-intro: first section the user scrolls to, must be ready
           immediately so the hero→about transition is instant.
         - home-tech-section: the skills carousel contains ~50 tech cards
           (~6400px of horizontal content inside a clipped wrapper) with
           gradient backgrounds, box-shadows, and `filter: brightness/invert`
           on every SVG icon. Waking that subtree up with content-visibility
           caused a ~1s layout+paint spike the user could feel on first scroll.
         - home-experience-section: alternating timeline with multiple cards,
           each with border + box-shadow + date badge + gradient icon. First
           hydration of this subtree cost ~500ms on mobile — small but still
           perceivable. Rendered under the loader instead so it's invisible.

       Everything from recommendations down still uses content-visibility
       because by that point the user has already built scroll inertia and
       small per-section paint spikes are hidden inside the scroll momentum.

       contain-intrinsic-size reserves a rough block of space up front so the
       page's total height is stable before sections hydrate; the `auto`
       keyword swaps in the real measured size once a section has rendered
       once, so the scrollbar and anchor links stay accurate. */
    .rec-section,
    .home-projects-section,
    .home-education-section,
    .home-articles,
    .contact-section {
        content-visibility: auto;
        contain-intrinsic-size: auto 900px;
    }
}

@media (max-width: 480px) {
    .home-articles {
        padding: 32px 0 48px;
    }

    .home-articles .latest-header h2 {
        font-size: 20px;
    }

    .home-articles .insight-image {
        height: 160px;
    }

    .home-articles .insight-content {
        padding: 12px 14px;
    }

    .home-articles .insight-title {
        font-size: 15px;
    }
}

/* ── Dark mode overrides ─────────────────────────────────────────────────── */
[data-theme="dark"] .loader-wrapper {
    background: #0f172a;
}

[data-theme="dark"] .loader-ring {
    border-color: #334155;
    border-top-color: #06b6d4;
    border-right-color: #3b82f6;
}

[data-theme="dark"] .loader-bar {
    background: #334155;
}

[data-theme="dark"] .loader-status {
    color: #64748b;
}

[data-theme="dark"] .home-articles {
    background:
        radial-gradient(ellipse at 10% 30%, rgba(6, 182, 212, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 90% 70%, rgba(99, 102, 241, 0.04) 0%, transparent 50%);
}

[data-theme="dark"] .home-articles-title {
    color: #e2e8f0;
}

[data-theme="dark"] .home-articles .insight-card {
    background: #1e293b;
    border-color: #334155;
}

[data-theme="dark"] .home-articles .insight-content {
    background: #1e293b;
}

[data-theme="dark"] .home-articles .insight-content p {
    color: #94a3b8;
}

[data-theme="dark"] .home-articles .card-author {
    color: #64748b;
}

[data-theme="dark"] .home-articles .card-author strong {
    color: #94a3b8;
}

[data-theme="dark"] .insight-image-placeholder {
    background-color: #334155;
    color: #64748b;
}

@media (min-width: 769px) {
    .home-articles .insight-grid {
        margin-bottom: 0 !important;
    }

    footer {
        margin-top: 0 !important;
    }
}