/* Reader chrome is scoped to the reader route; shared pages keep their shell. */
:is(body.manga-reader-page, body:has(#manga-reader)) {
    background: #000;
    overflow-y: auto !important;
}
:is(body.manga-reader-page, body:has(#manga-reader)).reader-dialog-open { overflow: hidden !important; }
:is(body.manga-reader-page, body:has(#manga-reader)) .navbar,
:is(body.manga-reader-page, body:has(#manga-reader)) .footer,
:is(body.manga-reader-page, body:has(#manga-reader)) .sidebar,
:is(body.manga-reader-page, body:has(#manga-reader)) .sidebar-backdrop,
:is(body.manga-reader-page, body:has(#manga-reader)) #welcome-popup {
    display: none !important;
}
:is(body.manga-reader-page, body:has(#manga-reader)) .main-content {
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0 !important;
    min-height: 100dvh;
}
html:has(#manga-reader) { scroll-behavior: auto; scroll-padding-top: 84px; }
.manga-reader {
    --reader-top-height: 76px;
    --reader-bottom-height: 76px;
    --reader-notice-height: 0px;
    --reader-width: 760px;
    --reader-scale: 1;
    --reader-canvas: #000;
    --reader-placeholder: #111419;
    --reader-page-muted: #aeb2bc;
    --reader-page-gap: 0px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    background: var(--reader-canvas);
    min-height: 100dvh;
}
.manga-reader[data-reader-tone="charcoal"] { --reader-canvas: #202329; --reader-placeholder: #2a2e36; }
.manga-reader[data-reader-tone="paper"] { --reader-canvas: #eee7da; --reader-placeholder: #e3dccf; --reader-page-muted: #5b5248; }
.manga-reader [hidden] { display: none !important; }
.manga-reader button, .manga-reader input, .manga-reader select { font: inherit; }
.manga-reader a { text-decoration: none; }
.manga-reader button { cursor: pointer; }
.manga-reader button:disabled, .manga-reader input:disabled { opacity: .4; cursor: default; }
.manga-reader :focus-visible { outline: 2px solid var(--accent-muted); outline-offset: 3px; }
.reader-skip { position: fixed; left: 16px; top: -100px; z-index: 80; padding: 12px 16px; color: #fff; background: var(--surface-3); border: 1px solid var(--accent); border-radius: 8px; }
.reader-skip:focus { top: 12px; }
.reader-toolbar, .reader-bottom { position: fixed; left: 0; right: 0; z-index: 40; background: #0a0b0e; }
.reader-toolbar {
    top: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
    border-bottom: 1px solid var(--border-light);
}
.reader-button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text-primary);
    font-size: .8rem !important;
    font-weight: 600 !important;
    line-height: 1.2;
    white-space: nowrap;
}
.reader-button:not(:disabled):hover { background: var(--surface-3); border-color: rgba(255,255,255,.28); }
.reader-button svg { flex: 0 0 auto; }
.reader-icon-button { width: 40px; padding: 8px; }
.reader-button-primary { background: var(--text-primary); border-color: var(--text-primary); color: #111419; }
.reader-button-primary:not(:disabled):hover { background: #fff; border-color: #fff; }
.reader-heading { min-width: 0; }
.reader-heading h1 { font-size: .94rem; line-height: 1.3; font-weight: 700; margin: 0 0 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-heading h1 a { color: var(--text-primary); }
.reader-chapter-select { width: min(100%, 280px); max-width: 100%; padding: 4px 28px 4px 8px; border-radius: 6px; border: 1px solid var(--border-color); background: var(--surface-2); color: var(--text-secondary); font-size: .75rem !important; line-height: 1.3; }
.reader-chapter-title { margin: 0; color: var(--text-secondary); font-size: .75rem; }
.reader-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.reader-zoom { display: flex; align-items: center; border: 1px solid var(--border-light); border-radius: 8px; overflow: hidden; }
.reader-zoom .reader-button { border: 0; border-radius: 0; background: transparent; width: 34px; min-height: 38px; }
.reader-zoom-value { color: var(--text-secondary); font-size: .75rem !important; background: transparent; border: 0; min-width: 44px; min-height: 38px; padding: 4px; }
.reader-counter { display: inline-flex; align-items: center; justify-content: center; min-width: 72px; height: 36px; padding: 4px 10px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--surface-2); color: var(--text-secondary); font-size: .75rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.reader-stage { min-height: 100dvh; padding: var(--reader-top-height) 0 var(--reader-bottom-height); overflow-x: auto; background: var(--reader-canvas); }
.reader-images { width: var(--reader-width); max-width: none; margin-inline: auto; display: flex; flex-direction: column; gap: var(--reader-page-gap); }
.reader-page { position: relative; margin: 0; width: 100%; flex: 0 0 auto; }
.reader-page img { display: block; width: 100%; height: auto; margin-inline: auto; }
.reader-page.is-loading { min-height: 480px; background: var(--reader-placeholder); }
.reader-page.is-loading img { opacity: 0; }
.reader-page-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 16px; pointer-events: none; color: var(--reader-page-muted); font-size: .8rem; }
.reader-page-loading span { width: 32px; height: 32px; border: 2px solid var(--border-light); border-top-color: var(--accent-muted); border-radius: 50%; animation: reader-loading .9s linear infinite; }
.reader-page-loading p { margin: 0; }
.reader-page:not(.is-loading) .reader-page-loading { display: none; }
.reader-page.is-error { min-height: 280px; background: var(--reader-placeholder); }
.reader-page.is-error img { display: none; }
.reader-page-error { min-height: 280px; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 16px; padding: 24px; text-align: center; color: var(--reader-page-muted); }
.reader-page-error p { margin: 0; }
.manga-reader[data-reader-mode="single"] .reader-images,
.manga-reader[data-reader-mode="double"] .reader-images { flex-direction: row; align-items: flex-start; justify-content: center; gap: 8px; padding-block: 12px; min-height: calc(100dvh - var(--reader-top-height) - var(--reader-bottom-height) - var(--reader-notice-height)); }
.manga-reader[data-reader-mode="double"][data-reader-direction="rtl"] .reader-images { flex-direction: row-reverse; }
.manga-reader:not([data-reader-mode="vertical"]) .reader-page { flex: 1 1 0; min-width: 0; display: flex; justify-content: center; }
.manga-reader:not([data-reader-mode="vertical"]) .reader-page img { width: auto; max-width: 100%; max-height: calc((100dvh - var(--reader-top-height) - var(--reader-bottom-height) - var(--reader-notice-height) - 24px) * var(--reader-scale)); object-fit: contain; }
.manga-reader:not([data-reader-mode="vertical"]) .reader-page.is-loading { min-height: min(480px, calc(100dvh - var(--reader-top-height) - var(--reader-bottom-height) - var(--reader-notice-height) - 24px)); }
.reader-page-arrows { position: relative; z-index: 20; }
.reader-page-arrow { position: fixed; top: 50%; transform: translateY(-50%); width: 44px; height: 52px; display: flex; justify-content: center; align-items: center; border: 1px solid var(--border-light); border-radius: 50%; background: rgba(10,11,14,.9); color: var(--text-primary); }
.reader-page-arrow:not(:disabled):hover { background: var(--surface-3); border-color: var(--accent-muted); }
.reader-page-arrow-left { left: max(16px, env(safe-area-inset-left)); }
.reader-page-arrow-right { right: max(16px, env(safe-area-inset-right)); }
.reader-chapter-end { text-align: center; padding: 48px 16px 56px; color: var(--reader-page-muted); }
.reader-chapter-end h2 { margin: 16px 0 8px; font-size: 1.15rem; color: inherit; }
.reader-chapter-end p { margin: 8px 0 24px; font-size: .85rem; }
.reader-end-mark { display: inline-flex; padding: 16px; border: 1px solid var(--border-light); border-radius: 50%; }
.manga-reader:not([data-reader-mode="vertical"]) .reader-chapter-end { display: none; }
.reader-last-chapter { color: var(--reader-page-muted); }
.reader-provider-error, .reader-language-note { max-width: 900px; margin: 0 auto; padding: 12px 16px; font-size: .8rem; line-height: 1.5; }
.reader-provider-error { color: #fecaca; background: #301317; }
.reader-language-note { color: var(--reader-page-muted); text-align: center; }
.reader-empty { min-height: calc(100dvh - var(--reader-top-height) - var(--reader-bottom-height)); max-width: 520px; display: flex; align-items: center; justify-content: center; flex-direction: column; margin: 0 auto; padding: 48px 24px; text-align: center; color: var(--reader-page-muted); }
.reader-empty-icon { display: flex; align-items: center; justify-content: center; width: 64px; height: 64px; margin-bottom: 24px; border: 1px solid var(--border-light); border-radius: 16px; }
.reader-empty-icon svg { width: 28px; height: 28px; }
.reader-empty h2 { margin: 0 0 16px; color: inherit; font-size: 1.25rem; }
.reader-empty p { margin: 0 0 24px; font-size: .9rem; line-height: 1.7; }
.reader-empty > div { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.reader-bottom { bottom: 0; display: grid; grid-template-columns: auto minmax(100px, 1fr) auto auto; align-items: center; gap: 16px; padding: 12px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); border-top: 1px solid var(--border-light); }
.reader-page-seek { display: flex; align-items: center; gap: 12px; min-width: 0; }
.reader-page-seek input { flex: 1; width: 100%; min-width: 0; margin: 0; accent-color: var(--accent); height: 24px; cursor: pointer; }
.reader-modes { display: flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--border-light); border-radius: 8px; }
.reader-mode-button { min-height: 34px; padding: 6px 12px; border: 0; border-radius: 5px; background: transparent; color: var(--text-secondary); font-size: .7rem !important; font-weight: 600 !important; white-space: nowrap; }
.reader-mode-button[aria-pressed="true"] { background: var(--text-primary); color: #111419; }
.reader-mode-button:not(:disabled):hover:not([aria-pressed="true"]) { color: #fff; background: var(--surface-3); }
.reader-progress-line { position: absolute; bottom: 0; left: 0; width: 0; height: 2px; background: var(--accent); pointer-events: none; }
.reader-status { position: fixed; bottom: calc(var(--reader-bottom-height) + 12px); left: 50%; z-index: 70; max-width: calc(100vw - 32px); margin: 0; transform: translateX(-50%); padding: 10px 16px; border: 1px solid var(--border-light); border-radius: 8px; background: #1b1e24; color: #f7f7f4; font-size: .8rem; text-align: center; box-shadow: 0 4px 24px rgba(0,0,0,.3); }
.reader-dialog { color: var(--text-primary); background: #111419; border: 1px solid var(--border-light); border-radius: 12px; padding: 24px; max-width: calc(100vw - 24px); }
.reader-dialog:not([open]) { display: none; }
.reader-dialog::backdrop { background: rgba(0,0,0,.75); }
.reader-dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex: 0 0 auto; margin-bottom: 20px; }
.reader-dialog-heading h2 { margin: 4px 0 0; font-size: 1.25rem; line-height: 1.3; }
.reader-dialog-heading form { margin: 0; }
.reader-eyebrow { color: var(--text-secondary); font-size: .65rem; text-transform: uppercase; letter-spacing: .1em; }
.reader-chapters-dialog { position: fixed; inset: 0 0 0 auto; margin: 0; width: 400px; height: 100dvh; max-height: 100dvh; max-width: 100vw; border-radius: 0; border-width: 0 0 0 1px; }
.reader-chapters-dialog[open] { display: flex; flex-direction: column; }
.reader-search, .reader-setting select { min-height: 42px; width: 100%; padding: 10px 12px; border: 1px solid var(--border-light); border-radius: 8px; background: var(--surface-3); color: var(--text-primary); font-size: .85rem !important; }
.reader-search { flex: 0 0 auto; }
.reader-chapter-count { color: var(--text-secondary); font-size: .75rem; margin: 16px 0 8px; flex: 0 0 auto; }
.reader-chapter-list { min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.reader-chapter-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 12px; margin-bottom: 4px; border: 1px solid transparent; border-radius: 8px; color: var(--text-secondary); font-size: .8rem; }
.reader-chapter-item > span { min-width: 0; overflow-wrap: anywhere; }
.reader-chapter-item:hover { background: var(--surface-3); color: var(--text-primary); }
.reader-chapter-item.is-current { border-color: rgba(239,68,68,.45); background: rgba(239,68,68,.1); color: #fff; }
.reader-chapter-state { flex: 0 0 auto; color: var(--text-secondary); font-size: .65rem; }
.reader-chapter-item.is-current .reader-chapter-state { color: #fda4af; }
.reader-search-empty { color: var(--text-secondary); font-size: .85rem; }
.reader-settings-dialog { width: 420px; max-height: calc(100dvh - 24px); margin: auto; overflow-y: auto; overscroll-behavior: contain; }
.reader-setting { margin-bottom: 20px; }
.reader-setting label { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: .85rem; font-weight: 600; }
.reader-setting output { color: var(--text-secondary); font-weight: 400; font-variant-numeric: tabular-nums; }
.reader-setting small { display: block; margin-top: 8px; color: var(--text-secondary); font-size: .75rem; line-height: 1.5; }
.reader-setting input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }
.reader-checkbox { display: flex; align-items: center; gap: 8px; font-size: .8rem; }
.reader-checkbox input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.reader-shortcuts { border-top: 1px solid var(--border-color); margin-top: 24px; padding-top: 16px; color: var(--text-secondary); }
.reader-shortcuts h3 { margin: 0 0 12px; color: var(--text-primary); font-size: .8rem; }
.reader-shortcuts p { margin: 8px 0; font-size: .75rem; line-height: 1.8; }
.reader-shortcuts p > span { margin-inline: 8px; }
.reader-shortcuts kbd { display: inline-block; min-width: 24px; margin-right: 4px; padding: 0 5px; text-align: center; font-family: inherit; background: var(--surface-3); border: 1px solid var(--border-light); border-radius: 4px; color: var(--text-primary); }
.reader-storage-note { color: var(--text-secondary); font-size: .7rem; line-height: 1.7; margin: 20px 0 0; }
@keyframes reader-loading { to { transform: rotate(360deg); } }
@media (max-width: 1024px) {
    .reader-toolbar { gap: 12px; }
    .reader-back span { display: none; }
    .reader-back { width: 40px; padding: 8px; }
    .reader-actions { gap: 6px; }
    .reader-top-counter { display: none; }
    .reader-bottom { gap: 12px; }
    .reader-bottom .reader-button { padding-inline: 10px; font-size: .75rem !important; }
    .reader-mode-button { padding-inline: 10px; }
}
@media (max-width: 680px) {
    .manga-reader { --reader-top-height: 120px; --reader-bottom-height: 104px; }
    .reader-toolbar { grid-template-columns: 40px minmax(0, 1fr); gap: 8px 12px; padding: 8px 12px; }
    .reader-heading h1 { font-size: .85rem; }
    .reader-actions { grid-column: 1 / -1; justify-content: space-between; gap: 8px; }
    .reader-actions > .reader-button { min-height: 40px; }
    .reader-actions #reader-open-chapters { flex: 1; }
    .reader-top-counter { display: none; }
    .reader-bottom { grid-template-columns: 40px minmax(0, 1fr) 40px; gap: 8px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
    .reader-page-seek { grid-column: 1 / -1; grid-row: 1; gap: 12px; }
    .reader-page-seek .reader-counter { height: 28px; min-width: 64px; font-size: .7rem; }
    .reader-chapter-nav { grid-column: 1; grid-row: 2; }
    .reader-next-nav { grid-column: 3; }
    .reader-chapter-nav .reader-button { min-height: 40px; width: 40px; padding: 8px; }
    .reader-chapter-nav .reader-button span { display: none; }
    .reader-modes { grid-column: 2; grid-row: 2; justify-content: center; }
    .reader-mode-button { flex: 1; padding: 6px; min-height: 32px; font-size: .68rem !important; }
    .reader-page-arrow { width: 34px; height: 44px; background: rgba(10,11,14,.78); }
    .reader-page-arrow-left { left: 4px; }
    .reader-page-arrow-right { right: 4px; }
    .reader-page.is-loading { min-height: 400px; }
    .reader-dialog { padding: 20px; }
    .reader-empty { padding-inline: 20px; }
}
@media (prefers-reduced-motion: reduce) {
    .reader-page-loading span { animation: none; border-color: var(--accent-muted); }
}
@media (max-width: 480px) {
    .reader-actions #reader-open-chapters { min-width: 40px; padding-inline: 8px; }
    .reader-actions #reader-open-chapters span { display: none; }
}
