/* ==========================================================================
   PRODUCTION WEBTOON & MANGA READER STYLESHEET (CSS3)
   Immersive Vertical Scroll & Paginated Manga Modes
   ========================================================================== */

:root {
    --reader-bg: #090d16;
    --reader-bg-light: #131b2e;
    --reader-card-bg: #1a233a;
    --reader-text: #f8fafc;
    --reader-text-muted: #94a3b8;
    --reader-border: #232f4e;
    --reader-input-bg: #0b1120;
    --reader-input-border: #232f4e;
    --reader-max-width: 800px;
}

body.reader-body {
    background-color: var(--reader-bg);
    color: var(--reader-text);
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* Background Color Themes */
body.theme-black {
    --reader-bg: #000000;
    --reader-bg-light: #0d0d12;
    --reader-card-bg: #14141a;
    --reader-text: #f8fafc;
    --reader-text-muted: #94a3b8;
    --reader-border: #22222b;
    --reader-input-bg: #050508;
    --reader-input-border: #252533;
}

body.theme-dark {
    --reader-bg: #090d16;
    --reader-bg-light: #131b2e;
    --reader-card-bg: #1a233a;
    --reader-text: #f8fafc;
    --reader-text-muted: #94a3b8;
    --reader-border: #232f4e;
    --reader-input-bg: #0b1120;
    --reader-input-border: #232f4e;
}

body.theme-sepia {
    --reader-bg: #fbf0d9;
    --reader-bg-light: #f3e5c8;
    --reader-card-bg: #ebd9b5;
    --reader-text: #433422;
    --reader-text-muted: #79664e;
    --reader-border: #dcbe94;
    --reader-input-bg: #faf2df;
    --reader-input-border: #cfb992;
}

body.theme-light {
    --reader-bg: #f8fafc;
    --reader-bg-light: #ffffff;
    --reader-card-bg: #ffffff;
    --reader-text: #0f172a;
    --reader-text-muted: #64748b;
    --reader-border: #e2e8f0;
    --reader-input-bg: #f8fafc;
    --reader-input-border: #cbd5e1;
}

/* --------------------------------------------------------------------------
   READER FIXED FLOATING HEADER & CONTROLS
   -------------------------------------------------------------------------- */
.reader-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    color: #ffffff;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.reader-header.header-hidden {
    transform: translateY(-100%);
}

.reader-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.reader-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.reader-back-btn:hover {
    background: var(--primary);
}

.reader-title-info {
    min-width: 0;
}

.reader-series-title {
    font-size: 14px;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.reader-episode-title {
    font-size: 12px;
    color: var(--primary);
    font-weight: 600;
}

.reader-header-center {
    display: flex;
    align-items: center;
    gap: 8px;
}

.reader-nav-select {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    outline: none;
    cursor: pointer;
    max-width: 200px;
}

.reader-nav-select option {
    background: #0f172a;
    color: #ffffff;
}

.reader-header-page-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: var(--radius-full);
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 700;
    color: #38bdf8;
    letter-spacing: 0.3px;
    font-family: inherit;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.reader-header-page-pill:hover {
    background: rgba(56, 189, 248, 0.15);
    border-color: rgba(56, 189, 248, 0.4);
}

.reader-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.reader-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.reader-icon-btn:hover, .reader-icon-btn.active {
    background: var(--primary);
    border-color: var(--primary);
}

/* Progress Indicator Bar */
.reader-progress-bar-container {
    position: fixed;
    top: 60px;
    left: 0;
    width: 100%;
    height: 3px;
    background: transparent;
    z-index: 1001;
}

.reader-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary);
    box-shadow: 0 0 8px rgba(234, 88, 12, 0.8);
    transition: width 0.1s ease-out;
}

/* --------------------------------------------------------------------------
   IMAGE DISPLAY & WEBTOON CANVAS
   -------------------------------------------------------------------------- */
