/* Magazine Viewer Styles */

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #1a1a1a;
    color: #fff;
}

/* Header */
.viewer-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
}

.back-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    text-decoration: none;
    border-radius: 50%;
    transition: background 0.2s;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.header-title {
    flex: 1;
    text-align: center;
    overflow: hidden;
}

.header-title h1 {
    font-size: 1rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-issue {
    font-size: 0.8rem;
    color: #888;
}

.fullscreen-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.fullscreen-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Main Viewer */
.viewer-main {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a1a;
}

/* Navigation Buttons */
.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 80px;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 10;
    transition: background 0.2s, opacity 0.2s;
}

.nav-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

.nav-prev {
    left: 0;
    border-radius: 0 8px 8px 0;
}

.nav-next {
    right: 0;
    border-radius: 8px 0 0 8px;
}

/* Page Container */
.page-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 70px;
}

/* Two-page spread (Desktop) */
.page-spread {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 100%;
}

.page-spread .page-wrapper {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-spread .page-left {
    justify-content: flex-end;
}

.page-spread .page-right {
    justify-content: flex-start;
}

.page-spread .page-image {
    max-height: 100%;
    width: auto;
    object-fit: contain;
    box-shadow: 0 5px 30px rgba(0, 0, 0, 0.5);
}

/* Single page (Mobile) */
.page-single {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
}

.page-single .page-wrapper {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-single .page-image {
    max-height: 100%;
    max-width: 100%;
    object-fit: contain;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

/* Page image common */
.page-image {
    cursor: zoom-in;
    user-select: none;
    -webkit-user-drag: none;
    transition: opacity 0.2s;
}

/* Loading Spinner */
.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    z-index: 5;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Footer Controls */
.viewer-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 72px;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
}

.page-indicator {
    font-size: 0.95rem;
    color: #fff;
    min-width: 60px;
}

.page-indicator .separator {
    margin: 0 4px;
    color: #666;
}

.page-slider-container {
    flex: 1;
    max-width: 400px;
    margin: 0 24px;
}

.page-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

.page-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s;
}

.page-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.page-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.footer-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 1.1rem;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Thumbnail Modal */
.thumbnail-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    overflow-y: auto;
}

.thumbnail-modal.active {
    opacity: 1;
    visibility: visible;
}

.thumbnail-header {
    position: sticky;
    top: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    z-index: 10;
}

.thumbnail-header h2 {
    font-size: 1.1rem;
    font-weight: 500;
}

.close-thumbnail {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.3rem;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.close-thumbnail:hover {
    background: rgba(255, 255, 255, 0.1);
}

.thumbnail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
    padding: 20px;
}

.thumbnail-item {
    position: relative;
    aspect-ratio: 3 / 4;
    background: #333;
    border: 2px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s;
}

.thumbnail-item:hover {
    transform: scale(1.03);
}

.thumbnail-item.active {
    border-color: #4a6741;
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-num {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 12px;
}

/* Zoom Modal */
.zoom-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.98);
    z-index: 300;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
    overflow: hidden;
}

.zoom-modal.active {
    opacity: 1;
    visibility: visible;
}

.zoom-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.zoom-modal img {
    max-width: none;
    max-height: none;
    cursor: grab;
    transition: transform 0.1s ease-out;
    user-select: none;
    -webkit-user-drag: none;
}

.zoom-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    color: #fff;
    font-size: 1.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.zoom-close:hover {
    background: rgba(0, 0, 0, 0.8);
}

.zoom-controls {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(0, 0, 0, 0.7);
    padding: 12px 20px;
    border-radius: 30px;
}

.zoom-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 1rem;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.zoom-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.zoom-level {
    font-size: 0.9rem;
    color: #fff;
    min-width: 50px;
    text-align: center;
}

/* Responsive - Tablet */
@media (max-width: 1023px) {
    .page-container {
        padding: 15px 60px;
    }
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    .viewer-header {
        height: 50px;
        padding: 0 12px;
    }

    .header-title h1 {
        font-size: 0.9rem;
    }

    .viewer-main {
        top: 50px;
        bottom: 64px;
    }

    .nav-btn {
        width: 36px;
        height: 60px;
        font-size: 1.2rem;
    }

    .page-container {
        padding: 10px 44px;
    }

    .viewer-footer {
        height: 64px;
        padding: 0 12px;
    }

    .page-slider-container {
        margin: 0 16px;
    }

    .thumbnail-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .nav-btn {
        width: 32px;
        height: 50px;
        font-size: 1rem;
        background: rgba(0, 0, 0, 0.3);
    }

    .page-container {
        padding: 8px 36px;
    }

    .thumbnail-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 12px;
    }
}

/* Hide elements in fullscreen */
:fullscreen .viewer-header,
:fullscreen .viewer-footer {
    opacity: 0;
    transition: opacity 0.3s;
}

:fullscreen .viewer-main {
    top: 0;
    bottom: 0;
}

:fullscreen:hover .viewer-header,
:fullscreen:hover .viewer-footer {
    opacity: 1;
}

:fullscreen .page-container {
    padding: 20px 70px;
}
