:root {
    color-scheme: light;
    --ebook-bg: #e7eaee;
    --ebook-surface: #ffffff;
    --ebook-surface-muted: #f3f5f7;
    --ebook-text: #17212b;
    --ebook-text-muted: #4c5a67;
    --ebook-border: #667583;
    --ebook-accent: #001b4d;
    --ebook-accent-dark: #001b4d;
    --ebook-focus: #a63d00;
    --ebook-highlight: rgba(255, 224, 51, 0.28);
    --ebook-danger: #a32121;
    --ebook-shadow: 0 8px 28px rgba(25, 39, 52, 0.24);
}

* {
    box-sizing: border-box;
}

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

body {
    overflow: hidden;
    background: var(--ebook-bg);
    color: var(--ebook-text);
    font-family: Arial, "Microsoft JhengHei", sans-serif;
    line-height: 1.5;
}

button,
input,
select {
    color: inherit;
    font: inherit;
}

.ebook-main {
    min-height: 100vh;
    min-height: 100dvh;
    padding: 8px;
}

.ebook-viewer {
    position: relative;
    display: flex;
    height: calc(100vh - 16px);
    height: calc(100dvh - 16px);
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #53616e;
    border-radius: 8px;
    background: var(--ebook-surface-muted);
}
.ebook-main-content {
    display: flex;
    min-width: 0;
    min-height: 0;
    flex: 1 1 auto;
    overflow: hidden;
    position:relative;
}
    .ebook-main-content > .ebook-accesskey {
        position:absolute;
        font-size:12px;
        left:5px;
        top:12px;
        text-decoration:none;
    }
        .ebook-main-content > .ebook-accesskey:focus-visible {
            outline: 3px solid var(--ebook-focus);
            outline-offset: 3px;
        }
        .ebook-main-content .ebook-stage {
            flex: 1 1 auto;
            min-width: 0;
            min-height: 0;
        }
    .ebook-main-content:focus {
        outline: none;
    }

        .ebook-main-content:focus::after {
            position: absolute;
            z-index: 100;
            inset: 0;
            border: 3px solid var(--ebook-focus);
            content: "";
            pointer-events: none;
        }
.ebook-viewer:fullscreen {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
}

.ebook-header,
.ebook-toolbar,
.ebook-footer,
.ebook-panel-header,
.ebook-search__summary,
.ebook-footer__controls,
.ebook-toolbar__group,
.ebook-search__controls,
.ebook-search__paging {
    display: flex;
    align-items: center;
}

.ebook-header {
    flex: 0 0 auto;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 14px;
    border-bottom: 1px solid #9aa5af;
    background: var(--ebook-surface);
    position: relative;
}
    .ebook-header:focus {
        outline: none;
        box-shadow: inset 0 0 0 3px var(--ebook-focus);
    }
    .ebook-header > .ebook-accesskey {
        position: absolute;
        font-size: 12px;
        left: 5px;
        top: 12px;
        text-decoration: none;
    }
    .ebook-header > .ebook-accesskey:focus-visible {
        outline: 3px solid var(--ebook-focus);
        outline-offset: 3px;
    }
.ebook-header__brand,
.ebook-header__actions {
    display: flex;
    gap: 6px;
    min-width: 0;
    align-items: center;
}

.ebook-header__brand {
    flex: 0 0 auto;
    margin-left:16px;
}

.ebook-header__actions {
    flex: 0 0 auto;
    margin-left: auto;
    order: 2;
}

.ebook-home-logo {
    display: block;
    width: 250px;
    max-width: 100%;
    flex: 0 1 auto;
    border-radius: 3px;
}

    .ebook-home-logo img {
        display: block;
        width: 100%;
        height: auto;
        max-height: 38px;
        object-fit: contain;
        object-position: left center;
    }

.ebook-home-logo:focus-visible {
    outline: 3px solid var(--ebook-focus);
    outline-offset: 3px;
}

