/* ============================================================
   Fun Science Facts Carousel v2.0 — Kids Edition
   kidssciencemagazine.com
   Performance: GPU-only animations (transform/opacity),
                will-change only where needed,
                prefers-reduced-motion respected
   ============================================================ */

/* ── Fonts ──────────────────────────────────────────────────────────
   Fredoka  – punchy display (titles, facts)
   Nunito   – warm rounded body (explanations, labels)
 ─────────────────────────────────────────────────────────────────── */

/* ── Reset scoped to plugin ───────────────────────────────────────── */
.ffc-hero *,
.ffc-hero *::before,
.ffc-hero *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* ── Hero container ───────────────────────────────────────────────── */
.ffc-hero {
    --ffc-radius:       24px;
    --ffc-radius-card:  20px;
    --ffc-radius-btn:   50%;
    --ffc-shadow:       0 8px 32px rgba(0,0,0,.10);
    --ffc-shadow-hover: 0 20px 48px rgba(0,0,0,.18);
    --ffc-transition:   .35s cubic-bezier(.34,1.56,.64,1);

    max-width: 960px;
    margin: 36px auto;
    padding: 28px 24px 22px;
    background: linear-gradient(145deg, #fdf4ff 0%, #eef9ff 55%, #fffbf0 100%);
    border-radius: var(--ffc-radius);
    box-shadow: var(--ffc-shadow);
    font-family: 'Nunito', 'Comic Neue', sans-serif;
    position: relative;
    overflow: hidden;
    isolation: isolate; /* stacking context */
}

/* ── Decorative star confetti background ─────────────────────────── */
.ffc-stars-bg {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(255,235,59,.25) 0, transparent 60px),
        radial-gradient(circle at 85% 10%, rgba(173,216,255,.30) 0, transparent 80px),
        radial-gradient(circle at 60% 85%, rgba(255,182,193,.25) 0, transparent 70px),
        radial-gradient(circle at 30% 75%, rgba(144,238,144,.20) 0, transparent 60px);
}

/* ── Header ───────────────────────────────────────────────────────── */
.ffc-head {
    text-align: center;
    margin-bottom: 22px;
    position: relative;
    z-index: 1;
}

.ffc-title {
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(30px, 6vw, 52px);
    font-weight: 700;
    color: #d81b60;
    margin: 0 0 10px;
    line-height: 1.1;
    letter-spacing: -1px;
    text-shadow: 3px 3px 0 #fff, 5px 5px 0 rgba(255,193,7,.45);
    animation: ffc-bounce 3.5s ease-in-out infinite;
}

.ffc-title-icon {
    display: inline-block;
    margin-right: 6px;
    animation: ffc-wiggle 2s ease-in-out infinite;
    transform-origin: bottom center;
}

.ffc-week-badge {
    display: inline-block;
    font-family: 'Nunito', sans-serif;
    font-size: clamp(13px, 2vw, 17px);
    font-weight: 700;
    color: #e65100;
    background: #fffde7;
    border: 2px solid #ffecb3;
    padding: 6px 20px;
    border-radius: 40px;
    box-shadow: 0 4px 12px rgba(255,193,7,.30);
    letter-spacing: .01em;
}

/* ── Track wrapper (overflow hidden for slide effect) ─────────────── */
.ffc-track-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: var(--ffc-radius-card);
}

/* ── Track ────────────────────────────────────────────────────────── */
.ffc-track {
    display: flex;
    gap: 18px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 14px 6px 20px;
    align-items: stretch;
}
.ffc-track::-webkit-scrollbar { display: none; }

/* ── Card ─────────────────────────────────────────────────────────── */
.ffc-card {
    flex: 0 0 clamp(240px, 80vw, 300px);
    scroll-snap-align: center;
    min-height: 320px;
    position: relative;
    perspective: 900px;     /* flip depth */
    cursor: pointer;
    opacity: 0;
    transform: translateY(28px) scale(.97);
    animation: ffc-card-in .6s var(--ffc-transition) forwards;
    outline: none;
}

/* Card focus ring for keyboard users */
.ffc-card:focus-visible .ffc-face--front {
    outline: 3px solid #1976d2;
    outline-offset: 3px;
}

/* ── Card inner (flip container) ──────────────────────────────────── */
.ffc-card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform .55s cubic-bezier(.4,0,.2,1);
    min-height: 320px;
}

.ffc-card.is-flipped .ffc-card-inner {
    transform: rotateY(180deg);
}

