.library { color:#e6d7c2; }
.library-loading,.library-empty,.library-error { padding:28px;border:1px dashed #84735f;background:#2c2a27;text-align:center; }
.library-heading h1,.reading-header h1 { margin:7px 0; }

/* Catalog */
.book-grid { display:grid;grid-template-columns:repeat(auto-fill,minmax(190px,1fr));gap:24px;margin-top:30px; }
.book-card { display:flex;flex-direction:column;justify-self:center;width:100%;max-width:328px;min-width:0;padding:12px;border:2px solid #6e604e;background:#2d2b27;box-shadow:5px 5px 0 #1d1c1a;text-decoration:none;transition:transform .15s ease,border-color .15s ease; }
.book-card:hover,.book-card:focus-visible { border-color:#b79b70;transform:translate(-2px,-2px); }
.book-cover-card,.cover-placeholder-card { width:100%;aspect-ratio:2/3;border:1px solid #7d6d59; }
.book-cover-card { display:block;object-fit:contain;image-rendering:auto; }
.cover-placeholder { display:grid;place-items:center;align-content:center;overflow:hidden;padding:12px;background:repeating-linear-gradient(135deg,#302d29 0 10px,#35312c 10px 20px);color:#bca783;text-align:center; }
.cover-placeholder>span { font:42px Georgia,serif; }
.book-card-copy { display:grid;gap:7px;padding:13px 3px 4px; }
.book-card-copy>span,.book-card small { color:#b7a995; }
.book-progress { height:7px;overflow:hidden;border:1px solid #736552;background:#1f1e1c; }
.book-progress span { display:block;height:100%;background:#9aab80; }

/* Reading page */
.book-view { --reader-safe:clamp(12px,2.5vw,34px);min-width:0; }
.reading-header { position:relative;padding:2px 0 16px;border-bottom:1px solid #655848; }
.reading-header h1 { max-width:1050px;font-size:clamp(25px,3.5vw,42px);line-height:1.15; }
.reading-header .eyebrow { margin:0;color:#9caf86; }
.mode-switch { display:flex;flex-wrap:wrap;position:absolute;right:0;bottom:14px; }
.library select,.library input,.library button,.mini-player button,.library-floating-controls button { accent-color:#9aab80;font:inherit; }
.library select,.library button { min-height:36px;border:1px solid #7e705f;background:#34312d;color:#f1e5d0; }
.library select { padding:6px 30px 6px 9px; }
.library button { padding:6px 11px;cursor:pointer; }
.library button:disabled { cursor:not-allowed;opacity:.42; }
.mode-switch button+button { border-left:0; }
.mode-switch button.active { background:#657052;color:#fff; }

.chapter-nav { display:grid;grid-template-columns:minmax(92px,1fr) auto minmax(92px,1fr);align-items:start;gap:12px;margin:18px 0; }
.chapter-nav>a,.chapter-nav-disabled,.chapter-toc>summary { display:flex;align-items:center;justify-content:center;min-height:38px;padding:7px 12px;border:1px solid #716451;background:#302e2a;color:#e8dbc4;text-decoration:none; }
.chapter-nav>:first-child { justify-self:start;width:max-content;max-width:100%; }
.chapter-nav>:nth-child(2) { justify-self:center; }
.chapter-nav>:last-child { justify-self:end;width:max-content;max-width:100%; }
.chapter-nav-disabled { opacity:.38; }
.chapter-toc { position:relative;z-index:8; }
.chapter-toc>summary { list-style:none;cursor:pointer; }
.chapter-toc>summary::-webkit-details-marker { display:none; }
.chapter-toc>div { position:absolute;left:50%;width:min(520px,85vw);max-height:50vh;overflow:auto;transform:translateX(-50%);border:1px solid #83725c;background:#292826;box-shadow:5px 5px 0 #171614; }
.chapter-toc a { display:block;padding:11px 14px;text-decoration:none;border-bottom:1px solid #4d463d; }
.chapter-toc a:hover,.chapter-toc a[aria-current=page] { background:#4b4d3d;color:#fff; }
.chapter-title { max-width:1100px;margin:26px auto 18px;font-size:clamp(24px,3.1vw,38px);line-height:1.25;text-align:center; }

.book-content { display:grid;grid-template-columns:minmax(0,1fr);gap:22px; }
.book-content.mode-audio .reader-panel,.book-content.mode-text .audio-panel { display:none; }
.audio-panel { width:min(100%,1120px);margin-inline:auto;padding:16px clamp(14px,2.5vw,28px);border-block:2px solid #6e604e;background:#302d29; }
.audio-primary { display:grid;grid-template-columns:minmax(240px,360px) minmax(280px,1fr);gap:22px;align-items:center; }
.transport { display:grid;grid-template-columns:46px minmax(140px,1fr) 46px;gap:9px; }
.transport button { min-width:0; }
.seek-row { display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:9px;align-items:center;font-size:13px; }
.seek-row input { min-width:0;width:100%; }
.audio-meta { display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:10px 18px;margin-top:11px;font-size:13px; }
.audio-source-note,.source-status { color:#d3b98f; }
.source-status:empty { display:none; }
.audio-more { position:relative; }
.audio-more>summary { cursor:pointer;color:#c9d9b3; }
.audio-settings { display:grid;grid-template-columns:repeat(3,minmax(140px,1fr));gap:14px;margin-top:12px;padding:14px;border:1px solid #625746;background:#282623; }
.audio-settings label,.reader-settings label,.audio-source-select { display:grid;gap:6px;font-size:12px;color:#cabb9f; }
.audio-settings input { width:100%; }
.audio-settings .autoplay-toggle { display:flex;grid-column:1/-1;flex-direction:row;align-items:center;gap:9px;min-height:38px;cursor:pointer; }
.audio-settings .autoplay-toggle input { width:20px;height:20px;flex:0 0 auto; }

.reader-panel { width:100%;margin-inline:auto;padding:0 var(--reader-safe) 10px;font-family:Georgia,"Times New Roman",serif;transition:max-width .15s ease; }
.reader-width-normal { max-width:900px; }
.reader-width-wide { max-width:1180px; }
.reader-width-max { max-width:none; }
.reader-dark { color:#e5dccd; }
.reader-light { padding-top:var(--reader-safe);padding-bottom:var(--reader-safe);background:#eee4d2;color:#29251f; }
.reader-tools { display:flex;justify-content:flex-end;min-height:42px;margin-bottom:12px;font-family:Consolas,"Courier New",monospace; }
.reader-tools>button { align-self:start; }
.reader-settings { display:flex;flex-wrap:wrap;justify-content:flex-end;align-items:end;gap:10px;width:100%;margin-top:9px;padding:12px;border-block:1px solid currentColor; }
.reader-settings[hidden] { display:none; }
.reader-dark .reader-settings label { color:#d1c6b5; }
.reader-light .reader-settings label { color:#514a40; }
.reader-content { width:100%;min-width:0;padding:0;overflow:visible;overflow-wrap:anywhere; }
.reader-content h2,.reader-content h3,.reader-content h4 { margin:1.6em 0 1em;text-align:center; }
.reader-content p { margin:1em 0; }
.reader-content .chapter-author-comment { margin:1.5em 0;padding:1em 1.15em;border-inline-start:4px solid #9aab80;background:rgba(154,171,128,.1);font-size:.94em;font-style:italic;overflow-wrap:anywhere; }
.reader-content .chapter-author-comment:first-child { margin-top:.25em; }
.reader-content .chapter-author-comment:last-child { margin-bottom:.25em; }
.reader-content .chapter-author-comment>:first-child { margin-top:0; }
.reader-content .chapter-author-comment>:last-child { margin-bottom:0; }
.reader-loading,.reader-error { font-style:italic;opacity:.8; }
.chapter-nav-bottom { margin-top:34px;padding-top:18px;border-top:1px solid #655848; }
.book-view[data-mode=audio] .chapter-nav-bottom { margin-top:20px; }

/* Persistent player and floating controls */
.mini-player { position:fixed;z-index:20;right:calc(72px + env(safe-area-inset-right));bottom:calc(14px + env(safe-area-inset-bottom));display:grid;grid-template-columns:minmax(130px,1fr) auto auto auto auto auto;gap:8px;align-items:center;width:min(680px,calc(100% - 100px));padding:10px;border:2px solid #8b7961;background:#292929f5;color:#eee0ca;box-shadow:6px 6px 0 #171614;font:13px Consolas,"Courier New",monospace; }
.mini-player[hidden] { display:none; }
.mini-player-meta { display:grid;min-width:0; }
.mini-player-meta strong,.mini-player-meta span { overflow:hidden;text-overflow:ellipsis;white-space:nowrap; }
.mini-player-meta span { color:#b8aa95; }
.mini-player button { width:34px;height:34px;border:1px solid #766957;background:#383530;color:#fff;cursor:pointer; }
.mini-player a { color:#c4d7aa;white-space:nowrap; }
.mini-time { white-space:nowrap; }
.library-floating-controls { position:fixed;z-index:22;right:calc(14px + env(safe-area-inset-right));bottom:calc(14px + env(safe-area-inset-bottom));display:flex;flex-direction:column;gap:9px; }
.library-floating-controls[hidden],.library-floating-controls button[hidden] { display:none; }
.library-floating-controls button { width:48px;height:48px;padding:0;border:2px solid #9b876b;background:#3a3732;color:#fff;font-size:24px;box-shadow:4px 4px 0 #171614;cursor:pointer; }

@media(max-width:900px){
  .reading-header { padding-bottom:12px; }
  .mode-switch { position:static;margin-top:12px; }
  .audio-primary { grid-template-columns:1fr;gap:12px; }
  .audio-settings { grid-template-columns:repeat(auto-fit,minmax(135px,1fr)); }
  .mini-player { grid-template-columns:minmax(0,1fr) auto auto;width:calc(100% - 94px); }
  .mini-time,.mini-player #mini-prev,.mini-player #mini-next { display:none; }
}

@media(max-width:560px){
  .reading-header h1 { font-size:24px; }
  .mode-switch { display:grid;grid-template-columns:repeat(3,1fr); }
  .mode-switch button { min-width:0;padding-inline:7px;font-size:12px; }
  .chapter-nav { grid-template-columns:1fr 1.15fr 1fr;gap:5px; }
  .chapter-nav>a,.chapter-nav-disabled,.chapter-toc>summary { min-height:42px;padding:6px 5px;font-size:12px; }
  .chapter-title { margin-block:21px 15px;text-align:left; }
  .audio-panel { padding:13px 8px; }
  .transport { grid-template-columns:44px minmax(0,1fr) 44px;gap:7px; }
  .seek-row { gap:5px; }
  .audio-meta { justify-content:space-between; }
  .audio-settings { grid-template-columns:1fr; }
  .reader-panel { padding-inline:4px; }
  .reader-light { padding-inline:10px; }
  .reader-tools { margin-bottom:8px; }
  .reader-tools>button { width:100%; }
  .reader-settings { display:grid;justify-content:stretch; }
  .reader-settings[hidden] { display:none; }
  .reader-content { font-size:min(var(--reader-size,18px),22px); }
  .mini-player { right:calc(62px + env(safe-area-inset-right));bottom:calc(7px + env(safe-area-inset-bottom));width:calc(100% - 72px);padding:7px; }
  .mini-player #mini-open { display:none; }
  .library-floating-controls { right:calc(7px + env(safe-area-inset-right));bottom:calc(7px + env(safe-area-inset-bottom)); }
  .library-floating-controls button { width:46px;height:46px; }
}

@media(prefers-reduced-motion:reduce){.book-card{transition:none}.reader-panel{transition:none}*{scroll-behavior:auto!important}}
