.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: minmax(13rem, 1fr) auto minmax(13rem, 1fr);
  align-items: center;
  min-height: 4.75rem;
  padding-inline: clamp(var(--space-4), 4vw, var(--space-10));
  background: color-mix(in srgb, var(--color-paper) 88%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--color-line) 72%, transparent);
  backdrop-filter: blur(18px) saturate(130%);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  width: fit-content;
}

.brand > span:last-child {
  display: grid;
}

.brand strong {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1;
}

.brand small {
  margin-top: var(--space-1);
  color: var(--color-muted);
  font-size: var(--text-xs);
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 4px);
  align-items: end;
  gap: 3px;
  width: 1.5rem;
  height: 1.75rem;
  padding: 3px;
  border-bottom: 2px solid var(--color-accent);
}

.brand-mark i {
  display: block;
  height: 100%;
  background: var(--color-accent);
  border-radius: 1px 1px 0 0;
}

.brand-mark i:nth-child(2) {
  height: 78%;
}

.brand-mark i:nth-child(3) {
  height: 91%;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.nav-link,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.nav-link {
  color: var(--color-muted);
  font-size: var(--text-sm);
  font-weight: 650;
}

.nav-link:hover {
  color: var(--color-ink);
  background: color-mix(in srgb, var(--color-ink) 6%, transparent);
}

.nav-link.is-current {
  color: var(--color-ink);
  background: transparent;
  border-radius: 0;
  box-shadow: inset 0 -2px 0 var(--color-accent);
}

.button {
  color: var(--color-on-action);
  background: var(--color-action);
  font-size: var(--text-sm);
  font-weight: 650;
}

.button:hover:not(:disabled) {
  background: var(--color-action-hover);
  transform: none;
}

.button:active:not(:disabled) {
  transform: scale(0.98);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.button-quiet {
  color: var(--color-ink-soft);
  background: transparent;
}

.button-quiet:hover:not(:disabled) {
  color: var(--color-ink);
  background: var(--color-surface);
}

.button-quiet:active:not(:disabled) {
  background: color-mix(in srgb, var(--color-ink) 10%, transparent);
}

.button-secondary {
  color: var(--color-ink);
  background: transparent;
  border: 1px solid var(--color-ink);
}

.button-secondary:hover:not(:disabled) {
  color: var(--color-ink);
  background: color-mix(in srgb, var(--color-ink) 8%, transparent);
}

.local-status {
  display: inline-flex;
  align-items: center;
  justify-self: end;
  gap: var(--space-2);
  color: var(--color-muted);
  font-size: var(--text-xs);
  font-weight: 650;
}

.local-status span {
  width: 0.5rem;
  height: 0.5rem;
  background: var(--color-positive);
  border-radius: 50%;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-positive) 15%, transparent);
}

.loading-state {
  display: grid;
  place-content: center;
  min-height: 55vh;
  color: var(--color-muted);
  text-align: center;
}

.loading-mark {
  width: 2.5rem;
  height: 2.5rem;
  margin-inline: auto;
  border: 2px solid var(--color-line);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(1turn); }
}

.home-intro {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(18rem, 0.55fr);
  gap: clamp(var(--space-8), 6vw, var(--space-20));
  align-items: end;
  padding-block: var(--space-8) var(--space-16);
}

.home-intro h1 {
  max-width: 15ch;
  margin-bottom: var(--space-4);
}

.home-intro .intro-copy {
  max-width: 58ch;
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-lg);
}

.library-stat {
  padding: var(--space-6) 0 var(--space-3) var(--space-6);
  border-left: 1px solid var(--color-line);
}

.library-stat strong {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 500;
  line-height: 1;
}

.library-stat span {
  display: block;
  margin-top: var(--space-2);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: var(--space-6);
}

.section-heading h2 {
  margin-bottom: 0;
}

.section-heading p {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.continue-section {
  margin-bottom: var(--space-16);
}

.empty-reading {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-5);
  align-items: center;
  min-height: 8rem;
  padding: var(--space-6);
  background: linear-gradient(120deg, var(--color-surface), color-mix(in srgb, var(--color-accent-soft) 22%, var(--color-surface)));
  border: 1px solid var(--color-line-soft);
  border-radius: var(--radius-lg);
}

.empty-reading-symbol {
  display: grid;
  place-items: center;
  width: 3.5rem;
  height: 4.25rem;
  color: var(--color-accent-strong);
  background: var(--color-accent-soft);
  border: 1px solid color-mix(in srgb, var(--color-accent) 30%, transparent);
  border-radius: 3px 8px 8px 3px;
  font-family: var(--font-reading);
  font-size: var(--text-xl);
}

.empty-reading h3 {
  margin-bottom: var(--space-1);
  font-family: var(--font-display);
  font-size: var(--text-lg);
}

.empty-reading p {
  max-width: 56ch;
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.collection-list {
  display: grid;
  gap: var(--space-12);
}

.collection-section {
  padding-top: var(--space-8);
  border-top: 1px solid var(--color-line);
}

.collection-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.collection-title-row h2 {
  margin: 0;
}

.collection-count {
  color: var(--color-muted);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.shelf-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}

.shelf-summary {
  position: relative;
  min-height: 8.75rem;
  overflow: hidden;
  padding: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-line-soft);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}

.shelf-summary:hover {
  border-color: color-mix(in srgb, var(--shelf-color) 45%, var(--color-line));
  box-shadow: 0 12px 28px color-mix(in srgb, var(--color-ink) 8%, transparent);
  transform: translateY(-2px);
}

.shelf-summary::after {
  content: "";
  position: absolute;
  inset: auto var(--space-5) var(--space-4);
  height: 3px;
  background: linear-gradient(90deg, var(--shelf-color, var(--color-accent)) 0 35%, var(--color-line-soft) 35% 100%);
  border-radius: var(--radius-pill);
}

.shelf-summary h3 {
  max-width: 24ch;
  margin-bottom: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-lg);
}

.shelf-summary p {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.shelf-arrow {
  position: absolute;
  right: var(--space-5);
  bottom: var(--space-6);
  color: var(--color-muted);
  font-size: var(--text-lg);
  transition: color var(--transition-fast), transform var(--transition-fast);
}

.shelf-summary:hover .shelf-arrow {
  color: var(--color-ink);
  transform: translateX(2px);
}

.stale-banner {
  position: relative;
  z-index: 19;
  padding: var(--space-3) var(--space-6);
  color: var(--color-ink);
  background: var(--color-accent-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--color-accent) 35%, transparent);
  text-align: center;
  font-size: var(--text-sm);
}

.banner-action,
.banner-dismiss {
  color: var(--color-accent-strong);
  background: transparent;
  cursor: pointer;
  font-weight: 750;
}

.banner-action {
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.banner-dismiss {
  position: absolute;
  right: var(--space-4);
  top: 50%;
  translate: 0 -50%;
  font-size: var(--text-lg);
}

.recovery-banner {
  position: relative;
  z-index: 19;
  padding: var(--space-3) var(--space-6);
  color: var(--color-ink);
  background: color-mix(in srgb, var(--color-warning) 20%, var(--color-surface));
  border-bottom: 1px solid color-mix(in srgb, var(--color-warning) 45%, transparent);
  text-align: center;
  font-size: var(--text-sm);
}

.recovery-banner .banner-action,
.recovery-banner .banner-dismiss {
  color: var(--color-warning);
}

.sheet {
  width: min(34rem, calc(100% - 2 * var(--space-4)));
  max-height: min(45rem, calc(100vh - 2 * var(--space-6)));
  margin: auto;
  padding: 0;
  color: var(--color-ink);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sheet);
}

.sheet::backdrop {
  background: var(--color-backdrop);
  backdrop-filter: blur(3px);
}

.sheet[open] {
  animation: sheet-in 160ms ease-out;
}

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(0.75rem) scale(0.985); }
}

.sheet-frame {
  margin: 0;
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-6);
  border-bottom: 1px solid var(--color-line-soft);
}

.sheet-header h2 {
  margin: 0;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  color: var(--color-muted);
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  font-size: var(--text-xl);
  line-height: 1;
}

.icon-button:hover {
  color: var(--color-ink);
  background: var(--color-paper-deep);
}

.settings-group {
  display: grid;
  gap: 0;
  padding: var(--space-2) var(--space-6) var(--space-6);
}

.settings-group fieldset {
  margin: 0;
  padding: var(--space-5) 0;
  border: 0;
  border-bottom: 1px solid var(--color-line-soft);
}

.settings-group legend {
  margin-bottom: var(--space-3);
  font-size: var(--text-sm);
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--color-paper-deep);
  border-radius: var(--radius-md);
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 2.25rem;
  padding-inline: var(--space-2);
  color: var(--color-muted);
  border-radius: calc(var(--radius-md) - var(--space-1));
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 650;
}

.segmented input:checked + span {
  color: var(--color-ink);
  background: var(--color-surface-raised);
  box-shadow: 0 1px 3px rgb(0 0 0 / 10%);
}

.segmented input:focus-visible + span {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  padding-block: var(--space-5);
  border-bottom: 1px solid var(--color-line-soft);
  cursor: pointer;
}

.switch-row:last-child {
  border-bottom: 1px solid var(--color-line-soft);
}

.rescan-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  padding-top: var(--space-5);
}

.rescan-row > span {
  display: grid;
  gap: var(--space-1);
}

.rescan-row strong {
  font-size: var(--text-sm);
}

.rescan-row small {
  color: var(--color-muted);
  font-size: var(--text-xs);
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-8);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.breadcrumbs a {
  color: var(--color-accent-strong);
  font-weight: 650;
}

.breadcrumbs a:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.shelf-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-8);
  margin-bottom: var(--space-12);
  padding-bottom: var(--space-8);
  border-bottom: 1px solid var(--color-line);
}

.shelf-header h1 {
  max-width: 18ch;
  margin-bottom: 0;
}

.shelf-blurb {
  max-width: 64ch;
  margin: var(--space-4) 0 0;
  color: var(--color-muted);
}