.reader-stage-container {
    width: 100%;
    min-height: 100vh;
    padding-top: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* Vertical Webtoon Strip Mode */
.webtoon-scroll-canvas {
    width: 100%;
    max-width: var(--reader-max-width);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.webtoon-page-wrapper {
    width: 100%;
    max-width: 100%;
    display: flex;
    justify-content: center;
    position: relative;
    background: #000000;
    min-height: 280px;
    content-visibility: auto;
    contain-intrinsic-size: 100vw 500px;
}

.webtoon-img {
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: auto;
    object-fit: contain;
    display: block;
    pointer-events: none; /* Image protection */
    -webkit-touch-callout: none;
}

.webtoon-img-placeholder {
    width: 100%;
    min-height: 500px;
    background: #0d1322;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--reader-text-muted);
    font-size: 14px;
}

/* --------------------------------------------------------------------------
   PAGINATED MANGA MODE (SINGLE / DOUBLE SPREAD)
   -------------------------------------------------------------------------- */
.manga-paginated-canvas {
    display: none;
    width: 100%;
    max-width: 1000px;
    height: calc(100vh - 120px);
    align-items: center;
    justify-content: center;
    position: relative;
    margin: 20px auto;
}

.manga-paginated-canvas.active {
    display: flex;
}

.manga-slide-frame {
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.manga-slide-img {
    max-width: 100%;
    max-height: calc(100vh - 140px);
    object-fit: contain;
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    pointer-events: none;
}

/* Manga Page Click Zones */
.manga-click-zone {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 40%;
    z-index: 50;
    cursor: pointer;
}

.manga-zone-prev { left: 0; }
.manga-zone-next { right: 0; }

/* --------------------------------------------------------------------------
   READER BOTTOM CONTROLS & EPISODE FOOTER
   -------------------------------------------------------------------------- */
.reader-bottom-nav {
    width: 100%;
    max-width: var(--reader-max-width);
    margin: 30px auto 50px;
    padding: 0 20px;
}

.reader-nav-buttons-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--reader-bg-light);
    border: 1px solid var(--reader-border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    margin-bottom: 30px;
}

.reader-bottom-floating-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-full);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 900;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.reader-bottom-floating-bar.hidden {
    transform: translate(-50%, 100px);
    opacity: 0;
    pointer-events: none;
}

.floating-page-counter {
    font-size: 13px;
    font-weight: 700;
    color: #ffffff;
    padding: 0 6px;
}

/* --------------------------------------------------------------------------
   READER SETTINGS MODAL
   -------------------------------------------------------------------------- */
.reader-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.reader-modal-overlay.open {
    display: flex;
}

.reader-modal-card {
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 440px;
    padding: 28px;
    color: #ffffff;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

.reader-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    border-bottom: 1px solid #1e293b;
    padding-bottom: 12px;
}

.reader-modal-header h3 {
    font-size: 18px;
    font-weight: 800;
}

.reader-setting-group {
    margin-bottom: 20px;
}

.reader-setting-label {
    font-size: 13px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: block;
}

.reader-toggle-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.reader-toggle-btn {
    padding: 10px;
    background: #1e293b;
    border: 1px solid #334155;
    color: #cbd5e1;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: var(--transition);
}

.reader-toggle-btn.active, .reader-toggle-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.reader-theme-swatches {
    display: flex;
    gap: 10px;
}

.theme-swatch {
    flex: 1;
    height: 38px;
    border-radius: var(--radius-md);
    cursor: pointer;
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

.theme-swatch.active {
    border-color: var(--primary);
}

.theme-swatch.swatch-dark { background: #090d16; color: #ffffff; }
.theme-swatch.swatch-black { background: #000000; color: #ffffff; border: 1px solid #333; }
.theme-swatch.swatch-sepia { background: #fbf0d9; color: #433422; }
.theme-swatch.swatch-light { background: #ffffff; color: #0f172a; }

/* --------------------------------------------------------------------------
   COMMENTS & DISCUSSION SECTION FOR EPISODE
   -------------------------------------------------------------------------- */
.reader-comments-section {
    width: 100%;
    max-width: var(--reader-max-width);
    margin: 40px auto 80px;
    padding: 0 20px;
}

.comments-card {
    background: var(--reader-bg-light);
    border: 1px solid var(--reader-border);
    border-radius: var(--radius-lg);
    padding: 28px;
    color: var(--reader-text);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.comments-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--reader-border);
}

.comments-header h3 {
    color: var(--reader-text);
    font-size: 18px;
    font-weight: 800;
    margin: 0;
}

.comment-input-area {
    margin-bottom: 30px;
}

.comment-textarea {
    width: 100%;
    background: var(--reader-input-bg, var(--reader-bg));
    border: 1px solid var(--reader-input-border, var(--reader-border));
    border-radius: var(--radius-md);
    padding: 14px;
    color: var(--reader-text);
    font-size: 14px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
    transition: var(--transition);
    box-sizing: border-box;
}

.comment-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.18);
}

.comment-textarea::placeholder {
    color: var(--reader-text-muted);
    opacity: 0.75;
}

.comment-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
}

.comment-item {
    display: flex;
    gap: 14px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--reader-border);
    transition: background-color 0.15s ease;
}

.comment-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.comment-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.comment-content-block {
    flex: 1;
    min-width: 0;
}

.comment-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.comment-author {
    font-weight: 700;
    font-size: 14px;
    color: var(--reader-text);
}

.comment-time {
    font-size: 12px;
    color: var(--reader-text-muted);
}

.comment-text {
    font-size: 14px;
    line-height: 1.6;
    color: var(--reader-text);
    margin-bottom: 8px;
    word-break: break-word;
}

.comment-spoiler-box {
    background: rgba(234, 88, 12, 0.1);
    border: 1px dashed var(--primary);
    padding: 10px 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-bottom: 8px;
}

.comment-spoiler-content {
    display: none;
}

.comment-spoiler-box.revealed .comment-spoiler-content {
    display: block;
}

.comment-spoiler-box.revealed .comment-spoiler-warning {
    display: none;
}

.comment-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 12px;
    color: var(--reader-text-muted);
}

