/* =========================================
   CHMRQS ARTICLE LAYOUTS V3.1 (UNIFIED)
   ========================================= */

/* --- PROGRESS BAR --- */
.reading-progress.nav-background-strip {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 80px;
    /* Matches nav height */
    z-index: calc(var(--z-nav) - 1); /* Just below nav */
    /* Just below nav (500) */
    pointer-events: none;
    overflow: hidden;
}

.reading-progress-bar {
    height: 100%;
    background: var(--accent);
    width: 0%;
    box-shadow: 0 0 15px var(--accent);
    transition: width 0.1s linear;
}

/* --- WRAPPER --- */
.article-wrapper {
    max-width: 800px;
    /* Standard Layout Default */
    margin: 0 auto;
    padding: 0 20px 40px;
    /* Top padding géré par body global */
    position: relative;
    z-index: auto;
    /* Was 2, changed to auto to allow children to pop above cursor */
}

/* --- HEADER --- */
.article-header {
    margin-bottom: 60px;
    display: flex;
    flex-direction: column;
    padding-top: 40px;
    position: relative;
    /* Ensure abstract shard is positioned relative to header */
}

.article-header.no-hero {
    margin-bottom: 40px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 40px;
}

.header-content {
    margin-bottom: 30px;
}

/* Inherits global styles where possible, overrides only when needed */
.header-brand {
    font-family: var(--font-code);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.header-title {
    font-family: var(--font-head);
    font-size: clamp(2.5rem, 6vw, 4rem);
    color: var(--text-main);
    margin: 0 0 10px 0;
    line-height: 0.95;
    text-transform: uppercase;
    word-break: break-word;
}

.header-module {
    font-family: var(--font-code);
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    margin-top: 15px;
}

.article-desc {
    font-family: var(--font-body);
    color: #ccc;
    font-size: 1.1rem;
    line-height: 1.6;
    max-width: 100%;
    margin-bottom: 30px;
    padding-left: 20px;
    border-left: 3px solid var(--accent);
}

/* --- ABSTRACT SHARD (New Cover) --- */
.abstract-shard {
    position: absolute;
    top: -100px;
    right: -10%;
    width: 80%;
    height: 500px;
    background-size: cover;
    background-position: center;
    /* Abstract Geometric Shape */
    clip-path: polygon(20% 0, 100% 0, 100% 80%, 0 100%);
    /* Glassmorphism & Abstraction */
    filter: blur(15px) contrast(1.2) brightness(0.6) saturate(1.2);
    opacity: 0.6;
    z-index: 0;
    pointer-events: none;
    mix-blend-mode: screen;
    transform: rotate(-5deg);
    mask-image: linear-gradient(to bottom, black 40%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 40%, transparent 100%);
}

/* Mobile Adjustment */
@media (max-width: 768px) {
    .abstract-shard {
        width: 100%;
        right: 0;
        height: 350px;
        filter: blur(10px) brightness(0.5);
        clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%);
        transform: none;
    }
}

/* --- CONTENT --- */
.article-content {
    font-size: 1.1rem;
    line-height: 1.8;
    color: #d4d4d4;
    font-family: var(--font-body);
    opacity: 0;
    animation: fade-in-up 0.8s ease-out forwards;
    animation-delay: 0.2s;
}

@keyframes fade-in-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.article-content p {
    margin-bottom: 24px;
}

.article-content h2 {
    font-family: var(--font-head);
    font-size: 1.8rem;
    color: var(--text-main);
    margin-top: 60px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
}

.article-content h3 {
    font-family: var(--font-code);
    font-size: 1.3rem;
    color: var(--accent);
    margin-top: 40px;
    margin-bottom: 15px;
}

.article-content a {
    color: var(--accent);
    border-bottom: 1px dashed var(--accent);
    transition: all 0.2s;
}

.article-content a:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* --- IMAGES IN CONTENT --- */
.article-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 30px 0 10px 0;
    border: 1px solid var(--border);
    display: block;
}

.notion-image figcaption {
    font-family: var(--font-code);
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 10px;
}

/* --- SPECIAL BLOCKS --- */
.notion-quote {
    border-left: 3px solid var(--accent);
    padding-left: 20px;
    margin: 30px 0;
    font-style: italic;
    color: #aaa;
    background: rgba(255, 255, 255, 0.02);
    padding: 20px;
    border-radius: 0 4px 4px 0;
}

.notion-callout {
    background: #111;
    border: 1px solid #333;
    padding: 20px;
    border-radius: 6px;
    display: flex;
    gap: 15px;
    margin: 30px 0;
    align-items: flex-start;
}

.notion-divider {
    border: 0;
    height: 1px;
    background: var(--border);
    margin: 40px 0;
}

.notion-code {
    background: #08080a;
    border: 1px solid var(--border);
    padding: 20px;
    overflow-x: auto;
    margin: 30px 0;
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: var(--font-code);
}

/* --- NAVIGATION PANEL --- */
.article-nav-panel {
    margin-top: 80px;
    padding-top: 40px;
    margin-bottom: 40px;
}

.nav-divider {
    border-top: 1px dashed var(--border);
    text-align: center;
    margin-bottom: 40px;
    height: 1px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.nav-divider span {
    background: var(--bg);
    padding: 0 20px;
    color: var(--text-muted);
    font-family: var(--font-code);
    font-size: 0.9rem;
    letter-spacing: 2px;
}

.nav-actions {
    display: flex;
    justify-content: center;
    gap: 20px;
}

.nav-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 15px 30px;
    font-family: var(--font-code);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(255, 255, 255, 0.03);
}

