:root {
    /* Dark is the default: this is a reader, and a page of prose at night should not be a lamp.
       Every colour the application uses is named here and only here, so the light theme below is
       the same list with other values - and nothing has to be hunted down twice. */
    --bg: #14161a;
    --panel: #1b1f26;
    --panel-alt: #20242c;
    --field: #14171d;
    --ink: #e6e9ef;
    --muted: #98a2b3;
    --line: #2c323c;
    --accent: #8ba4ff;
    --accent-ink: #12151c;
    --accent-soft: #232a3d;
    --ok: #4ade80;
    --ok-soft: #14291f;
    --warn: #fbbf24;
    --warn-soft: #2e2415;
    --err: #f87171;
    --err-soft: #2e1a1a;
    --info-soft: #16292e;
    --info-ink: #67e8f9;
    --soft: #262b34;
    --log-bg: #0c0f14;
    --log-ink: #cbd5e1;
    --note-bg: #26210f;
    --note-ink: #e7c877;
    --parsing: #1b2233;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
    /* The reader's page: paper, ink and the width of a column of prose. */
    --read-bg: #16181d;
    --read-paper: #1c1f25;
    --read-ink: #dfe3ea;
    --radius: 10px;
    /* Scrollbars, form controls and the browser's own widgets follow the theme too. */
    color-scheme: dark;
}

/* The other way round, for anybody who reads better on white. Chosen in the header; the choice is
   this browser's, kept in localStorage and applied before the first paint so no page flashes. */
:root[data-theme="light"] {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-alt: #fafbfd;
    --field: #ffffff;
    --ink: #1d2430;
    --muted: #667085;
    --line: #dfe3e8;
    --accent: #3b5bdb;
    --accent-ink: #ffffff;
    --accent-soft: #eef2ff;
    --ok: #1f7a4d;
    --ok-soft: #ecfdf3;
    --warn: #b45309;
    --warn-soft: #fff7ed;
    --err: #b42318;
    --err-soft: #fef3f2;
    --info-soft: #e6f6f8;
    --info-ink: #0e7490;
    --soft: #eef2f6;
    --log-bg: #0f172a;
    --log-ink: #e2e8f0;
    --note-bg: #fffbeb;
    --note-ink: #7c4a03;
    --parsing: #f5f8ff;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
    --read-bg: #f3f2ee;
    --read-paper: #fffdf8;
    --read-ink: #24282f;
    color-scheme: light;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

header.site {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 0.85rem 0;
}

/* Same bar on every page: same height with a cover or without one. */
header.site .bar { min-height: 3.4rem; align-items: center; }

.titlebar { display: flex; align-items: center; gap: 0.85rem; min-width: 0; }

.titlebar-cover {
    width: 2.4rem;
    height: 3.4rem;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--line);
    background: var(--soft);
    flex: none;
}

.titlebar-text { min-width: 0; }
.titlebar-text h1 { margin: 0; font-size: 1.3rem; line-height: 1.25; }
.titlebar-text p { margin: 0.1rem 0 0; }

.brand {
    font-size: 0.85rem;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
    flex: none;
}

.brand:hover { color: var(--accent); }

/* Every view uses the whole window, and the side menu is the same width on all of them. */
.wrap { max-width: none; margin: 0 auto; padding: 0 1.5rem; }

/* Panels stretch, but a paragraph nobody can follow across 2000 pixels does not, and a form
   field does not need to be a metre wide either. */
.panel > p, .panel > ul, .panel > .meta, .menu-title { max-width: 80ch; }
.panel .grid, .panel fieldset { max-width: 70rem; }

/* Every page is a side menu and a column of panels. */
.shell { display: flex; align-items: flex-start; gap: 1.25rem; }
.content { flex: 1; min-width: 0; }

