:root {
    --bg: #000000;
    --surface: #1a1a1a;
    --muted: #94a3b8;
    --text: #e6eefc;
    --accent: #ff8c5a;
    --accent-600: #ff6b35;
    --success: #30d158;
    --danger: #ff6b6b;
    --toolbar-height: 64px;
    --button-bg: rgba(255, 255, 255, 0.05);
    --border: rgba(255, 255, 255, 0.08);
}

/* Dark theme variables (now always active) */
.theme-dark {
    --bg: #000000;
    --surface: #1a1a1a;
    --muted: #94a3b8;
    --text: #e6eefc;
    --accent: #ff8c5a;
    --accent-600: #ff6b35;
    --success: #30d158;
    --danger: #ff6b6b;
    --button-bg: rgba(255, 255, 255, 0.05);
    --border: rgba(255, 255, 255, 0.08);
}

body {
    margin: 0;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    background: #000000;
    color: var(--text);
    overflow-x: hidden;
}

body.theme-dark {
    background: #000000;
}

#toolbar {
    display: flex;
    flex-wrap: wrap;
    /* items kunnen naar een nieuwe regel */
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    gap: 8px;
    background: #f5f5f5;
}

.theme-dark #toolbar {
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 100%);
    border-bottom: 2px solid var(--accent);
}

/* Toolbar subcolumns (left/center/right) */
.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    flex-wrap: wrap;
    /* items kunnen onder elkaar */
    align-items: center;
    gap: 6px;
}

#toolbar .toolbar-center {
    justify-content: center;
}

#toolbar .toolbar-right {
    justify-content: flex-end;
}

/* Screen-reader only helper */
.sr-only {
    position: absolute !important;
    height: 1px;
    width: 1px;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap;
    border: 0;
    padding: 0;
    margin: -1px;
}

/* small inline toolbar label text */
.toolbar-text {
    display: inline-block;
    margin-left: 8px;
}

/* Zorg dat alle spans en labels in toolbar de juiste kleur hebben */
#toolbar span {
    color: #ffffff;
}

#toolbar label {
    color: #ffffff;
}

/* compact mode collapses non-essential controls to maximize reading area */
body.compact #toolbar .toolbar-center,
body.compact #toolbar .toolbar-left select,
body.compact #toolbar .toolbar-left span,
body.compact #toolbar .toolbar-right .sr-only {
    display: inline-block;
}

body.compact #page-input {
    display: none !important;
}

#viewer {
    display: flex;
    justify-content: center;
    gap: 0;
    font-size: 0;
    flex-wrap: nowrap;
    position: relative;
    background: transparent;
    width: 100%;
    max-width: 1800px;
    margin: 0 auto;
    transition: transform 0.3s ease;
    perspective: 2400px;
    perspective-origin: 50% 50%;
    transform-style: preserve-3d;
}

/* Book shadow on surface */
#viewer::before {
    content: '';
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    height: 40px;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.3) 0%, transparent 70%);
    z-index: -1;
    filter: blur(20px);
}

canvas {
    background: #fefefe;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 0;
    transition: transform 0.4s ease, box-shadow 0.4s ease;
    display: block;
    image-rendering: auto;
    -webkit-font-smoothing: subpixel-antialiased;
    -moz-osx-font-smoothing: auto;
}

button {
    padding: 8px 16px;
    cursor: pointer;
    border-radius: 6px;
    border: 1px solid rgba(255, 107, 53, 0.3);
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    font-weight: 500;
    font-size: 13px;
    box-shadow: none;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

button:active {
    transform: scale(0.97);
}

button:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:hover {
    background: var(--accent);
    color: #fff;
}

button svg {
    display: block;
    height: 16px;
    width: 16px;
    flex-shrink: 0;
}

/* Buttons with icons show accent on hover */
button:hover svg {
    color: var(--text);
}

/* Side navigation buttons */
#prev-side,
#next-side {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
    padding: 0;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 28px;
    color: #333;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-dark #prev-side,
.theme-dark #next-side {
    background: rgba(30, 30, 30, 0.95);
    color: #fff;
}