/* ── Card faces ───────────────────────────────────────────────────── */
.ffc-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: var(--ffc-radius-card);
    padding: 22px 18px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    overflow: hidden;          /* front face: no scroll — content is designed to fit */
}

.ffc-face--front {
    background: linear-gradient(145deg, var(--card-bg) 0%, var(--card-bg2) 100%);
    box-shadow: 0 8px 24px rgba(0,0,0,.10), inset 0 1px 0 rgba(255,255,255,.7);
}

.ffc-face--back {
    background: linear-gradient(145deg, var(--card-bg2) 0%, var(--card-bg) 100%);
    box-shadow: 0 8px 24px rgba(0,0,0,.10), inset 0 1px 0 rgba(255,255,255,.7);
    transform: rotateY(180deg);
    overflow-y: auto;          /* back face: scrollable when explanation is long */
    overflow-x: hidden;
    /* Custom scrollbar — thin and card-coloured */
    scrollbar-width: thin;
    scrollbar-color: var(--card-accent) transparent;
}

.ffc-face--back::-webkit-scrollbar {
    width: 4px;
}
.ffc-face--back::-webkit-scrollbar-track {
    background: transparent;
}
.ffc-face--back::-webkit-scrollbar-thumb {
    background: var(--card-accent);
    border-radius: 4px;
    opacity: .5;
}

/* Scroll-hint fade at bottom — shows there's more content below */
.ffc-face--back::after {
    content: '';
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    height: 28px;
    display: block;
    flex-shrink: 0;
    background: linear-gradient(to bottom, transparent, var(--card-bg));
    pointer-events: none;
    /* Only show when content overflows — controlled via JS class */
    opacity: 0;
    transition: opacity .3s ease;
}

.ffc-face--back.has-overflow::after {
    opacity: 1;
}

/* ── Card hover effect (front only, no flip state) ───────────────── */
.ffc-card:not(.is-flipped):hover .ffc-face--front,
.ffc-card:not(.is-flipped):focus-visible .ffc-face--front {
    box-shadow: var(--ffc-shadow-hover);
    transform: translateY(-4px) scale(1.015);
    transition: transform .25s ease, box-shadow .25s ease;
}

/* ── Decorative circle in card corner ─────────────────────────────── */
.ffc-card-deco {
    position: absolute;
    top: -30px;
    right: -30px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: rgba(255,255,255,.30);
    pointer-events: none;
}

/* ── Chip (category label) ────────────────────────────────────────── */
.ffc-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: 'Nunito', sans-serif;
    font-size: 12px;
    font-weight: 700;
    color: var(--chip-text);
    background: var(--chip-bg);
    border-radius: 40px;
    padding: 5px 13px;
    margin-bottom: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
    letter-spacing: .03em;
    text-transform: uppercase;
}

.ffc-chip-emoji {
    font-size: 15px;
    line-height: 1;
}

/* ── Fact text ────────────────────────────────────────────────────── */
.ffc-fact {
    font-family: 'Fredoka', sans-serif;
    font-size: clamp(20px, 4vw, 26px);
    font-weight: 600;
    color: #1a237e;
    line-height: 1.25;
    margin: 0 0 auto;
    padding-bottom: 14px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Explanation text ─────────────────────────────────────────────── */
.ffc-explain {
    font-family: 'Nunito', sans-serif;
    font-size: clamp(15px, 2.8vw, 19px);
    font-weight: 700;
    color: var(--card-accent);
    line-height: 1.55;
    width: 100%;
    margin-bottom: 14px;
    padding: 0 4px;
    text-align: center;
    text-shadow: 0 1px 0 rgba(255,255,255,.6);
    /* Natural height — does NOT stretch with flex.
       Back face scrolls to reach the button if text is long. */
}

/* ── "WOW!" label above explanation ──────────────────────────────── */
.ffc-back-wow {
    font-family: 'Fredoka', sans-serif;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: #fff;
    background: var(--card-accent);
    border-radius: 30px;
    padding: 3px 14px;
    margin-bottom: 10px;
    opacity: .9;
}

/* ── Back face emoji ──────────────────────────────────────────────── */
.ffc-back-emoji {
    font-size: 44px;
    margin-bottom: 10px;
    animation: ffc-wiggle 3s ease-in-out infinite;
    transform-origin: bottom center;
}

/* ── Buttons on card ──────────────────────────────────────────────── */
.ffc-flip-btn {
    font-family: 'Nunito', sans-serif;
    font-size: 13px;
    font-weight: 700;
    background: var(--card-accent);
    color: #fff;
    border: none;
    border-radius: 40px;
    padding: 9px 20px;
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,.18);
    margin-top: 4px;
    letter-spacing: .02em;
    white-space: nowrap;
}