.nav-btn.primary {
    border-color: var(--accent);
    color: var(--accent);
}

.nav-btn.primary:hover {
    background: var(--accent);
    color: #000;
}

/* --- LAYOUT: MASONRY (SMART GRID) --- */

body.layout-masonry .article-wrapper {
    max-width: 1200px;
    /* Plus large pour apprécier la grille */
    padding: 0 40px 40px;
}

body.layout-masonry .article-content {
    /* ON ACTIVE LA GRILLE */
    display: grid;
    /* Colonnes responsives : minimum 300px, sinon partage l'espace */
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    /* La hauteur des lignes sert d'unité de base pour le JS (10px) */
    grid-auto-rows: 10px;
    gap: 20px;
}

body.layout-masonry .span-col-2 {
    grid-column: span 2;
}

body.layout-masonry .notion-image {
    margin: 0;
    /* Le JS et le Grid gèrent l'espacement */
    display: block;
    width: 100%;
    /* Important pour l'alignement */
    align-self: start;
}

body.layout-masonry .notion-image img {
    width: 100%;
    height: auto;
    display: block;
    border: 1px solid #333;
    border-radius: 4px;
    transition: transform 0.3s ease;
}

/* --- RESPONSIVE --- */

/* Tablet: 2 Columns */
@media (max-width: 1200px) {
    body.layout-masonry .article-content {
        column-count: 2;
    }
}

/* Mobile: 1 Column */
@media (max-width: 768px) {
    body.layout-masonry .article-content {
        column-count: 1;
    }

    body.layout-masonry .notion-image img {
        height: auto;
        aspect-ratio: 16/9;
    }
}

/* Hide clutter in Masonry */
body.layout-masonry .notion-divider,
body.layout-masonry h2,
body.layout-masonry h3,
body.layout-masonry .article-content p {
    display: none;
}

/* --- RESPONSIVE NAV --- */
@media (max-width: 1024px) {
    .article-header {
        padding-top: 20px;
    }

    .header-title {
        font-size: 2.5rem;
    }

    .nav-actions {
        flex-direction: column;
    }

    .nav-btn {
        width: 100%;
        justify-content: center;
    }
}

/* =========================================
   10. LIGHTBOX & PROTECTION
   ========================================= */

/* Protection */
img {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-select: none;
    -webkit-user-select: none;
}

/* Lightbox Overlay */
#lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: var(--z-lightbox);
    /* Increased to cover Nav/Back links (60005) */
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    cursor: none; /* Custom cursor (Cross) handles this */
}

#lightbox-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

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

.lightbox-container {
    position: relative;
    z-index: 2;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    /* Removed border/shadow from img, moved to frame */
    user-select: none;
    /* Protection inside lightbox */
    cursor: none; /* Hide system cursor for custom ring */
}

.lightbox-frame {
    position: relative;
    /* CRITICAL: Masks the zoomed image */
    overflow: hidden;
    
    /* Frame Styling */
    border: 1px solid var(--border);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    
    /* Flex to center image */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- LIGHTBOX CURSOR OVERRIDE --- */
body.lightbox-active .cursor-dot,
body.lightbox-active .cursor-ring {
    z-index: calc(var(--z-cursor) - 1) !important; /* Below cursor */
    /* Above Lightbox (80000) */
}

.lightbox-caption {
    margin-top: 15px;
    font-family: var(--font-code);
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
    background: rgba(0, 0, 0, 0.5);
    padding: 5px 15px;
    border-radius: 4px;
}

/* Controls */
.lightbox-close {
    position: absolute;
    top: -50px;
    right: 0;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    transition: color 0.3s;
}

.lightbox-close:hover {
    color: var(--accent);
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: #fff;
    font-size: 1.5rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s;
}

.lightbox-nav:hover {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
}

.lightbox-nav.prev {
    left: -80px;
}

.lightbox-nav.next {
    right: -80px;
}

@media (max-width: 768px) {
    .lightbox-nav {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
        background: rgba(0, 0, 0, 0.5);
    }

    .lightbox-nav.prev {
        left: 10px;
    }

    .lightbox-nav.next {
        right: 10px;
    }

    .lightbox-close {
        top: 10px;
        right: 10px;
        position: fixed;
        z-index: 10;
    }
}

/* --- READING PROGRESS BAR --- */
#prog-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: var(--accent);
    width: 0%;
    z-index: calc(var(--z-cursor) - 1); /* Below cursor, topmost visibility */
    box-shadow: 0 0 10px var(--accent-glow), 0 0 20px var(--accent-glow);
    transition: width 0.1s ease-out;
    pointer-events: none;
}

/* --- PREMIUM INFINITE SCROLL ANIMATIONS --- */
.article-content .notion-image {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease-out, transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: opacity, transform;
}

.article-content .notion-image.loaded {
    opacity: 1;
    transform: translateY(0);
}

/* --- PREMIUM LOADER --- */
#loading-indicator {
    text-align: center;
    padding: 40px;
    font-family: var(--font-code);
    color: var(--text-muted);
    font-size: 0.9rem;
    display: none; /* Hidden by default */
}

/* Replace text with spinner */
#loading-indicator::after {
    content: '';
    display: inline-block;
    width: 30px;
    height: 30px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

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