/* ===== CSS Variables ===== */
:root {
    --primary-color: #8B4513;
    --secondary-color: #DEB887;
    --accent-color: #CD853F;
    --background-light: #FFF8F0;
    --background-white: #FFFFFF;
    --text-dark: #2C1810;
    --text-medium: #5D4E37;
    --text-light: #8B7355;
    --border-color: #E6D7C3;
    --success-color: #4CAF50;
    --error-color: #F44336;
    --warning-color: #FF9800;
    --shadow-light: 0 2px 8px rgba(139, 69, 19, 0.1);
    --shadow-medium: 0 4px 16px rgba(139, 69, 19, 0.15);
    --shadow-heavy: 0 8px 32px rgba(139, 69, 19, 0.2);
    --border-radius: 12px;
    --transition: all 0.3s ease;
    
    /* New variables for enhanced design */
    --page-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --book-spine: #654321;
    --paper-texture: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><defs><filter id="paper"><feTurbulence baseFrequency="0.04" numOctaves="5" result="noise" seed="2"/><feDiffuseLighting in="noise" lighting-color="white" surfaceScale="1"><feDistantLight azimuth="45" elevation="60"/></feDiffuseLighting></filter></defs><rect width="100%" height="100%" fill="%23FFF8F0" filter="url(%23paper)"/></svg>');
    --gradient-gold: linear-gradient(135deg, #FFD700, #FFA500, #FF8C00);
    --gradient-book: linear-gradient(145deg, #8B4513 0%, #A0522D 25%, #CD853F 50%, #DEB887 75%, #F5DEB3 100%);
}

/* Dark Mode Variables */
.dark-mode {
    --background-light: #1a1a1a;
    --background-white: #2d2d2d;
    --text-dark: #e8e8e8;
    --text-medium: #c0c0c0;
    --text-light: #9e9e9e;
    --border-color: #404040;
    --shadow-light: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-medium: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-heavy: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* ===== Base Styles ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comfortaa', cursive;
    background: linear-gradient(135deg, #2C1810 0%, #5D4E37 25%, var(--background-light) 50%, var(--background-white) 100%);
    background-attachment: fixed;
    color: var(--text-dark);
    line-height: 1.6;
    overflow-x: hidden;
    transition: var(--transition);
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

/* ===== Password Protection Screen ===== */
.password-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #8B4513 0%, #CD853F 50%, #DEB887 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}

.password-container {
    background: var(--background-white);
    padding: 40px;
    border-radius: 20px;
    box-shadow: var(--shadow-heavy);
    text-align: center;
    max-width: 500px;
    width: 100%;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.book-cover-mini {
    margin-bottom: 30px;
}

.book-cover-mini i {
    font-size: 60px;
    color: var(--primary-color);
    margin-bottom: 15px;
    display: block;
}

.book-cover-mini h2 {
    font-family: 'Caveat', cursive;
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 10px;
    font-weight: 700;
}

.book-cover-mini p {
    color: var(--text-medium);
    font-size: 1.1rem;
    font-style: italic;
}

.password-form h3 {
    color: var(--text-dark);
    margin-bottom: 10px;
    font-size: 1.4rem;
}

.password-form p {
    color: var(--text-medium);
    margin-bottom: 25px;
}

.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#password-input {
    flex: 1;
    padding: 15px 20px;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-family: 'Comfortaa', cursive;
    background: var(--background-light);
    transition: var(--transition);
    outline: none;
}

#password-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.1);
}

#unlock-btn {
    padding: 15px 25px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-family: 'Comfortaa', cursive;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

#unlock-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.error-message {
    color: var(--error-color);
    font-size: 0.9rem;
    min-height: 20px;
    margin-top: 10px;
}

.copyright-info {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.copyright-info p {
    color: var(--text-light);
    font-size: 0.85rem;
}

/* ===== Main Ebook Interface ===== */
#ebook-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Header ===== */
.ebook-header {
    background: var(--background-white);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-light);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    max-width: 1400px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo i {
    font-size: 2rem;
    color: var(--primary-color);
}

.logo h1 {
    font-family: 'Caveat', cursive;
    font-size: 2rem;
    color: var(--primary-color);
    font-weight: 700;
}

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

.control-btn {
    padding: 12px 15px;
    background: var(--background-light);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-dark);
    cursor: pointer;
    transition: var(--transition);
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-2px);
}

/* ===== Table of Contents Sidebar ===== */
.toc-sidebar {
    position: fixed;
    top: 0;
    left: -350px;
    width: 350px;
    height: 100vh;
    background: var(--background-white);
    border-right: 1px solid var(--border-color);
    box-shadow: var(--shadow-medium);
    transition: var(--transition);
    z-index: 200;
    overflow-y: auto;
}

.toc-sidebar.active {
    left: 0;
}

.toc-header {
    padding: 25px;
    border-bottom: 1px solid var(--border-color);
    background: var(--gradient-book);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.toc-header h3 {
    font-size: 1.2rem;
    font-weight: 600;
}

.close-toc {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: var(--transition);
}

.close-toc:hover {
    background: rgba(255, 255, 255, 0.2);
}

.toc-content {
    padding: 15px 0;
}

.toc-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 18px 25px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0.0, 0.2, 1);
    border-left: 4px solid transparent;
    position: relative;
    overflow: hidden;
}

