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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #D97706 0%, #B45309 100%);
    color: #333;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    touch-action: none;
    -webkit-overflow-scrolling: touch;
    /* Support for iOS safe area (Notch) */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

/* Loading Screen */
.loading-screen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    background: #fff;
    color: #333;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #D97706;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    background: #fff;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    /* iOS Safe Area: Add padding for notch at top */
    padding-left: max(15px, env(safe-area-inset-left));
    padding-right: max(15px, env(safe-area-inset-right));
    background: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 100;
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.5rem;
    color: #333;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.btn-icon {
    background: #D97706;
    border: none;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s;
}

.btn-icon:hover {
    background: #B45309;
    transform: scale(1.05);
}

.btn-icon:active {
    transform: scale(0.95);
}

/* Flipbook Wrapper */
.flipbook-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 5px 10px 10px 10px;
    overflow: hidden;
    background: linear-gradient(135deg, #D97706 0%, #B45309 100%);
}

.flipbook {
    box-shadow: 0 10px 50px rgba(0,0,0,0.3);
    background: #fff;
    touch-action: pan-x pan-y;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.flipbook .page {
    background: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
}

.flipbook .page img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    user-select: none;
    -webkit-user-drag: none;
    display: block;
}

/* Navigation */
.navigation {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    padding: 12px 20px;
    /* iOS Safe Area: Add padding for home indicator at bottom */
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    background: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.nav-btn {
    background: #D97706;
    border: none;
    color: #fff;
    font-size: 2rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.nav-btn:hover {
    background: #B45309;
    transform: scale(1.1);
}

.nav-btn:active {
    transform: scale(0.95);
}

.nav-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.5;
}

.page-indicator {
    font-size: 1.2rem;
    font-weight: 600;
    color: #333;
}

/* Instructions */
.instructions {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 15px 30px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 15px;
    animation: fadeIn 0.5s, pulse 2s infinite;
    z-index: 200;
}

.instructions.hidden {
    display: none;
}

.btn-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes pulse {
    0%, 100% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.05); }
}

/* Error Screen */
.error-screen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    background: #fff;
    text-align: center;
    padding: 20px;
}

.error-screen h2 {
    font-size: 2rem;
    margin-bottom: 20px;
    color: #e53e3e;
}

.btn-reload {
    margin-top: 20px;
    background: #D97706;
    color: #fff;
    border: none;
    padding: 15px 30px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-reload:hover {
    background: #B45309;
    transform: scale(1.05);
}

/* Responsive */
@media (max-width: 768px) {
    .header {
        padding: 8px 10px;
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .flipbook-wrapper {
        padding: 5px;
    }

    .navigation {
        gap: 20px;
        padding: 10px 15px;
    }

    .nav-btn {
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
    }

    .page-indicator {
        font-size: 1rem;
    }

    .btn-icon {
        padding: 8px 12px;
        font-size: 1rem;
    }
}

/* Dark Mode Support (optional) */
@media (prefers-color-scheme: dark) {
    body {
        background: #1a202c;
    }

    .app-container {
        background: #2d3748;
    }

    .header {
        background: #2d3748;
        color: #fff;
    }

    .header h1 {
        color: #fff;
    }

    .navigation {
        background: #2d3748;
    }

    .page-indicator {
        color: #fff;
    }
}
