:root {
    color-scheme: light;
    font: 15px/1.4 system-ui, sans-serif;
    color: #13252b;
    background: #edf2f0;
    --panel: #fff;
    --surface: #f4f7f6;
    --line: #cbd8d5;
    --muted: #455e61;
    --accent: #00665d;
    --tint: #e1f2ed;
    --dock-shadow: 0 4px 18px #17382d12, 0 1px 3px #17382d13;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
    height: 100vh;
    height: 100dvh;
    margin: 0;
    display: flex;
    flex-direction: column;
    background: radial-gradient(ellipse at 34% 18%, #fbfdfa 0%, #edf2f0 50%, #dbe5e3 100%);
}
button, input { font: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.icon-library { position: absolute; width: 0; height: 0; pointer-events: none; }
.icon { width: 1.2rem; height: 1.2rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: none;
    gap: .55rem;
    padding: max(.6rem, env(safe-area-inset-top)) max(1.3rem, env(safe-area-inset-right)) .25rem max(1.3rem, env(safe-area-inset-left));
}
.brand, .top-actions { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.brand { gap: .75rem; }
.brand-mark { flex: none; display: grid; place-items: center; width: 2.55rem; height: 2.55rem; border: 1px solid #bcdbd4; border-radius: .76rem; color: var(--accent); background: var(--tint); }
.top-actions { gap: .12rem; padding: .18rem; border: 1px solid #cddcd7; border-radius: .87rem; background: var(--panel); box-shadow: var(--dock-shadow); }
.top-actions .control { min-height: 2.3rem; border-color: transparent; }
.top-actions .control[aria-pressed=true] { color: var(--accent); background: var(--tint); }
.brand-copy span { color: var(--muted); font-size: .74rem; line-height: 1.2; display: block; }
.brand-copy h1 { margin: .1rem 0 0; font-size: clamp(.97rem, 2.2vw, 1.24rem); line-height: 1.2; letter-spacing: -.025em; }
.control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .46rem;
    flex: none;
    min-width: 2.6rem;
    min-height: 2.55rem;
    padding: .38rem .62rem;
    border: 1px solid var(--line);
    border-radius: .6rem;
    color: #213b40;
    background: var(--panel);
    font-weight: 620;
    text-decoration: none;
    cursor: pointer;
}
.control:hover:not(:disabled) { background: var(--tint); border-color: #abc9c2; }
.control:disabled { opacity: .36; cursor: default; }
.reader { position: relative; display: flex; flex: 1; min-height: 0; isolation: isolate; }
.stage { flex: 1; height: 100%; min-width: 0; overflow: auto; overscroll-behavior: contain; touch-action: pan-y pinch-zoom; }
.stage[data-zoomed=true] { touch-action: auto; }
.stage[data-mode=scroll] { touch-action: auto; overflow-anchor: none; }
.stage:focus-visible { outline-offset: -3px; }
.stage-center { display: grid; place-items: center; min-width: 100%; min-height: 100%; width: max-content; height: max-content; padding: 14px; }
.spread { --book-gutter: 4px; position: relative; display: flex; align-items: center; isolation: isolate; }
.spread[data-count="2"] { gap: var(--book-gutter); }
.spread[data-count="2"] > .leaf { box-shadow: 0 0 0 1px #c4cfcc, 0 8px 26px #28453d22; }
.spread[data-count="2"] > .leaf::before {
    position: absolute;
    z-index: -1;
    inset: 3px auto 3px -4px;
    width: 4px;
    background: repeating-linear-gradient(90deg, #cbd3ce 0 1px, #f2f5f1 1px 2px);
    box-shadow: -1px 0 1px #39514914;
    content: '';
    pointer-events: none;
}
.spread[data-count="2"] > .leaf:last-child::before { inset-inline: auto -4px; }
.leaf, .cover-placeholder {
    position: relative;
    flex: none;
    background: #fff;
    box-shadow: 0 0 0 1px #c4cfcc, 0 3px 0 #c1cac5, 0 12px 38px #28453d2b;
}
.leaf canvas { display: block; width: 100%; height: 100%; }
.leaf { user-select: none; }
.scroll-pages { display: grid; justify-items: center; align-content: start; gap: 16px; min-width: 100%; width: max-content; padding: 16px; }
.scroll-page { position: relative; display: grid; place-items: center; background: #dde8e5; box-shadow: 0 6px 20px #28453d26; }
.scroll-page .leaf { box-shadow: none; }
.scroll-page[aria-busy=true]:empty::after { content: ''; position: absolute; inset: 0; background: linear-gradient(135deg, #f6f8fb, #dce4ea); }
.scroll-retry { margin: .7rem; }
.stage[data-corner=true] .leaf { cursor: grab; }
.stage[data-dragging=true] .leaf, .stage[data-dragging=true] { cursor: grabbing; }
.stage[data-turning] .spread { opacity: 0; }
.stage[data-turning=true] .pdf-link { pointer-events: none; }
.cover-placeholder { width: min(70vw, 42vh, 29rem); aspect-ratio: 595 / 842; }
.cover-placeholder, .thumbnail-art:empty { background: #e6ecf1; overflow: hidden; }
.cover-placeholder::after, .thumbnail-art:empty::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, transparent 25%, #ffffffb0 50%, transparent 75%);
    animation: shimmer 1.5s linear infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .cover-placeholder::after, .thumbnail-art:empty::after { animation: none; } }
.paper-turn { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; }
.stage-arrow {
    position: absolute;
    z-index: 4;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 50%;
    width: 2.7rem;
    height: 2.7rem;
    padding: 0;
    background: var(--panel);
    color: var(--accent);
    box-shadow: var(--dock-shadow);
}
.stage-previous { left: var(--stage-arrow-inset, 1.5rem); }
.stage-next { right: var(--stage-arrow-inset, 1.5rem); }
.stage-arrow:disabled:not(:focus) { visibility: hidden; }
@media (max-width: 979px), (max-height: 530px) { .stage-arrow { display: none; } }
.pdf-link { position: absolute; display: block; border-radius: .16rem; }
.pdf-link:is(:hover, :focus-visible) { outline: 2px solid #005ca8; outline-offset: 1px; background: #36a9ed30; }
.reader-message, .notification {
    position: absolute;
    z-index: 5;
    left: 50%;
    transform: translateX(-50%);
    padding: .58rem .86rem;
    border: 1px solid var(--line);
    border-radius: .7rem;
    background: var(--panel);
    text-align: center;
    box-shadow: var(--dock-shadow);
}
.reader-message { bottom: 1.2rem; width: max-content; max-width: calc(100% - 1.5rem); }
.resume { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .55rem; padding: .38rem .48rem .38rem .8rem; font-size: .87rem; }
.resume .control { min-height: 2.2rem; }
#resume-dismiss { min-width: 2.2rem; padding: 0; background: transparent; border-color: transparent; }
.error-message { bottom: 50%; transform: translate(-50%, 50%); }
.error-message p { margin: .1rem 0 .65rem; }
.error-message .control { margin-left: .6rem; }
.notification { position: fixed; bottom: 5.3rem; max-width: calc(100% - 1.5rem); }
.toolbar { display: grid; justify-items: center; gap: .08rem; flex: none; padding: .13rem max(.6rem, env(safe-area-inset-right)) max(.45rem, env(safe-area-inset-bottom)) max(.6rem, env(safe-area-inset-left)); }
.toolbar-inner, .control-group { display: flex; align-items: center; justify-content: center; }
.toolbar-inner { gap: clamp(.18rem, 1.15vw, .65rem); padding: .17rem; border: 1px solid var(--line); border-radius: .85rem; background: var(--panel); box-shadow: var(--dock-shadow); max-width: 100%; }
.toolbar-inner > .control { border-color: transparent; }
.control-group { border: 1px solid #dae7e3; border-radius: .65rem; background: var(--surface); }
.control-group .control { border: 0; background: transparent; min-width: 2.45rem; min-height: 2.45rem; }
.pagination .control { color: var(--accent); }
.page-status { min-width: 5.2rem; padding: 0 .35rem; text-align: center; font-size: .84rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.control-group .page-counter { flex: 1; padding-inline: 0; color: inherit; }
.page-counter:hover .page-status { text-decoration: underline; text-underline-offset: .22em; }
#zoom-reset { font-size: .8rem; min-width: 2.75rem; padding-inline: .2rem; }
.page-scrubber {
    --progress: 0%;
    appearance: none;
    width: min(88vw, 34rem);
    height: 1.13rem;
    padding: 0;
    margin: 0;
    background: transparent;
    cursor: pointer;
}
.page-scrubber::-webkit-slider-runnable-track { height: .27rem; border-radius: 2rem; background: linear-gradient(to right, #5e9b8d var(--progress), #c6d6d1 var(--progress)); }
.page-scrubber::-webkit-slider-thumb { appearance: none; width: .85rem; height: .85rem; margin-top: -.29rem; border-radius: 50%; border: 2px solid #fff; background: var(--accent); box-shadow: 0 0 0 1px #367a70; }
.page-scrubber::-moz-range-track { height: .27rem; border-radius: 2rem; background: #c6d6d1; }
.page-scrubber::-moz-range-progress { height: .27rem; border-radius: 2rem; background: #5e9b8d; }
.page-scrubber::-moz-range-thumb { width: .65rem; height: .65rem; border-radius: 50%; border: 2px solid #fff; background: var(--accent); box-shadow: 0 0 0 1px #367a70; }
.page-scrubber:disabled { opacity: .5; cursor: default; }
.sheet-dialog {
    width: min(46rem, calc(100% - 1.45rem));
    max-height: min(80dvh, 42rem);
    padding: 0;
    border: 1px solid #b8cbc5;
    border-radius: 1rem;
    color: inherit;
    background: var(--panel);
    box-shadow: 0 22px 60px #1a3b343b;
}
.sheet-dialog::backdrop { background: #17332f63; }
.dialog-header { display: flex; position: sticky; z-index: 1; top: 0; align-items: center; justify-content: space-between; gap: .6rem; padding: .65rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line); }
.dialog-header h2 { font-size: 1.06rem; margin: 0; }
.page-jump { display: flex; align-items: center; gap: .55rem; padding: .7rem 1rem 0; }
.page-jump label { font-size: .86rem; color: var(--muted); }
.page-jump input { width: 4.25rem; padding: .48rem; font-size: 1rem; border-radius: .48rem; background: var(--surface); border: 1px solid var(--line); color: inherit; }
.page-jump .control { font-size: .85rem; }
.reading-settings { width: min(28rem, calc(100% - 1.45rem)); }
.reading-settings-body { padding: .95rem; display: grid; gap: .95rem; }
.view-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .54rem; }
.view-choice { justify-content: flex-start; text-align: left; min-width: 0; padding: .62rem; }
.view-choice[aria-pressed=true] { color: var(--accent); background: var(--tint); border-color: #8dbeb4; }
.view-choice strong, .sound-setting strong { display: block; font-size: .89rem; }
.view-choice small, .sound-setting small { display: block; color: var(--muted); font-size: .76rem; font-weight: 480; line-height: 1.32; }
.sound-setting { display: flex; align-items: center; justify-content: space-between; gap: .7rem; padding-top: .88rem; border-top: 1px solid var(--line); cursor: pointer; }
.sound-setting strong { margin-bottom: .15rem; }
.sound-setting input {
    appearance: none;
    position: relative;
    flex: none;
    width: 2.65rem;
    height: 1.5rem;
    margin: 0;
    border: 1px solid #829d95;
    border-radius: 1rem;
    background: #d7e3de;
    color: #4e6a63;
    cursor: pointer;
}
.sound-setting input::after { content: ''; position: absolute; left: .18rem; top: .17rem; width: 1.02rem; height: 1.02rem; background: currentColor; border-radius: 50%; }
.sound-setting input:checked { color: #fff; background: var(--accent); border-color: var(--accent); }
.sound-setting input:checked::after { left: calc(100% - 1.2rem); }
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 6.3rem), 1fr)); gap: .6rem; padding: .8rem 1rem 1rem; }
.thumbnail { min-width: 0; display: grid; justify-items: center; gap: .4rem; padding: .5rem; font-size: .8rem; }
.thumbnail[aria-current=page] { border-color: var(--accent); color: var(--accent); }
.thumbnail-art { display: block; position: relative; width: 100%; aspect-ratio: 595 / 842; border-radius: .21rem; overflow: hidden; }
.thumbnail-art.failed::after { animation: none; }
.thumbnail-art canvas { display: block; width: 100%; height: 100%; object-fit: contain; background: var(--surface); }
.share-dialog { width: min(29rem, calc(100% - 1.45rem)); }
.share-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .55rem; padding: 1rem; }
.share-form label, #share-status { grid-column: 1 / -1; }
.share-form input { min-width: 0; font-size: 1rem; padding: .48rem .65rem; border: 1px solid var(--line); border-radius: .48rem; color: inherit; background: var(--surface); }
.share-copy { background: var(--accent); color: #fff; border-color: transparent; }
.share-copy:hover:not(:disabled) { background: #007b71; }
#share-status { margin: 0; color: var(--muted); font-size: .86rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 640px) {
    .action-label { display: none; }
    .top-actions { gap: .05rem; }
    .top-actions .control { min-width: 2.2rem; padding-inline: .35rem; }
    .topbar { padding-inline: .65rem; }
    .brand { gap: .5rem; }
    .brand-mark { width: 2.2rem; height: 2.2rem; }
}
@media (max-width: 410px) {
    .toolbar .control-group .control { min-width: 2.1rem; padding-inline: .3rem; }
    .toolbar .control-group .page-counter { padding-inline: 0; }
    .toolbar .page-status { min-width: 4.3rem; }
    #zoom-reset { min-width: 2.45rem; }
}
@media (max-width: 335px) {
    .brand-mark { display: none; }
    .toolbar .control-group .control { min-width: 1.79rem; }
    .toolbar .page-status { min-width: 3.75rem; }
    .toolbar-inner { gap: .23rem; }
    #zoom-reset { min-width: 2.15rem; }
    .view-choice > .icon { display: none; }
}
.reader-embed { background: #e6eeea; }
.reader-embed .topbar { justify-content: center; padding: .35rem .45rem 0; }
.reader-embed .brand { display: none; }
.reader-embed .top-actions .action-label { display: none; }
.reader-embed .stage { overscroll-behavior: auto; }
.reader-embed .toolbar { padding-block: .05rem .26rem; }
.reader-embed .page-scrubber { width: min(83vw, 26rem); }
@media (max-height: 360px) {
    .reader-embed .topbar { padding-block: .12rem 0; }
    .reader-embed .toolbar .control { min-height: 1.9rem; }
}
