/* Thirunaal Booklet – Fullscreen Flipbook Theme */
:root {
    --bg-main: #fdfbf7;
    --bg-canvas-area: #f5f2eb;
    --border-color: #e7e2d8;
    --text-main: #292524;
    --text-secondary: #57534e;
    --text-muted: #a8a29e;

    --button-bg: #ffffff;
    --button-hover-bg: #fdfcfb;
    --button-active-bg: #f5f2eb;
    --button-border: #d6d3d1;

    --accent: #991b1b;
    --accent-hover: #7f1d1d;
    --gold-color: #b45309;

    --sidebar-width: 220px;
    --header-height: 50px;
    --footer-height: 52px;

    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

    /* Flip animation timing */
    --flip-duration: 0.6s;
    --flip-easing: cubic-bezier(0.645, 0.045, 0.355, 1.000);
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-main);
}

/* Scrollbar Customization */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}
::-webkit-scrollbar-track {
    background: #fdfbf7;
}
::-webkit-scrollbar-thumb {
    background: #d6d3d1;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #a8a29e;
}

/* ===== APP LAYOUT ===== */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* ===== HEADER ===== */
.app-header {
    height: var(--header-height);
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    z-index: 100;
    flex-shrink: 0;
}

.header-logo {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.brand-main {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.06em;
    color: var(--accent);
    text-transform: uppercase;
}

.brand-sep {
    color: var(--border-color);
    font-weight: 300;
    font-size: 0.95rem;
}

.brand-sub {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gold-color);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Buttons */
button {
    font-family: inherit;
    cursor: pointer;
    border: 1px solid var(--button-border);
    background: var(--button-bg);
    color: var(--text-main);
    outline: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

button:hover {
    background: var(--button-hover-bg);
    border-color: #a8a29e;
}

button:active {
    background: var(--button-active-bg);
}

button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #f5f2eb;
    border-color: #e7e2d8;
}

.icon-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    font-size: 0.9rem;
    border-radius: 6px;
}

.action-btn {
    font-weight: 500;
}

.share-btn {
    font-size: 0.85rem;
}

/* ===== WORKSPACE ===== */
.workspace-container {
    display: flex;
    flex: 1;
    height: calc(100vh - var(--header-height) - var(--footer-height));
    position: relative;
    overflow: hidden;
}

/* ===== SIDEBAR ===== */
.thumbnail-sidebar {
    width: var(--sidebar-width);
    background: #ffffff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease, transform 0.25s ease;
    z-index: 80;
    flex-shrink: 0;
}

.thumbnail-sidebar.collapsed {
    width: 0;
    border-right: none;
    transform: translateX(-100%);
}

.sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h3 {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.thumbnail-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.thumbnail-item {
    cursor: pointer;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: #ffffff;
    padding: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.thumbnail-item:hover {
    border-color: #a1a1aa;
}

.thumbnail-item.active {
    border-color: #18181b;
    background: #f4f4f5;
    outline: 1px solid #18181b;
}

.thumbnail-wrapper {
    width: 100%;
    aspect-ratio: 1 / 1.414;
    background: #f4f4f5;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 3px;
}

.thumbnail-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.thumbnail-label {
    margin-top: 5px;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ===== VIEWER MAIN ===== */
.viewer-main {
    flex: 1;
    position: relative;
    background: var(--bg-canvas-area);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 16px;
}

/* ===== CAROUSEL ===== */
.carousel-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 2000px;
}

/* ===== NAVIGATION ARROWS ===== */
.carousel-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border-radius: 0;
    background: none;
    border: none;
    color: #888;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    z-index: 100;
    transition: color 0.15s ease, opacity 0.15s ease;
    padding: 0;
    font-size: 1.4rem;
    cursor: pointer;
}

.carousel-nav-btn:hover {
    background: none;
    border: none;
    color: #555;
}

.carousel-nav-btn:disabled {
    opacity: 0.2;
    cursor: not-allowed;
    background: none;
    border: none;
}

.carousel-nav-btn.prev {
    left: 16px;
}

.carousel-nav-btn.next {
    right: 16px;
}

/* ===== CANVAS / SLIDES ===== */
.canvas-viewport {
    flex: 1;
    height: 100%;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Flip engine canvas overlay */
.flip-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 50;
    display: none;
    pointer-events: none;
}

.slide-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transform-style: preserve-3d;
}

