/* Alexandrea's Library — dark theme. Desktop ≈ Okular, mobile ≈ Librera. */
:root {
  --bg: #121417; --bg2: #1b1e23; --bg3: #252a31; --line: #343a43;
  --fg: #e3e6ea; --fg2: #9aa3ad; --accent: #3daee9; --accent2: #1d6fa5; --danger: #e5534b;
  --bar-h: 48px; --side-w: 280px;
  --page-bg: #121417; --pdf-bg: #2a2e34; --pdf-filter: invert(1) hue-rotate(180deg);
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans", Roboto, sans-serif;
}
[data-theme="day"] {
  --bg: #f6f5f1; --bg2: #eef0f3; --bg3: #dfe3e8; --line: #c9cfd6;
  --fg: #1d2126; --fg2: #59626c; --accent: #1d6fa5; --accent2: #1d6fa5;
  --page-bg: #fbfaf6; --pdf-bg: #c9ccd1; --pdf-filter: none;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body { overflow: hidden; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 4px; z-index: 100; background: var(--accent); color: #000; padding: 6px 10px; }
.skip-link:focus { left: 4px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; }
.toolbar { display: flex; align-items: center; gap: 6px; height: var(--bar-h); padding: 0 8px;
  padding-top: env(safe-area-inset-top); box-sizing: content-box;
  background: var(--bg2); border-bottom: 1px solid var(--line); flex: none; z-index: 10; }
.toolbar h1 { font-size: 1rem; font-weight: 600; margin: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.logo { flex: none; }
.group { display: flex; align-items: center; gap: 2px; padding: 0 4px; border-left: 1px solid var(--line); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--bg3); cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 6px;
  border: 1px solid transparent; background: none; cursor: pointer; color: var(--fg); }
.icon-btn:hover { background: var(--bg3); border-color: var(--line); }
.icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"] { background: var(--bg3); color: var(--accent); }
select, input[type=text] { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px; }
input[type=range] { accent-color: var(--accent); }

/* ---------- Library ---------- */
.library-main { flex: 1; overflow: auto; padding: 20px; outline: none; }
.empty { color: var(--fg2); text-align: center; margin-top: 15vh; font-size: 1.1rem; }
.book-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: 22px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.book { position: relative; }
.book .open { all: unset; display: block; cursor: pointer; width: 100%; border-radius: 6px; }
.book .open:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.cover { aspect-ratio: 2 / 3; border-radius: 4px; overflow: hidden; background: linear-gradient(160deg, #2d3a4a, #1a2029);
  box-shadow: 0 4px 14px #0008; display: grid; place-items: center; text-align: center; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .ph { padding: 12px; font-weight: 600; color: #cfd8e3; font-size: .95rem; }
.book .meta { margin-top: 8px; }
.book .title { font-weight: 600; font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book .author { color: var(--fg2); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book .bar { height: 3px; background: var(--bg3); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.book .bar > i { display: block; height: 100%; background: var(--accent); }
.book .pct { font-size: .75rem; color: var(--fg2); }
.book .fmt { position: absolute; top: 6px; left: 6px; background: #000a; color: #fff; font-size: .68rem; padding: 2px 5px; border-radius: 3px; text-transform: uppercase; }
.book .del { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; background: #000b; border-radius: 50%; opacity: 0; }
.book:hover .del, .book .del:focus-visible { opacity: 1; }
@media (hover: none) { .book .del { opacity: .85; } }
.book .del:hover { color: var(--danger); }
.drop-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(3px); }
.drop-inner { width: 100%; height: 100%; border: 3px dashed var(--accent); border-radius: 18px; display: grid; place-content: center;
  justify-items: center; gap: 10px; color: var(--fg); pointer-events: none; text-align: center; }
.drop-inner svg { width: 64px; height: 64px; color: var(--accent); animation: bob 1.2s ease-in-out infinite alternate; }
.drop-inner strong { font-size: 1.6rem; }
.drop-inner span { color: var(--fg2); }
@keyframes bob { to { transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .drop-inner svg { animation: none; } }
a.icon-btn { text-decoration: none; }

/* ---------- Reader ---------- */
.reader-body { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar { width: var(--side-w); flex: none; background: var(--bg2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; }
#reader-view.no-sidebar .sidebar { display: none; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; border: 0; padding: 9px 4px; cursor: pointer; color: var(--fg2); border-bottom: 2px solid transparent; font-size: .85rem; }
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.panel { flex: 1; overflow: auto; padding: 6px 0; }
.panel ol { list-style: none; margin: 0; padding: 0; }
.panel ol ol { padding-left: 14px; }
.panel a, .panel .item { display: block; padding: 6px 12px; color: var(--fg); text-decoration: none; font-size: .88rem; border-radius: 4px; cursor: pointer; }
.panel a:hover, .panel .item:hover { background: var(--bg3); }
.panel a[aria-current="true"] { color: var(--accent); background: #3daee91a; }
.panel .muted { color: var(--fg2); padding: 10px 12px; font-size: .85rem; }
.bm-row { display: flex; align-items: center; }
.bm-row .item { flex: 1; }
.thumbs { display: grid; justify-items: center; gap: 10px; padding: 10px; }
.thumbs button { background: none; border: 2px solid transparent; padding: 2px; cursor: pointer; color: var(--fg2); font-size: .75rem; }
.thumbs button[aria-current="true"] { border-color: var(--accent); }
.thumbs canvas { display: block; width: 120px; background: #fff; }

.doc { flex: 1; min-width: 0; position: relative; background: var(--page-bg); outline: none; }
.doc foliate-view { position: absolute; inset: 0; display: block; }
.pdf-scroll { position: absolute; inset: 0; overflow: auto; padding: 12px 0; background: var(--pdf-bg);
  display: flex; flex-direction: column; align-items: center; gap: 12px; overflow-anchor: none; }
.pdf-page { position: relative; flex: none; box-shadow: 0 2px 12px #0008; background: #fff; }
.pdf-page canvas { display: block; filter: var(--pdf-filter); }
[data-theme="night"] .pdf-page, :root:not([data-theme]) .pdf-page { background: #1e1e1e; }
.textLayer .hl { background: rgba(61, 174, 233, .45); }
.textLayer .hl-cur { background: rgba(255, 140, 0, .75); }
.textLayer ::selection { background: rgba(61, 174, 233, .35); }
.pdf-page .al-marker { position: absolute; width: 0; border-left: 2px solid #ff9800; pointer-events: none; z-index: 5; }
.pdf-page .al-marker::before { content: ''; position: absolute; left: -6px; top: -7px; border: 5px solid transparent; border-top: 7px solid #ff9800; }
.flow-scroll { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; overflow-anchor: none; background: var(--page-bg); }
.flow-sec { position: relative; }
.flow-frame { display: block; width: 100%; border: 0; background: transparent; color-scheme: normal; }
.doc foliate-view { background: var(--page-bg); }

.bottombar { display: flex; align-items: center; gap: 12px; padding: 6px 12px; padding-bottom: calc(6px + env(safe-area-inset-bottom));
  background: var(--bg2); border-top: 1px solid var(--line); font-size: .8rem; color: var(--fg2); flex: none; }
.chapter-label { max-width: 30%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-wrap { flex: 1; display: flex; }
.progress-wrap input { width: 100%; }
.progress-text { min-width: 9ch; white-space: nowrap; text-align: right; }
.page-box input { width: 4.5em; text-align: center; }
.page-total { color: var(--fg2); font-size: .85rem; white-space: nowrap; }
#zoom-select { max-width: 110px; }

.popover { position: absolute; right: 8px; top: calc(var(--bar-h) + 6px + env(safe-area-inset-top)); z-index: 30; width: 290px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 14px; box-shadow: 0 8px 30px #000a;
  display: grid; gap: 12px; }
.popover label { display: grid; gap: 4px; font-size: .88rem; }
.popover select { width: 100%; }
.popover .row { display: flex; gap: 8px; }
.popover fieldset { border: 1px solid var(--line); border-radius: 6px; display: flex; gap: 16px; }
.popover fieldset label { display: flex; align-items: center; gap: 6px; }
.note { color: var(--fg2); font-size: .78rem; margin: 0; }
.popover { max-height: calc(100vh - var(--bar-h) - 30px); overflow: auto; }
.popover label.check { display: flex; align-items: center; gap: 8px; }
.piper-box { display: grid; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
.piper-box progress { width: 100%; }
#bookmark-btn[aria-pressed="true"] { color: var(--accent); }
#bookmark-btn[aria-pressed="true"] .bm-shape { fill: currentColor; }
.theme-btn .i-sun { display: none; }
[data-theme="day"] .theme-btn .i-sun { display: inline; }
[data-theme="day"] .theme-btn .i-moon { display: none; }
.search-box input { width: 190px; }
.search-panel { display: flex; flex-direction: column; padding: 0; }
.search-head { display: flex; align-items: center; gap: 2px; padding: 8px; border-bottom: 1px solid var(--line); }
.search-head .search-box { flex: 1; }
.search-head input { width: 100%; }
.search-results { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.search-results .result { all: unset; box-sizing: border-box; display: block; width: 100%; padding: 7px 12px; cursor: pointer; font-size: .85rem; border-bottom: 1px solid var(--line); }
.search-results .result:hover, .search-results .result[aria-current] { background: var(--bg3); }
.search-results .result:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.search-results .pg { display: block; color: var(--accent); font-size: .75rem; margin-bottom: 2px; }
.search-results mark { background: #ff9800; color: #000; border-radius: 2px; }
.shelf h2 { font-size: 1.05rem; margin: 4px 0 12px; color: var(--fg2); font-weight: 600; }
.shelf + .shelf { margin-top: 28px; }
.book-row { list-style: none; margin: 0; padding: 4px 2px 10px; display: flex; gap: 18px; overflow-x: auto; scroll-snap-type: x proximity; }
.book-row .book { flex: none; width: 130px; min-width: 0; scroll-snap-align: start; }
[data-theme="day"] .cover { background: linear-gradient(160deg, #c9d6e3, #e8edf2); box-shadow: 0 3px 10px #0003; }
[data-theme="day"] .cover .ph { color: #233; }
.toast { position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 6px; z-index: 60; font-size: .9rem; }

/* ---------- Mobile (Librera-style) ---------- */
@media (max-width: 720px) {
  .desktop-only { display: none !important; }
  .group { border-left: 0; padding: 0; }
  #reader-view:not(.sidebar-open) .sidebar { display: none; }
  .sidebar { position: absolute; inset: 0 auto 0 0; width: min(85vw, 320px); z-index: 20; box-shadow: 4px 0 20px #000c; }
  #reader-view .reader-toolbar, #reader-view .bottombar { position: absolute; left: 0; right: 0; transition: transform .2s; z-index: 15; }
  #reader-view .reader-toolbar { top: 0; }
  #reader-view .bottombar { bottom: 0; flex-wrap: wrap; }
  #reader-view .reader-body { position: absolute; inset: 0; }
  #reader-view.bars-hidden .reader-toolbar { transform: translateY(-110%); }
  #reader-view.bars-hidden .bottombar { transform: translateY(110%); }
  .chapter-label { max-width: none; width: 100%; order: -1; }
  .search-group { border: 0; }
  .book-row .book { width: 100px; }
  .library-main { padding: 14px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 14px; }
  .toolbar h1 { font-size: .95rem; }
  #import-btn span { display: none; }
  .popover { left: 8px; right: 8px; width: auto; }
}
.search-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: .8rem; color: var(--fg2); }
.search-opts .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.search-opts .seg label { padding: 3px 8px; cursor: pointer; }
.search-opts .seg input { position: absolute; opacity: 0; pointer-events: none; }
.search-opts .seg label:has(input:checked) { background: var(--accent2); color: #fff; }
.search-opts .seg label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.search-opts .check { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

/* ---------- Account / cloud ---------- */
.btn.big { white-space: nowrap; padding: 9px 18px; font-size: 1rem; font-weight: 600; border-radius: 8px; }
.account-slot { display: flex; gap: 8px; align-items: center; }
.modal a, .guest-note a { color: var(--accent); }
.usage { display: grid; gap: 4px; font-size: .88rem; margin: 0; }
.meter { height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--accent); }
.badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 10px; font-size: .75rem; font-weight: 700;
  background: linear-gradient(90deg, #d4a017, #f1c40f); color: #222; }
.guest-note { margin: 0 0 18px; padding: 10px 14px; border: 1px dashed var(--line); border-radius: 8px; color: var(--fg2); }
.guest-note .fine, .fine { font-size: .85rem; color: var(--fg2); }
.upload-strip { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 60; width: min(440px, calc(100% - 24px));
  display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 10px 14px; border-radius: 8px;
  background: var(--bg2); border: 1px solid var(--line); box-shadow: 0 6px 20px #0006; font-size: .88rem; }
.upload-strip .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-strip progress { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); }
.cloud-ic { position: absolute; top: 4px; left: calc(100% - 66px); width: 28px; height: 28px; display: grid; place-items: center;
  border-radius: 50%; background: #000b; color: #fff; border: 0; padding: 0; }
.cloud-ic svg { width: 18px; height: 18px; }
button.cloud-ic { cursor: pointer; }
.cloud-ic.local { color: #ccc; }
.cloud-ic.remote { color: #9fd3f5; }
button.cloud-ic:hover { color: var(--accent); }
.cloud-ic.cloud { color: #7bd88f; }
.cloud-ic.cloud .fill { fill: currentColor; fill-opacity: .35; }
.cloud-ic.downloading svg { animation: bob .8s ease-in-out infinite alternate; color: var(--accent); }
.cloud-ic.uploading svg { animation: bob .8s ease-in-out infinite alternate; color: var(--accent); }
@media (prefers-reduced-motion: reduce) { .cloud-ic.uploading svg { animation: none; } }
.modal { max-width: min(460px, calc(100% - 24px)); border: 1px solid var(--line); border-radius: 12px; padding: 22px;
  background: var(--bg2); color: var(--fg); box-shadow: 0 20px 60px #000a; }
.modal::backdrop { background: #0009; }
.modal h2 { margin: 0 0 10px; font-size: 1.25rem; }
.modal .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.modal .col { display: grid; gap: 10px; margin-top: 14px; }
.modal .col .btn { display: grid; justify-items: start; text-align: left; }
.modal .col small { color: var(--fg2); font-size: .8rem; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.modal .slider { display: grid; gap: 8px; margin: 14px 0 4px; }
.modal .slider input { width: 100%; }
.modal .price { font-size: 1.8rem; font-weight: 700; margin: 6px 0; }
@media (max-width: 720px) {
  .wide-only { display: none; }
  .btn.big { padding: 7px 9px; font-size: .88rem; }
  #library-view .help-btn { display: none; }   /* "How it works" is in the profile menu */
  #lib-title { font-size: .9rem; }
}
@media (max-width: 420px) { #library-view .logo, #tour-view .logo { display: none; } }
@media (max-width: 480px) { .account-slot .login:not(.continue) { display: none; } }   /* Log in stays in the profile menu */
/* "Continue as <email>" (signed in on another chadmurchison.com app): one tap, kept short */
.account-slot .login.continue { max-width: min(46vw, 22rem); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
@media (max-width: 480px) { .account-slot .login.continue + .signup { display: none; } }
[data-theme="day"] chadm-appbar { --cab-shadow: 0 8px 28px #0003; }

/* ---------- PDF reflow ---------- */
.rf-scroll { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; background: var(--page-bg); color: var(--fg);
  font-family: Georgia, "Iowan Old Style", "Noto Serif", serif; font-size: calc(1.1rem * var(--rf-size, 1)); line-height: var(--rf-lh, 1.5); }
.rf-page { position: relative; width: var(--rf-width, 90%); max-width: 46em; margin: 0 auto; padding: .4em 0; }
.rf-page.pending { min-height: 70vh; }
.rf-page p { margin: 0 0 .8em; text-align: justify; hyphens: auto; }
.rf-page h2 { font-size: 1.5em; margin: 1em 0 .5em; line-height: 1.25; }
.rf-page h3 { font-size: 1.2em; margin: .9em 0 .4em; line-height: 1.3; }
.rf-page figure { margin: 1em 0; text-align: center; break-inside: avoid; page-break-inside: avoid; }
/* images keep their own colours in night mode; one picture always fits on one screen */
.rf-page img { max-width: 100%; max-height: calc(var(--rf-vh, 100vh) - 3em); height: auto; object-fit: contain; border-radius: 2px; }
.rf-scroll.paged { overflow: hidden; }
.rf-scroll.paged::after { content: ''; display: block; height: 100%; }   /* any line can be the top of a page */
.rf-mask { position: absolute; left: 0; right: 0; bottom: 0; background: var(--page-bg); pointer-events: none; z-index: 2; }
.rf-pno { font: .72rem system-ui, sans-serif; color: var(--fg2); text-align: center; border-top: 1px solid var(--line);
  margin: .6em 0 .8em; padding-top: .3em; opacity: .7; user-select: none; }
.rf-page:first-child .rf-pno { border-top: 0; }
.rf-page .al-marker { position: absolute; width: 0; border-left: 2px solid #ff9800; pointer-events: none; z-index: 5; }
#reader-view:not(.is-pdf) #reflow-btn { display: none; }

/* ---------- Read-aloud bar (Librera-style) ---------- */
.tts-bar { position: absolute; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 16; transform: translateX(-50%);
  display: flex; align-items: center; gap: 2px; padding: 4px 6px; border-radius: 28px; max-width: calc(100% - 16px);
  background: var(--bg2); border: 1px solid var(--line); box-shadow: 0 6px 24px #0009; animation: slide-up .18s ease-out; }
@keyframes slide-up { from { transform: translate(-50%, 120%); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .tts-bar { animation: none; } }
.tts-bar .icon-btn { width: 42px; height: 42px; border-radius: 50%; }
.tts-bar .play { width: 48px; height: 48px; background: var(--accent2); color: #fff; }
.tts-bar .play:hover { background: var(--accent); }
.tts-bar svg { width: 22px; height: 22px; }
.tts-bar .tts-state { font-size: .75rem; color: var(--fg2); white-space: nowrap; }
.tts-bar .tts-state:empty { display: none; }
#ttsb-prev svg path, #ttsb-next svg path, .i-play path { fill: currentColor; }
.i-pause { display: none; }
.on > .i-pause { display: inline; }
.on > .i-play { display: none; }
/* its settings open just above the bar */
#tts-panel { top: auto; right: auto; left: calc(50% - 160px); width: 320px; bottom: calc(var(--bb-h, 40px) + 76px); max-height: 65vh; }
@media (max-width: 720px) {
  #reader-view:not(.bars-hidden) .tts-bar { bottom: calc(var(--bb-h, 56px) + 8px); }
  #tts-panel { left: 8px; right: 8px; width: auto; }
}

/* ---------- Car mode ---------- */
#reader-view { --car-h: min(40vh, 320px); }
#reader-view.car-mode { --page-bg: #000; --pdf-bg: #000; --fg: #fff; }
[data-theme="day"] #reader-view.car-mode { --page-bg: #fff; --pdf-bg: #fff; --fg: #000; }
#reader-view.car-mode .reader-toolbar, #reader-view.car-mode .bottombar, #reader-view.car-mode .sidebar,
#reader-view.car-mode .tts-bar { display: none !important; }
#reader-view.car-mode .reader-body { position: absolute; inset: env(safe-area-inset-top) 0 var(--car-h) 0; }
#reader-view.car-mode .rf-page p { text-align: left; }
#reader-view.car-mode .pdf-page canvas { filter: var(--pdf-filter) contrast(1.35); }
#reader-view.car-mode .pdf-scroll, #reader-view.car-mode .rf-scroll, #reader-view.car-mode .flow-scroll { overflow: hidden; }
.car-shield { position: fixed; inset: 0 0 var(--car-h) 0; z-index: 40; touch-action: none; }
.car-bar { position: fixed; left: 0; right: 0; bottom: 0; height: var(--car-h); z-index: 41; box-sizing: border-box;
  display: grid; grid-template: auto 1fr / 1fr 1.3fr 1fr; gap: 10px; padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  background: #000; border-top: 2px solid #444; }
[data-theme="day"] .car-bar { background: #fff; border-top-color: #000; }
.car-btn { display: grid; place-content: center; justify-items: center; gap: 4px; border-radius: 18px; border: 2px solid #fff;
  background: #1a1a1a; color: #fff; font-size: 1.15rem; font-weight: 700; cursor: pointer; min-height: 0; }
.car-btn svg { width: 56px; height: 56px; stroke-width: 2.6; }
.car-play { background: #ffd400; color: #000; border-color: #ffd400; border-radius: 24px; }
.car-play svg { width: 88px; height: 88px; stroke-width: 3; }
.car-play .i-play path { fill: #000; }
.car-exit { grid-column: 1 / -1; padding: 12px; border-radius: 14px; border: 2px solid #ff6b6b; background: none; color: #ff6b6b;
  font-size: 1.05rem; font-weight: 700; cursor: pointer; }
[data-theme="day"] .car-btn { background: #f2f2f2; color: #000; border-color: #000; }
[data-theme="day"] .car-play { background: #ffd400; border-color: #000; }
[data-theme="day"] .car-exit { color: #b00020; border-color: #b00020; }
.car-btn:focus-visible, .car-exit:focus-visible { outline: 4px solid var(--accent); outline-offset: 2px; }
@media (min-width: 721px) { #reader-view { --car-h: min(30vh, 240px); } .car-bar { padding-inline: max(10px, calc(50% - 360px)); } }

/* Search field: our own clear (x), shown only when there is text */
.search-box { position: relative; display: inline-flex; align-items: center; }
.search-box input { padding-right: 28px; }
.search-box input::-webkit-search-cancel-button { display: none; }
.search-clear { position: absolute; right: 2px; width: 26px; height: 26px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: none; color: var(--fg2); cursor: pointer; }
.search-clear:hover { background: var(--bg3); color: var(--fg); }
.search-clear svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.search-box input:placeholder-shown + .search-clear { display: none; }

/* Read-aloud: settings cog, sleep-timer countdown */
.tts-bar .i-gear { stroke-width: 1.8; }
.sleep-left { font: inherit; font-size: .8rem; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--accent);
  background: none; border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; cursor: pointer; }
.sleep-left[hidden] { display: none; }
.car-sleep { grid-column: 1 / -1; justify-self: center; font-size: 1.1rem; cursor: default; }
.sleep-left { display: inline-flex; align-items: center; gap: 4px; }
.sleep-left svg { width: 14px; height: 14px; }
.car-sleep svg { width: 20px; height: 20px; }
/* "download Piper for screen-off" banner, above the read-aloud bar */
.piper-banner { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 17;
  width: min(94vw, 30rem); background: var(--bg2); color: var(--fg); border: 2px solid var(--accent); border-radius: 14px;
  padding: 12px 14px; box-shadow: 0 6px 24px #0007; font-size: .92rem; }
.piper-banner[hidden] { display: none; }
.piper-banner p { margin: 0 0 10px; line-height: 1.4; }
.piper-banner .row { display: flex; gap: 8px; }
.piper-banner .btn { flex: 1; padding: 10px; }
.piper-banner progress { width: 100%; margin-bottom: 8px; }
@media (max-width: 720px) { #reader-view:not(.bars-hidden) .piper-banner { bottom: calc(var(--bb-h, 56px) + 76px); } }
#reader-view.car-mode .piper-banner { bottom: auto; top: 12px; }
.diag { max-height: 40vh; overflow: auto; font-size: .7rem; white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.piper-banner .btn { text-align: center; }