.comment-action-btn {
    background: none;
    border: none;
    color: var(--reader-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    padding: 0;
    transition: color 0.15s ease;
}

.comment-action-btn:hover {
    color: var(--primary);
}

.comment-action-btn.liked {
    color: var(--primary);
}

/* ==========================================================================
   MOBILE MEDIA QUERY OPTIMIZATIONS FOR READER VIEW
   Lighthouse Touch Targets (Min 44x44px/48x48px) & Intrinsic Sizing
   ========================================================================== */
@media (max-width: 768px) {
    /* Header layout & touch targets */
    .reader-header {
        height: 60px;
        padding: 0 14px;
    }

    .reader-header-left {
        gap: 12px;
    }

    .reader-back-btn {
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
    }

    .reader-series-title {
        font-size: 13.5px;
        max-width: 140px;
    }

    .reader-episode-title {
        font-size: 11.5px;
    }

    .reader-header-center {
        gap: 8px;
    }

    .reader-nav-select {
        min-height: 44px;
        font-size: 16px !important; /* 16px prevents iOS Safari auto-zoom penalty */
        padding: 8px 12px;
        max-width: 140px;
    }

    .reader-header-page-pill {
        min-height: 40px;
        padding: 6px 12px;
        font-size: 12px;
    }

    .reader-header-right {
        gap: 8px;
    }

    /* Enforce 44px x 44px minimum touch targets on all header buttons */
    .reader-icon-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        border-radius: var(--radius-md);
    }

    #readerRateBtn {
        min-height: 44px;
        min-width: 44px;
        padding: 0 12px;
    }

    /* Hide fullscreen toggle on mobile (not supported on iOS Safari and takes valuable touch space) */
    #fullscreenBtn {
        display: none;
    }

    /* Intrinsic image presentation & responsive container */
    .reader-stage-container {
        padding-top: 60px;
    }

    .webtoon-scroll-canvas {
        max-width: 100%;
        width: 100%;
    }

    .webtoon-page-wrapper {
        min-height: 280px;
        contain-intrinsic-size: 100vw 600px;
        background: #000000;
        position: relative;
    }

    .webtoon-img {
        width: 100%;
        max-width: 100%;
        height: auto;
        aspect-ratio: 2 / 3;
        object-fit: contain;
        display: block;
    }

    /* Paginated Manga mode touch targets */
    .manga-paginated-canvas {
        height: calc(100vh - 110px);
        margin: 10px auto;
    }

    .manga-slide-img {
        max-height: calc(100vh - 120px);
        aspect-ratio: 2 / 3;
        width: auto;
        height: auto;
    }

    .manga-click-zone {
        width: 50%;
    }

    /* Bottom Navigation & Rating Touch Targets */
    .reader-bottom-nav {
        margin: 20px auto 40px;
        padding: 0 14px;
    }

    #readerEndRatingCard {
        padding: 18px 16px;
        gap: 14px;
    }

    #readerEndStarsContainer {
        width: 100%;
        justify-content: space-around;
        gap: 8px;
    }

    .reader-star-btn {
        min-width: 48px;
        min-height: 48px;
        padding: 10px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .reader-nav-buttons-row {
        flex-direction: column;
        gap: 12px;
        padding: 16px;
    }

    .reader-nav-buttons-row a,
    .reader-nav-buttons-row button {
        width: 100%;
        min-height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 15px;
        font-weight: 700;
        box-sizing: border-box;
    }

    /* Floating bottom bar touch sizes */
    .reader-bottom-floating-bar {
        bottom: 16px;
        padding: 6px 14px;
        gap: 8px;
    }

    .reader-bottom-floating-bar .reader-icon-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    /* Comment Section touch targets & inputs */
    .comment-item {
        gap: 10px;
    }

    .comment-avatar {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }

    .comment-action-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 14px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .comment-textarea {
        font-size: 16px !important; /* Prevents auto-zoom in mobile Safari */
        min-height: 90px;
    }

    .comment-toolbar button {
        min-height: 44px;
        padding: 10px 18px;
        font-size: 14.5px;
    }

    /* Settings modal touch sizes */
    .reader-modal-card {
        padding: 20px 16px;
        max-width: 95%;
    }

    .reader-toggle-btn {
        min-height: 44px;
        font-size: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .reader-header {
        height: 58px;
        padding: 0 10px;
    }

    /* Keep at minimum 44px x 44px touch targets on narrow mobile */
    .reader-back-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    .reader-series-title {
        max-width: 110px;
        font-size: 12.5px;
    }

    .reader-nav-select {
        max-width: 120px;
        padding: 8px 10px;
        font-size: 16px !important;
        min-height: 44px;
    }

    .reader-icon-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    .reader-header-page-pill {
        display: none; /* Replaced by floating counter on ultra-compact mobile */
    }

    .webtoon-page-wrapper {
        min-height: 240px;
        contain-intrinsic-size: 100vw 500px;
    }

    .webtoon-img {
        aspect-ratio: 2 / 3;
        width: 100%;
        height: auto;
    }
}

