:root {
    --bg-color: #0a0a0a;
    --text-color: #f0f0f0;
    --accent-color: #00e5ff;
    --page-bg: #fff;
    --modal-bg: rgba(0, 0, 0, 0.9);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    background-image: radial-gradient(circle at 50% 0%, #1a1a2e 0%, #0a0a0a 70%);
}

.app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    padding: 0;
}

.flip-book-container {
    width: 100%;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    perspective: 2000px;
}

.flip-book-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.flip-book {
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
    display: none; /* hidden until js loads */
    border-radius: 4px;
}

.page {
    background-color: var(--page-bg);
    overflow: hidden;
    position: relative;
    cursor: pointer;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.2);
}

/* Subtle gradient to simulate page spine/lighting */
.page::after {
    content: '';
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* Right pages shadow */
.page:nth-child(even)::after {
    left: 0;
    background: linear-gradient(to right, rgba(0,0,0,0.3) 0%, rgba(0,0,0,0) 15%);
}

/* Left pages shadow */
.page:nth-child(odd)::after {
    right: 0;
    background: linear-gradient(to left, rgba(0,0,0,0.3) 0%, rgba(0,0,0,0) 15%);
}

.page-content {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.page-image {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Guarantees the image is never cropped */
    background-color: #fff; /* Fills the background in case of slight aspect ratio mismatches */
    transition: transform 0.4s ease, filter 0.4s ease;
}

/* Click Animation Class */
.animate-click {
    animation: magic-pop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes magic-pop {
    0% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.1) rotate(2deg); filter: brightness(1.5) contrast(1.2); box-shadow: 0 0 30px var(--accent-color); z-index: 50; }
    100% { transform: scale(1); filter: brightness(1); }
}

/* Add a subtle "click me" ripple or glow to the center of pages on hover */
.page:not(.page-cover):hover::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background: radial-gradient(circle, rgba(0,229,255,0.4) 0%, rgba(0,0,0,0) 70%);
    border-radius: 50%;
    z-index: 10;
    animation: pulse-soft 2s infinite;
    pointer-events: none;
}

@keyframes pulse-soft {
    0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0.5; }
    50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(0.8); opacity: 0.5; }
}

/* Canvas Particles */
#magic-particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1; /* Behind the magazine */
}

/* Zoom Container (Interactive Pan) */
.zoom-container {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(5, 5, 10, 0.95);
    backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 0.5s ease;
    overflow: hidden;
    cursor: crosshair;
}

.zoom-container.show {
    display: block;
    opacity: 1;
}

#zoom-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    animation: cinematic-pan 20s ease-in-out infinite alternate;
    pointer-events: none; /* Let mouse events hit container */
    filter: drop-shadow(0 0 30px rgba(0,229,255,0.4));
}

@keyframes cinematic-pan {
    0% { transform: scale(1) translate(0, 0); }
    33% { transform: scale(1.15) translate(-2%, 3%); }
    66% { transform: scale(1.15) translate(2%, -3%); }
    100% { transform: scale(1.2) translate(0, 0); }
}

/* (Mobile rules consolidated at bottom of file) */

/* --- NEW SEPARATED LAYOUT STYLES --- */
.page-text {
    background: #fdfdfd;
    box-shadow: inset 20px 0 30px -15px rgba(0,0,0,0.1); /* Inner spine shadow */
}

.story-text {
    padding: 3rem !important;
    font-size: 1.3rem !important;
    line-height: 1.9 !important;
    color: #2c2a29 !important; /* Soft dark charcoal */
    background-color: #fcfaf6 !important; /* Premium cream paper background */
    font-family: 'Lora', serif !important;
    font-weight: 400 !important;
    text-align: justify !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    height: 100% !important;
    box-sizing: border-box !important;
    overflow-y: auto !important;
}

/* Safe vertical centering without cutting off top when overflowing */
.story-text > :first-child {
    margin-top: auto !important;
}

.story-text > :last-child {
    margin-bottom: auto !important;
}

.story-text p {
    color: #2c2a29 !important;
    /* Animation hidden by default */
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

/* Class added by JS when page is active */
.story-text.animate-in p {
    opacity: 1;
    transform: translateY(0);
}

.dropcap {
    float: left !important;
    font-size: 5rem !important;
    line-height: 0.85 !important;
    padding-top: 5px !important;
    padding-right: 12px !important;
    padding-left: 2px !important;
    font-weight: 600 !important;
    color: var(--accent-color) !important;
    background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none; /* Removed shadow to let gradient shine */
}

.crop-left {
    object-fit: cover;
    object-position: left center;
}

/* Interactive Video Styles */
.page-illustration .page-content {
    cursor: pointer;
    position: relative;
}

.play-hint {
    position: absolute;
    bottom: 30px;
    right: 30px;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 1.2rem;
    pointer-events: none;
    opacity: 0.8;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255,255,255,0.2);
}

.page-illustration:hover .play-hint {
    transform: scale(1.1);
    background: var(--accent-color);
    opacity: 1;
}

.page-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
    z-index: 10;
    display: none;
}
.page-video.playing {
    display: block;
}

