/* bg3 full width if present */
.bg3 { width: 100%; display: block; margin-top: 13vh; position: relative; z-index: 0; pointer-events: none; }
/* Pyramid grid */
.pyramid-wrap { position: relative; width: 100%; display: grid; place-items: center; margin: 4vh 0; --tri-size: 250px;}
.pyramid-wrap img.project { width: min(70vw, 1000px); height: auto; display: block; margin-bottom: 2vh; }
.pyramid-box { position: relative; width: min(93vw, 1200px); margin: 0 auto; display: flex; justify-content: center; margin-top: 5vh; }
.pyramid { width: 100%; display: grid; gap: 2vh; margin-left: -5vw; }
/* approximate pyramid height: 3 rows of triangles + gaps (2 * 2vh) */
.pyramid-box { --pyr-h: calc(3 * var(--tri-size) + 4vh); }
.pyramid-box img.man { position: absolute; right: -14vw; bottom: 0; height: calc(var(--pyr-h) * 0.66); width: auto; z-index: -1; pointer-events: none; }
.pyramid-box img.women { position: absolute; left: -8vw; bottom: 0; height: calc(var(--pyr-h) * 0.66); width: auto; z-index: -1; pointer-events: none; }
.pyramid .row { display: grid; justify-content: center; align-items: center; gap: 2vh; }
.pyramid .row-top { grid-template-columns: repeat(1, var(--tri-size)); }
.pyramid .row-mid { grid-template-columns: repeat(3, var(--tri-size)); column-gap: 2vw; }
.pyramid .row-bottom { grid-template-columns: repeat(5, var(--tri-size)); column-gap: 2vw; }
.pyramid .tri { display: inline-grid; place-items: center; text-decoration: none; width: var(--tri-size); }
.pyramid .tri img { width: 100%; height: auto; filter: drop-shadow(0 6px 12px rgba(0,0,0,0.15)); transition: none; }
.pyramid .tri:hover img { transform: none; }
/* Make individual triangles position-adjustable; do NOT clip visuals */
.pyramid .tri { position: relative; overflow: visible; }

/* Define a generic upward triangle click area. Adjust if assets have different orientation. */
/* Clickable hit area overlay: triangle only, to avoid overlap click issues */
.pyramid .tri .hit-area {
    position: absolute;
    inset: 0;
    display: block;
    -webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
            clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

/* Horizontal compaction via half/full-width shifts as requested */
.pyramid .tri.engineering { transform: translateX(calc(var(--tri-size) / 2)); }
.pyramid .tri.results { transform: translateX(calc(-1 * var(--tri-size) / 2)); }
.pyramid .tri.model { transform: translateX(calc(var(--tri-size) / 2)); }
.pyramid .tri.education { transform: translateX(calc(-1 * var(--tri-size) / 2)); }
.pyramid .tri.parts { transform: translateX(var(--tri-size)); }
.pyramid .tri.game { transform: translateX(calc(-1 * var(--tri-size))); }

/* Extend hit area for model and education to cover the gap caused by translation */
.pyramid .tri.model .hit-area {
    left: calc(-1 * var(--tri-size) / 2);
    width: calc(100% + var(--tri-size) / 2);
}
.pyramid .tri.education .hit-area {
    right: calc(-1 * var(--tri-size) / 2);
    width: calc(100% + var(--tri-size) / 2);
}
/* Carousel */
.carousel-section {
    position: relative;
    padding: 8vh 0;
    display: grid;
    place-items: center;
    z-index: 5;
}
.carousel-section .guide { margin-bottom: 4vh; }
.carousel {
    position: relative;
    width: min(90vw, 1200px);
    --card-width: clamp(220px, 24vw, 340px);
    --card-gap: clamp(12px, 2vw, 24px);
    --card-height: 420px; /* all cards same height */
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 1rem;
}
.carousel-viewport {
    overflow: hidden;
    position: relative;
    z-index: 1;
}
.carousel-track {
    display: flex;
    gap: var(--card-gap);
    transition: transform 0.4s ease;
}
.carousel-slide {
    flex: 0 0 var(--card-width);
    display: grid;
    place-items: center;
}
.carousel-slide img { width: 100%; height: auto; }
.carousel-slide {
    perspective: 1000px;
    position: relative;
    z-index: 1;
    /* Ensure full card area is hoverable */
    isolation: isolate;
}
.flip-card {
    width: 100%;
    position: relative;
    z-index: 1;
    /* Ensure card captures all pointer events */
    pointer-events: auto;
}
.flip-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
    z-index: 1;
    /* Ensure inner area captures pointer events */
    pointer-events: auto;
}
.carousel-slide:hover .flip-inner { transform: rotateY(180deg); }
.carousel-slide:hover { z-index: 10; }
.flip-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
}
.flip-back { transform: rotateY(180deg); }