.ebook-eyebrow {
    margin: 0;
    color: var(--ebook-accent-dark);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.ebook-title {
    margin: 0;
    font-size: clamp(1rem, 2vw, 1.35rem);
    line-height: 1.25;
}

.ebook-toolbar {
    z-index: 5;
    flex: 0 0 auto;
    flex-basis: 100%;
    order: 3;
    justify-content: space-between;
    gap: .5rem;
    padding: 7px 10px;
    border-bottom: 1px solid #9aa5af;
    background: #f9fafb;
}

@media (min-width: 1500px) {
    .ebook-header {
        flex-wrap: nowrap;
        gap: .5rem;
        padding: 5px 8px;
    }

    .ebook-toolbar {
        order: 2;
        flex: 1 1 auto;
        flex-basis: auto;
        min-width: 0;
        flex-wrap: nowrap;
        gap: .35rem;
        padding: 4px 0;
        border-bottom: 0;
        background: transparent;
    }

    .ebook-toolbar__group {
        gap: .3rem;
    }

    .ebook-header__actions {
        order: 3;
        margin-left: 0;
    }
}

@media (min-width: 1024px) and (max-width: 1499px) {
    .ebook-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        column-gap: 8px;
        row-gap: 5px;
        padding: 5px 8px;
    }

    .ebook-header__brand {
        grid-column: 1;
        grid-row: 1;
    }

    .ebook-header__actions {
        grid-column: 2;
        grid-row: 1;
        margin-left: 0;
    }

    .ebook-toolbar {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
        min-width: 0;
        flex-basis: auto;
        flex-wrap: nowrap;
        gap: .35rem;
        padding: 4px 0;
        border-bottom: 0;
        background: transparent;
    }

    .ebook-toolbar__group {
        flex: 0 0 auto;
        gap: .3rem;
    }

    .ebook-toolbar__button {
        white-space: nowrap;
    }
}

.ebook-toolbar__group,
.ebook-search__controls,
.ebook-search__paging {
    gap: 6px;
}

.ebook-toolbar__group {
    flex: 0 0 auto;
}

.ebook-toolbar__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .3rem;
    font-size: 1rem;
    padding: .25rem .55rem;
}

.ebook-button {
    min-width: 40px;
    min-height: 34px;
    padding: .25rem .55rem;
    border: 1px solid #001b4d;
    border-radius: 5px;
    background: #fff;
    color: #001b4d;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.ebook-button:hover:not(:disabled):not([aria-disabled="true"]) {
    background: #001b4d;
    color: #fff;
}

.ebook-button--secondary {
    border-color: #001b4d;
    background: #fff;
    color: #001b4d;
}

.ebook-button--secondary:hover:not(:disabled):not([aria-disabled="true"]) {
    background: #001b4d;
    color: #fff;
}

.ebook-button:disabled,
.ebook-button[aria-disabled="true"] {
    border-color: #8e99a3;
    background: #eef0f3;
    color: #68727b;
    opacity: .78;
    cursor: not-allowed;
}

.ebook-button:focus-visible,
.ebook-viewer input:focus-visible,
.ebook-viewer select:focus-visible,
.ebook-stage__scroll:focus-visible,
.ebook-thumbnail:focus-visible,
.ebook-search-result:focus-visible {
    outline: 3px solid var(--ebook-focus);
    outline-offset: 2px;
    box-shadow: 0 0 0 2px #fff, 0 0 0 5px var(--ebook-focus);
}

