/* 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); }
.b-link-row { display: flex; gap: var(--space-2); }
.b-link-row .b-input { flex: 1; min-width: 0; }
.b-send { display: grid; gap: var(--space-3); padding: var(--space-5); border-radius: var(--radius-md); background: var(--paper-sunken); }
.b-send__title { margin: 0; font: 620 1rem/1.5rem var(--font-sans); color: var(--ink); }
.b-send__body { margin: 0; color: var(--ink-2); }
.b-send__drag { justify-self: start; cursor: grab; }

/* ---------- Send to Bounds window ---------- */
.b-auth--compact { padding-top: var(--space-8); }
.b-auth--compact .b-auth__mark { margin-bottom: var(--space-8); }
.b-auth--compact .b-auth__foot { display: none; }
.b-save__working { justify-self: center; padding: var(--space-6) 0; }
.b-save__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.b-saved { display: grid; gap: var(--space-2); }
.b-saved__eyebrow { display: flex; align-items: center; gap: var(--space-2); margin: 0; font: 600 0.8125rem/1.125rem var(--font-sans); color: var(--ink-2); }
.b-saved__title { margin: 0; font: 600 1.375rem/1.875rem var(--font-serif); color: var(--ink); }
.b-saved__author { margin: 0; color: var(--ink-2); }
.b-saved .b-save__actions { 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; }
}

/* Reader title: a button that opens "Your reading" */
.b-rhead__title { margin: 0; font: inherit; display: flex; justify-content: center; }
.b-rhead__btn { display: grid; justify-items: center; min-width: 0; max-width: 100%; padding: 0.25rem 0.75rem; border: 0; border-radius: var(--radius-md, 10px); background: transparent; color: inherit; cursor: pointer; font: inherit; }
.b-rhead__btn:hover { background: var(--fill); }
.b-rhead__doc { display: inline-flex; align-items: center; gap: 0.25rem; max-width: 100%; }
.b-rhead__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.b-rhead__chev { display: inline-flex; flex: none; color: var(--ink-2); }
.b-rhead__chev .b-icon { width: 0.875rem; height: 0.875rem; }
.b-rhead__chapter { display: block; max-width: 100%; }

/* Your reading: a 520px dialog on wide screens, a near-full-height sheet on phones */
.b-panel--book {
  position: absolute; z-index: var(--z-dialog); top: 50%; bottom: auto; left: 50%; transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 2rem)); max-width: none; max-height: calc(100% - 4rem); overflow: auto; overscroll-behavior: contain;
  padding: var(--space-8) var(--space-8) var(--space-6); border-radius: var(--radius-xl); box-shadow: var(--elev-3);
  animation: b-dialog-in var(--dur-ui) var(--ease-out) both;
}
@keyframes b-dialog-in { from { opacity: 0; transform: translate(-50%, calc(-50% + 6px)) scale(0.98); } }
.b-panel__close { position: absolute; right: var(--space-4); top: var(--space-4); }
.b-panel--book .sp-title { padding-right: 2.5rem; }
@media (max-width: 599px) {
  .b-panel--book { top: 2.5rem; bottom: 0; left: 0; right: 0; width: 100%; transform: none; max-height: none; border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 0.5rem var(--space-5) calc(var(--space-6) + env(safe-area-inset-bottom)); animation: b-sheet-in var(--dur-sheet) var(--ease-out) both; }
  .b-panel--book .b-panel__close { top: 1.25rem; right: var(--space-4); }
  .b-panel--book .sp-book { padding-top: var(--space-3); }
}
@media (prefers-reduced-motion: reduce) { .b-panel--book { animation: none; } }
.b-reader__scrim.is-modal { background: var(--scrim) !important; }