.sidemenu {
    width: 12.5rem;
    flex: none;
    position: sticky;
    top: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.menu-group {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.menu-group form { margin: 0; }

.menu-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 0.25rem 0.55rem 0.4rem;
}

/* Links and submit buttons have to look like one list, so they share everything. */
.menu-item {
    display: block;
    width: 100%;
    text-align: left;
    font: inherit;
    font-size: 0.87rem;
    line-height: 1.3;
    padding: 0.45rem 0.55rem;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
}

.menu-item:hover { background: var(--accent-soft); filter: none; }
.menu-item.here { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.menu-item.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}

.menu-item.primary:hover { background: var(--accent); filter: brightness(0.95); }
.menu-item.danger { color: var(--err); }
.menu-item.danger:hover { background: var(--err-soft); }
.menu-item:disabled { color: var(--muted); cursor: default; }
.menu-item:disabled:hover { background: transparent; }

/* Narrow windows: the menu becomes a row of groups above the content. */
@media (max-width: 860px) {
    .shell { flex-direction: column; }
    .sidemenu { width: 100%; position: static; flex-direction: row; flex-wrap: wrap; }
    .sidemenu .menu-group { flex: 1 1 13rem; }
}

header.site p { color: var(--muted); font-size: 0.85rem; }

main { padding: 1.5rem 0 3rem; }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.panel h2 { margin-top: 0; font-size: 1.05rem; }

fieldset { border: 0; padding: 0; margin: 0 0 1rem; }
legend {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    padding: 0 0 0.4rem;
}

.grid { display: grid; gap: 0.9rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid .full { grid-column: 1 / -1; }

label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.25rem; }
label .hint { display: block; font-weight: 400; color: var(--muted); font-size: 0.78rem; }

input[type="text"], input[type="url"], input[type="number"], select, textarea {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    font-size: 0.9rem;
    background: var(--field);
    color: var(--ink);
}

textarea { min-height: 5.5rem; resize: vertical; font-family: ui-monospace, "SFMono-Regular", monospace; }

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.check { display: flex; align-items: center; gap: 0.5rem; margin-top: 1.5rem; }
.check label { margin: 0; }
.check input { width: auto; }

.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin-top: 0.5rem; }

button, .btn {
    font: inherit;
    font-size: 0.9rem;
    padding: 0.55rem 1.1rem;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--accent-ink);
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

button.secondary, .btn.secondary {
    background: transparent;
    color: var(--accent);
}

button.danger, .btn.danger { background: transparent; border-color: var(--err); color: var(--err); }

button:hover, .btn:hover { filter: brightness(0.95); }

.error { color: var(--err); font-size: 0.82rem; margin-top: 0.2rem; }

.notice { border-left: 3px solid var(--accent); padding: 0.6rem 0.9rem; background: var(--accent-soft); border-radius: 6px; }
.notice.bad { border-color: var(--err); background: var(--err-soft); }
.notice.good { border-color: var(--ok); background: var(--ok-soft); }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }

.badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: var(--soft);
    color: var(--muted);
}
.badge.RUNNING { background: var(--accent-soft); color: var(--accent); }
.badge.COMPLETED { background: var(--ok-soft); color: var(--ok); }
/* Up to date - positive, but not to be confused with a run that fetched something. */
.badge.CURRENT { background: var(--info-soft); color: var(--info-ink); }
.badge.FAILED { background: var(--err-soft); color: var(--err); }
.badge.CANCELLED { background: var(--warn-soft); color: var(--warn); }

.progress { height: 10px; background: var(--soft); border-radius: 999px; overflow: hidden; margin: 0.6rem 0; }
.progress span { display: block; height: 100%; background: var(--accent); transition: width 0.3s ease; }

.log {
    background: var(--log-bg);
    color: var(--log-ink);
    border-radius: 6px;
    padding: 0.8rem;
    font-family: ui-monospace, "SFMono-Regular", monospace;
    font-size: 0.8rem;
    max-height: 20rem;
    overflow-y: auto;
    white-space: pre-wrap;
}

.excerpt {
    background: var(--panel-alt);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.8rem;
    font-size: 0.9rem;
    max-height: 16rem;
    overflow-y: auto;
}

.meta { color: var(--muted); font-size: 0.82rem; }
.meta-preview { margin-bottom: 1rem; }
.meta-preview th { width: 7rem; }
.optional {
    font-weight: 400;
    font-size: 0.72rem;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0 0.4rem;
    margin-left: 0.3rem;
}
.mono { font-family: ui-monospace, "SFMono-Regular", monospace; font-size: 0.82rem; word-break: break-all; }

footer.site { color: var(--muted); font-size: 0.8rem; padding: 1.5rem 0 2.5rem; }

@media (max-width: 700px) {
    .grid { grid-template-columns: 1fr; }
    .check { margin-top: 0; }
}

/* --- project screens ---------------------------------------------------- */

.bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

header.site h1 a { color: inherit; text-decoration: none; }