.slide-item {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    z-index: 10;
    backface-visibility: hidden;
    transform-style: preserve-3d;
}

.slide-item.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 20;
}

.image-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 2px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
    position: relative;
    overflow: hidden;
}



.image-wrapper img {
    max-width: 100%;
    max-height: 100%;
    display: block;
    height: auto;
    object-fit: contain;
}

/* ===== 3D PAGE FLIP ANIMATIONS ===== */

/* Next page: current page flips away to the left (like turning a real page) */
.slide-item.flip-out-next {
    animation: flipOutNext var(--flip-duration) var(--flip-easing) forwards;
    transform-origin: left center;
    z-index: 30;
}

/* Next page: new page appears from behind */
.slide-item.flip-in-next {
    animation: flipInNext var(--flip-duration) var(--flip-easing) forwards;
    transform-origin: right center;
    z-index: 25;
}

/* Prev page: current page flips away to the right */
.slide-item.flip-out-prev {
    animation: flipOutPrev var(--flip-duration) var(--flip-easing) forwards;
    transform-origin: right center;
    z-index: 30;
}

/* Prev page: new page appears from behind */
.slide-item.flip-in-prev {
    animation: flipInPrev var(--flip-duration) var(--flip-easing) forwards;
    transform-origin: left center;
    z-index: 25;
}

@keyframes flipOutNext {
    0% {
        transform: perspective(2000px) rotateY(0deg);
        opacity: 1;
        filter: brightness(1);
    }
    30% {
        filter: brightness(0.92);
    }
    100% {
        transform: perspective(2000px) rotateY(-90deg);
        opacity: 0;
        filter: brightness(0.7);
    }
}

@keyframes flipInNext {
    0% {
        transform: perspective(2000px) rotateY(90deg);
        opacity: 0;
        filter: brightness(0.7);
    }
    40% {
        opacity: 1;
    }
    100% {
        transform: perspective(2000px) rotateY(0deg);
        opacity: 1;
        filter: brightness(1);
    }
}

@keyframes flipOutPrev {
    0% {
        transform: perspective(2000px) rotateY(0deg);
        opacity: 1;
        filter: brightness(1);
    }
    30% {
        filter: brightness(0.92);
    }
    100% {
        transform: perspective(2000px) rotateY(90deg);
        opacity: 0;
        filter: brightness(0.7);
    }
}

@keyframes flipInPrev {
    0% {
        transform: perspective(2000px) rotateY(-90deg);
        opacity: 0;
        filter: brightness(0.7);
    }
    40% {
        opacity: 1;
    }
    100% {
        transform: perspective(2000px) rotateY(0deg);
        opacity: 1;
        filter: brightness(1);
    }
}

/* Shadow overlay that appears during flip to simulate page shadow */
.slide-item.flip-out-next .image-wrapper::after,
.slide-item.flip-in-next .image-wrapper::after,
.slide-item.flip-out-prev .image-wrapper::after,
.slide-item.flip-in-prev .image-wrapper::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to right,
        rgba(0,0,0,0.15) 0%,
        rgba(0,0,0,0) 30%,
        rgba(0,0,0,0) 70%,
        rgba(0,0,0,0.15) 100%
    );
    pointer-events: none;
    z-index: 10;
    animation: shadowPulse var(--flip-duration) ease-in-out forwards;
}

@keyframes shadowPulse {
    0% { opacity: 0; }
    30% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

/* Keep old slide classes for backward compat (legacy) – just map them */
.slide-item.slide-out-left {
    animation: flipOutNext var(--flip-duration) var(--flip-easing) forwards;
    transform-origin: left center;
    z-index: 30;
}
.slide-item.slide-in-right {
    animation: flipInNext var(--flip-duration) var(--flip-easing) forwards;
    transform-origin: right center;
    z-index: 25;
}
.slide-item.slide-out-right {
    animation: flipOutPrev var(--flip-duration) var(--flip-easing) forwards;
    transform-origin: right center;
    z-index: 30;
}
.slide-item.slide-in-left {
    animation: flipInPrev var(--flip-duration) var(--flip-easing) forwards;
    transform-origin: left center;
    z-index: 25;
}

/* ===== PAGE INDICATOR ===== */
.page-indicator-overlay {
    position: absolute;
    top: 12px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border-color);
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    z-index: 60;
    pointer-events: none;
}