.toc-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, rgba(139, 69, 19, 0.1), rgba(205, 133, 63, 0.1));
    transition: width 0.4s ease;
}

.toc-item:hover {
    background: var(--background-light);
    border-left-color: var(--accent-color);
    transform: translateX(8px);
    box-shadow: 0 4px 15px rgba(139, 69, 19, 0.15);
}

.toc-item:hover::before {
    width: 100%;
}

.toc-item.active {
    background: linear-gradient(90deg, rgba(139, 69, 19, 0.15), rgba(205, 133, 63, 0.1));
    border-left-color: var(--primary-color);
    color: var(--primary-color);
    font-weight: 600;
    transform: translateX(12px);
    box-shadow: 0 6px 20px rgba(139, 69, 19, 0.2);
}

.toc-item i {
    width: 20px;
    color: var(--accent-color);
}

.toc-item span {
    flex: 1;
    font-size: 0.95rem;
}

/* ===== Main Content ===== */
.ebook-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 25px;
    width: 100%;
    perspective: 2000px;
}

/* ===== Book Container with 3D Effect ===== */
.book-container {
    position: relative;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    perspective: 2000px;
    transform-style: preserve-3d;
}

.book-spine {
    position: absolute;
    left: 50%;
    top: 0;
    width: 8px;
    height: 100%;
    background: var(--gradient-book);
    transform: translateX(-50%) rotateY(90deg);
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.book-pages {
    position: relative;
    display: flex;
    width: 100%;
    height: auto;
    min-height: 700px;
    transform-style: preserve-3d;
}

.page-left, .page-right {
    width: 50%;
    position: relative;
    transform-style: preserve-3d;
}

.page-left {
    transform-origin: right center;
}

.page-right {
    transform-origin: left center;
}

.progress-container {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    margin-bottom: 30px;
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 2px;
}

/* ===== Page Content ===== */
.page-content {
    flex: 1;
    background: var(--background-white);
    background-image: var(--paper-texture);
    border-radius: var(--border-radius);
    box-shadow: var(--page-shadow);
    padding: 50px;
    margin-bottom: 30px;
    min-height: 700px;
    font-size: 1.1rem;
    line-height: 1.8;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(139, 69, 19, 0.1);
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.page-content.flipping {
    transform: rotateY(-15deg);
}

.page-content.page-turn-left {
    animation: pageFlipLeft 0.8s ease-in-out;
}

.page-content.page-turn-right {
    animation: pageFlipRight 0.8s ease-in-out;
}

@keyframes pageFlipLeft {
    0% { transform: rotateY(0deg); }
    50% { transform: rotateY(-90deg); }
    100% { transform: rotateY(0deg); }
}

@keyframes pageFlipRight {
    0% { transform: rotateY(0deg); }
    50% { transform: rotateY(90deg); }
    100% { transform: rotateY(0deg); }
}

.page-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: var(--gradient-gold);
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.page-content::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, transparent 0%, rgba(255, 255, 255, 0.1) 25%, transparent 50%, rgba(255, 255, 255, 0.1) 75%, transparent 100%);
    pointer-events: none;
    border-radius: var(--border-radius);
}