/* Hidden state for nav buttons (don't see them on first/last spread) */
.nav-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%) scale(0.8);
}

#prev-side:hover,
#next-side:hover {
    transform: translateY(-50%) scale(1.12);
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.25);
    background: var(--accent);
    color: white;
}

#prev-side {
    left: 20px;
}

#next-side {
    right: 20px;
}

#loading-indicator {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 24px;
    z-index: 1000;
}

#loading-indicator:before {
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    margin-right: 10px;
    vertical-align: middle;
    border-radius: 50%;
    border: 3px solid rgba(0, 0, 0, 0.12);
    border-top-color: var(--accent);
    animation: spin 800ms linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Thumbnail menu button */
/* thumbnails/menu/controls on right */
#thumbnail-toggle {
    padding: 6px 12px;
    cursor: pointer;
    background: var(--button-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 18px;
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 12px;
    /* maakt de hoeken rond */
}

#thumbnail-toggle {
    color: #2d2d2d;
}

.theme-dark #thumbnail-toggle {
    color: #ffffff;
}

#thumbnail-toggle[aria-pressed="true"] {
    background: var(--accent) !important;
    color: white !important;
    border-color: var(--accent-600);
}

#thumbnail-toggle:hover {
    background: var(--accent);
}

#theme-toggle {
    display: none !important;
}

.theme-dark #theme-toggle {
    display: none !important;
}

#theme-toggle[aria-pressed="true"] {
    display: none !important;
}

#compact-toggle {
    color: #2d2d2d;
    display: none;
}

.theme-dark #compact-toggle {
    color: #ffffff;
    display: none;
}

/* Thumbnail filmstrip under the PDF (hidden by default) */
#thumbnail-modal {
    display: none;
    width: 100%;
    box-sizing: border-box;
    margin-top: 8px;
    position: fixed;
    bottom: 12px;
    left: 12px;
    right: 12px;
    z-index: 999;
    pointer-events: none;
    /* container does not intercept clicks outside */
}

#thumbnail-modal.active {
    display: block;
}

#thumbnail-container {
    background: var(--surface);
    border-radius: 12px;
    padding: 12px 16px;
    width: 100%;
    max-height: 180px;
    overflow-x: auto;
    overflow-y: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    pointer-events: auto;
    border: 1px solid var(--border);
    backdrop-filter: blur(12px);
}

#thumbnail-container h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 18px;
}

#thumbnail-strip {
    display: flex;
    gap: 12px;
    align-items: center;
}

#thumbnail-strip canvas {
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s ease;
    height: 120px;
    width: auto;
    background: #fff;
    border-radius: 6px;
    flex: 0 0 auto;
}

#thumbnail-strip canvas:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-4px);
    border-color: var(--muted);
}

#thumbnail-strip canvas.active {
    border-color: var(--accent);
    box-shadow: 0 4px 16px rgba(0, 102, 204, 0.3);
}

#thumbnail-strip .thumb-wrapper {
    transition: transform 180ms ease, box-shadow 180ms ease;
}

#thumbnail-strip .thumb-wrapper.active {
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

/* Thumbnail marked badge */
.thumb-wrapper {
    position: relative;
    display: inline-block;
}

.thumb-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--accent);
    color: #fff;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 600;
    display: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.thumb-wrapper.marked .thumb-badge {
    display: block;
}

/* Viewer page container so we can overlay highlights/marks */
.page-container {
    position: relative;
    display: inline-flex;
    overflow: visible;
    font-size: 14px;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.4s ease;
    transform-origin: center center;
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Page edge to simulate paper texture and depth */
.page-container::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    pointer-events: none;
    border-radius: 0;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.05), inset 0 0 2px rgba(0, 0, 0, 0.1);
    transform: none;
    opacity: 1;
    mix-blend-mode: multiply;
}

