/* Lumin Reader: search in this book and the Contents panel (PB-U4; design 9, build plan 6.9).
   Copyright (C) 2026 B7 Collective LLC. Licensed under AGPL-3.0-only.
   Both float over the page in the paper's own colors (--pcard, --ink, --pmuted, --prule from reader.css), never move
   it, and keep every target at least 44 px. Phones: full width cards; 760 px and up: 400 px panels (search on the
   right, Contents on the left) with the page visible beside them. */

/* ---- Search: the field (in the top card's place) ---- */
.srch { position: absolute; inset: 0; z-index: 24; pointer-events: none; font-family: var(--sans); color: var(--ink); }
.reader[data-mode="scroll"] .srch { position: fixed; }
.srch > * { pointer-events: auto; }
.srch-top { position: absolute; top: calc(8px + var(--safe-top)); left: 8px; right: 8px; min-height: 56px; box-sizing: border-box; display: flex; align-items: center; gap: 4px; padding: 0 6px 0 14px;
  background: var(--pcard, #FFFDF8); border-radius: 22px; box-shadow: var(--float, 0 10px 30px rgb(0 0 0 / .18)), 0 0 0 1px var(--pline2, rgb(0 0 0 / .06)); margin: 0; }
.srch-top[hidden] { display: none; }
.srch-ic { display: inline-flex; color: var(--pmuted); flex-shrink: 0; }
.srch-in { flex: 1; min-width: 0; height: 44px; border: 0; background: transparent; color: var(--ink); font-family: var(--sans); font-size: calc(17px * var(--cscale, 1)); padding: 0 4px; outline: none; -webkit-appearance: none; appearance: none; }
.srch .srch-in, .srch .srch-in:focus-visible, .rd-toc .toc-filter, .rd-toc .toc-filter:focus-visible { border: 0; box-shadow: none; background: transparent; border-radius: 0; outline: none; width: auto; min-height: 44px; }
.srch-in::-webkit-search-cancel-button { display: none; }
.srch-in::placeholder { color: var(--pmuted); opacity: 1; }
.srch-top:focus-within { box-shadow: var(--float, 0 10px 30px rgb(0 0 0 / .18)), 0 0 0 2px var(--sel-edge, #1F6F78); }
.srch-clear { width: 44px; height: 44px; flex-shrink: 0; display: inline-grid; place-items: center; border: 0; border-radius: 50%; background: color-mix(in srgb, var(--ink) 8%, transparent); color: var(--pmuted); }
.srch-clear[hidden] { display: none; }
.srch-cancel { min-height: 44px; padding: 0 10px; border: 0; background: none; color: var(--sel-edge, #1F6F78); font-family: var(--sans); font-weight: 700; font-size: calc(16px * var(--cscale, 1)); flex-shrink: 0; border-radius: 12px; }
.reader[data-paper="night"] .srch-cancel, .reader[data-paper="dusk"] .srch-cancel { color: #8FD3DA; }

/* ---- Search: the results card ---- */
.srch-list { position: absolute; top: calc(76px + var(--safe-top)); left: 8px; right: 8px; bottom: calc(8px + var(--safe-bottom)); display: flex; flex-direction: column; overflow: hidden;
  background: var(--pcard, #FFFDF8); border-radius: 26px; box-shadow: var(--float, 0 10px 30px rgb(0 0 0 / .18)), 0 0 0 1px var(--pline2, rgb(0 0 0 / .06)); }
.srch-list[hidden] { display: none; }
.srch-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px 12px 20px; border-bottom: 1px solid var(--prule); flex-shrink: 0; flex-wrap: wrap; }
.srch-head[hidden] { display: none; }
.srch-count { margin: 0; font-weight: 700; font-size: calc(15px * var(--cscale, 1)); min-width: 0; }
.srch-chip { min-height: 44px; padding: 0 16px; border-radius: 22px; border: 1px solid var(--prule); background: transparent; color: var(--ink); font-family: var(--sans); font-weight: 700; font-size: calc(14px * var(--cscale, 1)); }
.srch-chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.srch-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 8px 16px; }
.srch-jumps:empty { display: none; }
.srch-jumps { padding: 6px 0; border-bottom: 1px solid var(--prule); margin-bottom: 4px; }
.srch-jump { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 0 12px; border: 0; border-radius: 14px; background: none; color: var(--ink); text-align: left;
  font-family: var(--sans); font-weight: 700; font-size: calc(16px * var(--cscale, 1)); }
.srch-jump .icon { color: var(--sel-edge, #1F6F78); flex-shrink: 0; }
.srch-grp { margin-top: 8px; }
.srch-gh { display: flex; justify-content: space-between; gap: 12px; margin: 0; padding: 12px 12px 6px; font-family: var(--sans); font-weight: 700; font-size: calc(12px * var(--cscale, 1)); letter-spacing: .08em; text-transform: uppercase; color: var(--pmuted); }
.srch-gh span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srch-gn { flex-shrink: 0; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.srch-rows { list-style: none; margin: 0; padding: 0; }
.srch-row { display: flex; flex-direction: column; gap: 4px; width: 100%; padding: 12px; border: 0; border-radius: 16px; background: none; color: var(--ink); text-align: left; min-height: 44px; }
.srch-row:hover, .srch-jump:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.srch-row[aria-current="true"] { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.srch-text { font-family: var(--serif); font-size: calc(16px * var(--cscale, 1)); line-height: 1.45; overflow-wrap: anywhere; }
.srch-text mark { background: rgb(var(--hl-y, 242 181 68) / .38); color: inherit; font-weight: 600; border-radius: 3px; padding: 0 1px; }
/* Dark papers: white text on a deeper gold, 4.5:1 or better (APD-09: 4.33:1 on Dusk) */
.reader[data-paper="dusk"] .srch-text mark, .reader[data-paper="night"] .srch-text mark { background: rgb(242 181 68 / .3); color: #FFFFFF; }
.reader[data-paper="dusk"] ::highlight(srch), .reader[data-paper="night"] ::highlight(srch) { background-color: rgb(242 181 68 / .26); color: #FFFFFF; }
.srch-where { font-family: var(--sans); font-size: calc(13px * var(--cscale, 1)); color: var(--pmuted); }
.srch-more, .srch-try { min-height: 44px; margin: 12px 12px 0; padding: 0 18px; border-radius: 22px; border: 1px solid var(--prule); background: transparent; color: var(--ink); font-family: var(--sans); font-weight: 700; font-size: calc(15px * var(--cscale, 1)); }
.srch-more[hidden], .srch-empty[hidden] { display: none; }
.srch-empty { padding: 20px 12px 8px; }
.srch-empty p { margin: 0 0 4px; font-size: calc(16px * var(--cscale, 1)); line-height: 1.45; }
.srch-try { margin-left: 0; margin-right: 8px; background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---- Search: the results bar (an ink pill) and "Done takes you back to page 3" ---- */
.srch-dock { position: absolute; left: 8px; right: 8px; bottom: calc(8px + var(--safe-bottom)); z-index: 26; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.srch-dock[hidden] { display: none; }
.srch-dock[data-at="top"] { bottom: auto; top: calc(8px + var(--safe-top)); flex-direction: column-reverse; }
.srch-dock > * { pointer-events: auto; }
.srch-bar { box-sizing: border-box; width: 100%; max-width: 560px; min-height: 54px; display: flex; align-items: center; gap: 2px; padding: 4px 6px; border-radius: 27px;
  background: var(--bar-ink, #1B232C); color: var(--bar-text, #F4F1EA); box-shadow: 0 14px 30px -12px rgb(0 0 0 / .5); }
.srch-b { min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 10px; border: 0; border-radius: 22px; background: none; color: inherit;
  font-family: var(--sans); font-weight: 700; font-size: calc(15px * var(--cscale, 1)); white-space: nowrap; flex-shrink: 0; }
.srch-b:hover { background: rgb(255 255 255 / .08); }
.srch-b:disabled { opacity: .4; }
.srch-b .icon { width: 20px; height: 20px; }
.srch-pos { flex: 0 0 auto; padding: 0 6px; text-align: center; font-weight: 700; font-size: calc(15px * var(--cscale, 1)); font-variant-numeric: tabular-nums; white-space: nowrap; }
.srch-sep { width: 1px; align-self: stretch; margin: 8px 4px; background: rgb(255 255 255 / .18); flex-shrink: 0; }
.srch-done { color: var(--accent, #F2B544); }
/* "Done takes you back to page 3": the bar's first row, a quiet button inside the ink bar (never over the page) */
.srch-bar { flex-wrap: wrap; }
.srch-pill { flex: 1 0 100%; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; max-width: 100%; box-sizing: border-box; padding: 2px 12px 0; border: 0; border-radius: 16px;
  background: none; color: rgb(244 241 234 / .78); font-family: var(--sans); font-weight: 700; font-size: calc(13px * var(--cscale, 1)); cursor: pointer; }
.srch-pill[hidden] { display: none; }
.srch-pill:hover { color: var(--bar-text, #F4F1EA); background: rgb(255 255 255 / .06); }
.srch-pill span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srch-pill .icon { flex-shrink: 0; }
.srch-nav, .srch-acts { display: flex; align-items: center; gap: 2px; min-width: 0; }
.srch-nav { flex: 1 1 auto; justify-content: space-between; }
.srch-acts { flex: 0 0 auto; }
/* When one row can't hold it all (narrow phones, large text, long counts): ‹ 1 of 9 › above List · Read here · Done */
.srch-bar[data-rows="2"] { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 0; padding: 4px 6px; border-radius: 22px; }
.srch-bar[data-rows="2"] .srch-sep { width: auto; height: 1px; margin: 2px 8px; align-self: auto; }
.srch-bar[data-rows="2"] .srch-acts { justify-content: space-between; flex-wrap: wrap; }
@media (max-width: 359px) {
  .srch-b { padding: 0 8px; font-size: calc(14px * var(--cscale, 1)); }
  .srch-pill span { white-space: normal; text-align: center; text-wrap: balance; }
  .srch-pill { padding: 6px 14px; }
  .srch-top { padding-left: 10px; }
  .srch-cancel { padding: 0 6px; }
  .srch-head { padding-left: 14px; }
}

/* Matches on the page: every match tinted, the current one strong with ink text */
::highlight(srch) { background-color: rgb(var(--hl-y, 242 181 68) / .30); }
::highlight(srch-cur) { background-color: rgb(var(--hl-y, 242 181 68) / .85); color: #1B232C; }
.srch-boxes { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.srch-boxes i { position: fixed; border-radius: 3px; background: rgb(var(--hl-y, 242 181 68) / .30); mix-blend-mode: multiply; }
.srch-boxes i.cur { background: rgb(var(--hl-y, 242 181 68) / .85); box-shadow: 0 0 0 3px rgb(var(--hl-y, 242 181 68) / .45); }
.reader[data-paper="night"] .srch-boxes i, .reader[data-paper="dusk"] .srch-boxes i { mix-blend-mode: normal; }

/* ---- Contents ---- */
.rd-toc { position: absolute; z-index: 24; left: 0; right: 0; top: calc(44px + var(--safe-top)); bottom: 0; display: flex; flex-direction: column; overflow: hidden;
  background: var(--pcard, #FFFDF8); color: var(--ink); border-radius: 26px 26px 0 0; box-shadow: var(--float, 0 10px 30px rgb(0 0 0 / .18)), 0 0 0 1px var(--pline2, rgb(0 0 0 / .06)); font-family: var(--sans);
  padding-bottom: var(--safe-bottom); animation: tocIn 220ms var(--ease) both; }
.reader[data-mode="scroll"] .rd-toc { position: fixed; }
@keyframes tocIn { from { transform: translateY(24px); opacity: 0; } }
.toc-head { display: flex; align-items: flex-start; gap: 8px; padding: 16px 10px 8px 20px; flex-shrink: 0; }
.toc-ttl { flex: 1; min-width: 0; }
.toc-ttl h2 { margin: 6px 0 0; font-family: var(--serif); font-weight: 400; font-size: calc(21px * var(--cscale, 1)); line-height: 1.2; overflow-wrap: anywhere; }
.toc-by { margin: 4px 0 0; color: var(--pmuted); font-size: calc(14px * var(--cscale, 1)); }
.toc-x { width: 44px; height: 44px; flex-shrink: 0; display: inline-grid; place-items: center; border: 0; border-radius: 50%; background: color-mix(in srgb, var(--ink) 7%, transparent); color: var(--ink); }
.toc-fwrap { display: flex; align-items: center; gap: 8px; margin: 4px 16px 8px; padding: 0 12px; border-radius: 14px; background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--pmuted); flex-shrink: 0; }
.toc-fwrap:focus-within { box-shadow: 0 0 0 2px var(--sel-edge, #1F6F78); }
.toc-filter { flex: 1; min-width: 0; height: 44px; border: 0; background: transparent; color: var(--ink); font-family: var(--sans); font-size: calc(16px * var(--cscale, 1)); outline: none; -webkit-appearance: none; appearance: none; }
.toc-filter::placeholder { color: var(--pmuted); opacity: 1; }
.toc-filter::-webkit-search-cancel-button { display: none; }
.toc-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 8px 20px; }
.toc-tree, .toc-subs, .toc-found ul { list-style: none; margin: 0; padding: 0; }
.toc-tree[hidden], .toc-found[hidden], .toc-subs[hidden] { display: none; }
.toc-part h3 { margin: 18px 12px 6px; font-size: calc(12px * var(--cscale, 1)); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--pmuted); }
.toc-row { display: flex; align-items: stretch; gap: 2px; }
.toc-go, .toc-hit { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 8px 12px; border: 0; border-radius: 14px; background: none; color: var(--ink); text-align: left;
  font-family: var(--sans); font-size: calc(16px * var(--cscale, 1)); }
.toc-go:hover, .toc-hit:hover, .toc-sub:hover, .toc-exp:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.toc-name { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.toc-t { overflow-wrap: anywhere; line-height: 1.3; }
.toc-alt { color: var(--pmuted); font-size: calc(13px * var(--cscale, 1)); }
.toc-meta { flex-shrink: 0; display: inline-flex; align-items: center; gap: 8px; color: var(--pmuted); font-size: calc(13px * var(--cscale, 1)); font-variant-numeric: tabular-nums; }
.toc-meta.ok { color: var(--sage, #6F8F6C); }
.reader[data-paper="night"] .toc-meta.ok, .reader[data-paper="dusk"] .toc-meta.ok { color: #9CC59A; }
.toc-rib { flex-shrink: 0; display: inline-flex; color: var(--berry, #B4527A); }
.reader[data-paper="night"] .toc-rib, .reader[data-paper="dusk"] .toc-rib { color: #E58AAE; }
.toc-ch.done .toc-t { color: color-mix(in srgb, var(--ink) 78%, var(--pmuted)); }
/* Your place: raised, a marigold edge and a progress bar */
.toc-ch.cur > .toc-row .toc-go { background: color-mix(in srgb, var(--ink) 5%, var(--pcard, #FFFDF8)); box-shadow: inset 4px 0 0 var(--accent, #F2B544), 0 6px 16px -10px rgb(0 0 0 / .35); font-weight: 700; }
.toc-here { font-size: calc(12px * var(--cscale, 1)); font-weight: 700; color: var(--ink); }
.toc-bar { display: inline-block; width: 44px; height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--ink) 12%, transparent); overflow: hidden; }
.toc-bar i { display: block; height: 100%; background: var(--accent, #F2B544); border-radius: 2px; }
.toc-exp { width: 44px; min-height: 44px; flex-shrink: 0; display: inline-grid; place-items: center; border: 0; border-radius: 14px; background: none; color: var(--pmuted); }
.toc-exp .icon { transition: transform 160ms var(--ease); }
.toc-exp[aria-expanded="true"] .icon { transform: rotate(180deg); }
.toc-subs { padding: 2px 4px 10px 16px; }
.toc-subs.nums { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 4px; }
.toc-sub { width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: 12px; background: none; color: var(--ink); text-align: left; font-family: var(--sans); font-size: calc(15px * var(--cscale, 1)); }
.toc-subs.nums .toc-sub { text-align: center; padding: 0; background: color-mix(in srgb, var(--ink) 4%, transparent); font-variant-numeric: tabular-nums; }
.toc-hit { flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; }
.toc-none { margin: 16px 12px; color: var(--pmuted); font-size: calc(15px * var(--cscale, 1)); }

/* Focus rings for both panels */
.srch button:focus-visible, .rd-toc button:focus-visible { outline: 2px solid var(--link, #1F6F78); outline-offset: 2px; }
.srch-bar button:focus-visible { outline-color: #8FD3DA; }
.reader[data-paper="night"] .srch button:focus-visible, .reader[data-paper="dusk"] .srch button:focus-visible,
.reader[data-paper="night"] .rd-toc button:focus-visible, .reader[data-paper="dusk"] .rd-toc button:focus-visible { outline-color: #8FD3DA; }

/* Wide screens: panels beside the page */
@media (min-width: 760px) {
  .srch-top { left: auto; right: 16px; width: 400px; top: calc(14px + var(--safe-top)); }
  .srch-list { left: auto; right: 16px; width: 400px; top: calc(84px + var(--safe-top)); bottom: calc(16px + var(--safe-bottom)); border-radius: 22px; }
  .srch-dock { left: 50%; right: auto; width: min(560px, calc(100vw - 32px)); transform: translateX(-50%); bottom: calc(14px + var(--safe-bottom)); }
  .srch-dock[data-at="top"] { top: calc(14px + var(--safe-top)); }
  .rd-toc { left: 16px; right: auto; width: 400px; top: calc(14px + var(--safe-top)); bottom: calc(14px + var(--safe-bottom)); border-radius: 22px; padding-bottom: 0; animation-name: tocInSide; }
  @keyframes tocInSide { from { transform: translateX(-16px); opacity: 0; } }
}
/* Short screens held sideways: the field and the list share the height */
@media (max-height: 520px) and (max-width: 759px) {
  .srch-list { top: calc(70px + var(--safe-top)); }
  .rd-toc { top: calc(8px + var(--safe-top)); border-radius: 22px 22px 0 0; }
}
/* Calmer motion: no slide-ins */
@media (prefers-reduced-motion: reduce) { .rd-toc { animation: none; } .toc-exp .icon { transition: none; } }
html.calm .rd-toc { animation: none; } html.calm .toc-exp .icon { transition: none; }
