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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #ffffff;
    overflow: hidden;
    cursor: grab;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    -webkit-touch-callout: none; /* Disable callout on iOS */
    -webkit-user-select: none; /* Disable text selection */
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
    touch-action: manipulation; /* Optimize touch handling */
}

/* Navbar */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    z-index: 9998;
}

.navbar-content {
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
}

.navbar-title a {
    text-decoration: none;
    color: inherit;
}

.navbar-title h1 {
    font-size: 24px;
    font-weight: 700;
    color: #333;
    letter-spacing: -0.5px;
    transition: color 0.3s ease;
}

.navbar-title a:hover h1 {
    color: #e74c3c;
}

.navbar-links {
    display: flex;
    gap: 30px;
    align-items: center;
}

.nav-link {
    text-decoration: none;
    color: #666;
    font-size: 16px;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 25px;
    transition: all 0.3s ease;
    position: relative;
}

.nav-link:hover {
    color: #333;
    background: rgba(0, 0, 0, 0.05);
    transform: translateY(-1px);
}

.nav-link:first-child {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
    color: white;
    padding: 10px 20px;
    font-weight: 600;
}

.nav-link:first-child:hover {
    background: linear-gradient(45deg, #c0392b, #a93226);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

body:active {
    cursor: grabbing;
}

#canvas-container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0a0a0a;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease-out;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    text-align: center;
    color: #fff;
}

.book-loader {
    width: 60px;
    height: 80px;
    margin: 0 auto 20px;
    position: relative;
    transform-style: preserve-3d;
    animation: bookRotate 2s infinite;
}

.book-page {
    position: absolute;
    width: 100%;
    height: 100%;
    background: #fff;
    border: 2px solid #333;
    border-radius: 0 5px 5px 0;
}

.book-page:nth-child(1) {
    transform: rotateY(0deg) translateZ(3px);
    background: #e74c3c;
}

.book-page:nth-child(2) {
    transform: rotateY(0deg) translateZ(0px);
    background: #ecf0f1;
}

.book-page:nth-child(3) {
    transform: rotateY(0deg) translateZ(-3px);
    background: #34495e;
}

@keyframes bookRotate {
    0%, 100% {
        transform: rotateY(-20deg);
    }
    50% {
        transform: rotateY(20deg);
    }
}

/* Controls */
#controls {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 30px;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    padding: 15px 25px;
    border-radius: 50px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    z-index: 1000;
    flex-wrap: wrap;
    justify-content: center;
    flex-direction: row;
}

.control-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    font-size: 14px;
    flex-direction: column;
    text-align: center;
}

@media (min-width: 769px) {
    .control-hint {
        flex-direction: row;
        text-align: left;
    }
}

.control-hint .icon {
    font-size: 18px;
}

/* Mobile/Desktop specific controls */
.desktop-only {
    display: flex;
}

.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none;
    }
    
    .mobile-only {
        display: flex;
        /* flex-direction: row; */
        
    }
}

/* Page Indicator */
#page-indicator {
    position: fixed;
    top: 90px; /* Moved down to account for navbar */
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    padding: 10px 20px;
    border-radius: 25px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    color: #fff;
    font-size: 14px;
    z-index: 1000;
}

/* Navigation Arrows */
#navigation-arrows {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80vw;
    max-width: 800px;
    display: none; /* Hidden by default, shown when book is open */
    justify-content: space-between;
    align-items: center;
    pointer-events: none; /* Allow clicking through the container */
    z-index: 1500;
}

@media (max-width: 768px) {
    #navigation-arrows {
        width: 100vw;
        padding: 0 10px;
        box-sizing: border-box;
    }
}

#navigation-arrows.show {
    display: flex;
}

.nav-arrow {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    color: #fff;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto; /* Arrows are clickable */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
    user-select: none; /* Prevent text selection */
    touch-action: manipulation; /* Optimize touch handling */
}

.nav-arrow:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

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

.nav-arrow-left {
    left: 0;
}

.nav-arrow-right {
    right: 0;
}

.nav-arrow:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.nav-arrow:disabled:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Swipe Hint for Mobile */
.swipe-hint {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    padding: 15px 25px;
    border-radius: 25px;
    color: #fff;
    font-size: 14px;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

.swipe-hint.show {
    opacity: 1;
}

.swipe-animation {
    display: flex;
    align-items: center;
    gap: 10px;
}

.swipe-icon {
    font-size: 18px;
    animation: swipeAnimation 2s infinite;
}

.swipe-text {
    font-weight: 500;
}

@keyframes swipeAnimation {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-5px);
    }
    75% {
        transform: translateX(5px);
    }
}