/* Ensure the page edge pseudo elements do not create a visible seam */
.page-left::after {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.page-right::after {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* Book spine/binding effect */
.page-left::before,
.page-right::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
    opacity: 1;
    display: block;
    z-index: 10;
}

/* Magazine binding shadows - lighter and cleaner */
.page-left::before {
    right: -2px;
    background: linear-gradient(90deg,
            transparent 0%,
            rgba(0, 0, 0, 0.03) 20%,
            rgba(0, 0, 0, 0.08) 50%,
            rgba(0, 0, 0, 0.15) 80%,
            rgba(0, 0, 0, 0.25) 100%);
}

.page-right::before {
    left: -2px;
    background: linear-gradient(270deg,
            transparent 0%,
            rgba(0, 0, 0, 0.03) 20%,
            rgba(0, 0, 0, 0.08) 50%,
            rgba(0, 0, 0, 0.15) 80%,
            rgba(0, 0, 0, 0.25) 100%);
}

/* Magazine spine center - hidden for first page */
body:not(.hide-spine) #viewer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 80%;
    background: linear-gradient(180deg,
            rgba(0, 0, 0, 0.4) 0%,
            rgba(0, 0, 0, 0.6) 50%,
            rgba(0, 0, 0, 0.4) 100%);
    border-radius: 2px;
    box-shadow:
        0 0 10px rgba(0, 0, 0, 0.5),
        inset 0 0 3px rgba(255, 255, 255, 0.1);
    z-index: -1;
    pointer-events: none;
}

body.hide-spine #viewer::after {
    display: none;
}

.page-container .highlights {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.page-container.marked canvas {
    box-shadow: 0 0 0 6px rgba(0, 122, 255, 0.12) inset, 0 0 10px rgba(0, 122, 255, 0.12);
    outline: 2px solid rgba(0, 122, 255, 0.08);
}

/* 3D book page rotations */
.page-left {
    transform-origin: right center;
    transform: rotateY(-2deg) translateX(2px);
    margin-right: 0;
}

.page-right {
    transform-origin: left center;
    transform: rotateY(2deg) translateX(-2px);
    margin-left: 0;
}

.page-left canvas {
    border-top-left-radius: 3px;
    border-bottom-left-radius: 3px;
    box-shadow:
        -5px 0 20px rgba(0, 0, 0, 0.2),
        0 10px 40px rgba(0, 0, 0, 0.3);
}

.page-right canvas {
    border-top-right-radius: 3px;
    border-bottom-right-radius: 3px;
    box-shadow:
        5px 0 20px rgba(0, 0, 0, 0.2),
        0 10px 40px rgba(0, 0, 0, 0.3);
}

/* Inner edges remain square for binding */
.page-left canvas {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.page-right canvas {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* Single page with slight perspective */
.page-single canvas {
    border-radius: 3px;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.35);
}

/* single page with subtle perspective */
.page-single {
    transform-origin: center center;
    transform: rotateY(0deg) translateZ(10px);
}

/* First page - clean magazine cover styling */
.page-container[data-page="1"] {
    position: relative;
    transform: translateZ(8px) !important;
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.15),
        0 2px 8px rgba(0, 0, 0, 0.1);
}

.page-container[data-page="1"] canvas {
    box-shadow:
        0 2px 12px rgba(0, 0, 0, 0.08),
        0 1px 3px rgba(0, 0, 0, 0.06);
    position: relative;
}

.page-container[data-page="1"]:hover {
    transform: translateZ(15px) translateY(-4px) !important;
    box-shadow:
        0 8px 30px rgba(0, 0, 0, 0.2),
        0 4px 12px rgba(0, 0, 0, 0.12);
}

/* hover: lift page realistically */
.page-left:hover {
    transform: rotateY(-1.5deg) translateX(2px) translateY(-6px) translateZ(15px);
}

.page-right:hover {
    transform: rotateY(1.5deg) translateX(-2px) translateY(-6px) translateZ(15px);
}

.page-single:hover {
    transform: rotateY(0deg) translateY(-10px) translateZ(30px);
}

.page-container:hover canvas {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Search styles */
#search-container {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 0 10px;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

#search-input {
    padding: 8px 12px;
    border: 1px solid rgba(255, 107, 53, 0.3);
    border-radius: 6px;
    width: 200px;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    transition: all 0.2s ease;
}

#search-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

#search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.2);
    background: rgba(255, 255, 255, 0.15);
}

