* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-red: #DC143C;
    --primary-blue: #1E3A8A;
    --white: #FFFFFF;
    --gray-light: #F3F4F6;
    --gray-dark: #374151;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.2);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, var(--gray-light) 0%, var(--white) 100%);
    min-height: 100vh;
    overflow-x: hidden;
}

header {
    background: linear-gradient(90deg, var(--primary-blue) 0%, var(--primary-red) 100%);
    color: var(--white);
    padding: 1rem;
    box-shadow: var(--shadow);
    position: relative;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    gap: 40px;
    text-align: center;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

header p {
    font-size: 1rem;
    opacity: 0.95;
}

main {
    padding: 0;
    max-width: 100vw;
    margin: 0 auto;
    position: relative;
    height: calc(100vh - 60px);
    display: flex;
    flex-direction: column;
}

.controls {
    position: absolute;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 25px;
    box-shadow: var(--shadow);
    z-index: 10;
    backdrop-filter: blur(10px);
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

.controls:hover {
    opacity: 1;
}

/* Invisible hover trigger zone for top controls */
.controls::before {
    content: '';
    position: absolute;
    top: -20px;
    left: -20px;
    right: -20px;
    bottom: -20px;
    z-index: -1;
}

.controls:hover {
    opacity: 1;
}

.nav-btn {
    background: var(--primary-blue);
    color: var(--white);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.nav-btn:hover {
    background: var(--primary-red);
    transform: scale(1.1);
}

.nav-btn:active {
    transform: scale(0.95);
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--gray-dark);
    min-width: 60px;
    text-align: center;
}

#flipbook-container {
    position: relative;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    height: calc(100vh - 60px);
    perspective: 2000px;
    overflow: hidden;
    padding: 0;
    z-index: 1;
}

/* Allow shifting of flipbook for hiding empty pages */
#flipbook-container.shift-left {
    justify-content: flex-start;
}

#flipbook-container.shift-right {
    justify-content: flex-end;
}

#flipbook {
    border-radius: 4px;
    overflow: visible;
    position: relative;
    transition: transform 0.3s ease;
}

#flipbook .page {
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

/* Hide Turn.js's empty pages */
#flipbook .p0,
#flipbook .odd:last-child {
    background: transparent !important;
}

/* Remove background for empty pages */
#flipbook .page:empty {
    background: transparent !important;
}

#flipbook canvas {
    max-width: 100%;
    height: auto;
    display: block;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    -webkit-font-smoothing: subpixel-antialiased;
}

.bottom-controls {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 25px;
    box-shadow: var(--shadow);
    z-index: 10;
    backdrop-filter: blur(10px);
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

/* Invisible hover trigger zone for bottom controls */
.bottom-controls::before {
    content: '';
    position: absolute;
    top: -20px;
    left: -20px;
    right: -20px;
    bottom: -20px;
    z-index: -1;
}

.bottom-controls:hover {
    opacity: 1;
}

.control-btn {
    background: var(--white);
    color: var(--primary-blue);
    border: 2px solid var(--primary-blue);
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
}

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

.download-btn {
    background: var(--primary-red);
    color: var(--white);
    border-color: var(--primary-red);
    padding: 0.4rem 0.8rem;
}

.download-btn:hover {
    background: var(--white);
    color: var(--primary-red);
}

.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #FFFFFF;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    gap: 1.5rem;
}

.loading.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--gray-light);
    border-top-color: var(--primary-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading p {
    color: var(--gray-dark);
    font-size: 1.1rem;
    font-weight: 500;
}

/* Zoom container */
.zoom-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Preload pages for smooth transitions */
#flipbook .page.loading {
    background: var(--gray-light);
    min-height: 400px;
    position: relative;
}

/* Individual page loader */
.page-loader {
    width: 100%;
    height: 100%;
    background: #f8f8f8;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.page-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--gray-light);
    border-top-color: var(--primary-blue);
    border-radius: 50%;
    animation: pageSpin 0.8s linear infinite;
}

@keyframes pageSpin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.page-number {
    color: #999;
    font-size: 14px;
    font-weight: 500;
}

