/* ============================================
   Manga Atlas - Chapter Reader Styles (Dark Theme)
   ============================================ */

:root {
    /* Color Palette - Dark Theme (Unified with home.css) */
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16213e;
    --bg-card-hover: #1f3460;

    /* Accent Colors */
    --accent-primary: #e94560;
    --accent-secondary: #0f3460;
    --accent-glow: rgba(233, 69, 96, 0.3);

    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #6b6b80;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body.reader-page {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* Top Navigation Bar */
.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(180deg, rgba(15, 15, 26, 0.98) 0%, rgba(15, 15, 26, 0) 100%);
    padding: 15px 25px;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: opacity 0.3s;
    backdrop-filter: blur(10px);
}

.top-nav.hidden {
    opacity: 0;
    pointer-events: none;
}

.nav-left a {
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    transition: var(--transition-fast);
}

.nav-left a:hover {
    background: var(--bg-card-hover);
    color: var(--accent-primary);
}

.nav-center {
    flex: 1;
    text-align: center;
}

.manga-title {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 400px;
    margin: 0 auto;
}

.chapter-info {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 3px;
}

.nav-right {
    display: flex;
    gap: 12px;
}

.nav-btn {
    background: var(--bg-card);
    border: none;
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition-fast);
    text-decoration: none;
}

.nav-btn:hover {
    background: var(--accent-primary);
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Reader Container */
.reader-container {
    max-width: 950px;
    margin: 0 auto;
    padding: 80px 0 120px;
}

/* Image Display */
.page-wrapper {
    position: relative;
    margin-bottom: 3px;
    background: var(--bg-secondary);
}

.page-image {
    display: block;
    width: 100%;
    height: auto;
    cursor: pointer;
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-card) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    min-height: 300px;
}

.page-image.loaded {
    animation: none;
    background: none;
    min-height: auto;
}

.page-image.error {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 1rem;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

.page-number {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.75);
    color: var(--text-primary);
    padding: 6px 14px;
    border-radius: var(--radius-lg);
    font-size: 0.8rem;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s;
    backdrop-filter: blur(5px);
}

.page-wrapper:hover .page-number {
    opacity: 1;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(0deg, rgba(15, 15, 26, 0.98) 0%, rgba(15, 15, 26, 0) 100%);
    padding: 35px 25px 25px;
    z-index: 1000;
    transition: opacity 0.3s;
    backdrop-filter: blur(10px);
}

.bottom-nav.hidden {
    opacity: 0;
    pointer-events: none;
}

.progress-bar {
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin-bottom: 18px;
    cursor: pointer;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary) 0%, #f06292 100%);
    border-radius: 3px;
    transition: width 0.1s;
}

.bottom-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 25px;
}

.chapter-nav-btn {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 12px 28px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition-fast);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.chapter-nav-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.chapter-nav-btn:disabled,
.chapter-nav-btn.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.page-indicator {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    min-width: 90px;
    text-align: center;
}

/* Scroll to Top Button */
.scroll-top {
    position: fixed;
    bottom: 110px;
    right: 25px;
    width: 50px;
    height: 50px;
    background: var(--accent-primary);
    border: none;
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 1.3rem;
    cursor: pointer;
    opacity: 0;
    transition: var(--transition-normal);
    z-index: 999;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.scroll-top.visible {
    opacity: 1;
}

.scroll-top:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 30px var(--accent-glow);
}

/* No Images State */
.no-images {
    text-align: center;
    padding: 120px 25px;
    color: var(--text-muted);
}

