#content-textbooks { margin-top:20px; }
.textbook-heading { display:flex; align-items:flex-end; justify-content:space-between; gap:16px; padding:12px 2px 22px; }
.textbook-heading h2 { margin:0 0 8px; font-size:28px; letter-spacing:-.5px; }
.textbook-heading p { margin:0; color:var(--muted); font-size:14px; line-height:1.6; }
.textbook-badge { flex-shrink:0; padding:8px 12px; border-radius:10px; background:#faeee8; color:var(--accent-dark); font-size:12px; }
.textbook-layout { display:grid; grid-template-columns:220px minmax(0,1fr); gap:20px; align-items:start; }
.textbook-directory { padding:12px; background:var(--paper); border:1px solid var(--line); border-radius:20px; }
.textbook-directory h3 { margin:4px 4px 12px; font-size:14px; }
.textbook-pages { display:grid; gap:8px; max-height:70vh; overflow:auto; padding:3px; }
.textbook-page { display:flex; align-items:center; gap:10px; padding:8px; min-width:0; text-align:left; color:var(--ink); background:transparent; border:2px solid transparent; border-radius:12px; }
.textbook-page:hover { background:var(--bg); }
.textbook-page[aria-current="page"] { border-color:var(--accent); background:#faeee8; }
.textbook-page img { width:72px; height:48px; object-fit:contain; background:#fff; border:1px solid var(--line); border-radius:5px; }
.textbook-page span { font-size:12px; line-height:1.5; }
.textbook-page small { display:block; color:var(--muted); font-size:11px; }
.textbook-reader { min-width:0; background:var(--paper); border:1px solid var(--line); border-radius:20px; overflow:hidden; }
.textbook-toolbar { display:flex; align-items:center; gap:8px; flex-wrap:wrap; padding:14px; border-bottom:1px solid var(--line); }
.textbook-toolbar button, .textbook-toolbar a, .textbook-toolbar select { min-height:40px; padding:8px 12px; border:1px solid #dfe2e7; border-radius:9px; background:white; color:var(--ink); font:inherit; font-size:13px; text-decoration:none; }
.textbook-toolbar button:disabled { opacity:.35; cursor:default; }
.textbook-toolbar select { max-width:100%; min-width:0; }
.textbook-zoom { display:flex; gap:6px; align-items:center; margin-left:auto; }
.textbook-zoom output { width:42px; text-align:center; font-size:12px; color:var(--muted); }
.textbook-stage { overflow:auto; max-height:78vh; min-height:160px; background:#e9ebee; overscroll-behavior:contain; }
.textbook-stage img { display:block; width:calc(100% * var(--textbook-zoom, 1)); max-width:none; height:auto; margin:0 auto; }
.textbook-status { margin:0; padding:12px 16px; color:var(--muted); font-size:13px; line-height:1.6; }
.textbook-status:empty { display:none; }
.textbook-status.is-error { color:#a63d25; }
.textbook-footer { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:14px 16px; border-top:1px solid var(--line); font-size:13px; }
.textbook-footer p { margin:0; color:var(--muted); }
.textbook-footer strong { flex-shrink:0; font-variant-numeric:tabular-nums; }
.textbook-toolbar a:focus-visible, .textbook-toolbar select:focus-visible { outline:3px solid #c4543570; outline-offset:3px; }
.textbook-directory-scroll { display:none; }
@media(min-width:901px) {
  .textbook-layout { align-items:stretch; }
  .textbook-directory { display:flex; flex-direction:column; min-height:0; contain:size; }
  .textbook-directory h3 { flex-shrink:0; }
  .textbook-pages { flex:1; min-height:0; max-height:none; align-content:start; }
  .textbook-directory-scroll { display:block; flex-shrink:0; width:100%; margin-top:8px; padding:12px 4px 4px; border:0; border-top:1px solid var(--line); background:transparent; color:var(--accent-dark); font:inherit; font-size:11px; line-height:1.6; cursor:pointer; }
  .textbook-directory-scroll:disabled { color:var(--muted); cursor:default; }
  .textbook-directory-scroll:focus-visible { outline:2px solid var(--accent); outline-offset:2px; border-radius:6px; }
  .textbook-pages { scrollbar-width:thin; scrollbar-color:#b7bbc3 transparent; }
}
@media(min-width:1024px) { .topic-nav { max-width:640px; } }
@media(max-width:900px) {
  .textbook-layout { grid-template-columns:minmax(0,1fr); gap:14px; }
  .textbook-directory { padding:10px; }
  .textbook-directory h3 { margin-bottom:8px; }
  .textbook-pages { display:flex; max-height:none; overflow-x:auto; scroll-snap-type:x proximity; }
  .textbook-page { flex:0 0 116px; flex-direction:column; align-items:stretch; gap:6px; scroll-snap-align:start; }
  .textbook-page img { width:96px; height:62px; }
  .textbook-page small { display:none; }
  .textbook-stage { max-height:70vh; }
}
@media(max-width:480px) {
  .topic-tab { padding:12px 4px; } .topic-tab strong { font-size:13px; }
  .textbook-heading { align-items:flex-start; flex-direction:column; gap:10px; padding-top:10px; }
  .textbook-heading h2 { font-size:26px; }
  .textbook-toolbar { padding:10px; gap:6px; }
  .textbook-toolbar button, .textbook-toolbar a, .textbook-toolbar select { min-height:44px; padding:8px 10px; font-size:12px; }
  .textbook-toolbar select { flex:1; }
  .textbook-zoom { width:100%; justify-content:center; margin:0; }
  .textbook-zoom a { margin-left:auto; }
  .textbook-footer { align-items:flex-start; font-size:12px; }
}

html.textbook-fullscreen-open { overflow:hidden; }
.textbook-fullscreen { position:fixed; inset:0; width:100%; max-width:none; height:100%; height:100dvh; max-height:none; margin:0; padding:0; border:0; background:#000; color:#fff; overflow:hidden; }
.textbook-fullscreen::backdrop { background:#000; }
.textbook-fullscreen-bar { position:absolute; inset:0 0 auto; z-index:2; display:flex; align-items:center; justify-content:space-between; gap:12px; padding:calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); background:linear-gradient(#11151bc9, transparent); pointer-events:none; }
.textbook-fullscreen-bar strong { font-size:14px; font-weight:500; }
.textbook-fullscreen-image { position:absolute; inset:0; overflow:hidden; background:#000; }
.textbook-fullscreen-image img { display:block; width:100%; height:100%; max-width:none; object-fit:contain; object-position:center; margin:0; }
.textbook-fullscreen-image p { position:absolute; bottom:10px; left:0; right:0; margin:0; padding:10px; text-align:center; background:#11151be6; color:white; font-size:13px; }
.textbook-fullscreen-image p:empty { display:none; }
.textbook-fullscreen-arrow { position:absolute; top:50%; transform:translateY(-50%); z-index:2; display:grid; place-items:center; width:48px; height:64px; padding:0; border:1px solid #ffffff30; border-radius:12px; background:#303741e6; color:#fff; font-size:40px; line-height:1; }
.textbook-fullscreen-previous { left:max(12px, env(safe-area-inset-left)); }
.textbook-fullscreen-next { right:max(12px, env(safe-area-inset-right)); }
.textbook-fullscreen-arrow:disabled { opacity:.25; cursor:default; }
@media(max-width:600px) {
  .textbook-zoom { flex-wrap:wrap; }
  .textbook-fullscreen-arrow { top:auto; bottom:calc(12px + env(safe-area-inset-bottom)); transform:none; width:64px; height:48px; font-size:32px; }
  .textbook-fullscreen-previous { left:calc(50% - 80px); }
  .textbook-fullscreen-next { right:calc(50% - 80px); }
  .textbook-fullscreen-bar strong { font-size:12px; }
}
.textbook-lock-thumb { display: grid; place-items: center; width: 96px; min-height: 62px; background: #f2edf7; border-radius: 8px; color: #9983ad; font-size: 24px; }

/* Textbook media library and persistent players */
#content-textbooks [hidden], .textbook-media-dock [hidden] { display:none !important; }
.textbook-view-switch { display:flex; gap:6px; margin:0 0 18px; padding:5px; width:fit-content; border-radius:14px; background:#e9ebee; }
.textbook-view-switch button { border:0; border-radius:10px; padding:11px 20px; font:inherit; font-size:14px; background:transparent; color:var(--ink); }
.textbook-view-switch button[aria-pressed=true] { background:white; box-shadow:0 2px 8px #0000000d; color:var(--accent-dark); }
.textbook-media-library { border:1px solid var(--line); border-radius:20px; background:var(--paper); padding:24px; }
.textbook-media-heading { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:16px; }
.textbook-media-heading h3 { margin:0 0 8px; font-size:22px; }
.textbook-media-heading p, .textbook-media-notice { font-size:14px; line-height:1.6; color:#656b76; }
.textbook-media-heading label { display:flex; align-items:center; gap:10px; font-size:14px; }
.textbook-unit-select { background:white; color:#242933; border:1px solid #dfe2e7; padding:10px; border-radius:9px; font:inherit; }
.textbook-media-notice { padding:12px 16px; background:#fff4e8; border-radius:10px; color:#815329; }
.textbook-resource-list { display:grid; gap:8px; }
.textbook-resource-list h4 { margin:18px 0 4px; font-size:16px; }
.textbook-resource-list p { font-size:14px; color:#656b76; }
.textbook-resource { display:grid; grid-template-columns:1fr auto; gap:6px 12px; width:100%; border:1px solid #e2e4e8; border-radius:12px; background:white; padding:14px 16px; text-align:left; color:#242933; font:inherit; }
.textbook-resource strong { font-size:15px; }
.textbook-resource small { grid-row:2; font-size:12px; color:#656b76; overflow-wrap:anywhere; }
.textbook-resource span { grid-column:2; grid-row:1 / 3; align-self:center; font-size:13px; color:#815329; }
.textbook-resource:disabled { opacity:1; cursor:default; background:#fafafa; }
.textbook-media-dock { position:relative; z-index:20; color:#242933; }
.textbook-media-toggle { position:fixed; bottom:24px; right:24px; z-index:21; padding:12px 16px; border:1px solid #ffffff40; border-radius:30px; background:#303741; color:white; font:inherit; font-size:14px; box-shadow:0 6px 24px #0003; }
.textbook-media-drawer { position:fixed; z-index:22; bottom:80px; right:24px; width:min(390px, calc(100vw - 32px)); max-height:65dvh; overflow:auto; border:1px solid #dde0e5; border-radius:18px; background:#fff; color:#242933; padding:18px; box-sizing:border-box; box-shadow:0 12px 48px #0004; }
.textbook-media-drawer .textbook-resource { grid-template-columns:1fr; }
.textbook-media-drawer .textbook-resource span { grid-column:1; grid-row:3; }
.textbook-drawer-close, .textbook-audio-close, .textbook-video-handle button { border:0; border-radius:8px; min-width:36px; min-height:36px; font-size:20px; cursor:pointer; }
.textbook-audio-player { position:fixed; z-index:23; left:20px; bottom:20px; width:min(360px, calc(100vw - 40px)); padding:14px; border:1px solid #ddd; border-radius:16px; background:white; box-shadow:0 8px 32px #0003; box-sizing:border-box; }
.textbook-audio-player span { display:block; font-size:14px; padding-right:32px; margin-bottom:10px; }
.textbook-audio-player audio { width:100%; height:40px; }
.textbook-audio-close { position:absolute; right:8px; top:5px; }
.textbook-video-player { position:fixed; z-index:24; right:24px; bottom:90px; width:min(420px, calc(100vw - 32px)); max-height:80dvh; overflow:auto; border-radius:14px; background:#171b23; color:white; box-shadow:0 12px 48px #0006; }
.textbook-video-handle { display:flex; align-items:center; gap:6px; padding:8px; cursor:move; touch-action:none; }
.textbook-video-handle span { flex:1; padding-left:6px; font-size:14px; }
.textbook-video-handle button { background:#343b48; color:white; }
.textbook-video-player video { display:block; width:100%; max-height:60dvh; }
.textbook-video-player p { padding:0 12px; font-size:14px; }
.textbook-video-player p:empty { display:none; }
.textbook-fullscreen-close { pointer-events:auto; background:#303741; color:white; border:1px solid #ffffff40; border-radius:9px; padding:10px 14px; font:inherit; font-size:14px; }
.textbook-fullscreen .textbook-media-toggle { bottom:90px; }
.textbook-fullscreen .textbook-media-drawer { bottom:146px; }
@media(max-width:600px) {
  .textbook-media-library { padding:16px; }
  .textbook-resource { grid-template-columns:1fr; }
  .textbook-resource span { grid-column:1; grid-row:3; }
  .textbook-media-toggle { right:16px; bottom:16px; }
  .textbook-media-drawer { right:16px; }
  .textbook-audio-player { bottom:78px; }
}
.textbook-unit-group { display:grid; gap:8px; padding:20px 0; border-top:1px solid #e2e4e8; }
.textbook-unit-group:first-child { border-top:0; }
.textbook-unit-group > h3 { margin:0; font-size:20px; color:var(--accent-dark, #a0442c); }
.textbook-media-drawer .textbook-unit-group > h3 { font-size:18px; }
/* Drag the header; collapse to a narrow player that fits in the page gutter. */
.textbook-audio-player { padding:10px; }
.textbook-audio-handle { display:flex; align-items:center; gap:4px; margin-bottom:8px; cursor:grab; touch-action:none; user-select:none; }
.textbook-audio-handle:active { cursor:grabbing; }
.textbook-audio-handle span { flex:1; min-width:0; margin:0; padding:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.textbook-audio-handle span::before { content:'⠿ '; color:#737b89; }
.textbook-audio-handle button { flex-shrink:0; min-width:30px; min-height:32px; border:0; border-radius:8px; background:#f0f1f3; color:#242933; font-size:20px; cursor:pointer; }
.textbook-audio-handle .textbook-audio-close { position:static; }
.textbook-audio-play { display:none; }
.textbook-audio-player.is-compact { width:82px; border-radius:14px; }
.textbook-audio-player.is-compact .textbook-audio-handle { flex-wrap:wrap; justify-content:center; gap:2px; }
.textbook-audio-player.is-compact .textbook-audio-handle span { flex:0 0 100%; height:24px; font-size:0; }
.textbook-audio-player.is-compact .textbook-audio-handle span::before { display:block; font-size:22px; text-align:center; }
.textbook-audio-player.is-compact audio { display:none; }
.textbook-audio-player.is-compact .textbook-audio-play { display:block; width:100%; min-height:44px; border:0; border-radius:10px; background:#303741; color:white; font-size:20px; cursor:pointer; }
.textbook-page .textbook-thumb { position:relative; display:block; flex:0 0 72px; width:72px; }
.textbook-thumb img { display:block; }
.textbook-page .textbook-member-badge { position:absolute; inset:auto 0 0; display:flex; justify-content:center; align-items:center; gap:3px; padding:3px 1px; border-radius:0 0 5px 5px; background:#28202ee8; color:#ffe2a1; line-height:1.3; pointer-events:none; }
.textbook-member-badge svg { width:10px; height:10px; flex-shrink:0; }
.textbook-page .textbook-member-badge span { font-size:10px; }
.textbook-is-member .textbook-member-badge { display:none; }
@media(max-width:900px) { .textbook-page .textbook-thumb { width:96px; flex-basis:auto; } }
