@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@100..900&family=Prompt:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap');

:root {
    --doh-ebook-primary: #0054A6; 
    --doh-ebook-secondary: #FFC107; 
    --doh-ebook-light: #E9ECEF; 
    --doh-ebook-dark: #343A40; 
    --control-ebook-bg: #4361ee; 
    --control-ebook-hover: #3a56d4;
}

.doh-ebook {font-family: 'Prompt', sans-serif; color: var(--doh-ebook-dark); overflow-x: hidden; }
.doh-ebook .header {background: linear-gradient(135deg, var(--doh-ebook-primary) 0%, #003366 100%); color: white; padding: 1rem 0; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);}
.doh-ebook .header h1 {font-weight: 700; margin: 0; font-size: 1.8rem;}
.doh-ebook .flipbook-container {background-color: white; border-radius: 8px; }
.doh-ebook .ebook-header {display: flex; align-items: center; padding: 1rem 0; margin-bottom: 1.5rem; border-bottom: 1px solid #dee2e6;}
.doh-ebook .btn-back {margin-right: 1.5rem;}
.doh-ebook .btn-back a {display: flex; align-items: center; gap: 0.5rem; color: var(--doh-ebook-primary); text-decoration: none; font-weight: 500; transition: color 0.2s ease;}
.doh-ebook .btn-back a:hover {color: #FFF;}
.doh-ebook .ebook-header li:last-child {font-size: 1.2rem; font-weight: 600; color: var(--doh-ebook-dark);}
.doh-ebook .search-tags {display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 20px;}
.doh-ebook .tag {background-color: var(--doh-ebook-light); color: var(--doh-ebook-primary); padding: 0.3rem 0.8rem; border-radius: 20px; font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: all 0.2s ease;}
.doh-ebook .tag:hover {background-color: var(--doh-ebook-primary); color: white;}
.doh-ebook .tag.active {background-color: var(--doh-ebook-primary); color: white;}

/* Flipbook Container */
.doh-ebook .flipbook-wrapper {
    position: relative;
    width: 100%;
    height: min(87vh, 600px);
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1500px;
    overflow: hidden;
}

.doh-ebook #flipbook {
    width: 800px;
    height: 600px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.3s ease;
    margin: 0 auto;
}

/* Page Styles */
.doh-ebook .page {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: white;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    cursor: grab;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    border-radius: 4px;
    display: none;
}

.doh-ebook .page.active {
    display: block;
}

.doh-ebook .page:active {
    cursor: grabbing;
}

.doh-ebook .page-front, 
.doh-ebook .page-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 4px;
    overflow: hidden;
}

.doh-ebook .page-front {
    transform: rotateY(0deg);
    background: white;
    z-index: 2;
}

.doh-ebook .page-back {
    transform: rotateY(180deg);
    background: #f8f9fa;
}

.doh-ebook .page img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    box-shadow: rgba(0, 0, 0, 0.2) 0px 10px 30px, rgba(0, 0, 0, 0.1) 0px 15px 40px, rgba(255, 255, 255, 0.3) 1px 0px 0px inset;
}

.doh-ebook .page-number {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.9);
    color: #000;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    border: 1px solid #e0e0e0;
}

/* Flip Animations */
.doh-ebook .page.flipping-next {
    transform: rotateY(-180deg);
    transform-origin: left center;
    box-shadow: 
        -15px 0 30px rgba(0,0,0,0.3),
        inset -2px 0 10px rgba(0,0,0,0.1);
    z-index: 100;
}

.doh-ebook .page.flipping-prev {
    transform: rotateY(0deg);
    transform-origin: right center;
    box-shadow: 
        15px 0 30px rgba(0,0,0,0.3),
        inset 2px 0 10px rgba(0,0,0,0.1);
    z-index: 100;
}

/* Drag Effects */
.doh-ebook .page.dragging {
    transition: none !important;
    z-index: 200;
    cursor: grabbing;
}

.doh-ebook .page.dragging-next {
    transform: rotateY(var(--drag-rotation, -45deg));
    transform-origin: left center;
    box-shadow: 
        -10px 0 25px rgba(0,0,0,0.25),
        inset -2px 0 8px rgba(0,0,0,0.15);
}

.doh-ebook .page.dragging-prev {
    transform: rotateY(var(--drag-rotation, 45deg));
    transform-origin: right center;
    box-shadow: 
        10px 0 25px rgba(0,0,0,0.25),
        inset 2px 0 8px rgba(0,0,0,0.15);
}

