body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 5vh;
    min-height: 100vh;
    color: #2d3436;
    overflow-x: hidden;
}

.container {
    width: 95%;
    max-width: 1400px;
    min-height: 85vh;
    text-align: center;
    margin: 20px auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    transition: width 0.3s ease;
    position: relative;
}

h1 {
    font-weight: 800;
    font-size: clamp(2rem, 8vw, 3.5rem);
    color: #ffffff;
    margin-bottom: 0.5rem;
    letter-spacing: -1px;
    text-shadow: 0 2px 10px rgba(0,0,0,0.2);
    line-height: 1.2;
}

h1 a {
    color: inherit;
    text-decoration: none;
    transition: opacity 0.2s;
}

h1 a:hover { opacity: 0.9; }

.make-own-link {
    color: #ffffff;
    text-decoration: none;
    font-size: 1.1rem;
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 12px 40px;
    border-radius: 100px;
    margin-top: 20px;
    display: inline-block;
    font-weight: 700;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    letter-spacing: -0.02em;
    text-shadow: none;
}

.make-own-link:hover {
    background: #ffffff;
    color: #6c5ce7;
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    border-color: #ffffff;
}

.subtitle {
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 2.5rem;
    font-size: 1.2rem;
    text-shadow: 0 1px 5px rgba(0,0,0,0.1);
}

/* ─── Upload section ────────────────────────────────────────────────────────── */

.upload-section {
    margin-bottom: 2rem;
    padding: 4rem 2rem;
    border: 3px dashed rgba(255, 255, 255, 0.3);
    border-radius: 24px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    position: relative;
    cursor: pointer;
}

.upload-section.drag-over {
    border-color: #ffffff;
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.02);
}

.upload-section:hover {
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.15);
}

.upload-icon {
    width: 4rem;
    height: 4rem;
    color: #ffffff;
    margin-bottom: 1.5rem;
    display: block;
    margin-left: auto;
    margin-right: auto;
    stroke-width: 1.5;
}

.is-shared-view .upload-icon,
.is-shared-view .upload-btn { display: none !important; }

.visually-hidden,
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.upload-btn {
    display: inline-block;
    padding: 1.2rem 3rem;
    background: #ffffff;
    color: #6c5ce7;
    border-radius: 14px;
    cursor: pointer;
    font-weight: 700;
    font-size: 1.1rem;
    transition: all 0.3s;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    border: 0;
}

.upload-btn:hover {
    background: #f8f9fa;
    transform: translateY(-2px);
    box-shadow: 0 15px 25px rgba(0, 0, 0, 0.2);
}

.upload-btn:disabled {
    cursor: not-allowed;
    opacity: 0.58;
    transform: none;
    box-shadow: none;
}

.upload-btn:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 3px solid #ffeaa7;
    outline-offset: 3px;
}

.turnstile-container {
    min-height: 66px;
    margin: 1.25rem auto 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

#file-name {
    margin-top: 1.5rem;
    color: #ffffff;
    font-weight: 700;
    font-size: 2.5rem;
    text-shadow: 0 2px 15px rgba(0,0,0,0.3);
    letter-spacing: -0.03em;
    line-height: 1.2;
}

/* ─── Toast ─────────────────────────────────────────────────────────────────── */

.toast-notification {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(25, 25, 25, 0.9);
    color: white;
    padding: 14px 28px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.toast-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ─── Flipbook container ─────────────────────────────────────────────────────── */

#flipbook-container {
    margin-top: 2rem;
    width: 100%;
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#flipbook-container.ready {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    opacity: 1;
}

.load-error {
    margin: 2rem auto;
    max-width: 640px;
    border-radius: 20px;
    padding: 2rem;
    background: rgba(25, 25, 25, 0.78);
    color: white;
}

.load-error h2 { margin-top: 0; }
.load-error a { color: white; font-weight: 700; }

/* ─── Flipbook scene ─────────────────────────────────────────────────────────── */

.fb-scene {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0 80px;
    /* perspective applied here so the 3D flip has depth */
    perspective: 3000px;
    perspective-origin: 50% 40%;
    transform-origin: top center;
}

/* ─── Book ───────────────────────────────────────────────────────────────────── */

.fb-book {
    position: relative;
    display: flex;
    flex-direction: row;
    /* perspective here so the flipper (direct child) gets real 3D depth */
    perspective: 1200px;
    perspective-origin: 50% 50%;
    /* transition for cover → spread width expansion */
    transition: width 0.65s cubic-bezier(0.645, 0.045, 0.355, 1.000);
    /* large drop shadow to ground the book */
    filter: drop-shadow(0 30px 50px rgba(0,0,0,0.5));
}