.shelf-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  max-width: 100%;
  gap: var(--space-2) var(--space-4);
  color: var(--color-muted);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.sort-select {
  max-width: 100%;
  min-height: 2.75rem;
  padding: 0 var(--space-8) 0 var(--space-3);
  color: var(--color-ink);
  background-color: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
  --ledge-gap: clamp(var(--space-4), 3vw, var(--space-8));
  gap: var(--space-10) var(--ledge-gap);
  align-items: start;
}

/* Sub-shelves: a shelf whose folder has folders inside it shows one titled section per folder. */
.subshelf-list {
  display: grid;
  gap: var(--space-12);
}

.subshelf-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: calc(-1 * var(--space-6)) 0 var(--space-8);
}

.subshelf-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 2.75rem;
  padding: 0 var(--space-4);
  color: var(--color-ink);
  font-size: var(--text-sm);
  font-weight: 600;
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: 999px;
  cursor: pointer;
}

.subshelf-chip small {
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

.subshelf-chip:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.subshelf {
  scroll-margin-top: var(--space-20, 5rem);
}

.subshelf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-2);
  color: var(--color-muted);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--color-line);
}

.subshelf-head h2 {
  min-width: 0;
  margin: 0;
  color: var(--color-ink);
  font-size: var(--text-xl);
}

.subshelf-head span {
  white-space: nowrap;
}

/* Covers stand on wooden ledges: each card's plank reaches half a gap to either side. */
.book-grid > .book-card .book-card-copy {
  padding-top: 0;
}

.book-grid > .book-card .book-card-copy::before {
  content: "";
  display: block;
  height: 9px;
  margin: 0 calc(-0.5 * var(--ledge-gap)) var(--space-3);
  background: linear-gradient(180deg, var(--wood-hi) 0 2px, var(--wood) 2px 7px, var(--wood-edge) 7px);
  box-shadow: 0 8px 12px -8px rgb(40 26 14 / 40%);
}

.book-card {
  display: grid;
  min-width: 0;
  padding: 0;
  color: var(--color-ink);
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
}

@media (hover: hover) {
  .book-card:hover .book-cover,
  .book-card:focus-visible .book-cover {
    box-shadow: var(--shadow-book), 0 22px 30px -18px rgb(40 28 18 / 34%);
    transform: translateY(-3px);
  }
}

.book-cover {
  position: relative;
  display: flex;
  flex-direction: column;
  aspect-ratio: 3 / 4.4;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  padding: clamp(var(--space-4), 1.8vw, var(--space-6)) var(--space-4) var(--space-4) clamp(var(--space-5), 2vw, var(--space-6));
  color: var(--bind-ink, #f3e9d8);
  background:
    linear-gradient(105deg, rgb(255 255 255 / 7%) 0%, transparent 28%, rgb(0 0 0 / 14%) 100%),
    var(--bind, #5c2a22);
  border-radius: 2px 3px 3px 2px;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 6%), var(--shadow-book);
  transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
  isolation: isolate;
}

.book-cover::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0 auto 0 0;
  width: 7%;
  background: linear-gradient(90deg, rgb(0 0 0 / 22%), rgb(255 255 255 / 6%) 60%, transparent);
  border-right: 1px solid rgb(0 0 0 / 12%);
  pointer-events: none;
}

.book-cover::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 1px 0 1px auto;
  width: 3px;
  background: repeating-linear-gradient(90deg, #efe8da 0 1px, #d5ccbb 1px 2px);
  pointer-events: none;
}

.cover-rule {
  width: 2.25rem;
  height: 2px;
  margin-bottom: var(--space-5);
  background: currentColor;
  opacity: 0.55;
}

.cover-copy {
  display: grid;
  gap: var(--space-3);
}

.cover-copy strong {
  display: -webkit-box;
  overflow: hidden;
  font-family: var(--font-display);
  letter-spacing: -0.005em;
  font-size: clamp(var(--text-sm), 1.5vw, var(--text-lg));
  font-weight: 600;
  line-height: 1.16;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
}