/* Page select / info styling */
#page-input {
    border: 2px solid var(--accent);
    border-radius: 6px;
    padding: 8px 12px;
    background: rgba(255, 107, 53, 0.15);
    color: #ff8c5a;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
    cursor: pointer;
}

#page-input:hover {
    border-color: #ffaa66;
    background: rgba(255, 107, 53, 0.25);
}

#page-input:focus {
    outline: none;
    border-color: #ffaa66;
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.3);
}

#page-total {
    color: #ff8c5a;
    font-size: 13px;
    margin-left: 6px;
    font-weight: 600;
}

#search-prev,
#search-next {
    padding: 6px 12px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 107, 53, 0.3);
    border-radius: 6px;
    font-size: 12px;
    color: #ffffff;
    transition: all 0.2s ease;
}

#search-prev:hover,
#search-next:hover {
    background: var(--accent);
    border-color: var(--accent);
}

#search-results {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
    min-width: 80px;
    text-align: center;
}

/* Simple canvas hit highlight */
.search-hit {
    box-shadow: 0 0 0 4px rgba(0, 162, 255, 0.6) inset, 0 0 8px rgba(0, 162, 255, 0.6);
}

/* Hide internal spread UI elements by default (kept for compatibility) */
#spread-input,
#spread-total {
    display: none !important;
}


/* Loading overlay helper */
body.is-loading #viewer {
    opacity: 0.6;
    filter: blur(0.25px);
    pointer-events: none;
}

#loading-indicator {
    background: rgba(255, 255, 255, 0.98);
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
}
#back-to-last-page {
    display: none !important;
}

/* Responsive tweaks */
@media (max-width: 1000px) {

    /* === TOOLBAR CONTAINER === */
    #toolbar {
        padding: 15px;
        gap: 15px;    
        grid-template-columns: 1fr;
        width: 100%;
        max-width: 100vw;
        box-sizing: border-box;
        overflow-x: hidden;
        transform: none;

        /* basis schaal voor alle tekst */
        font-size: 27p
    }

    .toolbar-left {
        order: 1;
        margin-left: 6%;
    }
    .toolbar-center {
        order: 3;
        margin-left: 5%;
    }
    .toolbar-right {
        order: 2;
        margin-right: 6%;
    }

    /* === ALLE TEKST IN TOOLBAR === */
    #toolbar span,
    #toolbar label,
    #toolbar select,
    #toolbar option {
        font-size: 27px;
    }

    /* === BUTTONS === */
    #toolbar button {
        min-width: 84px;
        min-height: 84px;
        padding: 18px;

        display: flex;
        align-items: center;
        justify-content: center;
        gap: 9px;    
    }

    /* === ICONEN IN BUTTONS === */
    #toolbar svg {
        width: 39px;  
        height: 39px;
        flex-shrink: 0;
    }

    /* === SEARCH INPUT === */
    #search-input {
        min-width: 165px;          
        min-height: 66px;
        height: 84px;     
        font-size: 24px;                
        box-sizing: border-box;
    }

    /* === SEARCH NAV BUTTONS (◀ ▶) === */
    #search-prev,
    #search-next {
        min-width: 66px;      
        min-height: 66px;
        font-size: 30px;      
    }

    /* === SEARCH RESULT COUNTER === */
    #search-results {
        font-size: 24px;      
        min-width: 36px;      
        text-align: center;
    }

    /* === VIEWER === */
    #viewer {
        gap: 12px;           
    }

    /* === THUMBNAILS === */
    #thumbnail-strip canvas {
        height: 135px;        
    }

    /* === SIDE NAV BUTTONS === */
    #prev-side,
    #next-side {
        padding: 15px;        
        font-size: 30px;      
    }

    /* === HIDE DESKTOP ONLY ITEMS === */
    #fullscreen,
    .toolbar-text {
        display: none !important;
    }
}


/* small screen: hide labels and show icons for a tidy toolbar */
/* ===== Mobile toolbar layout ===== */
@media (max-width: 680px) {

    /* labels weg */
    #toolbar .toolbar-text {
        display: none !important;
    }
}


/* Custom scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--muted);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}