﻿/* ───────────────────────────────────────────────────────────────
   Novela Reader — reader.css
   Shared reader styles (page/scroll mode, nav bar, click zones)
   ─────────────────────────────────────────────────────────────── */

/* ── Theme Variables ─────────────────────────────────────────── */
:root {
    /* Theme colors — theme.js overrides these for Sepia, Dark and Custom */
    --reader-bg: #fdfcf9;       /* page */
    --reader-fg: #1f1f1f;       /* text */
    --reader-muted: #6b6b6b;    /* secondary text */
    --reader-link: #2a5db0;
    --chrome-bg: #ffffff;       /* bars, panel, buttons */
    --chrome-border: #e2e0da;
    --chrome-hover: #f1efe9;
    --grain-opacity: .07;       /* paper texture strength */
    --grain-blend: multiply;
    /* Icon colors */
    --epub-icon-color: var(--reader-fg);
    --epub-icon-hover: var(--reader-fg);
    --epub-openbook-bg: var(--chrome-bg); /* soft beige */
    /* Paging (header height is measured and overridden by reader.js) */
    --reader-header-h: 64px;
    --reader-nav-h: 50px;
    --reader-margin: 4rem;                 /* Settings → Margins (set by reader.js) */
    --page-margin: var(--reader-margin);
}

html, body {
    height: 100%;
}

/* The text size is Novela's alone. Without this, the iPhone's web view enlarges text by itself
   ("text autosizing") — after turning the phone sideways, or in columns it decides are too narrow —
   so the size seemed to change for no reason. 100% = leave it exactly as set. */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* ── Top-right controls ──────────────────────────────────────── */
.epub-top-controls {
    position: absolute;
    top: 10px;
    right: 12px;
    display: flex;
    gap: 12px;
    z-index: 9999;
    color: var(--reader-fg);
}

#epub-openbook-button {
    padding: 6px 10px;
    background: var(--epub-openbook-bg);
    border-radius: 6px;
    text-decoration: none;
    color: var(--epub-icon-color);
    font-size: 0.9rem;
    backdrop-filter: blur(6px);
}

/* ── Buttons ─────────────────────────────────────────────────── */
.nav-btn {
    background: none;
    border: none;
    padding: 6px;
    margin: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--epub-icon-color);
    transition: color 0.15s ease;
}

    .nav-btn:hover {
        color: var(--epub-icon-hover);
    }

/* ── Utility Classes ─────────────────────────────────────────── */
.hidden {
    display: none !important;
}

[hidden] {
    display: none !important;
}

/* Page mode: content flows into columns, one screen = one page */
body.paged {
    overflow: hidden;
}

    body.paged .reader-content {
        position: fixed;
        top: var(--reader-header-h);
        bottom: var(--reader-nav-h);
        left: 0;
        right: 0;
        overflow: hidden;
        padding: 1.5rem var(--page-margin);
        column-count: 1; /* 2 = two-page spread later */
        column-gap: calc(var(--page-margin) * 2); /* must stay 2 × margin */
        column-fill: auto;
    }

        /* Pictures fit on one page. The page is the text area's height less its 1.5rem padding at the
           top and bottom (reader.js measures it: --page-picture-h, and gives pictures 85% of it); room is left free, because a picture sits on a line of text
           and the small gap under that line (plus a book's own margins) would otherwise push a
           full-page picture — a cover — a few pixels too tall, and that sliver spilled onto page 2.
           Width: never wider than one page (--page-col-w, below). "max-width: 100%" alone isn't enough
           on iPad/iPhone/Mac: there WebKit takes 100% of BOTH pages of a two-page spread for an SVG, so
           a cover was drawn across both and spilled onto the right-hand page (measured 2026-11-11:
           1084 px wide, one page 542). The PC's browser takes one page, so it never showed there.
           svg: covers made by Calibre and others are an SVG picture, <svg width="100%" height="100%"
           viewBox="0 0 600 800">. width/height: auto lets it take the shape of its viewBox, and the two
           limits then shrink it, shape kept, to fit one page. */
        body.paged .reader-content img,
        body.paged .reader-content svg {
            max-width: min(100%, var(--page-col-w));
            /* --page-picture-h: measured by reader.js (syncLayoutHeights), as 100vh is wrong in the app */
            max-height: var(--page-picture-h, calc(100vh - var(--reader-header-h) - var(--reader-nav-h) - 4rem));
            break-inside: avoid;
        }

        /* A picture limited both in width and height keeps its shape (a book may give it a height of
           its own, e.g. style="height: 100%", which would otherwise squeeze it) */
        body.paged .reader-content img {
            object-fit: contain;
        }

        body.paged .reader-content svg[height="100%"],
        body.paged .reader-content svg[width="100%"] {
            width: auto;
            height: auto;
        }

    /* The invisible dot at the very end of a chapter's last page (reader.js → fillLastSpread), so the
       last page can be scrolled fully into view (iPad/Mac leave the right margin out otherwise) */
    body.paged .reader-content > .chapter-end-mark {
        position: absolute;
        top: 0;
        width: 1px;
        height: 1px;
        pointer-events: none;
    }

    /* One page's width: the window less the margins on both sides; a two-page spread splits that in
       two, less the gap in the middle (2 × the margin — see column-gap above). */
    body.paged .reader-content {
        --page-col-w: calc(100vw - 2 * var(--page-margin));
    }

    body.paged.two-col .reader-content {
        --page-col-w: calc(50vw - 2 * var(--page-margin));
    }

    /* Narrow (an iPad held upright, a narrow window): one column after all. Not a phone held
       sideways (short as well as narrow, about 830 × 400 points): its two columns are each as wide
       as the phone held upright, so two pages fit there like an open book. */
    @media (max-width: 900px) and (min-height: 501px) {
        body.paged.two-col .reader-content {
            --page-col-w: calc(100vw - 2 * var(--page-margin));
        }
    }

/* Scroll mode: normal page flow (the top: room for the fixed top bar below) */
body.scroll .reader-content {
    max-width: 48rem;
    margin: 0 auto;
    padding: calc(var(--reader-header-h) + 1.5rem) var(--page-margin) calc(var(--reader-nav-h) + 1.5rem);
}

body.scroll .click-zone {
    display: none;
}

/* Scroll mode: the top bar (Library, Contents, bookmark) stays in view while the page scrolls,
   like the bottom bar. Fixed, not sticky: the page itself scrolls, and sticky doesn't hold there. */
body.scroll .reader-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    background: var(--chrome-bg);
    border-bottom: 1px solid var(--chrome-border);
}

/* Bottom nav bar */
.reader-nav-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--reader-nav-h);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    background: var(--chrome-bg);
    border-top: 1px solid var(--chrome-border);
    z-index: 20;
}

    .reader-nav-bar .nav-btn {
        background: none;
        border: none;
        font-size: 1.25rem;
        padding: .4rem .7rem;
        border-radius: 6px;
        cursor: pointer;
    }

        .reader-nav-bar .nav-btn:hover:not(:disabled) {
            background: var(--chrome-hover);
        }

        .reader-nav-bar .nav-btn:disabled {
            opacity: .3;
            cursor: default;
        }

        .reader-nav-bar .nav-btn[data-tooltip] {
            position: relative;
        }

            .reader-nav-bar .nav-btn[data-tooltip]:hover::after {
                content: attr(data-tooltip);
                position: absolute;
                bottom: calc(100% + 8px);
                left: 50%;
                transform: translateX(-50%);
                white-space: nowrap;
                background: #333;
                color: #fff;
                font-size: .8rem;
                padding: .3rem .6rem;
                border-radius: 4px;
                pointer-events: none;
            }

.reader-progress {
    /* Room for "Pages 123–124 of 1084 · 45%" without the arrows moving as the numbers change, and no
       more: it was 15rem, which left wide gaps between the page arrows (seen on the iPad) */
    min-width: 10rem;
    text-align: center;
    font-size: .85rem;
    color: var(--reader-muted);
}

/* The page numbers open the page slider (reader.js → openPageSlider) */
.reader-progress[role="button"] {
    cursor: pointer;
    border-radius: 4px;
}

/* The page slider: pops up above the page numbers, gone again after a few seconds or a tap elsewhere.
   reader.js sets "bottom" so it sits just above the bar, wherever the bar is. */
.page-slider {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    width: min(30rem, calc(100vw - 32px));
    padding: .5rem 1rem .6rem;
    background: var(--chrome-bg);
    color: var(--reader-fg);
    border: 1px solid var(--chrome-border);
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
    z-index: 28;                         /* above the bars (20) and the page, below the panels (30) */
}

    .page-slider[hidden] {
        display: none;
    }

    .page-slider-label {
        text-align: center;
        font-size: .85rem;
        color: var(--reader-muted);
        margin-bottom: .25rem;
    }

    .page-slider input[type=range] {
        width: 100%;
        height: 2rem;                    /* a finger-sized place to grab */
        margin: 0;
        accent-color: var(--reader-link);
    }

/* Click zones on the page margins */
.click-zone {
    position: fixed;
    top: var(--reader-header-h);
    bottom: var(--reader-nav-h);
    width: max(var(--page-margin), 2.5rem);   /* stays easy to click with narrow margins */
    z-index: 10;
    cursor: pointer;
    /* A finger dragging here is the brightness drag (reader.js), not a page scroll: without this,
       iOS (an iPhone held sideways especially) took the drag over to scroll the page and the
       brightness never changed */
    touch-action: none;
}

.left-zone {
    left: 0;
}

.right-zone {
    right: 0;
}

/* ── Two-column spread (page mode only) ───────── */
body.paged.two-col {
    --page-margin: calc(var(--reader-margin) * .75); /* outer margins; center gutter = 2× this */
}

/* In the iPhone/iPad app the margins shrink with the screen (--margin-scale, set by reader.js:
   1 from 1600 points wide, less below), so the center gutter (2 × the margin) shrinks with them */
html.in-app body {
    --page-margin: calc(var(--reader-margin) * var(--margin-scale, 1));
}

html.in-app body.paged.two-col {
    --page-margin: calc(var(--reader-margin) * .75 * var(--margin-scale, 1));
}

    body.paged.two-col .reader-content {
        column-count: 2;
        column-rule: 1px solid var(--chrome-border);
    }

    /* The empty page after a chapter that ends on an odd page, so the last spread is whole
       (reader.js → fillLastSpread). */
    body.paged.two-col .reader-content > .chapter-tail {
        height: 1px;
        break-before: column;
        -webkit-column-break-before: always;
    }

/* Narrow windows fall back to one column */
@media (max-width: 900px) and (min-height: 501px) {      /* see above: not a phone held sideways */
    body.paged.two-col .reader-content {
        column-count: 1;
        column-rule: none;
    }
}

/* ── Text alignment ───────────────────────────── */
body.text-justify .reader-content p {
    text-align: justify;
    hyphens: auto;
}

body.text-left .reader-content p {
    text-align: left;
    hyphens: manual;
}

/* Stop the browser's own scroll adjustments from shifting pages */
body.paged .reader-content {
    overflow-anchor: none;
}

