/* ===================================
   Design Tokens
   =================================== */
:root {
    --color-bg: #0a0a0a;
    --color-bg-secondary: #111;
    --color-bg-card: #141414;
    --color-bg-card-active: #1a1a1a;
    --color-text-primary: #e8e8e8;
    --color-text-secondary: #888;
    --color-text-muted: #666;
    --color-accent: #c49a3a;
    --color-accent-hover: #d4a843;
    --color-pop-green: #2d6a4f;
    --color-yellow: #c49a3a;
    --color-warning: #e76f51;
    --color-danger: #c41e3a;
    --color-danger-dark: #8b0000;
    --color-border: rgba(196, 154, 58, 0.15);
    --color-border-active: rgba(196, 154, 58, 0.4);

    --font-heading: 'IM Fell English', 'Georgia', serif;
    --font-body: 'IBM Plex Sans', 'Segoe UI', sans-serif;

    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    --transition-fast: 150ms ease;
    --transition-base: 300ms ease;
    --transition-slow: 500ms ease;

    --counter-height: 160px;
}

/* ===================================
   Reset & Base
   =================================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: auto;
    height: 100%;
    overflow: hidden;
}

body {
    background: var(--color-bg);
    color: var(--color-text-primary);
    font-family: var(--font-body);
    line-height: 1.6;
    height: 100%;
    overflow-x: hidden;
    overflow-y: hidden;   /* Prevent body scroll — cards-section is the only scroll container */
    -webkit-text-size-adjust: 100%;
}

/* ===================================
   Atmospheric Background
   =================================== */
.atmo-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: background-image 0.6s ease;
    /* Default fallback */
    background-color: var(--color-bg);
}

/* Dark vignette overlay — makes cards readable over the images */
.atmo-overlay {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: radial-gradient(
        ellipse at center,
        rgba(10, 10, 10, 0.2) 0%,
        rgba(10, 10, 10, 0.85) 100%
    );
}

/* ===================================
   Splash Overlay
   ==================================== */
.splash {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
    opacity: 1;
    transition: opacity 0.6s ease;
    will-change: opacity;
}

.splash.hidden {
    opacity: 0;
    pointer-events: none;
}

.splash-inner {
    max-width: 600px;
    text-align: center;
}

.splash-title {
    font-family: var(--font-heading);
    font-size: clamp(2rem, 6vw, 3rem);
    font-weight: 400;
    letter-spacing: 0.05em;
    color: var(--color-text-primary);
    margin-bottom: 0.5rem;
}

.splash-subtitle {
    font-family: var(--font-body);
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    color: var(--color-text-secondary);
    font-style: italic;
    margin-bottom: 2rem;
}

.splash-image {
    margin: 0 auto 2rem;
    max-width: 500px;
}

.splash-image img {
    width: 100%;
    height: auto;
    border-radius: var(--radius-lg);
    display: block;
}

.splash-image figcaption {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 0.5rem;
    font-style: italic;
}

.splash-text {
    text-align: left;
    margin-bottom: 2rem;
    font-family: var(--font-body);
}

.splash-text p {
    margin-bottom: 0.75rem;
    font-size: 1.05rem;
    color: var(--color-text-secondary);
}

.splash-text strong {
    color: var(--color-text-primary);
}

.splash-enter {
    font-family: var(--font-body);
    font-size: 1rem;
    padding: 14px 2rem;
    background: transparent;
    border: 2px solid var(--color-accent);
    color: var(--color-accent);
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    border-radius: var(--radius-md);
    transition: all var(--transition-base);
    font-weight: 600;
}

.splash-enter:hover {
    background: var(--color-accent);
    color: var(--color-bg);
}

/* ===================================
   Sticky Counter
   =================================== */
.counter-sticky {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--color-bg);
    padding: 1rem 1rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
}

