:root {
    --toolbar-height: 58px;
    --sidebar-width: 230px;

    --background: #202124;
    --toolbar-background: #ffffff;
    --toolbar-border: #d8d8d8;

    --button-background: #f4f4f4;
    --button-hover: #e6e6e6;
    --button-active: #d8d8d8;

    --text-color: #262626;
    --muted-color: #696969;
    --accent-color: #a21822;

    --focus-color: #1a73e8;
}

.viewer,
.viewer * {
    box-sizing: border-box;
}

.viewer button,
.viewer input {
    font: inherit;
}

.viewer button {
    color: inherit;
}

/*
 * Gesamter Viewer
 */

.viewer {
    position: relative;
    display: grid;
    grid-template-rows: var(--toolbar-height) minmax(0, 1fr);
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    color: var(--text-color);
}

/*
 * Toolbar
 */

.toolbar {
    position: relative;
    z-index: 100;

    display: flex;
    align-items: center;
    gap: 6px;

    min-width: 0;
    height: var(--toolbar-height);
    padding: 7px max(10px, env(safe-area-inset-right)) 7px max(10px, env(safe-area-inset-left));

    background: var(--toolbar-background);
    border-bottom: 1px solid var(--toolbar-border);
    box-shadow: 0 2px 8px rgb(0 0 0 / 15%);
}

.toolbar__group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.toolbar__separator {
    width: 1px;
    height: 28px;
    margin: 0 4px;
    background: var(--toolbar-border);
}

.toolbar__spacer {
    flex: 1 1 auto;
    min-width: 4px;
}

.toolbar__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-width: 40px;
    height: 40px;
    padding: 0 11px;

    border: 1px solid transparent;
    border-radius: 6px;
    background: var(--button-background);

    cursor: pointer;
    user-select: none;
}

.toolbar__button:hover:not(:disabled) {
    background: var(--button-hover);
}

.toolbar__button:active:not(:disabled) {
    background: var(--button-active);
}

.toolbar__button:disabled {
    opacity: 0.4;
    cursor: default;
}

.toolbar__button:focus-visible,
.page-number:focus-visible,
.thumbnail:focus-visible,
.pageflip-lightbox__close:focus-visible {
    outline: 3px solid rgb(26 115 232 / 35%);
    outline-offset: 1px;
    border-color: var(--focus-color);
}

.toolbar__button svg,
.pageflip-lightbox__close svg {
    width: 20px;
    height: 20px;
    pointer-events: none;
}

.toolbar__label {
    margin-left: 5px;
    white-space: nowrap;
}

/*
 * Seiteneingabe
 */

.page-control {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
}

.page-control__label {
    color: var(--muted-color);
    font-size: 14px;
}

.page-number {
    width: 68px;
    height: 40px;
    padding: 5px 7px;

    border: 1px solid #bcbcbc;
    border-radius: 6px;
    background: #ffffff;

    text-align: center;
    font-weight: 600;

    appearance: textfield;

    margin: 0;
}

.page-number::-webkit-outer-spin-button,
.page-number::-webkit-inner-spin-button {
    margin: 0;
    appearance: none;
}

.page-count {
    min-width: 42px;
    color: var(--muted-color);
    white-space: nowrap;
}

/*
 * Hauptbereich
 */

.viewer__body {
    display: flex;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

/*
 * Thumbnail-Seitenleiste
 */

.sidebar {
    position: relative;
    z-index: 50;

    flex: 0 0 var(--sidebar-width);
    width: var(--sidebar-width);
    min-width: 0;

    overflow: hidden;
    background: #f5f5f5;
    border-right: 1px solid var(--toolbar-border);

    transition: flex-basis 180ms ease,
    width 180ms ease,
    border-width 180ms ease;
}

.sidebar[hidden] {
    display: block;
    flex-basis: 0;
    width: 0;
    border-right-width: 0;
}

.sidebar__header {
    position: sticky;
    top: 0;
    z-index: 2;

    display: flex;
    align-items: center;
    justify-content: space-between;

    height: 48px;
    padding: 0 14px;

    background: #ffffff;
    border-bottom: 1px solid var(--toolbar-border);
}

.sidebar__title {
    margin: 0;
    font-size: 15px;
}

.thumbnail-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;

    height: calc(100% - 48px);
    padding: 12px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.thumbnail--cover {
    grid-column: 2;
}

.thumbnail {
    display: flex;
    flex-direction: column;
    gap: 5px;

    min-width: 0;
    padding: 5px;

    border: 2px solid transparent;
    border-radius: 6px;
    background: transparent;

    cursor: pointer;
}

.thumbnail:hover {
    background: #e8e8e8;
}

.thumbnail--active {
    border-color: var(--accent-color);
    background: #ffffff;
}

.thumbnail__image {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 210 / 297;

    object-fit: cover;
    background: #dddddd;
    box-shadow: 0 1px 5px rgb(0 0 0 / 20%);
}

.thumbnail__number {
    color: var(--muted-color);
    font-size: 12px;
    text-align: center;
}

/*
 * Buchbereich
 */

.book-area {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--background);
    isolation: isolate;

    cursor: default;
    touch-action: none;
}

.book-zoom {
    position: relative;

    width: 100%;
    height: 100%;
    overflow: visible;
    min-width: 0;
    min-height: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    transform-origin: center center;
    transition: none;
}

.book-zoom.is-zoomed {
    will-change: transform;
}

