/* 電子書閱讀器樣式 —— 沿用全站設計代幣，雙欄雜誌式版面 */
.reader {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  align-items: start;
}

/* 側邊目錄 */
.reader-toc {
  position: sticky; top: calc(var(--header-h) + 1rem);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; max-height: calc(100vh - var(--header-h) - 2rem);
  display: flex; flex-direction: column;
}
.toc-head { padding: 1.4rem 1.4rem 1rem; border-bottom: 1px solid var(--border); }
.toc-kicker { font-size: .72rem; font-weight: 700; letter-spacing: 3px; color: var(--accent); text-transform: uppercase; }
.toc-head h2 { font-size: 1.25rem; margin: .35rem 0 .3rem; }
.toc-sub { margin: 0; font-size: .82rem; color: var(--text-mute); }
.toc-list { overflow-y: auto; padding: .6rem; display: flex; flex-direction: column; gap: 2px; }
.toc-item {
  display: flex; align-items: baseline; gap: .7rem; padding: .6rem .75rem;
  border-radius: var(--radius-sm); color: var(--text-soft); font-size: .95rem; font-weight: 600;
}
.toc-item:hover { background: var(--bg-soft); color: var(--brand); }
.toc-num { font-size: .78rem; color: var(--text-mute); font-variant-numeric: tabular-nums; min-width: 1.6em; }

/* 閱讀中的章節：整個包覆亮藍、白字（反相），最顯眼 */
.reader-toc .toc-item.active {
  background: var(--brand); color: #fff; font-weight: 700;
  box-shadow: 0 4px 14px rgba(37, 99, 235, .45);
}
.reader-toc .toc-item.active .toc-num { color: rgba(255, 255, 255, .85); }
.reader-toc .toc-item.active .toc-dot { background: #fff; }

/* 分組小標（前置 / 附錄）*/
.toc-group {
  font-size: .7rem; font-weight: 800; letter-spacing: 2px; text-transform: uppercase;
  color: var(--accent); padding: .9rem .75rem .3rem; margin-top: .2rem;
}
/* 篇章分隔（Part）*/
.toc-item.toc-part { font-weight: 800; color: var(--text); margin-top: .3rem; }
.toc-item.toc-part .toc-dot { background: var(--accent); }
/* 前置 / 附錄 次要項 */
.toc-item.toc-front, .toc-item.toc-appendix { color: var(--text-mute); font-weight: 500; }
.toc-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-mute); flex: 0 0 auto; display: inline-block; }

/* 內容區 */
.reader-main { min-width: 0; }
.toc-fab { display: none; }