.counter-sticky-inner {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.counter-year {
    font-family: var(--font-body);
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    font-weight: 700;
    color: var(--color-accent);
    line-height: 1.1;
}

.counter-value {
    font-family: var(--font-heading);
    font-size: clamp(2.8rem, 14vw, 5rem);
    font-weight: 400;
    color: var(--color-pop-green);
    line-height: 1;
    text-shadow: 0 0 40px rgba(45, 106, 79, 0.25);
    transition: color var(--transition-base), text-shadow var(--transition-base);
    margin: 0.25rem 0;
}

.counter-value.warning {
    color: var(--color-yellow);
    text-shadow: 0 0 60px rgba(196, 154, 58, 0.3);
}

.counter-value.declining {
    color: var(--color-danger);
    text-shadow: 0 0 60px rgba(196, 30, 58, 0.3);
}

.counter-value.critical {
    color: var(--color-danger-dark);
    text-shadow: 0 0 60px rgba(139, 0, 0, 0.4);
}

.counter-label {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    font-style: italic;
}

.counter-status {
    font-family: var(--font-body);
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

/* ===================================
   Timeline
   =================================== */
.timeline-wrap {
    max-width: 600px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
}

.timeline-track {
    position: relative;
    height: 6px;
    background: var(--color-bg-secondary);
    border-radius: 999px;
    overflow: hidden;
}

.timeline-fill {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    border-radius: 999px;
    width: 0%;
    will-change: width;
    transition: background 0.4s ease, width 0.2s ease;
}

/* Pulse animation when population hits critical (< 100K) */
@keyframes pulse-critical {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}
.timeline-fill.pulse-critical {
    animation: pulse-critical 1.8s ease-in-out infinite;
    box-shadow: 0 0 8px var(--color-danger);
}

/* Slower, dimmer pulse for extinction (< 10K) — fading out */
@keyframes pulse-extinct {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 0.2; }
}
.timeline-fill.pulse-extinct {
    animation: pulse-extinct 2.5s ease-in-out infinite;
    box-shadow: 0 0 4px var(--color-danger-dark);
}

/* ===================================
   Timeline labels
   =================================== */
.timeline-labels {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-body);
    font-size: 0.7rem;
    color: var(--color-text-muted);
    margin-top: 2px;
    padding: 0 2px;
}

/* ===================================
   Scroll Prompt
   =================================== */
.scroll-prompt {
    text-align: center;
    padding: 0.5rem 1rem 1rem;
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    animation: scroll-bounce 2s ease-in-out infinite;
}

.scroll-prompt .arrow {
    display: block;
    font-size: 1.4rem;
    margin-bottom: 0.25rem;
}

@keyframes scroll-bounce {
    0%, 100% { transform: translateY(0); opacity: 0.6; }
    50% { transform: translateY(6px); opacity: 1; }
}

/* ===================================
   Cards Section — scroll snap
   =================================== */
.cards-section {
    scroll-snap-type: y proximity;
    overflow-y: auto;
    height: 100vh;
    scroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
    /* Extra bottom padding so the last card's text + footer fully clear the viewport */
    padding-bottom: 15vh;
    box-sizing: border-box;
}

/* On mobile, use mandatory snap so cards snap firmly in both directions */
@media (max-width: 767px) {
    .cards-section {
        scroll-snap-type: y mandatory;
    }
}

 .card {
    scroll-snap-align: start;
    scroll-snap-stop: always;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 2rem 1rem;
    opacity: 0.35;
    transform: scale(0.97);
    transition: opacity 0.4s ease, transform 0.4s ease, background 0.4s ease;
    background: transparent;
}

.card.active {
    opacity: 1;
    transform: scale(1);
    background: var(--color-bg-card-active);
}

.card.card-end {
    padding-bottom: 30vh;
    /* Extra space to scroll past the finale */
}

/* Scroll buffer — invisible spacer after footer, no snap, absorbs trailing momentum */
.card-buffer {
    scroll-snap-align: none;
    scroll-snap-stop: normal;
    min-height: 80vh;
    opacity: 0;
    pointer-events: none;
    transform: none;
    background: transparent;
    padding: 0;
    margin: 0;
}


.card-inner {
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

.card-year {
    font-family: var(--font-heading);
    font-size: clamp(2rem, 7vw, 3rem);
    font-weight: 400;
    color: var(--color-accent);
    line-height: 1;
    margin-bottom: 0.25rem;
}

.card-title {
    font-family: var(--font-body);
    font-size: clamp(1rem, 3.5vw, 1.3rem);
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: 0.75rem;
    line-height: 1.25;
}

.card-image {
    margin: 0 0 0.75rem;
    border-radius: var(--radius-lg);
    overflow: hidden;
    aspect-ratio: 16 / 9;
    background: rgba(0,0,0,0.2);
}

.card-image img {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: var(--radius-lg);
    object-fit: contain;
    background: #000;
}

.card-image figcaption {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    margin-top: 0.4rem;
    font-style: italic;
}

/* Final card closing image — full width, natural proportion, no crop */
.card-image-final {
    margin: 1.25rem 0 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: rgba(0,0,0,0.2);
}

.card-image-final img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: var(--radius-lg);
}

.card-image-final figcaption {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    margin-top: 0.4rem;
    font-style: italic;
}

.card-text {
    font-family: var(--font-body);
    font-size: clamp(1rem, 3vw, 1.1rem);
    color: var(--color-text-secondary);
    line-height: 1.65;
}

.card-text .flag {
    font-size: 1.1em;
}