.ebook-page-input,
.ebook-mode {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.ebook-page-input input {
    width: 4rem;
}

.ebook-viewer input,
.ebook-viewer select {
    min-height: 34px;
    border: 1px solid var(--ebook-border);
    border-radius: 4px;
    background: #fff;
    padding: 5px 7px;
}

.ebook-page-total,
.ebook-zoom-value {
    min-width: 52px;
    text-align: center;
    font-weight: 700;
}

.ebook-stage {
    display: flex;
    min-height: 0;
    flex: 1 1 auto;
    overflow: hidden;
    background: #56616b;
}

.ebook-stage__scroll {
    display: flex;
    width: 100%;
    min-width: 0;
    min-height: 0;
    align-items: flex-start;
    justify-content: flex-start;
    overflow: hidden;
    overscroll-behavior: contain;
    padding: 14px;
    touch-action: pan-x pan-y;
}

.ebook-viewer--flipping:not(.ebook-viewer--zoomed) .ebook-stage__scroll {
    overflow: hidden;
}

.ebook-book-gesture {
    position: relative;
    display: flex;
    flex: 0 0 auto;
    margin-inline: auto;
    transform-origin: center center;
    cursor: grab;
    touch-action: pan-y;
    user-select: none;
    isolation: isolate;
}

.ebook-viewer--zoomed .ebook-book-gesture,
.ebook-viewer:fullscreen .ebook-book-gesture {
    touch-action: none;
}

.ebook-viewer--interacting .ebook-book-gesture {
    cursor: grabbing;
}

.ebook-book {
    z-index: 1;
    position: relative;
    display: block;
    flex: 0 0 auto;
    align-items: stretch;
    justify-content: center;
    overflow: hidden;
    border-radius: 3px;
    background: #f8f6ef;
    box-shadow: var(--ebook-shadow);
    transform-origin: center center;
}

.ebook-page {
    position: relative;
    min-width: 0;
    height: 100%;
    overflow: hidden;
    background: #fff;
}

.ebook-page + .ebook-page {
    border-left: 0;
}

.stf__wrapper.--landscape .ebook-page[data-density="soft"].--left {
    box-shadow: none;
}

.stf__wrapper.--landscape .ebook-page[data-density="soft"].--right {
    box-shadow: none;
}

/* The page image is stacked above the page box in the StPageFlip renderer.
   Draw the same soft inner-edge effect above that image, without blocking input. */
.stf__wrapper.--landscape .ebook-page[data-density="soft"].--left::after,
.stf__wrapper.--landscape .ebook-page[data-density="soft"].--right::after {
    position: absolute;
    z-index: 2;
    top: 0;
    bottom: 0;
    width: 24px;
    content: "";
    pointer-events: none;
}

.stf__wrapper.--landscape .ebook-page[data-density="soft"].--left::after {
    right: 0;
    background: linear-gradient(to left, rgba(0, 0, 0, .10), rgba(0, 0, 0, .04) 38%, transparent);
}

.stf__wrapper.--landscape .ebook-page[data-density="soft"].--right::after {
    left: 0;
    background: linear-gradient(to right, rgba(0, 0, 0, .10), rgba(0, 0, 0, .04) 38%, transparent);
}

.ebook-page__image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0;
    transition: opacity 140ms ease;
    user-select: none;
    -webkit-user-drag: none;
}

.ebook-page--loaded .ebook-page__image {
    opacity: 1;
}

.ebook-page__loading,
.ebook-page__error {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    padding: 18px;
    background: #f4f5f6;
    color: var(--ebook-text-muted);
    text-align: center;
}

.ebook-page__loading::before {
    width: 34px;
    height: 34px;
    border: 4px solid #bbc4cc;
    border-top-color: var(--ebook-accent);
    border-radius: 50%;
    content: "";
    animation: ebook-spin 800ms linear infinite;
}

.ebook-page--loaded .ebook-page__loading,
.ebook-page--loaded .ebook-page__error,
.ebook-page--error .ebook-page__loading,
.ebook-page__error {
    display: none;
}

.ebook-page--error .ebook-page__error {
    display: flex;
    color: var(--ebook-danger);
}

.ebook-text-layer,
.ebook-highlight-layer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.ebook-text-item {
    position: absolute;
    color: transparent;
    line-height: 1;
    transform-origin: 0 0;
    white-space: pre;
}