.ffc-flip-btn:hover,
.ffc-flip-btn:focus-visible {
    transform: scale(1.07) translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,.24);
}

.ffc-flip-btn:active {
    transform: scale(.96);
}

.ffc-flip-btn--back {
    background: rgba(255,255,255,.55);
    color: var(--card-accent);
    box-shadow: none;
    border: 2px solid var(--card-accent);
    font-weight: 800;
    margin-top: auto;     /* always push to bottom of scroll container */
    flex-shrink: 0;       /* never compress — always fully visible */
    position: sticky;     /* sticks to bottom when scrolling */
    bottom: 0;
    z-index: 1;
}

.ffc-flip-btn--back:hover,
.ffc-flip-btn--back:focus-visible {
    background: var(--card-accent);
    color: #fff;
    border-color: var(--card-accent);
    box-shadow: 0 4px 14px rgba(0,0,0,.18);
}

/* ── Share button (replaced with two-button row) ──────────────────── */
.ffc-action-row {
    display: flex;
    gap: 7px;
    margin-top: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.ffc-copy-btn,
.ffc-social-btn {
    font-family: 'Nunito', sans-serif;
    font-size: 11px;
    font-weight: 800;
    border-radius: 40px;
    padding: 6px 13px;
    cursor: pointer;
    letter-spacing: .02em;
    white-space: nowrap;
    transition: background .2s ease, transform .2s ease, color .2s ease;
    line-height: 1;
}

.ffc-copy-btn {
    background: rgba(255,255,255,.7);
    color: var(--card-accent);
    border: 2px solid var(--card-accent);
}

.ffc-copy-btn:hover,
.ffc-copy-btn:focus-visible {
    background: var(--card-accent);
    color: #fff;
    transform: scale(1.05);
}

.ffc-social-btn {
    background: var(--card-accent);
    color: #fff;
    border: 2px solid var(--card-accent);
}

.ffc-social-btn:hover,
.ffc-social-btn:focus-visible {
    filter: brightness(1.12);
    transform: scale(1.05);
}

.ffc-copy-btn:active,
.ffc-social-btn:active {
    transform: scale(.95);
}

/* ── Social share popup ───────────────────────────────────────────── */
.ffc-share-popup {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.08);
    padding: 14px 16px 10px;
    z-index: 200;
    min-width: 220px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease, transform .22s cubic-bezier(.34,1.56,.64,1);
}

.ffc-share-popup.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

.ffc-share-popup-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 14px;
    font-weight: 700;
    color: #333;
    text-align: center;
    margin-bottom: 10px;
}

.ffc-share-links {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.ffc-share-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    font-family: 'Nunito', sans-serif;
    font-size: 10px;
    font-weight: 700;
    color: #555;
    border-radius: 10px;
    padding: 7px 9px;
    transition: background .18s ease, transform .18s ease;
    cursor: pointer;
    border: none;
    background: transparent;
}

.ffc-share-link:hover,
.ffc-share-link:focus-visible {
    background: #f5f5f5;
    transform: scale(1.08);
    color: #222;
}

.ffc-share-icon {
    font-size: 22px;
    line-height: 1;
}

/* Close popup button */
.ffc-popup-close {
    display: block;
    margin: 8px auto 0;
    background: none;
    border: none;
    font-size: 11px;
    color: #aaa;
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    padding: 2px 8px;
}

.ffc-popup-close:hover { color: #666; }

/* ── Controls row ─────────────────────────────────────────────────── */
.ffc-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 16px;
}

/* ── Prev / Next nav buttons ──────────────────────────────────────── */
.ffc-btn {
    width: 52px;
    height: 52px;
    border: none;
    border-radius: var(--ffc-radius-btn);
    font-size: 22px;
    color: #fff;
    background: linear-gradient(135deg, #ff9800, #f44336);
    box-shadow: 0 6px 18px rgba(244,67,54,.38);
    cursor: pointer;
    transition: transform var(--ffc-transition), box-shadow .25s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex-shrink: 0;
    will-change: transform;
}

.ffc-btn:hover,
.ffc-btn:focus-visible {
    transform: scale(1.18) translateY(-3px);
    box-shadow: 0 12px 28px rgba(244,67,54,.55);
}

.ffc-btn:active {
    transform: scale(.92);
}

.ffc-btn:disabled {
    opacity: .38;
    cursor: not-allowed;
    transform: none;
}

/* ── Dot indicators ───────────────────────────────────────────────── */
.ffc-dots {
    display: flex;
    gap: 7px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 180px;
}

.ffc-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #d1c4e9;
    border: none;
    cursor: pointer;
    transition: background .25s ease, transform .25s var(--ffc-transition), width .25s ease;
    padding: 0;
    flex-shrink: 0;
}

