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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f0f2f5;
    color: #333;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Top Navigation Bar */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    padding: 10px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    height: 56px;
}

.nav-left, .nav-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav-center {
    font-weight: 600;
    color: #2d5f4f;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-btn {
    background: #2d5f4f;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s, transform 0.1s;
    white-space: nowrap;
}

.nav-btn:hover {
    background: #1e4a3a;
    transform: translateY(-1px);
}

.nav-btn.active-toggle {
    background: #1e4a3a;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

/* Zoom Controls */
.zoom-controls {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-left: 8px;
}

.zoom-btn {
    background: #2d5f4f;
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.zoom-btn:hover {
    background: #1e4a3a;
}

.zoom-level {
    font-size: 12px;
    color: #2d5f4f;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
}

/* Search Panel */
.search-panel {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 999;
    padding: 16px 20px;
    transition: transform 0.3s ease;
}

.search-panel.hidden {
    display: none;
}

.search-content {
    display: flex;
    gap: 10px;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
}

.search-content input {
    flex: 1;
    padding: 10px 14px;
    border: 2px solid #2d5f4f;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}

.search-content input:focus {
    border-color: #1e4a3a;
    box-shadow: 0 0 0 3px rgba(45, 95, 79, 0.15);
}

.search-btn {
    background: #2d5f4f;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.search-btn:hover {
    background: #1e4a3a;
}

.close-btn {
    background: #e74c3c;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.close-btn:hover {
    background: #c0392b;
}

.search-results {
    max-width: 800px;
    margin: 12px auto 0;
    max-height: 300px;
    overflow-y: auto;
}

.search-summary {
    padding: 8px 14px;
    background: #e8f5e9;
    color: #2d5f4f;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    margin-bottom: 8px;
}

.search-result-item {
    padding: 12px 14px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background 0.2s;
    border-radius: 6px;
    margin-bottom: 4px;
}

.search-result-item:hover {
    background: #f0f7f4;
}

.search-result-item.result-active {
    background: #d4edda;
    border-left: 3px solid #2d5f4f;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.result-page {
    background: #2d5f4f;
    color: white;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.result-count {
    font-size: 11px;
    color: #888;
    font-style: italic;
}

.result-snippet {
    font-size: 13px;
    color: #555;
    line-height: 1.5;
    word-break: break-word;
}

.search-mark {
    background: #fff176;
    color: #333;
    padding: 1px 2px;
    border-radius: 2px;
    font-weight: 600;
}

.result-title {
    font-size: 13px;
    color: #555;
}

.no-results {
    text-align: center;
    color: #999;
    padding: 20px;
    font-style: italic;
}

.no-results strong {
    color: #666;
}

/* Table of Contents Panel */
.toc-panel {
    position: fixed;
    top: 56px;
    left: 0;
    width: 380px;
    bottom: 0;
    background: white;
    box-shadow: 4px 0 16px rgba(0,0,0,0.12);
    z-index: 998;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.toc-panel.hidden {
    display: none;
}

.toc-content {
    padding: 24px;
    position: relative;
}

.toc-content h3 {
    color: #2d5f4f;
    font-size: 20px;
    margin-bottom: 20px;
    padding-right: 40px;
}

.toc-content .close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
}

#tocList {
    list-style: none;
    padding: 0;
}

#tocList li {
    margin-bottom: 4px;
}

#tocList a {
    display: block;
    padding: 12px 16px;
    color: #333;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 14px;
    line-height: 1.4;
}

#tocList a:hover {
    background: #e8f5e9;
    color: #2d5f4f;
    padding-left: 22px;
}

/* Flipbook Container */
.flipbook-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 76px 20px 80px;
    min-height: calc(100vh - 56px);
    perspective: 2000px;
    overflow: auto;
}

.flipbook {
    width: 100%;
    max-width: 850px;
    position: relative;
    transform-style: preserve-3d;
    transition: max-width 0.4s ease;
}

/* Two-page view */
.flipbook.two-page-view {
    max-width: 1600px;
    display: flex;
    gap: 0;
    justify-content: center;
}

/* Page Styling */
.page {
    display: none;
    background: white;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    overflow: hidden;
    position: relative;
    transform-style: preserve-3d;
}

.page.active {
    display: block;
}

/* Two-page view page styling */
.flipbook.two-page-view .page.active {
    display: block;
    flex: 0 0 auto;
    max-width: 50%;
}

.flipbook.two-page-view .page.active:first-of-type {
    border-radius: 4px 0 0 4px;
}