/* 工具列：語系切換、字級、日夜 —— 凍結在頁首下方，不隨長文捲走 */
.reader-bar {
  position: sticky; top: var(--header-h); z-index: 90;
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .7rem 0; margin-bottom: 1rem;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.reader-bar .lang-switch { display: inline-flex; background: var(--surface); border: 1px solid var(--border);
  border-radius: 100px; padding: 3px; box-shadow: var(--shadow); }
.reader-bar .lang-switch button {
  border: none; background: none; cursor: pointer; padding: .35rem .85rem; border-radius: 100px;
  font-weight: 700; font-size: .92rem; color: var(--text-soft); font-family: inherit;
}
.reader-bar .lang-switch button.active { background: var(--grad); color: #fff; }
.reader-tools { margin-left: auto; display: inline-flex; gap: .4rem; }
.reader-tools button {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--brand); cursor: pointer; font-weight: 700; font-size: .95rem; box-shadow: var(--shadow);
  display: grid; place-items: center; transition: background .18s, color .18s;
}
.reader-tools button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* 封面 */
.ebook-cover {
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-lg);
  background: linear-gradient(135deg, var(--brand-700), var(--brand) 55%, var(--brand-light));
  color: #fff; text-align: center; padding: 4rem 1.5rem;
}
.cover-inner { max-width: 560px; margin: 0 auto; }
.cover-img {
  display: block; max-width: 300px; width: 70%; margin: 0 auto 1.6rem; border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35);
}
/* 章節頂部封面圖（A4 直式，不裁切、置中）*/
.chapter-cover {
  display: block; width: auto; max-width: min(380px, 100%); height: auto;
  margin: 0 auto 2rem; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.cover-kicker { font-size: .78rem; letter-spacing: 3px; font-weight: 700; text-transform: uppercase; opacity: .85; }
.ebook-cover h1 { font-size: 2.6rem; font-weight: 800; margin: 1rem 0 .8rem; letter-spacing: 2px; }
.cover-sub { font-size: 1.1rem; opacity: .92; margin: 0 0 .6rem; }
.cover-author { font-size: .95rem; opacity: .8; margin: 0 0 2rem; }
.ebook-cover .btn-primary { background: #fff; color: var(--brand) !important; }
.ebook-cover .btn-primary:hover { background: var(--surface-2); }
@media (max-width: 600px) { .ebook-cover h1 { font-size: 2rem; } .ebook-cover { padding: 3rem 1.2rem; } }

.chapter {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 2.4rem 2.6rem;
  font-size: calc(1.08rem * var(--reader-fs, 1));
}
.chapter h1 { font-size: 1.9rem; margin: 0 0 1.2rem; padding-bottom: .6rem; border-bottom: 2px solid var(--border); }
.chapter h2 { font-size: 1.8rem; margin: 2rem 0 1.2rem; padding-bottom: .6rem; border-bottom: 2px solid var(--border); }
.chapter svg, .chapter img { max-width: 100%; height: auto; }

.ebook-download {
  max-width: var(--maxw); margin: 1.5rem auto -1rem; padding: 0 1.25rem;
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; color: var(--text-soft); font-weight: 600;
}
.chapter h3 { font-size: 1.3rem; margin: 2rem 0 .8rem; color: var(--text); }
.chapter p { margin: 0 0 1.1rem; }
.chapter ul, .chapter ol { padding-left: 1.4rem; margin: 0 0 1.1rem; }
.chapter li { margin-bottom: .4rem; }
.chapter img { border-radius: var(--radius-sm); margin: 1.4rem 0; box-shadow: var(--shadow); }
.chapter blockquote {
  margin: 1.4rem 0; padding: .7rem 1.2rem; border-left: 4px solid var(--accent);
  background: var(--bg-soft); border-radius: 0 8px 8px 0; color: var(--text-soft);
}
.chapter code { background: var(--surface-2); padding: .12rem .4rem; border-radius: 5px; font-size: .92em; }

/* 表格 */
.chapter .table-wrap { overflow-x: auto; margin: 1.4rem 0; -webkit-overflow-scrolling: touch; }
.chapter table { width: 100%; border-collapse: collapse; font-size: .95em; background: var(--surface); }
.chapter th, .chapter td { border: 1px solid var(--border); padding: .55rem .8rem; text-align: left; vertical-align: top; }
.chapter thead th { background: var(--bg-soft); color: var(--brand); font-weight: 700; white-space: nowrap; }
.chapter tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--bg-soft) 45%, transparent); }
.reader-loading { color: var(--text-mute); text-align: center; padding: 3rem 0; }

.chapter-nav { display: flex; justify-content: space-between; gap: 1rem; margin-top: 1.5rem; }
.chapter-nav .btn:disabled { opacity: .4; cursor: not-allowed; transform: none; box-shadow: none; }

/* 響應式：目錄變抽屜 */
.toc-toggle { display: none; }
.toc-overlay { display: none; }
@media (max-width: 820px) {
  .reader { grid-template-columns: 1fr; }
  /* 抽屜開啟時，點右側遮罩即可關閉目錄 */
  .toc-toggle:checked ~ .toc-overlay {
    display: block; position: fixed; inset: 0; z-index: 150;
    background: rgba(0, 0, 0, .45); -webkit-backdrop-filter: blur(1px); backdrop-filter: blur(1px);
  }
  .toc-fab {
    display: inline-flex; align-items: center; gap: .5rem; margin-bottom: 1rem;
    padding: .55rem 1.1rem; border-radius: 100px; cursor: pointer; font-weight: 700;
    background: var(--surface); border: 1px solid var(--border); color: var(--brand); box-shadow: var(--shadow);
  }
  .reader-toc {
    position: fixed; top: 0; left: 0; bottom: 0; width: 82%; max-width: 320px; z-index: 200;
    max-height: 100vh; border-radius: 0; transform: translateX(-105%); transition: transform .28s;
  }
  .toc-toggle:checked ~ .reader-toc { transform: translateX(0); }
  .chapter { padding: 1.6rem 1.4rem; }
}
