/* Manga Reader Styles - Theme Aware */

.reader-container {
    background-color: var(--bg-primary);
    min-height: 100vh;
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.reader-header {
    background-color: var(--bg-secondary);
    padding: 1.5rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
    transition: all 0.3s ease;
    transform: translateY(0);
}

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

.reader-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.reader-title {
    flex: 1;
    min-width: 0;
    /* Allow text to truncate */
}

.reader-title h2 {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0 0 0.25rem 0;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reader-title h3 {
    font-size: 1rem;
    font-weight: 400;
    margin: 0;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reader-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-shrink: 0;
}

.page-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
    white-space: nowrap;
}

.reader-button {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    background-color: var(--bg-primary);
}

.reader-button:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-inverse);
}

/* Main Content */
/* .reader-content {
    padding: 2rem 0;
} */

.page-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 70vh;
    /* position: relative; */
}

.manga-page {
    max-width: 100%;
    max-height: 90vh;
    /* object-fit: contain; */
    cursor: pointer;
    /* transform-origin: 0 0; */
    border-radius: 8px;
    box-shadow: var(--shadow-medium);
}

/* .manga-page:hover {
    transform: scale(1.02);
} */

/* Navigation */
.reader-navigation {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    padding: 0.875rem 1.75rem;
    border-radius: 25px;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-medium);
    z-index: 1000;
    transition: all 0.3s ease;
}

.nav-button {
    background-color: transparent;
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
}

.nav-button:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.nav-button:disabled {
    border-color: var(--border-color);
    color: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.5;
}

.page-indicator {
    color: var(--text-secondary);
    font-size: 0.9rem;
    min-width: 80px;
    text-align: center;
}

/* Loading States */
.page-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.loading-spinner {
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-right: 1rem;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Error States */
.page-error {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    padding: 2rem;
    text-align: center;
}

.page-error-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--error-text, #e74c3c);
}

.page-error-message {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.retry-button {
    background-color: var(--accent-primary);
    color: var(--text-inverse);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.retry-button:hover {
    background-color: var(--accent-hover);
}

/* Keyboard Hints */
.keyboard-hints {
    position: fixed;
    top: 50%;
    right: 2rem;
    transform: translateY(-50%);
    background-color: var(--bg-secondary);
    padding: 1rem;
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.7;
    transition: opacity 0.3s;
    border: 1px solid var(--border-color);
}

.keyboard-hints:hover {
    opacity: 1;
}

.keyboard-hints h4 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.keyboard-hints ul {
    list-style: none;
    padding: 0;
}

.keyboard-hints li {
    margin-bottom: 0.25rem;
}

.key {
    background-color: var(--bg-tertiary);
    color: var(--text-inverse);
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.7rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .manga-page {
        max-height: 85vh;
    }

    .keyboard-hints {
        right: 1rem;
        font-size: 0.75rem;
    }

    .reader-navigation {
        padding: 0.75rem 1.75rem;
    }

    .reader-header {
        padding: 1rem 0;
    }

    .reader-title h2 {
        font-size: 1.1rem;
    }

    .reader-title h3 {
        font-size: 0.9rem;
    }

    .reader-controls {
        gap: 0.5rem;
    }

    .reader-button {
        padding: 0.4rem 0.8rem;
        font-size: 0.85rem;
    }
}

@media (max-width: 768px) {
    /* .reader-content {
        padding: 1rem 0.5rem;
    } */

    .reader-navigation {
        bottom: 1rem;
        padding: 0.4rem 0.75rem;
    }

    .page-indicator {
        font-size: 0.85rem;
        min-width: 70px;
    }

    .nav-button {
        width: 44px;
        height: 44px;
    }

    .keyboard-hints {
        display: none;
    }

    /* Mobile header layout */
    .reader-header {
        padding: 0.75rem 0;
    }

    .reader-nav {
        flex-direction: column;
        gap: 0.75rem;
        align-items: stretch;
    }

    .reader-title {
        text-align: center;
        order: 1;
    }

    .reader-title h2 {
        font-size: 1rem;
        margin-bottom: 0.125rem;
    }

    .reader-title h3 {
        font-size: 0.85rem;
    }

    .reader-controls {
        order: 2;
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .reader-button {
        padding: 0.375rem 0.75rem;
        font-size: 0.8rem;
        flex: 0 0 auto;
    }

    .page-info {
        font-size: 0.8rem;
        text-align: center;
        padding: 0.25rem 0.5rem;
        background-color: var(--bg-primary);
        border-radius: 12px;
        border: 1px solid var(--border-color);
    }
}


/* Zoom and Pan Styles */
/* .manga-page {
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
} */

.manga-page.zoomed {
    cursor: grab;
    transition: none;
}

.manga-page.zoomed:active {
    cursor: grabbing;
}

.manga-page.zoomed {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Vertical Scrolling Mode */
.reader-container.vertical-mode .page-container {
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 90vh;
    scroll-behavior: smooth;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.reader-container.vertical-mode .manga-page {
    max-width: 100%;
    width: auto;
    height: auto;
    max-height: none;
    cursor: default;
    margin-bottom: 10px;
}

.reader-container.vertical-mode .manga-page:hover {
    transform: none;
}

.vertical-pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 0 0 20px 0; /* Only bottom padding, no top padding */
    width: 100%;
    min-height: 100%;
}

.vertical-page {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: var(--shadow-medium);
}

.reader-navigation.vertical-nav {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    padding: 0.875rem 1.75rem;
    border-radius: 25px;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-medium);
}

.reader-navigation.vertical-nav .nav-button {
    background-color: transparent;
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
}

.reader-navigation.vertical-nav .nav-button:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Disable zoom and pan for vertical mode */
.reader-container.vertical-mode .manga-page {
    pointer-events: auto;
    touch-action: auto;
}

.reader-container.vertical-mode .page-container {
    touch-action: pan-y;
}

/* Immersive Mode */
.reader-container.immersive .reader-header,
.reader-container.immersive .keyboard-hints {
    display: none !important;
}

.reader-container.immersive {
    margin: 0 !important;
    padding: 0 !important;
    background: var(--bg-primary);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    overscroll-behavior: contain;
}

.reader-container.immersive .page-container {
    min-height: 100vh;
    padding: 0;
}

.reader-container.immersive .manga-page {
    max-height: 100vh;
    border-radius: 0;
    box-shadow: none;
}

/* Vertical mode immersive adjustments */
.reader-container.vertical-mode.immersive .page-container {
    max-height: 100vh;
}

.reader-container.vertical-mode.immersive .vertical-pages-container {
    padding: 0;
}

.reader-container.vertical-mode.immersive .vertical-page {
    border-radius: 0;
    box-shadow: none;
}

/* Touch Optimizations */
/* .touch-enabled .manga-page {
    touch-action: pan-x pan-y;
} */

.touch-enabled .nav-button {
    min-width: 40px;
    min-height: 40px;
}

/* Reader Error Styles */
.reader-error {
    text-align: center;
    padding: 2rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin: 2rem;
}

.reader-error h2 {
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.reader-error p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.reader-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    color: var(--text-secondary);
}

.reader-loading .loading-spinner {
    width: 50px;
    height: 50px;
    margin-bottom: 1rem;
}

/* Chapter Navigation Toast */
.chapter-nav-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 1rem 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow-medium);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
    border: 1px solid var(--border-color);
}

.chapter-nav-toast.show {
    opacity: 1;
}

/* Chapter Boundary Message */
.chapter-boundary-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 1rem 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow-medium);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
    border: 1px solid var(--border-color);
    text-align: center;
    max-width: 300px;
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Settings Popup Styles */
.settings-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    backdrop-filter: blur(2px);
    overflow: visible;
}

