.aev-reader,
.aev-reader * {
    box-sizing: border-box;
}

.aev-reader {
    --aev-height: 700px;
    --aev-bg: #fff;
    --aev-panel: #f7f7f8;
    --aev-text: #202124;
    --aev-muted: #5f6368;
    --aev-border: #d9dce1;
    --aev-accent: #1f5fae;
    --aev-accent-contrast: #fff;
    position: relative;
    width: 100%;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--aev-border);
    border-radius: 8px;
    background: var(--aev-bg);
    color: var(--aev-text);
    box-shadow: 0 2px 12px rgba(0, 0, 0, .08);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.35;
}

.aev-reader.aev-theme-sepia {
    --aev-bg: #f4ecd8;
    --aev-panel: #ebe0c5;
    --aev-text: #3b3024;
    --aev-muted: #6a5947;
    --aev-border: #cfc1a2;
    --aev-accent: #79511f;
}

.aev-reader.aev-theme-dark {
    --aev-bg: #171a1f;
    --aev-panel: #242930;
    --aev-text: #eef1f5;
    --aev-muted: #b3bac5;
    --aev-border: #414852;
    --aev-accent: #8ab4f8;
    --aev-accent-contrast: #101216;
    color-scheme: dark;
}

.aev-reader:focus-visible {
    outline: 3px solid var(--aev-accent);
    outline: 3px solid color-mix(in srgb, var(--aev-accent) 70%, transparent);
    outline-offset: 2px;
}

.aev-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 52px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--aev-border);
    background: var(--aev-panel);
    color: var(--aev-text);
}

.aev-button,
.aev-theme-select {
    min-width: 38px;
    min-height: 36px;
    margin: 0;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    color: inherit;
    font: inherit;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
}

.aev-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 9px;
    font-weight: 600;
}

.aev-button:hover,
.aev-theme-select:hover {
    border-color: var(--aev-border);
    background: rgba(127, 127, 127, .12);
    background: color-mix(in srgb, var(--aev-text) 8%, transparent);
    color: inherit;
}

.aev-button:focus-visible,
.aev-theme-select:focus-visible,
.aev-progress:focus-visible,
.aev-toc-link:focus-visible {
    outline: 2px solid var(--aev-accent);
    outline-offset: 1px;
}

.aev-button[hidden] {
    display: none !important;
}

.aev-book-heading {
    min-width: 120px;
    max-width: min(44vw, 520px);
    margin-left: 6px;
    overflow: hidden;
}

.aev-book-title,
.aev-chapter {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.aev-book-title {
    font-size: 14px;
}

.aev-chapter {
    min-height: 15px;
    color: var(--aev-muted);
    font-size: 11px;
}

.aev-toolbar-spacer {
    flex: 1 1 auto;
}

.aev-theme-label {
    display: inline-flex;
    align-items: center;
}

.aev-theme-select {
    width: auto;
    min-width: 76px;
    padding: 5px 24px 5px 8px;
    border-color: var(--aev-border);
    background-color: var(--aev-bg);
    line-height: 1.2;
}

.aev-shell {
    position: relative;
    display: flex;
    width: 100%;
    height: var(--aev-height);
    min-height: 300px;
    overflow: hidden;
    background: var(--aev-bg);
}

.aev-viewport {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    height: 100%;
    overflow: hidden;
    background: var(--aev-bg);
}

.aev-viewport iframe {
    border: 0 !important;
    background: var(--aev-bg);
}

.aev-toc {
    display: none;
    flex: 0 0 300px;
    width: 300px;
    height: 100%;
    overflow: auto;
    border-right: 1px solid var(--aev-border);
    background: var(--aev-panel);
    color: var(--aev-text);
    z-index: 5;
}

.aev-toc-open .aev-toc {
    display: block;
}

.aev-toc-heading {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    padding: 7px 8px 7px 16px;
    border-bottom: 1px solid var(--aev-border);
    background: var(--aev-panel);
}

.aev-toc-nav {
    padding: 8px 8px 24px;
}

.aev-toc-nav ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

.aev-toc-nav ol ol {
    padding-left: 16px;
}

.aev-toc-link {
    display: block;
    width: 100%;
    margin: 1px 0;
    padding: 8px 9px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 13px;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
}

.aev-toc-link:hover {
    background: rgba(127, 127, 127, .12);
    background: color-mix(in srgb, var(--aev-text) 8%, transparent);
}

.aev-toc-empty {
    padding: 12px;
    color: var(--aev-muted);
    font-size: 13px;
}

.aev-loading,
.aev-error {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 30px;
    background: var(--aev-bg);
    color: var(--aev-muted);
    text-align: center;
}

.aev-loading[hidden],
.aev-error[hidden] {
    display: none;
}

.aev-error {
    color: #b32d2e;
}

.aev-theme-dark .aev-error {
    color: #ff9b94;
}

.aev-spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--aev-border);
    border-top-color: var(--aev-accent);
    border-radius: 50%;
    animation: aev-spin .8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .aev-spinner { animation-duration: 1.8s; }
}

.aev-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 42px;
    padding: 6px 12px;
    border-top: 1px solid var(--aev-border);
    background: var(--aev-panel);
}

.aev-progress-wrap {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
}

.aev-progress {
    width: 100%;
    accent-color: var(--aev-accent);
    cursor: pointer;
}

.aev-progress:disabled {
    opacity: .45;
    cursor: wait;
}

.aev-location {
    flex: 0 0 auto;
    min-width: 42px;
    color: var(--aev-muted);
    font-size: 12px;
    text-align: right;
}

.aev-screen-reader-text {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.aev-notice {
    padding: 12px 16px;
    border-left: 4px solid #2271b1;
    background: #fff;
}

.aev-notice-error {
    border-left-color: #d63638;
}

.aev-reader:fullscreen,
.aev-reader.aev-is-fullscreen,
.aev-reader:-webkit-full-screen {
    width: 100vw;
    height: 100vh;
    max-width: none;
    border: 0;
    border-radius: 0;
}

.aev-reader:fullscreen .aev-shell,
.aev-reader.aev-is-fullscreen .aev-shell,
.aev-reader:-webkit-full-screen .aev-shell {
    height: calc(100vh - 94px);
}

@media (max-width: 720px) {
    .aev-toolbar {
        gap: 2px;
        padding: 5px;
    }

    .aev-button {
        min-width: 34px;
        padding-left: 7px;
        padding-right: 7px;
    }

    .aev-book-heading {
        max-width: 28vw;
        margin-left: 2px;
    }

    .aev-chapter,
    .aev-theme-label,
    .aev-font-down,
    .aev-font-up {
        display: none;
    }

    .aev-toc {
        position: absolute;
        inset: 0 auto 0 0;
        width: min(88vw, 340px);
        box-shadow: 8px 0 20px rgba(0,0,0,.18);
    }

    .aev-shell {
        min-height: 420px;
    }
}

@media (max-width: 430px) {
    .aev-book-heading {
        display: none;
    }

    .aev-toolbar-spacer {
        display: block;
    }
}