.page-title {
    font-family: 'Caveat', cursive;
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 15px;
    font-weight: 700;
    text-align: center;
}

.page-subtitle {
    color: var(--text-medium);
    font-size: 1.2rem;
    text-align: center;
    margin-bottom: 30px;
    font-style: italic;
}

.story-content {
    max-width: none;
    margin: 0;
}

.story-content h2 {
    font-family: 'Caveat', cursive;
    font-size: 2rem;
    color: var(--primary-color);
    margin: 30px 0 20px 0;
    font-weight: 600;
}

.story-content h3 {
    color: var(--accent-color);
    margin: 25px 0 15px 0;
    font-size: 1.4rem;
}

.story-content p {
    margin-bottom: 18px;
    color: var(--text-dark);
    text-align: justify;
}

.story-content .greeting {
    font-weight: 500;
    color: var(--primary-color);
    font-size: 1.2rem;
}

.story-content .signature {
    text-align: right;
    font-style: italic;
    color: var(--text-medium);
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.story-content .questions {
    background: var(--background-light);
    padding: 25px;
    border-radius: var(--border-radius);
    margin: 30px 0;
    border-left: 4px solid var(--accent-color);
}

.story-content .questions h4 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.story-content .questions ul {
    padding-left: 20px;
}

.story-content .questions li {
    margin-bottom: 10px;
    color: var(--text-dark);
}

.story-content .moral {
    background: linear-gradient(135deg, rgba(139, 69, 19, 0.1), rgba(205, 133, 63, 0.1));
    padding: 25px;
    border-radius: var(--border-radius);
    margin: 30px 0;
    text-align: center;
    border: 2px solid var(--accent-color);
}

.story-content .moral h4 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.3rem;
}

/* ===== Navigation Controls ===== */
.navigation-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30px 0;
    margin-bottom: 30px;
    position: relative;
}

.navigation-controls::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-color), transparent);
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 30px;
    background: var(--gradient-book);
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 1.1rem;
    font-family: 'Comfortaa', cursive;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0.0, 0.2, 1);
    font-weight: 600;
    box-shadow: 0 8px 25px rgba(139, 69, 19, 0.3);
    position: relative;
    overflow: hidden;
}

.nav-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.6s ease;
}

.nav-btn:hover:not(:disabled) {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 35px rgba(139, 69, 19, 0.4);
}

.nav-btn:hover:not(:disabled)::before {
    left: 100%;
}

.nav-btn:active:not(:disabled) {
    transform: translateY(-1px) scale(1.02);
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 4px 15px rgba(139, 69, 19, 0.1);
}

.nav-btn i {
    font-size: 1.2rem;
    transition: transform 0.3s ease;
}

.nav-btn:hover:not(:disabled) i {
    transform: scale(1.2);
}

.page-indicator {
    background: var(--gradient-gold);
    padding: 15px 25px;
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    font-weight: 700;
    color: white;
    box-shadow: 0 8px 25px rgba(255, 215, 0, 0.3);
    font-size: 1.1rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
}

.page-indicator::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.2) 50%, transparent 70%);
    animation: shine 3s infinite;
}

@keyframes shine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* ===== Usage Tips ===== */
.usage-tips {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    animation: slideUpTips 0.5s ease-out;
}

.tips-content {
    background: var(--gradient-book);
    color: white;
    padding: 15px 25px;
    border-radius: 25px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 500px;
    font-size: 0.9rem;
    position: relative;
    overflow: hidden;
}

.tips-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    animation: shine 3s infinite;
}

.close-tips {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: var(--transition);
    margin-left: 10px;
}

.close-tips:hover {
    background: rgba(255, 255, 255, 0.2);
}

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

/* ===== Loading Screen ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(139, 69, 19, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    text-align: center;
    color: white;
}

.paw-print {
    font-size: 60px;
    animation: bounce 1s infinite;
    margin-bottom: 20px;
}

.loading-spinner p {
    font-size: 1.2rem;
    font-weight: 500;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-20px);
    }
    60% {
        transform: translateY(-10px);
    }
}

/* ===== Responsive Design ===== */
@media (max-width: 1200px) {
    .ebook-main {
        max-width: 900px;
    }
}

