:root {
    color-scheme: dark;
    --reader-bg: #111317;
    --reader-panel: #191c22;
    --reader-panel-strong: #22262e;
    --reader-border: #323741;
    --reader-muted: #9ca5b4;
    --reader-text: #f4f6f8;
    --reader-accent: #49b7ef;
    --reader-accent-strong: #168fca;
    --reader-header-height: 54px;
    --reader-toolbar-height: 52px;
    --reader-sidebar-width: 168px;
    --dcm-font-size: 13px;
}

html[data-theme="light"] {
    color-scheme: light;
    --reader-bg: #edf1f5;
    --reader-panel: #ffffff;
    --reader-panel-strong: #e8edf2;
    --reader-border: #cbd3dd;
    --reader-muted: #626d7c;
    --reader-text: #19202a;
    --reader-accent: #087eb8;
    --reader-accent-strong: #087eb8;
}

* {
    box-sizing: border-box;
}

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

body.reader-body {
    min-width: 320px;
    overflow: hidden;
    background: var(--reader-bg);
    color: var(--reader-text);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    font-size: var(--dcm-font-size);
}

button,
select,
input {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.skip-link {
    position: fixed;
    z-index: 100;
    top: 8px;
    left: 8px;
    padding: 8px 12px;
    transform: translateY(-160%);
    border-radius: 4px;
    background: #fff;
    color: #111;
}

.skip-link:focus {
    transform: translateY(0);
}

.reader-shell {
    display: grid;
    grid-template-rows: var(--reader-header-height) minmax(0, 1fr) var(--reader-toolbar-height);
    width: 100%;
    height: 100dvh;
}

.reader-header,
.reader-toolbar {
    position: relative;
    z-index: 20;
    display: flex;
    align-items: center;
    background: rgba(25, 28, 34, 0.98);
}

.reader-header {
    gap: 16px;
    padding: 0 10px 0 14px;
    border-bottom: 1px solid var(--reader-border);
}

.reader-brand {
    display: flex;
    flex: 0 0 auto;
    align-items: baseline;
    gap: 7px;
    color: var(--reader-text);
    text-decoration: none;
    text-transform: uppercase;
}

.reader-brand-mark {
    color: var(--reader-accent);
    font-size: 20px;
    font-weight: 900;
    letter-spacing: -1px;
}

.reader-brand-text {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1.7px;
}

.reader-title {
    min-width: 0;
    flex: 1 1 auto;
    line-height: 1.15;
}

.reader-title strong,
.reader-title span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reader-title strong {
    font-size: 14px;
}

.reader-title span {
    margin-top: 3px;
    color: var(--reader-muted);
    font-size: 11px;
}

.reader-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 2px;
}

.reader-actions a,
.reader-actions button,
.reader-font-value,
.reader-toolbar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--reader-muted);
    cursor: pointer;
    text-decoration: none;
}

.reader-font-value {
    min-width: 38px;
    padding: 0 6px;
    color: var(--reader-muted);
    cursor: default;
    font-size: 10px;
}

.reader-actions a:hover,
.reader-actions button:hover,
.reader-actions a:focus-visible,
.reader-actions button:focus-visible,
.reader-toolbar button:hover,
.reader-toolbar button:focus-visible {
    outline: none;
    background: var(--reader-panel-strong);
    color: var(--reader-text);
}

.reader-content {
    display: grid;
    min-width: 0;
    min-height: 0;
    grid-template-columns: var(--reader-sidebar-width) minmax(0, 1fr);
}

.reader-sidebar {
    display: flex;
    min-height: 0;
    flex-direction: column;
    border-right: 1px solid var(--reader-border);
    background: var(--reader-panel);
    transition: width 180ms ease, transform 180ms ease;
}

.reader-sidebar-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 12px 9px;
    border-bottom: 1px solid var(--reader-border);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.reader-sidebar-heading strong {
    color: var(--reader-accent);
    font-size: 10px;
}

.reader-library {
    display: grid;
    gap: 5px;
    padding: 10px;
    border-bottom: 1px solid var(--reader-border);
}