.cover-copy small {
  display: -webkit-box;
  overflow: hidden;
  font-size: 0.625rem;
  font-weight: 720;
  letter-spacing: 0.08em;
  line-height: 1.35;
  text-transform: uppercase;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.cover-format {
  margin-top: auto;
  font-size: 0.625rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  opacity: 0.64;
}

.flag-badge {
  position: absolute;
  z-index: 2;
  top: var(--space-2);
  right: var(--space-2);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 1.35rem;
  padding: 0 var(--space-2);
  color: #fff;
  background: #6e4b15;
  border: 1px solid rgb(255 255 255 / 32%);
  border-radius: var(--radius-pill);
  box-shadow: 0 2px 6px rgb(0 0 0 / 18%);
  font-size: 0.625rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.flag-badge i {
  width: 0.42rem;
  height: 0.42rem;
  background: currentColor;
  border-radius: 50%;
}

.flag-note {
  color: #fff;
  background: #356777;
}

.flag-warning {
  background: #92342f;
}

.flag-legend {
  width: min(100%, 52rem);
  color: var(--color-ink-soft);
  background: var(--color-surface);
  border: 1px solid var(--color-line-soft);
  border-radius: var(--radius-md);
}

.flag-legend summary {
  padding: var(--space-3) var(--space-4);
  color: var(--color-ink-soft);
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 750;
}

.flag-legend-body {
  padding: 0 var(--space-4) var(--space-4);
}

.flag-legend-body > p {
  margin: 0 0 var(--space-3);
  color: var(--color-muted);
  font-size: var(--text-xs);
}

.flag-legend-list {
  display: grid;
  gap: var(--space-3);
  margin: 0;
}

.flag-legend-item {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  gap: var(--space-3);
  align-items: start;
}

.flag-legend-item dd {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-xs);
  line-height: 1.5;
}

.flag-key {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 1.35rem;
  padding: 0 var(--space-2);
  color: #fff;
  background: #356777;
  border-radius: var(--radius-pill);
  font-size: 0.625rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.flag-key i {
  width: 0.42rem;
  height: 0.42rem;
  background: currentColor;
  border-radius: 50%;
}

.flag-key-caution { background: #6e4b15; }
.flag-key-warning { background: #92342f; }

.shelf-view > .flag-legend {
  margin: calc(-1 * var(--space-5)) 0 var(--space-8);
}

.home-view > .flag-legend {
  margin: var(--space-4) 0 0;
}

.context-section .flag-legend {
  margin-top: var(--space-5);
}

.book-card-copy {
  display: grid;
  gap: var(--space-1);
  padding-top: var(--space-4);
}

.book-card-copy strong {
  display: -webkit-box;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: 600;
  line-height: 1.28;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.book-card-copy small {
  display: -webkit-box;
  overflow: hidden;
  color: var(--color-muted);
  font-size: var(--text-xs);
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.unavailable-label {
  width: fit-content;
  margin-top: var(--space-1);
  color: var(--color-warning);
  font-size: 0.625rem;
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.book-tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 1.35rem;
  margin-top: var(--space-1);
  padding: 0 var(--space-2);
  color: var(--color-accent-strong);
  background: var(--color-accent-soft);
  border: 1px solid color-mix(in srgb, var(--color-accent) 28%, transparent);
  border-radius: var(--radius-pill);
  font-family: var(--font-ui);
  font-size: 0.625rem;
  font-style: normal;
  font-weight: 780;
  letter-spacing: 0.06em;
  line-height: 1;
  text-transform: uppercase;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.series-card {
  grid-column: span 2;
  overflow: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-line-soft);
  border-radius: var(--radius-md);
}

.series-card-top {
  display: grid;
  grid-template-columns: minmax(6.5rem, 0.72fr) minmax(9rem, 1.28fr);
  gap: var(--space-6);
  align-items: center;
  padding: var(--space-5);
}

.series-cover-stack {
  position: relative;
  width: 100%;
}

.series-cover-stack::before,
.series-cover-stack::after {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 4px -6px -4px 6px;
  background: color-mix(in srgb, var(--color-accent-soft) 72%, var(--color-surface));
  border: 1px solid var(--color-line);
  border-radius: 2px 7px 7px 2px;
  transform: rotate(2deg);
}

.series-cover-stack::after {
  inset: 7px -10px -7px 10px;
  opacity: 0.6;
  transform: rotate(4deg);
}

.series-copy h3 {
  margin-bottom: var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-lg);
}

.series-copy > p:last-child {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-xs);
}

.series-details {
  border-top: 1px solid var(--color-line-soft);
}

.series-details summary {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  color: var(--color-accent-strong);
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 750;
  list-style: none;
}

.series-details summary::-webkit-details-marker {
  display: none;
}

.series-details[open] summary > span:last-child {
  transform: rotate(45deg);
}

.series-volume-list {
  display: grid;
  padding: 0 var(--space-3) var(--space-3);
}

.series-volume {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3);
  color: var(--color-ink);
  background: transparent;
  border-top: 1px solid var(--color-line-soft);
  cursor: pointer;
  text-align: left;
}

.series-volume:hover {
  background: var(--color-paper-deep);
}

.series-volume > span:nth-child(2) {
  display: grid;
  min-width: 0;
}

.series-volume strong,
.series-volume small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.series-volume strong {
  font-family: var(--font-reading);
  font-size: var(--text-sm);
}

.series-volume small {
  color: var(--color-muted);
  font-size: 0.6875rem;
}

.volume-number {
  color: var(--color-muted);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
}

.volume-arrow {
  color: var(--color-muted);
}

.series-progress {
  color: var(--color-accent-strong);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
}

.restricted-shelf {
  max-width: 42rem;
  margin: var(--space-20) auto;
  text-align: center;
}

.restricted-shelf h1 {
  margin-bottom: var(--space-4);
}

.restricted-shelf .button {
  margin: var(--space-4) var(--space-3) var(--space-3);
}

.text-link {
  display: inline-block;
  color: var(--color-accent-strong);
  font-size: var(--text-sm);
  font-weight: 700;
}

.book-detail-sheet {
  width: min(52rem, calc(100% - 2 * var(--space-4)));
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
  padding: var(--space-6) var(--space-8);
  border-bottom: 1px solid var(--color-line-soft);
}

.detail-header h2 {
  max-width: 28ch;
  margin-bottom: var(--space-2);
}

.detail-byline {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.detail-body {
  display: grid;
  grid-template-columns: minmax(10rem, 15rem) minmax(0, 1fr);
  gap: var(--space-8);
  align-items: start;
  overflow-y: auto;
  padding: var(--space-8);
}

.book-cover-large {
  max-width: 15rem;
}

.book-cover-large .cover-copy strong {
  font-size: var(--text-lg);
}

.detail-copy {
  min-width: 0;
}

.detail-description {
  margin-bottom: var(--space-6);
  font-family: var(--font-reading);
  font-size: var(--text-lg);
  line-height: 1.55;
}

.detail-flag {
  margin-bottom: var(--space-6);
  padding: var(--space-4);
  background: var(--color-paper-deep);
  border-left: 3px solid var(--color-note);
}

.detail-flag-caution {
  border-left-color: var(--color-caution);
}

.detail-flag-warning {
  border-left-color: var(--color-warning);
}

.detail-flag p:last-child {
  margin: 0;
  font-size: var(--text-sm);
  line-height: 1.55;
}

.detail-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  margin: 0 0 var(--space-6);
}

.detail-fact dt {
  color: var(--color-muted);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-fact dd {
  margin: var(--space-1) 0 0;
  color: var(--color-ink-soft);
  font-size: var(--text-sm);
}

.file-detail {
  margin-bottom: var(--space-5);
  font-size: var(--text-xs);
}

.book-page-export {
  width: 100%;
}

.file-detail summary {
  width: fit-content;
  color: var(--color-accent-strong);
  cursor: pointer;
  font-weight: 700;
}

.file-detail code {
  display: block;
  overflow-wrap: anywhere;
  margin-top: var(--space-2);
  padding: var(--space-3);
  color: var(--color-muted);
  background: var(--color-paper-deep);
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
}

.reader-coming {
  margin: 0;
  padding-top: var(--space-4);
  color: var(--color-muted);
  border-top: 1px solid var(--color-line-soft);
  font-size: var(--text-xs);
}

.switch-row span {
  display: grid;
  gap: var(--space-1);
}

.switch-row strong {
  font-size: var(--text-sm);
}

.switch-row small {
  color: var(--color-muted);
  font-size: var(--text-xs);
}

.switch-row input {
  position: relative;
  flex: 0 0 auto;
  width: 2.75rem;
  height: 1.625rem;
  margin: 0;
  appearance: none;
  background: var(--color-line);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.switch-row input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 1.25rem;
  height: 1.25rem;
  background: var(--color-surface-raised);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgb(0 0 0 / 24%);
  transition: transform var(--transition-fast);
}

.switch-row input:checked {
  background: var(--color-accent);
}

.switch-row input:checked::after {
  transform: translateX(1.125rem);
}

.toast-region {
  position: fixed;
  z-index: 80;
  right: var(--space-5);
  bottom: var(--space-5);
  display: grid;
  gap: var(--space-2);
}

.toast {
  max-width: 24rem;
  padding: var(--space-3) var(--space-4);
  color: var(--color-ink);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sheet);
  font-size: var(--text-sm);
}

.toast-path {
  display: block;
  margin-top: var(--space-1);
  overflow-wrap: anywhere;
  color: var(--color-ink-soft);
  font-size: var(--text-xs);
}

.toast-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-2);
}

.toast-action {
  color: var(--color-accent-strong);
  background: transparent;
  cursor: pointer;
  font-weight: 750;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.error-state {
  max-width: 42rem;
  margin: var(--space-20) auto;
  padding: var(--space-8);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-left: 0;
}

.error-state h1 {
  font-size: var(--text-xl);
}

@media (max-width: 62rem) {
  .site-header {
    grid-template-columns: 1fr auto auto;
    gap: var(--space-3);
  }

  .site-nav .nav-link {
    display: none;
  }

  .home-intro {
    grid-template-columns: 1fr;
    gap: var(--space-8);
  }

  .library-stat {
    padding: var(--space-4) 0 0;
    border-top: 1px solid var(--color-line);
    border-left: 0;
  }

  .shelf-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  }
}

@media (max-width: 44rem) {
  .site-header {
    min-height: 4.25rem;
  }

  .brand small,
  .local-status {
    display: none;
  }

  .shelf-summary-grid {
    grid-template-columns: 1fr;
  }

  .home-intro {
    padding-block-start: var(--space-5);
  }

  .empty-reading {
    grid-template-columns: 1fr;
  }

  .shelf-header {
    display: grid;
    gap: var(--space-5);
    margin-bottom: var(--space-8);
  }

  .shelf-tools {
    justify-content: space-between;
  }

  .book-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    --ledge-gap: var(--space-4);
    gap: var(--space-8) var(--ledge-gap);
  }

  .series-card {
    grid-column: 1 / -1;
  }

  .detail-header {
    padding: var(--space-5);
  }

  .detail-body {
    grid-template-columns: 7.5rem minmax(0, 1fr);
    gap: var(--space-5);
    padding: var(--space-5);
  }

  .detail-description {
    font-size: var(--text-md);
  }

  .detail-facts {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 31rem) {
  .detail-body {
    grid-template-columns: 1fr;
  }

  .book-cover-large {
    width: min(10rem, 56vw);
  }
}

/* M4: cached covers and reading progress. */
.book-cover.has-image {
  padding: 0;
  background: var(--color-paper-deep);
}

.book-cover.has-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-progress {
  position: absolute;
  z-index: 4;
  inset: auto 0 0;
  height: 3px;
  background: rgb(0 0 0 / 35%);
}

.cover-progress::after {
  content: "";
  display: block;
  width: var(--book-progress);
  height: 100%;
  background: #e0906f;
  box-shadow: 0 0 0 1px rgb(255 255 255 / 20%);
}

.continue-row {
  display: grid;
  grid-auto-columns: minmax(10.5rem, 12rem);
  grid-auto-flow: column;
  gap: clamp(var(--space-4), 3vw, var(--space-8));
  overflow-x: auto;
  padding: var(--space-2) var(--space-2) var(--space-5);
  margin-inline: calc(-1 * var(--space-2));
  scroll-snap-type: x proximity;
}

.continue-card {
  display: grid;
  min-width: 0;
  scroll-snap-align: start;
}

.continue-card .book-cover {
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

@media (hover: hover) {
  .continue-card:hover .book-cover,
  .continue-card:focus-visible .book-cover {
    box-shadow: var(--shadow-book), 0 22px 30px -18px rgb(40 28 18 / 34%);
    transform: translateY(-3px);
  }
}

.continue-copy {
  display: grid;
  gap: var(--space-1);
  padding-top: var(--space-3);
}

.continue-copy strong {
  display: -webkit-box;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: var(--text-sm);
  line-height: 1.3;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.continue-copy small {
  color: var(--color-muted);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.detail-read-button {
  width: fit-content;
  margin-top: var(--space-2);
}

/* M4–M5: integrated PDF and EPUB readers. */
body.reader-open {
  overflow: hidden;
  background: var(--color-paper-deep);
}

.reader-open .site-header,
.reader-open .stale-banner,
.reader-open .recovery-banner,
.reader-open .skip-link {
  display: none;
}

.reader-open main {
  width: 100%;
  height: 100dvh;
  min-height: 0;
  padding: 0;
}

.reader-host,
.reader-view {
  width: 100%;
  height: 100%;
}

.reader-view {
  position: relative;
  overflow: hidden;
  background: var(--color-paper-deep);
}

.reader-toolbar {
  position: absolute;
  z-index: 30;
  top: 0;
  left: 0;
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(12rem, 0.8fr) minmax(20rem, 1fr);
  gap: var(--space-4);
  align-items: center;
  width: 100%;
  min-height: 4.75rem;
  padding: var(--space-3) clamp(var(--space-3), 3vw, var(--space-6));
  background: color-mix(in srgb, var(--color-surface-raised) 91%, transparent);
  border-bottom: 1px solid var(--color-line);
  box-shadow: 0 8px 30px color-mix(in srgb, var(--color-ink) 8%, transparent);
  backdrop-filter: blur(18px) saturate(130%);
  transition: transform 170ms ease-out;
}

.reader-toolbar-hidden .reader-toolbar {
  transform: translateY(calc(-100% - 1px));
}

.reader-book-identity {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.reader-book-identity > div {
  display: grid;
  min-width: 0;
}

.reader-book-identity strong,
.reader-book-identity small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-book-identity strong {
  font-family: var(--font-reading);
  font-size: var(--text-sm);
}

.reader-book-identity small {
  color: var(--color-muted);
  font-size: var(--text-xs);
}

.reader-close,
.reader-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-width: 2.45rem;
  min-height: 2.45rem;
  padding: 0 var(--space-3);
  color: var(--color-ink-soft);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 700;
}

.reader-close {
  gap: var(--space-2);
}

.reader-close:hover,
.reader-icon-button:hover {
  color: var(--color-ink);
  background: var(--color-surface);
  border-color: var(--color-line-soft);
}

.reader-loading {
  display: grid;
  grid-template-columns: minmax(5rem, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  min-width: 0;
  opacity: 1;
  transition: opacity 220ms ease-out;
}

.reader-loading.is-complete {
  opacity: 0;
}

.reader-load-progress {
  width: 100%;
  height: 0.35rem;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-pill);
  accent-color: var(--color-accent);
}

.reader-load-label {
  overflow: hidden;
  color: var(--color-muted);
  font-size: 0.6875rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-controls {
  display: flex;
  grid-column: 3;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
  min-width: 0;
}

.reader-page-control {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-muted);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.reader-page-input {
  width: 3.7rem;
  min-height: 2.25rem;
  padding: 0 var(--space-2);
  color: var(--color-ink);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  text-align: center;
}

.reader-zoom {
  min-height: 2.35rem;
  padding: 0 var(--space-6) 0 var(--space-3);
  color: var(--color-ink);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-xs);
}

.reader-text-status {
  margin-right: var(--space-2);
  padding: var(--space-1) var(--space-2);
  color: var(--color-caution);
  background: color-mix(in srgb, var(--color-caution) 11%, transparent);
  border-radius: var(--radius-pill);
  font-size: 0.625rem;
  font-weight: 750;
  white-space: nowrap;
}

.epub-toolbar {
  grid-template-columns: minmax(10rem, 0.75fr) minmax(7rem, 0.35fr) minmax(36rem, 1.6fr);
}

.epub-controls {
  gap: var(--space-1);
}

.reader-chapter,
.reader-flow {
  min-height: 2.35rem;
  padding: 0 var(--space-6) 0 var(--space-3);
  color: var(--color-ink);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-xs);
}

.reader-chapter {
  width: min(13rem, 18vw);
}

.reader-flow {
  width: 5.5rem;
}

.reader-flow:disabled {
  cursor: help;
  opacity: 0.68;
}

.reader-epub-location {
  display: block;
  overflow: hidden;
  width: min(10rem, 14vw);
  color: var(--color-muted);
  font-size: var(--text-xs);
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-font-value {
  min-width: 2.8rem;
  color: var(--color-muted);
  font-size: 0.6875rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.epub-loading {
  grid-template-columns: auto minmax(0, 1fr);
}

.reader-epub-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--color-line);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: epub-spin 760ms linear infinite;
}

@keyframes epub-spin {
  to { transform: rotate(360deg); }
}

.pdf-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.epub-viewer {
  position: absolute;
  inset: 4.75rem 0 0;
  overflow: hidden;
  background: var(--color-surface);
  outline: none;
}

.epub-viewer > div,
.epub-viewer iframe {
  width: 100% !important;
  height: 100% !important;
}

.epub-viewer iframe {
  display: block;
  background: #fff;
  border: 0;
}

/* Scroll flow: next chapter in a strip of space below the chapter; previous at its head (epub-engine.js). */
.epub-viewer[data-flow="scrolled"] > .epub-container {
  padding-bottom: calc(3.75rem + env(safe-area-inset-bottom, 0px));
}

.epub-viewer > .epub-chapter-nav {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.epub-chapter-nav > .button {
  position: absolute;
  inset-inline: 0;
  width: max-content;
  margin-inline: auto;
  background: var(--color-surface);
  box-shadow: var(--shadow-cover);
  pointer-events: auto;
}

.epub-chapter-nav > [data-chapter="previous"] {
  top: var(--space-2);
}

.epub-chapter-nav > [data-chapter="next"] {
  bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
}

.epub-viewer > .epub-chapter-nav[hidden],
.epub-chapter-nav > .button[hidden] {
  display: none;
}

/* Touch screens, Pages flow: catches swipes and taps the sandboxed book frame cannot (epub-engine.js). */
.epub-viewer > .epub-touch-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.epub-viewer > .epub-touch-layer[hidden] {
  display: none;
}

.pdf-pages {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  min-width: max-content;
  min-height: 100%;
  padding: 6.5rem clamp(var(--space-4), 4vw, var(--space-10)) var(--space-20);
}

.pdf-page-slot {
  position: relative;
  flex: none;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 10px 30px rgb(20 16 13 / 18%), 0 0 0 1px rgb(20 16 13 / 10%);
}

.pdf-page-slot.is-placeholder {
  background:
    linear-gradient(110deg, transparent 35%, rgb(255 255 255 / 55%) 48%, transparent 61%),
    #e9e5df;
  background-size: 220% 100%;
  animation: reader-placeholder 1.7s ease-in-out infinite;
}

.pdf-page-slot.is-placeholder::after {
  content: "Page " attr(data-page);
  position: absolute;
  inset: 50% auto auto 50%;
  translate: -50% -50%;
  color: #756e67;
  font-size: var(--text-xs);
}

@keyframes reader-placeholder {
  0%, 25% { background-position: 100% 0; }
  75%, 100% { background-position: -100% 0; }
}

.pdf-page-surface,
.pdf-page-surface canvas {
  width: 100%;
  height: 100%;
}

.pdf-page-surface {
  position: relative;
}

.pdf-page-surface canvas {
  display: block;
}

.pdf-page-slot.has-render-error {
  display: grid;
  place-items: center;
  padding: var(--space-6);
  color: #713928;
  background: #fff8f3;
  font-size: var(--text-sm);
}

.textLayer {
  position: absolute;
  z-index: 1;
  inset: 0;
  overflow: clip;
  color: transparent;
  line-height: 1;
  text-align: initial;
  text-size-adjust: none;
  transform-origin: 0 0;
  forced-color-adjust: none;
}

.textLayer :is(span, br) {
  position: absolute;
  color: transparent;
  cursor: text;
  white-space: pre;
  transform-origin: 0 0;
}

.textLayer ::selection {
  background: color-mix(in srgb, var(--color-focus), transparent 72%);
}

.reader-error {
  position: absolute;
  z-index: 20;
  inset: 50% auto auto 50%;
  width: min(34rem, calc(100% - 2 * var(--space-6)));
  padding: var(--space-8);
  translate: -50% -50%;
  color: var(--color-ink);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-line);
  border-left: 4px solid var(--color-warning);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sheet);
}

.reader-error h1 {
  margin-bottom: var(--space-4);
  font-size: var(--text-xl);
}

.reader-error .button {
  margin-top: var(--space-3);
}

.reader-error-path {
  display: block;
  overflow-wrap: anywhere;
  margin-top: var(--space-4);
  padding: var(--space-3);
  color: var(--color-muted);
  background: var(--color-paper-deep);
  border-radius: var(--radius-sm);
  font-size: 0.6875rem;
}

@media (max-width: 58rem) {
  .reader-toolbar {
    grid-template-columns: minmax(10rem, 1fr) auto;
  }

  .reader-loading {
    position: absolute;
    right: var(--space-4);
    bottom: -1.25rem;
    left: var(--space-4);
  }

  .reader-controls {
    grid-column: 2;
  }

  .reader-load-label {
    display: none;
  }

  .reader-text-status,
  .reader-book-identity small {
    display: none;
  }

  .epub-toolbar {
    grid-template-columns: minmax(8rem, 0.5fr) minmax(0, 1.5fr);
  }

  .reader-chapter {
    width: min(10rem, 20vw);
  }
}

@media (max-width: 40rem) {
  .reader-toolbar {
    min-height: 4rem;
    padding: var(--space-2);
  }

  .reader-close > span:last-child,
  .reader-book-identity > div,
  .reader-controls > .reader-icon-button:not(:last-child) {
    display: none;
  }

  /* The Reflow | Original switch stays on the phone: it is the only way back to Reflow. */
  .reader-controls > .reader-layout-toggle {
    flex: none;
  }

  .reader-controls > .reader-layout-toggle .reader-layout-option {
    padding-inline: 0.55rem;
  }

  /* Original layout on a phone: the back arrow keeps its own column and the controls
     never spill over it. The page-number box gives way to Reflow | Original. */
  .reader-view:not(.text-reader-view) .reader-toolbar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .reader-view:not(.text-reader-view) .reader-controls {
    min-width: 0;
    justify-content: flex-end;
    gap: var(--space-1);
  }

  .reader-view:not(.text-reader-view) .reader-controls > .reader-page-control {
    display: none;
  }

  .reader-view:not(.text-reader-view) .reader-zoom {
    flex: 0 1 6.4rem;
    min-width: 4.5rem;
  }

  .reader-controls {
    gap: 0;
  }

  .reader-zoom {
    max-width: 6.4rem;
  }

  .pdf-pages {
    gap: var(--space-4);
    padding: 5.5rem var(--space-3) var(--space-12);
  }

  .epub-viewer {
    inset-block-start: 4rem;
  }

  .reader-chapter,
  .reader-font-value {
    display: none;
  }

  .reader-epub-location {
    width: 4.5rem;
  }
}

.site-nav kbd {
  margin-left: var(--space-2);
  padding: 0.1rem 0.35rem;
  color: var(--color-muted);
  background: var(--color-paper-deep);
  border: 1px solid var(--color-line-soft);
  border-radius: 0.3rem;
  font-family: var(--font-ui);
  font-size: 0.625rem;
}

.shortcuts-sheet kbd {
  padding: 0.15rem 0.45rem;
  color: var(--color-ink);
  background: var(--color-paper-deep);
  border: 1px solid var(--color-line-soft);
  border-radius: 0.3rem;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  white-space: nowrap;
}

.shortcuts-group {
  padding: var(--space-5) var(--space-6);
  border-top: 1px solid var(--color-line-soft);
}

.shortcuts-group:first-of-type {
  border-top: none;
}

.shortcuts-heading {
  margin: 0 0 var(--space-3);
  color: var(--color-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.shortcuts-list {
  display: grid;
  gap: var(--space-3);
}

.shortcuts-list > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
}

.shortcuts-list dt {
  display: flex;
  gap: var(--space-1);
}

.shortcuts-list dd {
  margin: 0;
  color: var(--color-ink-soft);
  font-size: var(--text-sm);
  text-align: right;
}

.book-progress-block {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.book-progress-label {
  order: 2;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  color: var(--color-muted);
  font-size: 0.625rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.book-progress-label > span {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.book-progress-label strong {
  display: inline;
  overflow: visible;
  font-family: var(--font-ui);
  font-size: 0.6875rem;
  font-weight: 750;
  line-height: 1;
}

.book-progress-track,
.book-page-progress-track {
  display: block;
  overflow: hidden;
  width: 100%;
  height: 0.25rem;
  background: var(--color-line-soft);
  border-radius: var(--radius-pill);
}

.book-progress-track > span,
.book-page-progress-track > span {
  display: block;
  min-width: 0;
  height: 100%;
  background: var(--color-accent);
  border-radius: inherit;
  transition: width 180ms ease-out;
}

.book-progress-unavailable {
  width: fit-content;
  margin-top: var(--space-2);
  color: var(--color-warning);
  font-size: 0.6875rem;
  font-weight: 750;
}

.book-page {
  max-width: 74rem;
  margin-inline: auto;
}

.book-page-hero {
  display: grid;
  grid-template-columns: minmax(11rem, 16rem) minmax(0, 1fr);
  gap: clamp(var(--space-6), 4vw, var(--space-12));
  align-items: stretch;
  padding-block: var(--space-8) var(--space-12);
}

.book-page-intro {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-left: clamp(var(--space-6), 4vw, var(--space-12));
  border-left: 1px solid var(--color-line);
}

.book-page-intro h1 {
  max-width: 21ch;
  margin-bottom: var(--space-4);
}

.book-page-byline {
  color: var(--color-muted);
  font-family: var(--font-reading);
  font-size: var(--text-lg);
}

.book-page-read {
  width: fit-content;
  margin-top: var(--space-6);
}

.book-page-unavailable {
  width: fit-content;
  margin-top: var(--space-6);
  padding: var(--space-2) var(--space-4);
  color: var(--color-warning);
  background: color-mix(in srgb, var(--color-warning) 10%, transparent);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 750;
}

.book-page-progress {
  margin-bottom: var(--space-10);
  padding: var(--space-5) 0;
  background: none;
  border: 0;
  border-block: 1px solid var(--color-line);
  border-radius: 0;
}

.book-page-progress-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-5);
  margin-bottom: var(--space-4);
}

.book-page-progress-heading h2 {
  margin: 0;
  font-size: var(--text-lg);
}

.book-page-progress-heading strong {
  color: var(--color-ink);
  font-size: var(--text-xl);
  font-variant-numeric: tabular-nums;
}

.book-page-progress-track {
  height: 0.7rem;
}

.book-page-progress p {
  margin: var(--space-3) 0 0;
  color: var(--color-muted);
  font-size: var(--text-xs);
}

.book-page-progress.is-unavailable {
  border-left: 4px solid var(--color-warning);
}

.book-page-progress.is-unavailable .book-page-progress-heading strong {
  color: var(--color-warning);
  font-size: var(--text-sm);
}

.book-page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(14rem, 19rem);
  gap: clamp(var(--space-8), 6vw, var(--space-16));
  align-items: start;
}

.book-page-main {
  display: grid;
  gap: var(--space-12);
}

.book-page-section {
  padding-top: var(--space-8);
  border-top: 1px solid var(--color-line);
}

.book-page-section h2 {
  margin-bottom: var(--space-5);
}

.book-about-copy {
  font-family: var(--font-reading);
  font-size: var(--text-lg);
  line-height: 1.65;
}

.source-line {
  margin: var(--space-5) 0 0;
  color: var(--color-muted);
  font-size: var(--text-xs);
  overflow-wrap: anywhere;
}

.context-section {
  padding: var(--space-7);
  background: var(--color-paper-deep);
  border: 0;
  border-left: 4px solid var(--color-note);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.context-section.context-caution { border-left-color: var(--color-caution); }
.context-section.context-warning { border-left-color: var(--color-warning); }

.context-section p:last-child {
  margin-bottom: 0;
}

.book-page-sidebar {
  position: sticky;
  top: 7rem;
  padding: var(--space-4) var(--space-5) var(--space-6);
  color: #2b2521;
  background: #f6efdd;
  border: 0;
  border-top: 3px solid #a2463a;
  border-radius: 3px;
  box-shadow: 0 1px 2px rgb(40 28 18 / 20%), 0 10px 18px -12px rgb(40 28 18 / 40%);
}

.card-mark {
  margin: 0 0 var(--space-2);
  font: 700 var(--text-2xs)/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: right;
}

.card-author {
  margin: 0;
  font: 600 var(--text-md)/1.4 var(--font-display);
  color: #2b2521;
}

.card-title {
  margin: 0 0 var(--space-3) var(--space-5);
  font: 400 var(--text-md)/1.4 var(--font-reading);
}

.book-page-sidebar dl {
  display: grid;
  gap: 0;
  margin: 0 0 var(--space-5);
}

.book-page-fact {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  align-items: baseline;
  padding: var(--space-2) 0;
  border-bottom: 1px solid rgb(74 110 140 / 28%);
}

.book-page-fact dt {
  color: #6a5f55;
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.book-page-fact dd {
  margin: 0;
  color: #2b2521;
  font-size: var(--text-sm);
}

.book-page-sidebar .file-detail,
.book-page-sidebar .file-detail code {
  color: #2b2521;
}

.book-page-sidebar .button-secondary {
  color: #2b2521;
  border-color: #2b2521;
}

.knowledge-list {
  display: grid;
  gap: var(--space-4);
}

.knowledge-entry {
  position: relative;
  padding: var(--space-4) 0 var(--space-4) var(--space-4);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--color-line-soft);
  border-left: 4px solid var(--annotation-color, var(--color-accent));
  border-radius: 0;
}

.knowledge-entry header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  color: var(--color-muted);
  font-size: var(--text-xs);
}

.knowledge-kind {
  color: var(--annotation-color, var(--color-accent-strong));
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.knowledge-entry blockquote {
  margin: 0 0 var(--space-3);
  color: var(--color-ink-soft);
  font-family: var(--font-reading);
  font-style: italic;
}

.knowledge-note {
  margin: 0 0 var(--space-3);
  font-size: 0.9375rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.reflection-entry { border-left-color: var(--color-accent); }

.knowledge-empty,
.notes-empty {
  padding: var(--space-8);
  color: var(--color-muted);
  background: var(--color-paper-deep);
  border: 1px dashed var(--color-line);
  border-radius: var(--radius-md);
  text-align: center;
}

.knowledge-empty p,
.notes-empty p { margin: 0; }

.anchor-lost {
  color: var(--color-warning);
  font-size: var(--text-xs);
  font-weight: 750;
}

.notes-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: var(--space-8);
  margin-block: var(--space-8) var(--space-12);
}

.notes-header > div > p:last-child {
  max-width: 62ch;
  margin-bottom: 0;
  color: var(--color-muted);
}

.notes-header > strong {
  color: var(--color-muted);
  font-size: var(--text-sm);
  white-space: nowrap;
}

.global-notes-groups {
  display: grid;
  gap: var(--space-14);
}

.global-note-group {
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-line);
}

.global-note-book {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: var(--space-2);
}

.global-note-book h2 { margin-bottom: var(--space-1); font-size: var(--text-xl); }

.global-note-book p:last-child {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.global-note-list {
  display: grid;
  gap: 0;
}

.global-note {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-4);
  padding: var(--space-5) 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--color-line-soft);
  border-radius: 0;
}

.global-note-marker {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  color: color-mix(in srgb, var(--annotation-color) 72%, #241b13);
  background: color-mix(in srgb, var(--annotation-color) 25%, var(--color-surface));
  border-radius: 50%;
  font-family: var(--font-reading);
  font-size: var(--text-lg);
}

.global-note-copy header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-2);
}

.global-note-copy header span {
  color: var(--color-muted);
  font-size: var(--text-xs);
  text-transform: capitalize;
}

.global-note-copy blockquote {
  display: -webkit-box;
  overflow: hidden;
  margin: 0 0 var(--space-2);
  font-family: var(--font-reading);
  font-style: italic;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.global-note-copy p {
  margin: 0 0 var(--space-3);
  line-height: 1.6;
  white-space: pre-wrap;
}

.search-dialog,
.reflection-dialog,
.annotation-composer {
  margin: auto;
  padding: 0;
  color: var(--color-ink);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sheet);
}

.search-dialog::backdrop,
.reflection-dialog::backdrop,
.annotation-composer::backdrop {
  background: var(--color-backdrop);
  backdrop-filter: blur(4px);
}

.search-dialog {
  width: min(58rem, calc(100% - 2 * var(--space-4)));
  max-height: min(48rem, calc(100dvh - 2 * var(--space-6)));
}

.search-frame {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  max-height: inherit;
  padding: var(--space-6);
}

.search-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: var(--space-5);
}

