/* ═══ Library: Header & Add Button ═══ */
.import-btn{display:inline-flex;align-items:center;gap:6px;border:none;background:var(--accent);color:#fff;font-family:var(--font-ui);font-size:13px;font-weight:600;padding:9px var(--space-4);border-radius:var(--radius-pill);cursor:pointer;box-shadow:0 3px 0 0 rgba(120,55,20,.35);transition:transform var(--duration-fast),box-shadow var(--duration-fast);flex-shrink:0}
.import-btn svg{width:14px;height:14px;stroke:currentColor;fill:none;stroke-width:2.5;stroke-linecap:round}
/* Touch ergonomics for the shelf: the import button is a primary action, its
   tap feedback is instant (no sticky hover on touch); .b-go / .b-del / .b-ghost
   get invisible hit-area extensions via the shared ::after inset below. */
.import-btn{touch-action:manipulation;-webkit-tap-highlight-color:transparent;position:relative}
.import-btn::after{content:'';position:absolute;inset:-4px}
/* Hover lift + tint are desktop enhancements only (sticky-hover guard). */
@media (hover:hover){
  .import-btn:hover{transform:translateY(-2px)}
  .lastread:hover{transform:translateY(-1px)}
  .b-ghost:hover{color:var(--accent);border-color:var(--accent)}
  .b-del:hover{color:var(--color-danger);background:rgba(228,88,79,.12)}
}
.b-del:active{color:var(--color-danger)}

.shelf-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}
.shelf-head strong{font-family:var(--font-ui);font-size:15px;font-weight:600}
.shelf-head span{font-size:11px;color:var(--muted);background:var(--surface);border:1px solid var(--border);padding:4px 10px;border-radius:var(--radius-pill);font-weight:500}