.no-images h2 {
    font-size: 1.5rem;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

/* Keyboard Hints */
.keyboard-hints {
    position: fixed;
    bottom: 110px;
    left: 25px;
    background: rgba(0, 0, 0, 0.85);
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 999;
    backdrop-filter: blur(5px);
}

.keyboard-hints.visible {
    opacity: 1;
}

.keyboard-hints kbd {
    background: var(--bg-card);
    padding: 3px 8px;
    border-radius: 4px;
    margin: 0 3px;
    font-family: inherit;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .nav-center {
        display: none;
    }

    .top-nav,
    .bottom-nav {
        padding-left: 15px;
        padding-right: 15px;
    }

    .manga-title {
        font-size: 0.9rem;
    }

    .reader-container {
        padding: 60px 0 100px;
    }

    .chapter-nav-btn {
        padding: 10px 18px;
        font-size: 0.85rem;
    }

    .keyboard-hints {
        display: none;
    }

    .scroll-top {
        width: 45px;
        height: 45px;
        bottom: 100px;
        right: 15px;
    }
}

/* ============================================
   Mobile-Specific Styles (Touch Optimized)
   ============================================ */

body.reader-page.is-mobile {
    /* Prevent pull-to-refresh interfering with scroll */
    overscroll-behavior-y: contain;

    /* Prevent text selection */
    -webkit-user-select: none;
    user-select: none;
}

/* Full-width images on mobile */
body.is-mobile .reader-container {
    max-width: 100%;
    padding: 50px 0 130px;
}

body.is-mobile .page-wrapper {
    margin-bottom: 1px;
}

body.is-mobile .page-image {
    width: 100%;
    display: block;
}

/* Larger touch targets for navigation */
body.is-mobile .chapter-nav-btn {
    min-height: 48px;
    padding: 14px 24px;
    font-size: 1rem;
}

body.is-mobile .chapter-nav-btn:active {
    background: var(--accent-primary);
    transform: scale(0.98);
}

/* Hide keyboard hints on mobile */
body.is-mobile .keyboard-hints {
    display: none !important;
}

/* Larger scroll-to-top button */
body.is-mobile .scroll-top {
    width: 56px;
    height: 56px;
    font-size: 1.5rem;
    bottom: 140px;
}

/* Progress bar easier to tap */
body.is-mobile .progress-bar {
    height: 8px;
    margin-bottom: 20px;
}

/* Tap zones visual feedback */
body.is-mobile .page-wrapper::before,
body.is-mobile .page-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 20%;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

body.is-mobile .page-wrapper::before {
    left: 0;
    background: linear-gradient(90deg, rgba(233, 69, 96, 0.1) 0%, transparent 100%);
}

body.is-mobile .page-wrapper::after {
    right: 0;
    background: linear-gradient(-90deg, rgba(233, 69, 96, 0.1) 0%, transparent 100%);
}

body.is-mobile .page-wrapper:active::before,
body.is-mobile .page-wrapper:active::after {
    opacity: 1;
}

/* Safe area support for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    body.reader-page.is-mobile .bottom-nav {
        padding-bottom: calc(25px + env(safe-area-inset-bottom));
    }

    body.reader-page.is-mobile .reader-container {
        padding-bottom: calc(130px + env(safe-area-inset-bottom));
    }
}

/* ============================================
   Swipe/Page Mode Styles
   ============================================ */

/* Mode Toggle Button */
.mode-toggle {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 6px;
}

.mode-toggle:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-primary);
}

.mode-toggle .mode-icon {
    font-size: 1.1rem;
}

/* Swipe Mode Container */
.reader-container.swipe-mode {
    max-width: 100%;
    height: calc(100vh - 130px);
    padding: 60px 0 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.reader-container.swipe-mode .page-wrapper {
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 70px;
    display: none;
    align-items: center;
    justify-content: center;
    margin-bottom: 0;
    background: var(--bg-primary);
}

.reader-container.swipe-mode .page-wrapper.active {
    display: flex;
}

.reader-container.swipe-mode .page-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    min-height: auto;
}