.doh-ebook .page.dragging::before {
    content: '';
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to right,
        transparent 0%,
        rgba(255,255,255,0.1) 10%,
        rgba(255,255,255,0.3) 50%,
        rgba(255,255,255,0.1) 90%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 1;
}

/* Navigation Areas */
.doh-ebook .page-nav-area {
    position: absolute;
    top: 0;
    height: 100%;
    z-index: 5;
    cursor: pointer;
}

.doh-ebook .page-nav-area.prev {
    left: 0;
    width: 40%;
}

.doh-ebook .page-nav-area.next {
    right: 0;
    width: 40%;
}

/* Controls */
.doh-ebook .controls-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1.5rem auto;
    flex-wrap: wrap;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 50px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    padding: 1rem;
    gap: 1rem;
    max-width: 900px;
}

.doh-ebook .zoom-controls, 
.doh-ebook .navigation-controls, 
.doh-ebook .action-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.doh-ebook .control-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--control-ebook-bg);
    color: white;
    border: none;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(67, 97, 238, 0.3);
}

.doh-ebook .control-btn:hover, 
.doh-ebook .control-btn:focus {
    background: var(--control-ebook-hover);
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(67, 97, 238, 0.4);
}

.doh-ebook .control-btn:active {
    transform: translateY(-1px);
}

.doh-ebook .control-btn:disabled {
    background: #a0a0a0;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.doh-ebook .page-indicator {
    background-color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 600;
    color: var(--doh-ebook-primary);
    border: 1px solid #ced4da;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    min-width: 80px;
    text-align: center;
}

/* Spread Layout */
.doh-ebook .spread-container {
    display: flex;
    width: 100%;
    height: 100%;
}

.doh-ebook .left-page, 
.doh-ebook .right-page {
    width: 50%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.doh-ebook .left-page img,
.doh-ebook .right-page img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Grid View */
.doh-ebook .grid-view {
    display: none;
    padding: 1rem;
}

.doh-ebook .grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.doh-ebook .grid-item {
    position: relative;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    height: 200px;
}

.doh-ebook .grid-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.doh-ebook .grid-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.doh-ebook .grid-item .page-number {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.9);
    color: #000;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    border: 1px solid #e0e0e0;
}

/* Statistics */
.doh-ebook .stats-container {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin: 1.5rem 0;
    flex-wrap: wrap;
}

.doh-ebook .stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.doh-ebook .stat-icon {
    color: var(--doh-ebook-primary);
    font-size: 1.25rem;
}

.doh-ebook .stat-number {
    font-weight: 500;
    font-size: 1.1rem;
    color: var(--doh-ebook-primary);
}

.doh-ebook .stat-label {
    color: var(--doh-ebook-dark);
}

/* Fullscreen */
.doh-ebook .flipbook-container.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    margin: 0;
    border-radius: 0;
    padding: 1rem;
    background: white;
}

.doh-ebook .flipbook-container.fullscreen .flipbook-wrapper {
    height: calc(100vh - 200px);
}

/* Responsive */
@media (max-width: 900px) {
    .doh-ebook #flipbook { width: 600px; height: 450px; }
    .doh-ebook .page { height: 450px; }
    .doh-ebook .controls-container { flex-direction: column; gap: 1rem; border-radius: 20px; }
    .doh-ebook .flipbook-wrapper { height: min(70vh, 450px); }
}

@media (max-width: 650px) {
    .doh-ebook #flipbook { width: 400px; height: 300px; }
    .doh-ebook .page { height: 300px; }
    .doh-ebook .control-btn { width: 40px; height: 40px; }
    .doh-ebook .grid-item { height: 150px; }
    .doh-ebook .flipbook-wrapper { height: min(65vh, 350px); }
}

@media (max-width: 450px) {
    .doh-ebook #flipbook { width: 320px; height: 240px; }
    .doh-ebook .page { height: 240px; }
    .doh-ebook .controls-container { padding: 0.8rem; }
    .doh-ebook .control-btn { width: 38px; height: 38px; }
    .doh-ebook .page-indicator { padding: 0.4rem 0.8rem; font-size: 0.9rem; }
    .doh-ebook .ebook-header { flex-direction: column; gap: 1rem; }
    .doh-ebook .btn-back { margin-right: 0; }
    .doh-ebook .grid-item { height: 120px; }
    .doh-ebook .flipbook-wrapper { height: min(60vh, 250px); }
    .doh-ebook .grid-item img { object-fit: contain;}
}