:root {
    --bg-color: #0d0f12;
    --text-color: #fdfdfd;
    --accent: #ffffff;
    --ui-bg: rgba(20, 22, 26, 0.6);
    --ui-border: rgba(255, 255, 255, 0.08);
}

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

body, html {
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    overscroll-behavior-y: none;
    -webkit-font-smoothing: antialiased;
}

/* --- Loading Screen --- */
#loading-screen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle at center, #1a1c23 0%, var(--bg-color) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

#loading-screen.active {
    opacity: 1;
    pointer-events: all;
}

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loading-text {
    font-weight: 500;
    font-size: 16px;
    letter-spacing: 0.5px;
    color: #a0a5b1;
}

.progress-bar-container {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.3s ease-out;
}

/* --- Application Layout --- */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    z-index: 1;
}

.app-header {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    z-index: 100;
    width: auto;
}

.nav-btn {
    background: var(--ui-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--ui-border);
    color: var(--text-color);
    width: 48px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, border-color 0.2s;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
    color: #000;
}

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

.page-indicator {
    background: var(--ui-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--ui-border);
    padding: 0 20px;
    height: 48px;
    display: flex;
    align-items: center;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 1px;
    color: #cfd4df;
    font-variant-numeric: tabular-nums;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* --- Viewer Area --- */
.viewer-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
    position: relative;
    perspective: 2000px; /* For 3D realism */
    overflow: hidden;
    touch-action: none;
}

.book-assembly {
    display: flex;
    align-items: stretch;
    position: relative;
    transition: margin-left 0.3s ease-out;
}

.page-roll {
    position: relative;
    width: var(--roll-width, 50px);
    background-color: #f5f5f5;
    /* Soft, matte paper cylinder gradient for a highly realistic 3D tube effect */
    background-image: linear-gradient(to right, 
        rgba(0, 0, 0, 0.25) 0%, 
        rgba(0, 0, 0, 0.05) 8%, 
        rgba(255, 255, 255, 0.9) 25%, 
        rgba(255, 255, 255, 0) 50%, 
        rgba(0, 0, 0, 0.05) 85%, 
        rgba(0, 0, 0, 0.3) 100%);
    /* Realistic curve on the outer edge of the roll */
    border-radius: 12px 0 0 12px; 
    box-shadow: -15px 15px 30px rgba(0,0,0,0.15), inset 4px 0 10px rgba(255,255,255,0.5);
    z-index: 10;
    transition: width 0.3s ease-out;
    overflow: hidden;
}



/* Deep, sharp crease where the cylinder meets the flat page */
.page-roll::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: 12px;
    background: linear-gradient(to right, transparent, rgba(0,0,0,0.25));
    z-index: 2;
}

.book-container {
    position: relative;
    background: #fff;
    box-shadow: 
        10px 20px 40px rgba(0,0,0,0.4),
        0 0 0 1px rgba(0,0,0,0.1);
    /* Transition for zoom/resize */
    transition: transform 0.3s cubic-bezier(0.2, 0, 0, 1), width 0.3s, height 0.3s;
    user-select: none;
    -webkit-user-select: none;
    transform-origin: center center;
}

/* Add realistic 3D paper stack thickness */
.book-stack-1, .book-stack-2, .book-stack-3 {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.05);
    z-index: -1;
}
.book-stack-1 { transform: translate(1px, 2px); }
.book-stack-2 { transform: translate(3px, 4px); }
.book-stack-3 { transform: translate(4px, 6px); box-shadow: 4px 6px 15px rgba(0,0,0,0.2); }

/* --- Page Elements --- */
.page-layer {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-color: #fff;
    pointer-events: none;
}

.page-base {
    z-index: 1;
    -webkit-clip-path: polygon(0 0, 100% 0, 100% calc(100% - 50px), calc(100% - 50px) 100%, 0 100%);
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 50px), calc(100% - 50px) 100%, 0 100%);
    transition: clip-path 0.3s ease-out, -webkit-clip-path 0.3s ease-out;
}

.page-base::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, 
        #ffffff 0%, 
        #f4f4f4 40%, 
        #e0e0e0 48%, 
        #b0b0b0 50%, 
        transparent 50%
    );
    box-shadow: -4px -4px 10px rgba(0,0,0,0.12);
    z-index: 10;
    pointer-events: none;
    transition: width 0.3s ease-out, height 0.3s ease-out, box-shadow 0.3s ease-out;
    border-top-left-radius: 4px;
}

.book-container:hover .page-base {
    -webkit-clip-path: polygon(0 0, 100% 0, 100% calc(100% - 75px), calc(100% - 75px) 100%, 0 100%);
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 75px), calc(100% - 75px) 100%, 0 100%);
}

.book-container:hover .page-base::after {
    width: 75px;
    height: 75px;
    box-shadow: -6px -6px 15px rgba(0,0,0,0.18);
}

/* Dynamic Drop Shadow */
.shadow-drop {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(to right, rgba(0,0,0,0.3) 0%, transparent 100%);
    z-index: 1;
}

/* Turning Page Anchor */
.turning-page {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    transform-style: preserve-3d;
    z-index: 5;
}

/* Segmented 3D Curve Strips */
.flip-strip {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    transform-style: preserve-3d;
    backface-visibility: hidden;
}

.strip-front, .strip-back {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background-repeat: no-repeat;
    background-color: #fff;
}

.strip-back {
    transform: rotateY(180deg);
    background-color: #fdfdfd;
}

.strip-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
}

/* --- Toast --- */
.toast {
    position: fixed;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ui-bg);
    color: var(--text-color);
    padding: 12px 24px;
    border-radius: 30px;
    font-size: 14px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--ui-border);
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
    z-index: 100;
}

.toast.show {
    opacity: 1;
}

/* --- Fullscreen Mode --- */
:fullscreen .app-header {
    opacity: 0;
    pointer-events: none;
    position: absolute;
}

:fullscreen .viewer-area {
    padding: 0;
}
