/* Trang đọc EPUB. Màu dùng lại token trong ../style.css */
:root { --read-size: 19px; }
body { background: var(--bg); }
.r-top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.r-back { text-decoration: none; color: var(--muted); white-space: nowrap; font-size: 14px; }
.r-heading { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.r-heading strong { font: 700 16px/1.25 var(--serif); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-heading span { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-tools { display: flex; gap: 6px; flex: none; }
.r-btn { height: 36px; min-width: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: 13.5px; }

#view { max-width: 720px; margin: 0 auto; padding: 28px 20px 24px; }
/* .chapter: cỡ chữ và màu của web. Sách có CSS gốc thì CSS đó lo bố cục; .plain là sách không có CSS. */
#view .chapter { font-size: var(--read-size); line-height: 1.7; color: var(--text); }
.chapter {
  -webkit-user-select: none; user-select: none; overflow-wrap: break-word;
}
:root:not([data-font="original"]) #view .chapter { font-family: var(--read-font); }
:root[data-font="original"] .chapter.plain { font-family: "Literata", Georgia, serif; }
.chapter img { max-width: 100%; height: auto; -webkit-user-drag: none; }
.chapter a { color: var(--accent); }
.chapter table { max-width: 100%; display: block; overflow-x: auto; }
.chapter.plain p { margin: 0 0 1em; }
.chapter.plain h1, .chapter.plain h2, .chapter.plain h3, .chapter.plain h4 { font-family: var(--serif); color: var(--ink); line-height: 1.25; margin: 1.4em 0 .7em; }
.chapter.plain h1 { font-size: 1.6em; } .chapter.plain h2 { font-size: 1.35em; } .chapter.plain h3 { font-size: 1.15em; }
.chapter.plain img { margin: 1em auto; border-radius: 6px; }
.chapter.plain blockquote { margin: 1em 0; padding-left: 1em; border-left: 2px solid var(--line); color: var(--muted); }
.chapter.plain hr { border: 0; border-top: 1px solid var(--line); margin: 2em 25%; }
.chapter.plain td, .chapter.plain th { border: 1px solid var(--line); padding: 4px 8px; }

.r-nav { max-width: 720px; margin: 0 auto; padding: 8px 20px 48px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.r-nav span { color: var(--muted); font-size: 13px; white-space: nowrap; }
.r-nav .btn { height: 44px; padding: 0 14px; font-size: 14px; }
.r-nav .btn[disabled] { opacity: .35; cursor: default; }

/* Bảng Aa: cỡ chữ + font */
.r-btn.aa { font-family: var(--serif); font-size: 16px; font-weight: 600; }
.font-panel {
  position: fixed; top: 60px; right: 16px; z-index: 6; width: min(280px, calc(100vw - 32px)); padding: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.2);
  max-height: calc(100dvh - 80px); overflow-y: auto;
}
.size-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-bottom: 10px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.size-row .r-btn { width: 72px; height: 40px; background: var(--bg-soft); }
.size-row span#sizeLabel { font-size: 13px; color: var(--muted); }
.font-list { display: flex; flex-direction: column; gap: 2px; }
.font-list button {
  display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; min-height: 44px; border: 0; border-radius: 8px;
  background: none; cursor: pointer; font-size: 17px; text-align: left; color: var(--text);
}
.font-list button:hover { background: var(--bg-soft); }
.font-list button[aria-checked="true"] { background: var(--accent-soft); font-weight: 600; }
.font-list button[aria-checked="true"]::after { content: "✓"; color: var(--accent); font-family: var(--sans); }

.gate { text-align: center; padding: 48px 8px; }
.gate h1 { font: 700 26px/1.25 var(--serif); color: var(--ink); margin: 0 0 10px; }
.gate p { color: var(--muted); margin: 0 auto 18px; max-width: 46ch; }
.gate .btn { margin: 4px; }
.gate small { display: block; color: var(--muted); margin-top: 18px; font-size: 12.5px; }
.gate .link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 13px; }

/* ---------- danh sách truyện ---------- */
#view.wide { max-width: 1180px; }
.shelf-hero {
  position: relative; overflow: hidden; border-radius: 18px; padding: 34px 32px; margin-bottom: 18px;
  background: linear-gradient(120deg, #7a2230, #1d2433 75%); color: #fff;
}
.shelf-hero-bg {
  position: absolute; inset: -40px; background-size: cover; background-position: center;
  filter: blur(36px) saturate(1.3); transform: scale(1.1); opacity: .3; mix-blend-mode: luminosity;
}
.shelf-hero .btn.soft { background: #fff; color: #1d2433; border-color: transparent; }
.shelf-hero-text { position: relative; max-width: 62ch; }
.shelf-hero .eyebrow { color: #f6c445; }
.shelf-hero h1 { margin: 0 0 8px; font: 700 clamp(30px, 4.4vw, 46px)/1.1 var(--serif); color: #fff; }
.shelf-hero p { margin: 0 0 16px; color: rgba(255,255,255,.86); }
.shelf-hero p.eyebrow { margin-bottom: 8px; }
.who { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; color: #fff; font-size: 14.5px; }
.who b { font-weight: 600; }

.shelf-tools { display: flex; gap: 8px; margin-bottom: 18px; }
.shelf-tools .search { flex: 1; min-width: 0; }
.shelf-tools input, .shelf-tools select {
  height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); padding: 0 12px; font-size: 15px; outline: none;
}
.shelf-tools input { width: 100%; padding-left: 40px; font-size: 16px; }
.shelf-tools input:focus, .shelf-tools select:focus { border-color: var(--accent); }

.books { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.book {
  display: flex; gap: 18px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow); transition: transform .15s;
}
.book:hover { transform: translateY(-2px); }
/* chỉ có một truyện: thẻ giãn hết hàng, bìa to hơn */
.books:has(> .book:only-child) { grid-template-columns: 1fr; }
.book:only-child .book-cover { width: 190px; }
.book:only-child h2 { font-size: 28px; }
.book:only-child .book-blurb { font-size: 15.5px; -webkit-line-clamp: 6; max-width: 70ch; }
.book-cover { flex: none; width: 138px; align-self: flex-start; display: block; border-radius: 10px; overflow: hidden; background: var(--bg-soft); box-shadow: 0 8px 20px rgba(0,0,0,.25); }
.book-cover img { width: 100%; height: auto; }
.no-cover { display: flex; align-items: center; justify-content: center; min-height: 190px; padding: 12px; text-align: center; font: 600 15px/1.3 var(--serif); color: var(--ink); }
.book-body { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.book h2 { margin: 2px 0 0; font: 700 21px/1.22 var(--serif); }
.book h2 a { color: var(--ink); text-decoration: none; }
.book-meta { margin: 0; font-size: 13.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 7px; }
.book-meta b { font-weight: 500; color: var(--text); }
.book-meta i { font-style: normal; }
.book-blurb { margin: 4px 0 0; font-size: 14px; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.book-foot { margin-top: auto; padding-top: 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; width: 100%; }
.book-foot .btn { height: 40px; font-size: 14.5px; gap: 7px; }
.progress { flex: 1 1 60px; height: 6px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); }
.shelf-empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

.tier-badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 11px 3px 8px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; letter-spacing: .01em; color: #1d2433; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.tier-badge.silver { background: linear-gradient(135deg, #eef0f3, #c3c8d0); }
.tier-badge.gold { background: linear-gradient(135deg, #fbe39a, #e0b04a); color: #3a2800; }
.tier-badge.platinum { background: linear-gradient(135deg, #e2f2fb, #9ccfe9); color: #0d3247; }

@media (max-width: 860px) { .books { grid-template-columns: 1fr; } }
@media (max-width: 480px) {
  .shelf-hero { padding: 24px 20px; }
  .shelf-tools { flex-wrap: wrap; }
  .shelf-tools .search, .shelf-tools select { flex: 1 1 100%; width: 100%; }
  .book { gap: 12px; padding: 12px; }
  .book-cover, .book:only-child .book-cover { width: 104px; }
  .book:only-child h2 { font-size: 18px; }
  .book:only-child .book-blurb { font-size: 13.5px; -webkit-line-clamp: 3; }
  .book h2 { font-size: 18px; }
  .book-blurb { -webkit-line-clamp: 3; font-size: 13.5px; }
}

dialog#tocDialog { padding: 18px 20px; }
#tocDialog h3 { margin: 0 0 10px; font: 700 20px var(--serif); color: var(--ink); }
.toc { list-style: none; margin: 0; padding: 0; }
.toc button { display: block; width: 100%; text-align: left; padding: 9px 10px; background: none; border: 0; border-radius: 8px; cursor: pointer; font-size: 14.5px; line-height: 1.35; }
.toc button:hover { background: var(--bg-soft); }
.toc button.on { background: var(--accent-soft); font-weight: 600; }

@media (max-width: 560px) {
  .r-back span { display: none; }
  #view { padding: 20px 16px; }
  .r-btn { padding: 0 8px; }
  .r-nav .btn { padding: 0 10px; font-size: 13px; }
}