/* Purchase Popup */
.purchase-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.purchase-popup.show {
    opacity: 1;
}

.popup-content {
    background: linear-gradient(145deg, #ffffff, #f8f9fa);
    border-radius: 20px;
    padding: 0;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(0, 0, 0, 0.1);
    transform: scale(0.8);
    transition: transform 0.3s ease;
}

.purchase-popup.show .popup-content {
    transform: scale(1);
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 30px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.popup-header h2 {
    margin: 0;
    color: #333;
    font-size: 24px;
    font-weight: 600;
}

.close-popup {
    background: none;
    border: none;
    color: #666;
    font-size: 30px;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.close-popup:hover {
    background-color: rgba(0, 0, 0, 0.1);
    color: #333;
}

.popup-body {
    padding: 30px;
    text-align: center;
}

.popup-body p {
    color: #555;
    font-size: 16px;
    line-height: 1.6;
    margin: 0 0 20px;
}

.popup-body p:last-of-type {
    font-size: 18px;
    margin-bottom: 30px;
}

.popup-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.buy-button, .continue-reading {
    padding: 15px 30px;
    border-radius: 50px;
    text-decoration: none;
    font-size: 16px;
    font-weight: 600;
    transition: all 0.3s ease;
    cursor: pointer;
    border: none;
    min-width: 150px;
}

.buy-button {
    background: linear-gradient(45deg, #e74c3c, #c0392b);
    color: white;
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

.buy-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

.continue-reading {
    background: rgba(0, 0, 0, 0.05);
    color: #333;
    border: 2px solid rgba(0, 0, 0, 0.2);
}

.continue-reading:hover {
    background: rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
    border-color: rgba(0, 0, 0, 0.3);
}

/* Responsive */
@media (max-width: 768px) {
    /* Navbar Mobile */
    .navbar {
        height: 60px;
    }

    .navbar-content {
        padding: 0 15px;
    }

    .navbar-title h1 {
        font-size: 20px;
    }

    .navbar-links {
        gap: 15px;
    }

    .nav-link {
        font-size: 14px;
        padding: 6px 12px;
    }

    .nav-link:first-child {
        padding: 8px 16px;
    }

    .control-hint {
        font-size: 12px;
    }

    .control-hint .icon {
        font-size: 16px;
    }

    #page-indicator {
        top: 90px; /* Adjusted for smaller mobile navbar */
        font-size: 12px;
        padding: 8px 16px;
    }

    /* Navigation Arrows Mobile - Larger touch targets */
    .nav-arrow {
        width: 70px;
        height: 70px;
        font-size: 32px;
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    }

    #navigation-arrows {
        width: 95vw;
        padding: 0 5px;
    }

    /* Larger controls for touch */
    #controls {
        padding: 10px;
        font-size: 14px;
        gap: 8px;
        max-width: 90%;
        text-align: center;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        bottom: 10px;
        border-radius: 15px;
    }

    .control-hint {
        font-size: 1px;
        gap: 4px;
        flex: 1;
        min-width: 90px;
        text-align: center;
        /* flex-direction: column; */
        flex-direction: row;
    }

    .control-hint .icon {
        font-size: 16px;
    }

    .popup-content {
        width: 95%;
        margin: 20px;
    }

    .popup-header {
        padding: 20px 25px 15px;
    }

    .popup-header h2 {
        font-size: 20px;
    }

    .popup-body {
        padding: 25px 20px;
    }

    .popup-actions {
        flex-direction: column;
        align-items: center;
    }

    .buy-button, .continue-reading {
        width: 100%;
        max-width: 250px;
    }
}

@media (max-width: 480px) {
    .navbar-links {
        gap: 10px;
    }

    .nav-link {
        font-size: 13px;
        padding: 5px 10px;
    }

    .nav-link:first-child {
        padding: 7px 14px;
    }

    .navbar-title h1 {
        font-size: 18px;
    }

    .nav-arrow {
        width: 45px;
        height: 45px;
        font-size: 22px;
    }

    #navigation-arrows {
        width: 95vw;
    }

    #controls {
        padding: 10px 10px;
        gap: 8px;
        max-width: 98vw;
    }

    .control-hint {
        font-size: 10px;
        min-width: 90px;
        gap: 3px;
    }

    .control-hint .icon {
        font-size: 14px;
    }
}