/*
 * StPageFlip braucht eine echte Messfläche.
 * Die Library setzt .stf__wrapper (im Bundle fälschlich .sft__) kaum selbst.
 */

#book.stf__parent,
.book-zoom .stf__parent {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    min-width: 0 !important;
    min-height: 0 !important;
    touch-action: none;
    transform: translateZ(0);
}

.book-zoom .stf__wrapper {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}

.book-zoom .stf__block {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    perspective: 2000px;
    background: var(--background);
    transform: translateZ(0);
}

/*
 * Chrome flasht sonst beim Wechsel von clip-path/Animation zurück
 * auf die statische Seite (cssText-Reset in StPageFlip).
 */
.book-zoom .stf__item,
.book-page {
    background: #ffffff;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.book-page img,
.book-zoom .stf__item img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    pointer-events: none;
    -webkit-user-drag: none;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/*
 * Höhere Spezifität als .stf__item, sonst bleibt die Hilfsseite
 * links neben dem Titel weiß sichtbar.
 */
.book-zoom .stf__item.book-page--blank,
.book-page.book-page--blank {
    box-shadow: none;
    background: var(--background);
    background-color: var(--background);
}

#zoomValue {
    min-width: 72px;
}

/*
 * Ladeanzeige
 */

.loading {
    position: absolute;
    inset: 0;
    z-index: 200;

    display: flex;
    align-items: center;
    justify-content: center;

    color: #ffffff;
    background: var(--background);
}

.loading[hidden] {
    display: none;
}

.loading__box {
    padding: 16px 22px;
    border-radius: 8px;
    background: rgb(0 0 0 / 45%);
}

/*
 * Kurze Statusmeldungen
 */

.status-message {
    position: absolute;
    left: 50%;
    bottom: 20px;
    z-index: 80;

    max-width: calc(100% - 40px);
    padding: 9px 14px;

    color: #ffffff;
    background: rgb(0 0 0 / 78%);
    border-radius: 6px;

    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 10px);

    transition: opacity 150ms ease,
    transform 150ms ease;
}

.status-message--visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/*
 * Vollbild
 */

.viewer:fullscreen {
    width: 100vw;
    height: 100vh !important;
    min-height: 0;
    background: var(--background);
}

.viewer:fullscreen .viewer__body,
.viewer:fullscreen .book-area,
.viewer:fullscreen .book-zoom {
    min-height: 0;
}

/*
 * Lightbox-Overlay (Startseite / Artikel)
 */

.pageflip-lightbox-on {
    overflow: hidden;
}

.pageflip-lightbox {
    position: fixed;
    inset: 0;
    z-index: 100001;
    display: none;
    background: #111111;
}

.pageflip-lightbox.is-open {
    display: block;
}

.pageflip-lightbox__overlay {
    position: absolute;
    inset: 0;
    background: rgb(0 0 0 / 55%);
}

.pageflip-lightbox__panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--background);
}

.pageflip-lightbox__panel .viewer {
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
}

.pageflip-lightbox__close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 120;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    width: 42px;
    height: 42px;
    padding: 0;

    border: 1px solid #555555;
    border-radius: 6px;
    background: #222222;
    color: #ffffff;

    cursor: pointer;
}

.pageflip-lightbox__close:hover {
    background: #333333;
}

.pageflip-trigger {
    cursor: pointer;
}

/*
 * Tablet
 */

@media (max-width: 900px) {
    .toolbar__label {
        display: none;
    }

    .toolbar__button {
        padding-inline: 9px;
    }

    .sidebar {
        position: absolute;
        inset: 0 auto 0 0;
        width: min(300px, 85vw);
        flex-basis: min(300px, 85vw);

        box-shadow: 5px 0 18px rgb(0 0 0 / 30%);
    }

    .sidebar[hidden] {
        width: 0;
        flex-basis: 0;
        box-shadow: none;
    }
}

/*
 * Smartphone
 */

@media (max-width: 620px) {
    :root {
        --toolbar-height: 54px;
    }

    .toolbar {
        gap: 4px;
        padding-inline: 6px;
    }

    .toolbar__separator,
    .toolbar__desktop-only,
    .page-control__label {
        display: none;
    }

    .toolbar__button {
        min-width: 38px;
        height: 38px;
        padding-inline: 7px;
    }

    .page-number {
        width: 52px;
        height: 38px;
    }

    .page-count {
        min-width: 32px;
        font-size: 14px;
    }

    .pageflip-lightbox__close {
        top: 8px;
        right: 8px;
        width: 38px;
        height: 38px;
    }
}

/*
 * Ausgabenmenü-Layout liegt in meraner-6.scss → app.css.
 * Hier nur der Mobile-Wrapper auf der Blätterseite.
 */
.blaettermenu-mobile-wrap {
    margin-bottom: 8px;
}

.blaettermenu .button {
    white-space: nowrap;
}

/*
 * Reduced-motion nur für den Buchbereich – nicht für .blaettermenu
 * (sonst stirbt die Cover-Zoom-Transition mit !important).
 */
@media (prefers-reduced-motion: reduce) {
    .viewer .book-area *,
    .viewer .book-area *::before,
    .viewer .book-area *::after,
    .viewer .book-zoom,
    .pageflip-lightbox .book-area *,
    .pageflip-lightbox .book-area *::before,
    .pageflip-lightbox .book-area *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

