/* ==========================================================================
   SEGUI IL FILO — CSS SPECIFICO (Aesthetics: Bordeaux / Gold / Dark Mode)
   ========================================================================== */

:root {
    --accent-oro: #d4af37;
    --bg-card: rgba(255, 255, 255, 0.03);
    --border-soft: rgba(255, 255, 255, 0.08);
    --transition-panel: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    --font-heading: 'Playfair Display', serif;
    --font-body: 'Inter', sans-serif;
}

/* Container & Trigger Button */
.thread-container {
    margin: 80px 0 40px;
    padding: 30px;
    background: linear-gradient(180deg, rgba(212, 175, 55, 0.01) 0%, rgba(212, 175, 55, 0.03) 100%);
    border-top: 1px solid var(--border-soft);
    border-bottom: 1px solid var(--border-soft);
    text-align: center;
    border-radius: 8px;
}

.thread-trigger-wrapper {
    display: inline-block;
}

.thread-trigger-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--accent-oro);
    color: var(--accent-oro);
    padding: 15px 40px;
    font-size: 1.1rem;
    font-family: var(--font-body);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.thread-trigger-btn:hover {
    background: var(--accent-oro);
    color: #121212;
}

.thread-trigger-icon {
    width: 60px;
    height: 12px;
    margin-bottom: 8px;
    color: currentColor;
    opacity: 0.8;
    transition: transform 0.3s ease;
}

.thread-trigger-btn:hover .thread-trigger-icon {
    transform: scaleX(1.1);
}

.thread-arrow {
    display: inline-block;
    transition: transform 0.3s ease;
}

.thread-trigger-btn:hover .thread-arrow {
    transform: translateX(5px);
}

/* Fallback Inline (No JS) */
.thread-inline-fallback {
    margin-top: 40px;
    text-align: left;
}

.thread-fallback-header {
    margin-bottom: 45px;
    text-align: center;
}

.thread-kicker {
    display: block;
    font-family: var(--font-body);
    text-transform: uppercase;
    letter-spacing: 3px;
    font-size: 0.85rem;
    color: var(--accent-oro);
    margin-bottom: 10px;
}

.thread-fallback-header h2,
.thread-panel-header h2 {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    color: #fff;
    margin: 0 0 15px 0;
}

.thread-intro {
    font-size: 1.1rem;
    color: #aaa;
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.6;
}

.thread-fallback-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
}

/* Panel Overlay (Glassmorphism) */
.thread-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10002;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

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

/* Panel / Drawer (Bordeaux molto scuro con tocchi d'oro) */
.thread-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 480px;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    background-color: #160c0e; /* Bordeaux scurissimo */
    border-left: 1px solid rgba(212, 175, 55, 0.15);
    z-index: 10003;
    transform: translateX(100%);
    transition: var(--transition-panel);
    display: flex;
    flex-direction: column;
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.8);
}

.thread-panel.active {
    transform: translateX(0);
}

/* Header & Footer del Pannello */
.thread-panel-header {
    padding: 40px 40px 25px 40px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
}

.thread-close-btn {
    position: absolute;
    top: 30px;
    right: 30px;
    background: transparent;
    border: none;
    color: #888;
    font-size: 2.2rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s ease;
}

.thread-close-btn:hover {
    color: var(--accent-oro);
}

.thread-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    scroll-behavior: smooth;
}

.thread-panel-footer {
    padding: 25px 40px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: #11090a;
}

.thread-back-btn {
    width: 100%;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ccc;
    padding: 12px;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.3s ease;
}

.thread-back-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border-color: var(--accent-oro);
}

/* Card Relazioni */
.thread-list {
    list-style: none;
    padding: 0;
    margin: 0;
    position: relative;
}

/* Il Filo Conduttore (Linea Dorata) */
.thread-list::before {
    content: '';
    position: absolute;
    top: 15px;
    left: 20px;
    bottom: 15px;
    width: 1px;
    background: linear-gradient(to bottom, transparent, var(--accent-oro) 10%, var(--accent-oro) 90%, transparent);
    opacity: 0.3;
}

.thread-card {
    position: relative;
    padding-left: 50px;
    margin-bottom: 40px;
}

.thread-card:last-child {
    margin-bottom: 0;
}

/* Il Nodo Dorato sul Filo */
.thread-card::before {
    content: '';
    position: absolute;
    top: 15px;
    left: 17px;
    width: 7px;
    height: 7px;
    background-color: var(--accent-oro);
    border-radius: 50%;
    z-index: 2;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.thread-card:hover::before {
    transform: scale(1.4);
    box-shadow: 0 0 10px var(--accent-oro);
}

/* Contenuto Card Linkable */
.thread-card-link {
    display: block;
    text-decoration: none;
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.thread-card-link:hover {
    border-color: rgba(212, 175, 55, 0.3);
    background: rgba(255, 255, 255, 0.05);
    transform: translateY(-2px);
}

/* Mini Copertina / Immagine Card */
.thread-card-img-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: #000;
}

/* Modifica specifica per i libri (evita il taglio delle copertine verticali) */
.thread-card--book .thread-card-img-wrapper {
    aspect-ratio: 3 / 4;
    background: #121212;
}

.thread-card--book .thread-card-img {
    object-position: center;
}

.thread-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 15%; /* Mantiene visibile la parte superiore delle immagini (teste e volti nei ritratti) */
    filter: grayscale(100%);
    transition: filter 0.6s ease, transform 0.8s ease;
}

/* Modifiche per i loghi/progetti e per articoli con loghi (evita tagli) */
.thread-card--project .thread-card-img,
.thread-card-img[src*="logo-g9"] {
    object-fit: contain;
    object-position: center;
    padding: 20px;
    background-color: #121212; /* Sfondo scuro per far risaltare il logo bianco */
    filter: none;
}

