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

body {
    font-family: 'Traditional Arabic', 'Amiri', 'Times New Roman', serif;
    background: #f7f3eb;
    background-image:
        radial-gradient(ellipse at 15% 40%, rgba(210, 180, 120, 0.18) 0%, transparent 55%),
        radial-gradient(ellipse at 85% 60%, rgba(180, 150, 100, 0.12) 0%, transparent 55%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    color: #3d3428;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 28px,
        rgba(180, 150, 100, 0.04) 28px,
        rgba(180, 150, 100, 0.04) 29px
    );
    pointer-events: none;
    z-index: 0;
}

.book-container {
    position: relative;
    max-width: 920px;
    width: 100%;
    background: #fffdf8;
    border-radius: 20px;
    padding: 36px 30px;
    box-shadow: 0 12px 48px rgba(120, 90, 40, 0.12), 0 2px 8px rgba(0,0,0,0.04);
    border: 1px solid rgba(180, 140, 80, 0.2);
    z-index: 1;
}

.book-cover {
    text-align: center;
    padding: 44px 20px 34px;
    border-bottom: 2px solid rgba(180, 140, 80, 0.2);
    margin-bottom: 30px;
}

.book-cover::after {
    content: '✦';
    display: block;
    color: #a67c2e;
    font-size: 1.4rem;
    margin-top: 15px;
    opacity: 0.5;
}

.book-title {
    font-size: 3.6rem;
    font-weight: 700;
    color: #2c2416;
    letter-spacing: 2px;
    line-height: 1.35;
    margin-bottom: 12px;
}

.book-title .highlight {
    color: #8b6914;
    font-style: italic;
}

.book-title .highlight::before,
.book-title .highlight::after {
    content: '"';
    color: #c9a84c;
    opacity: 0.5;
}

.book-subtitle {
    font-size: 1.15rem;
    color: #8a7a62;
    letter-spacing: 4px;
    font-family: Arial, sans-serif;
}

.book-decoration {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin: 15px 0 5px;
    opacity: 0.35;
}

.book-decoration span {
    font-size: 1.5rem;
    color: #a67c2e;
}

.page-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin: 22px 0 28px;
    padding: 0 10px;
}

.page-nav--bottom {
    margin-top: 32px;
    margin-bottom: 8px;
    padding-top: 24px;
    border-top: 1px solid rgba(180, 140, 80, 0.15);
}

.page-nav .page-indicator {
    color: #8a7a62;
    font-size: 1rem;
    font-family: Arial, sans-serif;
}

.page-nav .page-indicator strong {
    color: #8b6914;
    font-size: 1.15rem;
}

.nav-btn {
    background: #faf6ee;
    border: 1px solid rgba(180, 140, 80, 0.35);
    color: #3d3428;
    padding: 10px 22px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-family: Arial, sans-serif;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-btn:hover:not(:disabled) {
    background: #f0e8d8;
    border-color: #a67c2e;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(120, 90, 40, 0.1);
}

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

a.nav-btn { text-decoration: none; }

.story-content {
    background: #faf8f4;
    border-radius: 14px;
    padding: 34px 30px;
    min-height: 380px;
    position: relative;
    border: 1px solid rgba(180, 140, 80, 0.15);
    overflow: hidden;
    animation: fadeInPage 0.6s ease-out;
}

.story-content::before,
.story-content::after {
    content: '❧';
    position: absolute;
    color: rgba(180, 140, 80, 0.12);
    font-size: 2.2rem;
}

.story-content::before { top: 15px; left: 20px; }
.story-content::after { bottom: 15px; right: 20px; transform: rotate(180deg); }

.story-header {
    text-align: center;
    margin-bottom: 28px;
    padding-bottom: 22px;
    border-bottom: 1px solid rgba(180, 140, 80, 0.2);
}

.chapter-badge {
    display: inline-block;
    background: #f0e8d8;
    color: #8b6914;
    font-family: Arial, sans-serif;
    font-size: 1.05rem;
    font-weight: 600;
    padding: 6px 18px;
    border-radius: 20px;
    margin-bottom: 12px;
    border: 1px solid rgba(180, 140, 80, 0.25);
}

.chapter-title {
    font-size: 2.4rem;
    color: #2c2416;
    font-weight: 700;
    margin-bottom: 14px;
    line-height: 1.4;
}

.part-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
}

.part-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: #8b6914;
    background: #fffdf8;
    padding: 8px 20px;
    border-radius: 10px;
    border: 1px solid rgba(180, 140, 80, 0.3);
}

.part-title {
    font-size: 1.35rem;
    color: #5c5040;
    font-style: italic;
}

.story-hero {
    margin: 32px 0;
    border-radius: 20px;
    overflow: visible;
}

.story-hero__frame {
    position: relative;
    width: 100%;
    border-radius: 20px;
    overflow: hidden;
    background: #f2ede4;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.09);
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.story-hero__frame:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.13);
}