.search-header h1 {
  margin: 0;
  font-size: var(--text-xl);
}

.search-input {
  width: 100%;
  min-height: 3.25rem;
  padding: 0 var(--space-4);
  color: var(--color-ink);
  background: var(--color-paper);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
}

.search-results {
  display: grid;
  gap: var(--space-7);
  overflow-y: auto;
  padding-top: var(--space-6);
}

.search-prompt,
.search-group-empty {
  margin: 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.search-group h2 {
  margin-bottom: var(--space-3);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.search-list {
  display: grid;
  gap: var(--space-2);
}

.search-result {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  background: var(--color-paper-deep);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}

a.search-result:hover,
a.search-result:focus-visible {
  background: var(--color-accent-soft);
  border-color: color-mix(in srgb, var(--color-accent) 35%, transparent);
}

.search-result span,
.search-result small {
  color: var(--color-muted);
  font-size: var(--text-xs);
}

.search-result small {
  display: -webkit-box;
  overflow: hidden;
  white-space: pre-wrap;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.search-result blockquote {
  margin: 0;
  font-family: var(--font-reading);
  font-style: italic;
}

.search-result.is-wanted { opacity: 0.76; }

.reflection-dialog,
.annotation-composer {
  width: min(36rem, calc(100% - 2 * var(--space-4)));
}

.reflection-form,
.annotation-form {
  padding: var(--space-7);
}

.reflection-form > header,
.annotation-form-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
}

.reflection-form h2,
.annotation-form h2 { margin-bottom: var(--space-3); }

.reflection-book {
  margin-bottom: var(--space-1);
  font-family: var(--font-reading);
  font-size: var(--text-lg);
  font-weight: 650;
}

.reflection-range,
.annotation-context {
  margin-bottom: var(--space-5);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.reflection-form label,
.annotation-note-label {
  display: grid;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 700;
}

.reflection-form textarea,
.annotation-note-input {
  width: 100%;
  resize: vertical;
  padding: var(--space-3);
  color: var(--color-ink);
  background: var(--color-paper);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  font-weight: 400;
  line-height: 1.55;
}

.reflection-hint,
.annotation-note-hint {
  margin: var(--space-2) 0 0;
  color: var(--color-muted);
  font-size: var(--text-xs);
}

.reflection-form footer,
.annotation-form footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

.reader-toolbar .reader-icon-button.is-active {
  color: var(--color-on-accent);
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.reader-controls {
  overflow-x: auto;
  scrollbar-width: none;
}

.reader-controls::-webkit-scrollbar { display: none; }

.reader-notes-panel {
  position: absolute;
  z-index: 42;
  top: 4.75rem;
  right: 0;
  bottom: 0;
  width: min(28rem, 92vw);
  overflow-y: auto;
  padding: var(--space-5);
  background: color-mix(in srgb, var(--color-surface-raised) 96%, transparent);
  border-left: 1px solid var(--color-line);
  box-shadow: -12px 0 30px color-mix(in srgb, var(--color-ink) 12%, transparent);
  backdrop-filter: blur(18px);
}

.reader-notes-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-line-soft);
}

.reader-notes-header h2 {
  margin: 0;
  font-size: var(--text-lg);
}

.reader-notes-actions {
  display: flex;
  gap: var(--space-2);
  padding-block: var(--space-4);
}

.reader-notes-actions .button {
  min-height: 2.25rem;
  padding-inline: var(--space-3);
}

.reader-notes-list {
  display: grid;
  gap: var(--space-3);
}

.reader-note {
  position: relative;
  padding: var(--space-4);
  background: var(--color-paper-deep);
  border-left: 4px solid var(--annotation-color);
  border-radius: var(--radius-sm);
}

.reader-note-jump {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  padding: 0;
  color: var(--color-ink);
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.reader-note-jump span {
  color: var(--color-muted);
  font-size: var(--text-xs);
  text-transform: capitalize;
}

.reader-note blockquote {
  display: -webkit-box;
  overflow: hidden;
  margin: var(--space-3) 0;
  font-family: var(--font-reading);
  font-style: italic;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.reader-note p {
  margin: var(--space-3) 0;
  font-size: var(--text-sm);
  line-height: 1.55;
  white-space: pre-wrap;
}

.reader-note-delete {
  padding: 0;
  color: var(--color-warning);
  background: transparent;
  cursor: pointer;
  font-size: var(--text-xs);
}

.reader-notes-empty {
  padding: var(--space-8) var(--space-4);
  color: var(--color-muted);
  text-align: center;
}

.annotation-excerpt {
  max-height: 8rem;
  overflow-y: auto;
  margin: 0 0 var(--space-5);
  padding: var(--space-3) var(--space-4);
  color: var(--color-ink-soft);
  background: var(--color-paper-deep);
  border-left: 3px solid var(--color-accent);
  font-family: var(--font-reading);
  font-style: italic;
}

.annotation-form fieldset {
  margin: var(--space-5) 0 0;
  padding: 0;
  border: 0;
}

.annotation-form legend {
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 700;
}

.annotation-colors {
  display: flex;
  gap: var(--space-3);
}

.annotation-color-choice {
  position: relative;
  display: block;
  cursor: pointer;
}

.annotation-color-choice input {
  position: absolute;
  opacity: 0;
}

.annotation-color-choice > span[aria-hidden] {
  display: block;
  width: 2rem;
  height: 2rem;
  background: var(--annotation-color);
  border: 3px solid var(--color-surface-raised);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--color-line);
}

.annotation-color-choice input:checked + span {
  box-shadow: 0 0 0 3px var(--color-focus);
}

.annotation-color-amber { --annotation-color: #d69a26; }
.annotation-color-rose { --annotation-color: #cf6679; }
.annotation-color-sky { --annotation-color: #4d9bc9; }
.annotation-color-mint { --annotation-color: #47a77e; }
.annotation-color-violet { --annotation-color: #846dcc; }

.pdf-annotation-layer {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
}

.pdf-highlight {
  position: absolute;
  padding: 0;
  background: color-mix(in srgb, var(--annotation-color) 46%, transparent);
  border: 0;
  border-radius: 1px;
  mix-blend-mode: multiply;
  pointer-events: none;
}

.pdf-pin {
  position: absolute;
  display: grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  padding: 0;
  translate: -50% -50%;
  color: #1e1710;
  background: var(--annotation-color);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  box-shadow: 0 2px 7px rgb(0 0 0 / 30%);
  cursor: pointer;
  font-size: 0.6875rem;
  font-weight: 800;
  pointer-events: auto;
  rotate: -45deg;
}

.pdf-pages.is-placing-pin .pdf-page-surface { cursor: crosshair; }

.textLayer { z-index: 3; }

@media (max-width: 62rem) {
  .book-page-grid { grid-template-columns: 1fr; }
  .book-page-sidebar { position: static; }
}

@media (max-width: 44rem) {
  .site-header { grid-template-columns: 1fr auto; }
  .site-nav kbd,
  .local-status { display: none; }
  .book-page-hero { grid-template-columns: 7.5rem minmax(0, 1fr); gap: var(--space-5); align-items: start; padding-block: 0 var(--space-6); }
  .book-page-hero .book-cover { width: 100%; }
  .book-page-intro { padding-left: 0; border-left: 0; justify-content: flex-start; }
  .book-page-intro h1 { max-width: none; margin-bottom: var(--space-2); font-size: clamp(1.5rem, 6.4vw, 2rem); }
  .book-page-byline { font-size: var(--text-md); }
  .book-page-read { width: 100%; margin-top: var(--space-4); }
  .book-page-hero .book-cover-large .cover-copy strong { font-size: var(--text-sm); }
  .book-page-progress-heading,
  .notes-header,
  .global-note-book {
    align-items: flex-start;
    flex-direction: column;
  }
  .global-note { grid-template-columns: auto minmax(0, 1fr); gap: var(--space-3); }
  .global-note-marker { width: 1.75rem; height: 1.75rem; }
  .reader-notes-panel { top: 4rem; }
}

/* ---------------------------------------------------------------------------
   Home: recently added + discreet mode
   ------------------------------------------------------------------------- */

.section-heading .discreet-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  white-space: nowrap;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
}

.section-heading .discreet-toggle kbd {
  font-size: var(--text-xs);
  padding: 1px 6px;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  background: var(--color-paper-deep);
}

.section-heading .discreet-toggle.is-on {
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
  border-color: var(--color-accent);
}

.discreet-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  flex-wrap: wrap;
  padding: var(--space-6) var(--space-8);
  border: 1px dashed var(--color-line);
  border-radius: var(--radius-lg);
  background: var(--color-paper-deep);
}

.discreet-panel strong {
  display: block;
  font-family: var(--font-reading);
  font-size: var(--text-lg);
}

.discreet-panel small {
  display: block;
  margin-top: var(--space-1);
  color: var(--color-muted);
  max-width: 52ch;
}

.recent-section {
  margin-top: var(--space-12);
}

.recent-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(9.5rem, 1fr);
  gap: var(--space-5);
  overflow-x: auto;
  padding-bottom: var(--space-3);
  scroll-snap-type: x proximity;
}

.recent-card {
  display: grid;
  gap: var(--space-3);
  text-decoration: none;
  color: inherit;
  scroll-snap-align: start;
}

.recent-card .book-cover {
  width: 100%;
}

.recent-copy {
  display: grid;
  gap: 2px;
}

.recent-copy strong {
  font-family: var(--font-reading);
  font-size: var(--text-md);
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.recent-copy small {
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.recent-copy em {
  font-style: normal;
  font-size: var(--text-xs);
  color: var(--color-faint);
}

.recent-card:hover .recent-copy strong,
.recent-card:focus-visible .recent-copy strong {
  color: var(--color-accent-strong);
}

.book-added {
  font-style: normal;
  font-size: var(--text-xs);
  color: var(--color-faint);
}

.home-visibility .switch-row {
  margin-top: var(--space-4);
}

/* ---------------------------------------------------------------------------
   Recently added — the whole library by date
   ------------------------------------------------------------------------- */

.section-heading .section-link {
  white-space: nowrap;
  font-size: var(--text-sm);
}

.recent-view {
  display: grid;
  gap: var(--space-8);
}

.recent-groups {
  display: grid;
  gap: var(--space-16);
}

.recent-group {
  display: grid;
  gap: var(--space-6);
}

.recent-group-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-line-soft);
}

.recent-group-heading h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-xl);
}

.recent-group-heading p {
  margin: var(--space-1) 0 0;
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.recent-group-heading span {
  color: var(--color-faint);
  font-size: var(--text-sm);
}

.recent-discreet-note {
  margin: 0;
  padding: var(--space-4) var(--space-5);
  border: 1px dashed var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-paper-deep);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

/* The shelf a book was filed on, on cards in mixed-shelf views. */
.book-shelf-label {
  font-style: normal;
  font-size: var(--text-xs);
  color: var(--color-muted);
  background: var(--color-paper-deep);
  border: 1px solid var(--color-line-soft);
  border-radius: var(--radius-pill);
  padding: 1px var(--space-2);
  justify-self: start;
}

/* ---------------------------------------------------------------------------
   Ask panel — a local model, beside the page
   ------------------------------------------------------------------------- */

.reader-ask-panel {
  position: fixed;
  top: 4.5rem;
  right: var(--space-4);
  bottom: var(--space-4);
  width: min(26rem, calc(100vw - 2 * var(--space-4)));
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-sheet);
  overflow-y: auto;
  z-index: 40;
}

.ask-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.ask-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-lg);
}

.ask-model {
  max-width: 11rem;
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  background: var(--color-surface-raised);
  color: var(--color-ink);
}

.ask-context {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-muted);
}

