:root {
    --header-height: 82px;
    --controls-height: 76px;

    --page-ratio: 0.7070707;

    --background: #e8e8e8;
    --background-dark: #d8d8d8;
    --surface: #ffffff;
    --text: #202020;
    --muted: #666666;
    --border: rgba(0, 0, 0, 0.12);
    --shadow: rgba(0, 0, 0, 0.26);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

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

html {
    background: var(--background);
}

body {
    margin: 0;
    overflow: hidden;
    background:
        radial-gradient(
            circle at center,
            #f4f4f4 0,
            var(--background) 55%,
            var(--background-dark) 100%
        );
    color: var(--text);
    font-family:
        Arial,
        Helvetica,
        sans-serif;
}

button,
a {
    font: inherit;
}

button {
    color: inherit;
}

/*
|--------------------------------------------------------------------------
| Overall application
|--------------------------------------------------------------------------
*/

.brochure-app {
    display: grid;
    grid-template-rows:
        var(--header-height)
        minmax(0, 1fr)
        var(--controls-height);
    width: 100%;
    height: 100vh;
    height: 100dvh;
}

/*
|--------------------------------------------------------------------------
| Header
|--------------------------------------------------------------------------
*/

.brochure-header {
    position: relative;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding:
        env(safe-area-inset-top, 0)
        max(24px, env(safe-area-inset-right, 0))
        0
        max(24px, env(safe-area-inset-left, 0));
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.brand {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    text-decoration: none;
}

.brand img {
    display: block;
    width: auto;
    max-width: 190px;
    height: 54px;
    object-fit: contain;
    object-position: left center;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-width: 46px;
    min-height: 46px;
    padding: 0 14px;
    background: #ffffff;
    color: #222222;
    border: 1px solid var(--border);
    border-radius: 6px;
    text-decoration: none;
    cursor: pointer;
    transition:
        background-color 160ms ease,
        border-color 160ms ease,
        transform 160ms ease;
}

.control-button:hover {
    background: #f2f2f2;
    border-color: rgba(0, 0, 0, 0.25);
}

.control-button:active {
    transform: translateY(1px);
}

.control-button:focus-visible,
.page-button:focus-visible {
    outline: 3px solid rgba(0, 0, 0, 0.35);
    outline-offset: 3px;
}

.button-icon {
    font-size: 21px;
    line-height: 1;
}

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

/*
|--------------------------------------------------------------------------
| Main viewer
|--------------------------------------------------------------------------
*/

.viewer-area {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.book-stage {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px 72px;
    overflow: hidden;
}

.book {
    margin: auto;
    filter: drop-shadow(0 16px 22px var(--shadow));
}

/*
|--------------------------------------------------------------------------
| Individual generated pages
|--------------------------------------------------------------------------
*/

.page {
    position: relative;
    overflow: hidden;
    background: #ffffff;
}

.page canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #ffffff;
    object-fit: contain;
}

.page-cover {
    background: #ffffff;
}

.page-loading {
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 14px;
}

.page-number-marker {
    position: absolute;
    right: 10px;
    bottom: 8px;
    z-index: 2;
    display: none;
}

/*
|--------------------------------------------------------------------------
| Loading state
|--------------------------------------------------------------------------
*/

.loading-panel,
.error-panel {
    position: absolute;
    inset: 0;
    display: grid;
    align-content: center;
    justify-items: center;
    padding: 30px;
    text-align: center;
}

.loading-logo {
    display: block;
    width: min(220px, 55vw);
    height: auto;
    max-height: 100px;
    margin-bottom: 24px;
    object-fit: contain;
}

.loading-panel p {
    margin: 0 0 18px;
    color: var(--muted);
    font-size: 16px;
}

.progress-track {
    width: min(360px, 76vw);
    height: 5px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 999px;
}

.progress-bar {
    width: 0;
    height: 100%;
    background: #333333;
    border-radius: inherit;
    transition: width 180ms ease;
}

.error-panel h1 {
    margin: 0 0 12px;
    font-size: clamp(24px, 4vw, 38px);
}

.error-panel p {
    margin: 0 0 22px;
    color: var(--muted);
}

.error-panel a {
    display: inline-flex;
    min-height: 46px;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    background: #222222;
    color: #ffffff;
    border-radius: 5px;
    text-decoration: none;
}

/*
|--------------------------------------------------------------------------
| Bottom controls
|--------------------------------------------------------------------------
*/

.brochure-controls {
    position: relative;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 22px;
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.05);
}

.page-button {
    display: inline-grid;
    place-items: center;
    width: 48px;
    height: 48px;
    padding: 0;
    background: #ffffff;
    color: #202020;
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    transition:
        background-color 160ms ease,
        opacity 160ms ease,
        transform 160ms ease;
}

.page-button span {
    display: block;
    margin-top: -4px;
    font-family: Georgia, serif;
    font-size: 42px;
    line-height: 1;
}

.page-button:hover:not(:disabled) {
    background: #eeeeee;
}

.page-button:active:not(:disabled) {
    transform: scale(0.97);
}

.page-button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-status {
    min-width: 180px;
    color: #444444;
    font-size: 15px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/*
|--------------------------------------------------------------------------
| Fullscreen
|--------------------------------------------------------------------------
*/

:fullscreen .brochure-app {
    height: 100vh;
    height: 100dvh;
}

:fullscreen body {
    background: var(--background);
}

/*
|--------------------------------------------------------------------------
| Tablet and mobile
|--------------------------------------------------------------------------
*/

@media (max-width: 760px) {
    :root {
        --header-height: 68px;
        --controls-height: 68px;
    }

    .brochure-header {
        padding-right: 12px;
        padding-left: 12px;
    }

    .brand img {
        max-width: 145px;
        height: 44px;
    }

    .control-button {
        min-width: 42px;
        min-height: 42px;
        padding: 0 11px;
    }

    .control-button-text .button-label {
        display: none;
    }

    .book-stage {
        padding: 14px 12px;
    }

    .brochure-controls {
        gap: 15px;
    }

    .page-button {
        width: 44px;
        height: 44px;
    }

    .page-status {
        min-width: 130px;
        font-size: 14px;
    }
}

@media (max-width: 420px) {
    .brand img {
        max-width: 125px;
    }

    .header-actions {
        gap: 6px;
    }

    .book-stage {
        padding: 10px 6px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}