/* ============================================
   FLIP BOOK - Complete Stylesheet
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #3a3a3a;
    --toolbar-bg: #2d2d2d;
    --toolbar-hover: #444;
    --panel-bg: #f5f5f5;
    --panel-text: #333;
    --book-bg: #e8e0d5;
    --page-bg: #fff;
    --accent: #e8733a;
    --accent-hover: #d1622a;
    --nav-bg: #252525;
    --nav-btn-bg: #3a3a3a;
    --nav-btn-hover: #555;
    --text-light: #ccc;
    --text-dark: #222;
    --shadow-color: rgba(0,0,0,0.3);
    --page-shadow: rgba(0,0,0,0.15);
    --transition-speed: 0.4s;
}

html, body {
    width: 100%; height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text-light);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* --- Loading Screen --- */
.loading-screen {
    position: fixed; inset: 0;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
}
.loader {
    text-align: center; color: var(--text-light);
}
.loader p { margin-top: 16px; font-size: 14px; letter-spacing: 1px; }
.book-spine {
    width: 60px; height: 80px; margin: 0 auto;
    background: linear-gradient(90deg, #c4956a, #a0744a, #c4956a);
    border-radius: 2px; position: relative;
    animation: pulse 1.2s ease-in-out infinite;
}
.book-page {
    width: 54px; height: 74px; margin: -77px auto 0;
    background: #fff; border-radius: 0 2px 2px 0; 
    transform-origin: left center;
    animation: flipPreload 1.2s ease-in-out infinite;
}
@keyframes pulse {
    0%,100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
@keyframes flipPreload {
    0%,100% { transform: rotateY(0deg); }
    50% { transform: rotateY(-25deg); }
}

/* --- App Container --- */
.app-container {
    width: 100%; height: 100%;
    display: flex; flex-direction: column;
}

/* --- Top Toolbar --- */
.top-toolbar {
    height: 44px; min-height: 44px;
    background: var(--toolbar-bg);
    display: flex; align-items: center;
    padding: 0 12px;
    border-bottom: 1px solid #1a1a1a;
    z-index: 100;
}
.toolbar-left, .toolbar-right {
    display: flex; align-items: center; gap: 4px;
}
.toolbar-center {
    flex: 1; text-align: center;
}
.book-title {
    font-size: 14px; font-weight: 600;
    color: var(--text-light);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 300px; display: inline-block;
}
.toolbar-btn {
    width: 34px; height: 34px;
    background: transparent;
    border: none; border-radius: 4px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
.toolbar-btn:hover { background: var(--toolbar-hover); }
.toolbar-btn svg {
    width: 20px; height: 20px; fill: #bbb;
}
.toolbar-btn:hover svg { fill: #fff; }

/* --- Main Area --- */
.main-area {
    flex: 1; display: flex; position: relative;
    overflow: hidden; min-height: 0;
}

/* --- Left Panel --- */
.left-panel {
    width: 300px; min-width: 300px;
    background: var(--panel-bg);
    color: var(--panel-text);
    display: flex; flex-direction: column;
    border-right: 1px solid #ddd;
    z-index: 50;
    animation: slideIn 0.25s ease-out;
}
@keyframes slideIn {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}
.panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    background: #e8e8e8;
    border-bottom: 1px solid #ddd;
    font-weight: 600; font-size: 14px;
}
.close-btn {
    background: none; border: none;
    font-size: 22px; cursor: pointer; color: #666;
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 4px;
}
.close-btn:hover { background: #ddd; color: #333; }
.panel-content {
    flex: 1; overflow-y: auto; padding: 8px;
}

/* --- TOC List --- */
.toc-list { list-style: none; }
.toc-item {
    padding: 10px 12px; cursor: pointer;
    border-radius: 4px; margin-bottom: 2px;
    font-size: 13px; line-height: 1.4;
    transition: background 0.15s;
    display: flex; align-items: center; gap: 8px;
}
.toc-item:hover { background: #e0e0e0; }
.toc-item.active { background: var(--accent); color: #fff; }
.toc-num {
    font-size: 11px; color: #888; min-width: 24px;
}
.toc-item.active .toc-num { color: rgba(255,255,255,0.7); }

/* --- Bookmarks --- */
.bookmarks-list { list-style: none; }
.bookmark-item {
    padding: 10px 12px; cursor: pointer;
    border-radius: 4px; margin-bottom: 4px;
    font-size: 13px;
    display: flex; align-items: center; justify-content: space-between;
    background: #fff; border: 1px solid #e0e0e0;
    transition: box-shadow 0.15s;
}
.bookmark-item:hover { box-shadow: 0 1px 4px rgba(0,0,0,0.12); }
.bookmark-remove {
    background: none; border: none; color: #c00;
    cursor: pointer; font-size: 16px; padding: 0 4px;
}
.add-bookmark-btn {
    width: 100%; padding: 10px; margin-top: 8px;
    border: 2px dashed #ccc; background: none;
    border-radius: 4px; cursor: pointer; font-size: 13px;
    color: #666; transition: all 0.15s;
}
.add-bookmark-btn:hover { border-color: var(--accent); color: var(--accent); }

/* --- Thumbnails --- */
.thumbnails-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px; padding: 4px;
}
.thumb-item {
    cursor: pointer; border-radius: 4px;
    overflow: hidden; border: 2px solid transparent;
    transition: border-color 0.15s, transform 0.15s;
    aspect-ratio: 0.707; background: #eee;
    position: relative;
}
.thumb-item:hover { border-color: var(--accent); transform: scale(1.02); }
.thumb-item img {
    width: 100%; height: 100%; object-fit: cover; display: block;
}
.thumb-num {
    position: absolute; bottom: 2px; right: 4px;
    background: rgba(0,0,0,0.6); color: #fff;
    font-size: 10px; padding: 1px 5px; border-radius: 3px;
}

/* --- Search --- */
.search-box {
    display: flex; gap: 6px; margin-bottom: 12px;
}
.search-box input {
    flex: 1; padding: 8px 12px;
    border: 1px solid #ccc; border-radius: 4px;
    font-size: 13px; outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-box button {
    padding: 8px 16px;
    background: var(--accent); color: #fff;
    border: none; border-radius: 4px; cursor: pointer;
    font-size: 13px;
}
.search-box button:hover { background: var(--accent-hover); }
.search-results { font-size: 13px; }
.search-result-item {
    padding: 10px 12px; cursor: pointer;
    border-radius: 4px; margin-bottom: 4px;
    background: #fff; border: 1px solid #e0e0e0;
}
.search-result-item:hover { box-shadow: 0 1px 4px rgba(0,0,0,0.12); }
.search-result-item .highlight { background: #ffeb3b; padding: 0 2px; }

/* --- Book Wrapper --- */
.book-wrapper {
    flex: 1; display: flex; align-items: center; justify-content: center;
    perspective: 2500px;
}

/* --- Book Container --- */
.book-container {
    position: relative;
    display: flex;
    box-shadow:
        0 2px 8px rgba(0,0,0,0.3),
        0 8px 30px rgba(0,0,0,0.4),
        2px 0 15px rgba(0,0,0,0.2);
    border-radius: 3px 8px 8px 3px;
    transform-style: preserve-3d;
    transition: transform 0.3s ease;
}

/* --- Pages --- */
.page {
    position: relative;
    background: var(--page-bg);
    overflow: hidden;
    backface-visibility: hidden;
}
.left-page {
    border-radius: 8px 0 0 8px;
    box-shadow: inset -8px 0 12px -8px rgba(0,0,0,0.2);
}
.right-page {
    border-radius: 0 8px 8px 0;
    box-shadow: inset 8px 0 12px -8px rgba(0,0,0,0.2);
}

.page-content {
    width: 100%; height: 100%;
    position: relative; overflow: hidden;
}
.page-content img {
    width: 100%; height: 100%;
    object-fit: contain;
    display: block;
    background: #fff;
}

.page-shadow {
    position: absolute; top: 0; bottom: 0;
    width: 12px; pointer-events: none; z-index: 2;
}
.left-shadow { left: 0; background: linear-gradient(to right, rgba(0,0,0,0.06), transparent); }
.right-shadow { right: 0; background: linear-gradient(to left, rgba(0,0,0,0.06), transparent); }

.page-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    pointer-events: none; z-index: 1;
}

.page-number {
    position: absolute; bottom: 8px;
    font-size: 11px; color: #999;
    z-index: 3; pointer-events: none;
}
.left-page-num { left: 12px; }
.right-page-num { right: 12px; }

/* --- Flip Animation --- */
.flip-page {
    position: absolute; top: 0;
    height: 100%; width: 50%;
    transform-origin: left center;
    transform-style: preserve-3d;
    z-index: 10;
    transition: transform var(--transition-speed) ease-in-out;
    border-radius: 0 8px 8px 0;
}
.flip-page.flipping-left {
    left: 0;
    transform-origin: right center;
    border-radius: 8px 0 0 8px;
}
.flip-page.flipping-right {
    right: 0;
    transform-origin: left center;
    border-radius: 0 8px 8px 0;
}

.flip-front, .flip-back {
    position: absolute; inset: 0;
    backface-visibility: hidden;
    overflow: hidden;
    background: #fff;
}
.flip-front img, .flip-back img {
    width: 100%; height: 100%;
    object-fit: contain; display: block;
    background: #fff;
}
.flip-front {
    z-index: 2;
    transform: rotateY(0deg);
}
.flip-back {
    transform: rotateY(180deg);
    z-index: 1;
}

.flip-page.flipping-left .flip-front {
    border-radius: 8px 0 0 8px;
}
.flip-page.flipping-left .flip-back {
    border-radius: 0 8px 8px 0;
}
.flip-page.flipping-right .flip-front {
    border-radius: 0 8px 8px 0;
}
.flip-page.flipping-right .flip-back {
    border-radius: 8px 0 0 8px;
}

/* Flip shadow */
.flip-page::after {
    content: '';
    position: absolute; top: 0; bottom: 0;
    width: 50px; z-index: 3;
    pointer-events: none;
    opacity: 0; transition: opacity 0.3s;
}
.flip-page.flipping-right::after {
    right: -25px;
    background: linear-gradient(to left, rgba(0,0,0,0.25), transparent);
}
.flip-page.flipping-left::after {
    left: -25px;
    background: linear-gradient(to right, rgba(0,0,0,0.25), transparent);
}
.flip-page.active-flip::after { opacity: 1; }

/* --- Bottom Navigation Bar --- */
.bottom-bar {
    height: 48px; min-height: 48px;
    background: var(--nav-bg);
    display: flex; align-items: center; justify-content: center;
    padding: 0 16px;
    border-top: 1px solid #1a1a1a;
    z-index: 100;
    gap: 24px;
}
.nav-controls {
    display: flex; align-items: center; gap: 4px;
}
.nav-btn {
    width: 36px; height: 36px;
    background: var(--nav-btn-bg);
    border: none; border-radius: 4px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
.nav-btn:hover { background: var(--nav-btn-hover); }
.nav-btn:active { background: #666; }
.nav-btn svg {
    width: 20px; height: 20px; fill: #bbb;
}
.nav-btn:hover svg { fill: #fff; }
.nav-btn:disabled {
    opacity: 0.35; cursor: default;
}
.nav-btn:disabled:hover { background: var(--nav-btn-bg); }
.nav-btn:disabled:hover svg { fill: #bbb; }

.page-indicator {
    display: flex; align-items: center; gap: 4px;
    margin: 0 8px;
    font-size: 14px; color: var(--text-light);
}
.page-input {
    width: 42px; height: 28px;
    text-align: center;
    background: #444; color: #fff;
    border: 1px solid #555; border-radius: 4px;
    font-size: 13px; outline: none;
}
.page-input:focus { border-color: var(--accent); }
.page-separator { color: #888; }
.total-pages { color: #888; min-width: 30px; }

.zoom-controls {
    display: flex; align-items: center; gap: 4px;
    position: absolute; right: 16px;
}
.zoom-level {
    font-size: 12px; color: #888;
    min-width: 40px; text-align: center;
}

/* --- Click Zones (for page turning) --- */
.click-zone {
    position: absolute; top: 0; bottom: 0;
    width: 18%; z-index: 5; cursor: pointer;
}
.click-zone-left { left: 0; }
.click-zone-right { right: 0; }
.click-zone:hover { background: rgba(0,0,0,0.02); }

/* --- Audio Player Bar --- */
.audio-bar {
    height: 44px; min-height: 44px;
    background: #1e1e1e;
    display: flex; align-items: center;
    padding: 0 12px; gap: 12px;
    border-top: 1px solid #333;
    z-index: 99;
    animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.audio-info {
    display: flex; align-items: center; gap: 8px;
    min-width: 120px;
}
.audio-label {
    font-size: 12px; color: #ccc; white-space: nowrap;
}
.audio-page-indicator {
    font-size: 11px; color: #888;
}
.audio-controls {
    display: flex; align-items: center; gap: 2px;
}
.audio-btn {
    width: 32px; height: 32px;
    background: transparent; border: none; border-radius: 4px;
    cursor: pointer; font-size: 14px; color: #ccc;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.audio-btn:hover { background: #333; color: #fff; }
.audio-play-btn {
    width: 36px; height: 36px;
    background: var(--accent); color: #fff; border-radius: 50%;
    font-size: 12px;
}
.audio-play-btn:hover { background: var(--accent-hover); color: #fff; }
.audio-play-btn.playing { background: #555; }
.audio-close-btn { margin-left: auto; font-size: 16px; }

.audio-progress-container {
    flex: 1; display: flex; align-items: center; gap: 8px;
    min-width: 100px;
}
.audio-time {
    font-size: 11px; color: #888; min-width: 35px; text-align: center;
    font-variant-numeric: tabular-nums;
}
.audio-seek {
    flex: 1; height: 4px; -webkit-appearance: none; appearance: none;
    background: #444; border-radius: 2px; outline: none; cursor: pointer;
}
.audio-seek::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--accent); cursor: pointer;
}
.audio-seek::-moz-range-thumb {
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--accent); cursor: pointer; border: none;
}

.audio-volume-container {
    display: flex; align-items: center; gap: 4px;
}
.audio-volume {
    width: 70px; height: 4px; -webkit-appearance: none; appearance: none;
    background: #444; border-radius: 2px; outline: none; cursor: pointer;
}
.audio-volume::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 10px; height: 10px; border-radius: 50%;
    background: #ccc; cursor: pointer;
}
.audio-volume::-moz-range-thumb {
    width: 10px; height: 10px; border-radius: 50%;
    background: #ccc; cursor: pointer; border: none;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .top-toolbar { height: 38px; min-height: 38px; padding: 0 8px; }
    .toolbar-btn { width: 30px; height: 30px; }
    .toolbar-btn svg { width: 18px; height: 18px; }
    .bottom-bar { height: 42px; min-height: 42px; }
    .book-title { font-size: 12px; max-width: 180px; }
    .left-panel { width: 260px; min-width: 260px; }
}

@media (max-width: 480px) {
    .page-indicator { margin: 0 4px; }
    .page-input { width: 34px; height: 24px; font-size: 11px; }
    .zoom-controls { display: none; }
    .book-title { max-width: 120px; font-size: 11px; }
    .left-panel { width: 100%; min-width: 100%; position: absolute; top: 38px; bottom: 42px; }
}