.ebook-highlight {
    position: absolute;
    border: 0;
    outline: none;
    box-shadow: none;
    border-radius: 3px;
    background: var(--ebook-highlight);
}

.ebook-highlight--current {
    border: 0;
    background: rgba(255, 186, 0, 0.36);
}

.ebook-footer {
    flex: 0 0 auto;
    justify-content: space-between;
    gap: 12px;
    min-height: 48px;
    padding: 5px 10px;
    border-top: 1px solid #9aa5af;
    background: var(--ebook-surface);
}

.ebook-status {
    color: var(--ebook-text-muted);
    font-size: 0.94rem;
}

.ebook-status--error {
    color: var(--ebook-danger);
    font-weight: 700;
}

.ebook-book-error {
    align-self: center;
    margin: auto;
    padding: 20px;
    color: var(--ebook-danger);
    font-weight: 700;
    text-align: center;
}

.ebook-footer__controls {
    gap: 10px;
    white-space: nowrap;
}

.ebook-search,
.ebook-thumbnails {
    position: absolute;
    z-index: 20;
    overflow: auto;
    border: 1px solid #44515d;
    border-radius: 6px;
    background: #fff;
    box-shadow: var(--ebook-shadow);
}

.ebook-search {
    top: 112px;
    right: 12px;
    width: min(520px, calc(100% - 24px));
    max-height: calc(100% - 172px);
    padding: 14px;
}

.ebook-search[hidden] {
    display: none !important;
}

.ebook-search-backdrop {
    display: none;
}

.ebook-search-backdrop[hidden] {
    display: none !important;
}

.ebook-search__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex: 0 0 auto;
    margin: -2px 0 8px;
}

.ebook-search__header h2 {
    margin: 0;
    font-size: 1rem;
}

.ebook-search__header .ebook-button {
    min-width: 40px;
    padding: 4px 10px;
    font-size: 1.25rem;
    line-height: 1;
}

.ebook-search__form label {
    display: block;
    margin-bottom: 5px;
    font-weight: 700;
}

.ebook-search__controls input {
    min-width: 120px;
    flex: 1 1 auto;
}

.ebook-search__summary {
    justify-content: space-between;
    gap: 12px;
    margin: 10px 0;
    border-top: 1px solid #c0c7ce;
    border-bottom: 1px solid #c0c7ce;
    padding: 8px 0;
}

.ebook-search__summary p {
    margin: 0;
}

.ebook-search-results {
    max-height: 300px;
    overflow: auto;
}

.ebook-search-results {
    overscroll-behavior: contain;
}

.ebook-search-results__list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.ebook-search-result {
    display: block;
    width: 100%;
    border: 0;
    border-bottom: 1px solid #d4d9de;
    background: #fff;
    padding: 9px 7px;
    color: var(--ebook-text);
    text-align: left;
    cursor: pointer;
}

.ebook-search-result:hover,
.ebook-search-result[aria-current="true"] {
    background: #e4f1fb;
}

.ebook-search-result[aria-current="true"]::before {
    color: var(--ebook-accent-dark);
    content: "目前結果 · ";
    font-weight: 700;
}

.ebook-thumbnails {
    inset: 112px auto 56px 12px;
    width: min(410px, calc(100% - 24px));
    padding: 12px;
}

.ebook-panel-header {
    position: sticky;
    z-index: 2;
    top: 0;
    justify-content: space-between;
    gap: 12px;
    margin: -12px -12px 10px;
    border-bottom: 1px solid #9aa5af;
    background: #fff;
    padding: 10px 12px;
}

.ebook-panel-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.ebook-thumbnails__list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.ebook-thumbnail {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 4px;
    border: 2px solid transparent;
    border-radius: 4px;
    background: #eef1f4;
    padding: 5px;
    color: var(--ebook-text);
    cursor: pointer;
}

.ebook-thumbnail:hover,
.ebook-thumbnail[aria-current="page"] {
    border-color: var(--ebook-accent);
}

