:root {
    color-scheme: light;
    --reader-background: #FFFFFF;
    --reader-text: #000000;
    --reader-muted: #77716c;
    --reader-accent: #e85b20;
    --reader-selection: rgba(244, 162, 78, .34);
    --reader-highlight: rgba(255, 216, 74, .52);
    --reader-font-family: "Droid Serif", "PT Serif", Georgia, serif;
    --reader-font-size: 20px;
    --reader-line-height: 1.58;
    --reader-margin: 28px;
    --reader-text-align: justify;
    --reader-page-block-padding: 18px;
}

* {
    box-sizing: border-box;
}

html,
body,
#reader-shell {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: var(--reader-background);
}

html,
body {
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    color: var(--reader-text);
    font-family: var(--reader-font-family);
    font-optical-sizing: auto;
    touch-action: pan-y;
    transition: background-color 140ms ease, color 140ms ease;
}

body.theme-light {
    color-scheme: light;
    --reader-background: #FFFFFF;
    --reader-text: #000000;
    --reader-muted: #77716c;
    --reader-selection: rgba(244, 162, 78, .34);
}

body.theme-sepia {
    color-scheme: light;
    --reader-background: #F6F3E0;
    --reader-text: #000000;
    --reader-muted: #8F806B;
    --reader-selection: rgba(218, 139, 52, .35);
}

body.theme-dark {
    color-scheme: dark;
    --reader-background: #000000;
    --reader-text: #F4F4F4;
    --reader-muted: #9D9C9F;
    --reader-selection: rgba(206, 116, 57, .45);
    --reader-highlight: rgba(185, 140, 24, .46);
}

.reader-surface {
    position: absolute;
    inset: 0;
    display: none;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--reader-background);
    color: var(--reader-text);
    contain: layout paint;
}

.reader-surface.is-active {
    display: block;
}

#epub-viewer,
#epub-viewer > div {
    background: var(--reader-background) !important;
}

#fb2-viewer.is-scrolled {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}

#fb2-document {
    position: relative;
    margin: var(--reader-page-block-padding) var(--reader-margin);
    padding: 0;
    color: var(--reader-text);
    background: var(--reader-background);
    font-family: var(--reader-font-family);
    font-size: var(--reader-font-size);
    font-weight: 400;
    line-height: var(--reader-line-height);
    text-align: var(--reader-text-align);
    hyphens: auto;
    overflow-wrap: anywhere;
    word-break: normal;
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
    transform-origin: left top;
    will-change: transform;
}

#fb2-viewer.is-paginated #fb2-document {
    height: calc(100% - (2 * var(--reader-page-block-padding)));
    column-fill: auto;
    overflow: visible;
}

#fb2-viewer.is-scrolled #fb2-document {
    min-height: calc(100% - (2 * var(--reader-page-block-padding)));
    column-width: auto !important;
    column-gap: normal !important;
    transform: none !important;
    will-change: auto;
}

#fb2-document p {
    margin: 0 0 .56em;
    text-indent: 1.25em;
}

#fb2-document h1,
#fb2-document h2,
#fb2-document h3,
#fb2-document h4,
#fb2-document h5,
#fb2-document h6 {
    break-after: avoid;
    color: inherit;
    font-family: var(--reader-font-family);
    font-weight: 700;
    line-height: 1.28;
    text-align: center;
    text-wrap: balance;
}

#fb2-document h1,
#fb2-document h2 {
    margin: 1.5em 0 .8em;
    font-size: 1.38em;
}

#fb2-document h3,
#fb2-document h4 {
    margin: 1.25em 0 .65em;
    font-size: 1.12em;
}

#fb2-document .fb2-section:first-child > :first-child {
    margin-top: .35em;
}

#fb2-document .fb2-subtitle {
    margin: .9em 0 .65em;
    font-size: 1.03em;
    font-weight: 600;
    text-align: center;
    text-indent: 0;
}

#fb2-document .fb2-epigraph,
#fb2-document .fb2-cite {
    margin: 1.05em 0 1.05em 12%;
    font-size: .92em;
}

#fb2-document .fb2-epigraph {
    font-style: italic;
}

#fb2-document .fb2-cite {
    padding-left: .9em;
    border-left: 2px solid color-mix(in srgb, var(--reader-text) 22%, transparent);
}

#fb2-document .fb2-epigraph p,
#fb2-document .fb2-cite p,
#fb2-document .fb2-poem p,
#fb2-document .fb2-code {
    text-indent: 0;
}

#fb2-document .fb2-text-author {
    text-align: right;
    text-indent: 0;
}

#fb2-document .fb2-poem {
    width: fit-content;
    max-width: 92%;
    margin: 1em auto;
    text-align: left;
}

#fb2-document .fb2-stanza {
    margin: 0 0 .9em;
}

#fb2-document .fb2-stanza p {
    margin: 0;
}

#fb2-document .fb2-code {
    display: block;
    max-width: 100%;
    margin: .9em 0;
    padding: .75em;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    border-radius: 3px;
    background: color-mix(in srgb, var(--reader-text) 7%, transparent);
    font-family: ui-monospace, "Cascadia Mono", monospace;
    font-size: .84em;
    line-height: 1.45;
    text-align: left;
}

#fb2-document .fb2-image {
    display: block;
    max-width: min(100%, 760px);
    max-height: 76vh;
    margin: 1em auto;
    object-fit: contain;
    break-inside: avoid;
}

#fb2-document .fb2-table-wrap {
    max-width: 100%;
    margin: .9em 0;
    overflow: hidden;
    break-inside: avoid;
}

#fb2-document table {
    width: 100%;
    border-collapse: collapse;
    font-size: .82em;
    line-height: 1.35;
    text-align: left;
}

#fb2-document th,
#fb2-document td {
    padding: .35em .45em;
    border: 1px solid color-mix(in srgb, var(--reader-text) 24%, transparent);
    vertical-align: top;
}

#fb2-document a {
    color: var(--reader-accent);
    text-decoration-color: color-mix(in srgb, var(--reader-accent) 55%, transparent);
    text-underline-offset: .14em;
}

#fb2-document mark.reader-highlight {
    padding: 0;
    border-radius: .08em;
    color: inherit;
    background: var(--reader-highlight);
}

#fb2-document mark.reader-search-current {
    padding: 0;
    border-radius: .08em;
    color: inherit;
    background: rgba(238, 101, 37, .42);
    outline: 1px solid rgba(214, 72, 18, .56);
}

::selection {
    color: inherit;
    background: var(--reader-selection);
}

#reader-status {
    position: absolute;
    z-index: 20;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px;
    color: var(--reader-muted);
    background: var(--reader-background);
    font: 500 15px/1.4 system-ui, sans-serif;
    text-align: center;
    opacity: 1;
    visibility: visible;
    transition: opacity 140ms ease, visibility 140ms ease;
}

#reader-status.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

#reader-status.is-error {
    color: #b33a27;
}

#reader-status.is-error .status-spinner {
    display: none;
}

.status-spinner {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    border: 2px solid color-mix(in srgb, var(--reader-muted) 28%, transparent);
    border-top-color: var(--reader-accent);
    border-radius: 50%;
    animation: reader-spin .75s linear infinite;
}

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

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