/* Ensure flip-card has height (absolute faces otherwise collapse) */
.flip-card {
    position: relative;
    height: var(--card-height);
    z-index: 1;
}
.flip-card:hover {
    z-index: 10;
}
.flip-face { width: 100%; height: 100%; object-fit: contain; display: block; }
.carousel-btn {
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
}
.carousel-btn img { width: 48px; height: auto; }
.carousel-btn.disabled { opacity: 0.4; pointer-events: none; }
/* Section 3 sticky scene (people -> peopleleft) */
.home-section-3-wrap {
    position: relative;
    height: 80vh; /* fixed viewport-like height */
    z-index: 3; /* above section2 */
}
.home-section-3 {
    position: sticky;
    top: 0;
    height: 80vh; /* keep viewport fixed height */
    display: grid;
    place-items: center;
    overflow: hidden;
    contain: layout style paint;
}
.home-section-3 img {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: min(85vw, 1400px);
}
.home-section-3 .people {
    top: 35%;
    transform: translate(-50%, -50%);
    opacity: 1;
    transition: transform 0.8s ease, opacity 0.8s ease;
    z-index: 2;
    will-change: transform, opacity;
}
.home-section-3 .peopleleft {
    top: 35%; /* same vertical position as people */
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 0.8s ease, transform 0.8s ease;
    z-index: 1;
    will-change: transform, opacity;
}

.home-section-3.active .people,
.home-section-3.active .peopleleft {
    will-change: auto;
}
.home-section-3.active .people {
    transform: translate(-50%, -50%) translateY(-10vh); /* move up on scroll */
}
.home-section-3.active .peopleleft {
    opacity: 1; /* fade in under people */
    transform: translate(-50%, -50%) translateY(23vh); /* move down slightly */
}
.introduction {
    width: 70vw;
    display: block;
    margin: 5vh auto 0;
}

/* Background for the Home section */
.home-section {
    position: relative;
    width: 100%;
    min-height: 100vh;
    padding: 5vh 0 6vh;
}

/* Use a pseudo-element to render a taller background that can overflow below
   while keeping both top and bottom edges visible (stretched as needed). */
.home-section::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -4vh; /* show a bit above */
    height: calc(100% + 20vh); /* extend below into next section */
    background-image: url('https://static.igem.wiki/teams/5607/home/bg.webp');
    background-repeat: no-repeat;
    background-size: 100% 100%; /* fill width & height (allow distortion) */
    background-position: top center;
    z-index: 0;
    pointer-events: none;
}

.home-section > * { position: relative; z-index: 1; }

/* lock body scroll during scene animation */
/* removed scroll lock; scroll remains natural */

/* Scene 1 container positions overlays */
.scene1 {
    position: relative;
    display: grid;
    place-items: center;
    overflow-x: hidden;
    margin-top: 5vh;
    min-height: 70vh;
    contain: layout style paint;
}

/* Section 2 (bg2 background) */
.home-section-2 {
    position: relative; /* default not sticky */
    width: 100%;
    height: 80vh; /* section height = background视觉高度 */
    display: grid;
    place-items: center; /* center banner */
    overflow: hidden;
    z-index: 2; /* ensure above the extended bg from previous section */
}

/* release sticky after animations so scrolling can continue */
.home-section-2.released {
    position: relative !important;
    top: auto !important;
}

/* turn sticky when section enters viewport - bottom fixed to viewport bottom */
.home-section-2.sticky-on {
    position: sticky;
    bottom: 0; /* 底部固定在视口底部 */
    top: auto;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 2;
}

