/* The audiobook library is a separate browser over the existing narration engine. */
.audiobook-backdrop {
  position: fixed;
  z-index: 60;
  inset: 0 0 0 var(--rail-width);
  background: rgb(22 15 34 / 22%);
  backdrop-filter: blur(1px);
}

.audiobook-drawer {
  position: fixed;
  z-index: 70;
  inset: 0 auto 0 var(--rail-width);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  width: calc(100vw - var(--rail-width));
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  transform: translateX(calc(-100% - 18px));
  visibility: hidden;
  pointer-events: none;
  transition: transform 220ms cubic-bezier(.22, .8, .3, 1), visibility 0s linear 220ms;
}

.audiobook-drawer.is-open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

body.audiobook-library-open #narration-dock,
body.audiobook-library-open #narration-follow {
  display: none !important;
}

.audiobook-library-header { grid-row: 1; min-width: 0; }
.audiobook-library-header, .audiobook-library-tools, .audiobook-player { padding-inline: max(22px, calc((100% - 760px) / 2)); }
#audiobook-browse, .audiobook-detail, .audiobook-load-status { width: 100%; max-width: 720px; margin-inline: auto; }
.audiobook-library-header > div { min-width: 0; }
.audiobook-library-header h1 { overflow-wrap: anywhere; }
.audiobook-library-header .icon-button { flex: none; }
.audiobook-library-tools { grid-row: 2; display: grid; min-width: 0; gap: 10px; padding: 0 22px 16px; border-bottom: 1px solid var(--line); }
.audiobook-author-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--canvas); }
.audiobook-drawer button, .audiobook-drawer select { touch-action: manipulation; }
.audiobook-author-tabs button, .audiobook-view-options button, .audiobook-drawer select, .audiobook-start-actions button, .audiobook-back-button, .audiobook-load-status button, .audiobook-detail-retry {
  min-height: 44px;
  min-width: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.35;
}
.audiobook-author-tabs button { border-color: transparent; background: transparent; color: var(--muted); }
.audiobook-author-tabs button[aria-pressed="true"] { background: var(--paper); color: var(--purple-dark); box-shadow: var(--shadow-sm); }
.audiobook-display-tools { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; min-width: 0; }
.audiobook-sort-label { display: flex; align-items: center; gap: 7px; min-width: 0; color: var(--muted); font-size: 11px; font-weight: 700; }
.audiobook-drawer select { min-width: 0; max-width: 100%; padding-right: 22px; }
.audiobook-view-options { display: flex; gap: 5px; }
.audiobook-view-options button { display: grid; width: 44px; padding: 11px; place-items: center; }
.audiobook-view-options button[aria-pressed="true"] { border-color: var(--purple); background: var(--purple-soft); color: var(--purple-dark); }
.audiobook-drawer svg { width: 21px; height: 21px; flex: none; fill: currentColor; }
.audiobook-library-scroll { grid-row: 3; min-width: 0; min-height: 0; padding: 16px 20px 24px; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-gutter: stable; }
.audiobook-library-summary { margin: 0 2px 14px; color: var(--muted); font-size: 11px; font-weight: 750; }
.audiobook-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 19px 14px; min-width: 0; }
.audiobook-card { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; align-items: start; gap: 10px; min-width: 0; width: 100%; padding: 5px; border: 1px solid transparent; border-radius: 12px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.audiobook-card:hover, .audiobook-card:focus-visible { border-color: var(--line-strong); background: var(--purple-soft); }
.audiobook-art { position: relative; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 9px; background: linear-gradient(145deg, var(--purple-dark), var(--purple)); color: white; }
.audiobook-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.audiobook-art-fallback { display: grid; place-items: center; width: 100%; height: 100%; }
.audiobook-art-fallback svg { width: 34%; height: 34%; max-width: 64px; max-height: 64px; opacity: .65; }
.audiobook-card-art { width: 100%; aspect-ratio: 1; }
.audiobook-card-copy { display: grid; min-width: 0; gap: 5px; }
.audiobook-card-copy strong { font-family: Georgia, "Times New Roman", serif; font-size: 19px; font-weight: 650; line-height: 1.2; overflow-wrap: anywhere; }
.audiobook-card-copy small { color: var(--muted); font-size: 11px; line-height: 1.4; overflow-wrap: anywhere; }
.audiobook-card-copy .audiobook-card-progress { color: var(--purple-dark); font-weight: 700; }
.audiobook-card-copy .audiobook-card-attribution { font-style: italic; }
.audiobook-cards[data-view="list"] { grid-template-columns: minmax(0, 1fr); gap: 7px; }
.audiobook-cards[data-view="list"] .audiobook-card { grid-template-columns: 76px minmax(0, 1fr); align-items: center; padding: 8px; gap: 14px; border-color: var(--line); }
.audiobook-cards[data-view="list"] .audiobook-card-copy strong { font-size: 19px; }
.audiobook-empty { grid-column: 1 / -1; color: var(--muted); line-height: 1.6; }
.audiobook-load-status { display: grid; justify-items: start; gap: 10px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.audiobook-detail { min-width: 0; }
.audiobook-back-button { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; }
.audiobook-detail-hero { display: grid; grid-template-columns: 112px minmax(0, 1fr); align-items: center; gap: 17px; }
.audiobook-detail-art { width: 100%; aspect-ratio: 1; }
.audiobook-detail-copy { min-width: 0; }
.audiobook-detail-copy h2 { margin: 5px 0 9px; font-family: Georgia, "Times New Roman", serif; font-size: 27px; line-height: 1.15; font-weight: 600; overflow-wrap: anywhere; }
.audiobook-detail-copy > p:last-child { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.audiobook-detail-note { color: var(--muted); font-size: 12px; line-height: 1.5; }
.audiobook-saved-status { margin: 18px 0 10px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.audiobook-start-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.audiobook-start-actions .audiobook-primary-action { border-color: var(--purple); background: var(--purple); color: white; }
.audiobook-drawer button:disabled { cursor: not-allowed; opacity: .5; }
.audiobook-detail-status { color: var(--muted); font-size: 12px; line-height: 1.5; }
.audiobook-detail-status:not(:empty) { margin-top: 14px; }
.audiobook-detail-retry { margin-top: 8px; }
.audiobook-chapters-heading { margin: 23px 0 10px; color: var(--purple-dark); font-size: 12px; font-weight: 800; }
.audiobook-chapters { display: grid; gap: 4px; padding: 0; margin: 0; list-style: none; }
.audiobook-chapter-button { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; min-width: 0; width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.audiobook-chapter-button span { min-width: 0; font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.audiobook-chapter-button small { flex: none; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.audiobook-chapter-button.is-current { border-color: var(--purple); background: var(--purple-soft); box-shadow: inset 3px 0 0 var(--purple); }
.audiobook-player { grid-row: 4; min-width: 0; min-height: 0; padding: 14px 22px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line-strong); background: color-mix(in srgb, var(--paper) 90%, var(--purple-soft)); box-shadow: 0 -6px 20px rgb(24 17 38 / 5%); }
.audiobook-player-summary { display: grid; grid-template-columns: 46px minmax(0, 1fr); gap: 11px; align-items: center; }
.audiobook-player-art { width: 46px; height: 46px; }
.audiobook-player-copy { min-width: 0; }
.audiobook-player-copy p { margin: 0 0 3px; color: var(--purple-dark); font-size: 9px; font-weight: 800; letter-spacing: .055em; text-transform: uppercase; }
.audiobook-player-copy strong { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-family: Georgia, "Times New Roman", serif; font-size: 19px; line-height: 1.15; overflow-wrap: anywhere; }
.audiobook-player-copy small { display: block; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.audiobook-progress { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; margin-top: 13px; }
.audiobook-progress span { color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.audiobook-progress input { min-width: 0; width: 100%; height: 26px; margin: 0; accent-color: var(--purple); cursor: pointer; }
.audiobook-transport { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 5px; }
.audiobook-transport button { position: relative; display: grid; place-items: center; width: 44px; height: 44px; padding: 9px; border: 1px solid var(--line-strong); border-radius: 50%; background: var(--paper); color: var(--purple-dark); cursor: pointer; }
.audiobook-transport button > span { position: absolute; top: 17px; font-size: 8px; font-weight: 800; }
.audiobook-transport .audiobook-play-button { width: 54px; height: 54px; border-color: var(--purple); background: var(--purple); color: white; }
.audiobook-progress-privacy { margin: 7px 0 0; color: var(--muted); font-size: 9px; line-height: 1.4; text-align: center; }
.audiobook-player-error { margin: 9px 0 0; color: var(--danger); font-size: 11px; line-height: 1.5; }
.audiobook-rail-button { position: relative; }
.audiobook-rail-button > span { max-width: 100%; font-size: 9px; line-height: 1.2; letter-spacing: 0; white-space: normal; overflow-wrap: normal; }
.audiobook-rail-button.is-playing::after { position: absolute; top: 12px; right: 9px; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 8px var(--gold); content: ""; }

html[data-study-theme="dark"] .audiobook-drawer { background: #211c29; }
html[data-study-theme="dark"] .audiobook-start-actions .audiobook-primary-action,
html[data-study-theme="dark"] .audiobook-transport .audiobook-play-button { border-color: #5c43ba; background: #5c43ba; color: white; }
html[data-study-theme="retro"] .audiobook-drawer { border-right-color: rgb(73 233 255 / 32%); background: radial-gradient(ellipse at 15% 0%, rgb(28 128 166 / 14%), transparent 38%), linear-gradient(145deg, #0d112d, #160d25); }
html[data-study-theme="retro"] .audiobook-library-header { background: linear-gradient(110deg, rgb(35 176 209 / 12%), transparent 60%); }
html[data-study-theme="retro"] .audiobook-author-tabs { border-color: rgb(73 233 255 / 25%); background: #0a1026; }
html[data-study-theme="retro"] .audiobook-author-tabs button[aria-pressed="true"], html[data-study-theme="retro"] .audiobook-view-options button[aria-pressed="true"] { color: #49e9ff; background: rgb(73 233 255 / 10%); box-shadow: inset 0 -2px 0 #ff4ab6; }
html[data-study-theme="retro"] .audiobook-card:hover, html[data-study-theme="retro"] .audiobook-card:focus-visible { background: rgb(73 233 255 / 6%); border-color: rgb(73 233 255 / 40%); }
html[data-study-theme="retro"] .audiobook-card-art { box-shadow: 0 3px 16px rgb(73 233 255 / 9%); }
html[data-study-theme="retro"] .audiobook-start-actions .audiobook-primary-action, html[data-study-theme="retro"] .audiobook-transport .audiobook-play-button { border-color: #49e9ff; background: #49e9ff; color: #071021; box-shadow: 0 0 17px rgb(73 233 255 / 15%); }
html[data-study-theme="retro"] .audiobook-player { border-top-color: #ff4ab6; background: linear-gradient(115deg, rgb(29 115 149 / 16%), transparent 70%), #0c1029; box-shadow: 0 -1px 0 rgb(73 233 255 / 55%); }
html[data-study-theme="retro"] .audiobook-chapter-button.is-current { border-color: rgb(255 74 182 / 40%); background: rgb(255 74 182 / 8%); box-shadow: inset 3px 0 0 #ff4ab6; }

@media (max-width: 720px) {
  .audiobook-drawer { width: calc(100vw - var(--rail-width)); }
  .audiobook-library-header { padding: 17px 14px 12px; gap: 10px; }
  .audiobook-library-header h1 { font-size: 26px; }
  .audiobook-library-tools { padding: 0 12px 12px; gap: 8px; }
  .audiobook-sort-label { gap: 5px; }
  .audiobook-drawer select { padding-inline: 7px 18px; font-size: 11px; }
  .audiobook-display-tools { gap: 5px; }
  .audiobook-view-options { gap: 4px; }
  .audiobook-library-scroll { padding: 12px 10px 20px; scrollbar-gutter: auto; }
  .audiobook-cards { gap: 16px 7px; }
  .audiobook-card { padding: 3px; gap: 8px; }
  .audiobook-card-copy strong { font-size: 17px; }
  .audiobook-card-copy small { font-size: 10px; }
  .audiobook-cards[data-view="list"] .audiobook-card { grid-template-columns: 62px minmax(0, 1fr); gap: 10px; padding: 7px; }
  .audiobook-cards[data-view="list"] .audiobook-card-copy strong { font-size: 17px; }
  .audiobook-detail-hero { grid-template-columns: 80px minmax(0, 1fr); gap: 12px; }
  .audiobook-detail-copy h2 { font-size: 21px; }
  .audiobook-detail-copy .eyebrow { font-size: 9px; }
  .audiobook-player { padding: 11px 12px max(10px, env(safe-area-inset-bottom)); }
  .audiobook-player-copy strong { font-size: 17px; }
  .audiobook-progress { gap: 7px; margin-top: 8px; }
}

@media (max-width: 360px) {
  .audiobook-sort-label { flex: 1 1 100%; }
  .audiobook-sort-label select { flex: 1; }
  .audiobook-view-options { margin-left: auto; }
  .audiobook-display-tools { row-gap: 6px; }
  .audiobook-library-header h1 { font-size: 24px; }
  .audiobook-detail-hero { grid-template-columns: 66px minmax(0, 1fr); gap: 9px; }
  .audiobook-detail-copy h2 { font-size: 19px; }
}

@media (max-height: 620px) {
  .tool-rail { overflow-y: auto; scrollbar-width: none; }
  .rail-actions { flex: none; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .audiobook-library-header { padding-block: 8px; }
  .audiobook-library-header .eyebrow { display: none; }
  .audiobook-library-header h1 { font-size: 24px; }
  .audiobook-library-tools { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; padding-bottom: 8px; }
  .audiobook-display-tools { flex-wrap: nowrap; }
  .audiobook-sort-label { font-size: 0; }
  .audiobook-sort-label select { font-size: 11px; }
  .audiobook-view-options button { width: 36px; min-width: 36px; padding: 9px; }
  .audiobook-player { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 14px; padding-block: 7px; }
  .audiobook-player-summary { grid-column: 1; grid-row: 1; grid-template-columns: 36px minmax(0, 1fr); }
  .audiobook-player-art { width: 36px; height: 36px; }
  .audiobook-player-copy strong { font-size: 15px; -webkit-line-clamp: 1; }
  .audiobook-player-copy small { display: none; }
  .audiobook-progress { grid-column: 1; grid-row: 2; margin-top: 1px; }
  .audiobook-transport { grid-column: 2; grid-row: 1 / 3; gap: 7px; margin: 0; }
  .audiobook-progress-privacy { display: none; }
  .audiobook-player-error { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  .audiobook-drawer { transition: none; }
}

@media (min-width: 721px) {
  .audiobook-library-header, .audiobook-library-tools, .audiobook-player { padding-inline: max(22px, calc((100% - 760px) / 2)); }
}

@media (prefers-contrast: more) {
  .audiobook-card, .audiobook-art, .audiobook-chapter-button, .audiobook-player { border-color: currentColor; }
  .audiobook-drawer button:disabled { opacity: .7; }
}