/* ===================================
   Citation Toast
   =================================== */
.citation-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    z-index: 1000;
    background: var(--color-bg-card);
    color: var(--color-text-primary);
    padding: 12px 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border-active);
    font-size: 0.85rem;
    font-family: var(--font-body);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
    max-width: 90vw;
    text-align: center;
}

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

.cite {
    color: var(--color-accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.8em;
    vertical-align: super;
    margin-left: 2px;
    transition: color var(--transition-fast);
}

.cite:hover {
    color: var(--color-accent-hover);
    text-decoration: underline;
}

.card-end .card-year {
    color: var(--color-danger-dark);
}

/* ===================================
   Sources bar
   =================================== */
.sources-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 60;
    background: var(--color-bg-secondary);
    border-top: 1px solid var(--color-border);
}

.sources-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 10px;
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-family: var(--font-body);
    font-size: 0.8rem;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
}

.sources-toggle-icon {
    transition: transform var(--transition-fast);
    font-size: 0.7rem;
}

.sources-toggle[aria-expanded="true"] .sources-toggle-icon {
    transform: rotate(180deg);
}

.sources-panel {
    max-height: 50vh;
    overflow-y: auto;
    padding: 0 1rem 1rem;
}

.sources-panel[hidden] {
    display: none;
}

.sources-panel h3 {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--color-accent);
    margin: 1rem 0 0.5rem;
    font-weight: 700;
}

.sources-panel ul {
    list-style: none;
    padding: 0;
}

.sources-panel li {
    font-size: 0.82rem;
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.sources-panel a {
    color: var(--color-accent);
    text-decoration: none;
}

.sources-panel a:hover {
    text-decoration: underline;
}

.sources-note {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    font-style: italic;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
}

/* ===================================
   Footer
   =================================== */
.footer {
    text-align: center;
    padding: 1.5rem 1rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-family: var(--font-body);
}

.footer a {
    color: var(--color-accent);
    text-decoration: none;
}

/* ===================================
   Responsive
   =================================== */

/* ===================================
   Mobile Optimizations (screens narrower than 768px)
   =================================== */
@media (max-width: 767px) {
    :root {
        --counter-height: 160px;
    }

    .counter-sticky {
        padding: 0.75rem 1rem 0.5rem;
    }

    .counter-year {
        font-size: clamp(1.1rem, 5vw, 1.4rem);
    }

    .counter-value {
        font-size: clamp(2.2rem, 12vw, 3.5rem);
    }

    .counter-label {
        font-size: 0.75rem;
    }

    .counter-status {
        font-size: 0.7rem;
    }

    .timeline-wrap {
        padding: 0.5rem 1rem;
    }

    .timeline-labels {
        font-size: 0.6rem;
    }

    .scroll-prompt {
        padding: 0.4rem 1rem 0.8rem;
        font-size: 0.75rem;
    }

    .splash-inner {
        padding: 0 0.5rem;
    }

    .splash-title {
        font-size: clamp(1.6rem, 8vw, 2.2rem);
        margin-bottom: 0.4rem;
    }

    .splash-subtitle {
        font-size: clamp(0.9rem, 3vw, 1rem);
        margin-bottom: 1.5rem;
    }

    .splash-image {
        max-width: 400px;
        margin-bottom: 1.5rem;
    }

    .splash-image figcaption {
        font-size: 0.75rem;
    }

    .splash-text p {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }

    .splash-enter {
        padding: 12px 1.5rem;
        font-size: 0.9rem;
    }

    .sources-toggle {
        padding: 8px;
        font-size: 0.75rem;
    }

    .sources-panel {
        padding: 0 0.75rem 0.75rem;
    }

    .sources-panel h3 {
        font-size: 0.8rem;
    }

    .sources-panel li {
        font-size: 0.78rem;
        line-height: 1.5;
    }

    .card {
        justify-content: flex-start;
        padding: 1.25rem 1rem;
        
    }

    .card-year {
        font-size: clamp(2rem, 7vw, 3rem);
        margin-bottom: 0.15rem;
    }

    .card-title {
        font-size: clamp(1rem, 3.5vw, 1.3rem);
        margin-bottom: 0.65rem;
        line-height: 1.2;
    }

    .card-image {
        margin-bottom: 0.5rem;
    }

    .card-image img {
        max-height: 170px;
        object-fit: cover;
    }

    .card-text {
        font-size: clamp(1rem, 3vw, 1.1rem);
        line-height: 1.55;
    }

    .footer {
        font-size: 0.75rem;
        padding: 1rem;
    }
}


@media (min-width: 768px) {
    :root {
        --counter-height: 200px;
    }

    .card {
        padding: 3rem 2rem;
    }
}