/* Cover state: left half is the "book back" texture */
.fb-book.state-cover .fb-slot-left {
    background: linear-gradient(to right, #5a4a3a 0%, #7a6150 40%, #6b5545 60%, #5a4a3a 100%);
    border-right: 2px solid rgba(0,0,0,0.3);
}

/* Spine line in the center when spread is open */
.fb-book.state-spread .fb-slot-left {
    border-right: 1px solid rgba(0,0,0,0.15);
}

/* ─── Slots ──────────────────────────────────────────────────────────────────── */

.fb-slot {
    position: relative;
    overflow: hidden;
    background: white;
    flex-shrink: 0;
}

.fb-slot-left  { border-radius: 3px 0 0 3px; }
.fb-slot-right { border-radius: 0 3px 3px 0; }

/* Spine shadow on left slot during flip */
.fb-slot-left::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 35%;
    height: 100%;
    background: linear-gradient(to left, rgba(0,0,0,0.18), transparent);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 5;
}

.fb-book.is-flipping .fb-slot-left::after { opacity: 1; }

/* Page stack on right edge (cover closed look) */
.fb-book.state-cover .fb-slot-right::after {
    content: '';
    position: absolute;
    top: 2px; right: -5px;
    width: 5px;
    height: calc(100% - 4px);
    background: linear-gradient(to right, #d8cfc8, #c8bfb8);
    border-radius: 0 2px 2px 0;
    box-shadow: 1px 0 0 #b8afaa, 2px 0 0 #a8a09a, 3px 0 0 #989089;
}

/* ─── Flipper ────────────────────────────────────────────────────────────────── */

.fb-flipper {
    position: absolute;
    top: 0;
    transform-style: preserve-3d;
    /* transition applied via JS to allow for instant reset */
    display: none;
    z-index: 10;
}

.fb-flipper-face {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    overflow: hidden;
    background: white;
}

.fb-flipper-back {
    transform: rotateY(180deg);
}

/* Inner mirror-fix wrapper (counteracts the Y-flip on back face) */
.fb-back-mirror {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    transform: scaleX(-1);
}

/* Gradient overlay simulating page curl / shadow */
.fb-flipper-face::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 20;
    opacity: 0;
    transition: opacity 0.1s;
}

.fb-flipper-front::after {
    background: linear-gradient(to left, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.04) 30%, transparent 60%);
    opacity: 1;
}

.fb-flipper-back::after {
    background: linear-gradient(to right, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.04) 30%, transparent 60%);
    opacity: 1;
}

/* ─── PDF page ───────────────────────────────────────────────────────────────── */

.fb-page {
    display: block;
    position: relative;
    width: 100%;
    height: 100%;
    line-height: 0; /* prevent gap under canvas */
}

.fb-page canvas {
    display: block;
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
}

.fb-page[data-evicted="true"]::before {
    content: "Page preview will load when opened";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #555;
    background: #fff;
    font-size: 0.9rem;
    line-height: 1.4;
    padding: 1rem;
    z-index: 1;
}

/* Annotation layer — invisible but clickable */
.fb-annotations {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
}

.fb-annotations a {
    position: absolute;
    display: block;
    pointer-events: all;
    cursor: pointer;
    /* visible outline on hover for UX feedback */
}

.fb-annotations a:hover {
    background: rgba(100, 160, 255, 0.12);
    outline: 1px solid rgba(100, 160, 255, 0.3);
    border-radius: 2px;
}

/* Disable links during animation */
.fb-book.is-flipping .fb-annotations,
.fb-book.is-opening .fb-annotations {
    pointer-events: none !important;
}

/* ─── Navigation arrows ──────────────────────────────────────────────────────── */

.fb-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.92);
    border: none;
    border-radius: 50%;
    width: 48px; height: 48px;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    z-index: 100;
    transition: all 0.2s;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    color: #2d3436;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.fb-nav:hover:not(:disabled) {
    background: white;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

.fb-nav:disabled {
    opacity: 0.25;
    cursor: not-allowed;
    transform: translateY(-50%);
}

.fb-nav-prev { left: -64px; }
.fb-nav-next { right: -64px; }

@media (max-width: 900px) {
    .fb-nav-prev { left: -52px; }
    .fb-nav-next { right: -52px; }
}

@media (max-width: 600px) {
    /* On mobile nav buttons overlay the book edges instead of sitting outside */
    .fb-nav       { width: 40px; height: 40px; font-size: 1.4rem; opacity: 0.82; }
    .fb-nav-prev  { left: 6px; }
    .fb-nav-next  { right: 6px; }
}

/* ─── Open button ────────────────────────────────────────────────────────────── */

.fb-open-btn {
    position: absolute;
    bottom: -56px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    color: #6c5ce7;
    border: none;
    padding: 14px 36px;
    border-radius: 100px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(0,0,0,0.22);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    letter-spacing: 0.01em;
}