.topnav { display: flex; gap: 0.6rem; align-items: center; }
.topnav a { color: var(--accent); text-decoration: none; font-size: 0.9rem; }
.topnav a.btn { color: var(--accent-ink); }

.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }
.row-actions form { margin: 0; }

button.tiny, .btn.tiny { padding: 0.25rem 0.55rem; font-size: 0.78rem; }

label.inline {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 0.35rem;
}
label.inline input { width: auto; }

.lock { font-size: 0.8rem; }
tr.muted td { opacity: 0.55; }

.cover-box {
    border: 1px dashed var(--line);
    border-radius: 6px;
    padding: 0.4rem;
    min-height: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
img.cover { max-height: 8rem; border-radius: 4px; }

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.9rem;
}
.image-grid figure {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.5rem;
}
.image-grid img { width: 100%; height: 7rem; object-fit: contain; }
.image-grid figcaption { font-size: 0.72rem; color: var(--muted); word-break: break-all; }

details.panel summary { cursor: pointer; font-size: 1.05rem; }
details.panel[open] summary { margin-bottom: 1rem; }

textarea.editor {
    min-height: 24rem;
    font-size: 0.85rem;
    line-height: 1.5;
}

.usage-banner {
    border: 1px solid var(--line);
    border-left: 4px solid var(--warn);
    background: var(--note-bg);
    border-radius: var(--radius);
    padding: 0.9rem 1.1rem;
    font-size: 0.85rem;
    color: var(--note-ink);
    margin-bottom: 1.25rem;
}
.usage-banner strong { display: inline-block; margin-right: 0.3rem; }

/* --- project list covers ------------------------------------------------ */

.cover-col { width: 56px; padding-right: 0; }

.cover-thumb {
    display: block;
    width: 48px;
    height: 68px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--line);
    background: var(--soft);
}

.cover-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    text-decoration: none;
}

/* --- parallel parsing indicators ---------------------------------------- */

.parsing-summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1.1rem;
    font-size: 0.9rem;
    border-left: 4px solid var(--accent);
}

.parsing-summary.quiet {
    border-left-color: var(--line);
    color: var(--muted);
}

.parsing-summary .meta { margin-left: auto; }

.recheck-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.1rem;
    font-size: 0.9rem;
    flex-wrap: wrap;
}

.recheck-bar .meta { margin-left: auto; }

.check {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    cursor: pointer;
    margin: 0;
    font-weight: 500;
}

.check input { margin: 0; }

.pulse {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent);
    flex: none;
    animation: pulse 1.4s ease-in-out infinite;
}

.parsing-summary.quiet .pulse { background: var(--line); animation: none; }

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.8); }
}

@media (prefers-reduced-motion: reduce) {
    .pulse { animation: none; }
}

.progress.mini { height: 6px; margin: 0.35rem 0 0.2rem; max-width: 12rem; }

.run-cell { min-width: 11rem; }

/* The project list: one row per novel, everything on it lined up on the same middle. */
.project-table td { vertical-align: middle; }
.project-table tbody tr:hover td { background: var(--panel-alt); }
.project-table tbody tr.is-parsing:hover td { background: var(--parsing); }

.project-table .num-col {
    width: 6rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    padding-right: 1rem;
}

.project-table .run-col { width: 12rem; }
.project-table .when-col { width: 7rem; white-space: nowrap; }

.project-table .auto-col {
    width: 4rem;
    text-align: center;
}

.project-table .auto-col form { margin: 0; }
.project-table .auto-col input { width: 1.05rem; height: 1.05rem; cursor: pointer; margin: 0; }

.project-table .actions-col { width: 1%; white-space: nowrap; }
.project-table .actions-col .row-actions { justify-content: flex-end; flex-wrap: nowrap; }

/* The title cell carries two lines; let it keep the width the rest does not need. */
.project-table td:nth-child(2) { min-width: 12rem; }

/* The novel's three views. */
.tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--line);
}

.tab {
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    background: transparent;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    color: var(--muted);
    padding: 0.55rem 1rem;
    margin-bottom: -1px;
    cursor: pointer;
}

.tab:hover { background: var(--accent-soft); color: var(--accent); filter: none; }

.tab.is-active {
    background: var(--panel);
    border-color: var(--line);
    border-bottom: 1px solid var(--panel);
    color: var(--ink);
}