.ask-context-preview summary {
  cursor: pointer;
  font-size: var(--text-xs);
  color: var(--color-faint);
}

.ask-context-preview p {
  margin: var(--space-2) 0 0;
  padding: var(--space-3);
  border-left: 2px solid var(--color-line);
  background: var(--color-paper-deep);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-reading);
  font-size: var(--text-sm);
  color: var(--color-ink-soft);
  max-height: 9rem;
  overflow-y: auto;
}

.ask-form {
  display: grid;
  gap: var(--space-3);
}

.ask-input {
  width: 100%;
  resize: vertical;
  padding: var(--space-3);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  color: var(--color-ink);
  font: inherit;
  font-size: var(--text-sm);
}

.ask-form-actions {
  display: flex;
  gap: var(--space-2);
}

.ask-status {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--color-muted);
}

.ask-status[data-kind="warn"] {
  color: var(--color-warning);
}

.ask-answer {
  flex: 1 1 auto;
  min-height: 6rem;
  max-height: 24rem;
  overflow-y: auto;
  padding: var(--space-4);
  border: 1px solid var(--color-line-soft);
  border-radius: var(--radius-md);
  background: var(--color-paper-deep);
  font-family: var(--font-reading);
  font-size: var(--text-md);
  line-height: 1.55;
  white-space: pre-wrap;
  /* Selecting parts of the answer is the whole point of the panel. */
  user-select: text;
}