/* Fullscreen controls overlay */
.fullscreen-controls {
    display: none;
}

:fullscreen .fullscreen-controls,
:-webkit-full-screen .fullscreen-controls {
    display: flex;
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    gap: 2rem;
    z-index: 1002;
    background: rgba(0, 0, 0, 0.7);
    padding: 1rem 2rem;
    border-radius: 50px;
}

:fullscreen .fullscreen-controls .nav-btn,
:-webkit-full-screen .fullscreen-controls .nav-btn {
    background: rgba(255, 255, 255, 0.9);
    color: var(--primary-blue);
}

:fullscreen .fullscreen-controls .page-info,
:-webkit-full-screen .fullscreen-controls .page-info {
    color: var(--white);
}

:fullscreen .fullscreen-controls .nav-btn:hover,
:-webkit-full-screen .fullscreen-controls .nav-btn:hover {
    background: var(--white);
    transform: scale(1.1);
}

.exit-fullscreen-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.9);
    color: var(--primary-blue);
    border: none;
    padding: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    z-index: 1003;
    display: none;
}

:fullscreen .exit-fullscreen-btn,
:-webkit-full-screen .exit-fullscreen-btn {
    display: block;
}

/* Annotation Layer Styles */
.annotationLayer {
    pointer-events: auto;
    z-index: 100;
}

.annotationLayer a {
    display: block;
    text-decoration: none;
    color: transparent;
    outline: none;
}

.annotationLayer a:hover {
    background-color: rgba(0, 123, 255, 0.1) !important;
    border: 1px solid rgba(0, 123, 255, 0.3);
}

/* Ensure links work with zoom */
#flipbook-container.zoomed .annotationLayer a {
    transform-origin: top left;
}

/* Mobile Styles */
/* Mobile Styles */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.5rem;
    }

    header p {
        font-size: 0.9rem;
    }

    main {
        height: calc(100vh - 50px);
        margin-top: 10px;
    }

    .controls {
        gap: 0.5rem;
        padding: 0.4rem 0.8rem;
        top: 5px;
        opacity: 0.8;
        /* Semi-transparent on mobile */
        background: rgba(255, 255, 255, 0.9);
        position: fixed;
    }

    .bottom-controls {
        opacity: 0.8;
        /* Semi-transparent on mobile */
        background: rgba(255, 255, 255, 0.9);
        position: fixed;
        bottom: 5px;
    }

    .nav-btn {
        width: 32px;
        height: 32px;
    }

    .nav-btn svg {
        width: 18px;
        height: 18px;
    }

    .page-info {
        font-size: 0.85rem;
        min-width: 50px;
    }

    #flipbook-container {
        height: calc(100vh - 50px);
        padding: 60px 10px;
    }

    .bottom-controls {
        padding: 0.4rem 0.8rem;
        gap: 0.5rem;
        bottom: 0.5rem;
    }

    .control-btn {
        padding: 0.35rem 0.5rem;
        font-size: 0.75rem;
    }

    .control-btn svg {
        width: 16px;
        height: 16px;
    }

    .download-btn {
        padding: 0.35rem 0.6rem;
    }

    #fullscreen {
        display: none;
    }

    .no-mobile {
        display: none;
    }
}

/* Tablet Styles */
@media (min-width: 769px) and (max-width: 1024px) {
    #flipbook-container {
        height: calc(100vh - 60px);
    }
}

/* Desktop Styles */
@media (min-width: 1025px) {
    #flipbook-container {
        height: calc(100vh - 60px);
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {

    .nav-btn:hover,
    .control-btn:hover {
        transform: none;
    }

    .nav-btn:active {
        transform: scale(0.95);
    }
}

/* Fullscreen styles */
:fullscreen #flipbook-container,
:-webkit-full-screen #flipbook-container {
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

:fullscreen .controls,
:-webkit-full-screen .controls {
    display: none;
}

:fullscreen .bottom-controls,
:-webkit-full-screen .bottom-controls {
    display: none;
}

:fullscreen #flipbook,
:-webkit-full-screen #flipbook {
    max-height: 90vh;
}