/* Magic GIF Overlay inside zoom */
.zoom-magic-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('https://media1.giphy.com/media/v1.Y2lkPTc5MGI3NjExNjMwMmVhZDhhNGI3NjMyZTQ1YzZiZmZkMjYyZGU2NWIxZDk4ZjQxZSZlcD12MV9pbnRlcm5hbF9naWZzX2dpZklkJmN0PWc/3o7TKSjRrfIPjeiVyM/giphy.gif');
    background-size: cover;
    mix-blend-mode: screen;
    opacity: 0.3;
    pointer-events: none;
    z-index: 2005;
}

.zoom-close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: rgba(255,255,255,0.8);
    font-size: 40px;
    font-weight: 300;
    cursor: pointer;
    z-index: 2010;
    transition: all 0.3s ease;
}

.zoom-close:hover {
    color: var(--accent-color);
    transform: rotate(90deg) scale(1.1);
}

.zoom-instruction {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.6);
    border: 1px solid rgba(0,229,255,0.4);
    padding: 10px 25px;
    border-radius: 30px;
    color: var(--accent-color);
    font-size: 1rem;
    pointer-events: none;
    z-index: 2010;
    animation: fadeOut 3s forwards 2s; /* Disappears after 5s */
}

@keyframes fadeOut {
    to { opacity: 0; visibility: hidden; }
}

/* --- Minigame UI --- */
.btn-play-game {
    display: block;
    margin: 1.5rem auto 0 auto !important;
    padding: 12px 25px;
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    color: #004d40;
    font-size: 1.1rem;
    font-weight: 800;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(67, 233, 123, 0.4);
    transition: all 0.3s ease;
    font-family: 'Inter', sans-serif;
    opacity: 0;
    transform: translateY(20px);
}

.story-text.animate-in .btn-play-game {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.8s ease-out 0.4s, transform 0.8s ease-out 0.4s;
}

.btn-play-game:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 20px rgba(67, 233, 123, 0.6);
}

/* Modal Overlay */
.game-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh; /* Dynamic viewport: accounts for mobile browser chrome */
    background: rgba(10, 10, 10, 0.85);
    backdrop-filter: blur(10px);
    z-index: 3000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    position: fixed;
    inset: 0; /* top/left/right/bottom: 0 — covers everything */
}

.game-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.game-modal-content {
    background: #fdfbf7;
    width: 90%;
    max-width: 800px;
    height: 80vh;
    height: 80dvh;
    max-height: calc(100dvh - 40px); /* Never taller than screen */
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), inset 0 0 0 8px rgba(139, 90, 43, 0.1);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.game-modal.active .game-modal-content {
    transform: scale(1);
}

.close-game-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: #ff4757;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    z-index: 100;
    box-shadow: 0 4px 10px rgba(255, 71, 87, 0.3);
    transition: all 0.2s;
}

.close-game-btn:hover {
    background: #ff6b81;
    transform: scale(1.05);
}

.game-ui {
    background: linear-gradient(to bottom, rgba(253, 251, 247, 1) 0%, rgba(253, 251, 247, 0.9) 100%);
    padding: 20px;
    text-align: center;
    border-bottom: 2px solid rgba(0,0,0,0.05);
    z-index: 10;
}

.game-ui h3 {
    font-family: 'Lora', serif;
    color: #2c2a29;
    font-size: 1.8rem;
    margin-bottom: 5px;
}

.game-ui p {
    color: #666;
    font-size: 1rem;
}

#game-score {
    position: absolute;
    top: 20px;
    left: 20px;
    background: #f6d365;
    color: #8b5a2b;
    padding: 5px 15px;
    border-radius: 20px;
    font-weight: 800;
    box-shadow: 0 4px 10px rgba(246, 211, 101, 0.4);
    z-index: 100;
}

.game-container {
    flex-grow: 1;
    position: relative;
    background-color: #8b5a2b; /* Default dirt color */
    overflow: hidden;
}

/* --- Mobile Responsiveness --- */
/* On mobile, the flipbook shrinks proportionally via StPageFlip stretch mode.
   We scale the typography proportionally using vw units so text stays readable. */
@media (max-width: 768px) {
    .app-header {
        padding: 8px 0 !important;
    }
    .app-header h1 {
        font-size: clamp(1rem, 3.5vw, 2rem) !important;
    }

    /* Text pages scale with the viewport so they match the shrunk book */
    .story-text {
        padding: 4% !important;
        font-size: clamp(0.5rem, 2.4vw, 1rem) !important;
        line-height: 1.5 !important;
    }

    .dropcap {
        font-size: clamp(1.5rem, 7vw, 3.5rem) !important;
        padding-right: 3px !important;
        padding-top: 1px !important;
    }

    .btn-play-game {
        margin: 0.5rem auto 0 auto !important;
        padding: 6px 12px !important;
        font-size: clamp(0.5rem, 2.2vw, 0.85rem) !important;
    }

    /* Game modal fills full visible screen on mobile */
    .game-modal-content {
        width: 100%;
        height: 100dvh; /* Respects address bar */
        max-height: 100dvh;
        border-radius: 0;
        transform: none !important; /* Skip scale animation */
    }

    .game-ui h3 {
        font-size: 1.2rem;
    }

    #game-score {
        top: 8px;
        left: 8px;
        font-size: 0.85rem;
    }
}