.fb-open-btn:hover {
    transform: translateX(-50%) translateY(-3px);
    box-shadow: 0 10px 32px rgba(0,0,0,0.3);
}

/* ─── Page indicator ─────────────────────────────────────────────────────────── */

.fb-page-indicator {
    position: absolute;
    bottom: -44px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

/* ─── Single/dual page toggle button ────────────────────────────────────────── */

.fb-view-btn {
    position: absolute;
    bottom: -52px;
    right: 0;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.85);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    color: #2d3436;
    z-index: 100;
    transition: background 0.2s, transform 0.15s;
}

.fb-view-btn:hover {
    background: white;
    transform: scale(1.1);
}

/* Single-page mode clips overflow to hide the second page. Move the return
   control onto the visible page so that clipping cannot trap the reader. */
.fb-view-btn.is-single-page {
    top: 12px;
    bottom: auto;
    right: 12px;
    background: rgba(255, 255, 255, 0.96);
}

.fb-view-btn svg {
    width: 18px;
    height: 18px;
    display: block;
}

/* ─── Modals ─────────────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-overlay[aria-hidden="true"] { visibility: hidden; }

.modal-content {
    background: rgba(25, 25, 25, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 3.5rem 2.5rem;
    border-radius: 32px;
    width: 90%;
    max-width: 480px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transform: translateY(30px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-content {
    transform: translateY(0) scale(1);
}

.modal-content h3 {
    margin: 0 0 0.75rem 0;
    font-size: 2rem;
    color: white;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.modal-content p {
    margin: 0 0 2.5rem 0;
    color: rgba(255, 255, 255, 0.6);
    font-size: 1.1rem;
    line-height: 1.5;
}

.modal-content .large-file-disclosure {
    margin-bottom: 1.25rem;
    padding: 0.9rem 1rem;
    border-radius: 12px;
    background: rgba(103, 88, 221, 0.18);
    color: rgba(255, 255, 255, 0.9);
    text-align: left;
    font-size: 0.95rem;
}

#flipbook-name-input {
    width: 100%;
    padding: 0.9rem 1.2rem;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    font-size: 1rem;
    margin-bottom: 1.5rem;
    box-sizing: border-box;
    outline: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    transition: all 0.2s;
}

#flipbook-name-input::placeholder { color: rgba(255, 255, 255, 0.5); }

#flipbook-name-input:focus {
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.modal-buttons button {
    padding: 0.8rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.btn-primary {
    background: #6c5ce7;
    color: white;
}

.btn-primary:hover {
    background: #5b4bc4;
    transform: translateY(-1px);
}

.btn-secondary {
    background: #f1f2f6;
    color: #2d3436;
}

.btn-secondary:hover { background: #dfe4ea; }

/* ─── Share modal ────────────────────────────────────────────────────────────── */

.share-link-container {
    display: flex;
    gap: 0;
    margin: 15px 0 30px 0;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 6px;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.share-label {
    text-align: left;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#share-link-input,
#embed-code-input {
    flex: 1;
    padding: 12px 18px;
    border: none;
    background: transparent;
    color: white;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    width: 100%;
}

.btn-copy {
    background: #ffffff;
    color: #6c5ce7;
    border: none;
    padding: 0 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-copy:hover {
    background: #f8f9fa;
    transform: scale(1.02);
}

.share-buttons {
    display: flex;
    gap: 15px;
    margin-bottom: 35px;
    justify-content: center;
}

.btn-share {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(255, 255, 255, 0.05);
}

.btn-share:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.3);
}

.btn-share svg { width: 28px; height: 28px; }

.btn-whatsapp svg     { color: #25D366; }
.btn-whatsapp-biz svg { color: #128C7E; }
.btn-messenger svg    { color: #0084FF; }

#share-modal-close {
    border-radius: 99px !important;
    width: auto !important;
    min-width: 140px !important;
    height: 54px !important;
    padding: 0 30px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    font-size: 16px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: white !important;
    color: #6c5ce7 !important;
    border: none !important;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2) !important;
    transition: all 0.3s ease !important;
}

#share-modal-close:hover {
    transform: translateY(-3px) scale(1.05) !important;
    box-shadow: 0 15px 35px rgba(0,0,0,0.3) !important;
}

/* ─── Embed mode ─────────────────────────────────────────────────────────────── */

body.is-embedded {
    background: #f0f0f0;
    padding: 0;
    margin: 0;
    display: block;
}

.is-embedded .container {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    justify-content: center;
}

.is-embedded h1,
.is-embedded .subtitle,
.is-embedded .make-own-link { display: none !important; }

.is-embedded #flipbook-container {
    margin-top: 0;
}

.is-embedded .fb-scene {
    padding-top: 10px;
    padding-bottom: 60px;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