@media (max-width: 768px) {
    .password-container {
        padding: 30px 25px;
        margin: 20px;
    }
    
    .book-cover-mini h2 {
        font-size: 2rem;
    }
    
    .input-group {
        flex-direction: column;
    }
    
    .header-content {
        padding: 15px 20px;
    }
    
    .logo h1 {
        font-size: 1.6rem;
    }
    
    .header-controls {
        gap: 8px;
    }
    
    .control-btn {
        padding: 10px 12px;
        font-size: 0.9rem;
    }
    
    .toc-sidebar {
        width: 300px;
        left: -300px;
    }
    
    .ebook-main {
        padding: 0 20px;
    }
    
    .book-container {
        max-width: 100%;
    }
    
    .page-content {
        padding: 30px 25px;
        font-size: 1rem;
        min-height: 600px;
    }
    
    .page-title {
        font-size: 2rem;
    }
    
    .story-content h2 {
        font-size: 1.6rem;
    }
    
    .navigation-controls {
        flex-direction: column;
        gap: 15px;
        padding: 20px 0;
    }
    
    .nav-btn {
        width: 100%;
        justify-content: center;
        padding: 15px 20px;
    }
    
    .usage-tips {
        bottom: 10px;
        left: 10px;
        right: 10px;
        transform: none;
    }
    
    .tips-content {
        max-width: none;
        font-size: 0.85rem;
        padding: 12px 20px;
    }
}

@media (max-width: 480px) {
    .password-container {
        padding: 25px 20px;
    }
    
    .book-cover-mini i {
        font-size: 50px;
    }
    
    .book-cover-mini h2 {
        font-size: 1.8rem;
    }
    
    .toc-sidebar {
        width: 280px;
        left: -280px;
    }
    
    .toc-item {
        padding: 12px 20px;
        font-size: 0.9rem;
    }
    
    .page-content {
        padding: 25px 20px;
        font-size: 0.95rem;
    }
    
    .page-title {
        font-size: 1.8rem;
    }
    
    .story-content .questions,
    .story-content .moral {
        padding: 20px;
        margin: 25px 0;
    }
}

/* ===== Print Styles ===== */
@media print {
    .ebook-header,
    .navigation-controls,
    .progress-container,
    .toc-sidebar {
        display: none;
    }
    
    .page-content {
        box-shadow: none;
        border: 1px solid #ccc;
        page-break-inside: avoid;
    }
    
    .story-content h2 {
        page-break-after: avoid;
    }
}

/* ===== Animation Classes ===== */
.fade-in {
    animation: fadeIn 0.8s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.slide-in-left {
    animation: slideInLeft 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.slide-in-right {
    animation: slideInRight 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.book-entrance {
    animation: bookEntrance 1.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.page-glow {
    animation: pageGlow 2s ease-in-out infinite alternate;
}

@keyframes fadeIn {
    from { 
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to { 
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes slideInLeft {
    from { 
        transform: translateX(-50px) rotateY(-15deg); 
        opacity: 0; 
    }
    to { 
        transform: translateX(0) rotateY(0deg); 
        opacity: 1; 
    }
}

@keyframes slideInRight {
    from { 
        transform: translateX(50px) rotateY(15deg); 
        opacity: 0; 
    }
    to { 
        transform: translateX(0) rotateY(0deg); 
        opacity: 1; 
    }
}

@keyframes bookEntrance {
    0% {
        opacity: 0;
        transform: scale(0.8) rotateY(-30deg);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.9) rotateY(-10deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotateY(0deg);
    }
}

@keyframes pageGlow {
    0% {
        box-shadow: var(--page-shadow);
    }
    100% {
        box-shadow: var(--page-shadow), 0 0 30px rgba(139, 69, 19, 0.3);
    }
}

/* ===== Custom Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-light);
}

::-webkit-scrollbar-thumb {
    background: var(--accent-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* ===== Fullscreen Mode ===== */
.fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9998 !important;
    background: var(--background-light) !important;
}

.fullscreen .ebook-header {
    position: relative !important;
}

.fullscreen .ebook-main {
    max-width: none !important;
    height: calc(100vh - 80px) !important;
    overflow-y: auto !important;
}