/* ---------- Guest reader (pages#try) ---------- */
.b-rhead--guest { grid-template-columns: 5rem 1fr 5rem; }
.b-rhead--guest .b-rhead__end { justify-self: end; }
.b-rhead__btn--static { cursor: default; }
.b-rhead__btn--static:hover { background: transparent; }
.b-end .b-end__pitch { margin: var(--space-3) 0 var(--space-6); color: var(--ink-2); font-size: 1rem; line-height: 1.5rem; }

/* ---------- Front page ---------- */
.b-front { width: min(100%, 44rem); margin-inline: auto; padding: 0 var(--gutter) var(--space-12); }
.b-front__bar { display: flex; align-items: center; justify-content: space-between; min-height: var(--header-height); padding-top: env(safe-area-inset-top); }
.b-front__bar .b-wordmark svg { height: 1.5rem; width: auto; }
.b-front__bar .b-btn { margin-inline-end: calc(-1 * var(--space-2)); }
.b-front__hero { padding-top: var(--space-12); }
.b-front__title { margin: 0 0 var(--space-3); font: 620 clamp(2rem, 1.4rem + 2.6vw, 2.75rem)/1.12 var(--font-sans); letter-spacing: -0.02em; text-wrap: balance; }
.b-front__lede { margin: 0 0 var(--space-8); max-width: 34rem; color: var(--ink-2); font-size: 1.125rem; line-height: 1.6; text-wrap: pretty; }
.b-front__h2 { margin: 0 0 var(--space-2); font: 620 1.375rem/1.3 var(--font-sans); letter-spacing: -0.01em; }
.b-front__h3 { margin: 0 0 var(--space-1); font: 620 1rem/1.4 var(--font-sans); }
.b-front__body { margin: 0; color: var(--ink-2); font-size: 1rem; line-height: 1.55; text-wrap: pretty; }
.b-front__try { margin-top: var(--space-16); }
.b-front__try .b-front__body { margin-bottom: var(--space-5); }
.b-front__points { display: grid; gap: var(--space-6); margin-top: var(--space-16); padding-top: var(--space-8); border-top: 1px solid var(--hairline); }
@media (min-width: 600px) { .b-front__points { grid-template-columns: repeat(3, 1fr); } }
.b-front__foot { margin-top: var(--space-12); color: var(--ink-2); font-size: 0.9375rem; line-height: 1.5; }

/* The live demo: a small window onto the reader */
.b-demo { --read-size: var(--read-step-3); }
@media (min-width: 600px) { .b-demo { --read-size: var(--read-step-4); } }
.b-demo__stage {
  position: relative; height: clamp(15rem, 42vh, 21rem); overflow: hidden; cursor: pointer;
  border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--elev-1);
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
.b-demo__scroll { position: absolute; inset: 0; overflow: hidden; overflow-anchor: none; z-index: var(--z-text); }
.b-demo .b-reading { --gutter: var(--space-5); will-change: transform; transition: opacity var(--dur-ui) var(--ease-out); }
.b-demo .b-reading.is-fading { opacity: 0; }
.b-demo:not(.is-ready) .b-reading { visibility: hidden; }
.b-demo .b-fade--top { background: linear-gradient(to bottom, var(--surface) 8%, transparent 92%); }
.b-demo .b-fade--bottom { background: linear-gradient(to top, var(--surface) 8%, transparent 92%); }
.b-demo .b-guide.is-paused .b-fade { opacity: 1; }
.b-demo__controls { display: flex; align-items: center; gap: var(--space-4); margin-top: var(--space-4); }
.b-demo__speed { flex: 1; min-width: 0; }
.b-demo__speed-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.b-demo__wpm { margin: 0; color: var(--ink-2); font-size: 0.9375rem; text-align: center; }
.b-demo__wpm b { color: var(--ink); font-weight: 650; font-size: 1.125rem; font-variant-numeric: tabular-nums; }
.b-demo__hint { margin: var(--space-2) 0 0; color: var(--ink-2); font-size: 0.875rem; line-height: 1.4; }
@media (prefers-reduced-motion: reduce) { .b-demo .b-reading { will-change: auto; transition: none; } }
