/* App-specific layout on top of bounds.css (the design system). */

html, body { margin: 0; }
body { min-height: 100dvh; background: var(--paper); color: var(--ink); }
main:focus { outline: none; }
[hidden] { display: none !important; }
.b-root--reader, .b-root--reader body { height: 100%; overflow: hidden; overscroll-behavior: none; }

/* ---------- Toasts ---------- */
.b-toasts {
  position: fixed; z-index: var(--z-toast); left: 0; right: 0; bottom: calc(var(--space-6) + env(safe-area-inset-bottom));
  display: grid; justify-items: center; gap: var(--space-2); pointer-events: none; padding: 0 var(--space-4);
}
.b-toasts .b-toast { pointer-events: auto; }
.b-toasts--reader { position: absolute; bottom: calc(9.5rem + env(safe-area-inset-bottom)); }

/* ---------- Library ---------- */
.b-row__main { min-width: 0; }
.b-row__actions .b-menu { min-width: 11rem; }
.b-continue .b-play { pointer-events: none; }
dialog.b-dialog { border: 0; padding: var(--space-6); }
dialog.b-dialog::backdrop { background: var(--scrim); }
.b-settings__actions { display: flex; align-items: center; gap: var(--space-3); margin: var(--space-5) 0 var(--space-3); }
.b-settings form.button_to, .b-settings .button_to { display: inline; }

/* ---------- Add text ---------- */
.b-add { display: grid; gap: var(--space-6); }
.b-add__tabs { justify-self: start; }
.b-file-pick { cursor: pointer; }
.b-file-pick:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.b-drop__idle { display: grid; justify-items: center; gap: var(--space-2); }
.b-add .b-notice { margin-top: var(--space-4); }

/* ---------- Reader ---------- */
.b-reader { opacity: 1; }
.b-reader:not(.is-ready) .b-reading { visibility: hidden; }
.b-reader__scroll { outline: none; -webkit-overflow-scrolling: touch; overflow-anchor: none; } /* the reader anchors its own scroll when sections come and go */
.b-reader__scroll::-webkit-scrollbar { display: none; }
.b-reading { box-sizing: border-box; will-change: transform; }
.b-section + .b-section { margin-top: 2.6em; }
.b-section > :is(h1, h2, h3):first-child { margin-top: 0; }
.b-section > p:first-child, .b-section > :is(h1, h2, h3, h4, h5, h6) + p { text-indent: 0; }
.b-reading .b-matter { color: var(--ink-2); }
.b-tail { display: flex; flex-direction: column; justify-content: flex-start; }
.b-tail .b-end { margin-top: 4.5rem; margin-bottom: 9rem; }
.b-reading .b-end p { text-indent: 0; }
.b-reader.is-at-end .b-rfoot, .b-reader.is-at-end .b-guide { opacity: 0; pointer-events: none; }
.b-guide { transition: opacity var(--dur-ui) var(--ease-out); }

.b-rhead__doc { margin: 0; }
.b-play .b-play__pause { display: none; transform: none; }
.b-play.is-playing .b-play__play { display: none; }
.b-play.is-playing .b-play__pause { display: block; }

.b-overlay { position: absolute; left: 0; right: 0; display: flex; justify-content: center; pointer-events: none; }
.b-overlay > * { pointer-events: auto; }
.b-overlay--resume { z-index: var(--z-pill); top: calc(var(--read-line) + var(--read-size) * 1.55 / 2 + 0.75rem); }
.b-overlay--hud { z-index: var(--z-pill); bottom: calc(2.5rem + env(safe-area-inset-bottom)); }
.b-overlay--hud .b-hud b { font-weight: 620; }
.b-overlay--coach { z-index: var(--z-card); top: calc(var(--read-line) + var(--read-size) * 1.55 / 2 + 1.25rem); padding: 0 var(--space-4); }
.b-overlay--dialog { z-index: var(--z-dialog); inset: 0; align-items: center; padding: var(--space-4); }
.b-reader__scrim { z-index: var(--z-scrim); }

.b-coach__keys--touch { display: none; }
@media (pointer: coarse) {
  .b-coach__keys--touch { display: flex; }
  .b-coach__keys--keyboard { display: none; }
}
.b-coach__keys dt .b-icon { width: 1rem; height: 1rem; color: var(--ink-2); }

.b-tset__foot { width: 100%; border: 0; border-top: 1px solid var(--hairline); background: transparent; cursor: pointer; text-align: left; }
.b-tset__foot:hover span:first-child { color: var(--ink); }

/* Panels: popovers above the control bar on wide screens */
.b-panel {
  position: absolute; z-index: var(--z-popover); bottom: calc(6.75rem + env(safe-area-inset-bottom));
  width: var(--popover-width); max-width: calc(100vw - 2rem); padding: var(--space-4);
  border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: var(--elev-2);
  animation: b-pop-in var(--dur-ui) var(--ease-out) both;
}
.b-panel--speed { left: max(1rem, calc(50% - 15rem)); }
.b-panel--chapters { left: min(calc(100% - 1rem - 300px), calc(50% + 60px)); width: 300px; }
.b-panel--text { left: min(calc(100% - 1rem - 300px), calc(50% - 30px)); width: 300px; }
.b-panel .b-sheet__grabber, .b-panel .b-panel__sheet-head { display: none; }

/* ...and bottom sheets on phones */
@media (max-width: 599px) {
  .b-wide-only { display: none !important; }
  .b-panel {
    left: 0; right: 0; bottom: 0; width: 100%; max-width: none; z-index: var(--z-dialog);
    padding: 0.5rem var(--space-5) calc(var(--space-6) + env(safe-area-inset-bottom));
    border-radius: var(--radius-xl) var(--radius-xl) 0 0; box-shadow: var(--elev-3);
    animation: b-sheet-in var(--dur-sheet) var(--ease-out) both;
  }
  .b-panel .b-sheet__grabber { display: block; }
  .b-panel .b-panel__sheet-head { display: grid; }
  .b-panel--speed .b-speed__step { width: 3.5rem; height: 3.5rem; }
  .b-panel--speed .b-speed__num { font-size: 3.25rem; line-height: 3.5rem; }
  .b-panel .b-toc { max-height: 55vh; }
}
@media (min-width: 600px) { .b-reader__scrim:not(.is-modal) { background: transparent; } }
.b-reader__scrim:has(~ .b-overlay--dialog:not([hidden])) { background: var(--scrim); }

@media (prefers-reduced-motion: reduce) {
  .b-panel { animation: none; }
  .b-reading { will-change: auto; }
}