.tab-count {
    font-weight: 500;
    font-size: 0.78rem;
    color: var(--muted);
    background: var(--soft);
    border-radius: 999px;
    padding: 0.05rem 0.45rem;
    margin-left: 0.3rem;
}

.tab-pane { display: none; }
.tab-pane.is-active { display: block; }

/* The chapter list: the same treatment, one line of actions per chapter. */
.chapter-table td { vertical-align: middle; }
.chapter-table tbody tr:hover td { background: var(--panel-alt); }
.chapter-table .num-col { width: 5rem; text-align: right; font-variant-numeric: tabular-nums; }
.chapter-table .state-col { width: 16rem; }
.chapter-table .actions-col { width: 1%; white-space: nowrap; }
.chapter-table .actions-col .row-actions { justify-content: flex-end; flex-wrap: nowrap; }
.chapter-table .mono { color: var(--muted); }

/* The runs of one novel: time, how it ended, and the only action there is. */
.run-table td { vertical-align: middle; }
.run-table .when-col { width: 9rem; white-space: nowrap; }
.run-table .state-col { width: 8rem; }
.run-table .num-col { width: 8rem; white-space: nowrap; }
.run-table .actions-col { width: 1%; white-space: nowrap; text-align: right; }

tr.is-parsing td { background: var(--parsing); }

.parsing-panel { border-left: 4px solid var(--accent); }

/* --- who is signed in, and which theme they read in ---------------------- */

.session { display: flex; align-items: center; gap: 0.6rem; flex: none; }
.session .who { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.session .who strong { color: var(--ink); font-weight: 600; }
.session form { margin: 0; }

/* A switch, not a button with a word on it: it says what you would get, in one character. */
.theme-toggle {
    font-size: 0.95rem;
    line-height: 1;
    padding: 0.4rem 0.55rem;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--accent); filter: none; }
.theme-toggle .in-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .in-dark { display: inline; }
:root[data-theme="dark"] .theme-toggle .in-light { display: none; }

/* --- signing in and claiming an empty installation ---------------------- */

.gate { display: flex; justify-content: center; padding: 3.5rem 1.5rem; }
.gate .panel { width: min(26rem, 100%); box-shadow: var(--shadow); }
.gate h2 { margin-bottom: 0.35rem; }
.gate .notice { margin-bottom: 1rem; }
.gate .actions { margin-top: 1.1rem; }
.gate button { width: 100%; justify-content: center; }

/* --- the accounts -------------------------------------------------------- */

.user-table td { vertical-align: middle; }
.user-table .actions-col { width: 1%; white-space: nowrap; text-align: right; }
.user-table .inline-form { display: flex; gap: 0.4rem; align-items: center; }
.user-table .inline-form input[type="password"] { width: 9rem; }

.badge.admin { background: var(--accent-soft); color: var(--accent); }
.badge.reader { background: var(--soft); color: var(--muted); }

/* --- the reader ---------------------------------------------------------
   A page for reading, so it is not the application's shell: no side menu, no panels, one column
   of prose on its own ground, and the chrome gets out of the way while it is being read. */

body.reading { background: var(--read-bg); }