/* Posizionamento specifico per copertine con testo allineato a sinistra per evitare il taglio delle lettere iniziali */
.thread-card-img[src*="abdicare_cover"],
.thread-card-img[src*="cover_scorciatoie"],
.thread-card-img[src*="cover_illusione_testo"] {
    object-position: left center;
}

.thread-card-link:hover .thread-card-img {
    filter: grayscale(0%);
    transform: scale(1.03);
}

/* Testi Card */
.thread-card-body {
    padding: 25px;
}

.thread-label {
    display: inline-block;
    color: var(--accent-oro);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 12px;
}

.thread-card-body h3 {
    font-family: var(--font-heading);
    font-size: 1.35rem;
    color: #fff;
    margin: 0 0 10px 0;
    line-height: 1.3;
}

.thread-card-body p {
    font-size: 0.95rem;
    color: #ccc;
    line-height: 1.6;
    margin: 0 0 20px 0;
    display: -webkit-box;
    -webkit-line-clamp: 6;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.thread-cta {
    display: inline-block;
    font-size: 0.85rem;
    color: var(--accent-oro);
    font-weight: 600;
    transition: transform 0.2s ease;
}

.thread-card-link:hover .thread-cta {
    transform: translateX(4px);
}

/* Bottom Notification: Riprendi il Filo */
.resume-thread-banner {
    position: fixed;
    bottom: 30px;
    left: 30px;
    background-color: #1a0f11;
    border: 1px solid var(--accent-oro);
    border-radius: 6px;
    padding: 20px 25px;
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    max-width: 380px;
    transform: translateY(150px);
    opacity: 0;
    transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.6s ease;
    display: flex;
    flex-direction: column;
}

.resume-thread-banner.visible {
    transform: translateY(0);
    opacity: 1;
}

.resume-thread-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.resume-thread-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--accent-oro);
    font-weight: 600;
}

.resume-thread-close {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0;
    line-height: 1;
}

.resume-thread-close:hover {
    color: #fff;
}

.resume-thread-body {
    color: #eee;
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 15px;
}

.resume-thread-link {
    align-self: flex-start;
    color: var(--accent-oro);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.resume-thread-link:hover {
    text-decoration: underline;
}

/* ==========================================================================
   RESPONSIVE DESIGN & ACCESSIBILITY
   ========================================================================== */

/* Mobile Bottom Sheet (< 900px) */
@media (max-width: 900px) {
    .thread-panel {
        top: auto;
        bottom: 0;
        right: 0;
        width: 100%;
        height: 85vh;
        border-left: none;
        border-top: 1px solid rgba(212, 175, 55, 0.25);
        transform: translateY(100%);
    }

    .thread-panel.active {
        transform: translateY(0);
    }
    
    .thread-panel-header {
        padding: 35px 25px 20px 25px;
    }
    
    .thread-close-btn {
        top: 25px;
        right: 25px;
    }
    
    .thread-panel-content {
        padding: 25px;
    }
    
    .thread-panel-footer {
        padding: 20px 25px;
    }

    .resume-thread-banner {
        left: 20px;
        right: 20px;
        max-width: none;
    }
}

/* Accessibilità tastiera */
.thread-trigger-btn:focus-visible,
.thread-close-btn:focus-visible,
.thread-back-btn:focus-visible,
.thread-card-link:focus-visible,
.resume-thread-link:focus-visible,
.resume-thread-close:focus-visible {
    outline: 2px solid var(--accent-oro);
    outline-offset: 4px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .thread-panel,
    .thread-overlay,
    .thread-trigger-btn,
    .thread-trigger-icon,
    .thread-arrow,
    .thread-card-link,
    .thread-card-img,
    .resume-thread-banner {
        transition: none !important;
        transform: none !important;
    }
    
    .thread-overlay.active {
        opacity: 1 !important;
    }
    
    .thread-panel.active {
        transform: none !important;
    }
}

/* --- ZETTELKASTEN TOOLTIP --- */
.zettel-tooltip {
    position: fixed;
    pointer-events: none;
    z-index: 10000;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    background: rgba(15, 15, 15, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-radius: 6px;
    padding: 10px;
    width: 260px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    color: var(--text-light, #e0e0e0);
}

.zettel-tooltip.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.zettel-tooltip-inner {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.zettel-tooltip-inner img {
    width: 50px;
    aspect-ratio: 2/3;
    object-fit: cover;
    border-radius: 4px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.zettel-tooltip-text strong {
    display: block;
    font-size: 0.9rem;
    color: var(--accent-oro, #D4AF37);
    margin-bottom: 4px;
    line-height: 1.2;
}

.zettel-tooltip-text p {
    font-size: 0.75rem;
    line-height: 1.4;
    margin: 0;
    opacity: 0.8;
}

/* --- INLINE EXPANSION STYLES --- */
.thread-container--inline {
    margin-top: 30px;
    width: 100%;
}
.thread-trigger-btn--inline[aria-expanded="true"] .thread-arrow {
    transform: rotate(180deg);
}
.thread-panel-inline {
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.6s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.6s ease;
    margin-top: 20px;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 0 25px;
    border-left: 1px solid var(--accent-oro);
}
.thread-panel-inline.active {
    max-height: 2000px;
    opacity: 1;
    padding: 30px 25px;
    margin-bottom: 20px;
}
.thread-panel-inline .thread-panel-header {
    margin-bottom: 30px;
}
.thread-panel-inline .thread-kicker {
    display: block;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--accent-oro);
    margin-bottom: 8px;
}
.thread-panel-inline h2 {
    font-size: 1.8rem;
    margin-bottom: 15px;
}
