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

:root {
    color-scheme: light;
    --ink: #20242b;
    --muted: #626a73;
    --paper: #fffaf0;
    --panel: #ffffff;
    --line: #d8d0c2;
    --accent: #c7482d;
    --accent-strong: #a33322;
    --teal: #16737c;
    --shadow: 0 20px 55px rgba(32, 36, 43, 0.2);
}

html,
body {
    min-height: 100%;
}

body {
    min-width: 320px;
    background:
        linear-gradient(135deg, rgba(199, 72, 45, 0.13), transparent 32%),
        linear-gradient(225deg, rgba(22, 115, 124, 0.16), transparent 35%),
        #f5efe3;
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
}

button,
input {
    font: inherit;
}

.reader-shell {
    width: min(1180px, calc(100% - 32px));
    min-height: 100vh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 22px 0;
}

.reader-header,
.reader-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.kicker {
    margin-bottom: 4px;
    color: var(--teal);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1 {
    font-size: 2rem;
    line-height: 1.05;
    letter-spacing: 0;
}

.pdf-link,
.text-button,
.icon-button {
    border: 1px solid rgba(32, 36, 43, 0.14);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
    box-shadow: 0 8px 18px rgba(32, 36, 43, 0.08);
    cursor: pointer;
    transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.pdf-link,
.text-button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    font-size: 0.95rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.icon-button {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    font-size: 1.9rem;
    line-height: 1;
}

.pdf-link:hover,
.text-button:hover,
.icon-button:hover {
    background: var(--accent);
    color: #fff;
    transform: translateY(-1px);
}

.pdf-link:focus-visible,
.text-button:focus-visible,
.icon-button:focus-visible,
.page-slider:focus-visible {
    outline: 3px solid rgba(22, 115, 124, 0.34);
    outline-offset: 3px;
}

.text-button:disabled,
.icon-button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
    transform: none;
}

.reader-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 70vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow: auto;
    border: 1px solid rgba(32, 36, 43, 0.1);
    border-radius: 8px;
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.18)),
        repeating-linear-gradient(90deg, rgba(32, 36, 43, 0.03) 0 1px, transparent 1px 22px),
        var(--paper);
    box-shadow: var(--shadow);
    padding: 26px;
}

.book {
    position: relative;
    flex: 0 0 auto;
    margin: 0 auto;
    perspective: 1800px;
    opacity: 0;
    transition: opacity 220ms ease;
}

.book.is-ready {
    opacity: 1;
}

.native-viewer {
    width: 100%;
    height: 100%;
    min-height: 72vh;
    display: none;
    border: 0;
    border-radius: 6px;
    background: #fff;
}

.reader-stage.is-native {
    padding: 0;
    background: #fff;
}

.reader-stage.is-native .book,
.reader-stage.is-native .loader {
    display: none;
}

.reader-stage.is-native .native-viewer {
    display: block;
}

.loader {
    position: absolute;
    z-index: 3;
    width: min(360px, calc(100% - 40px));
    display: grid;
    gap: 12px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 16px 40px rgba(32, 36, 43, 0.14);
    color: var(--muted);
    text-align: center;
}

.loader.is-hidden {
    display: none;
}

.progress-track {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #e9dfcf;
}

.progress-track span {
    display: block;
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--teal), var(--accent));
    transition: width 180ms ease;
}

.reader-controls {
    flex-wrap: wrap;
    justify-content: center;
    padding: 0 4px;
}

.page-status {
    min-width: 78px;
    color: var(--muted);
    font-size: 0.95rem;
    font-weight: 700;
    text-align: center;
}

.page-slider {
    width: min(360px, 100%);
    accent-color: var(--accent-strong);
}

.pdf-page {
    position: absolute;
    inset: 0;
    display: block;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 18px 28px rgba(32, 36, 43, 0.2);
    transform-style: preserve-3d;
    backface-visibility: hidden;
}

.pdf-canvas,
.pdf-svg {
    width: 100%;
    height: 100%;
    display: block;
    background: #fff;
}

.pdf-page.turn-next {
    animation: turn-next 360ms ease-out both;
    transform-origin: left center;
}

.pdf-page.turn-prev {
    animation: turn-prev 360ms ease-out both;
    transform-origin: right center;
}

@keyframes turn-next {
    from {
        opacity: 0.55;
        transform: rotateY(-28deg) translateX(18px);
    }

    to {
        opacity: 1;
        transform: rotateY(0deg) translateX(0);
    }
}

@keyframes turn-prev {
    from {
        opacity: 0.55;
        transform: rotateY(28deg) translateX(-18px);
    }

    to {
        opacity: 1;
        transform: rotateY(0deg) translateX(0);
    }
}

@media (max-width: 760px) {
    .reader-shell {
        width: min(100% - 20px, 540px);
        gap: 12px;
        padding: 12px 0;
    }

    .reader-header {
        align-items: flex-start;
    }

    h1 {
        font-size: 1.45rem;
    }

    .reader-stage {
        min-height: 60vh;
        padding: 14px;
    }

    .pdf-link,
    .text-button {
        min-height: 40px;
        padding: 0 12px;
        font-size: 0.86rem;
    }

    .reader-controls {
        gap: 10px;
    }
}