/* ═══ Empty state CTA ═══ */
.empty-sub{font-size:12px;color:var(--muted);margin:4px 0 0;font-weight:400}
.empty-cta{margin-top:14px;border:none;background:var(--accent);color:#fff;font-family:var(--font-ui);font-size:13px;font-weight:600;padding:11px 24px;border-radius:var(--radius-pill);cursor:pointer;box-shadow:0 3px 0 0 rgba(120,55,20,.35);transition:transform var(--duration-fast),box-shadow var(--duration-fast)}
.empty-cta:active{transform:translateY(2px);box-shadow:0 1px 0 0 rgba(120,55,20,.35)}

/* ═══ Currently Reading Card — dominant element of Library Home ═══ */
.lastread{position:relative;display:flex;gap:14px;align-items:center;background:var(--surface);border:1px solid color-mix(in srgb,var(--accent) 26%,var(--border));border-radius:var(--radius-lg);padding:18px 16px;box-shadow:var(--shadow-lg);margin-bottom:var(--space-4);cursor:pointer;transition:transform var(--duration-base),box-shadow var(--duration-base);overflow:hidden;animation:taskIn var(--duration-slow) var(--ease-out)}
.lastread::before{content:'';position:absolute;inset-inline-start:0;top:0;bottom:0;width:4px;background:var(--accent)}
/* Flex-wrap lets the title/progress column drop below the cover on very narrow
   screens (<360px) instead of squeezing or overlapping the artwork. */
@media (max-width:359px){
  .lastread{flex-wrap:wrap}
  .lastread img{width:44px;height:60px}
  .lr-info{flex-basis:100%;order:3}
  .lr-top{flex-wrap:wrap;gap:4px}
  .lr-title{white-space:normal;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
}
.lr-kicker{font-size:10px;font-weight:700;color:var(--accent)}
.lr-goal{font-size:11px;color:var(--text);background:color-mix(in srgb,var(--accent) 9%,var(--surface));border:1px solid color-mix(in srgb,var(--accent) 22%,transparent);padding:3px 10px;border-radius:var(--radius-pill);align-self:flex-start;font-weight:500;width:fit-content}
.lastread img{width:56px;height:76px;object-fit:cover;border-radius:var(--radius-xs);border:1px solid var(--border);flex-shrink:0;box-shadow:var(--shadow-sm)}
.lr-info{flex:1;min-width:0;display:flex;flex-direction:column;gap:6px}
.lr-top{display:flex;justify-content:space-between;align-items:center;gap:8px}
.lr-title{font-size:14px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.lr-pct{font-family:var(--font-personality);font-size:13px;color:var(--accent);flex-shrink:0;font-weight:700}
.lr-track{height:5px;border-radius:var(--radius-pill);background:var(--border);overflow:hidden}
.lr-track i{display:block;height:100%;background:linear-gradient(90deg,var(--accent),var(--accent-2));border-radius:var(--radius-pill);transition:width var(--duration-slow) ease}
.lr-sub{font-size:11px;color:var(--muted);font-weight:400}
.lr-btn{border:none;background:var(--accent);color:#fff;font-family:var(--font-ui);font-size:12px;font-weight:600;padding:9px 16px;border-radius:var(--radius-pill);cursor:pointer;box-shadow:0 3px 0 0 rgba(120,55,20,.35);flex-shrink:0;transition:transform var(--duration-fast),box-shadow var(--duration-fast)}
.lr-btn:active{transform:translateY(2px);box-shadow:0 1px 0 0 rgba(120,55,20,.35)}

/* ═══ Book Shelf — fluid column count (no single 430px breakpoint) ═══
   auto-fill + minmax lets the grid settle at 2/3/4 columns smoothly as the
   viewport grows, instead of jumping at one arbitrary width. */
.shelf-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:12px}
@media (min-width:768px){.shelf-grid{grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:16px}}

.book-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-lg);padding:10px;box-shadow:var(--shadow-1);display:flex;flex-direction:column;gap:8px;transition:transform var(--duration-base),box-shadow var(--duration-base);animation:taskIn var(--duration-slow) var(--ease-out) backwards}
/* Hover lift + cover zoom are desktop enhancements only (see base.css). */
@media (hover:hover){
  .book-card:hover{transform:translateY(-1px);box-shadow:var(--shadow-lg)}
  .book-card:hover .book-cover img{transform:scale(1.03)}
}
.book-cover{position:relative;aspect-ratio:3/4;border-radius:var(--radius-sm);overflow:hidden;background:linear-gradient(160deg,var(--accent-soft),var(--bg));display:grid;place-items:center;border:1px solid var(--border)}
.book-cover img{width:100%;height:100%;object-fit:cover;transition:transform var(--duration-slow) var(--ease-out)}
.book-cover svg{width:40px;height:40px;stroke:var(--muted);fill:none;stroke-width:1.5;opacity:.5}
.book-prog{position:absolute;bottom:0;left:0;height:4px;background:linear-gradient(90deg,var(--accent),var(--accent-2));border-radius:0 4px 4px 0;transition:width var(--duration-slow)}
.book-pct-badge{position:absolute;top:6px;inset-inline-start:6px;background:rgba(0,0,0,.55);color:#fff;font-family:var(--font-personality);font-size:11px;font-weight:700;padding:2px 8px;border-radius:var(--radius-pill);backdrop-filter:blur(4px)}
.book-title{font-size:13px;font-weight:600;line-height:1.6;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;min-height:2.6em}
.book-meta{font-size:11px;color:var(--muted);display:flex;gap:6px;flex-wrap:wrap;font-weight:400}
.book-actions{display:flex;gap:6px;align-items:center}
.b-go{flex:1;border:none;background:var(--accent);color:#fff;font-family:var(--font-ui);font-size:11px;font-weight:600;padding:7px 8px;border-radius:var(--radius-pill);cursor:pointer;box-shadow:0 2px 0 0 rgba(120,55,20,.3);transition:transform var(--duration-fast);position:relative}
.b-go::after{content:'';position:absolute;inset:-7px}
.b-go:active{transform:scale(.94)}
.b-ghost{border:1.5px solid var(--border);background:transparent;color:var(--muted);font-family:var(--font-ui);font-size:11px;font-weight:500;padding:6px 10px;border-radius:var(--radius-pill);cursor:pointer;transition:all var(--duration-fast);position:relative}
.b-ghost::after{content:'';position:absolute;inset:-7px}
.b-del{border:none;background:transparent;color:var(--muted);width:28px;height:28px;border-radius:var(--radius-xs);cursor:pointer;display:grid;place-items:center;flex-shrink:0;transition:all var(--duration-fast);position:relative}
/* Visual size stays subtle; the touch target is what must clear 44px.
   Without the invisible expansion a thumb tap next to the icon lands on the
   card (opening the book) instead of the delete button. */
.b-del::after{content:'';position:absolute;inset:-9px}
.b-del svg{width:14px;height:14px;stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}

/* Completed books — kept, visually quieter */
.book-done{opacity:.78}
.book-done .book-title{text-decoration:line-through;text-decoration-color:color-mix(in srgb,var(--muted) 55%,transparent);text-decoration-thickness:1.5px}
.book-done-badge{position:absolute;top:6px;inset-inline-start:6px;background:var(--green);color:#fff;width:22px;height:22px;border-radius:50%;display:grid;place-items:center;font-size:12px;font-weight:700}
.book-done .b-go{background:color-mix(in srgb,var(--green) 18%,var(--surface));color:var(--green);box-shadow:none;cursor:default}

/* ═══ Focus Page Background Scenes (Restored) ═══ */
.scenes{position:fixed;inset:0;pointer-events:none;z-index:0;overflow:hidden}
.scene{position:absolute;inset:0;opacity:0;transition:opacity var(--duration-slow) ease}
#page-focus.scene-rain .scene-rain{opacity:1}
#page-focus.scene-sea .scene-sea{opacity:1}
#page-focus.scene-forest .scene-forest{opacity:1}

/* Rain */
.scene-rain{background:linear-gradient(180deg,rgba(96,125,180,.16),rgba(96,125,180,.04) 55%,transparent)}
.rain-drops i{position:absolute;top:-12%;width:2px;height:16px;border-radius:2px;background:rgba(96,125,180,.4);animation:fall linear infinite}
/* Scene loops are ambient, not interaction: they keep their own slow cadence
   and are never compressed onto the UI motion tokens. */
@keyframes fall{to{transform:translateY(115vh)}}

/* Sea */
.scene-sea{background:linear-gradient(0deg,rgba(64,150,160,.18),rgba(64,150,160,.05) 45%,transparent 70%)}
.waves{position:absolute;bottom:0;left:0;width:100%;height:160px;overflow:hidden}
.waves svg{position:absolute;bottom:0;left:0;width:200%;height:100%}
.waves svg:first-child{animation:waveMove 11s linear infinite}
.waves svg:last-child{animation:waveMove 17s linear infinite reverse}
.w1{fill:rgba(64,150,160,.22)}
.w2{fill:rgba(64,150,160,.14)}
@keyframes waveMove{to{transform:translateX(-50%)}}

/* Forest */
.scene-forest{background:linear-gradient(0deg,rgba(90,140,90,.16),rgba(90,140,90,.04) 50%,transparent 75%)}
.trees{position:absolute;bottom:0;left:0;width:100%;height:140px}
.trees path{fill:rgba(70,120,80,.22)}
.flies i{position:absolute;width:5px;height:5px;border-radius:50%;background:rgba(255,220,120,.8);box-shadow:0 0 8px 2px rgba(255,220,120,.5);animation:flyFloat 8s ease-in-out infinite,twinkle 4s ease-in-out infinite}
@keyframes flyFloat{0%,100%{transform:translate(0,0)}25%{transform:translate(14px,-10px)}50%{transform:translate(-8px,-18px)}75%{transform:translate(-16px,-6px)}}

/* Only the selected ambience is allowed to animate. The unselected scenes stay
   mounted so the cross-fade still works, but their loops are paused — otherwise
   Focus, which must be the calmest view, carries all three scenes at once.
   Declared after the scene loops so the shorthand `animation` declarations above
   cannot reset animation-play-state back to running. */
.scene .rain-drops i,.scene .waves svg,.scene .flies i{animation-play-state:paused}
#page-focus.scene-rain .scene-rain .rain-drops i,
#page-focus.scene-sea .scene-sea .waves svg,
#page-focus.scene-forest .scene-forest .flies i{animation-play-state:running}

/* ═══ Reading View ═══ */
#readerView{position:fixed;inset:0;z-index:90;background:var(--bg);display:flex;flex-direction:column;padding-bottom:calc(var(--nav-height) + var(--sab))}
#readerView[hidden]{display:none}

/* Safe-area-aware header: on notched phones the title and back button would
   otherwise sit under the cutout; on devices without one, max() keeps the
   familiar 10px rhythm. */
.reader-top{display:flex;align-items:center;gap:10px;padding:calc(10px + var(--sat)) 12px 10px;padding-top:max(10px,var(--sat));background:color-mix(in srgb,var(--surface) 82%,transparent);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);border-bottom:1px solid var(--border)}
.r-back{border:none;background:var(--accent-soft);color:var(--accent);font-family:var(--font-ui);font-size:12px;font-weight:600;padding:8px 14px;border-radius:var(--radius-pill);cursor:pointer;flex-shrink:0;transition:transform var(--duration-fast)}
.r-back:active{transform:scale(.94)}
.reader-thumb{width:30px;height:40px;object-fit:cover;border-radius:6px;border:1px solid var(--border);flex-shrink:0}
.reader-thumb[hidden]{display:none}
.reader-titles{flex:1;min-width:0}
.reader-title{font-size:14px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.reader-sub{font-size:11px;color:var(--muted);margin-top:2px;font-weight:400}
.r-icon{border:none;background:transparent;color:var(--muted);width:36px;height:36px;border-radius:var(--radius-sm);cursor:pointer;display:grid;place-items:center;font-size:16px;transition:all var(--duration-fast);flex-shrink:0;position:relative}
.r-icon::after{content:'';position:absolute;inset:-5px}
@media (hover:hover){
  .r-icon:hover{color:var(--accent);background:var(--accent-soft)}
  .fallback-note button:hover{background:var(--accent-soft)}
}

.goal-bar{padding:8px 14px;background:var(--surface);border-bottom:1px solid var(--border);font-size:11px;color:var(--muted);font-weight:400}
.goal-line{display:flex;justify-content:space-between;align-items:center;gap:8px}
.goal-line button{border:none;background:none;color:var(--accent);font-family:var(--font-ui);font-size:11px;font-weight:600;cursor:pointer}
.goal-track{height:4px;border-radius:var(--radius-pill);background:var(--border);margin-top:6px;overflow:hidden}
.goal-track i{display:block;height:100%;background:linear-gradient(90deg,var(--green),var(--accent-2));border-radius:var(--radius-pill);transition:width var(--duration-slow) ease}

/* Reading scene + modes */
/* Reading scene + modes */
/* The extra bottom padding keeps the last lines of a zoomed page clear of the
   floating study dock. */
.reader-stage{flex:1;overflow:auto;display:flex;justify-content:center;padding:16px 14px 92px;position:relative;transition:background var(--duration-base);overscroll-behavior-y:contain;--reader-bright:1;--reader-fx:brightness(1)}
.reader-stage.mode-sepia{background:#efe3cd;--reader-fx:sepia(.3) saturate(.94)}
.reader-stage.mode-dark{background:#141118;--reader-fx:invert(.92) hue-rotate(180deg) contrast(.92)}
/* Optical filters act on the rendered page itself — the pdf.js canvas, or the
   fallback iframe — never on the container, so the page frame's shadow and
   every reader control keep their true colours. Highlights are deliberately
   left out: they carry their own authored colour and already switch blend mode
   with the theme, while an inverted highlight would lose its hue.
   The rule only turns on when a mode or a brightness change actually alters
   something, which keeps plain light mode completely filter-free. */
.reader-stage.has-fx :is(#pdfCanvas,#pdfFrame){filter:var(--reader-fx) brightness(var(--reader-bright))}
/* Sepia paper tone. The sepia() filter can only warm a white page by a couple of
   units — the paper colour itself comes from a colour-only multiply overlay,
   which never resamples the page, so glyphs stay exactly as crisp as pdf.js drew
   them while the blue channel drops enough to matter in low light. */
.reader-stage.mode-sepia .page-wrap::after{content:'';position:absolute;inset:0;pointer-events:none;background:#efdec0;mix-blend-mode:multiply;opacity:.62}
.mode-dark .page-wrap{background:#1b1b1b}

.reader-loading{position:absolute;inset:0;display:grid;place-items:center;background:rgba(0,0,0,.06);z-index:5}
.reader-loading[hidden]{display:none}
.spinner{width:34px;height:34px;border-radius:50%;border:3px solid var(--border);border-top-color:var(--accent);animation:spin .8s linear infinite}

.page-wrap{position:relative;isolation:isolate;margin:auto;box-shadow:var(--shadow-lg);border-radius:4px;background:#fff;width:100%;height:100%;overflow:hidden;flex-shrink:0;direction:ltr}
#pdfCanvas{display:block;position:absolute;inset:0}
#pdfFallback{position:absolute;inset:0;display:flex;flex-direction:column}
#pdfFallback[hidden]{display:none}
#pdfFrame{flex:1;min-height:0;width:100%;border:none;display:block;border-radius:4px;background:#fff}
.fallback-note{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-shrink:0;margin-bottom:6px;padding:7px 10px;border-radius:var(--radius-sm);background:color-mix(in srgb,var(--surface) 90%,transparent);border:1px solid var(--border);font-size:11px;color:var(--muted)}
.fallback-note button{border:none;background:transparent;color:var(--accent);font-family:var(--font-ui);font-size:11.5px;font-weight:700;cursor:pointer;white-space:nowrap;flex-shrink:0;padding:6px 9px;border-radius:var(--radius-xs);transition:background var(--duration-fast) var(--ease-out)}

/* pdf.js text layer — source of truth for text selection.
   Follows the upstream contract: geometry is driven by --scale-factor, and PDF
   typography stays independent from UI typography, so the inherited font
   metrics that would shift glyph advances are pinned back to their defaults.
   The page area is LTR: each run carries its own `dir` from pdf.js, and the
   surrounding RTL shell must not influence bidi inside the document. */
#textLayer{--scale-factor:1;position:absolute;inset:0;z-index:0;overflow:clip;text-align:initial;line-height:1;text-size-adjust:none;-webkit-text-size-adjust:none;forced-color-adjust:none;transform-origin:0 0;caret-color:CanvasText;letter-spacing:normal;word-spacing:normal;font-kerning:normal;font-variant-ligatures:normal;font-feature-settings:normal;text-rendering:auto;cursor:text;user-select:text;-webkit-user-select:text}
#textLayer :is(span,br){color:transparent;position:absolute;white-space:pre;cursor:text;transform-origin:0 0}
#textLayer>:not(.markedContent),#textLayer .markedContent span:not(.markedContent){z-index:1}
#textLayer span.markedContent{top:0;height:0}
#textLayer ::selection{background:color-mix(in srgb,var(--accent) 32%,transparent)}
#textLayer br::selection{background:transparent}

/* Highlights overlay */
#highlightLayer{position:absolute;inset:0;pointer-events:none;mix-blend-mode:multiply}
#highlightLayer i{position:absolute;border-radius:2px}
html[data-mode="dark"] #highlightLayer{mix-blend-mode:screen}

/* Freehand pen — the optional draw surface. It sits between the text layer and
   the highlight layer; when the pen is off it is pointer-transparent so
   selection keeps working exactly as before. */
#drawLayer{position:absolute;inset:0;pointer-events:none;z-index:0}
#drawLayer.pen-on{pointer-events:auto;touch-action:none;cursor:crosshair;z-index:1}
#textLayer.pen-off{pointer-events:none}
#drawLayer.eraser-on{pointer-events:auto;touch-action:none;cursor:cell;z-index:1}

/* Live eraser halo: follows the pointer while erasing so the user sees the
   exact kill zone. The element is created on gesture start and removed on
   gesture end — never left behind between books or engines. */
.eraser-cursor{position:fixed;width:56px;height:56px;margin:-28px 0 0 -28px;border-radius:50%;
  border:1.5px dashed var(--accent);background:color-mix(in srgb,var(--surface) 55%,transparent);
  pointer-events:none;z-index:30;will-change:left,top}

/* One-time hint that the pen can highlight anything on the page (internal
   renderer only) */
.reader-hint{position:absolute;top:10px;inset-inline:14px;z-index:4;text-align:center;padding:8px 12px;border-radius:var(--radius-pill);background:color-mix(in srgb,var(--surface) 92%,transparent);border:1px solid var(--border);box-shadow:var(--shadow-lg);font-size:11.5px;color:var(--muted);animation:hlbarIn var(--duration-fast) var(--ease-out)}
.reader-hint[hidden]{display:none}

/* Contextual highlight toolbar */
/* Contextual selection toolbar (kept for text-selection highlights; the hand
   tool and the popover share the colour swatches with it) */
#hlBar{position:absolute;z-index:6;display:flex;align-items:center;gap:7px;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-pill);padding:6px 12px;box-shadow:var(--shadow-lg);animation:hlbarIn var(--duration-fast) var(--ease-out)}
#hlBar[hidden]{display:none}
@keyframes hlbarIn{from{opacity:0;transform:translateY(4px)}}
.hlbar-label{font-size:11px;color:var(--muted);font-weight:500}
/* Color dots: the 22px swatch stays compact, but each dot owns a 36px touch
   disc so a thumb picks a color without retrying. */
.hl-dot{width:22px;height:22px;border-radius:50%;border:2px solid transparent;cursor:pointer;background:var(--hl);transition:transform var(--duration-fast);position:relative}
.hl-dot::after{content:'';position:absolute;inset:-7px;border-radius:50%}
@media (hover:hover){.hl-dot:hover{transform:scale(1.15)}}
.hl-dot.sel{border-color:var(--text)}
.hlbar-note{border:none;background:transparent;color:var(--accent);font-family:var(--font-ui);font-size:12px;font-weight:600;cursor:pointer;padding:4px 6px}

/* Pen toggle inside the pen popover */
.dock-tool{display:inline-flex;align-items:center;gap:5px;border:none;background:transparent;color:var(--muted);font-family:var(--font-ui);font-size:12px;font-weight:700;padding:8px 10px;border-radius:var(--radius-xs);cursor:pointer;white-space:nowrap;position:relative;transition:color var(--duration-fast) var(--ease-out),background var(--duration-fast) var(--ease-out)}
.dock-tool::after{content:'';position:absolute;inset:-4px -2px}
.dock-tool.on{background:var(--accent-soft);color:var(--accent)}

/* Nib-size picker: three dots at true relative sizes, each with a grown hit
   area, so the choice is self-explanatory without labels. */
.pen-widths{display:flex;align-items:center;gap:2px}
.pen-width{display:grid;place-items:center;width:30px;height:30px;border:none;background:transparent;border-radius:50%;cursor:pointer;position:relative;transition:background var(--duration-fast) var(--ease-out)}
.pen-width::after{content:'';position:absolute;inset:-7px;border-radius:50%}
.pen-width i{display:block;border-radius:50%;background:currentColor;color:var(--muted);transition:color var(--duration-fast) var(--ease-out)}
.pen-width.on{background:var(--accent-soft)}
.pen-width.on i{color:var(--accent)}
@media (hover:hover){.pen-width:hover i{color:var(--accent)}}

/* Manual page completion */
.mark-read{border:1.5px solid color-mix(in srgb,var(--green) 55%,transparent);background:color-mix(in srgb,var(--green) 12%,var(--surface));color:var(--green);font-family:var(--font-ui);font-size:12px;font-weight:700;padding:7px 14px;border-radius:var(--radius-pill);cursor:pointer;white-space:nowrap;flex-shrink:0;transition:transform var(--duration-fast),background var(--duration-fast),color var(--duration-fast);position:relative}
.mark-read::after{content:'';position:absolute;inset:-5px}
.mark-read:active{transform:scale(.96)}
.mark-read.is-read{background:var(--green);color:#fff;border-color:var(--green)}

/* Book completion reaction — brief, small */
.done-pop{position:absolute;inset:0;z-index:8;display:grid;place-items:center;background:color-mix(in srgb,var(--bg) 45%,transparent);animation:hlbarIn var(--duration-base) var(--ease-out)}
.done-pop[hidden]{display:none}
.done-pop-card{display:flex;flex-direction:column;align-items:center;gap:10px;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius-lg);padding:26px 38px;box-shadow:var(--shadow-2);text-align:center}
.done-pop-card .jingool{width:88px;height:88px}
.done-pop-card p{margin:0;font-family:var(--font-personality);font-size:16px;font-weight:700;color:var(--text)}

/* Goal overlay — reading goal choices */
.goal-choices{display:flex;gap:8px;margin:10px 0 4px}
.goal-choice{flex:1;border:1.5px solid var(--border);background:var(--bg);color:var(--text);font-family:var(--font-ui);font-size:12px;font-weight:600;padding:10px 8px;border-radius:var(--radius-sm);cursor:pointer;transition:border-color var(--duration-fast),background var(--duration-fast)}
.goal-choice.sel{border-color:var(--accent);background:color-mix(in srgb,var(--accent) 10%,var(--bg))}
.goal-text-input{width:100%;border:1.5px solid var(--border);background:var(--bg);border-radius:var(--radius-sm);padding:10px var(--space-3);font-family:var(--font-ui);font-size:16px;color:var(--text);outline:none;margin-bottom:8px}
.goal-text-input:focus{border-color:var(--accent)}
.goal-daily{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--muted);margin-bottom:10px}
.goal-daily input{width:80px;border:1.5px solid var(--border);background:var(--bg);border-radius:var(--radius-sm);padding:7px 10px;font-family:var(--font-ui);font-size:16px;color:var(--text);outline:none}
.goal-name{color:var(--text);font-weight:600}

#readerView .reader-stage{user-select:none}
#readerView .reader-stage #textLayer{user-select:text;-webkit-user-select:text}

/* Reader bottom bar — glass style matching the nav dock.
   Bottom margin clears the home indicator (max keeps the 10px rhythm on
   devices without one). */
/* Header timer — a quiet glass capsule that only reports elapsed time.
   It stays low-opacity until it is running or focused, so the reading surface
   keeps the attention. */
.reader-timer{display:inline-flex;align-items:center;gap:5px;border:1px solid var(--border);background:color-mix(in srgb,var(--surface) 64%,transparent);backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);color:var(--muted);font-family:var(--font-ui);font-size:11px;font-weight:600;font-variant-numeric:tabular-nums;padding:8px 12px;border-radius:var(--radius-pill);cursor:pointer;flex-shrink:0;opacity:.66;position:relative;transition:opacity var(--duration-fast) var(--ease-out),color var(--duration-fast) var(--ease-out),border-color var(--duration-fast) var(--ease-out),background var(--duration-fast) var(--ease-out)}
/* The capsule stays visually quiet, but its hit area is grown to the 44px
   touch minimum the rest of the reader follows. */
.reader-timer::after{content:'';position:absolute;inset:-5px}
.reader-timer.on{opacity:1;color:var(--accent);border-color:color-mix(in srgb,var(--accent) 38%,var(--border));background:var(--accent-soft)}
@media (hover:hover){.reader-timer:hover{opacity:1}}
.reader-timer:focus-visible{opacity:1}

/* ═══ Floating Study Dock ═══
   One pill replaces the old full-width bar: page stepping and the three tools
   that belong to reading. The wrapper is fixed only to anchor the pill to the
   viewport and clear the home indicator; it is pointer-transparent, so page
   gestures and text selection pass straight through to the document. */
.reader-dock{position:fixed;inset-inline:0;bottom:calc(var(--nav-height) + var(--sab) + 14px);z-index:20;display:flex;justify-content:center;pointer-events:none;opacity:1;transform:translateY(0);transition:transform var(--duration-base) var(--ease-out),opacity var(--duration-base) var(--ease-out)}
/* Zen: the dock steps aside while the reader scrolls forward and returns on a
   tap, so no control ever floats over the lines being read. */
.reader-dock.zen{opacity:0;transform:translateY(calc(100% + 28px))}
/* A hidden dock must not keep an invisible tab stop below the viewport. */
.reader-dock.zen .dock-pill{pointer-events:none}
.dock-pill{pointer-events:auto;display:flex;align-items:center;gap:4px;padding:6px 8px;border-radius:var(--radius-pill);background:linear-gradient(135deg,rgba(255,252,245,.72),rgba(255,252,245,.46));backdrop-filter:blur(22px) saturate(1.7);-webkit-backdrop-filter:blur(22px) saturate(1.7);border:1px solid rgba(255,255,255,.6);box-shadow:0 16px 38px -16px rgba(122,80,35,.34),inset 0 1px 0 rgba(255,255,255,.65)}
html[data-mode="dark"] .dock-pill{background:linear-gradient(135deg,rgba(34,29,23,.7),rgba(34,29,23,.48));border-color:rgba(255,220,180,.14);box-shadow:0 16px 38px -16px rgba(0,0,0,.74),inset 0 1px 0 rgba(255,255,255,.1)}
/* 42px visual + 3px hit-area ring keeps every dock control above the 44px
   touch minimum. */
.dock-btn{border:none;background:transparent;color:var(--muted);width:42px;height:42px;border-radius:var(--radius-pill);cursor:pointer;display:grid;place-items:center;font-size:19px;font-family:var(--font-ui);font-weight:700;line-height:1;position:relative;transition:background var(--duration-fast) var(--ease-out),color var(--duration-fast) var(--ease-out)}
.dock-btn::after{content:'';position:absolute;inset:-3px;border-radius:inherit}
.dock-btn.on{background:var(--accent-soft);color:var(--accent)}

/* Pen indicator dot: mirrors the live nib — colour of the stroke, size of the
   nib. Sits in the button's corner so the icon stays readable. */
.pen-indicator{position:absolute;inset-block-end:5px;inset-inline-start:7px;width:7px;height:7px;border-radius:50%;background:var(--muted);box-shadow:0 0 0 2px var(--surface);transition:background var(--duration-fast) var(--ease-out),transform var(--duration-fast) var(--ease-out);transform:scale(.9)}
.pen-indicator.w-thin{width:4px;height:4px}
.pen-indicator.w-medium{width:7px;height:7px}
.pen-indicator.w-thick{width:10px;height:10px;transform:scale(1)}
.dock-nav{color:var(--accent)}
.dock-page{pointer-events:auto;display:inline-flex;align-items:center;justify-content:center;gap:6px;min-width:64px;border:none;background:transparent;color:var(--text);font-family:var(--font-ui);font-size:12px;font-weight:600;padding:12px 10px;border-radius:var(--radius-pill);cursor:pointer;position:relative;transition:background var(--duration-fast) var(--ease-out),color var(--duration-fast) var(--ease-out)}
.dock-page::after{content:'';position:absolute;inset:-4px 0;border-radius:inherit}
.dock-page.on{background:var(--accent-soft);color:var(--accent)}
/* Page state is never colour-only: a dot marks a page that is already done. */
.dock-page.is-read::before{content:'';width:6px;height:6px;border-radius:50%;background:var(--green);flex-shrink:0}
.dock-sep{width:1px;height:20px;background:var(--border);flex-shrink:0;margin:0 2px}
.bar-sep{width:1px;height:22px;background:var(--border);flex-shrink:0}

/* Dock popovers — one small menu at a time, anchored to the pill */
/* The centring translate lives inside the keyframes as well: an entrance
   animation that only animates transform would otherwise override the
   centring for its whole duration and park the menu off to one side. */
.dock-pop{position:absolute;bottom:calc(100% + 10px);inset-inline-start:50%;transform:translateX(50%);pointer-events:auto;display:flex;align-items:center;gap:8px;padding:8px 12px;border-radius:var(--radius-pill);background:var(--surface);border:1px solid var(--border);box-shadow:var(--shadow-lg);animation:dockPopIn var(--duration-fast) var(--ease-out)}
@keyframes dockPopIn{from{opacity:0;transform:translateX(50%) translateY(6px)}to{opacity:1;transform:translateX(50%)}}
.dock-pop[hidden]{display:none}
.dock-pop-label{font-size:11px;color:var(--muted);font-weight:500}
.dock-pop-btn{border:none;background:transparent;color:var(--accent);font-family:var(--font-ui);font-size:12px;font-weight:600;padding:8px;border-radius:var(--radius-xs);cursor:pointer;white-space:nowrap;position:relative}
.dock-pop-btn::after{content:'';position:absolute;inset:-6px -2px}
.dock-pop-page{flex-direction:column;align-items:stretch;gap:12px;width:min(300px,86vw);padding:14px}
.dock-pop-page input[type=range]{width:100%;-webkit-appearance:none;appearance:none;height:6px;border-radius:var(--radius-pill);background:var(--border);outline:none}
.dock-pop-page input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:22px;height:22px;border-radius:50%;background:var(--surface);border:2.5px solid var(--accent);cursor:grab}
.dock-pop-page input[type=range]::-moz-range-thumb{width:22px;height:22px;border-radius:50%;background:var(--surface);border:2.5px solid var(--accent);cursor:grab}

@media (max-width:400px){
  #hlBar{gap:5px;padding:5px 9px}
}
/* ═══ Reading settings sheet ═══
   Light mode, brightness, zoom and the renderer switch live together here so
   the dock only keeps what is used while reading. */
/* The sheet is anchored to the viewport bottom, and the app's bottom nav floats
   above it — so the content carries the nav's clearance itself, otherwise the
   last row would sit behind the nav and be untappable. */
.settings-body{overflow:auto;padding:14px 18px calc(20px + var(--nav-height) + var(--sab));display:flex;flex-direction:column;gap:14px;overscroll-behavior-y:contain}
.set-row{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}
.set-label{font-size:12px;font-weight:600;color:var(--text)}
.set-chips{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
.set-chip{display:inline-flex;align-items:center;justify-content:center;border:1.5px solid var(--border);background:var(--bg);color:var(--text);font-family:var(--font-ui);font-size:12px;font-weight:600;min-height:44px;padding:0 16px;border-radius:var(--radius-pill);cursor:pointer;transition:border-color var(--duration-fast) var(--ease-out),background var(--duration-fast) var(--ease-out),color var(--duration-fast) var(--ease-out)}
.set-chip.on{border-color:var(--accent);background:var(--accent-soft);color:var(--accent)}
.set-chip.wide{padding:0 22px}
.set-val{font-size:11px;color:var(--muted);font-weight:600;min-width:42px;text-align:center;font-variant-numeric:tabular-nums}
.set-row input[type=range]{flex:1;min-width:110px;-webkit-appearance:none;appearance:none;height:6px;border-radius:var(--radius-pill);background:var(--border);outline:none}
.set-row input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:22px;height:22px;border-radius:50%;background:var(--surface);border:2.5px solid var(--accent);cursor:grab}
.set-row input[type=range]::-moz-range-thumb{width:22px;height:22px;border-radius:50%;background:var(--surface);border:2.5px solid var(--accent);cursor:grab}
.set-hint{margin:0;font-size:11px;line-height:1.9;color:var(--muted)}
.set-hint-inline{font-size:10.5px;color:var(--muted)}

/* ═══ Floating zoom & page-mode stack ═══
   Zoom and the page tint are the two controls used mid-reading, so they get a
   quiet stack on the page margin instead of hiding behind a menu. It keeps out
   of the way of the pen trail: vertical column, far side of the page. */
.reader-float{position:fixed;inset-inline-end:10px;bottom:calc(var(--nav-height) + var(--sab) + 96px);z-index:20;display:flex;flex-direction:column;align-items:center;gap:6px;pointer-events:none;opacity:1;transform:translateY(0);transition:transform var(--duration-base) var(--ease-out),opacity var(--duration-base) var(--ease-out)}
.reader-dock.zen ~ .reader-float,.reader-float.zen{opacity:0;transform:translateY(14px);pointer-events:none}
.float-btn{pointer-events:auto;width:42px;height:42px;border:none;border-radius:var(--radius-pill);background:var(--surface);color:var(--accent);font-family:var(--font-ui);font-size:19px;font-weight:700;cursor:pointer;display:grid;place-items:center;box-shadow:var(--shadow-lg);border:1px solid var(--border);position:relative;transition:transform var(--duration-fast) var(--ease-out),background var(--duration-fast) var(--ease-out),color var(--duration-fast) var(--ease-out)}
.float-btn::after{content:'';position:absolute;inset:-3px;border-radius:inherit}
.float-btn:active{transform:scale(.92)}
.float-btn.mode-light{color:var(--accent);background:var(--accent-soft);border-color:color-mix(in srgb,var(--accent) 30%,var(--border))}
.float-btn svg{display:block}
.float-val{pointer-events:none;background:var(--surface);border:1px solid var(--border);color:var(--muted);font-family:var(--font-ui);font-size:10px;font-weight:700;padding:3px 6px;border-radius:var(--radius-pill);font-variant-numeric:tabular-nums}
/* The single mode button rotates through the three tints; only the active
   glyph is visible. */
.float-btn .m-sepia,.float-btn .m-moon{display:none}
.float-btn.mode-sepia .m-sun{display:none}
.float-btn.mode-sepia .m-sepia{display:block}
.float-btn.mode-dark .m-sun,.float-btn.mode-dark .m-sepia{display:none}
.float-btn.mode-dark .m-moon{display:block}
.float-btn.mode-sepia,.float-btn.mode-dark{background:var(--surface);color:var(--accent)}

@media (max-width:400px){
  .float-btn{width:38px;height:38px;font-size:17px}
}

/* ═══ Notes Panel ═══ */
/* Small-viewport height units: svh = the keyboard-closed viewport, dvh = the
   live one. With a plain vh cap the sheet ignores the keyboard and its bottom
   rows land underneath it; with dvh-only, a fast keyboard animation can clip
   the sheet's top. svh-closed, dvh-open is the pairing that stays usable. */
.sheet{position:fixed;bottom:0;left:0;right:0;z-index:95;background:var(--surface);border-radius:var(--radius-xl) var(--radius-xl) 0 0;box-shadow:var(--shadow-2);max-height:85vh;max-height:85svh;max-height:85dvh;display:flex;flex-direction:column;animation:sheetUp var(--duration-base) var(--ease-out);padding-bottom:var(--sab)}
.sheet[hidden]{display:none}
@keyframes sheetUp{from{transform:translateY(100%)}}
.sheet-head{display:flex;justify-content:space-between;align-items:center;gap:8px;padding:16px 18px;border-bottom:1.5px dashed var(--border)}
.sheet-head strong{font-family:var(--font-ui);font-size:15px;font-weight:600}
.sheet-head div{display:flex;align-items:center;gap:6px}
.notes-list{overflow:auto;padding:12px 16px calc(12px + var(--nav-height) + var(--sab));display:flex;flex-direction:column;gap:10px;overscroll-behavior-y:contain}
.notes-empty{text-align:center;color:var(--muted);font-size:12px;padding:20px 0;font-weight:400}
.note-item{display:flex;gap:10px;align-items:flex-start;background:var(--bg);border:1px solid var(--border);border-radius:var(--radius-sm);padding:10px var(--space-3);cursor:pointer;transition:transform var(--duration-fast),border-color var(--duration-fast)}
.note-item .dot{width:10px;height:10px;border-radius:50%;flex-shrink:0;margin-top:4px}
.note-body{flex:1;min-width:0;display:flex;flex-direction:column;gap:4px}
.note-text{font-size:12px;line-height:1.7;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;font-weight:400}
.note-text .free-tag{font-style:italic;color:var(--muted);font-weight:500}
.note-note{font-size:11px;color:var(--accent);line-height:1.6;font-weight:500}
.note-page{font-size:10px;color:var(--muted);flex-shrink:0;font-weight:500}
.note-del{border:none;background:none;color:var(--muted);cursor:pointer;font-size:12px;flex-shrink:0}

#noteInput{width:100%;border:1.5px solid var(--border);background:var(--bg);border-radius:var(--radius-sm);padding:10px var(--space-3);font-family:var(--font-ui);font-size:16px;font-weight:400;color:var(--text);outline:none;resize:vertical;margin-bottom:10px}
#noteInput:focus{border-color:var(--accent)}

/* The 400px block shrinks visuals, never ergonomics: every control keeps its
   invisible hit-area expansion, so the effective touch target stays ≥44px. */
@media (max-width:400px){
  .shelf-grid{gap:10px}
  .book-title{font-size:12px}
  .lastread{padding:10px}
  .lastread img{width:44px;height:60px}
  .lr-btn{padding:7px 12px;font-size:11px}
  .dock-pill{gap:2px;padding:5px 6px}
  .dock-btn{width:38px;height:38px;font-size:17px}
  .dock-page{min-width:56px;padding:11px 8px}
  .r-icon{width:32px;height:32px}
  .reader-top{gap:8px}
}