/* ===== LOADING ===== */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 90;
}

.spinner-box {
    text-align: center;
}

.pulse-spinner {
    width: 32px;
    height: 32px;
    border: 2px solid #e4e4e7;
    border-top-color: #18181b;
    border-radius: 50%;
    margin: 0 auto 12px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner-box p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ===== FOOTER ===== */
.app-footer {
    height: var(--footer-height);
    background: #ffffff;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    z-index: 100;
    flex-shrink: 0;
}

.footer-section {
    display: flex;
    align-items: center;
    gap: 6px;
}

.page-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-color);
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.page-selector input {
    width: 36px;
    background: transparent;
    border: none;
    outline: none;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    color: var(--text-main);
}

.page-selector input::-webkit-outer-spin-button,
.page-selector input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.page-selector input[type=number] {
    -moz-appearance: textfield;
}

.zoom-level {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: center;
}

/* ===== TOAST ===== */
.toast-container {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-left: 3px solid #18181b;
    padding: 8px 16px;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-main);
    transform: translateY(10px);
    opacity: 0;
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast-success {
    border-left-color: #10b981;
}

.toast-error {
    border-left-color: #ef4444;
}

.toast-success i { color: #10b981; }
.toast-error i { color: #ef4444; }

.hidden {
    display: none !important;
}

/* ===== COVER PAGE CURL ===== */
.image-wrapper.has-cover-curl {
    position: relative;
    overflow: hidden;
}

.image-wrapper.has-cover-curl::after {
    content: '';
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg,
        rgba(0,0,0,0) 0%,
        rgba(0,0,0,0) 45%,
        rgba(0,0,0,0.2) 46%,
        rgba(0,0,0,0.25) 48%,
        rgba(0,0,0,0.06) 50%,
        #f0ece4 51%,
        #d6d1c7 75%,
        #f5f0e8 100%
    );
    box-shadow: -4px -4px 10px rgba(0, 0, 0, 0.2);
    z-index: 30;
    pointer-events: none;
    transition: width 0.25s cubic-bezier(0.16, 1, 0.3, 1), height 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    clip-path: polygon(100% 0, 0 100%, 100% 100%);
    -webkit-clip-path: polygon(100% 0, 0 100%, 100% 100%);
}

.image-wrapper.has-cover-curl img {
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 60px), calc(100% - 60px) 100%, 0 100%);
    -webkit-clip-path: polygon(0 0, 100% 0, 100% calc(100% - 60px), calc(100% - 60px) 100%, 0 100%);
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
    transition: clip-path 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.image-wrapper.has-cover-curl:hover::after {
    width: 80px;
    height: 80px;
}

.image-wrapper.has-cover-curl:hover img {
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 80px), calc(100% - 80px) 100%, 0 100%);
    -webkit-clip-path: polygon(0 0, 100% 0, 100% calc(100% - 80px), calc(100% - 80px) 100%, 0 100%);
}



/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 200px;
        --header-height: 46px;
        --footer-height: 48px;
    }

    .action-btn span {
        display: none;
    }

    .carousel-nav-btn {
        width: 36px;
        height: 36px;
        font-size: 1.2rem;
    }

    .carousel-nav-btn.prev {
        left: 8px;
    }

    .carousel-nav-btn.next {
        right: 8px;
    }

    .zoom-section {
        display: none;
    }

    .thumbnail-sidebar {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        width: var(--sidebar-width);
        box-shadow: 8px 0 20px rgba(0, 0, 0, 0.15);
        z-index: 200;
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .thumbnail-sidebar.collapsed {
        transform: translateX(-100%);
        width: var(--sidebar-width);
        border-right: none;
    }

    .viewer-main {
        padding: 8px;
    }

    .carousel-wrapper {
        gap: 0;
    }

    .image-wrapper {
        width: 100%;
        height: auto;
        max-height: calc(100vh - var(--header-height) - var(--footer-height) - 16px);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }

    .image-wrapper img {
        width: 100%;
        height: auto;
        max-height: calc(100vh - var(--header-height) - var(--footer-height) - 16px);
        object-fit: contain;
    }

    .app-footer {
        padding: 0 10px;
    }

    .footer-section {
        gap: 4px;
    }

    button {
        padding: 6px 10px;
    }
}
