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

body {
    background: #1a1a2e;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    overflow: hidden;
}

#viewer-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
}

#flipbook-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
    position: relative;
}

#flipbook {
    /* StPageFlip will manage sizing */
}

/* Floating navigation overlays (mobile) */
.nav-overlay {
    display: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    background: rgba(0,0,0,0.25);
    border: none;
    color: rgba(255,255,255,0.8);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}
.nav-overlay:active:not(:disabled) { background: rgba(0,0,0,0.5); }
.nav-overlay:disabled { opacity: 0.15; }
#nav-prev { left: 6px; }
#nav-next { right: 6px; }

/* Page images within StPageFlip */
.stf__parent {
    margin: 0 auto;
}

.stf__block {
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.3);
}

/* Attribution bar */
#attribution {
    text-align: center;
    padding: 5px 20px;
    font-size: 11px;
    color: rgba(255,255,255,0.35);
    background: rgba(0,0,0,0.4);
}

#attribution a {
    color: rgba(255,255,255,0.55);
    text-decoration: none;
}

#attribution a:hover {
    color: #fff;
    text-decoration: underline;
}

/* Controls bar */
#controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255,255,255,0.1);
}

#controls button {
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
}
#controls button:hover:not(:disabled) {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.4);
}
#controls button:disabled {
    opacity: 0.3;
    cursor: default;
}

#page-indicator {
    font-size: 13px;
    font-weight: 500;
    color: rgba(255,255,255,0.8);
    min-width: 70px;
    text-align: center;
    flex-shrink: 0;
}

.controls-spacer { flex: 0 0 4px; }

/* Page slider */
#page-slider-container {
    flex: 1;
    display: flex;
    align-items: center;
    min-width: 80px;
    padding: 0 4px;
}

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

#page-slider:hover {
    height: 6px;
}

#page-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
    transition: transform 0.15s;
}

#page-slider::-webkit-slider-thumb:hover {
    transform: scale(1.3);
}

#page-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* Share modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
}

.modal-content {
    position: relative;
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 28px;
    max-width: 520px;
    width: 90%;
}

.modal-content h3 {
    font-size: 18px;
    margin-bottom: 20px;
}

.modal-content .form-group {
    margin-bottom: 16px;
}

.modal-content label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: rgba(255,255,255,0.6);
    margin-bottom: 6px;
}

.share-page-option {
    margin-bottom: 18px !important;
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px !important;
    color: rgba(255,255,255,0.8) !important;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #6366f1;
}

.copy-field {
    display: flex;
    gap: 8px;
}

.copy-field input,
.copy-field textarea {
    flex: 1;
    padding: 8px 12px;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    color: #fff;
    font-family: 'SF Mono', monospace;
    font-size: 12px;
    outline: none;
}

.copy-field textarea { resize: none; }

.copy-field button {
    padding: 8px 14px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
}
.copy-field button:hover { background: rgba(255,255,255,0.2); }

.btn-close {
    display: block;
    width: 100%;
    padding: 10px;
    margin-top: 16px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
}
.btn-close:hover { background: rgba(255,255,255,0.15); }

.hidden { display: none !important; }

/* Search bar */
#search-bar {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 950;
}

#search-bar.hidden { display: none !important; }

#search-bar-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px;
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

#search-bar .search-icon {
    flex-shrink: 0;
    color: rgba(255,255,255,0.4);
}

#search-input {
    background: none;
    border: none;
    color: #fff;
    font-size: 14px;
    outline: none;
    width: 200px;
    font-family: inherit;
}

#search-input::placeholder {
    color: rgba(255,255,255,0.35);
}

#search-status {
    font-size: 12px;
    color: rgba(255,255,255,0.5);
    white-space: nowrap;
    min-width: 50px;
    text-align: center;
}

#search-bar button {
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

#search-bar button:hover:not(:disabled) {
    background: rgba(255,255,255,0.1);
}

#search-bar button:disabled {
    opacity: 0.3;
    cursor: default;
}

/* Grid overlay */
#grid-overlay {
    position: fixed;
    inset: 0;
    z-index: 900;
    background: #1a1a2e;
    display: flex;
    flex-direction: column;
}

#grid-overlay.hidden { display: none !important; }

#grid-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

#grid-header h3 {
    font-size: 16px;
    font-weight: 500;
}

#grid-header button {
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
#grid-header button:hover {
    background: rgba(255,255,255,0.1);
}

#grid-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    grid-auto-rows: max-content;
    gap: 16px;
}

.grid-page {
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color 0.2s, transform 0.15s;
    background: rgba(255,255,255,0.05);
}

.grid-page:hover {
    border-color: rgba(255,255,255,0.4);
    transform: scale(1.03);
}

.grid-page.active {
    border-color: #6366f1;
}

img.grid-page-img {
    width: 100%;
    height: auto;
    display: block;
    background: white;
}

.grid-page-num {
    text-align: center;
    padding: 6px;
    font-size: 12px;
    color: rgba(255,255,255,0.6);
}

/* Fullscreen adjustments */
:fullscreen #flipbook-container {
    padding: 5px;
}

:fullscreen #attribution {
    display: none;
}

/* iOS pseudo-fullscreen fallback */
.pseudo-fullscreen {
    position: fixed !important;
    inset: 0 !important;
    z-index: 9999 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
}
.pseudo-fullscreen #flipbook-container { padding: 5px; }
.pseudo-fullscreen #attribution { display: none; }
.pseudo-fullscreen #landscape-hint { display: none; }

/* Mobile responsive */
@media (max-width: 768px) {
    #flipbook-container { padding: 6px; }
    #attribution { font-size: 9px; padding: 3px 10px; }
    .nav-overlay { display: flex; }

    /* Disable 3D touch interaction — allow browser pinch-zoom */
    #flipbook, .stf__parent { touch-action: manipulation; }

    /* Two-row controls on mobile */
    #controls {
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px 10px;
    }
    #controls button {
        width: 40px;
        height: 40px;
        -webkit-tap-highlight-color: transparent;
    }
    #page-indicator { font-size: 12px; min-width: 60px; }

    /* Slider takes full width on its own row */
    #page-slider-container {
        order: 10;
        flex-basis: 100%;
        min-width: 0;
        padding: 2px 0 0;
    }
    #page-slider { height: 6px; }
    #page-slider::-webkit-slider-thumb { width: 20px; height: 20px; }
    #page-slider::-moz-range-thumb { width: 20px; height: 20px; }
    .controls-spacer { display: none; }

    /* Search bar mobile */
    #search-bar { top: 8px; width: 94%; left: 3%; transform: none; }
    #search-input { width: 100%; min-width: 0; flex: 1; font-size: 16px; }
    #search-bar-inner { padding: 8px 10px; gap: 6px; }

    /* Grid mobile */
    #grid-container {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
        padding: 10px;
    }
    #grid-header { padding: 12px 16px; }

    /* Modal mobile */
    .modal-content { padding: 20px; width: 95%; }
}

/* Landscape hint for portrait mobile */
@media (max-width: 768px) and (orientation: portrait) {
    #landscape-hint {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 6px 16px;
        background: rgba(99, 102, 241, 0.15);
        border-bottom: 1px solid rgba(99, 102, 241, 0.3);
        font-size: 12px;
        color: rgba(255,255,255,0.6);
        flex-shrink: 0;
    }
    #landscape-hint svg { flex-shrink: 0; }
}
@media (min-width: 769px), (orientation: landscape) {
    #landscape-hint { display: none; }
}
