/* ── fcc.cc/library styles ── */

*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0c0d0f;
  --panel: #111214;
  --panel2: #15171a;
  --text: #f5f6f7;
  --dim: #9aa3b2;
  --muted: #6b7280;
  --border: #2a2a2a;
  --line: #1e1e1e;
  --accent: #c7d2fe;
  --accent2: #e0e7ff;
  --good: #4ade80;
  --bad: #f87171;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --sans: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'Lilex', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --cover-ratio: 2 / 3;
}

html { background: var(--bg); color: var(--text); font-family: var(--sans); line-height: 1.5; -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body { min-height: 100dvh; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent2); }

/* ── Skip link ── */
.skip-link { position: absolute; left: -9999px; top: auto; z-index: 10000; padding: .5rem 1rem; background: var(--accent); color: var(--bg); border-radius: .3rem; }
.skip-link:focus { left: 1rem; top: 1rem; }

/* ── Layout ── */
.wrap { min-height: 100dvh; display: flex; flex-direction: column; }
.container { max-width: 1100px; margin: 0 auto; padding: 18px 18px 54px; width: 100%; flex: 1; }
.container--reader { max-width: 1440px; padding: 0; }
body.reader-active .fcc-ufab { left: auto; right: 1.5rem; }

/* ── Topbar ── */
.topbar { position: sticky; top: 0; z-index: 9000; background: linear-gradient(180deg, rgba(12,13,15,.97) 60%, rgba(12,13,15,.85)); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); padding: 0 18px; padding-top: env(safe-area-inset-top, 0px); }
.topbar-content { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 12px; height: 48px; }
.brand { font-family: var(--mono); font-weight: 700; font-size: 1.05rem; color: var(--text); letter-spacing: -.02em; white-space: nowrap; }
.brand:hover { color: var(--accent); }

/* ── Library Nav ── */
.lib-nav { border-bottom: 1px solid var(--line); padding: 0 18px; }
.lib-nav-inner { max-width: 1100px; margin: 0 auto; display: flex; gap: 4px; }
.lib-nav-link { display: inline-flex; align-items: center; padding: .55rem .9rem; font-size: .82rem; font-weight: 600; color: var(--dim); text-decoration: none; border-bottom: 2px solid transparent; transition: color .12s, border-color .12s; }
.lib-nav-link:hover { color: var(--text); }
.lib-nav-link--active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Footer ── */
.site-footer { border-top: 1px solid var(--line); padding: 24px 18px; text-align: center; font-size: .8rem; color: var(--muted); max-width: 1100px; margin: 0 auto; width: 100%; }
.site-footer a { color: var(--dim); }

/* ── Hero / Search ── */
.hero { text-align: center; padding: 48px 0 32px; }
.hero-title { font-family: var(--serif); font-size: clamp(1.6rem, 3vw, 2.4rem); font-weight: 700; margin-bottom: .35rem; letter-spacing: -.02em; }
.hero-sub { color: var(--dim); font-size: .95rem; max-width: 520px; margin: 0 auto 24px; }

.search-bar { display: flex; gap: 8px; max-width: 560px; margin: 0 auto; }
.search-input { flex: 1; background: var(--panel); border: 2px solid var(--border); border-radius: .35rem; padding: .65rem 1rem; font-size: .95rem; color: var(--text); font-family: var(--sans); outline: none; transition: border-color .15s; }
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--muted); }
.search-btn { background: var(--accent); color: var(--bg); border: none; border-radius: .35rem; padding: .65rem 1.2rem; font-size: .95rem; font-weight: 600; cursor: pointer; white-space: nowrap; font-family: var(--sans); }
.search-btn:hover { background: var(--accent2); }