.settings-popup-overlay[style*="flex"] {
    opacity: 1;
    visibility: visible;
}

.settings-popup {
    background-color: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: var(--shadow-large, 0 10px 25px rgba(0, 0, 0, 0.3));
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

.settings-popup-overlay[style*="flex"] .settings-popup {
    transform: scale(1) translateY(0);
}

.settings-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1.5rem 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.settings-popup-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.settings-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.settings-close-btn:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.settings-popup-content {
    padding: 1.5rem;
    max-height: calc(90vh - 120px);
    overflow-y: auto;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting-group-buttons {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
}

.setting-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

.setting-label:hover {
    background-color: var(--bg-primary);
}

.setting-label.setting-disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.setting-label.setting-disabled:hover {
    background-color: transparent;
    cursor: not-allowed;
}

.setting-label.setting-disabled .setting-checkbox:disabled {
    cursor: not-allowed;
}

.setting-label.setting-disabled .setting-text {
    color: var(--text-secondary);
}

.setting-label-text {
    font-weight: 500;
    color: var(--text-primary);
    display: block;
}

.setting-checkbox,
.setting-radio {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

.setting-text {
    color: var(--text-primary);
    font-weight: 400;
    user-select: none;
}

.setting-description {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0;
    padding-left: 2rem;
    line-height: 1.4;
}

.setting-radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-left: 0.5rem;
}

.setting-radio-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

.setting-radio-label:hover {
    background-color: var(--bg-primary);
}

.setting-actions {
    /* border-top: 1px solid var(--border-color);
    padding-top: 1.5rem; */
    margin-top: 0.5rem;
}

.settings-reset-btn {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    align-self: flex-start;
}

.settings-reset-btn:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-inverse);
    border-color: var(--text-secondary);
}

/* Prevent body scroll when popup is open */
body.settings-popup-open {
    overflow: hidden;
}

/* Mobile responsive styles for settings popup */
@media (max-width: 768px) {
    .settings-popup {
        width: 95%;
        max-width: none;
        margin: 1rem;
        border-radius: 8px;
    }

    .settings-popup-header {
        padding: 1.25rem 1.25rem 0.75rem 1.25rem;
    }

    .settings-popup-header h3 {
        font-size: 1.1rem;
    }

    .settings-popup-content {
        padding: 1.25rem;
        max-height: calc(90vh - 100px);
    }

    .settings-form {
        gap: 1.25rem;
    }

    /* .setting-label,
    .setting-radio-label {
        padding: 0.75rem 0.5rem;
        gap: 1rem;
    } */

    .setting-checkbox,
    .setting-radio {
        width: 20px;
        height: 20px;
    }

    .setting-text {
        font-size: 1rem;
    }

    .setting-description {
        font-size: 0.85rem;
        padding-left: 2rem;
    }

    .settings-reset-btn {
        padding: 0.875rem 1.25rem;
        font-size: 0.95rem;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .settings-popup {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .settings-popup-content {
        max-height: calc(100vh - 80px);
        padding: 1rem;
    }

    .settings-popup-header {
        padding: 1rem;
    }

    /* Vertical mode mobile adjustments */
    .reader-container.vertical-mode .page-container {
        max-height: 90vh;
    }

    .reader-container.vertical-mode .vertical-pages-container {
        padding: 10px 0;
        gap: 5px;
    }

    .reader-navigation.vertical-nav {
        padding: 0.5rem 1rem;
        gap: 0.75rem;
    }

    .reader-navigation.vertical-nav .nav-button {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .reader-navigation.vertical-nav .page-indicator {
        font-size: 0.8rem;
        min-width: auto;
    }
}