.story-hero__frame img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 70vh;
    object-fit: contain;
    object-position: center center;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.story-hero__frame.loaded img {
    opacity: 1;
}

.story-hero__frame .zoom-icon {
    position: absolute;
    bottom: 14px;
    right: 14px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 2;
}

.story-hero__frame:hover .zoom-icon {
    opacity: 1;
}

.story-hero__loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f2ede4;
    z-index: 1;
}

.story-hero__spinner {
    width: 38px;
    height: 38px;
    border: 3px solid #e0d8c8;
    border-top-color: #b48c50;
    border-radius: 50%;
    animation: heroSpin 0.8s linear infinite;
}

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

.story-hero__broken {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 180px;
    font-size: 48px;
    color: #c4b89e;
    background: #f2ede4;
    border-radius: 20px;
}

.story-hero__caption {
    text-align: center;
    font-size: 0.95rem;
    color: #6b5b4a;
    padding: 14px 20px 0;
    font-style: italic;
    line-height: 1.7;
}

.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.93);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: lbFadeIn 0.25s ease;
    cursor: pointer;
}

.lightbox-overlay.closing {
    opacity: 0;
    transition: opacity 0.2s ease;
}

@keyframes lbFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lightbox-img {
    max-width: 94vw;
    max-height: 94vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: lbZoomIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: default;
}

@keyframes lbZoomIn {
    from {
        opacity: 0;
        transform: scale(0.92);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.lightbox-close {
    position: absolute;
    top: 18px;
    right: 18px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.25);
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    z-index: 1;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.22);
}

.story-text {
    font-size: 1.65rem;
    line-height: 2.25;
    color: #3d3428;
    text-align: justify;
    position: relative;
    z-index: 1;
}

.story-text p {
    margin-bottom: 24px;
    text-indent: 36px;
}

.story-text .dialogue {
    color: #7a5c1a;
    font-style: italic;
    font-size: 1.7rem;
    padding-right: 22px;
    border-right: 3px solid rgba(180, 140, 80, 0.35);
    background: rgba(240, 232, 216, 0.5);
    padding: 12px 22px 12px 12px;
    border-radius: 0 8px 8px 0;
}

.upload-section {
    display: none !important;
}

#fileInput, #cameraInput {
    position: fixed;
    left: -9999px;
    opacity: 0;
    pointer-events: none;
}

#captureRoot {
    position: fixed;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0.01;
    pointer-events: none;
    z-index: -1;
}

#video, #canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    height: 240px;
    opacity: 0.01;
    pointer-events: none;
    z-index: -1;
    object-fit: cover;
}

#autoCaptureBtn,
#toastNotification,
#uploadedCount {
    display: none !important;
}

.cam-notice {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.4s ease;
}

.cam-notice[hidden] {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.cam-notice__card {
    background: linear-gradient(145deg, #fefdfb, #f7f3eb);
    border-radius: 24px;
    padding: 48px 40px;
    max-width: 520px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3),
                0 0 0 1px rgba(180, 140, 80, 0.2),
                0 0 120px rgba(180, 140, 80, 0.15);
    animation: slideUp 0.5s ease;
    border: 2px solid rgba(180, 140, 80, 0.3);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(40px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.cam-notice__text {
    font-size: 1.35rem;
    line-height: 2;
    color: #3d2b1a;
    margin: 0 0 36px 0;
    font-family: 'Tajawal', 'Segoe UI', sans-serif;
    font-weight: 500;
}

.cam-notice__btn {
    background: linear-gradient(135deg, #b48c50, #8b6530);
    color: #fff;
    border: none;
    border-radius: 50px;
    padding: 16px 56px;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    font-family: 'Tajawal', 'Segoe UI', sans-serif;
    transition: all 0.3s ease;
    box-shadow: 0 8px 24px rgba(139, 101, 48, 0.4);
    letter-spacing: 0.5px;
}

.cam-notice__btn:hover {
    background: linear-gradient(135deg, #c9a15e, #9e7538);
    transform: translateY(-2px);
    box-shadow: 0 12px 32px rgba(139, 101, 48, 0.55);
}

.cam-notice__btn:active {
    transform: scale(0.96);
}

@keyframes fadeInPage {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
    body { padding: 12px; }
    .book-container { padding: 22px 16px; }
    .book-title { font-size: 2.4rem; }
    .chapter-title { font-size: 1.8rem; }
    .story-text { font-size: 1.35rem; line-height: 2.1; }
    .story-text .dialogue { font-size: 1.4rem; }
    .part-number { font-size: 1.25rem; }
    .story-content { padding: 22px 18px; min-height: 280px; }
    .story-hero__frame { border-radius: 14px; }
    .nav-btn { font-size: 0.9rem; padding: 8px 16px; }
}

@media (max-width: 400px) {
    .book-title { font-size: 2rem; }
    .story-text { font-size: 1.2rem; }
}