.reader-bar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.55rem 1.25rem;
    background: color-mix(in srgb, var(--read-bg) 88%, transparent);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--line);
}
.reader-bar .where { min-width: 0; flex: 1; }
.reader-bar .where .novel {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reader-bar .where .novel:hover { color: var(--accent); }
.reader-bar .where .chapter {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reader-bar .tools { display: flex; align-items: center; gap: 0.45rem; flex: none; }
.reader-bar .count { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

/* How far through the book this chapter is - the thinnest thing that can say it. */
.reader-progress { height: 3px; background: var(--line); }
.reader-progress span { display: block; height: 100%; background: var(--accent); }

.reader-page {
    max-width: 42rem;
    margin: 0 auto;
    padding: 2.5rem 1.5rem 5rem;
}

.reader-page h1 {
    font-size: 1.5rem;
    line-height: 1.3;
    margin: 0 0 0.35rem;
}
.reader-page .chapter-meta { color: var(--muted); font-size: 0.8rem; margin: 0 0 2rem; }

/* The prose itself: the one place in the application with a reading measure and a reading size. */
.prose {
    background: var(--read-paper);
    color: var(--read-ink);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 2.2rem 2.4rem;
    font-size: var(--read-size, 1.06rem);
    line-height: 1.75;
}
.prose p { margin: 0 0 1.15em; }
.prose p:last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { line-height: 1.3; margin: 1.8em 0 0.6em; }
.prose img { max-width: 100%; height: auto; border-radius: 6px; display: block; margin: 1.4em auto; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.prose blockquote {
    margin: 1.4em 0;
    padding-left: 1.1rem;
    border-left: 3px solid var(--line);
    color: var(--muted);
}
.prose a { color: var(--accent); }
.prose em { font-style: italic; }

.reader-nav {
    display: flex;
    gap: 0.6rem;
    align-items: center;
    justify-content: space-between;
    margin-top: 1.6rem;
}
.reader-nav .btn { min-width: 8rem; text-align: center; }
.reader-nav .spacer { flex: 1; }
.reader-end { text-align: center; color: var(--muted); font-size: 0.85rem; margin-top: 1.6rem; }

/* The table of contents drops out of the bar rather than living beside the text. */
.toc {
    position: absolute;
    right: 1.25rem;
    top: 3.2rem;
    z-index: 30;
    width: min(24rem, calc(100vw - 2.5rem));
    max-height: 60vh;
    overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.4rem;
}
.toc a {
    display: flex;
    gap: 0.6rem;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--ink);
    font-size: 0.88rem;
}
.toc a:hover { background: var(--accent-soft); }
.toc a.here { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.toc a .n { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; min-width: 2.5rem; }
.toc a.here .n { color: var(--accent); }

/* Reading progress on the project list. */
.read-progress { display: block; font-size: 0.78rem; color: var(--muted); }
.read-progress.done { color: var(--ok); }

@media (max-width: 700px) {
    .prose { padding: 1.4rem 1.2rem; border-radius: 0; border-left: 0; border-right: 0; }
    .reader-page { padding: 1.5rem 0 4rem; }
    .reader-page h1, .reader-page .chapter-meta { padding: 0 1.2rem; }
    .reader-bar .count { display: none; }
}

/* --- the bookshelf -------------------------------------------------------
   The reading side's front page, and what the installed app opens on: covers, ordered by what was
   read last. It shares the reader's shape - a bar and one column - rather than the side menu, which
   is the tooling's. */

.shelf-page {
    max-width: 68rem;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 4rem;
}

.shelf-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin: 0 0 1.25rem;
}
.shelf-head h1 { font-size: 1.25rem; margin: 0; }
.shelf-empty { color: var(--muted); font-size: 0.9rem; }

.shelf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
    gap: 1.5rem 1.1rem;
}

.book { position: relative; min-width: 0; }

.book-cover {
    display: block;
    position: relative;
    aspect-ratio: 2 / 3;
    border-radius: 8px;
    overflow: hidden;
    background: var(--soft);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-cover:hover { border-color: var(--accent); }

.book-blank {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 2.6rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
}

/* The bookmark sticking out of the book: how far in this reader is. */
.book-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    background: color-mix(in srgb, var(--bg) 70%, transparent);
}
.book-bar span { display: block; height: 100%; background: var(--accent); }

/* Taking a book off the shelf: in the corner, quiet until the book is looked at. */
.book-hide { position: absolute; top: 0.35rem; right: 0.35rem; margin: 0; }
.book-hide button {
    width: 1.6rem;
    height: 1.6rem;
    padding: 0;
    line-height: 1;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel) 85%, transparent);
    color: var(--muted);
    font-size: 0.95rem;
    opacity: 0;
    transition: opacity 0.15s ease;
    cursor: pointer;
}
.book:hover .book-hide button, .book-hide button:focus-visible { opacity: 1; }
.book-hide button:hover { color: var(--ink); border-color: var(--accent); filter: none; }

.book-title {
    display: block;
    margin-top: 0.55rem;
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--ink);
    text-decoration: none;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.book-title:hover { color: var(--accent); }
.book-author, .book-state {
    display: block;
    font-size: 0.75rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.book-state { margin-top: 0.15rem; }
.book-state.done { color: var(--ok); }

/* A touch screen has no hover, so the button that takes a book away is simply always there. */
@media (hover: none) {
    .book-hide button { opacity: 1; }
}

@media (max-width: 480px) {
    .shelf-grid { grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr)); gap: 1.1rem 0.8rem; }
    .shelf-page { padding: 1rem 0.9rem 3rem; }
}
