/* ============================================================
   news-flipboard-mobile.css
   Layout mobile stile Flipboard con EFFETTO FLIP 3D per le news:
   - Deck di card impilate con prospettiva 3D
   - Swipe up (o tap) → flip 3D della card in alto, la successiva sale
   - Tap sulla card → flippa per mostrare excerpt/dettagli sul retro
   - Tap again → flippa indietro
   - Tap "Leggi" → apre articolo
   Su desktop il layout mostra la grid normale (vedi news-enhancements.css).
   ============================================================ */

/* === LISTA ARTICOLI (Flipboard-style 3D deck) === */

.news-flipboard-list {
    display: none;
}

@media (max-width: 768px) {
    /* Su mobile nascondi la grid desktop */
    .news-grid--latest {
        display: none;
    }

    /* Mostra la Flipboard list come deck 3D */
    .news-flipboard-list {
        display: block;
        margin: 16px 0 80px;
        padding: 0 var(--news-fb-gutter, 14px);
        padding-left: max(14px, env(safe-area-inset-left, 0px));
        padding-right: max(14px, env(safe-area-inset-right, 0px));
        /* Prospettiva 3D per effetto flip */
        perspective: 1400px;
        perspective-origin: 50% 30%;
    }

    /* === DECK (contenitore delle card impilate) === */
    .news-flipboard-deck {
        position: relative;
        width: 100%;
        height: 78vh;
        min-height: 520px;
        max-height: 760px;
        transform-style: preserve-3d;
        -webkit-transform-style: preserve-3d;
    }

    /* === Singola card === */
    .news-flipboard-card {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        margin: 0;
        background: white;
        border-radius: 22px;
        overflow: hidden;
        box-shadow:
            0 30px 60px -20px rgba(15, 23, 42, 0.35),
            0 18px 36px -18px rgba(99, 102, 241, 0.25),
            0 8px 16px rgba(15, 23, 42, 0.15);
        border: 1px solid rgba(99, 102, 241, 0.1);
        -webkit-tap-highlight-color: transparent;
        transform-style: preserve-3d;
        -webkit-transform-style: preserve-3d;
        transition:
            transform 0.55s cubic-bezier(0.23, 1, 0.32, 1),
            opacity 0.55s cubic-bezier(0.23, 1, 0.32, 1),
            box-shadow 0.4s ease;
        will-change: transform, opacity;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
    }

    /* Stato base: card in posizione con profondità variabile */
    .news-flipboard-card[data-stack-pos="0"] {
        z-index: 50;
        transform: translate3d(0, 0, 0) scale(1) rotateX(0deg);
        opacity: 1;
        pointer-events: auto;
    }
    .news-flipboard-card[data-stack-pos="1"] {
        z-index: 40;
        transform: translate3d(0, 14px, -80px) scale(0.96) rotateX(2.5deg);
        opacity: 0.95;
        pointer-events: none;
    }
    .news-flipboard-card[data-stack-pos="2"] {
        z-index: 30;
        transform: translate3d(0, 32px, -160px) scale(0.92) rotateX(5deg);
        opacity: 0.85;
        pointer-events: none;
    }
    .news-flipboard-card[data-stack-pos="3"] {
        z-index: 20;
        transform: translate3d(0, 54px, -240px) scale(0.88) rotateX(7deg);
        opacity: 0.65;
        pointer-events: none;
    }
    .news-flipboard-card[data-stack-pos="4"],
    .news-flipboard-card[data-stack-pos="5"] {
        z-index: 10;
        transform: translate3d(0, 80px, -320px) scale(0.84) rotateX(9deg);
        opacity: 0;
        pointer-events: none;
    }

    /* Stato FLIP (card girata sul proprio asse Y per mostrare il retro) */
    .news-flipboard-card.is-flipped {
        transform: translate3d(0, 0, 0) scale(1) rotateY(180deg) !important;
    }

    /* Stato EXIT (card che esce dal deck dopo swipe up, flip e fade) */
    .news-flipboard-card.is-exiting {
        transform: translate3d(0, -120%, -200px) scale(0.92) rotateX(-18deg) rotateZ(-6deg) !important;
        opacity: 0 !important;
        transition:
            transform 0.65s cubic-bezier(0.55, 0.06, 0.68, 0.19),
            opacity 0.5s ease-in;
    }

    /* Stato DRAGGING (l'utente sta trascinando la card) */
    .news-flipboard-card.is-dragging {
        transition: none !important;
        cursor: grabbing;
    }

    /* === Fronte e retro della card (3D flip interno) === */
    .news-flipboard-card-inner {
        position: relative;
        width: 100%;
        height: 100%;
        transform-style: preserve-3d;
        -webkit-transform-style: preserve-3d;
        transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
    }
    .news-flipboard-card.is-flipped .news-flipboard-card-inner {
        transform: rotateY(180deg);
    }

    .news-flipboard-face {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    .news-flipboard-face--front {
        transform: rotateY(0deg);
    }
    .news-flipboard-face--back {
        transform: rotateY(180deg);
        background: linear-gradient(160deg, #f8fafc 0%, #eef2ff 100%);
    }

    /* === FRONT: immagine + contenuto sovrapposto === */
    .news-flipboard-image {
        position: relative;
        flex: 1 1 auto;
        width: 100%;
        overflow: hidden;
        background: linear-gradient(135deg, #c7d2fe 0%, #a78bfa 100%);
        min-height: 0;
    }
    .news-flipboard-image img {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
        transition: transform 0.5s ease;
    }
    .news-flipboard-card:hover .news-flipboard-image img,
    .news-flipboard-card.is-flipped .news-flipboard-image img {
        transform: scale(1.04);
    }
    .news-flipboard-image::after {
        content: "";
        position: absolute;
        inset: 0;
        background:
            linear-gradient(180deg, transparent 0%, transparent 45%, rgba(15, 23, 42, 0.85) 100%);
        pointer-events: none;
    }
    .news-flipboard-category {
        position: absolute;
        top: 14px;
        left: 14px;
        padding: 6px 14px;
        border-radius: 20px;
        font-size: 0.72rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: white;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
        z-index: 3;
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
    }
    .news-flipboard-readtime {
        position: absolute;
        top: 14px;
        right: 14px;
        padding: 6px 12px;
        border-radius: 20px;
        font-size: 0.72rem;
        font-weight: 600;
        background: rgba(15, 23, 42, 0.6);
        color: white;
        z-index: 3;
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
        display: inline-flex;
        align-items: center;
        gap: 4px;
    }

    .news-flipboard-title-overlay {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        padding: 24px 20px 20px;
        color: white;
        z-index: 2;
    }
    .news-flipboard-title-overlay h3 {
        margin: 0 0 8px;
        font-size: 1.25rem;
        line-height: 1.25;
        font-weight: 800;
        text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
        color: white;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    .news-flipboard-title-overlay .news-flipboard-meta-mini {
        display: flex;
        gap: 12px;
        font-size: 0.78rem;
        font-weight: 500;
        color: rgba(255, 255, 255, 0.85);
        align-items: center;
    }
    .news-flipboard-title-overlay .news-flipboard-meta-mini span {
        display: inline-flex;
        align-items: center;
        gap: 4px;
    }

    /* === BACK: dettagli articolo === */
    .news-flipboard-back-content {
        flex: 1 1 auto;
        padding: 28px 24px 20px;
        display: flex;
        flex-direction: column;
        gap: 14px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .news-flipboard-back-content .back-category {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        align-self: flex-start;
        padding: 5px 12px;
        border-radius: 14px;
        font-size: 0.72rem;
        font-weight: 700;
        text-transform: uppercase;
        color: white;
        letter-spacing: 0.04em;
    }
    .news-flipboard-back-content h3 {
        margin: 0;
        font-size: 1.25rem;
        line-height: 1.3;
        font-weight: 800;
        color: #0f172a;
    }
    .news-flipboard-back-content .back-excerpt {
        font-size: 0.95rem;
        line-height: 1.55;
        color: #475569;
        margin: 0;
    }
    .news-flipboard-back-content .back-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-top: auto;
        padding-top: 12px;
        border-top: 1px dashed rgba(99, 102, 241, 0.25);
        font-size: 0.78rem;
        color: #64748b;
    }
    .news-flipboard-back-content .back-meta span {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 4px 10px;
        background: rgba(99, 102, 241, 0.08);
        border-radius: 12px;
    }

    .news-flipboard-back-actions {
        padding: 14px 24px 22px;
        background: white;
        border-top: 1px solid rgba(99, 102, 241, 0.12);
        display: flex;
        gap: 10px;
        align-items: center;
        justify-content: space-between;
    }
    .news-flipboard-back-actions .flip-back-hint {
        font-size: 0.78rem;
        color: #94a3b8;
        display: inline-flex;
        align-items: center;
        gap: 4px;
    }
    .news-flipboard-back-actions .flip-read-btn {
        flex: 1;
        max-width: 220px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 12px 18px;
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        color: white;
        text-decoration: none;
        border-radius: 14px;
        font-weight: 700;
        font-size: 0.92rem;
        box-shadow: 0 8px 18px rgba(99, 102, 241, 0.35);
        transition: transform 0.2s, box-shadow 0.2s;
    }
    .news-flipboard-back-actions .flip-read-btn:active {
        transform: scale(0.96);
    }

    /* === Card in stato LOADING (placeholder) === */
    .news-flipboard-card.is-loading {
        opacity: 0.4;
        pointer-events: none;
    }

    /* === Indicatore di swipe (freccia che appare in alto) === */
    .news-flipboard-swipe-hint {
        position: absolute;
        top: 16px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 5px;
        border-radius: 3px;
        background: rgba(99, 102, 241, 0.18);
        z-index: 60;
        pointer-events: none;
    }

    /* === Controlli sotto il deck === */
    .news-flipboard-controls {
        display: flex;
        justify-content: center;
        align-items: center;
        gap: 14px;
        margin-top: 20px;
        padding: 12px;
    }
    .news-flipboard-controls .ctrl-btn {
        width: 48px;
        height: 48px;
        border-radius: 50%;
        border: 1px solid rgba(99, 102, 241, 0.2);
        background: white;
        color: #6366f1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: 0 4px 12px rgba(99, 102, 241, 0.12);
        transition: all 0.2s;
        -webkit-tap-highlight-color: transparent;
    }
    .news-flipboard-controls .ctrl-btn:active {
        transform: scale(0.92);
        background: #6366f1;
        color: white;
    }
    .news-flipboard-controls .ctrl-btn:disabled {
        opacity: 0.35;
        pointer-events: none;
    }
    .news-flipboard-controls .ctrl-progress {
        flex: 1;
        text-align: center;
        font-size: 0.82rem;
        font-weight: 600;
        color: #475569;
        letter-spacing: 0.02em;
    }
    .news-flipboard-controls .ctrl-progress strong {
        color: #6366f1;
        font-weight: 800;
    }
    .news-flipboard-controls .ctrl-hint {
        font-size: 0.78rem;
        color: #94a3b8;
        text-align: center;
        flex-basis: 100%;
        margin-top: 6px;
    }

    /* Spazio sicuro in fondo */
    .news-flipboard-list::after {
        content: "";
        display: block;
        height: max(16px, env(safe-area-inset-bottom, 16px));
    }
}

/* === DARK MODE per Flipboard deck === */
@media (max-width: 768px) {
    [data-theme="dark"] .news-flipboard-card {
        background: #1e293b;
        border-color: rgba(99, 102, 241, 0.3);
        box-shadow:
            0 30px 60px -20px rgba(0, 0, 0, 0.6),
            0 18px 36px -18px rgba(99, 102, 241, 0.4),
            0 8px 16px rgba(0, 0, 0, 0.4);
    }
    [data-theme="dark"] .news-flipboard-face--back {
        background: linear-gradient(160deg, #1e293b 0%, #312e81 100%);
    }
    [data-theme="dark"] .news-flipboard-back-content h3 {
        color: #f1f5f9;
    }
    [data-theme="dark"] .news-flipboard-back-content .back-excerpt {
        color: #cbd5e1;
    }
    [data-theme="dark"] .news-flipboard-back-content .back-meta {
        color: #94a3b8;
        border-top-color: rgba(99, 102, 241, 0.3);
    }
    [data-theme="dark"] .news-flipboard-back-content .back-meta span {
        background: rgba(99, 102, 241, 0.15);
        color: #cbd5e1;
    }
    [data-theme="dark"] .news-flipboard-back-actions {
        background: #0f172a;
        border-top-color: rgba(99, 102, 241, 0.3);
    }
    [data-theme="dark"] .news-flipboard-back-actions .flip-back-hint {
        color: #64748b;
    }
    [data-theme="dark"] .news-flipboard-controls .ctrl-btn {
        background: #1e293b;
        border-color: rgba(99, 102, 241, 0.3);
        color: #a5b4fc;
    }
    [data-theme="dark"] .news-flipboard-controls .ctrl-progress {
        color: #cbd5e1;
    }
}

/* === ARTICOLO DETAIL: SWIPE ORIZZONTALE ARTICOLI (mantenuto) === */

.article-swipe-nav {
    display: none;
}

@media (max-width: 768px) {
    .article-swipe-nav {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        position: sticky;
        top: 60px;
        z-index: 50;
        margin: -20px -16px 24px;
        padding: 12px 16px;
        background: rgba(255, 255, 255, 0.92);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-bottom: 1px solid rgba(99, 102, 241, 0.15);
        box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
        font-size: 0.85rem;
    }
    [data-theme="dark"] .article-swipe-nav {
        background: rgba(15, 23, 42, 0.95);
        border-bottom-color: rgba(99, 102, 241, 0.3);
    }

    .article-swipe-hint {
        flex: 1;
        text-align: center;
        font-weight: 600;
        color: #475569;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
    }
    [data-theme="dark"] .article-swipe-hint { color: #cbd5e1; }
    .article-swipe-hint i { color: #6366f1; }

    .article-swipe-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 8px 12px;
        background: white;
        color: #6366f1;
        border: 1px solid #c7d2fe;
        border-radius: 12px;
        font-size: 0.82rem;
        font-weight: 600;
        text-decoration: none;
        cursor: pointer;
        transition: all 0.2s;
        min-width: 44px;
        min-height: 44px;
        font-family: inherit;
        -webkit-tap-highlight-color: transparent;
    }
    .article-swipe-btn:hover,
    .article-swipe-btn:active {
        background: #6366f1;
        color: white;
        border-color: #6366f1;
    }
    .article-swipe-btn:disabled,
    .article-swipe-btn.is-disabled {
        opacity: 0.4;
        cursor: not-allowed;
        pointer-events: none;
    }
    [data-theme="dark"] .article-swipe-btn {
        background: #1e293b;
        border-color: #4338ca;
        color: #a5b4fc;
    }
    [data-theme="dark"] .article-swipe-btn:hover,
    [data-theme="dark"] .article-swipe-btn:active {
        background: #4338ca;
        color: white;
    }
    .article-swipe-btn-label { font-size: 0.82rem; }
    .article-swipe-btn--icon-only { padding: 8px; }
}

/* === TTS READER: sticky in alto durante lo scrolling === */

@media (max-width: 768px) {
    .tts-reader-box {
        position: sticky;
        top: 117px;
        z-index: 40;
        margin: 0 -16px 16px;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: 1px solid #86efac;
        border-bottom: 1px solid #86efac;
        background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        box-shadow: 0 2px 8px rgba(16, 185, 129, 0.1);
    }
    .tts-reader-header { flex-wrap: nowrap; gap: 10px; }
    .tts-reader-icon {
        width: 40px; height: 40px; flex-shrink: 0;
    }
    .tts-reader-icon i { width: 20px !important; height: 20px !important; }
    .tts-reader-info {
        flex: 1 1 auto; min-width: 0; overflow: hidden;
    }
    .tts-reader-info strong {
        font-size: 0.9rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block;
    }
    .tts-reader-btn {
        flex-shrink: 0; padding: 10px 14px; font-size: 0.85rem;
    }
    .tts-reader-btn span { display: none; }
    .tts-reader-btn::after { content: "Ascolta"; margin-left: 6px; font-size: 0.85rem; }
    .tts-reader-btn.is-playing span,
    .tts-reader-btn.is-playing::after { content: "Ferma"; }
    .tts-reader-player { padding-top: 10px; }
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
    .news-flipboard-card,
    .news-flipboard-card-inner,
    .news-flipboard-image img,
    .article-swipe-nav,
    .tts-reader-box {
        transition: none !important;
        animation: none !important;
    }
}