/* sentinel marks the bottom edge for triggering stickiness */
.home-section-2 .section2-sentinel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 1px;
}

.home-section-2 .bg2-bg { /* pseudo background element */
    position: absolute;
    inset: 0;
    background-repeat: no-repeat;
    background-size: 100% auto; /* width fills, height auto */
    background-position: center top;
    z-index: 0;
}

.home-section-2 .speakcat {
    position: absolute;
    right: 2vw;
    top: 50%;
    transform: translateY(-50%); /* 右侧垂直居中 */
    z-index: 2;
    width: min(32vw, 420px);
    opacity: 1;
    transition: transform 0.8s ease, opacity 0.8s ease;
    will-change: transform, opacity;
}

.home-section-2.exit-stage .speakcat {
    will-change: auto;
}

.stats-banner {
    position: relative; /* stays centered by grid */
    z-index: 2;
    text-align: center;
    font-weight: 800;
    color: #000;
    font-family: 'Montserrat', 'Poppins', 'Segoe UI', Arial, Helvetica, sans-serif;
    opacity: 1;
    transition: opacity 0.6s ease;
}
.stats-banner .line1 {
    font-size: clamp(28px, 5vw, 72px);
    letter-spacing: 0.5px;
}
.stats-banner .line2 {
    font-size: clamp(40px, 9vw, 120px);
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.stats-banner .highlight {
    color: #f2c400;
}

/* Bounce animation for the line2 when it reaches viewport center */
@keyframes line2-bounce {
    0% { transform: translateY(0) scale(1); }
    30% { transform: translateY(-12px) scale(1.04); }
    60% { transform: translateY(0) scale(1); }
    80% { transform: translateY(-6px) scale(1.02); }
    100% { transform: translateY(0) scale(1); }
}
.stats-banner .line2.bounce {
    animation: line2-bounce 0.8s ease both;
}

/* Incoming elements */
.home-section-2 .littlecat,
.home-section-2 .problem {
    position: absolute;
    opacity: 0;
    z-index: 2;
    transition: transform 0.8s ease, opacity 0.8s ease;
    will-change: transform, opacity;
}

.home-section-2.exit-stage .littlecat,
.home-section-2.exit-stage .problem {
    will-change: auto;
}

.home-section-2 .problem {
    left: 50%;
    top: 60%;
    transform: translate(-50%, -50%) translate(-30%, 20%); /* start from lower-left offset */
}

.home-section-2 .littlecat {
    left: calc(50% - 25vw); /* to the left of problem */
    top: calc(40% - 15vh);  /* above the problem */
    transform: translate(-50%, -50%) translate(-30%, 20%);
}

/* Active state after counter finished and user scrolls */
.home-section-2.exit-stage .stats-banner {
    opacity: 0;
}
.home-section-2.exit-stage .speakcat {
    transform: translate(120%, -50%);
    opacity: 0;
}
.home-section-2.exit-stage .littlecat {
    transform: translate(-50%, -50%);
    opacity: 1;
}
.home-section-2.exit-stage .problem {
    transform: translate(-50%, -50%); /* center */
    opacity: 1;
}

/* Background stays at the back */
/* bg1 now applied via .home-section background */

/* Medicine centered above bg1 */
.scene1 .medicine {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    width: min(50vw, 640px);
    will-change: transform, opacity;
    transition: transform 0.9s cubic-bezier(.22,.61,.36,1), opacity 0.9s ease;
}

/* Remove will-change after animation */
.scene1.active .medicine {
    will-change: auto;
}

/* Question1 centered and initially hidden */
.scene1 .question1 {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) translateY(2vh);
    opacity: 0;
    z-index: 2;
    width: min(56vw, 760px);
    transition: transform 0.8s ease, opacity 0.8s ease;
}

/* When active: medicine slides left and fades, question1 fades in */
.scene1.active .medicine {
    left: 50%;
    transform: translate(-50%, -50%) translateX(-30vw);
    opacity: 0.4;
}

.scene1.active .question1 {
    transform: translate(-50%, -50%) translateY(0);
    opacity: 1;
}