.ebook-thumbnail[aria-current="page"]::after {
    content: "目前頁面";
    font-size: 0.78rem;
    font-weight: 700;
}

.ebook-thumbnail img {
    width: 100%;
    height: auto;
    aspect-ratio: 200 / 274;
    background: #d5dbe0;
    object-fit: contain;
}

.ebook-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    margin: -1px;
    border: 0;
    padding: 0;
    white-space: nowrap;
}

@keyframes ebook-spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 1180px) {
    .ebook-toolbar {
        flex-wrap: wrap;
        justify-content: flex-start;
        border-bottom: 0;
    }

    .ebook-search,
    .ebook-thumbnails {
        top: 154px;
    }
}

@media (min-width: 1024px) and (max-width: 1199px) {
    .ebook-toolbar {
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: .25rem;
        padding: 4px 6px;
    }

    .ebook-toolbar__group {
        gap: .25rem;
    }

    .ebook-toolbar__button {
        min-height: 32px;
        padding-inline: .45rem;
    }

    .ebook-page-input > span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .ebook-page-input input {
        width: 3.5rem;
    }

    .ebook-page-total,
    .ebook-zoom-value {
        min-width: 2.75rem;
    }

    #ebookZoomReset .ebook-button__text {
        font-size: 0;
    }

    #ebookZoomReset .ebook-button__text::after {
        content: "重設";
        font-size: 1rem;
    }

    #ebookThumbnailsToggle .ebook-button__text,
    #ebookSearchToggle .ebook-button__text {
        display: none;
    }

    .ebook-toolbar__group:last-child {
        margin-left: auto;
    }
}