.ask-answer:empty::before {
  content: "The answer will appear here. Select any part of it to keep.";
  color: var(--color-faint);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}

.ask-answer.is-streaming::after {
  content: "▌";
  color: var(--color-accent);
  animation: ask-caret 1s steps(2) infinite;
}

@keyframes ask-caret {
  50% { opacity: 0; }
}

.ask-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.ask-collected {
  display: grid;
  gap: var(--space-2);
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-line-soft);
}

.ask-collected-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-accent-soft);
}

.ask-collected-row p {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--color-ink-soft);
}

.ask-footnote {
  margin: 0;
  font-size: var(--text-xs);
  color: var(--color-faint);
}

.reader-ask-button.is-active {
  background: var(--color-accent-soft);
  color: var(--color-accent-strong);
}

.reader-zoom-custom {
  width: 5rem;
  font-size: var(--text-xs);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
  background: var(--color-surface-raised);
  color: var(--color-ink);
}

@media (max-width: 60rem) {
  .reader-ask-panel {
    left: var(--space-4);
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ask-answer.is-streaming::after {
    animation: none;
  }
}

/* ------------------------------------------------------------------------
 * Reflow reader (Shelf 2.0, handoff 10).  Paged CSS columns; the font, line
 * height, alignment and hyphenation come from the reader preferences as
 * --tx-* properties (handoff 11; reader-prefs.css has the themes).  Sizes the
 * engine computes arrive as --tx-* properties too.
 * ---------------------------------------------------------------------- */

.text-viewer {
  position: absolute;
  z-index: 1;
  /* Margins (reader preference) shrink the box the engine measures. */
  inset: 4.75rem calc(var(--reader-margin, 0) * 100%) 0;
  overflow: hidden;
  outline: none;
}

.tx-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  user-select: text;
}