/* ── Header row: Library + Contents (left) · book title (center) · Upgrade, Immersive, Full screen, Bookmark (right) ── */
.reader-header {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 12px;
}

    .reader-header .left,
    .reader-header .right {
        flex: 1;
    }

    .reader-header .center {
        flex: 2;
        text-align: center;
        overflow: hidden;
    }

    .reader-header .book-title {
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* The chapter you're in, under the title. Its line is always reserved, so the
       header doesn't grow (and shift the pages) when the name arrives. */
    .reader-header .chapter-name {
        min-height: 1.25em;
        font-size: .8rem;
        color: var(--reader-muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .reader-header .left {
        display: flex;
        align-items: center;
        gap: .5rem;
    }

    .reader-header .toc-button,
    .reader-header .library-button {
        gap: .4rem;
        font: inherit;
        font-size: .9rem;
        text-decoration: none;
    }

        .reader-header .toc-button i,
        .reader-header .library-button i { font-size: 1.15rem; }

/* ── Phones held upright: a compact top bar, so the book's title has room ──
   (The title was squeezed to "The…" between the words Library and Contents and the buttons.)
   • Library and Contents show just their icons; Upgrade just its gem.
   • The side groups take only the room they need; the title and chapter get all the rest.
   • In the app, Full screen steps aside: on an iPhone, Immersive (the eye) hides the bars instead. */
@media (max-width: 600px) {
    .reader-header { padding: 0 4px; }
    .reader-header .left,
    .reader-header .right { flex: none; }
    .reader-header .left { gap: 0; }
    .reader-header .center { flex: 1; min-width: 0; padding: 0 4px; }
    .reader-header .nav-btn { padding: .4rem .45rem; }
    .reader-header :is(.library-button, .toc-button) span { display: none; }
    .reader-header .plus-pill { font-size: 0; margin-left: .25rem; padding: .3rem .45rem; }
    .reader-header .plus-pill i { font-size: .95rem; }
    html.in-app .reader-header [data-fullscreen-toggle] { display: none; }
}

/* ── Contents panel (slides in from the left, like Settings) ── */
.settings-panel.toc-panel { width: 340px; }

.toc-book {
    padding: .7rem 1rem .8rem;
    border-bottom: 1px solid var(--chrome-border);
}

.toc-book-title { font-weight: 600; }

.toc-book-author {
    font-size: .85rem;
    color: var(--reader-muted);
}

.toc-body {
    flex: 1;
    overflow-y: auto;
    padding: .5rem .5rem 1.5rem;
    font-family: system-ui, "Segoe UI", sans-serif;
    font-size: .92rem;
}

.toc-list,
.toc-list ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

    .toc-list ul { padding-left: 1.1rem; }

.toc-row {
    display: flex;
    align-items: flex-start;
}

.toc-toggle,
.toc-spacer {
    flex: none;
    width: 1.5rem;
    height: 2rem;
}

.toc-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: .75rem;
    color: var(--reader-muted);
    background: none;
    border: none;
    cursor: pointer;
}

    .toc-toggle i { transition: transform .15s ease; transform: rotate(90deg); }
    .toc-item.collapsed > .toc-row .toc-toggle i { transform: none; }
    .toc-item.collapsed > ul { display: none; }

.toc-link {
    flex: 1;
    display: block;
    padding: .4rem .6rem;
    line-height: 1.3;
    color: var(--reader-fg);
    text-decoration: none;
    border-radius: 6px;
}

    a.toc-link:hover { background: var(--chrome-hover); }
    .toc-link.disabled { color: var(--reader-muted); }

    /* You are here */
    .toc-link.current {
        font-weight: 600;
        color: var(--reader-link);
        background: color-mix(in srgb, var(--reader-link) 12%, transparent);
        box-shadow: inset 3px 0 0 var(--reader-link);
    }

.toc-note {
    padding: 1rem;
    color: var(--reader-muted);
}

/* ── Contents | Bookmarks tabs ── */
.panel-tabs {
    display: flex;
    gap: .25rem;
}

    .panel-tabs button {
        font: 600 1rem system-ui, "Segoe UI", sans-serif;
        padding: .3rem .7rem;
        color: var(--reader-muted);
        background: none;
        border: none;
        border-bottom: 2px solid transparent;
        cursor: pointer;
    }

        .panel-tabs button.active {
            color: var(--reader-fg);
            border-bottom-color: var(--reader-link);
        }

.tab-count {
    font-size: .75rem;
    font-weight: 600;
    color: var(--reader-link);
}

/* ── Bookmarks ── */

/* The button at the top right: filled in (and colored) on a bookmarked page */
.reader-header .right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.reader-header .bookmark-button { font-size: 1.25rem; position: relative; }
.reader-header .bookmark-button[aria-pressed="true"] { color: var(--reader-link); }

    .reader-header .bookmark-button[data-tooltip]:hover::after {
        content: attr(data-tooltip);
        position: absolute;
        top: calc(100% + 6px);
        right: 0;
        white-space: nowrap;
        background: #333;
        color: #fff;
        font: .8rem system-ui, "Segoe UI", sans-serif;
        padding: .3rem .6rem;
        border-radius: 4px;
        pointer-events: none;
        z-index: 50;
    }

/* The ribbon hanging from the top of a bookmarked page */
.bookmark-ribbon {
    position: fixed;
    top: var(--reader-header-h);
    right: max(calc(var(--page-margin) * .5 - 9px), 6px);
    z-index: 12;                         /* above the page and click zones */
    width: 18px;
    height: 34px;
    background: linear-gradient(to bottom, color-mix(in srgb, var(--reader-link) 80%, #fff), var(--reader-link));
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 74%, 0 100%);
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .3));
    pointer-events: none;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity .15s ease, transform .15s ease;
}

body.page-bookmarked .bookmark-ribbon { opacity: 1; transform: none; }
body.scroll .bookmark-ribbon { right: max(calc((100vw - 48rem) / 2 - 24px), 6px); }

/* The list in the Bookmarks tab */
.bookmark-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.bookmark-item {
    display: flex;
    align-items: flex-start;
    gap: .25rem;
    border-bottom: 1px solid var(--chrome-border);
}

    .bookmark-item.current { box-shadow: inset 3px 0 0 var(--reader-link); }

.bookmark-go {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: .15rem;
    padding: .55rem .6rem;
    font: inherit;
    text-align: left;
    color: var(--reader-fg);
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

    .bookmark-go:hover { background: var(--chrome-hover); }

.bookmark-where {
    font-weight: 600;
    color: var(--reader-link);
}

.bookmark-snippet {
    font: .95rem/1.4 Georgia, "Times New Roman", serif;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bookmark-date {
    font-size: .75rem;
    color: var(--reader-muted);
}

.bookmark-remove {
    margin-top: .45rem;
    color: var(--reader-muted);
}

    .bookmark-remove:hover { color: #c0392b; }

/* "Bookmark removed · Undo" */
.undo-toast {
    position: fixed;
    bottom: calc(var(--reader-nav-h) + 14px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 45;
    display: flex;
    align-items: center;
    gap: .9rem;
    padding: .45rem .5rem .45rem 1rem;
    font: .9rem system-ui, "Segoe UI", sans-serif;
    color: var(--chrome-bg);
    background: var(--reader-fg);
    border-radius: 18px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
}

    .undo-toast button {
        font: 600 .85rem system-ui, "Segoe UI", sans-serif;
        padding: .25rem .8rem;
        color: var(--reader-fg);
        background: var(--chrome-bg);
        border: none;
        border-radius: 12px;
        cursor: pointer;
    }

#epub-openbook-button {
    font-family: inherit;
}

/* ── Start page: file picker + Recent Books ───────────────── */
.start-page {
    max-width: 40rem;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

.recent-books {
    list-style: none;
    padding: 0;
}

    .recent-books li a {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        padding: .6rem .8rem;
        border-bottom: 1px solid var(--chrome-border);
        color: inherit;
        text-decoration: none;
    }

        .recent-books li a:hover {
            background: var(--chrome-hover);
        }

    .recent-books .recent-title {
        font-weight: 600;
    }

    .recent-books .recent-author {
        color: var(--reader-muted);
    }

/* ── Start page: "Open a book" button ─────────────────────── */
.start-empty {
    min-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.start-open-btn {
    display: inline-flex;
    align-items: center;
    gap: .75rem;
    font: inherit;
    font-size: 1.4rem;
    padding: 1rem 2rem;
    border: 1px solid var(--chrome-border);
    border-radius: 12px;
    background: var(--chrome-bg);
    color: var(--reader-fg);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

    .start-open-btn:hover {
        background: var(--chrome-hover);
    }

    .start-open-btn i {
        font-size: 1.8rem;
    }

    .start-open-btn.small {
        font-size: 1rem;
        padding: .5rem 1rem;
    }

        .start-open-btn.small i {
            font-size: 1.2rem;
        }

.start-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.start-hint {
    color: var(--reader-muted);
}

/* ── Drag an EPUB onto the window ─────────────────────────── */
body.drag-over::after {
    content: "Drop the book to open it";
    position: fixed;
    inset: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--reader-fg);
    background: color-mix(in srgb, var(--reader-bg) 88%, transparent);
    border: 3px dashed var(--reader-muted);
    border-radius: 16px;
    z-index: 10000;
    pointer-events: none;   /* let the drop reach the window */
}

/* ── Status bar groups: left (gear, later) · center · right (A− A+) ── */
.reader-nav-bar .nav-group {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.reader-nav-bar .nav-left,
.reader-nav-bar .nav-right {
    flex: 1;
}

.reader-nav-bar .nav-left {
    padding-left: 1rem;
}

.reader-nav-bar .nav-right {
    justify-content: flex-end;
    padding-right: 1rem;
}

    /* Tooltips at the right edge open leftwards so they aren't cut off */
    .reader-nav-bar .nav-right .nav-btn[data-tooltip]:hover::after {
        left: auto;
        right: 0;
        transform: none;
    }

/* The Library's invisible twins of a book's right-hand buttons (Library.cshtml): they take up the
   same room, so the microphone stays in the same place in the Library as in a book */
.reader-nav-bar .nav-twin {
    visibility: hidden;
    pointer-events: none;
}

.reader-nav-bar .font-btn {
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 600;
    line-height: 1;
}

    .reader-nav-bar .font-btn.smaller {
        font-size: .95rem;
    }

    .reader-nav-bar .font-btn.larger {
        font-size: 1.3rem;
    }

/* ── Text size (set by reader.js from settings / A− A+) ── */
.chapter-content {
    font-size: var(--reader-font-size, 100%);
}

/* ── Library: book cards ─────────────────────────────────── */
.library {
    box-sizing: border-box;     /* padding inside the width, so nothing spills off the right */
    max-width: 72rem;
    width: 100%;
    margin: 1.5rem auto;
    padding: 0 1.5rem 3rem;
}

.library-header {
    /* "sticky": the top line stays at the top of the window while the books scroll under it
       (it used to scroll away with them). It's also the reference for "Continue reading",
       centred on this line, as "relative" was. */
    position: sticky;
    top: 0;
    z-index: 12;                     /* above the book cards, below the sidebar and menus */
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 -1.5rem 1.25rem;       /* the background reaches the Library's edges… */
    padding: .6rem 1.5rem;           /* …while the buttons stay where they were */
    background: var(--chrome-bg);
    background: color-mix(in srgb, var(--chrome-bg) 92%, transparent);
    backdrop-filter: blur(6px);      /* the covers scrolling under it are softened */
    -webkit-backdrop-filter: blur(6px);
}

    /* "Continue reading": the cover of the book you're reading, in the middle of the Library's
       top line. Placed on its own, so it stays put whatever the view's name or the buttons do. */
    .library-header .continue-reading {
        position: absolute;
        left: 40%;
        top: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        align-items: center;
        justify-content: center;
        height: 40px;
        min-width: 28px;
        color: var(--epub-icon-color);
        text-decoration: none;
        border-radius: 3px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
        transition: transform .15s ease, box-shadow .15s ease;
    }

        .library-header .continue-reading:hover {
            transform: translate(-50%, -50%) scale(1.08);
            box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
        }

        .library-header .continue-reading img {
            height: 100%;
            width: auto;
            border-radius: 3px;
        }

        .library-header .continue-reading > i { font-size: 1.6rem; padding: 0 .3rem; }

        /* While the search box is open it needs the room: "Continue reading" (placed on its own, so the
           box would slide under it) steps out of the way until the box folds again (library.js) */
        .library-header.searching .continue-reading {
            opacity: 0;
            pointer-events: none;
        }

    .library-header h2 {
        margin: 0;
    }

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1.5rem 1.25rem;
}

.book-card {
    display: flex;
    flex-direction: column;
    color: inherit;
    text-decoration: none;
}

.book-cover {
    position: relative;
    aspect-ratio: 2 / 3;
    border-radius: 4px;
    overflow: hidden;
    background: var(--chrome-hover);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .18);
    transition: transform .15s ease, box-shadow .15s ease;
}

.book-card:hover .book-cover {
    transform: translateY(-3px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, .22);
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Books without a cover get a plain "typeset" card */
.book-cover-placeholder {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: .5rem;
    padding: 1rem;
    text-align: center;
    background: linear-gradient(160deg, #5b6b7c, #3c4855);
    color: #fff;
    font-family: Georgia, "Times New Roman", serif;
}

    .book-cover-placeholder span {
        font-size: 1rem;
        font-weight: 600;
    }

    .book-cover-placeholder small {
        opacity: .8;
    }

/* Reading progress along the bottom of the cover */
.book-progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    background: rgba(0, 0, 0, .25);
}

    .book-progress div {
        height: 100%;
        background: #f0b429;
    }

/* A book that couldn't be read */
.book-warning {
    position: absolute;
    bottom: 10px;
    right: 6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #c0392b;
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-title {
    margin-top: .5rem;
    font-weight: 600;
    font-size: .9rem;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-author {
    font-size: .8rem;
    color: var(--reader-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Settings gear ────────────────────────────────────────── */
/* Tooltips at the left edge open rightwards so they aren't cut off */
.reader-nav-bar .nav-left .nav-btn[data-tooltip]:hover::after {
    left: 0;
    transform: none;
}

.library-actions {
    display: flex;
    align-items: center;
    gap: .5rem;
}


/* ── Settings panel (slides in from the left) ─────────────── */

.settings-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 320px;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    background: var(--chrome-bg);
    box-shadow: 2px 0 16px rgba(0, 0, 0, .15);
    transform: translateX(-105%);
    transition: transform .2s ease;
    z-index: 30;              /* above the status bar and click zones */
}

    .settings-panel.open {
        transform: none;
    }

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--chrome-border);
}

    .settings-header h3 {
        margin: 0;
        font-size: 1.1rem;
    }

.settings-body {
    overflow-y: auto;
    padding: .25rem 1rem 1.5rem;
    font-family: system-ui, "Segoe UI", sans-serif;
    font-size: .9rem;
}

    .settings-body section {
        padding: .75rem 0;
        border-bottom: 1px solid var(--chrome-border);
    }

    .settings-body h4 {
        margin: 0 0 .6rem;
        font-size: .75rem;
        text-transform: uppercase;
        letter-spacing: .06em;
        color: var(--reader-muted);
    }

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin: .55rem 0;
}

    .setting-row input[type=range] {
        flex: 1;
        min-width: 0;          /* let sliders shrink so − / + and the % always fit */
    }

    /* The value (60%, 24 px…) sits right beside the + button, not pushed to the far right, so the
       slider gets the room. min-width keeps the sliders lined up when values differ in length. */
    .setting-row output {
        min-width: 2.9rem;
        text-align: left;
        font-variant-numeric: tabular-nums;
    }

/* Two/three-way switches built from radio buttons */
.segmented {
    display: inline-flex;
    border: 1px solid var(--chrome-border);
    border-radius: 8px;
    overflow: hidden;
}

    .segmented label {
        position: relative;
        cursor: pointer;
    }

    .segmented input {
        position: absolute;
        opacity: 0;
        pointer-events: none;
    }

    .segmented span {
        display: block;
        padding: .35rem .8rem;
    }

    .segmented label + label span {
        border-left: 1px solid var(--chrome-border);
    }

    .segmented input:checked + span {
        background: var(--reader-fg);
        color: var(--chrome-bg);
    }

    .segmented input:disabled + span {
        opacity: .4;
        cursor: default;
    }

    .segmented input:focus-visible + span {
        outline: 2px solid #4a90d9;
        outline-offset: -2px;
    }

.setting-note {
    color: var(--reader-muted);
    font-size: .8rem;
    margin: .4rem 0;
}

/* Settings → About Novela */
.about-version {
    margin: .2rem 0 .6rem;
    font-weight: 600;
}

/* Feedback: "Something's wrong" / "I have an idea" */
.report-kinds {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem 1rem;
    margin-bottom: .2rem;
    font-size: .9rem;
}
.report-kinds label { display: flex; align-items: center; gap: .35rem; cursor: pointer; }

.report-box textarea {
    width: 100%;
    box-sizing: border-box;
    margin: .3rem 0 .4rem;
    padding: .45rem .55rem;
    font: .9rem system-ui, "Segoe UI", sans-serif;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 6px;
    resize: vertical;
}

    .setting-note button {
        font: inherit;
        background: none;
        border: none;
        padding: 0;
        color: var(--reader-link);
        text-decoration: underline;
        cursor: pointer;
    }

.setting-path {
    font-family: Consolas, monospace;
    font-size: .8rem;
    word-break: break-all;
    background: var(--chrome-hover);
    padding: .4rem .5rem;
    border-radius: 4px;
}

.settings-reset {
    margin-top: 1rem;
    font: inherit;
    padding: .45rem .9rem;
    border: 1px solid var(--chrome-border);
    border-radius: 8px;
    background: var(--chrome-bg);
    cursor: pointer;
}

/* Settings → About: "Take the tour" and "Visit SmartAlixPublishing" — links that look like the buttons */
.about-links {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

    .about-links a.settings-reset {
        display: inline-flex;
        align-items: center;
        gap: .4rem;
        text-decoration: none;
    }

    .settings-reset:hover {
        background: var(--chrome-hover);
    }

/* ── Library toolbar: sort + import menu ──────────────────── */
.library-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Find a book (library.html): a magnifying-glass button; clicked, it opens into a rounded field
   (.open, library.js) with the glass at its left */
.library-search {
    display: flex;
    align-items: center;
    margin-right: .25rem;
}

    .library-search:not(.open) input { display: none; }

    .library-search.open {
        gap: .4rem;
        height: 2.1rem;
        box-sizing: border-box;
        padding: 0 .6rem 0 .3rem;
        border: 1px solid var(--chrome-border);
        border-radius: 8px;
        background: var(--chrome-bg);
    }

    .library-search.open:focus-within { border-color: var(--reader-link); }

    /* Inside the open field, the glass is a plain icon (no raised button around it) */
    .library-search.open .search-toggle {
        background: none;
        border: none;
        box-shadow: none;
        padding: 0 .2rem;
        color: var(--reader-muted);
    }

    .library-search input {
        width: 11rem;
        min-width: 0;
        border: none;
        outline: none;
        background: none;
        /* 1rem (16px) or more: a smaller text box makes the iPhone zoom the page in when it's tapped */
        font: 1rem system-ui, "Segoe UI", sans-serif;
        color: var(--reader-fg);
    }

/* Narrow windows and iPhone: the open search box gets a row of its own, above the buttons */
@media (max-width: 800px) {
    .library-search.open { order: -1; flex: 1 1 100%; margin-right: 0; }
    .library-search.open input { flex: 1; width: auto; }
}

.library-sort {
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-right: .5rem;
    font-size: .9rem;
    color: var(--reader-muted);
}

    .library-sort select {
        font: inherit;
        padding: .3rem .4rem;
        border: 1px solid var(--chrome-border);
        border-radius: 6px;
        background: var(--chrome-bg);
    }

    .library-sort .sort-direction {
        font-size: 1.2rem;
    }

.import-menu {
    position: relative;
}

    .import-menu .menu {
        position: absolute;
        right: 0;
        top: calc(100% + 6px);
        min-width: 13rem;
        background: var(--chrome-bg);
        border: 1px solid var(--chrome-border);
        border-radius: 8px;
        box-shadow: 0 6px 18px rgba(0, 0, 0, .15);
        padding: .3rem 0;
        z-index: 25;
    }

        .import-menu .menu button {
            display: flex;
            align-items: center;
            gap: .6rem;
            width: 100%;
            font: inherit;
            text-align: left;
            padding: .5rem .9rem;
            background: none;
            border: none;
            cursor: pointer;
        }

            .import-menu .menu button:hover {
                background: var(--chrome-hover);
            }

/* Looks like a link, behaves like a button */
.link-btn {
    font: inherit;
    background: none;
    border: none;
    padding: 0;
    color: var(--reader-link);
    text-decoration: underline;
    cursor: pointer;
}

/* ── Import progress / summary ────────────────────────────── */
.import-status {
    position: relative;
    margin: 0 0 1.25rem;
    padding: .7rem 2.5rem .7rem 1rem;
    background: var(--chrome-hover);
    border: 1px solid var(--chrome-border);
    border-radius: 8px;
    font-size: .9rem;
}

    .import-status.busy .import-status-close {
        display: none;       /* can't dismiss while importing */
    }

.import-status-failed {
    margin: .4rem 0 0;
    padding-left: 1.2rem;
    color: #a33;
    font-size: .85rem;
}

    .import-status-failed:empty {
        display: none;
    }

.import-status-close {
    position: absolute;
    top: .4rem;
    right: .4rem;
}

/* ── Themes: page colors, paper grain, book text ──────────────
   theme.js sets the --reader-* / --chrome-* variables and the
   "theme-dark" and "grain" classes on <html>. */
html {
    background: var(--reader-bg);
}

body {
    color: var(--reader-fg);
    background: transparent;
}

html.theme-dark {
    color-scheme: dark;        /* dark scrollbars and form controls */
}

/* Paper grain: fine noise behind the text, so the color reads as paper, not paint.
   Made stronger 2026-11-24: the first version (specks at baseFrequency .85, 7%) blended into a flat
   color on sharp iPhone/iPad screens. Now: larger specks (.55, fewer layers of detail) and about
   double the strength (theme.js sets --grain-opacity), so it's visible when you look for it. */
html.grain body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: var(--grain-opacity);
    mix-blend-mode: var(--grain-blend);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.55' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

/* Book text follows the theme: no white boxes from the book's own styles */
.chapter-content * {
    background-color: transparent !important;
}

html.theme-dark .chapter-content * {
    color: inherit !important;           /* book colors like black text would vanish on dark */
}

.chapter-content a[href] {
    color: var(--reader-link) !important;
}

/* Links that leave the book (a website, an email address) are always underlined, also in Beautiful,
   so they can be told from the text. Links inside the book (notes, contents) keep their own look. */
.chapter-content a[href^="http"],
.chapter-content a[href^="mailto:"] {
    text-decoration: underline !important;
    text-underline-offset: .15em;
}

html.theme-dark .chapter-content img {
    filter: brightness(.9);              /* soften bright pictures at night */
}

/* Controls that had no text color of their own */
.start-open-btn,
.settings-reset,
.library-sort select,
.import-menu .menu button {
    color: var(--reader-fg);
}

/* Theme swatches in the settings panel */
.theme-swatches {
    display: flex;
    gap: .5rem;
}

    .theme-swatches label {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: .25rem;
        font-size: .75rem;
        cursor: pointer;
        position: relative;
    }

    .theme-swatches input[type=radio] {
        position: absolute;
        opacity: 0;
        pointer-events: none;
    }

    .theme-swatches .swatch {
        width: 2.4rem;
        height: 2.4rem;
        border-radius: 50%;
        border: 1px solid var(--chrome-border);
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: Georgia, serif;
        font-size: 1rem;
    }

    .theme-swatches input:checked + .swatch {
        outline: 2px solid var(--reader-link);
        outline-offset: 2px;
    }

    .theme-swatches input:focus-visible + .swatch {
        outline: 2px dashed var(--reader-link);
        outline-offset: 2px;
    }

.swatch-light  { background: #fdfcf9; color: #1f1f1f; }
.swatch-sepia  { background: #f4ecd8; color: #3b2f22; }
.swatch-dark   { background: #1b1b1d; color: #d8d6d0; }
.swatch-custom { background: conic-gradient(#e8c8c8, #e8e2c0, #c8e8cc, #c4dcea, #d8c8ea, #e8c8c8); color: #1f1f1f; }

/* The Custom theme button: an invisible color box covers it, so a tap opens the palette (reader.js) */
.theme-swatches .custom-swatch-picker {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    cursor: pointer;
}


.setting-check {
    display: flex;
    align-items: center;
    gap: .5rem;
    cursor: pointer;
}

/* ── Background pictures ──────────────────────────────────────
   Files live in wwwroot/images and are served at /images/... */

/* Parchment theme: the page itself is parchment */
/* A cream layer over the picture fades it: --parchment-fade 0 = full picture, 0.9 = almost cream.
   (Settings → Theme → Parchment slider; set by theme.js.) */
html.theme-parchment {
    --parchment-cream: rgba(252, 247, 236, var(--parchment-fade, .4));
    background:
        linear-gradient(var(--parchment-cream), var(--parchment-cream)) fixed,
        url("/novela-reader/images/parchment.jpg") center / cover fixed,
        var(--reader-bg);
}

.swatch-parchment {
    background: #efe0c2 url("/novela-reader/images/parchment.jpg") center / cover;
    color: #3a2a18;
}

/* Library: bookshelves behind the cards */
.library-backdrop {
    display: none;
}

html.library-bg .library-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: -1; /* behind everything on the page */
    pointer-events: none;
    background: url("/images/library-shelves.jpg") center / cover no-repeat;
    /*background: url("/images/hero-AI-5.png") center / cover no-repeat;*/
    /*background: url("/images/parchment.jpg") center / cover no-repeat;*/
    mix-blend-mode: multiply; /* takes on the theme's page color */
}

/* Dark themes: dim the shelves so the page stays dark */
html.theme-dark.library-bg .library-backdrop {
    mix-blend-mode: normal;
    filter: brightness(.28) saturate(.7);
}

/* Parchment already has a picture; use the shelves as-is over it */
html.theme-parchment.library-bg .library-backdrop {
    mix-blend-mode: normal;
}

/* ── Shelf cards on the bookshelf picture ──
   Instead of a flat grey box, each shelf is see-through: the picture shows through a light
   frosted glass, the covers stand on a small wooden board, and the name sits below it.
   --shelf-glass is how much the card hides the picture (0% = clear, 100% = solid);
   --shelf-blur softens the picture behind the card. */
html.library-bg .shelf-grid {
    --shelf-glass: 10%;
    --shelf-blur: 2px;
}

html.library-bg .shelf-card {
    background: color-mix(in srgb, var(--chrome-bg) var(--shelf-glass), transparent);
    backdrop-filter: blur(var(--shelf-blur));
    border: 1px solid color-mix(in srgb, #fff 35%, transparent);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 2px 10px rgba(0, 0, 0, .12);
}

    html.library-bg .shelf-card:hover {
        background: color-mix(in srgb, var(--chrome-bg) calc(var(--shelf-glass) + 15%), transparent);
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35), 0 8px 20px rgba(0, 0, 0, .22);
    }

    html.library-bg .shelf-card.new-shelf {
        background: color-mix(in srgb, var(--chrome-bg) 8%, transparent);
        border: 2px dashed color-mix(in srgb, var(--reader-fg) 35%, transparent);
    }

    /* The covers stand on a wooden board (the shelf's own color shows as a thin edge on its front) */
    html.library-bg .shelf-fan.large::after {
        left: -6%;
        right: -6%;
        bottom: -9px;
        height: 9px;
        border-radius: 2px;
        background:
            linear-gradient(to bottom, transparent 70%, var(--shelf-color, transparent) 70%),
            linear-gradient(to bottom, #b07a4f, #7a4c2c);
        box-shadow: 0 3px 5px rgba(0, 0, 0, .35);
    }

    html.library-bg .shelf-card .shelf-name { margin-top: 1rem; }

    /* Names and counts stay readable over the picture */
    html.library-bg .shelf-card :is(.shelf-name, .shelf-count) {
        text-shadow: 0 0 6px var(--reader-bg), 0 0 2px var(--reader-bg);
    }

/* Dark themes: a darker glass, a softer edge */
html.library-bg.theme-dark .shelf-card {
    border-color: color-mix(in srgb, #fff 12%, transparent);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 2px 10px rgba(0, 0, 0, .4);
}

/* Keep card text readable on the picture */
html.library-bg .card-title,
html.library-bg .card-author {
    text-shadow: 0 0 6px var(--reader-bg);
}

/* A setting that doesn't apply to the current choice */
.setting-row.disabled {
    opacity: .45;
}

/* − / + buttons beside the sliders in Settings */
.step-btn {
    flex: none;
    width: 1.8rem;
    height: 1.8rem;
    font: inherit;
    font-size: 1.05rem;
    line-height: 1;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 50%;
    cursor: pointer;
}

    .step-btn:hover:not(:disabled) {
        background: var(--chrome-hover);
    }

    .step-btn:disabled {
        cursor: default;
    }

/* Library: room at the bottom so the last row of cards clears the bottom bar */
.library {
    padding-bottom: calc(var(--reader-nav-h) + 2rem);
}

/* ════════════════════════════════════════════════════════════
   Shelves (library.js)
   ════════════════════════════════════════════════════════════ */

/* Sidebar + main area side by side */
.library-layout {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    align-items: start;
    transition: grid-template-columns .2s ease;
}

/* The sidebar is pinned to the window, so the books keep to the second column */
.library-layout > .library {
    grid-column: 2;
}

/* Folded sidebar: the button beside the heading hides it... */
.library-layout.sidebar-folded {
    grid-template-columns: 0 minmax(0, 1fr);
}

    .library-layout.sidebar-folded .library-sidebar {
        visibility: hidden;
        padding-left: 0;
        padding-right: 0;
        border-right: none;
    }

/* ...but it comes back while you drag a book, when it's holding the shelves to drop on */
body.dragging-books .library-layout.sidebar-folded.sidebar-has-shelves {
    grid-template-columns: 250px minmax(0, 1fr);
}

    body.dragging-books .library-layout.sidebar-folded.sidebar-has-shelves .library-sidebar {
        visibility: visible;
        padding: 1.25rem .75rem 1.5rem 1rem;
        border-right: 1px solid var(--chrome-border);
    }

/* The sidebar button beside the view name: a little larger than the other icons */
.library-heading .sidebar-toggle {
    font-size: 1.45rem;
    padding: 4px 6px;
    margin-right: .6rem;       /* space between the sidebar button and the view's name */
}

/* ── Raised (3D) buttons on the Library's top line ──
   On while Settings → "Raised buttons" is ticked (theme.js puts .raised-buttons on <html>).
   To retract it: untick it — or delete this whole section.
   Light from above: a gradient from a lighter top to a darker bottom, a shine on the top edge,
   a shadow below. Buttons lift a little under the mouse and sink in while pressed. */

/* The buttons' colors (--raised-top, --raised-bottom, --raised-text, --raised-border) come from
   theme.js: each theme's own color, or your color (Settings → Theme → Button style).
   The theme colors are the "button" entries in theme.js's THEMES; the fallback is in nav-buttons.css. */

html.raised-buttons .library-header :is(.sidebar-toggle, .shelf-header-menu, .lib-btn, .sort-direction, .library-search:not(.open) .search-toggle, .start-open-btn, .library-sort select) {
    height: 2.1rem;
    box-sizing: border-box;
    border-radius: 8px;
    color: var(--raised-text);
    background: linear-gradient(to bottom, var(--raised-top), var(--raised-bottom));
    border: 1px solid var(--raised-border);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, .35),    /* shine along the top edge */
        0 1px 0 rgba(0, 0, 0, .1),
        0 2px 4px rgba(0, 0, 0, .25);              /* shadow under the button */
    text-shadow: 0 -1px 0 rgba(0, 0, 0, .25);      /* letters pressed slightly into the surface */
    transition: box-shadow .12s ease, transform .12s ease, filter .12s ease;
}

    /* The dropdown's list keeps the page's normal colors */
    html.raised-buttons .library-header .library-sort select option {
        color: var(--reader-fg);
        background: var(--chrome-bg);
        text-shadow: none;
    }

    /* Icon-only buttons are square */
    html.raised-buttons .library-header :is(.sidebar-toggle, .shelf-header-menu, .sort-direction, .library-search:not(.open) .search-toggle) {
        width: 2.1rem;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    html.raised-buttons .library-header .sort-direction { font-size: 1.05rem; }

    html.raised-buttons .library-header .library-sort select { padding: 0 .5rem; cursor: pointer; }

    /* While the sidebar is hidden, its button's icon turns gold (blue wouldn't show on the gradient) */
    html.raised-buttons .library-header .sidebar-toggle[aria-expanded="false"] { color: var(--raised-active, #ffd27a); }

    html.raised-buttons .library-header :is(.sidebar-toggle, .shelf-header-menu, .lib-btn, .sort-direction, .library-search:not(.open) .search-toggle, .start-open-btn, .library-sort select):hover {
        filter: brightness(1.08);
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, .35),
            0 1px 0 rgba(0, 0, 0, .1),
            0 4px 8px rgba(0, 0, 0, .3);           /* lifts a little */
        transform: translateY(-1px);
    }

    /* Pressed: pushed in, only while the mouse is down */
    html.raised-buttons .library-header :is(.sidebar-toggle, .shelf-header-menu, .lib-btn, .sort-direction, .library-search:not(.open) .search-toggle, .start-open-btn):active {
        transform: translateY(1px);
        filter: brightness(.92);
        background: linear-gradient(to top, var(--raised-top), var(--raised-bottom));   /* the light flips */
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, .35);
    }

.sidebar-toggle[aria-expanded="false"] {
    color: var(--reader-link);
}

.library-sidebar {
    position: fixed;                     /* pinned to the window, not the page */
    top: 10px;                           /* from the very top… */
    bottom: var(--reader-nav-h);         /* …down to the bottom bar, so nothing is cut off */
    left: 0;
    width: 250px;                        /* same as the sidebar's column in .library-layout */
    z-index: 15;                         /* above the book cards, below menus and panels */
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;         /* never scroll sideways */
    padding: 1.25rem .75rem 1.5rem 1rem;
    border-right: 1px solid var(--chrome-border);
    background: color-mix(in srgb, var(--chrome-bg) 82%, transparent);
    backdrop-filter: blur(2px);
    font-family: system-ui, "Segoe UI", sans-serif;
    font-size: .88rem;
}

/* Phones held upright: the Library's top line in two tidy rows instead of four scattered ones.
   Row 1: the sidebar button, the view's name and Shelves / All Books (and "Continue reading" at the right).
   Row 2: Find · Select · Sort · Organize · Import, side by side; Select, Organize and Import show
   just their icons (their words take too much room), and the word "Sort" steps aside. */
@media (max-width: 600px) {
    .library { padding-left: 1rem; padding-right: 1rem; }
    .library-header { flex-wrap: wrap; row-gap: .55rem; margin-left: -1rem; margin-right: -1rem; padding: .5rem 1rem; }
    .library-heading { --view-gap: 12px; min-width: 0; }
    .library-title { white-space: nowrap; font-size: 1.4rem; }

    /* Continue reading: at the end of row 1 instead of floating over the middle */
    .library-header .continue-reading {
        position: static;
        transform: none;
        margin-left: auto;
        height: 36px;
    }
        .library-header .continue-reading:hover { transform: scale(1.08); }

    .library-header .library-actions {
        flex: 1 0 100%;
        justify-content: space-between;
        gap: .4rem;
        margin-left: 0;
    }

    .library-sort { margin-right: 0; }
    .library-sort label { display: none; }

    /* Icon only: the button's words are shrunk to nothing (they still name it for VoiceOver) */
    .library-header :is([data-select-toggle], [data-edit-shelf], [data-organize]) { font-size: 0; padding-left: .55rem; padding-right: .55rem; }
    .library-header :is([data-select-toggle], [data-edit-shelf], [data-organize]) i { font-size: 1.05rem; }
    .library-header .import-menu .start-open-btn.small span { display: none; }
}

/* Narrow screens (an iPhone, a narrow window): the sidebar is a drawer instead of a column.
   It's tucked away off the left edge, and the sidebar button slides it in over the books
   (.sidebar-open, library.js); a tap beside it, or choosing a shelf, slides it away again.
   (Before, it took half an iPhone's width, and the books were squeezed into the other half.)
   The PC's "folded" setting doesn't apply here: the drawer always starts closed. */
@media (max-width: 800px) {
    .library-layout,
    .library-layout.sidebar-folded,
    body.dragging-books .library-layout.sidebar-folded.sidebar-has-shelves {
        grid-template-columns: minmax(0, 1fr);
    }

    .library-layout > .library { grid-column: 1; }

    .library-layout .library-sidebar,
    .library-layout.sidebar-folded .library-sidebar {
        visibility: visible;
        top: 0;
        width: min(80vw, 300px);
        z-index: 30;                                 /* above the Library's top line too */
        padding: 1.25rem .75rem 1.5rem 1rem;
        background: var(--chrome-bg);
        box-shadow: 4px 0 18px rgba(0, 0, 0, .25);
        transform: translateX(-110%);                /* off the left edge (and its shadow with it) */
        transition: transform .2s ease;
    }

    .library-layout.sidebar-open .library-sidebar,
    body.dragging-books .library-layout.sidebar-has-shelves .library-sidebar {
        transform: none;
    }
}

.sidebar-heading {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--reader-muted);
    margin: 0 0 .5rem .25rem;
}

.sidebar-hint {
    margin: 0 0 .75rem .25rem;
    font-size: .78rem;
    color: var(--reader-muted);
}

.sidebar-divider {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: .9rem .25rem .4rem;
    padding-top: .7rem;
    border-top: 1px solid var(--chrome-border);
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--reader-muted);
}

.sidebar-divider { flex-wrap: wrap; row-gap: .35rem; }

/* Recent · A–Z · Manual — on its own line under "Your shelves" */
.shelf-order {
    display: flex;
    flex-basis: 100%;
    gap: .15rem;
    text-transform: none;
    letter-spacing: 0;
}

    .shelf-order button {
        white-space: nowrap;
        font: inherit;
        font-size: .75rem;
        padding: .1rem .4rem;
        border: none;
        border-radius: 4px;
        background: none;
        color: var(--reader-muted);
        cursor: pointer;
    }

        .shelf-order button.active {
            background: var(--reader-fg);
            color: var(--chrome-bg);
        }

/* One shelf in the sidebar */
.shelf-item {
    box-sizing: border-box;     /* padding inside the 100% width */
    display: flex;
    align-items: center;
    gap: .6rem;
    width: 100%;
    padding: .4rem .5rem;
    margin: 1px 0;
    font: inherit;
    text-align: left;
    color: var(--reader-fg);
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
}

    .shelf-item:hover { background: var(--chrome-hover); }
    .shelf-item.active { background: var(--chrome-hover); font-weight: 600; }

    /* Your shelves show their color as a thin stripe on the left */
    .shelf-item.has-color { box-shadow: inset 3px 0 0 var(--shelf-color); }

.shelf-icon {
    width: 1.6rem;
    text-align: center;
    font-size: 1rem;
    color: var(--reader-muted);
}

.shelf-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shelf-item-count,
.shelf-item-hint {
    color: var(--reader-muted);
    font-size: .78rem;
}

/* New shelf: a dashed drop target */
.shelf-item.new-shelf {
    margin-top: .35rem;
    border: 1px dashed var(--chrome-border);
    color: var(--reader-muted);
}

/* One book in the sidebar */
.sidebar-book {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .35rem .4rem;
    border-radius: 6px;
    color: inherit;
    text-decoration: none;
    cursor: grab;
}

    .sidebar-book:hover { background: var(--chrome-hover); }

    .sidebar-book img,
    .sidebar-book-cover {
        flex: none;
        width: 28px;
        height: 42px;
        object-fit: cover;
        border-radius: 2px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    }

.sidebar-book-cover {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #5b6b7c;
    color: #fff;
    font-family: Georgia, serif;
}

.sidebar-book-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-book-title,
.sidebar-book-author,
.sidebar-book-shelves {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-book-title { font-weight: 600; }
.sidebar-book-author { font-size: .78rem; color: var(--reader-muted); }

/* "On: Sci-Fi, To Read" — only while hovering, so the list stays calm */
.sidebar-book-shelves {
    display: none;
    font-size: .74rem;
    color: var(--reader-link);
}

@media (hover: hover) {
    .sidebar-book:hover .sidebar-book-shelves { display: block; }
}

.sidebar-book-percent {
    font-size: .74rem;
    color: var(--reader-muted);
    font-variant-numeric: tabular-nums;
}

/* ── Library heading with back arrow, view switch ── */
.library-heading {
    display: flex;
    align-items: center;
    gap: .35rem;
}

.library-back { font-size: 1.3rem; }

/* The view's name is always at least as wide as "All Books", so the button beside it
   stays put when you switch between All Books and Shelves (an invisible "All Books"
   shares the same grid cell as the real name and sets the minimum width) */
.library-title {
    display: inline-grid;
}

    .library-title > span,
    .library-title::after {
        grid-area: 1 / 1;
    }

    .library-title::after {
        content: "All Books";
        visibility: hidden;
        height: 0;
    }

/* The one view button: it always names the OTHER view — the one a click takes you to.
   --view-gap is the space between the view's name and the button (change it here). */
.library-heading { --view-gap: 20px; }
.view-switch { margin-left: var(--view-gap); }

/* The Library's top line: [sidebar] View name ··· [Shelves]        Select · Sort ▾ ⇅ · Organize · Import */
.library-header .library-actions { margin-left: auto; }

/* Import is the same size as the other buttons on this line */
.library-header .import-menu .start-open-btn.small {
    font-size: .88rem;
    padding: .35rem .8rem;
    gap: .35rem;
    border-radius: 6px;
    box-shadow: none;
}

    .library-header .import-menu .start-open-btn.small i { font-size: 1rem; }

/* Hover labels for the buttons in the Library's heading (sidebar, view, shelf options) */
.library-heading [data-tooltip] { position: relative; }

    .library-heading [data-tooltip]:hover::after {
        content: attr(data-tooltip);
        position: absolute;
        bottom: calc(100% + 8px);              /* above the button, so it never covers the books */
        left: 50%;
        transform: translateX(-50%);
        white-space: nowrap;
        background: #333;
        color: #fff;
        font: .8rem system-ui, "Segoe UI", sans-serif;
        padding: .3rem .6rem;
        border-radius: 4px;
        pointer-events: none;
        z-index: 50;
    }

/* ── Shelf cards (Shelves view) ── */
.shelf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 1.75rem 1.25rem;
}

.shelf-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem .75rem .85rem;
    border-radius: 10px;
    border: 1px solid transparent;
    background: color-mix(in srgb, var(--chrome-bg) 70%, transparent);
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}

    .shelf-card:hover {
        transform: translateY(-3px);
        box-shadow: 0 6px 16px rgba(0, 0, 0, .15);
    }

    .shelf-card.new-shelf {
        border: 2px dashed var(--chrome-border);
        background: transparent;
    }

.shelf-name {
    margin-top: .7rem;
    font-weight: 600;
    text-align: center;
}

.shelf-count {
    font-size: .8rem;
    color: var(--reader-muted);
}

/* Fanned covers — the heart of a shelf's look */
.shelf-fan {
    position: relative;
    flex: none;
}

    .shelf-fan.large { width: 120px; height: 120px; }
    .shelf-fan.small { width: 28px; height: 28px; }

    .shelf-fan > img,
    .shelf-fan > .fan-cover {
        position: absolute;
        bottom: 0;
        left: 50%;
        width: 52%;
        aspect-ratio: 2 / 3;
        object-fit: cover;
        border-radius: 2px;
        box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
        transform-origin: 50% 100%;
    }

    .shelf-fan .fan-0 { transform: translateX(-50%) rotate(0deg); z-index: 3; }
    .shelf-fan .fan-1 { transform: translateX(-80%) rotate(-12deg); z-index: 2; }
    .shelf-fan .fan-2 { transform: translateX(-20%) rotate(12deg); z-index: 1; }

    .shelf-fan .fan-cover {
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--shelf-color, #5b6b7c);
        color: #fff;
        font-family: Georgia, serif;
    }

    .shelf-fan.small .fan-cover { font-size: .5rem; }

    /* The shelf's color as a little plinth under the fan */
    .shelf-fan.large::after {
        content: "";
        position: absolute;
        left: 8%;
        right: 8%;
        bottom: -6px;
        height: 6px;
        border-radius: 3px;
        background: var(--shelf-color, var(--chrome-border));
    }

    .shelf-fan.empty {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 2rem;
        color: var(--reader-muted);
    }

        .shelf-fan.empty::after { display: none; }

.shelf-empty {
    padding: 2rem 0;
    color: var(--reader-muted);
    text-align: center;
}

/* ── Book cards: ⋯ menu, × remove, % badge, hover shelves ── */
.card-btn {
    position: absolute;
    top: 6px;
    width: 26px;
    height: 26px;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: .85rem;
    color: #fff;
    background: rgba(0, 0, 0, .55);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.card-menu { right: 6px; }
.card-remove { left: 6px; }

/* Shown by pointing with a mouse only — "(hover: hover)". On an iPad (a finger can't point), something
   that appears on hover makes the first tap only "point" and the book opens on the second tap. */
@media (hover: hover) {
    .book-card:hover .card-menu { display: flex; }
    .library.on-user-shelf .book-card:hover .card-remove { display: flex; }
}

/* Touch screens (iPad, iPhone — "(hover: none)"): the ⋯ is always there, so the book's menu is one tap
   away, and the iPad's own long-press menu (Open / Share / Save to Photos…) is switched off on the
   cards (-webkit-touch-callout). A long press still picks a book up to drag it to a shelf. */
@media (hover: none) {
    .book-card .card-menu,
    .shelf-card .shelf-card-menu { display: flex; }

    .book-card,
    .shelf-card,
    .sidebar-book,
    .continue-reading { -webkit-touch-callout: none; }
}

/* "37%" or "✓ Finished" on every started book (top-left, where the eye looks first).
   It steps aside for the select-mode tick box and the shelf's × button, which use that corner. */
.book-percent {
    position: absolute;
    top: 6px;
    left: 6px;
    display: block;
    padding: .1rem .4rem;
    font-size: .72rem;
    font-weight: 600;
    color: #fff;
    background: rgba(0, 0, 0, .6);
    border-radius: 10px;
}

.book-percent.finished {
    background: rgba(38, 110, 62, .85);
}

.library.selecting .book-percent { display: none; }
@media (hover: hover) {
    .library.on-user-shelf .book-card:hover .book-percent { display: none; }
}

.card-shelves {
    font-size: .74rem;
    color: var(--reader-link);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    visibility: hidden;          /* keeps its space so cards don't jump */
}

@media (hover: hover) {
    .book-card:hover .card-shelves { visibility: visible; }
}

/* Selected (Ctrl/Shift+click, or ticked in select mode) */
.book-card.selected .book-cover {
    outline: 3px solid var(--reader-link);
    outline-offset: 3px;
}

/* ── Select mode: checkboxes on the covers ── */
.lib-btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font: inherit;
    font-size: .88rem;
    padding: .35rem .8rem;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
}

    .lib-btn:hover { background: var(--chrome-hover); }

    .lib-btn.primary {
        color: #fff;
        background: var(--reader-link);
        border-color: var(--reader-link);
    }

.shelf-header-menu { font-size: 1.2rem; }

.card-check {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 2;
    width: 26px;
    height: 26px;
    display: none;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    font-size: 1rem;
    color: transparent;                       /* the tick only shows when ticked */
    background: rgba(255, 255, 255, .85);
    border: 2px solid rgba(0, 0, 0, .45);
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}

.library.selecting .card-check { display: flex; }
.library.selecting .book-card .card-btn { display: none !important; }   /* no ⋯ or × while ticking */
.library.selecting .book-card { cursor: pointer; }

/* Ticked: blue (selected, or being added to the shelf) */
.library.selecting .book-card.selected .card-check {
    color: #fff;
    background: var(--reader-link);
    border-color: var(--reader-link);
}

/* Edit shelf: already on the shelf — ticked in the shelf's own color */
.library.selecting .book-card.on-shelf .card-check {
    color: #fff;
    background: var(--edit-color, var(--reader-link));
    border-color: var(--edit-color, var(--reader-link));
}

.library.selecting .book-card.on-shelf .book-cover {
    outline: 3px solid var(--edit-color, var(--reader-link));
    outline-offset: 3px;
}

/* Edit shelf: unticked — will be removed (red box with a minus, cover faded) */
.library.selecting .book-card.will-remove .card-check {
    background: rgba(255, 255, 255, .9);
    border-color: #b03a2e;
}

    .library.selecting .book-card.will-remove .card-check i { display: none; }

    .library.selecting .book-card.will-remove .card-check::after {
        content: "−";
        color: #b03a2e;
        font-weight: 700;
        line-height: 1;
    }

.library.selecting .book-card.will-remove .book-cover img,
.library.selecting .book-card.will-remove .book-cover-placeholder {
    opacity: .45;
}

/* The bar under the heading: what's ticked, and what to do with it */
.select-bar {
    position: sticky;
    top: var(--library-header-h, 0px);   /* just under the Library's top line, which stays put too (library.js measures it) */
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    margin: -.5rem 0 1.25rem;
    padding: .55rem .6rem .55rem 1rem;
    font: .9rem system-ui, "Segoe UI", sans-serif;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 10px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .1);
}

    .select-bar .bar-text {
        display: inline-flex;
        align-items: center;
        flex-wrap: wrap;
        gap: .3rem;
        color: var(--reader-muted);
    }

        .select-bar .bar-text strong { color: var(--reader-fg); }

    .select-bar .bar-actions {
        display: inline-flex;
        gap: .4rem;
    }

    .select-bar .bar-add { color: #2e7d4f; font-weight: 600; }
    .select-bar .bar-remove { color: #b03a2e; font-weight: 600; }

/* Shelf cards: ⋯ appears on hover (Rename / Color / Delete) */
.shelf-card { position: relative; }
.shelf-card-menu { right: 8px; top: 8px; }
@media (hover: hover) {
    .shelf-card:hover .shelf-card-menu { display: flex; }
}

.sidebar-book.selected {
    background: color-mix(in srgb, var(--reader-link) 18%, transparent);
}

/* ── Dragging ── */
body.dragging-books [data-drop-shelf] {
    border-color: var(--reader-link);
    border-style: dashed;
}

.drop-hover {
    background: color-mix(in srgb, var(--reader-link) 18%, transparent) !important;
    border-color: var(--reader-link) !important;
    transform: scale(1.04);
}

.drop-done {
    animation: shelf-got-it .6s ease;
}

@keyframes shelf-got-it {
    0% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

/* Arranging: a bar shows where the dragged shelf or book will go */
body.dragging-shelf [data-drag-shelf] { cursor: grabbing; }

.drop-before,
.drop-after {
    position: relative;
}

    .drop-before::before,
    .drop-after::before {
        content: "";
        position: absolute;
        z-index: 5;
        background: var(--reader-link);
        border-radius: 2px;
        pointer-events: none;
    }

    /* In the grids (shelf cards, book covers) the bar stands between two cards */
    .drop-before::before { left: -9px; top: 0; bottom: 0; width: 4px; }
    .drop-after::before { right: -9px; top: 0; bottom: 0; width: 4px; }

    /* In the sidebar list it lies between two rows */
    .library-sidebar .drop-before::before { left: 0; right: 0; top: -3px; bottom: auto; width: auto; height: 3px; }
    .library-sidebar .drop-after::before { left: 0; right: 0; bottom: -3px; top: auto; width: auto; height: 3px; }

.drag-badge {
    position: fixed;
    top: -100px;
    left: -100px;
    padding: .4rem .8rem;
    font: 600 .85rem system-ui, sans-serif;
    color: #fff;
    background: var(--reader-link);
    border-radius: 14px;
}

/* ── Menus (right-click / ⋯) and the name box ── */
.lib-menu {
    position: fixed;
    z-index: 40;
    min-width: 13rem;
    max-width: 18rem;
    padding: .35rem 0;
    font: .9rem system-ui, "Segoe UI", sans-serif;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
}

.menu-heading {
    padding: .3rem .9rem .45rem;
    font-size: .75rem;
    font-weight: 600;
    color: var(--reader-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-row {
    display: flex;
    align-items: center;
    gap: .55rem;
    width: 100%;
    padding: .42rem .9rem;
    font: inherit;
    text-align: left;
    color: inherit;
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
}

    .menu-row:hover { background: var(--chrome-hover); }
    .menu-row.danger { color: #b03a2e; }

.menu-check {
    width: 1rem;
    text-align: center;
    font-weight: 700;
    color: var(--reader-link);
}

.menu-dot {
    width: .65rem;
    height: .65rem;
    border-radius: 50%;
}

/* Shelf color: swatches in the shelf's right-click menu */
.menu-label {
    padding: .35rem .9rem .2rem;
    font-size: .75rem;
    color: var(--reader-muted);
}

/* The book menu's shelves: a long list scrolls inside the menu, so the menu fits the window */
.menu-shelves {
    max-height: 45vh;
    overflow-y: auto;
}

.menu-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    padding: .2rem .9rem .45rem;
}

.menu-swatch {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--chrome-border);
}

    .menu-swatch:hover { transform: scale(1.12); }
    .menu-swatch.active { border-color: var(--chrome-bg); box-shadow: 0 0 0 2px var(--reader-fg); }

    .menu-swatch.custom {
        background: var(--chrome-hover);
        color: var(--reader-muted);
        font-size: .75rem;
    }

        /* The real color picker sits invisibly over the palette icon */
        .menu-swatch.custom input {
            position: absolute;
            inset: 0;
            width: 100%;
            height: 100%;
            opacity: 0;
            cursor: pointer;
        }

/* Reading page: the "New shelf" name box inside the shelf menu */
.menu-name-row {
    padding: .3rem .9rem .4rem;
}

    .menu-name-row .shelf-name-input { width: 100%; box-sizing: border-box; }

.nav-btn[data-shelf-button].active {
    color: var(--reader-link);
}

.menu-divider {
    margin: .3rem 0;
    border-top: 1px solid var(--chrome-border);
}

.menu-note {
    padding: .25rem .9rem;
    margin: 0;
}

.name-box {
    padding: .5rem .75rem .6rem;
}

    .name-box .menu-heading { padding: 0 0 .4rem; }

.shelf-name-input {
    width: 100%;
    box-sizing: border-box;
    font: inherit;
    padding: .4rem .5rem;
    color: var(--reader-fg);
    background: var(--reader-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 6px;
}

/* ── Recently deleted ── */
.shelf-grid.deleted-list {
    display: block;
}

.deleted-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .75rem .5rem;
    border-bottom: 1px solid var(--chrome-border);
}

    .deleted-row .shelf-name { margin: 0; text-align: left; }
    .deleted-row .settings-reset { margin: 0; }

.deleted-text { flex: 1; }

.link-btn.danger { color: #b03a2e; }

/* ── Brightness: a dark layer over everything (theme.js sets --dim) ── */
html::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 9990;
    pointer-events: none;        /* clicks go straight through */
    background: #000;
    opacity: var(--dim, 0);
}

/* Shown while dragging in the left margin */
.brightness-indicator {
    position: fixed;
    left: 50%;
    top: 40%;
    transform: translate(-50%, -50%);
    z-index: 9995;               /* above the dark layer, so it's always readable */
    padding: .6rem 1.1rem;
    font: 600 1.1rem system-ui, "Segoe UI", sans-serif;
    color: #fff;
    background: rgba(0, 0, 0, .7);
    border-radius: 12px;
    pointer-events: none;
    transition: opacity .3s ease;
}

    .brightness-indicator.hide {
        opacity: 0;
    }

.left-zone {
    cursor: ns-resize;           /* hints: drag up/down for brightness (a click still turns back) */
}

/* ── Library hover preview ── */
.book-preview {
    position: fixed; /* placed by library.js next to the card */
    z-index: 50;
    width: 280px;
    padding: .7rem .85rem;
    background: var(--chrome-bg);
    color: var(--reader-fg);
    border: 1px solid var(--chrome-border);
    border-radius: 8px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
    pointer-events: none; /* the mouse passes through it, so it never gets "stuck" */
    font-size: .85rem;
    line-height: 1.45;
}

.book-preview-chapter {
    font-weight: 600;
    margin-bottom: .35rem;
    color: var(--reader-link);
}

.book-preview-text {
    font-family: Georgia, serif;
    font-style: italic;
    color: var(--reader-muted);
}

/* ── "Back to where you were" (after a jump with Contents or a link) ── */
.return-pill {
    position: fixed;
    left: 50%;
    bottom: calc(var(--reader-nav-h) + 12px);
    transform: translateX(-50%);
    z-index: 25;                 /* above the page and click zones, below the panels */
    display: flex;
    align-items: center;
    max-width: calc(100vw - 2rem);
    font: .88rem system-ui, "Segoe UI", sans-serif;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
    overflow: hidden;
}

    .return-pill button {
        font: inherit;
        color: inherit;
        background: none;
        border: none;
        cursor: pointer;
    }

    .return-pill .return-back {
        display: flex;
        align-items: center;
        gap: .45rem;
        min-width: 0;
        padding: .5rem .5rem .5rem 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

        .return-pill .return-back i { color: var(--reader-link); }

    .return-pill .return-close {
        padding: .5rem .85rem .5rem .5rem;
        color: var(--reader-muted);
    }

    .return-pill button:hover { background: var(--chrome-hover); }

/* ── Removing books: Remove button, Undo message, removed books in "Recently deleted" ── */
.lib-btn.danger { color: #b03a2e; }

.lib-toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--reader-nav-h) + 14px);
    transform: translateX(-50%);
    z-index: 45;
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: calc(100vw - 2rem);
    padding: .6rem .7rem .6rem 1.1rem;
    font: .9rem system-ui, "Segoe UI", sans-serif;
    color: var(--chrome-bg);
    background: var(--reader-fg);
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}

    .lib-toast span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

.lib-toast-action {
    flex: none;
    padding: .25rem .7rem;
    font: inherit;
    font-weight: 600;
    color: inherit;
    background: none;
    border: 1px solid currentColor;
    border-radius: 6px;
    cursor: pointer;
}

.deleted-heading {
    margin: 1.25rem 0 .25rem;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--reader-muted);
}

    .deleted-heading:first-child { margin-top: 0; }

.deleted-cover {
    flex: none;
    width: 28px;
    height: 42px;
    object-fit: cover;
    border-radius: 2px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}

    .deleted-cover.placeholder {
        display: flex;
        align-items: center;
        justify-content: center;
        font: .8rem Georgia, serif;
        color: #fff;
        background: #5b6b7c;
    }

/* ── Book cards: series line ("Empire of Man, Book 4") ── */
.card-series {
    font-size: .74rem;
    font-style: italic;
    color: var(--reader-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Organize… (suggested shelves) ── */
.organize-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, .35);
}

.organize-panel {
    display: flex;
    flex-direction: column;
    width: min(560px, 100%);
    max-height: min(720px, calc(100vh - 2rem));
    padding: 1rem 1.25rem;
    box-sizing: border-box;
    font: .92rem system-ui, "Segoe UI", sans-serif;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, .3);
}

.organize-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

    .organize-header h3 { margin: 0; font-size: 1.15rem; }

.organize-kinds {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem 1.25rem;
    margin: .5rem 0 .35rem;
    font-weight: 600;
}

.organize-min {
    font-size: .85rem;
    color: var(--reader-muted);
}

.organize-list {
    flex: 1;
    overflow-y: auto;
    margin: .75rem 0;
    border-top: 1px solid var(--chrome-border);
    border-bottom: 1px solid var(--chrome-border);
}

.organize-heading {
    position: sticky;
    top: 0;
    padding: .55rem 0 .3rem;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--reader-muted);
    background: var(--chrome-bg);
}

.organize-row {
    display: flex;
    align-items: baseline;
    gap: .6rem;
    padding: .35rem .25rem;
    border-radius: 6px;
    cursor: pointer;
}

    .organize-row:hover { background: var(--chrome-hover); }
    .organize-row.done { color: var(--reader-muted); cursor: default; }

.organize-name { font-weight: 600; }

.organize-count,
.organize-note {
    font-size: .8rem;
    color: var(--reader-muted);
}

.organize-note {
    margin-left: auto;
    text-align: right;
}

.organize-footer {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
}

.lib-btn:disabled { opacity: .5; cursor: default; }

/* ── Who is this? ─────────────────────────────────────────── */

/* The button that appears above a selected name */
.who-chip {
    position: fixed;
    z-index: 26;                 /* above the page and click zones, below the panels */
    transform: translate(-50%, -100%);
    display: flex;
    align-items: center;
    gap: .35rem;
    padding: .35rem .75rem;
    font: 600 .82rem system-ui, "Segoe UI", sans-serif;
    color: #fff;
    background: var(--reader-link);
    border: none;
    border-radius: 16px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .25);
    cursor: pointer;
    white-space: nowrap;
}

/* The panel slides in from the right (Settings and Contents use the left) */
.settings-panel.who-panel {
    left: auto;
    right: 0;
    width: 360px;
    transform: translateX(105%);
    box-shadow: -2px 0 16px rgba(0, 0, 0, .15);
}

    .settings-panel.who-panel.open { transform: none; }

.who-body {
    flex: 1;
    overflow-y: auto;
    padding: .5rem 1rem 1.5rem;
    font: .92rem system-ui, "Segoe UI", sans-serif;
}

.who-name {
    margin: .4rem 0 .1rem;
    font: 600 1.35rem Georgia, "Times New Roman", serif;
}

.who-note {
    margin: .2rem 0 .6rem;
    color: var(--reader-muted);
}

.who-body section {
    padding: .7rem 0;
    border-top: 1px solid var(--chrome-border);
}

.who-body h4 {
    margin: 0 0 .3rem;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--reader-muted);
}

.who-where {
    font-weight: 600;
    color: var(--reader-link);
}

/* The passage, in the book's own type */
.who-snippet {
    margin: .4rem 0 .55rem;
    font: 1rem/1.5 Georgia, "Times New Roman", serif;
    color: var(--reader-fg);
}

    .who-snippet strong {
        background: color-mix(in srgb, var(--reader-link) 18%, transparent);
        border-radius: 2px;
    }

.who-go {
    padding: .3rem .8rem;
    font: inherit;
    font-size: .85rem;
    color: var(--reader-link);
    background: none;
    border: 1px solid currentColor;
    border-radius: 6px;
    cursor: pointer;
}

    .who-go:hover { background: color-mix(in srgb, var(--reader-link) 10%, transparent); }

.who-chapter {
    display: flex;
    align-items: baseline;
    gap: .5rem;
    width: 100%;
    padding: .35rem .4rem;
    font: inherit;
    text-align: left;
    color: var(--reader-fg);
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

    .who-chapter:hover { background: var(--chrome-hover); }

.who-chapter-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.who-chapter-count {
    font-size: .8rem;
    color: var(--reader-muted);
}

/* ── Search panel (slides in from the left) ── */
.settings-panel.search-panel { width: 380px; }

.search-box {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: .2rem 1rem .4rem;
    padding: .4rem .7rem;
    border: 1px solid var(--chrome-border);
    border-radius: 8px;
    background: var(--reader-bg, transparent);
    color: var(--reader-muted);
}

    .search-box:focus-within { border-color: var(--reader-link); }

    .search-box input {
        flex: 1;
        min-width: 0;
        border: none;
        outline: none;
        background: none;
        font: 1rem system-ui, "Segoe UI", sans-serif;
        color: var(--reader-fg);
    }

.search-group { padding: .5rem 0 .3rem; border-top: 1px solid var(--chrome-border); }

.search-chapter {
    margin: 0 0 .2rem;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--reader-muted);
}

.search-result {
    display: block;
    width: 100%;
    padding: .4rem .5rem;
    font: .95rem/1.45 Georgia, "Times New Roman", serif;
    text-align: left;
    color: var(--reader-fg);
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

    .search-result:hover { background: var(--chrome-hover); }

    .search-result strong {
        background: color-mix(in srgb, var(--reader-link) 20%, transparent);
        border-radius: 2px;
    }

/* Where you are reading, among the results */
.search-you {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: .5rem 0;
    font-size: .75rem;
    font-weight: 600;
    color: var(--reader-link);
}

    .search-you::before, .search-you::after {
        content: "";
        flex: 1;
        height: 1px;
        background: currentColor;
        opacity: .5;
    }

/* In the ◀ ▶ bar, the search words take you back to the results */
.who-nav .who-nav-search { cursor: pointer; text-decoration: underline dotted; }

/* Every mention of the name in this chapter, lightly marked… */
/* (!important and the .chapter-content prefix beat the rule that clears book backgrounds) */
.chapter-content mark.mention {
    color: inherit;
    background-color: color-mix(in srgb, var(--reader-link) 16%, transparent) !important;
    border-radius: 2px;
}

    /* …and the one you're on, clearly: a solid highlight with an outline that pulses once */
    .chapter-content mark.mention.found {
        background-color: color-mix(in srgb, #f5c542 70%, transparent) !important;
        box-shadow: 0 0 0 2px #e0a800;
        animation: found-pulse 1.2s ease 2;
    }

@keyframes found-pulse {
    50% { box-shadow: 0 0 0 5px color-mix(in srgb, #e0a800 40%, transparent); }
}

/* ◀ 3 of 88 ▶ — stepping through the mentions (top centre, under the header) */
.who-nav {
    position: fixed;
    top: calc(var(--reader-header-h) + 6px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 25;
    display: flex;
    align-items: center;
    gap: .35rem;
    padding: .25rem .35rem .25rem .35rem;
    font: .88rem system-ui, "Segoe UI", sans-serif;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
}

    .who-nav strong { margin-left: .2rem; }

    .who-nav .who-nav-count {
        min-width: 4.5em;
        margin-right: .2rem;
        color: var(--reader-muted);
        font-variant-numeric: tabular-nums;
    }

    .who-nav button {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 1.9rem;
        height: 1.9rem;
        padding: 0;
        font-size: .9rem;
        color: inherit;
        background: none;
        border: none;
        border-radius: 50%;
        cursor: pointer;
    }

        .who-nav button:hover:not(:disabled) { background: var(--chrome-hover); }
        .who-nav button:disabled { opacity: .35; cursor: default; }

/* ── The message at the top of the page ("Listening…", "Bookmark added"…) — showVoiceToast in reader.js.
   Read aloud and voice commands: speech.css ── */
.voice-toast {
    position: fixed;
    top: calc(var(--reader-header-h) + 6px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 27;
    max-width: min(640px, calc(100vw - 2rem));
    padding: .5rem 1rem;
    font: .9rem system-ui, "Segoe UI", sans-serif;
    color: var(--chrome-bg);
    background: var(--reader-fg);
    border-radius: 18px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
    text-align: center;
}


/* ════════════════════════════════════════════════════════════════════
   Beautiful — Novela's own typesetting (beautify.js)
   The book's CSS is switched off; beautify.js marks what things ARE with nv-… classes,
   and these rules decide how they LOOK. --nv-font and --nv-leading come from Settings.
   ════════════════════════════════════════════════════════════════════ */
.chapter-content.nv-beautiful {
    font-family: var(--nv-font, "Sitka Text", Georgia, serif);
    line-height: var(--nv-leading, 1.55);
    font-kerning: normal;
    font-variant-ligatures: common-ligatures;
    text-rendering: optimizeLegibility;
    orphans: 2;
    widows: 2;
}

    /* Everything inherits the chosen font and spacing (code keeps a fixed-width font) */
    .nv-beautiful :is(p, div, span, a, li, blockquote, dd, dt, td, th, h1, h2, h3, h4, h5, h6, header, figcaption, font, em, i, b, strong, small, big, cite) {
        font-family: inherit;
        line-height: inherit;
        color: inherit;
    }

    .nv-beautiful :is(pre, code, kbd, samp) {
        font-family: Consolas, "Cascadia Mono", monospace;
        font-size: .9em;
    }

    .nv-beautiful pre { white-space: pre-wrap; line-height: 1.4; }

    .nv-beautiful a[href] { text-decoration: none; }

    /* ── Body paragraphs: first-line indent, no gaps — like a printed book ── */
    .nv-beautiful .nv-p {
        margin: 0;
        padding: 0;
        text-indent: 1.4em;
        font-size: 1em;
    }

    body.text-justify .nv-beautiful .nv-p { text-align: justify; hyphens: auto; }
    body.text-left .nv-beautiful .nv-p { text-align: left; hyphens: manual; }

    .nv-beautiful .nv-p.nv-first { text-indent: 0; }

    /* Textbooks and manuals: a space between paragraphs instead of indents, no drop caps */
    .nv-beautiful.nv-spaced .nv-p { text-indent: 0; margin: 0 0 .8em; }
    .nv-beautiful.nv-spaced .nv-p.nv-lead::first-letter { initial-letter: normal; font-weight: inherit; margin: 0; }
    .nv-beautiful.nv-spaced .nv-p.nv-lead::first-line { font-variant-caps: normal; letter-spacing: normal; }

    /* The chapter's first paragraph: a drop cap and a small-caps first line */
    .nv-beautiful .nv-p.nv-lead::first-letter {
        initial-letter: 2;
        font-weight: 600;
        margin-right: .12em;
        color: var(--nv-accent, inherit);
    }

    .nv-beautiful .nv-p.nv-lead::first-line {
        font-variant-caps: small-caps;
        letter-spacing: .04em;
    }

    /* iPhone/iPad/Mac app: no small-caps first line. Apple's web engine (WebKit) works out where the
       letters of a ::first-line are as if they had no small caps or extra spacing, so on that line a
       selection lit up the wrong letters and its handles wouldn't move (seen in The Apocalypse
       Troll, chapter openings in Beautiful). The PC's engine (WebView2) has no such trouble. */
    html.in-app .nv-beautiful .nv-p.nv-lead::first-line {
        font-variant-caps: normal;
        letter-spacing: normal;
    }

    /* iPhone/iPad/Mac app: the drop cap is a real letter (<span class="nv-dropcap">, beautify.js)
       floated to the left, not ::first-letter — with ::first-letter, Apple's web engine got every
       selection beside the drop cap wrong (the highlight covered parts of several words, the handles
       wouldn't move). So ::first-letter is switched off here, and the span looks the same instead. */
    html.in-app .nv-beautiful .nv-p.nv-lead::first-letter {
        initial-letter: normal;
        font-weight: inherit;
        margin: 0;
        color: inherit;
    }

    html.in-app .nv-beautiful .nv-p.nv-lead .nv-dropcap {
        float: left;
        font-size: 3.15em;          /* two lines of text tall, like initial-letter: 2 */
        line-height: .82;
        margin: .06em .1em 0 0;
        font-weight: 600;
        color: var(--nv-accent, inherit);
    }

    html.in-app .nv-beautiful.nv-spaced .nv-p.nv-lead .nv-dropcap {
        float: none;
        font-size: inherit;
        line-height: inherit;
        margin: 0;
        font-weight: inherit;
        color: inherit;
    }

    /* Other text blocks keep what they meant (centred, italic…) with even spacing */
    .nv-beautiful .nv-block { margin: .6em 0; text-indent: 0; }
    .nv-beautiful .nv-center { text-align: center !important; text-indent: 0; }
    .nv-beautiful .nv-right { text-align: right !important; text-indent: 0; }
    .nv-beautiful .nv-indented { margin-left: 2em; margin-right: 1em; }
    .nv-beautiful .nv-small { font-size: .85em; }
    .nv-beautiful .nv-large { font-size: 1.2em; }
    .nv-beautiful .nv-larger { font-size: 1.5em; line-height: 1.25; }
    .nv-beautiful .nv-hidden { display: none !important; }
    .nv-beautiful .nv-gap { height: 1.5em; margin: 0; }

    .nv-beautiful .nv-i { font-style: italic; }
    .nv-beautiful .nv-roman { font-style: normal; }
    .nv-beautiful .nv-b { font-weight: 600; }
    .nv-beautiful .nv-unbold { font-weight: normal; }
    .nv-beautiful .nv-sc { font-variant-caps: small-caps; letter-spacing: .03em; }
    .nv-beautiful .nv-uc { text-transform: uppercase; letter-spacing: .04em; }
    .nv-beautiful .nv-u { text-decoration: underline; }
    .nv-beautiful .nv-strike { text-decoration: line-through; }
    .nv-beautiful .nv-smaller { font-size: .85em; }
    .nv-beautiful .nv-bigger { font-size: 1.2em; }
    .nv-beautiful .nv-sup { vertical-align: super; font-size: .7em; line-height: 0; }
    .nv-beautiful .nv-sub { vertical-align: sub; font-size: .7em; line-height: 0; }

    .nv-beautiful blockquote { margin: 1em 2em; font-size: .95em; }
    .nv-beautiful blockquote .nv-p { text-indent: 0; margin-bottom: .5em; }
    .nv-beautiful :is(ul, ol) { margin: .8em 0; padding-left: 1.8em; }
    .nv-beautiful li { margin: .25em 0; }

    /* Headings inside the chapter */
    .nv-beautiful .nv-h {
        font-weight: 600;
        line-height: 1.25;
        margin: 1.6em 0 .6em;
        text-indent: 0;
        break-after: avoid;
        text-align: left;
    }

    .nv-beautiful h1.nv-h { font-size: 1.6em; }
    .nv-beautiful h2.nv-h { font-size: 1.35em; }
    .nv-beautiful h3.nv-h { font-size: 1.15em; }
    .nv-beautiful :is(h4, h5, h6).nv-h { font-size: 1em; font-style: italic; font-weight: normal; }

    /* ── The chapter opener ── */
    .nv-beautiful .nv-opener {
        text-align: center;
        margin: 3em 0 2.4em;
        break-inside: avoid;
        break-after: avoid;
    }

    /* "Book One" above a chapter's opener: smaller and set apart, so the chapter stays the main line */
    .nv-beautiful .nv-kicker {
        font-variant-caps: all-small-caps;
        letter-spacing: .3em;
        font-size: .9em;
        opacity: .6;
        margin-bottom: 1.2em;
    }

    .nv-beautiful .nv-label {
        font-variant-caps: all-small-caps;
        letter-spacing: .25em;
        font-size: 1.05em;
        opacity: .75;
    }

    .nv-beautiful .nv-number {
        font-size: 3.2em;
        font-weight: 300;
        line-height: 1.05;
        margin-top: .05em;
        font-variant-numeric: oldstyle-nums;
    }

    .nv-beautiful .nv-title {
        font-size: 1.45em;
        font-weight: 500;
        font-style: italic;
        line-height: 1.3;
        margin: .45em 0 0;
        text-wrap: balance;
    }

        .nv-beautiful .nv-title.nv-caps {
            font-style: normal;
            font-size: 1.15em;
            letter-spacing: .12em;
        }

    .nv-beautiful .nv-subtitle {
        margin-top: .5em;
        font-variant-caps: all-small-caps;
        letter-spacing: .12em;
        opacity: .8;
    }

    .nv-beautiful .nv-rule {
        width: 4.5em;
        height: 1px;
        margin: 1.3em auto 0;
        background: currentColor;
        opacity: .35;
    }

    /* ── Scene breaks: one ornament, never lost at the bottom of a page ── */
    .nv-beautiful .nv-break {
        margin: .9em 0;
        height: auto;
        text-align: center !important;
        text-indent: 0;
        break-after: avoid;
        break-inside: avoid;
    }

        .nv-beautiful .nv-break::before {
            content: "\2042";               /* ⁂ */
            font-size: 1.1em;
            opacity: .6;
        }

    /* ── Pictures ── */
    .nv-beautiful img.nv-img {
        max-width: 100%;
        height: auto;
    }

    .nv-beautiful .nv-figure {
        text-align: center !important;
        text-indent: 0;
        margin: 1em 0;
        break-inside: avoid;
    }

    .nv-beautiful img.nv-img-wide { width: 100%; }

    /* ── Tables ── */
    .nv-beautiful table { border-collapse: collapse; margin: 1em auto; font-size: .92em; break-inside: avoid; }
    .nv-beautiful :is(td, th) { border-bottom: 1px solid color-mix(in srgb, currentColor 20%, transparent); padding: .3em .6em; text-align: left; }
    .nv-beautiful th { font-weight: 600; border-bottom-color: color-mix(in srgb, currentColor 45%, transparent); }

    /* ── Maths (KaTeX) ── */
    .nv-beautiful .nv-math .katex { font-size: 1.05em; }
    .nv-beautiful .nv-math-block { display: block; margin: .7em 0; text-align: center; overflow-x: auto; overflow-y: hidden; break-inside: avoid; }
    .nv-beautiful .nv-math-picture { vertical-align: middle; }

html.theme-dark .nv-beautiful img.nv-math-picture {
    filter: invert(.88) hue-rotate(180deg);      /* black-on-white formulas become light-on-dark */
}

/* While beautify.js works (a moment), the chapter stays hidden so the book's own look doesn't flash */
body.typesetting .chapter-content { opacity: 0; }

/* The ✨ button in the bar: lit while Beautiful is on */
body.beautiful-on .nav-btn[data-action="beautify"] { color: var(--reader-link); }

/* …and a small dot under the stars while it's on. The colour alone is easy to miss, and on a touch
   screen there's no tooltip to say which look you're in. (::before, because ::after is the tooltip.) */
.nav-btn[data-action="beautify"] { position: relative; }

body.beautiful-on .nav-btn[data-action="beautify"]::before {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 5px;
    height: 5px;
    margin-left: -2.5px;
    border-radius: 50%;
    background: currentColor;
    pointer-events: none;
}

/* ───────────────────────────────────────────────
   Importing a Word manuscript: the questions (replace or keep both? is this the cover?)
   ─────────────────────────────────────────────── */
.ask-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .45);
}

.ask-dialog {
    width: min(440px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    overflow: auto;
    padding: 1.2rem 1.4rem;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
}

    .ask-dialog h3 { margin: 0 0 .8rem; font-size: 1.1rem; }

.ask-group {
    margin: 0 0 1rem;
    padding: 0;
    border: none;
}

    .ask-group legend { margin-bottom: .5rem; font-weight: 600; }

.ask-choice {
    display: flex;
    gap: .5rem;
    align-items: baseline;
    margin: .3rem 0;
    cursor: pointer;
}

    .ask-choice small { display: block; color: var(--reader-muted); }

.ask-cover {
    display: block;
    max-width: 140px;
    max-height: 200px;
    margin: 0 0 .5rem;
    border: 1px solid var(--chrome-border);
    border-radius: 4px;
}

.ask-buttons {
    display: flex;
    justify-content: flex-end;
    gap: .6rem;
}

    .ask-buttons button {
        padding: .45rem 1.1rem;
        font: inherit;
        color: var(--reader-fg);
        background: none;
        border: 1px solid var(--chrome-border);
        border-radius: 8px;
        cursor: pointer;
    }

        .ask-buttons button:hover { background: var(--chrome-hover); }

    .ask-buttons .ask-ok {
        color: #fff;
        background: var(--reader-link);
        border-color: var(--reader-link);
    }

        .ask-buttons .ask-ok:hover { background: var(--reader-link); filter: brightness(1.1); }

/* ───────────────────────────────────────────────
   Highlights (reader.js, "Highlights"). Painted over the text, never changing it.
   ─────────────────────────────────────────────── */
::highlight(nv-hl-yellow) { background-color: rgba(255, 214, 10, .42); }
::highlight(nv-hl-green) { background-color: rgba(92, 201, 107, .38); }
::highlight(nv-hl-blue) { background-color: rgba(78, 163, 255, .34); }
::highlight(nv-hl-pink) { background-color: rgba(255, 111, 174, .34); }
/* A highlight with a note: dotted underline */
::highlight(nv-hl-note) {
    text-decoration-line: underline;
    text-decoration-style: dotted;
    text-decoration-thickness: 2px;
    text-decoration-color: currentColor;
}

/* The bar above selected text */
.selection-bar {
    position: fixed;
    z-index: 26;                 /* above the page and click zones, below the panels */
    transform: translate(-50%, -100%);
    display: flex;
    align-items: center;
    gap: .3rem;
    padding: .3rem .4rem;
    font: 600 .82rem system-ui, "Segoe UI", sans-serif;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 18px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, .25);
    white-space: nowrap;
}

    .selection-bar button {
        display: flex;
        align-items: center;
        gap: .3rem;
        height: 1.75rem;
        padding: 0 .45rem;
        font: inherit;
        color: inherit;
        background: none;
        border: none;
        border-radius: 14px;
        cursor: pointer;
    }

        .selection-bar button:hover { background: var(--chrome-hover); }

    /* A footnote, shown next to its star (reader.js "Footnotes in a pop-up") */
    .note-popup {
        position: fixed;
        z-index: 27;                 /* above the page and the selection bar, below the panels */
        max-width: min(26rem, calc(100vw - 16px));
        max-height: 40vh;
        overflow: auto;
        padding: .7rem .9rem;
        font-size: .92em;
        line-height: 1.45;
        color: var(--reader-fg);
        background: var(--chrome-bg);
        border: 1px solid var(--chrome-border);
        border-radius: 10px;
        box-shadow: 0 6px 22px rgba(0, 0, 0, .22);
    }

        .note-popup > * { margin: 0; text-indent: 0; }
        .note-popup p + p { margin-top: .5em; }

    /* With a finger: at the bottom of the screen, just above the bottom bar, out of the way of the
       iPad's own Copy / Look Up menu (which pops up beside the selected words) */
    .selection-bar.docked {
        top: auto;
        left: 50%;
        bottom: calc(var(--reader-nav-h, 56px) + 12px);
        transform: translateX(-50%);
    }

    .selection-bar .selection-who {
        margin-left: .15rem;
        color: #fff;
        background: var(--reader-link);
    }

        .selection-bar .selection-who:hover { background: var(--reader-link); filter: brightness(1.1); }

/* A color dot (selection bar and the highlight window) */
.hl-dot {
    width: 1.5rem;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 !important;
    background: var(--dot) !important;
    border: 2px solid rgba(0, 0, 0, .12) !important;
    border-radius: 50% !important;
    cursor: pointer;
}

    .hl-dot:hover { transform: scale(1.12); }
    .hl-dot[aria-pressed="true"] { border-color: var(--reader-fg) !important; }

/* The little window for one highlight: colors, note, remove */
.hl-pop {
    position: fixed;
    z-index: 30;
    width: 280px;
    padding: .7rem;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .28);
    font: .9rem system-ui, "Segoe UI", sans-serif;
}

.hl-colors {
    display: flex;
    gap: .5rem;
    margin-bottom: .6rem;
}

.hl-note {
    box-sizing: border-box;
    width: 100%;
    padding: .45rem .55rem;
    font: .95rem/1.4 Georgia, "Times New Roman", serif;
    color: var(--reader-fg);
    background: var(--reader-bg);
    border: 1px solid var(--chrome-border);
    border-radius: 6px;
    resize: vertical;
}

.hl-buttons {
    display: flex;
    justify-content: space-between;
    margin-top: .55rem;
}

    .hl-buttons button {
        padding: .3rem .8rem;
        font: inherit;
        color: var(--reader-fg);
        background: none;
        border: 1px solid var(--chrome-border);
        border-radius: 7px;
        cursor: pointer;
    }

        .hl-buttons button:hover { background: var(--chrome-hover); }

    .hl-buttons .hl-remove:hover { color: #c0392b; }

    .hl-buttons .hl-done {
        color: #fff;
        background: var(--reader-link);
        border-color: var(--reader-link);
    }

        .hl-buttons .hl-done:hover { background: var(--reader-link); filter: brightness(1.1); }

/* The Highlights tab: like bookmarks, with the highlight's color down the side */
.highlight-item { box-shadow: inset 4px 0 0 var(--hl); }

.highlight-quote {
    font: .95rem/1.4 Georgia, "Times New Roman", serif;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.highlight-note {
    padding-left: .5rem;
    font-size: .88rem;
    font-style: italic;
    color: var(--reader-muted);
    border-left: 2px solid var(--chrome-border);
    white-space: pre-wrap;
}

/* A highlight's note, shown while the mouse rests on it */
.note-peek {
    position: fixed;
    z-index: 27;
    max-width: 320px;
    max-height: 40vh;
    overflow: auto;
    padding: .55rem .75rem;
    font: italic .92rem/1.45 Georgia, "Times New Roman", serif;
    color: var(--reader-fg);
    background: var(--chrome-bg);
    border: 1px solid var(--chrome-border);
    border-left: 4px solid var(--hl);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
    white-space: pre-wrap;
    pointer-events: none;        /* never in the way of the mouse */
}

/* Settings → Back up */
.backup-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: .6rem;
}

.backup-list {
    list-style: none;
    margin: 0 0 .7rem;
    padding: 0;
}

    .backup-list li {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: .5rem;
        padding: .35rem 0;
        border-bottom: 1px solid var(--chrome-border);
    }

.backup-when { font-size: .88rem; }

.backup-restore {
    padding: .2rem .7rem;
    font: inherit;
    font-size: .85rem;
    color: var(--reader-link);
    background: none;
    border: 1px solid var(--chrome-border);
    border-radius: 6px;
    cursor: pointer;
}

    .backup-restore:hover { background: var(--chrome-hover); }

/* Picture zoom (reader.js, "Picture zoom") */
.nv-zoomable { cursor: zoom-in; }

.zoom-overlay {
    position: fixed;
    inset: 0;
    z-index: 1500;
    overflow: hidden;
    background: rgba(12, 12, 14, .92);
    cursor: zoom-out;
    outline: none;
    opacity: 0;
    transition: opacity .15s ease;
    touch-action: none;
}

    .zoom-overlay.ready { opacity: 1; }
    .zoom-overlay.dragging, .zoom-overlay.dragging .zoom-image { cursor: grabbing; }

.zoom-image {
    position: absolute;
    left: 50%;
    top: 50%;
    max-width: none;
    margin: 0;
    translate: -50% -50%;           /* centred; transform adds the move and the zoom */
    transform-origin: center;
    cursor: grab;
    user-select: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
    image-rendering: auto;
}

.zoom-tools {
    position: absolute;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    display: flex;
    gap: .3rem;
    padding: .3rem;
    background: rgba(40, 40, 44, .85);
    border-radius: 22px;
    cursor: default;
}

    .zoom-tools button {
        width: 2.4rem;
        height: 2.4rem;
        font-size: 1.1rem;
        color: #fff;
        background: none;
        border: none;
        border-radius: 50%;
        cursor: pointer;
    }

        .zoom-tools button:hover { background: rgba(255, 255, 255, .15); }