/* ── Autocomplete ── */
.search-wrap { position: relative; max-width: 560px; margin: 0 auto; }
.autocomplete-list { display: none; position: absolute; top: 100%; left: 0; right: 0; background: var(--panel); border: 1.5px solid var(--border); border-radius: 0 0 .35rem .35rem; z-index: 100; max-height: 260px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.autocomplete-item { display: flex; justify-content: space-between; align-items: baseline; padding: .55rem 1rem; text-decoration: none; color: var(--text); font-size: .88rem; border-bottom: 1px solid var(--line); gap: 12px; }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--panel2); }
.autocomplete-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.autocomplete-author { font-size: .78rem; color: var(--dim); white-space: nowrap; flex-shrink: 0; }

/* ── Book of the Day ── */
.botd { background: var(--panel); border: 2px solid var(--border); border-radius: .5rem; padding: 1.5rem; display: flex; gap: 1.5rem; margin-bottom: 32px; }
.botd-cover { width: 120px; flex-shrink: 0; }
.botd-cover img { width: 100%; border-radius: .3rem; display: block; }
.botd-info { flex: 1; min-width: 0; }
.botd-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 600; margin-bottom: .4rem; }
.botd-title { font-family: var(--serif); font-size: 1.3rem; font-weight: 700; margin-bottom: .25rem; }
.botd-author { color: var(--dim); font-size: .9rem; margin-bottom: .5rem; }
.botd-desc { color: var(--dim); font-size: .85rem; line-height: 1.55; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ── Shelves ── */
.shelf { margin-bottom: 36px; }
.shelf-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.shelf-title { font-size: 1.1rem; font-weight: 700; }
.shelf-see-all { font-size: .8rem; color: var(--dim); white-space: nowrap; }
.shelf-see-all:hover { color: var(--accent); }
.shelf-scroll { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; }
.shelf-scroll::-webkit-scrollbar { height: 4px; }
.shelf-scroll::-webkit-scrollbar-track { background: transparent; }
.shelf-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.shelf-scroll > .book-card { flex: 0 0 150px; scroll-snap-align: start; }

/* ── Book Grid ── */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }

/* ── Book Card ── */
.book-card { display: block; text-decoration: none; color: var(--text); transition: transform .12s; }
.book-card:hover { transform: translateY(-3px); color: var(--text); }
.book-cover { position: relative; aspect-ratio: var(--cover-ratio); background: var(--panel2); border-radius: .35rem; overflow: hidden; border: 1px solid var(--line); }
.book-cover-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-cover-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 2rem; color: var(--muted); }
.book-badges { position: absolute; bottom: 6px; left: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.badge { font-size: .6rem; padding: 2px 6px; border-radius: .2rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; line-height: 1.3; }
.badge--audio { background: rgba(74, 222, 128, .2); color: #4ade80; }
.badge--read { background: rgba(251, 191, 36, .2); color: #fbbf24; }
.badge--borrow { background: rgba(96, 165, 250, .2); color: #60a5fa; }
.book-info { padding: 8px 2px 0; }
.book-title { font-size: .85rem; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-author { font-size: .75rem; color: var(--dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-meta { font-size: .7rem; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── List Card (search results) ── */
.list-card { display: flex; gap: 16px; padding: 14px; background: var(--panel); border: 1.5px solid var(--border); border-radius: .4rem; text-decoration: none; color: var(--text); transition: border-color .12s; }
.list-card:hover { border-color: var(--accent); color: var(--text); }
.list-card-cover { width: 72px; flex-shrink: 0; aspect-ratio: var(--cover-ratio); background: var(--panel2); border-radius: .25rem; overflow: hidden; }
.list-card-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.list-card-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.list-card-title { font-size: .95rem; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.list-card-author { font-size: .82rem; color: var(--dim); }
.list-card-meta { font-size: .75rem; color: var(--muted); }
.list-card-desc { font-size: .78rem; color: var(--dim); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
.list-card-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.search-results-list { display: flex; flex-direction: column; gap: 10px; }

/* ── Skeleton ── */
.book-card--skeleton { pointer-events: none; }
.skeleton-pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: .4; } 50% { opacity: .15; } }
.skeleton-line { height: .7rem; background: var(--panel2); border-radius: .2rem; margin-top: 6px; }

/* ── Source Badges ── */
.source-badge { font-size: .65rem; padding: 2px 7px; border-radius: .2rem; font-weight: 600; letter-spacing: .02em; }
.source-badge--gutenberg { background: rgba(251,191,36,.15); color: #fbbf24; }
.source-badge--openlibrary { background: rgba(96,165,250,.15); color: #60a5fa; }
.source-badge--librivox { background: rgba(74,222,128,.15); color: #4ade80; }

/* ── Filter Bar ── */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.filter-pill { background: var(--panel); border: 1.5px solid var(--border); border-radius: 1rem; padding: .4rem .9rem; font-size: .78rem; color: var(--dim); cursor: pointer; font-family: var(--sans); transition: all .12s; }
.filter-pill:hover { border-color: var(--accent); color: var(--text); }
.filter-pill--active { background: rgba(199,210,254,.12); border-color: var(--accent); color: var(--accent); }
.filter-group { display: flex; gap: 4px; }
.filter-label { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-right: 4px; align-self: center; }

/* ── Search Results ── */
.results-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 8px; }
.results-count { font-size: .85rem; color: var(--dim); }
.results-sources { display: flex; gap: 6px; font-size: .7rem; }
.source-dot { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); }
.source-dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--good); }
.source-dot--loading::before { background: var(--muted); animation: pulse 1s infinite; }
.source-dot--error::before { background: var(--bad); }
.load-more-wrap { text-align: center; padding: 24px 0; }
.load-more-btn { background: var(--panel); border: 2px solid var(--border); border-radius: .35rem; padding: .7rem 2rem; font-size: .85rem; color: var(--dim); cursor: pointer; font-family: var(--sans); }
.load-more-btn:hover { border-color: var(--accent); color: var(--text); }

/* ── Detail Page ── */
.detail { display: grid; grid-template-columns: 220px 1fr; gap: 32px; margin-top: 12px; align-items: start; }
.detail-cover { width: 100%; }
.detail-cover img { width: 100%; border-radius: .4rem; display: block; border: 1px solid var(--line); }
.detail-meta { min-width: 0; }
.detail-title { font-family: var(--serif); font-size: clamp(1.3rem, 2.5vw, 1.8rem); font-weight: 700; line-height: 1.25; margin-bottom: .3rem; }
.detail-author { font-size: 1rem; color: var(--dim); margin-bottom: .5rem; }
.detail-author a { color: var(--accent); }
.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 1rem; }
.detail-tag { font-size: .7rem; padding: 3px 8px; border-radius: .2rem; background: var(--panel2); color: var(--dim); border: 1px solid var(--line); }
.detail-desc { color: var(--dim); font-size: .9rem; line-height: 1.65; margin-bottom: 1.5rem; }
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 1.5rem; }
.detail-btn { display: inline-flex; align-items: center; gap: 6px; padding: .6rem 1.1rem; border-radius: .35rem; font-size: .85rem; font-weight: 600; border: 2px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer; font-family: var(--sans); transition: all .12s; text-decoration: none; }
.detail-btn:hover { border-color: var(--accent); color: var(--accent); }
.detail-btn--primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.detail-btn--primary:hover { background: var(--accent2); border-color: var(--accent2); color: var(--bg); }

/* ── Formats Section ── */
.formats-section { margin-bottom: 1.5rem; }
.formats-section h3 { font-size: .9rem; font-weight: 600; margin-bottom: 10px; }
.format-card { background: var(--panel); border: 1.5px solid var(--border); border-radius: .4rem; padding: 1rem 1.25rem; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.format-info { min-width: 0; }
.format-label { font-weight: 600; font-size: .88rem; display: flex; align-items: center; gap: 6px; }
.format-detail { font-size: .78rem; color: var(--dim); margin-top: 2px; }
.format-action { flex-shrink: 0; }

/* ── Chapters ── */
.chapters { margin-bottom: 1.5rem; }
.chapters h3 { font-size: .9rem; font-weight: 600; margin-bottom: 10px; }
.chapter-list { list-style: none; }
.chapter-item { display: flex; justify-content: space-between; align-items: baseline; padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .85rem; }
.chapter-item:last-child { border-bottom: none; }
.chapter-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-dur { color: var(--dim); font-size: .78rem; font-family: var(--mono); flex-shrink: 0; margin-left: 12px; }

/* ── Related ── */
.related { margin-top: 2rem; }

/* ── Reader Layout (Three-Column Grid) ── */
.reader-layout { display: grid; grid-template-columns: var(--sidebar-left-w, 0px) 1fr var(--sidebar-right-w, 0px); grid-template-rows: auto 1fr; min-height: calc(100dvh - 100px); }
.reader-layout.left-open { --sidebar-left-w: 260px; }
.reader-layout.right-open { --sidebar-right-w: 280px; }
.reader-layout .reading-toolbar--sticky { grid-column: 1 / -1; grid-row: 1; }
.reader-center { grid-column: 2; grid-row: 2; min-width: 0; }

/* ── Sidebars ── */
.reader-sidebar { position: sticky; top: calc(48px + 45px); height: calc(100dvh - 48px - 45px); overflow-y: auto; overflow-x: hidden; background: var(--panel); transition: width 0.2s ease, opacity 0.15s ease; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.reader-sidebar--left { border-right: 1px solid var(--line); grid-column: 1; grid-row: 2; }
.reader-sidebar--right { border-left: 1px solid var(--line); grid-column: 3; grid-row: 2; }
.reader-layout:not(.left-open) .reader-sidebar--left,
.reader-layout:not(.right-open) .reader-sidebar--right { width: 0; overflow: hidden; opacity: 0; pointer-events: none; }
.reader-sidebar-inner { width: 260px; padding: 12px 14px; }
.reader-sidebar--right .reader-sidebar-inner { width: 280px; }

/* Sidebar sections */
.sidebar-section { margin-bottom: 18px; }
.sidebar-section-title { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }

/* Sidebar toggle buttons */
.sidebar-toggle { height: 32px; width: 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: .45rem; border: 1px solid var(--border); background: rgba(255,255,255,.04); color: var(--dim); font-size: .85rem; cursor: pointer; transition: background .15s, border-color .15s, color .15s; }
.sidebar-toggle:hover { background: rgba(255,255,255,.08); color: var(--text); }
.sidebar-toggle.active { background: linear-gradient(180deg, rgba(199,210,254,.18), rgba(199,210,254,.06)); border-color: rgba(199,210,254,.4); color: var(--accent); }

/* TOC */
.toc-list { list-style: none; max-height: 300px; overflow-y: auto; }
.toc-item { display: block; padding: .3rem .5rem; font-size: .78rem; color: var(--dim); cursor: pointer; border-radius: .25rem; transition: background .1s, color .1s; text-decoration: none; line-height: 1.35; }
.toc-item:hover { background: var(--panel2); color: var(--text); }
.toc-item.active { color: var(--accent); background: rgba(199,210,254,.08); }
.toc-item--h2 { padding-left: 1rem; }
.toc-item--h3 { padding-left: 1.8rem; font-size: .72rem; }
.toc-item--h4 { padding-left: 2.4rem; font-size: .7rem; }

/* Bookmarks */
.bookmark-list { }
.bookmark-item { display: flex; align-items: center; justify-content: space-between; padding: .3rem 0; font-size: .78rem; border-bottom: 1px solid var(--line); }
.bookmark-item:last-child { border-bottom: none; }
.bookmark-link { color: var(--dim); cursor: pointer; text-decoration: none; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookmark-link:hover { color: var(--accent); }

/* Dictionary */
.dict-panel { background: var(--panel2); border: 1px solid var(--border); border-radius: .35rem; padding: .7rem; }
.dict-word { font-family: var(--serif); font-size: .95rem; font-weight: 700; margin-bottom: 3px; }
.dict-phonetic { font-size: .75rem; color: var(--dim); font-style: italic; margin-bottom: 6px; }
.dict-def { font-size: .78rem; color: var(--text); line-height: 1.45; margin-bottom: 4px; }
.dict-pos { font-size: .65rem; color: var(--accent); font-weight: 600; text-transform: uppercase; margin-bottom: 2px; margin-top: 6px; }

/* Shout compose */
.shout-textarea { width: 100%; min-height: 56px; background: var(--panel2); border: 1.5px solid var(--border); border-radius: .35rem; padding: .45rem .55rem; font-size: .8rem; color: var(--text); font-family: var(--sans); resize: vertical; }
.shout-textarea:focus { border-color: var(--accent); outline: none; }
.shout-send { padding: .35rem .7rem; font-size: .75rem; font-weight: 600; background: var(--accent); color: var(--bg); border: none; border-radius: .3rem; cursor: pointer; font-family: var(--sans); }
.shout-send:hover { background: var(--accent2); }

/* Shout feed */
.shout-item { padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .78rem; }
.shout-item:last-child { border-bottom: none; }
.shout-author { font-weight: 600; font-size: .72rem; color: var(--accent); margin-bottom: 2px; }
.shout-body { color: var(--dim); line-height: 1.4; }
.shout-time { font-size: .65rem; color: var(--muted); margin-top: 3px; }

/* Share buttons */
.share-row { display: flex; gap: 6px; flex-wrap: wrap; }
.share-btn { flex: 1; min-width: 0; padding: .35rem .4rem; font-size: .7rem; font-weight: 600; text-align: center; border: 1.5px solid var(--border); border-radius: .3rem; background: var(--panel); color: var(--dim); cursor: pointer; transition: border-color .1s, color .1s; font-family: var(--sans); }
.share-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Backdrop for mobile drawers */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 199; }
.sidebar-backdrop.visible { display: block; }

/* ── Comments Slide-Out Panel ── */
.comments-panel { position: fixed; top: 0; right: 0; width: min(420px, 90vw); height: 100dvh; background: var(--panel); border-left: 1px solid var(--border); z-index: 9500; display: flex; flex-direction: column; transform: translateX(100%); transition: transform .25s ease; box-shadow: -4px 0 24px rgba(0,0,0,.5); }
.comments-panel.open { transform: translateX(0); }
.comments-panel-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 9499; opacity: 0; transition: opacity .25s; pointer-events: none; }
.comments-panel-backdrop.visible { opacity: 1; pointer-events: all; }
.comments-panel-header { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.comments-panel-title { font-size: .9rem; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comments-panel-close { background: none; border: none; color: var(--dim); font-size: 1.3rem; cursor: pointer; padding: 4px 8px; line-height: 1; }
.comments-panel-close:hover { color: var(--text); }
.comments-panel-compose { padding: .8rem 1rem; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.comments-panel-feed { flex: 1; overflow-y: auto; padding: .5rem 1rem; }
.comment-card { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.comment-card:last-child { border-bottom: none; }
.comment-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.comment-author { font-size: .78rem; font-weight: 600; color: var(--accent); text-decoration: none; }
.comment-author:hover { text-decoration: underline; }
.comment-time { font-size: .68rem; color: var(--muted); }
.comment-body { font-size: .85rem; color: var(--text); line-height: 1.5; }
.comment-body a { color: var(--accent); }
.comment-actions { margin-top: 4px; }

/* ── Reader (Stories-style book page) ── */
.reader-page { max-width: 800px; margin: 0 auto; padding: 12px 0 64px; }
.reader-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.reader-back { font-size: .85rem; color: var(--dim); display: inline-flex; align-items: center; gap: 4px; text-decoration: none; }
.reader-back:hover { color: var(--accent); }
.reader-book-title { font-family: var(--serif); font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; }
.reader-meta { font-size: .78rem; color: var(--muted); margin-bottom: 16px; display: flex; gap: 12px; flex-wrap: wrap; }
.reader-progress { position: fixed; top: 0; left: 0; height: 3px; background: var(--accent); z-index: 9999; transition: width .15s; pointer-events: none; }

/* Book page container */
.book-page-wrapper { display: flex; justify-content: center; margin-bottom: 16px; }
.book-page { width: 100%; max-width: 38em; min-height: 500px; background: #faf8f5; color: #1a1a1a; border-radius: 4px; box-shadow: 0 2px 24px rgba(0,0,0,.35), 0 0 0 1px rgba(255,255,255,.04); transition: background .3s, color .3s; }
.book-page.dark-page { background: #1a1a2e; color: #d4d4d8; }
.book-page-preview { padding: 3rem 2.5rem; font-family: var(--serif); font-size: 18px; line-height: 1.85; color: inherit; min-height: 500px; }
.book-page-preview h1 { font-size: 1.6em; margin: 1.2em 0 .5em; }
.book-page-preview h2 { font-size: 1.3em; margin: 1.2em 0 .5em; }
.book-page-preview h3 { font-size: 1.1em; margin: 1.2em 0 .5em; }
.book-page-preview p { margin: 0 0 1em; text-align: justify; hyphens: auto; }
.book-page-preview blockquote { border-left: 3px solid rgba(0,0,0,.2); padding-left: 1.2em; margin: 1em 0; font-style: italic; opacity: .85; }
.book-page.dark-page .book-page-preview blockquote { border-left-color: rgba(255,255,255,.2); }
.book-page-preview code { font-family: var(--mono); font-size: .88em; background: rgba(0,0,0,.06); padding: .15em .35em; border-radius: 3px; }
.book-page.dark-page .book-page-preview code { background: rgba(255,255,255,.08); }
.book-page-preview ul, .book-page-preview ol { padding-left: 1.5em; margin: .5em 0 1em; }
.book-page-preview img { max-width: 100%; height: auto; border-radius: 4px; }
.book-page-preview a { color: #4f46e5; }
.book-page.dark-page .book-page-preview a { color: #a5b4fc; }
.book-anchor-link { text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px; cursor: pointer; }

/* Soundtrack / audiobook companion player */
.soundtrack-player { display: flex; align-items: center; gap: .6rem; padding: .6rem 1rem; margin-bottom: 1rem; background: linear-gradient(180deg, rgba(199,210,254,.08), rgba(199,210,254,.03)); border: 1px solid rgba(199,210,254,.15); border-radius: .7rem; cursor: pointer; transition: border-color .2s, background .2s; max-width: 38em; margin-left: auto; margin-right: auto; text-decoration: none; color: var(--text); }
.soundtrack-player:hover { border-color: rgba(199,210,254,.3); background: linear-gradient(180deg, rgba(199,210,254,.12), rgba(199,210,254,.05)); color: var(--text); }
.soundtrack-player-icon { font-size: 1.1rem; flex-shrink: 0; }
.soundtrack-player-info { font-size: .85rem; color: var(--text); }
.soundtrack-player-label { font-size: .72rem; color: var(--dim); }

/* Typography toolbar */
.reading-toolbar { display: flex; align-items: center; justify-content: center; gap: .4rem; padding: .6rem 0; flex-wrap: wrap; max-width: 38em; margin: 0 auto; }
.reading-toolbar--sticky { position: sticky; top: 48px; z-index: 100; background: var(--bg); padding: .5rem 1rem; margin-bottom: 8px; border-bottom: 1px solid var(--line); border-radius: 0; max-width: none; backdrop-filter: blur(8px); }
.typo-btn { height: 32px; padding: 0 .6rem; display: inline-flex; align-items: center; justify-content: center; border-radius: .45rem; border: 1px solid var(--border); background: rgba(255,255,255,.04); color: var(--dim); font-size: .78rem; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s, color .15s; font-family: var(--sans); }
.typo-btn:hover { background: rgba(255,255,255,.08); color: var(--text); }
.typo-btn.active { background: linear-gradient(180deg, rgba(199,210,254,.18), rgba(199,210,254,.06)); border-color: rgba(199,210,254,.4); color: var(--accent); }
.typo-btn-dark { min-width: 80px; }
.typo-btn-dark.active { background: linear-gradient(180deg, rgba(100,80,180,.25), rgba(60,40,120,.15)); border-color: rgba(160,140,220,.4); color: #c4b5fd; }
.toolbar-divider { width: 1px; height: 18px; background: var(--border); margin: 0 .2rem; }

/* Reader navigation */
.reader-nav { display: flex; justify-content: center; gap: 12px; padding: 18px 0; max-width: 38em; margin: 0 auto; }
.reader-nav a, .reader-nav button { font-size: .85rem; }
.reader-bottom-meta { text-align: center; font-size: .78rem; color: var(--muted); padding: 8px 0; }
.stat-sep { margin: 0 6px; }

/* Fullscreen mode */
.fullscreen-container { background: var(--bg); min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 1rem; overflow-y: auto; }
.fullscreen-exit-btn { position: fixed; top: 1rem; right: 1rem; z-index: 10003; height: 32px; padding: 0 .7rem; display: flex; align-items: center; gap: .3rem; border-radius: .45rem; background: rgba(0,0,0,.6); border: 1px solid rgba(255,255,255,.15); color: var(--dim); font-size: .78rem; font-weight: 600; cursor: pointer; backdrop-filter: blur(8px); transition: opacity .3s; opacity: .3; }
.fullscreen-exit-btn:hover { opacity: 1; }

/* ── Selection Popup ── */
.selection-popup { display: flex; gap: 2px; background: var(--panel); border: 1.5px solid var(--border); border-radius: .4rem; box-shadow: 0 4px 16px rgba(0,0,0,.5); padding: 4px; }
.sel-btn { background: none; border: none; color: var(--dim); font-size: .75rem; font-weight: 600; padding: .4rem .6rem; cursor: pointer; border-radius: .3rem; font-family: var(--sans); white-space: nowrap; }
.sel-btn:hover { background: var(--panel2); color: var(--text); }

/* ── Highlights Panel ── */
.highlights-panel { max-width: 38em; margin: 24px auto 0; padding: 0; }
.highlight-item { background: var(--panel2); border: 1px solid var(--border); border-radius: .3rem; padding: .6rem .7rem; margin-bottom: 6px; position: relative; }
.highlight-text { font-family: var(--serif); font-size: .75rem; color: var(--dim); line-height: 1.4; font-style: italic; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.highlight-note { font-size: .7rem; color: var(--accent); margin-top: 4px; }
.highlight-remove { position: absolute; top: 4px; right: 6px; background: none; border: none; color: var(--muted); font-size: .8rem; cursor: pointer; padding: 2px 4px; }
.highlight-remove:hover { color: var(--bad); }

/* ── My Library ── */
.my-lib-shelf { margin-bottom: 2rem; }
.my-lib-shelf-title { font-size: 1rem; font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.my-lib-shelf-count { font-size: .75rem; color: var(--muted); font-weight: 400; }
.my-lib-empty { color: var(--muted); font-size: .85rem; padding: 12px 0; }
.progress-bar { height: 3px; background: var(--line); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width .2s; }

/* ── Reading Stats ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 2rem; }
.stat-card { background: var(--panel); border: 1.5px solid var(--border); border-radius: .4rem; padding: 1rem; text-align: center; }
.stat-value { font-size: 1.5rem; font-weight: 700; font-family: var(--mono); }
.stat-label { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }

/* ── Streak ── */
.streak-badge { display: inline-flex; align-items: center; gap: 4px; font-size: .8rem; font-weight: 600; color: #fb923c; }

/* ── Heatmap ── */
.heatmap-section { margin-bottom: 24px; }
.heatmap-grid { display: grid; grid-template-columns: repeat(30, 1fr); gap: 3px; }
.heatmap-cell { aspect-ratio: 1; background: var(--panel2); border-radius: 2px; border: 1px solid var(--line); }
.heatmap-cell--active { background: var(--accent); border-color: var(--accent); }

/* ── Categories Grid ── */
.categories { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 32px; }
.cat-card { background: var(--panel); border: 1.5px solid var(--border); border-radius: .35rem; padding: .8rem 1rem; text-align: center; font-size: .85rem; font-weight: 600; color: var(--dim); text-decoration: none; transition: all .12s; }
.cat-card:hover { border-color: var(--accent); color: var(--accent); }

/* ── Collection Cards ── */
.collection-card { background: var(--panel); border: 1.5px solid var(--border); border-radius: .4rem; padding: 1rem 1.2rem; text-decoration: none; color: var(--text); transition: border-color .12s; display: block; }
.collection-card:hover { border-color: var(--accent); color: var(--text); }
.collection-card-title { font-size: .95rem; font-weight: 700; margin-bottom: 4px; }
.collection-card-desc { font-size: .78rem; color: var(--dim); line-height: 1.4; margin-bottom: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.collection-card-count { font-size: .7rem; color: var(--muted); }

/* ── Empty / Error ── */
.empty-state, .error-state { text-align: center; padding: 48px 18px; color: var(--muted); }
.empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.error-state { color: var(--bad); }

/* ── Author Page ── */
.author-header { display: flex; gap: 24px; margin-bottom: 24px; }
.author-photo { width: 100px; height: 100px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border); flex-shrink: 0; }
.author-bio { color: var(--dim); font-size: .9rem; line-height: 1.6; }

/* ── Loading spinner ── */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ── */
@media (max-width: 900px) {
  .detail { grid-template-columns: 160px 1fr; gap: 20px; }
}

@media (max-width: 640px) {
  .container { padding: 12px 12px 40px; }
  .hero { padding: 32px 0 20px; }
  .search-bar { flex-direction: column; }
  .detail { grid-template-columns: 1fr; }
  .detail-cover { max-width: 200px; margin: 0 auto; }
  .botd { flex-direction: column; }
  .botd-cover { width: 100%; max-width: 160px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
  .shelf-scroll > .book-card { flex: 0 0 120px; }
  .format-card { flex-direction: column; align-items: stretch; }
  .author-header { flex-direction: column; align-items: center; text-align: center; }
  /* Reader mobile */
  .book-page-preview { padding: 2rem 1.5rem; font-size: 16px; }
  .list-card { gap: 12px; padding: 10px; }
  .list-card-cover { width: 56px; }
  /* Sidebar drawers on mobile */
  .reader-layout { grid-template-columns: 1fr !important; }
  .reader-layout.left-open, .reader-layout.right-open { --sidebar-left-w: 0px; --sidebar-right-w: 0px; }
  .reader-sidebar { position: fixed; top: 0; height: 100dvh; z-index: 8000; width: 280px !important; opacity: 1 !important; pointer-events: auto !important; overflow-y: auto !important; transform: translateX(-100%); transition: transform 0.25s ease; box-shadow: 4px 0 24px rgba(0,0,0,.5); }
  .reader-sidebar--right { right: 0; left: auto; transform: translateX(100%); box-shadow: -4px 0 24px rgba(0,0,0,.5); }
  .reader-sidebar--left.drawer-open { transform: translateX(0); }
  .reader-sidebar--right.drawer-open { transform: translateX(0); }
  .reader-center { grid-column: 1; }
}