@media (max-width: 1023px) {
    .ebook-main {
        padding: 0;
    }

    .ebook-viewer {
        height: 100vh;
        height: 100dvh;
        border: 0;
        border-radius: 0;
    }

    .ebook-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-rows: auto auto;
        align-items: center;
        column-gap: 8px;
        row-gap: 5px;
        padding: 6px 9px;
    }
        .ebook-header > .ebook-accesskey {
           display:none;
        }
    .ebook-header__brand {
        grid-column: 1;
        grid-row: 1;
        min-width: 0;
        overflow: hidden;
        margin-left:0;
    }

    .ebook-header__actions {
        grid-column: 2;
        grid-row: 1;
        margin-left: 0;
        min-width: max-content;
        flex-wrap: nowrap;
        white-space: nowrap;
    }
    .ebook-main-content > .ebook-accesskey {
        display: none;      
    }
    .ebook-main-content:focus::after {
        display: none;
    }
    .ebook-home-logo {
        display: block;
        width: min(230px, 100%);
        max-width: 100%;
        min-width: 0;
    }

        .ebook-home-logo img {
            display: block;
            width: 100%;
            height: auto;
            max-height: 34px;
            object-fit: contain;
            object-position: left center;
        }


    .ebook-eyebrow,
    .ebook-button__text,
    .ebook-mode {
        display: none;
    }

    .ebook-toolbar {
        grid-column: 1 / -1;
        grid-row: 2;
        flex-basis: 100%;
        width: 100%;
        min-width: 0;
        gap: 6px;
        padding: 6px;
    }

    .ebook-toolbar__group {
        gap: 4px;
    }

    .ebook-button {
        min-height: 40px;
        padding: 5px 9px;
    }

    .ebook-stage__scroll {
        padding: 8px;
    }

    .ebook-footer {
        flex-wrap: wrap;
        justify-content: center;
        gap: 3px 10px;
        padding: 4px 7px;
    }

    .ebook-status {
        width: 100%;
        text-align: center;
    }

    .ebook-search,
    .ebook-thumbnails {
        inset: 108px 6px 54px 6px;
        width: auto;
        max-height: none;
    }

    .ebook-search-backdrop {
        position: fixed;
        z-index: 19;
        inset: 0;
        display: block;
        background: rgba(15, 27, 38, 0.46);
    }

    .ebook-search {
        position: fixed;
        inset: 108px 6px max(54px, env(safe-area-inset-bottom)) 6px;
        display: flex;
        flex-direction: column;
        width: auto;
        height: calc(100dvh - 162px);
        max-height: none;
        min-height: 0;
        overflow: hidden;
        padding: 12px;
    }

    .ebook-search__form,
    .ebook-search__summary {
        flex: 0 0 auto;
    }

    .ebook-search-results {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    .ebook-search__summary,
    .ebook-search__controls {
        flex-wrap: wrap;
    }

    .ebook-thumbnails__list {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 560px) {
    .ebook-title {
        font-size: 1rem;
    }

    .ebook-header #ebookFullscreenText {
        display: none;
    }

    .ebook-toolbar__group:first-child {
        width: 100%;
        justify-content: center;
    }

    .ebook-toolbar__group:nth-child(2) {
        flex: 1 1 auto;
    }

    .ebook-page-input span {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    .ebook-page-input input {
        width: 58px;
    }

    .ebook-footer__controls {
        width: 100%;
        justify-content: space-between;
    }

    .ebook-thumbnails__list {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-height: 650px) and (min-width: 1024px) {
    .ebook-header {
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .ebook-eyebrow {
        display: none;
    }

    .ebook-toolbar {
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .ebook-button,
    .ebook-viewer input,
    .ebook-viewer select {
        min-height: 34px;
        padding-top: 3px;
        padding-bottom: 3px;
    }

    .ebook-footer {
        min-height: 40px;
    }
}

/* Unified pager layout: navigation belongs to the footer; the header is tools only. */
@media (min-width: 1024px) {
    .ebook-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        align-items: center;
        gap: 12px;
        flex-wrap: nowrap;
    }

    .ebook-header__brand { grid-column: 1; grid-row: 1; justify-self: start; }
    .ebook-toolbar {
        grid-column: 2;
        grid-row: 1;
        display: flex;
        flex: 0 0 auto;
        width: auto;
        min-width: 0;
        justify-self: center;
        flex-wrap: nowrap;
        order: initial;
        padding: 0;
        border-bottom: 0;
        background: transparent;
    }
    .ebook-header__actions {
        grid-column: 3;
        grid-row: 1;
        justify-self: end;
        margin-left: 0;
        order: initial;
    }
    .ebook-toolbar > .ebook-toolbar__group:last-child { margin-left: 0; }

    .ebook-footer {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        align-items: center;
    }
    .ebook-status { grid-column: 1; justify-self: start; }
    .ebook-footer__controls { grid-column: 2; justify-self: center; }
}

.ebook-footer__controls { gap: 6px; white-space: nowrap; }

@media (max-width: 1023px) {
    .ebook-footer {
        display: flex;
        flex-wrap: nowrap;
        justify-content: center;
        gap: 4px;
        min-height: 48px;
        padding: 4px 6px;
    }
    .ebook-status,
    .ebook-footer__controls {
        display: flex;
        width: auto;
        max-width: 100%;
        justify-content: center;
        gap: 3px;
    }
    .ebook-footer__controls .ebook-button {
        flex: 0 0 40px;
        width: 40px;
        min-width: 40px;
        min-height: 40px;
        padding: 5px 3px;
    }
    .ebook-footer__controls .ebook-pager__label { display: none; }
    .ebook-footer__controls .ebook-page-input input { width: 52px; }
    .ebook-footer__controls .ebook-page-total { min-width: 38px; }
}

@media (max-width: 360px) {
    .ebook-footer { gap: 2px; padding-inline: 3px; }
    .ebook-footer__controls { gap: 1px; }
    .ebook-footer__controls .ebook-button { flex-basis: 40px; width: 40px; min-width: 40px; }
    .ebook-footer__controls .ebook-page-input input { width: 44px; }
    .ebook-footer__controls .ebook-page-total { min-width: 34px; }
}

@media (prefers-reduced-motion: reduce) {
    .ebook-book,
    .ebook-page__image {
        transition-duration: 1ms;
    }

    .ebook-page__loading::before {
        animation-duration: 1ms;
        animation-iteration-count: 1;
    }
}

/* Medium desktop keeps the complete toolbar in one row; tablet desktop uses action icons. */
@media (min-width: 1200px) and (max-width: 1499px) {
    .ebook-header {
        gap: 6px;
    }

    .ebook-header__brand {
        max-width: min(190px, 18vw);
    }

    .ebook-home-logo {
        width: 100%;
        max-width: 100%;
    }

    .ebook-toolbar {
        gap: .15rem;
        padding: 4px 0;
    }

    .ebook-toolbar__group {
        gap: .15rem;
    }

    .ebook-toolbar__button {
        padding-inline: .25rem;
    }

    .ebook-page-input {
        gap: 3px;
    }

    .ebook-page-input > span,
    #ebookModeGroup > span {
        display: none;
    }

    .ebook-page-input input {
        width: 3.5rem;
    }
}

@media (min-width: 1200px) and (max-width: 1499px) {
    .ebook-header {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
    }

    .ebook-header__brand {
        flex: 0 0 auto;
        order: 1;
    }

    .ebook-toolbar {
        display: flex;
        order: 2;
        flex: 1 1 auto;
        flex-basis: auto;
        min-width: 0;
        flex-wrap: nowrap;
        width: auto;
        gap: .3rem;
        padding: 4px 0;
        border-bottom: 0;
        background: transparent;
    }

    .ebook-header__actions {
        flex: 0 0 auto;
        order: 3;
        margin-left: 0;
    }
}

@media (min-width: 1024px) and (max-width: 1199px) {
    .ebook-header {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        gap: .35rem;
        padding: 5px 6px;
    }

    .ebook-header__brand {
        flex: 0 0 auto;
        order: 1;
    }

    .ebook-header__actions {
        flex: 0 0 auto;
        order: 3;
        margin-left: 0;
    }

    .ebook-toolbar {
        display: flex;
        order: 2;
        flex: 1 1 auto;
        flex-basis: auto;
        min-width: 0;
        width: auto;
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: .2rem;
        padding: 4px 0;
        border-bottom: 0;
        background: transparent;
    }

    .ebook-toolbar__group {
        flex: 0 0 auto;
        gap: .2rem;
    }

    .ebook-toolbar__button {
        flex: 0 0 auto;
        min-width: 36px;
        min-height: 34px;
        padding-inline: .4rem;
        white-space: nowrap;
    }

    .ebook-toolbar__label,
    #ebookFullscreen .ebook-toolbar__label,
    #ebookZoomReset .ebook-toolbar__label,
    .ebook-page-input > span,
    #ebookModeGroup > span {
        display: none;
    }

    .ebook-page-input input {
        width: 3.5rem;
    }

    .ebook-page-total,
    .ebook-zoom-value {
        min-width: 2.75rem;
    }

    .ebook-toolbar__group:last-child {
        margin-left: 0;
    }
}

[hidden] {
    display: none;
}

/* Final pager/header placement overrides legacy responsive toolbar rules. */
@media (min-width: 1024px) {
    .ebook-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
        flex-wrap: nowrap;
        align-items: center;
    }
    .ebook-header__brand { grid-column: 1; grid-row: 1; justify-self: start; order: initial; }
    .ebook-toolbar {
        grid-column: 2; grid-row: 1; justify-self: center;
        display: flex; flex: 0 0 auto; width: auto; min-width: 0;
        order: initial; padding: 0; border-bottom: 0; background: transparent;
    }
    .ebook-header__actions {
        grid-column: 3; grid-row: 1; justify-self: end;
        display: flex; flex: 0 0 auto; order: initial; margin-left: 0;
    }
}