.reader-library label {
    margin-top: 2px;
    color: var(--reader-muted);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.reader-library select {
    width: 100%;
    height: 28px;
    padding: 0 24px 0 7px;
    overflow: hidden;
    border: 1px solid var(--reader-border);
    border-radius: 4px;
    background: var(--reader-panel-strong);
    color: var(--reader-text);
    font-size: 11px;
    text-overflow: ellipsis;
}

.reader-page-list {
    flex: 1 1 auto;
    min-height: 0;
    padding: 8px;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-color: #555b66 transparent;
    scrollbar-width: thin;
}

.reader-page-link {
    display: block;
    margin-bottom: 8px;
    padding: 5px;
    border: 1px solid transparent;
    border-radius: 5px;
    color: var(--reader-muted);
    font-size: 10px;
    text-align: center;
    text-decoration: none;
}

.reader-page-link:hover,
.reader-page-link:focus-visible {
    border-color: #505762;
    outline: none;
    background: var(--reader-panel-strong);
    color: var(--reader-text);
}

.reader-page-link.is-current {
    border-color: var(--reader-accent);
    background: rgba(73, 183, 239, 0.11);
    color: var(--reader-text);
}

.reader-page-link img,
.reader-page-placeholder {
    display: flex;
    width: 100%;
    aspect-ratio: 0.66;
    margin-bottom: 5px;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    background: #0e1013;
    object-fit: cover;
}

.reader-page-placeholder {
    color: #4c535e;
    font-size: 28px;
}

.reader-stage {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 0;
    align-items: center;
    justify-content: center;
    overflow: auto;
    background:
        radial-gradient(circle at center, rgba(255, 255, 255, 0.045), transparent 56%),
        #101216;
    scrollbar-color: #555b66 transparent;
    scrollbar-width: thin;
}

.reader-page-wrap {
    display: flex;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    align-items: center;
    justify-content: center;
    padding: 10px 46px;
}

.reader-stage.is-zoomed {
    display: block;
}

.reader-stage.is-zoomed .reader-page-wrap {
    min-width: 100%;
    min-height: 100%;
    align-items: center;
    justify-content: center;
}

.reader-page-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    cursor: pointer;
    object-fit: contain;
    box-shadow: 0 8px 34px rgba(0, 0, 0, 0.48);
    user-select: none;
}

.reader-end-card {
    display: grid;
    flex: 0 0 auto;
    gap: 5px;
    margin: 0 8px 8px;
    padding: 11px;
    border: 1px solid rgba(73, 183, 239, 0.35);
    border-radius: 5px;
    background: rgba(73, 183, 239, 0.08);
}