.ffc-dot--active {
    background: #e91e63;
    transform: scale(1.4);
    width: 22px;
    border-radius: 8px;
}

.ffc-dot:hover:not(.ffc-dot--active) {
    background: #ce93d8;
    transform: scale(1.2);
}

/* ── Fact counter ─────────────────────────────────────────────────── */
.ffc-counter {
    text-align: center;
    font-family: 'Nunito', sans-serif;
    font-size: 13px;
    color: #888;
    margin: 8px 0 0;
}

.ffc-counter-current {
    font-weight: 700;
    color: #e91e63;
    font-size: 16px;
}

.ffc-counter-total {
    font-weight: 700;
    color: #1976d2;
}

/* ── Toast notification ───────────────────────────────────────────── */
.ffc-toast {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #1b5e20;
    color: #fff;
    font-family: 'Nunito', sans-serif;
    font-size: 14px;
    font-weight: 700;
    padding: 10px 22px;
    border-radius: 40px;
    box-shadow: 0 8px 24px rgba(0,0,0,.20);
    pointer-events: none;
    opacity: 0;
    transition: transform .35s var(--ffc-transition), opacity .35s ease;
    white-space: nowrap;
    z-index: 100;
}

.ffc-toast.is-visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ── Empty state ──────────────────────────────────────────────────── */
.ffc-empty {
    text-align: center;
    color: #e91e63;
    font-family: 'Nunito', sans-serif;
    font-size: 1.2em;
    padding: 24px;
}

/* ── Keyframe animations ──────────────────────────────────────────── */
@keyframes ffc-bounce {
    0%, 100% { transform: translateY(0);    }
    50%       { transform: translateY(-7px); }
}

@keyframes ffc-wiggle {
    0%, 100% { transform: rotate(0deg);   }
    20%       { transform: rotate(-12deg); }
    40%       { transform: rotate(10deg);  }
    60%       { transform: rotate(-6deg);  }
    80%       { transform: rotate(4deg);   }
}

@keyframes ffc-card-in {
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes ffc-pulse-dot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(233,30,99,.4); }
    50%       { box-shadow: 0 0 0 5px rgba(233,30,99,0); }
}

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .ffc-hero {
        margin: 20px 12px;
        padding: 20px 16px 18px;
    }

    .ffc-card {
        flex: 0 0 86vw;
        min-height: 300px;
    }

    .ffc-title {
        font-size: clamp(26px, 8vw, 38px);
        text-shadow: 2px 2px 0 #fff, 3px 3px 0 rgba(255,193,7,.4);
    }

    .ffc-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }

    .ffc-dots {
        max-width: 130px;
    }
}

@media (max-width: 400px) {
    .ffc-card {
        flex: 0 0 90vw;
    }
    .ffc-controls {
        gap: 10px;
    }
}

/* ── Reduced motion ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .ffc-title,
    .ffc-title-icon,
    .ffc-back-emoji {
        animation: none;
    }

    .ffc-card {
        animation: none;
        opacity: 1;
        transform: none;
    }

    .ffc-card-inner {
        transition: none;
    }

    .ffc-btn,
    .ffc-flip-btn,
    .ffc-copy-btn,
    .ffc-social-btn,
    .ffc-dot {
        transition: none;
    }

    .ffc-toast {
        transition: none;
    }
}

/* ── Dark mode support ────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
    .ffc-hero {
        background: linear-gradient(145deg, #1a0a2e 0%, #0d1b2a 55%, #1a1500 100%);
        box-shadow: 0 8px 32px rgba(0,0,0,.45);
    }

    .ffc-title {
        color: #f48fb1;
        text-shadow: 3px 3px 0 rgba(0,0,0,.5), 5px 5px 0 rgba(255,193,7,.25);
    }

    .ffc-week-badge {
        background: #2d2400;
        border-color: #5d4e00;
        color: #ffca28;
    }

    .ffc-face--front,
    .ffc-face--back {
        filter: brightness(.92) saturate(.9);
    }

    .ffc-fact {
        color: #1a237e; /* keep dark – card bg is light-ish */
    }

    .ffc-counter {
        color: #aaa;
    }

    .ffc-dot {
        background: #5c4a70;
    }
}