.tx-frame {
  position: relative;
  overflow: hidden;
}

.tx-columns {
  column-fill: auto;
  color: var(--color-ink);
  font-family: var(--tx-font-family, var(--font-reading));
  font-size: var(--tx-font-px, 18px);
  line-height: var(--tx-line-height, 1.55);
  text-align: var(--tx-align, start);
  hyphens: var(--tx-hyphens, auto);
  overflow-wrap: break-word;
  will-change: transform;
}

.tx-block {
  margin: 0 0 0.75em;
  white-space: pre-line;
}

.tx-h {
  margin: 1.1em 0 0.6em;
  font-size: 1.2em;
  font-weight: 650;
  line-height: 1.25;
  break-after: avoid;
  break-inside: avoid;
  hyphens: manual;
}

.tx-block.tx-h:first-child {
  margin-top: 0;
}

.tx-quote {
  margin: 0.9em 0 0.9em 1.4em;
  color: var(--color-ink-soft);
}

.tx-list {
  position: relative;
  margin-left: 1.4em;
}

.tx-list::before {
  position: absolute;
  left: -1em;
  content: "•";
  color: var(--color-muted);
}

.tx-footnote {
  color: var(--color-ink-soft);
  font-size: 0.85em;
  line-height: 1.45;
}

.tx-image {
  margin: 0.6em 0 1em;
  text-align: center;
  break-inside: avoid;
}

.tx-image img {
  max-width: 100%;
  max-height: calc(var(--tx-frame-h, 600px) * 0.92);
  object-fit: contain;
}

.tx-image.tx-caption-only {
  color: var(--color-ink-soft);
  font-size: 0.85em;
  font-style: italic;
  line-height: 1.45;
}

.tx-columns sup,
.tx-columns sub {
  font-size: 0.7em;
  line-height: 0;
}

.tx-ref {
  color: var(--color-accent);
  text-decoration: none;
}

.tx-ref:hover {
  text-decoration: underline;
}

.tx-cited {
  background: color-mix(in srgb, var(--color-caution) 22%, transparent);
  box-shadow: 0 0 0 0.25em color-mix(in srgb, var(--color-caution) 22%, transparent);
  border-radius: 2px;
  transition: background 900ms ease-out, box-shadow 900ms ease-out;
}

.tx-cited.tx-cited-fading {
  background: transparent;
  box-shadow: 0 0 0 0.25em transparent;
}

.tx-folio {
  position: absolute;
  bottom: 0.9rem;
  left: 0;
  width: 100%;
  color: var(--color-faint);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  text-align: center;
  pointer-events: none;
}

.reader-layout-host {
  width: 100%;
  height: 100%;
}

.reader-layout-toggle {
  display: inline-flex;
  flex: none;
  gap: 2px;
  padding: 2px;
  background: var(--color-paper-deep);
  border-radius: var(--radius-pill);
}

.reader-layout-option {
  min-height: calc(2.45rem - 4px);
  padding: 0 var(--space-3);
  color: var(--color-muted);
  background: transparent;
  border: 0;
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 700;
}

.reader-layout-option:hover {
  color: var(--color-ink);
}

.reader-layout-option.is-active {
  color: var(--color-ink);
  background: var(--color-surface-raised);
  box-shadow: 0 1px 3px rgb(0 0 0 / 10%);
  cursor: default;
}

.reader-layout-option:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 2px;
}

.reader-feed-pill {
  position: absolute;
  z-index: 25;
  bottom: var(--space-6);
  left: 50%;
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  min-height: 2.5rem;
  padding: 0 var(--space-5);
  color: var(--color-on-accent);
  background: var(--color-accent);
  border: 0;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-cover);
  cursor: pointer;
  font: 600 var(--text-sm) var(--font-ui);
  transform: translateX(-50%);
}

.reader-feed-pill:hover {
  background: var(--color-accent-strong);
}

/* ---------------------------------------------------------------------------
   Bindings (handoff 33): a generated cover wears its bookcase's binding.
   ------------------------------------------------------------------------- */

.book-cover.has-image {
  background: var(--color-paper-deep);
}

.book-cover[data-binding="cloth"] .cover-rule {
  height: 1px;
  background: #d9b97a;
  opacity: 1;
}

.book-cover[data-binding="cloth"] .cover-copy small,
.book-cover[data-binding="cloth"] .cover-format {
  color: #d9b97a;
  opacity: 1;
}

.book-cover[data-binding="cloth"] .cover-format { font-weight: 700; }

.book-cover[data-binding="antiquarian"] {
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: inset 0 0 0 8px var(--bind), inset 0 0 0 9px rgb(227 201 140 / 55%), var(--shadow-book);
}

.book-cover[data-binding="antiquarian"] .cover-rule { display: none; }

.book-cover[data-binding="antiquarian"] .cover-format {
  position: absolute;
  inset: auto 0 14px 0;
  margin: 0;
  opacity: 0.8;
  text-align: center;
}

.book-cover[data-binding="paperback"] .cover-rule { height: 2px; opacity: 0.8; }

.book-cover[data-binding="paperback"] .cover-copy strong {
  font-size: clamp(var(--text-md), 1.7vw, var(--text-xl));
  letter-spacing: -0.012em;
}

.book-cover[data-binding="paperback"] .cover-format { opacity: 0.7; }

.book-cover[data-binding="archive"] .cover-rule { display: none; }

.book-cover[data-binding="archive"] .cover-copy {
  margin: 6% 2% 0 0;
  padding: var(--space-3);
  color: #2b2521;
  background: #f1ead9;
  border-radius: 1px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 30%);
}

.book-cover[data-binding="archive"] .cover-format { color: #f1ead9; opacity: 0.85; }

.book-card-copy strong { font-size: 0.9375rem; }

@media (min-width: 44.0625rem) {
  .book-card-copy strong { font-size: var(--text-md); }
}

.recent-more {
  display: flex;
  margin: var(--space-10) auto var(--space-2);
}

.recent-more-note {
  text-align: center;
  font-size: var(--text-sm);
}

/* See it on the shelf */
.on-shelf-link { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--space-3); min-height: 3.5rem; margin-bottom: var(--space-6); padding: var(--space-2) var(--space-3); color: var(--color-ink); border: 1px solid var(--color-line); border-radius: var(--radius-md); }
.on-shelf-link:hover { background: color-mix(in srgb, var(--color-ink) 4%, transparent); }
.on-shelf-link:active { background: color-mix(in srgb, var(--color-ink) 8%, transparent); }
.on-shelf-art { display: flex; align-items: flex-end; gap: 1px; height: 2.4rem; padding-inline: 4px; border-bottom: 4px solid var(--wood); }
.on-shelf-art i { display: block; width: 9px; height: 82%; background: linear-gradient(90deg, rgb(255 255 255 / 16%), transparent 30%, rgb(0 0 0 / 26%)), var(--color-muted); border-radius: 1px 1px 0 0; }
.on-shelf-art i:last-child { height: 90%; }
.on-shelf-art .is-this { height: 100%; background: linear-gradient(90deg, rgb(255 255 255 / 16%), transparent 30%, rgb(0 0 0 / 26%)), var(--bind); outline: 1.5px solid var(--color-accent); transform: translateY(-4px); }
.on-shelf-copy strong { display: block; font-size: var(--text-sm); font-weight: 650; }
.on-shelf-copy small { color: var(--color-muted); font-size: var(--text-xs); }
.on-shelf-chevron { color: var(--color-muted); font-size: var(--text-lg); }

.book-page-sidebar .file-detail summary { color: #8a362c; }

/* ---------------------------------------------------------------------------
   Home, the room (handoff 32). Scoped to .home-view so the shelf and recent views keep theirs.
   ------------------------------------------------------------------------- */

.home-view .home-intro { grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-6); padding-block: var(--space-2) var(--space-8); }
.home-view .home-intro h1 { max-width: none; margin-bottom: 0; }
.home-view .library-stat { margin: 0; padding: 0; color: var(--color-muted); font-size: var(--text-sm); font-variant-numeric: tabular-nums; border: 0; }
.home-view .library-stat strong { display: inline; color: var(--color-ink); font: inherit; font-weight: 650; }
.home-view .section-heading { gap: var(--space-4); margin-bottom: var(--space-3); flex-wrap: wrap; }
.home-view .continue-section { margin-bottom: var(--space-10); }
.home-view .recent-section { margin-top: 0; margin-bottom: var(--space-10); }
.home-cases { margin-bottom: var(--space-10); }