.reader-end-card span {
    color: var(--reader-accent);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.reader-end-card strong {
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reader-end-card a {
    color: var(--reader-muted);
    font-size: 10px;
    text-decoration: none;
}

.reader-end-card a:hover {
    color: var(--reader-text);
}

.reader-edge {
    position: fixed;
    z-index: 5;
    top: 50%;
    display: flex;
    width: 36px;
    height: 70px;
    align-items: center;
    justify-content: center;
    transform: translateY(-50%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 5px;
    background: rgba(18, 20, 24, 0.68);
    color: rgba(255, 255, 255, 0.72);
    cursor: pointer;
    opacity: 0.45;
}

.reader-edge:hover,
.reader-edge:focus-visible {
    opacity: 1;
    outline: none;
    color: #fff;
}

.reader-edge:disabled {
    display: none;
}

.reader-edge-previous {
    left: calc(var(--reader-sidebar-width) + 12px);
}

.reader-edge-next {
    right: 12px;
}

.reader-toolbar {
    gap: 8px;
    padding: 0 12px;
    border-top: 1px solid var(--reader-border);
}

.reader-toolbar button {
    gap: 8px;
    min-width: auto;
    color: var(--reader-text);
    font-size: 12px;
}

.reader-toolbar button:disabled {
    cursor: default;
    opacity: 0.3;
}

.reader-progress {
    display: grid;
    min-width: 120px;
    flex: 1 1 auto;
    grid-template-columns: 58px minmax(80px, 1fr);
    align-items: center;
    gap: 10px;
}

.reader-progress output {
    color: var(--reader-muted);
    font-size: 11px;
    text-align: center;
}

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

.reader-zoom {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    border-left: 1px solid var(--reader-border);
    padding-left: 6px;
}

.reader-zoom .reader-fit {
    color: var(--reader-accent);
}

.reader-zoom [data-zoom-value] {
    min-width: 42px;
    color: var(--reader-muted);
    font-size: 10px;
    text-align: center;
}

.reader-error {
    display: grid;
    max-width: 420px;
    place-items: center;
    gap: 10px;
    padding: 30px;
    color: var(--reader-muted);
    text-align: center;
}

.reader-error i {
    color: #f6bc4b;
    font-size: 36px;
}

.reader-error strong {
    color: var(--reader-text);
}

.reader-body.pages-hidden .reader-content {
    grid-template-columns: 0 minmax(0, 1fr);
}

.reader-body.pages-hidden .reader-sidebar {
    width: 0;
    overflow: hidden;
    border-right: 0;
}

.reader-body.pages-hidden .reader-edge-previous {
    left: 12px;
}

html[data-theme="light"] .reader-header,
html[data-theme="light"] .reader-toolbar {
    background: #ffffff;
}

html[data-theme="light"] .reader-stage {
    background:
        radial-gradient(circle at center, rgba(0, 0, 0, 0.035), transparent 56%),
        #dfe4ea;
}

html[data-theme="light"] .reader-page-placeholder {
    background: #e6ebf0;
    color: #8a95a3;
}

html[data-theme="light"] .reader-page-image {
    box-shadow: 0 8px 34px rgba(31, 45, 61, 0.28);
}

html[data-theme="light"] .reader-edge {
    border-color: rgba(0, 0, 0, 0.13);
    background: rgba(255, 255, 255, 0.82);
    color: rgba(0, 0, 0, 0.66);
}

html[data-theme="light"] .reader-edge:hover,
html[data-theme="light"] .reader-edge:focus-visible {
    color: #111;
}

/* Shared text scaler. The header controls write --dcm-font-size from dcm_font_size. */
.reader-brand-mark {
    font-size: calc(var(--dcm-font-size) + 7px);
}

.reader-brand-text,
.reader-title span,
.reader-sidebar-heading,
.reader-library select,
.reader-page-link,
.reader-end-card strong,
.reader-toolbar button {
    font-size: calc(var(--dcm-font-size) - 1px);
}

.reader-title strong {
    font-size: calc(var(--dcm-font-size) + 1px);
}

.reader-sidebar-heading strong,
.reader-library label,
.reader-font-value,
.reader-end-card span,
.reader-end-card a,
.reader-zoom [data-zoom-value] {
    font-size: calc(var(--dcm-font-size) - 3px);
}

@media (max-width: 820px) {
    :root {
        --reader-sidebar-width: 156px;
    }

    .reader-brand-text,
    .reader-title span,
    .reader-actions a:nth-child(2),
    .reader-actions a:nth-child(3),
    .reader-actions a:nth-child(4),
    .reader-actions a:nth-child(6) {
        display: none;
    }

    .reader-header {
        gap: 8px;
        padding-left: 10px;
    }

    .reader-actions {
        gap: 0;
    }

    .reader-actions a,
    .reader-actions button {
        min-width: 34px;
        padding: 0 8px;
    }

    .reader-content {
        grid-template-columns: minmax(0, 1fr);
    }

    .reader-sidebar {
        position: fixed;
        z-index: 30;
        top: var(--reader-header-height);
        bottom: var(--reader-toolbar-height);
        left: 0;
        width: min(78vw, 260px);
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.45);
    }

    .reader-body.pages-hidden .reader-sidebar {
        width: min(78vw, 260px);
        transform: translateX(-105%);
    }

    .reader-edge-previous,
    .reader-body.pages-hidden .reader-edge-previous {
        left: 8px;
    }

    .reader-edge-next {
        right: 8px;
    }

    .reader-page-wrap {
        padding: 7px 30px;
    }

    .reader-toolbar {
        gap: 2px;
        padding: 0 6px;
    }

    .reader-toolbar button span,
    .reader-zoom [data-zoom-value] {
        display: none;
    }

    .reader-progress {
        grid-template-columns: 50px minmax(70px, 1fr);
        gap: 4px;
    }

    .reader-zoom {
        padding-left: 2px;
    }

    .reader-zoom .reader-fit {
        padding: 0 7px;
        font-size: 10px;
    }
}

@media (max-width: 500px) {
    .reader-title strong {
        font-size: 12px;
    }

    .reader-actions a:first-child,
    .reader-actions button[data-action="fullscreen"] {
        display: none;
    }

    .reader-zoom button[data-action="zoom-out"],
    .reader-zoom button[data-action="zoom-in"] {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .reader-sidebar {
        transition: none;
    }
}