.flipbook.two-page-view .page.active + .page.active {
    border-radius: 0 4px 4px 0;
    box-shadow: 4px 4px 20px rgba(0,0,0,0.12);
}

/* Book spine shadow for two-page view */
.flipbook.two-page-view .page.active.left-page {
    border-radius: 4px 0 0 4px;
    box-shadow: -2px 4px 20px rgba(0,0,0,0.12), inset -8px 0 15px -10px rgba(0,0,0,0.15);
}

.flipbook.two-page-view .page.active.right-page {
    border-radius: 0 4px 4px 0;
    box-shadow: 2px 4px 20px rgba(0,0,0,0.12), inset 8px 0 15px -10px rgba(0,0,0,0.15);
}

/* Flip Animation */
.page.flip-forward-out {
    animation: flipForwardOut 0.6s ease-in-out forwards;
    transform-origin: left center;
    z-index: 10;
    display: block !important;
}

.page.flip-forward-in {
    animation: flipForwardIn 0.6s ease-in-out forwards;
    transform-origin: left center;
    z-index: 9;
    display: block !important;
}

.page.flip-backward-out {
    animation: flipBackwardOut 0.6s ease-in-out forwards;
    transform-origin: right center;
    z-index: 10;
    display: block !important;
}

.page.flip-backward-in {
    animation: flipBackwardIn 0.6s ease-in-out forwards;
    transform-origin: right center;
    z-index: 9;
    display: block !important;
}

@keyframes flipForwardOut {
    0% { transform: perspective(2000px) rotateY(0deg); opacity: 1; }
    100% { transform: perspective(2000px) rotateY(-180deg); opacity: 0; }
}

@keyframes flipForwardIn {
    0% { transform: perspective(2000px) rotateY(180deg); opacity: 0; }
    100% { transform: perspective(2000px) rotateY(0deg); opacity: 1; }
}

@keyframes flipBackwardOut {
    0% { transform: perspective(2000px) rotateY(0deg); opacity: 1; }
    100% { transform: perspective(2000px) rotateY(180deg); opacity: 0; }
}

@keyframes flipBackwardIn {
    0% { transform: perspective(2000px) rotateY(-180deg); opacity: 0; }
    100% { transform: perspective(2000px) rotateY(0deg); opacity: 1; }
}

/* Zoom styles */
.page-image-wrapper {
    width: 100%;
    line-height: 0;
    overflow: hidden;
    cursor: default;
    transition: transform 0.3s ease;
}

.page-image-wrapper.zoomed {
    overflow: auto;
    cursor: grab;
}

.page-image-wrapper.zoomed:active {
    cursor: grabbing;
}

.page-image {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.3s ease;
    transform-origin: center center;
}

/* Hidden search text */
.search-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

/* Bottom Navigation */
.bottom-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    padding: 12px 20px;
    background: white;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

.nav-arrow {
    background: #2d5f4f;
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.nav-arrow:hover:not(:disabled) {
    background: #1e4a3a;
    transform: translateY(-1px);
}

.nav-arrow:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Responsive */
@media (max-width: 768px) {
    .top-nav {
        padding: 8px 12px;
        flex-wrap: wrap;
        height: auto;
        gap: 6px;
    }

    .nav-left, .nav-right {
        gap: 4px;
    }

    .nav-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    .flipbook-container {
        padding: 70px 8px 70px;
    }

    .flipbook {
        max-width: 100%;
    }

    .flipbook.two-page-view {
        max-width: 100%;
        flex-direction: column;
    }

    .flipbook.two-page-view .page.active {
        max-width: 100%;
    }

    .toc-panel {
        width: 100%;
    }

    .zoom-controls {
        margin-left: 4px;
    }
}

@media (max-width: 480px) {
    .nav-btn {
        padding: 6px 8px;
        font-size: 10px;
    }

    .nav-center {
        font-size: 12px;
    }
}

/* Print Styles */
@media print {
    .top-nav, .bottom-nav, .search-panel, .toc-panel {
        display: none !important;
    }

    .flipbook-container {
        padding: 0;
    }

    .page {
        display: block !important;
        box-shadow: none;
        border-radius: 0;
        page-break-after: always;
        animation: none;
        max-width: 100% !important;
    }

    .page:last-child {
        page-break-after: auto;
    }

    .page-image {
        width: 100%;
        height: auto;
        transform: none !important;
    }

    body {
        background: white;
    }
}