/* The two ledges. */
.home-view .continue-row, .home-view .recent-row {
  --ledge-gap: var(--space-6);
  display: grid; grid-auto-flow: column; grid-auto-columns: 9rem; align-items: end; gap: var(--ledge-gap);
  margin-inline: 0; padding: var(--space-2) 0 var(--space-3);
  overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none;
}
.home-view .continue-row::-webkit-scrollbar, .home-view .recent-row::-webkit-scrollbar { display: none; }
/* One plank for the whole ledge: each card spans two rows of the row grid, so every cover
   stands on the same line and every plank starts at the same height. */
.home-view .continue-row, .home-view .recent-row { grid-template-rows: auto auto; }
.home-view .continue-card, .home-view .recent-card { grid-row: span 2; grid-template-rows: subgrid; align-items: end; gap: 0; row-gap: 0; }
.home-view .continue-copy, .home-view .recent-copy { align-self: start; }
.home-view .continue-copy small, .home-view .recent-copy small { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; text-transform: none; letter-spacing: 0; font-weight: 400; }
.home-view .continue-copy, .home-view .recent-copy { padding-top: 0; gap: 2px; }
.home-view .continue-copy::before, .home-view .recent-copy::before {
  content: ""; display: block; height: 9px; margin: 0 calc(-0.5 * var(--ledge-gap)) var(--space-2);
  background: linear-gradient(180deg, var(--wood-hi) 0 2px, var(--wood) 2px 7px, var(--wood-edge) 7px);
  box-shadow: 0 8px 12px -8px rgb(40 26 14 / 40%);
}
.home-view .continue-copy strong, .home-view .recent-copy strong { font-family: var(--font-display); font-weight: 600; font-size: var(--text-sm); -webkit-line-clamp: 1; }

/* Small generated covers never split a word mid-letter: the title is sized so ordinary words
   fit the cover's width, and a very long word is clipped by the line clamp, not broken. */
.home-view .continue-row .book-cover .cover-copy strong,
.home-view .recent-row .book-cover .cover-copy strong { font-size: 0.8125rem; overflow-wrap: normal; word-break: normal; hyphens: auto; -webkit-line-clamp: 4; }
.home-view .continue-row .book-cover, .home-view .recent-row .book-cover { padding-inline: 10px 8px; }

/* The miniature bookcases. */
.mini-cases { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-6); }
.mini-case { display: grid; align-content: start; justify-items: start; gap: var(--space-2); min-width: 0; color: inherit; }
.mini-frame { display: grid; gap: 5px; width: 100%; padding: 6px 6px 5px; background: var(--case-back); border: 5px solid var(--wood); border-top-width: 7px; border-radius: 2px; box-shadow: inset 0 0 0 1px var(--wood-edge), var(--shadow-case); transition: transform var(--dur-base) var(--ease-out); }
.mini-row { display: flex; align-items: flex-end; gap: 1px; height: 2.125rem; overflow: hidden; background: linear-gradient(180deg, var(--case-shade), transparent 60%); box-shadow: 0 5px 0 var(--wood-lo); }
.mini-row i { display: block; flex: none; background: linear-gradient(90deg, rgb(255 255 255 / 16%), transparent 30%, rgb(0 0 0 / 26%)), var(--bind); border-radius: 1px 1px 0 0; }
.mini-count { margin-top: -2px; color: var(--color-muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
@media (hover: hover) { .mini-case:hover .mini-frame { transform: translateY(-3px); } }
.mini-case:active .mini-frame { transform: scale(0.985); }
.mini-case:focus-visible { outline-offset: 4px; }

/* All shelves. */
.all-shelves { margin-top: var(--space-6); border-top: 1px solid var(--color-line); }
.all-shelves > summary { display: flex; align-items: center; justify-content: space-between; min-height: 2.75rem; cursor: pointer; color: var(--color-ink-soft); font-size: var(--text-sm); font-weight: 650; list-style: none; }
.all-shelves > summary::-webkit-details-marker { display: none; }
.all-shelves > summary::after { content: "›"; color: var(--color-muted); font-size: var(--text-lg); transition: rotate var(--dur-base) var(--ease-out); }
.all-shelves[open] > summary::after { rotate: 90deg; }
.all-shelves .collection-section { padding-top: var(--space-4); border-top: 0; }
.all-shelves .collection-title-row { margin-bottom: var(--space-1); padding-bottom: var(--space-2); border-bottom: 1px solid var(--color-ink); }
.all-shelves .collection-title-row h3 { margin: 0; font: 600 var(--text-lg)/1.2 var(--font-display); }
.all-shelves .collection-list, .all-shelves { display: block; }
.all-shelves .shelf-summary-grid { gap: 0 var(--space-8); }
.all-shelves .shelf-summary { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: var(--space-3); min-height: 3.25rem; padding: var(--space-2) 0 var(--space-2) var(--space-4); overflow: visible; background: transparent; border: 0; border-bottom: 1px solid var(--color-line-soft); border-radius: 0; }
.all-shelves .shelf-summary:hover { background: color-mix(in srgb, var(--color-ink) 4%, transparent); box-shadow: none; transform: none; }
.all-shelves .shelf-summary:active { background: color-mix(in srgb, var(--color-ink) 8%, transparent); }
.all-shelves .shelf-summary::after { content: none; }
.all-shelves .shelf-summary::before { content: ""; position: absolute; left: 0; top: 50%; width: 3px; height: 1.25rem; translate: 0 -50%; background: var(--shelf-color, var(--color-accent)); border-radius: 2px; }
.all-shelves .shelf-summary h3 { max-width: none; margin: 0; overflow: hidden; font-family: var(--font-display); font-size: 1.0625rem; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.all-shelves .shelf-summary p { font-variant-numeric: tabular-nums; white-space: nowrap; }
.all-shelves .shelf-arrow { position: static; }

.home-view .empty-reading { background: transparent; border: 1px solid var(--color-line); border-radius: var(--radius-md); }
.home-view .discreet-panel { border-radius: var(--radius-md); }

@media (max-width: 62rem) {
  .home-view .home-intro { grid-template-columns: 1fr; gap: var(--space-2); }
  .home-view .continue-row, .home-view .recent-row { margin-inline: calc(-1 * var(--gutter)); padding-inline: var(--gutter); scroll-padding-inline: var(--gutter); }
  .home-view .section-heading .discreet-toggle { display: none; }
  .all-shelves .shelf-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 44rem) {
  .home-view .home-intro { padding-block: 0 var(--space-6); }
  .home-view .section-heading p { display: none; }
  .home-view .continue-row, .home-view .recent-row { --ledge-gap: 0.875rem; grid-auto-columns: 6.5rem; }
  .home-view .continue-copy strong, .home-view .recent-copy strong { -webkit-line-clamp: 2; }
  .home-view .continue-row .book-cover .cover-copy strong, .home-view .recent-row .book-cover .cover-copy strong { font-size: 0.6875rem; }
  .mini-cases { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5) 0.875rem; }
  .all-shelves .shelf-summary-grid { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------------------
   Handoff 34: sheets, dialogs and notes links
   ------------------------------------------------------------------------- */

.global-note-copy .text-link,
.global-note-book .button,
.knowledge-entry .text-link {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
}

.sheet input, .sheet select, .sheet textarea,
.search-dialog input, .search-dialog select, .search-dialog textarea,
.reflection-dialog input, .reflection-dialog select, .reflection-dialog textarea,
.annotation-composer input, .annotation-composer select, .annotation-composer textarea,
.collection-new input, .feed-save-new input {
  font-size: max(1rem, 16px);
}

@keyframes sheet-up { from { opacity: 0; transform: translateY(24px); } }
@keyframes sheet-down { from { opacity: 0; transform: translateY(-24px); } }

@media (max-width: 44rem) {
  /* Bottom sheets: View settings, Save to a collection, Shortcuts. */
  .sheet {
    width: 100%;
    max-width: 100%;
    max-height: min(88dvh, calc(100dvh - 3rem));
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .sheet[open] { animation: sheet-up var(--dur-slow) var(--ease-out); }
  .sheet::before {
    content: "";
    display: block;
    width: 2.25rem;
    height: 4px;
    margin: var(--space-2) auto 0;
    background: var(--color-line);
    border-radius: var(--radius-pill);
  }
  .sheet-header {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: var(--space-4) var(--gutter);
    background: var(--color-surface-raised);
  }
  .settings-group { padding-inline: var(--gutter); }

  /* Top sheets for text entry. */
  .reflection-dialog,
  .annotation-composer,
  .text-reader-view .annotation-composer {
    width: 100%;
    max-width: 100%;
    margin: 0 0 auto;
    max-height: calc(100dvh - 1rem);
    overflow-y: auto;
    border-width: 0 0 1px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  }
  .reflection-dialog[open],
  .annotation-composer[open] { animation: sheet-down var(--dur-slow) var(--ease-out); }
  .reflection-form,
  .annotation-form,
  .text-reader-view .annotation-form {
    padding: calc(env(safe-area-inset-top, 0px) + var(--space-4)) var(--gutter) var(--space-5);
  }
  .reflection-form h2,
  .annotation-form h2 { font-size: var(--text-xl); }
  .reflection-form textarea { min-height: 7rem; max-height: 34dvh; }
  .reflection-form .eyebrow { white-space: nowrap; letter-spacing: 0.1em; }

  /* Search fills the screen. */
  .search-dialog {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .search-frame {
    height: 100%;
    max-height: none;
    padding: calc(env(safe-area-inset-top, 0px) + var(--space-3)) var(--gutter) env(safe-area-inset-bottom, 0px);
  }
  .search-header h1 { font-size: var(--text-xl); }
  .search-input { min-height: 3rem; font-size: 1rem; }
  .search-result { min-height: 3rem; }
}