.reader-container.swipe-mode .page-image.loaded {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Page number always visible in swipe mode */
.reader-container.swipe-mode .page-number {
    opacity: 1;
    bottom: 20px;
    right: 20px;
    font-size: 0.9rem;
    padding: 8px 18px;
}

/* Tap Zones for Navigation */
.swipe-tap-zone {
    position: fixed;
    top: 60px;
    bottom: 70px;
    width: 25%;
    z-index: 50;
    cursor: pointer;
    display: none;
}

.swipe-mode-active .swipe-tap-zone {
    display: block;
}

.swipe-tap-zone.left {
    left: 0;
}

.swipe-tap-zone.right {
    right: 0;
}

.swipe-tap-zone:active {
    background: rgba(233, 69, 96, 0.1);
}

/* Swipe indicators */
.swipe-indicator {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    font-size: 2rem;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    z-index: 60;
}

.swipe-indicator.left {
    left: 15px;
}

.swipe-indicator.right {
    right: 15px;
}

.swipe-tap-zone:hover+.swipe-indicator,
.swipe-tap-zone:active+.swipe-indicator {
    opacity: 0.5;
}

/* End of chapter overlay */
.chapter-end-overlay {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 70px;
    background: rgba(15, 15, 26, 0.95);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    text-align: center;
    padding: 20px;
}

.chapter-end-overlay.visible {
    display: flex;
}

.chapter-end-overlay h3 {
    font-size: 1.5rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.chapter-end-overlay p {
    color: var(--text-muted);
    margin-bottom: 25px;
}

.chapter-end-overlay .nav-buttons {
    display: flex;
    gap: 15px;
}

.chapter-end-overlay .nav-btn {
    padding: 14px 28px;
    font-size: 1rem;
}

/* Mobile optimizations for swipe mode */
body.is-mobile .mode-toggle {
    padding: 10px 14px;
    min-height: 44px;
}

body.is-mobile .swipe-tap-zone {
    width: 30%;
}

body.is-mobile .reader-container.swipe-mode {
    height: calc(100vh - 110px);
}

body.is-mobile .reader-container.swipe-mode .page-wrapper {
    bottom: 50px;
}

/* Swipe animation classes */
.page-wrapper.slide-left {
    animation: slideLeft 0.3s ease forwards;
}

.page-wrapper.slide-right {
    animation: slideRight 0.3s ease forwards;
}

.page-wrapper.slide-in-left {
    animation: slideInLeft 0.3s ease forwards;
}

.page-wrapper.slide-in-right {
    animation: slideInRight 0.3s ease forwards;
}

@keyframes slideLeft {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(-100%);
        opacity: 0;
    }
}

@keyframes slideRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================
   Gesture Guide Overlay
   ============================================ */

.gesture-guide {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.gesture-guide.visible {
    opacity: 1;
    visibility: visible;
}

.gesture-guide-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
}

.gesture-guide-content {
    position: relative;
    background: linear-gradient(145deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    padding: 30px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: guideSlideIn 0.4s ease;
}

@keyframes guideSlideIn {
    from {
        transform: translateY(30px) scale(0.95);
        opacity: 0;
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.gesture-guide-header {
    text-align: center;
    margin-bottom: 25px;
}

.gesture-guide-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 10px;
    animation: gestureIconPulse 2s ease-in-out infinite;
}

@keyframes gestureIconPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

.gesture-guide-header h3 {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.gesture-guide-items {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 25px;
}

.gesture-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.gesture-item p {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.gesture-item p strong {
    color: var(--accent-primary);
}

.gesture-demo {
    width: 60px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(233, 69, 96, 0.1);
    flex-shrink: 0;
}

/* Swipe demo animation */
.swipe-demo {
    position: relative;
    overflow: hidden;
}

.swipe-demo .gesture-hand {
    font-size: 1.3rem;
    animation: swipeHand 2s ease-in-out infinite;
}

.swipe-demo .gesture-arrow {
    position: absolute;
    right: 8px;
    font-size: 1rem;
    color: var(--accent-primary);
    opacity: 0.7;
}

.swipe-demo.reverse .gesture-hand {
    animation: swipeHandReverse 2s ease-in-out infinite;
}

.swipe-demo.reverse .gesture-arrow {
    right: auto;
    left: 8px;
}

@keyframes swipeHand {

    0%,
    100% {
        transform: translateX(10px);
    }

    50% {
        transform: translateX(-10px);
    }
}

@keyframes swipeHandReverse {

    0%,
    100% {
        transform: translateX(-10px);
    }

    50% {
        transform: translateX(10px);
    }
}

/* Tap demo animation */
.tap-demo {
    display: flex;
    gap: 8px;
}

.tap-demo .tap-zone-left,
.tap-demo .tap-zone-right {
    width: 24px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    font-size: 0.8rem;
    color: var(--text-muted);
    animation: tapPulse 1.5s ease-in-out infinite;
}

.tap-demo .tap-zone-right {
    animation-delay: 0.75s;
}

@keyframes tapPulse {

    0%,
    100% {
        background: rgba(255, 255, 255, 0.1);
        transform: scale(1);
    }

    50% {
        background: rgba(233, 69, 96, 0.3);
        transform: scale(1.05);
    }
}

/* Keyboard demo */
.keyboard-demo kbd {
    background: var(--bg-secondary);
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-family: inherit;
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin: 0 2px;
}

.keyboard-item {
    display: none;
}

/* Show keyboard hint only on desktop */
@media (min-width: 769px) {
    .keyboard-item {
        display: flex;
    }
}

.gesture-guide-close {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--accent-primary) 0%, #f06292 100%);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.gesture-guide-close:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(233, 69, 96, 0.4);
}

.gesture-guide-close:active {
    transform: translateY(0);
}

.gesture-guide-remember {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 15px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.gesture-guide-remember input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

/* Mobile adjustments */
@media (max-width: 480px) {
    .gesture-guide-content {
        padding: 25px 20px;
    }

    .gesture-guide-header h3 {
        font-size: 1.2rem;
    }

    .gesture-item {
        padding: 10px;
    }

    .gesture-item p {
        font-size: 0.9rem;
    }
}

/* ============================================
   Reading Progress Toast Notification
   ============================================ */

.progress-toast {
    position: fixed;
    bottom: 130px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-lg);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 1500;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.progress-toast.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.toast-icon {
    font-size: 1.3rem;
}

.toast-text {
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 0 0 8px;
    line-height: 1;
    transition: color 0.2s;
}

.toast-close:hover {
    color: var(--accent-primary);
}

/* Mobile toast position */
@media (max-width: 768px) {
    .progress-toast {
        bottom: 120px;
        padding: 10px 16px;
    }

    .toast-text {
        font-size: 0.85rem;
    }
}