/* 書扉 共用樣式（首頁 index.html、作品頁 book.html、閱讀頁 novel.html、排行 rank.html）
   手機版頁首的展開／收合由 header.js 處理（novel.html 除外）
   創作後台 writer.html 另外載入 writer.css */

:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --ink: #141414;
  --muted: #5c5c58;
  --line: #e2e0da;
  --line-strong: #d4d1c9;
  --chip: #ecebe4;
  --chip-on: #ffffff;
  --active: rgba(20, 20, 20, 0.06);
  --accent: #c63f25;
  --radius: 8px;
  --font-sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-serif: "Noto Serif TC", "Songti TC", serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --max: 1240px;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body.is-ready {
  transition: background-color 0.3s ease, color 0.3s ease;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.container {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding-inline: 24px;
}

.mono {
  font-family: var(--font-mono);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 20;
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--bg);
  border-radius: 999px;
  text-decoration: none;
}

.skip-link:focus {
  top: 1rem;
}

.is-hidden,
[hidden] {
  display: none !important;
}

/* —— Header —— */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  transition: background-color 0.3s ease;
}

.header-inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 40px;
  padding-block: 12px;
}

.logo {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  min-height: 44px;
  padding-top: 8px;
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-decoration: none;
}

.logo-en {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 400;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 28px;
  font-size: 0.9375rem;
  font-weight: 500;
}

.nav a {
  padding: 10px 0;
  text-decoration: none;
  transition: color 0.2s ease;
}

.nav a:hover {
  color: var(--accent);
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

/* 手機版頁首的切換按鈕（header.js）；寬螢幕隱藏，選單容器不參與排版 */
.header-toggles {
  display: none;
}

.header-menu {
  display: contents;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.icon-btn:hover,
.icon-btn[aria-expanded="true"] {
  background: var(--active);
}

.menu-icon-close,
.is-menu-open .menu-icon-open {
  display: none;
}

.is-menu-open .menu-icon-close {
  display: inline;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 260px;
  max-width: 100%;
  height: 44px;
  padding: 0 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  transition: border-color 0.2s ease;
}

.search:focus-within {
  border-color: var(--ink);
}

.search input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
}

.search input:focus {
  outline: none;
}

.search input::placeholder {
  color: #76746e;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s var(--ease);
}

.btn:active {
  transform: translateY(1px);
}

.btn-lg {
  height: 52px;
  padding: 0 26px;
  font-size: 1rem;
}

.btn-outline {
  border-color: var(--ink);
}

.btn-outline:hover {
  background: var(--ink);
  color: var(--bg);
}

.btn-dark {
  background: var(--ink);
  color: var(--bg);
}

.btn-dark:hover {
  background: #2c2c2a;
}

.btn-soft {
  background: var(--chip);
}

.btn-soft:hover {
  background: var(--line);
}

.btn-light {
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
}

.btn-light:hover {
  background: var(--bg);
}

.text-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}

.text-link svg {
  transition: transform 0.2s var(--ease);
}

.text-link:hover svg {
  transform: translateX(3px);
}

/* —— Hero —— */
.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 56px 64px;
  padding-block: 72px 88px;
}

.hero-copy {
  flex: 1 1 480px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  animation: fade-up 0.7s var(--ease) both;
}

.eyebrow {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.75rem, 6.4vw, 5.25rem);
  font-weight: 900;
  line-height: 1.12;
  letter-spacing: -0.01em;
}

.hero h1 em {
  font-style: normal;
  color: var(--accent);
}

.lead {
  margin: 0;
  max-width: 28em;
  font-size: 1.125rem;
  line-height: 1.8;
  color: var(--muted);
}

.cta-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
}

/* —— Featured pick —— */
.pick {
  flex: 1 1 520px;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  animation: fade-up 0.8s var(--ease) 0.1s both;
}

.pick-cover {
  flex: 0 0 200px;
  display: block;
}

.pick-body {
  flex: 1 1 240px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pick-tags {
  margin: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.75rem;
  color: var(--muted);
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.pick h2 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 900;
  line-height: 1.3;
}

.pick-title-link {
  color: inherit;
  text-decoration: none;
}

.pick-title-link:hover {
  color: var(--accent);
}

.pick-author {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.pick-quote {
  margin: 4px 0 0;
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  line-height: 1.95;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pick .text-link {
  margin-top: auto;
}

/* —— Covers（幾何封面，依類型換圖形） —— */
.cover {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 4px;
  background: var(--cover, #1e2a3a);
  color: var(--cover-ink, #ffffff);
  box-shadow: 0 22px 36px -24px rgba(20, 20, 20, 0.6);
  container-type: inline-size;
}

.cover-art,
.cover-art::before,
.cover-art::after {
  position: absolute;
  content: "";
}

.cover-art {
  inset: 0;
}

.cover-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.6em;
  padding: 9cqi;
}

.cover-title {
  font-size: 10.5cqi;
  font-weight: 900;
  line-height: 1.22;
  text-wrap: balance;
}

.cover-author {
  font-size: 4.6cqi;
  opacity: 0.85;
}

/* 懸疑：雨線與一盞燈 */
.cover--lamp .cover-art {
  background: repeating-linear-gradient(105deg, rgba(255, 255, 255, 0.07) 0 1px, transparent 1px 5cqi);
}

.cover--lamp .cover-art::after {
  top: 18%;
  right: 16%;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #f2c14e;
}

/* 科幻：軌道 */
.cover--orbit .cover-art::before {
  top: -18%;
  left: -30%;
  width: 120%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid currentColor;
  opacity: 0.3;
}

.cover--orbit .cover-art::after {
  top: -6%;
  left: -14%;
  width: 88%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid currentColor;
  opacity: 0.3;
}

.cover--orbit .cover-art {
  background: radial-gradient(circle at 51% 26%, currentColor 0 2.4cqi, transparent 2.6cqi);
}

/* 武俠：石橋 */
.cover--arch .cover-art::before {
  left: -10%;
  right: -10%;
  top: 30%;
  aspect-ratio: 2 / 1;
  border: 5cqi solid currentColor;
  border-bottom: 0;
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  opacity: 0.8;
}

.cover--arch .cover-art::after {
  left: 0;
  right: 0;
  top: 30%;
  height: 5cqi;
  background: currentColor;
  opacity: 0.8;
}

/* 愛情：交疊的兩個圓 */
.cover--bloom .cover-art::before,
.cover--bloom .cover-art::after {
  top: 14%;
  width: 52%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.22;
}

.cover--bloom .cover-art::before {
  left: 14%;
}

.cover--bloom .cover-art::after {
  left: 36%;
}

/* 奇幻：山峰 */
.cover--peak .cover-art::before {
  left: 10%;
  right: 10%;
  top: 14%;
  height: 40%;
  background: currentColor;
  opacity: 0.25;
  clip-path: polygon(0 100%, 38% 20%, 55% 55%, 72% 0, 100% 100%);
}

/* 日常／其他：橫條 */
.cover--stripes .cover-art {
  background: repeating-linear-gradient(180deg, transparent 0 9cqi, rgba(255, 255, 255, 0.1) 9cqi 13cqi);
  mask-image: linear-gradient(180deg, #000 0 55%, transparent 55%);
}

/* 作者上傳封面：畫布已含底色與置中圖，直接鋪滿 */
.cover--photo {
  background: var(--cover, #ede4d6);
}

.cover-photo {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

/* —— Sections —— */
.section {
  padding-bottom: 104px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 16px 40px;
  margin-bottom: 24px;
}

.section-head h2 {
  margin: 0 0 6px;
  font-size: 2.25rem;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.section-head p {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--muted);
}

.result-count {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-bottom: 40px;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.view-toggle {
  flex-shrink: 0;
}

.filter {
  height: 40px;
  min-width: 44px;
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.filter:hover {
  border-color: var(--ink);
}

.filter.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.novel-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 56px 40px;
}

.novel-grid[data-view="list"] {
  grid-template-columns: 1fr;
  gap: 0;
}

.novel-grid > li {
  animation: fade-up 0.55s var(--ease) both;
}

.novel-grid.is-settled > li {
  animation: none;
}

.novel-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-decoration: none;
}

.novel-card .cover {
  transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease);
}

.novel-card:hover .cover {
  transform: translateY(-4px);
  box-shadow: 0 30px 44px -26px rgba(20, 20, 20, 0.65);
}

.novel-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.novel-meta {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.5em;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.novel-meta > span + span::before {
  content: "· ";
}

.novel-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.novel-author {
  display: none;
  font-size: 0.8125rem;
  color: var(--muted);
}

.novel-card:hover .novel-title {
  color: var(--accent);
}

.novel-synopsis {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  line-height: 1.85;
  color: var(--muted);
}

/* 列表模式：每本書一列，左側小封面、右側資訊 */
.novel-grid[data-view="list"] > li {
  border-bottom: 1px solid var(--line);
}

.novel-grid[data-view="list"] > li:last-child {
  border-bottom: 0;
}

.novel-grid[data-view="list"] .novel-card {
  flex-direction: row;
  align-items: center;
  gap: 16px;
  padding: 14px 12px;
  margin-inline: -12px;
  border-radius: var(--radius);
  transition: background-color 0.2s ease;
}

.novel-grid[data-view="list"] .novel-card:hover {
  background: var(--active);
}

.novel-grid[data-view="list"] .novel-card .cover {
  flex: 0 0 48px;
  width: 48px;
  box-shadow: 0 8px 16px -12px rgba(20, 20, 20, 0.5);
}

.novel-grid[data-view="list"] .novel-card:hover .cover {
  transform: none;
  box-shadow: 0 8px 16px -12px rgba(20, 20, 20, 0.5);
}

.novel-grid[data-view="list"] .cover-text {
  display: none;
}

.novel-grid[data-view="list"] .novel-body {
  flex: 1;
  min-width: 0;
  gap: 4px;
}

.novel-grid[data-view="list"] .novel-title {
  order: -2;
  font-size: 1rem;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.novel-grid[data-view="list"] .novel-author {
  display: block;
  order: -1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.novel-grid[data-view="list"] .novel-meta {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0 0.5em;
  font-size: 0.75rem;
  line-height: 1.4;
}

.novel-grid[data-view="list"] .novel-synopsis {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.875rem;
  line-height: 1.5;
}

.empty-state {
  margin: 0;
  padding: 1.5rem 0;
  color: var(--muted);
}

.empty-state a {
  color: var(--accent);
}

/* —— 延伸閱讀 —— */
.site-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.site-link {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  transition: border-color 0.2s ease;
}

.site-link:hover {
  border-color: var(--ink);
}

.site-link::after {
  content: "↗";
  position: absolute;
  top: 20px;
  right: 22px;
  font-size: 1rem;
}

.site-meta {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.site-name {
  font-size: 1.1875rem;
  font-weight: 700;
}

.site-desc {
  font-size: 0.875rem;
  color: var(--muted);
}

/* —— 寫作者入口 —— */
.writer-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 32px 56px;
  padding: 56px 48px;
  background: var(--accent);
  color: #ffffff;
  border-radius: var(--radius);
}

.writer-entry > div {
  flex: 1 1 420px;
  min-width: 0;
}

.writer-entry h2 {
  margin: 0 0 12px;
  font-size: clamp(1.875rem, 3.6vw, 2.75rem);
  font-weight: 900;
  line-height: 1.25;
}

.writer-entry p {
  margin: 0;
  max-width: 30em;
  font-size: 1.0625rem;
  line-height: 1.8;
}

/* —— Footer —— */
.site-footer {
  border-top: 1px solid var(--line);
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px 48px;
  padding-block: 40px 48px;
}

.footer-inner .logo {
  font-size: 1.25rem;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
  font-size: 0.875rem;
}

.footer-links a {
  padding: 10px 0;
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--accent);
}

.fine {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

/* —— 作品介紹頁 —— */
.book-layout {
  padding-block: 40px 120px;
}

.book-shell {
  display: flex;
  flex-direction: column;
  gap: 56px;
  max-width: 920px;
  margin-inline: auto;
  animation: fade-up 0.55s var(--ease) both;
}

.book-hero {
  display: grid;
  grid-template-columns: minmax(140px, 220px) minmax(0, 1fr);
  gap: 40px 48px;
  align-items: start;
}

.book-cover {
  width: 100%;
  max-width: 220px;
}

.cover-lg {
  width: 100%;
}

.book-intro {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding-top: 4px;
}

.book-meta {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.book-intro h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 900;
  line-height: 1.25;
  text-wrap: balance;
}

.book-author {
  margin: 0;
  font-size: 1rem;
  color: var(--muted);
}

.book-synopsis {
  margin: 8px 0 0;
  max-width: 36em;
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  line-height: 1.95;
  color: var(--ink);
}

.book-intro .cta-group {
  margin-top: 16px;
}

.book-toc-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.book-toc-head h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
}

.book-toc-head .mono {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.book-chapters {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.book-chapter {
  display: grid;
  grid-template-columns: 2.5rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px 16px;
  min-height: 56px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  transition: color 0.2s ease;
}

.book-chapter:hover {
  color: var(--accent);
}

.book-chapter:hover .book-chapter-go {
  opacity: 1;
  transform: translateX(2px);
}

.book-chapter-num {
  font-size: 0.75rem;
  color: var(--muted);
}

.book-chapter-title {
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.4;
}

.book-chapter-go {
  font-size: 1rem;
  opacity: 0.35;
  transition: opacity 0.2s ease, transform 0.2s var(--ease);
}

.back-to-top {
  position: fixed;
  right: max(16px, calc((100vw - var(--max)) / 2 - 8px));
  bottom: 28px;
  z-index: 8;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 48px;
  min-height: 48px;
  padding: 10px 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  box-shadow: 0 10px 24px -16px rgba(20, 20, 20, 0.45);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    color 0.2s ease,
    border-color 0.2s ease,
    background-color 0.2s ease,
    opacity 0.2s ease,
    transform 0.2s var(--ease),
    visibility 0s linear 0.2s;
}

.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition-delay: 0s;
}

.back-to-top:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.page-book .footer-inner {
  padding-bottom: 96px;
}

.book-notice {
  margin: 0 0 20px;
  padding: 14px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--chip);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--ink);
}

/* —— 閱讀頁主題（掛在 html，避免載入閃爍） —— */
html[data-theme="sepia"] {
  --bg: #efe6d4;
  --ink: #2a2318;
  --muted: #5e513c;
  --line: #dccfb6;
  --chip: #e4d8c1;
  --chip-on: #f8f2e6;
  --active: rgba(42, 35, 24, 0.07);
  --accent: #a93a22;
}

html[data-theme="dark"] {
  --bg: #151515;
  --ink: #e6e3dc;
  --muted: #a09d96;
  --line: #2c2c2a;
  --chip: #232322;
  --chip-on: #3a3a38;
  --active: rgba(230, 227, 220, 0.08);
  --accent: #f07a5c;
}

.read-header .header-inner {
  gap: 12px 24px;
}

.read-header .logo {
  font-size: 1.375rem;
}

.read-crumb {
  margin: 0;
  min-width: 0;
  font-size: 0.875rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.read-toolbar {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.8125rem;
}

.pill-group {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 44px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--chip);
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  min-width: 40px;
  justify-content: center;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 500;
  cursor: pointer;
}

#font-smaller,
#font-larger {
  padding: 0;
  font-weight: 700;
}

.pill-btn-lg {
  font-size: 1.0625rem;
}

.pill-btn[aria-pressed="true"] {
  background: var(--chip-on);
  font-weight: 700;
}

.pill-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.font-size-value {
  min-width: 28px;
  text-align: center;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(127, 127, 127, 0.5);
}

.swatch-light {
  background: #f7f6f2;
}

.swatch-sepia {
  background: #efe6d4;
}

.swatch-dark {
  background: #151515;
}

.read-progress {
  height: 3px;
}

.read-progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.4s var(--ease);
}

.read-layout {
  padding-block: 48px 96px;
}

.read-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 168px;
  gap: 40px 56px;
  align-items: start;
}

/* 側欄降權：窄、淡、不搶正文焦點；sticky 跟視窗高，目錄超出可捲 */
.read-aside {
  position: sticky;
  top: 96px;
  width: 168px;
  max-width: 168px;
  height: auto;
  min-height: 0;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  color: var(--muted);
  opacity: 0.72;
  transition: opacity 0.25s var(--ease);
}

.read-aside > nav {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.read-aside:hover,
.read-aside:focus-within {
  opacity: 1;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  font-size: 0.8125rem;
  color: var(--muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--ink);
}

.cover-sm {
  width: 72px;
  opacity: 0.9;
}

.read-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.read-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.45;
  color: var(--ink);
}

.read-author {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.read-meta {
  margin: 4px 0 0;
  font-size: 0.6875rem;
  color: var(--muted);
  opacity: 0.85;
}

.aside-label {
  flex-shrink: 0;
  margin: 4px 0 6px;
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0.8;
}

.chapter-nav-shell {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chapter-nav {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-left: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.chapter-nav::-webkit-scrollbar {
  width: 4px;
}

.chapter-nav::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 2px;
}

/* 可捲動時底部靜態提示：柔和遮罩 + 箭頭，不搶正文注意力 */
.chapter-nav-fade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
  height: 44px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
  pointer-events: none;
  background: linear-gradient(
    to top,
    var(--bg) 0%,
    color-mix(in srgb, var(--bg) 72%, transparent) 45%,
    transparent 100%
  );
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s var(--ease), visibility 0.35s var(--ease);
}

.chapter-nav-shell.is-scrollable:not(.is-at-end) .chapter-nav-fade {
  visibility: visible;
  opacity: 0.75;
}

.chapter-nav-fade-mark {
  display: block;
  width: 10px;
  height: 10px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: translateY(0) rotate(45deg);
  opacity: 0.55;
}

.chapter-link {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 12px;
  margin-left: -1px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  text-align: left;
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.chapter-link:hover {
  color: var(--ink);
  background: transparent;
}

.chapter-link.is-active {
  background: transparent;
  border-left-color: var(--accent);
  color: var(--ink);
  font-weight: 500;
}

.chapter-num {
  flex-shrink: 0;
  font-size: 0.6875rem;
  color: inherit;
  opacity: 0.55;
}

.chapter-link.is-active .chapter-num {
  color: var(--accent);
  opacity: 1;
}

.read-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chapter-head,
.read-content,
.chapter-pager {
  width: 100%;
  max-width: 34em;
  font-size: var(--read-size, 18px);
}

.chapter-head {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 40px;
}

.chapter-code {
  margin: 0;
  font-size: 0.8125rem;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.chapter-head h2 {
  margin: 0;
  font-size: 2.5rem;
  font-weight: 900;
  line-height: 1.25;
}

.read-scroll {
  width: 100%;
  display: flex;
  justify-content: safe center;
}

.read-content {
  font-family: var(--font-serif);
  line-height: 2;
  letter-spacing: 0.02em;
  text-align: justify;
  margin-inline: auto;
}

.read-content p {
  margin: 0 0 1.2em;
}

/* 直排：容器也用 vertical-rl，捲動起點在右側（章節開頭） */
.is-vertical .read-scroll {
  overflow-x: auto;
  writing-mode: vertical-rl;
  justify-content: safe start;
}

.is-vertical .read-content {
  writing-mode: vertical-rl;
  width: auto;
  max-width: none;
  height: 30em;
  line-height: 2.1;
  letter-spacing: 0.08em;
  padding: 0 8px;
  margin-inline: 0;
}

.is-vertical .read-content p {
  margin: 0 0 0 1.2em;
  text-indent: 2em;
}

.chapter-pager {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 64px;
}

.pager-btn {
  flex: 1 1 200px;
  min-height: 72px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  font-family: var(--font-sans);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s ease, opacity 0.2s ease;
}

.pager-btn:hover:not(:disabled) {
  border-color: var(--ink);
}

.pager-next {
  align-items: flex-end;
  text-align: right;
  border-color: var(--ink);
  background: var(--ink);
  color: var(--bg);
}

.pager-next:hover:not(:disabled) {
  opacity: 0.88;
}

.pager-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.pager-label {
  font-size: 0.75rem;
  opacity: 0.75;
}

.pager-title {
  font-size: 1rem;
  font-weight: 700;
}

/* —— Motion —— */
@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* —— Responsive —— */
@media (max-width: 720px) {
  .header-actions,
  .read-toolbar {
    margin-left: 0;
    width: 100%;
  }

  .search {
    flex: 1 1 auto;
  }

  /* 首頁、作品頁、排行頁：收合成一列，選單與搜尋展開在下方 */
  .main-header .header-inner {
    gap: 0 8px;
    padding-block: 8px;
  }

  .main-header .header-toggles {
    display: flex;
    gap: 4px;
    margin-left: auto;
    margin-right: -10px;
  }

  .main-header .header-menu {
    display: none;
    flex-direction: column;
    width: 100%;
    padding-block: 8px;
  }

  .main-header.is-menu-open .header-menu,
  .main-header.is-search-open .header-menu {
    display: flex;
  }

  .main-header .nav {
    flex-direction: column;
    gap: 0;
    border-top: 1px solid var(--line);
  }

  .main-header .nav a {
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }

  .main-header .nav a[aria-current="page"] {
    color: var(--accent);
  }

  .main-header.is-menu-open .header-actions {
    padding-top: 16px;
  }

  .main-header .search {
    width: 100%;
  }

  .main-header:not(.is-menu-open) .nav,
  .main-header:not(.is-menu-open) .header-actions .btn,
  .main-header:not(.is-search-open) .search {
    display: none;
  }

  .novel-grid[data-view="list"] .novel-card {
    gap: 12px;
    padding: 12px;
    margin-inline: -12px;
  }

  .novel-grid[data-view="list"] .novel-card .cover {
    flex-basis: 40px;
    width: 40px;
  }

  .hero {
    padding-block: 48px 64px;
  }

  .pick {
    padding: 20px;
  }

  .pick-cover {
    flex-basis: 140px;
  }

  /* 手機上工具列較高，不固定在頂端；目錄在內文之後（DOM 順序） */
  .read-header {
    position: static;
  }

  .read-shell {
    grid-template-columns: 1fr;
  }

  .read-aside {
    position: static;
    width: auto;
    max-width: none;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    opacity: 0.85;
    padding-top: 32px;
    border-top: 1px solid var(--line);
  }

  .read-aside > nav {
    overflow: visible;
  }

  .read-aside .cover-sm {
    width: 56px;
  }

  .chapter-nav-shell {
    flex: none;
    overflow: visible;
  }

  .chapter-nav-fade {
    display: none;
  }

  .chapter-nav {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0 8px;
    flex: none;
    overflow: visible;
    border-left: 0;
  }

  .chapter-link {
    margin-left: 0;
    border-left: 0;
    border-bottom: 2px solid transparent;
    padding-inline: 4px;
  }

  .chapter-link.is-active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
  }

  .writer-entry {
    padding: 40px 24px;
  }

  .book-hero {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .book-cover {
    max-width: 160px;
  }

  .book-shell {
    gap: 44px;
  }
}

/* —— 閱讀排行 —— */
.page-rank .rank-page {
  padding-top: 48px;
  padding-bottom: 104px;
}

.page-rank .section-head h1 {
  margin: 0 0 6px;
  font-size: 2.25rem;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.rank-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px solid var(--line);
}

.rank-item {
  border-bottom: 1px solid var(--line);
}

.rank-row {
  display: grid;
  grid-template-columns: 3rem 64px minmax(0, 1fr);
  gap: 16px 20px;
  align-items: center;
  padding: 18px 4px;
  text-decoration: none;
  transition: background-color 0.2s ease;
}

.rank-row:hover {
  background: var(--active);
}

.rank-num {
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
}

.rank-item.is-top-1 .rank-num {
  color: var(--accent);
  font-weight: 700;
}

.rank-item.is-top-2 .rank-num,
.rank-item.is-top-3 .rank-num {
  color: var(--ink);
  font-weight: 700;
}

.rank-row .cover-sm {
  width: 64px;
}

.rank-row .cover-text {
  display: none;
}

.rank-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.rank-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  font-size: 0.8125rem;
  color: var(--muted);
}

.rank-count {
  color: var(--ink);
  font-size: 0.875rem;
}

.rank-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.35;
}

.rank-row:hover .rank-title {
  color: var(--accent);
}

.rank-author {
  font-size: 0.875rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  .rank-row {
    grid-template-columns: 2.25rem 52px minmax(0, 1fr);
    gap: 12px 12px;
    padding: 14px 0;
  }

  .rank-row .cover-sm {
    width: 52px;
  }

  .rank-title {
    font-size: 1.0625rem;
  }
}

/* —— 檢舉對話框／Toast（book、novel 共用） —— */
.btn-report {
  margin-top: 12px;
  height: 40px;
  padding: 0 14px;
  font-size: 0.8125rem;
}

.btn-text {
  border: 0;
  background: transparent;
  color: var(--muted);
}

.btn-text:hover {
  color: var(--ink);
}

.modal {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 30px 60px -20px rgba(20, 20, 20, 0.45);
}

.modal::backdrop {
  background: rgba(20, 20, 20, 0.45);
}

.modal-card {
  display: flex;
  flex-direction: column;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px 8px;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 900;
}

.modal .icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}

.modal .icon-btn:hover {
  background: var(--chip);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px 24px 8px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 24px 24px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 700;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}

.field textarea {
  resize: vertical;
  min-height: 80px;
}

.field-hint {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
}

.field-hint.is-error {
  color: var(--accent);
}

.report-reasons {
  margin: 0;
  padding: 0;
  border: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.report-reasons legend {
  margin-bottom: 8px;
  font-size: 0.875rem;
  font-weight: 700;
}

.report-reason {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.report-reason:has(input:checked) {
  border-color: var(--ink);
  background: var(--active);
}

.report-reason input {
  margin-top: 3px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 40;
  max-width: calc(100vw - 32px);
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.875rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.25s ease, transform 0.25s var(--ease);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* —— 管理者後台 —— */
.page-admin .admin-layout {
  padding-block: 40px 80px;
}

.admin-gate,
.admin-empty {
  margin: 48px 0;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.admin-gate h1,
.admin-head h1 {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: clamp(1.75rem, 3vw, 2.25rem);
  font-weight: 700;
}

.admin-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 24px;
  margin-bottom: 28px;
}

.admin-head p {
  margin: 0;
  color: var(--muted);
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-card {
  display: grid;
  gap: 14px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.admin-card-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
}

.admin-card-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 800;
}

.admin-card-meta {
  margin: 4px 0 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.admin-badge {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--chip);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.admin-badge.is-open {
  background: #fbe9e4;
  color: #a3301c;
}

.admin-reason {
  margin: 0;
  font-size: 0.9375rem;
}

.admin-detail {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 0.875rem;
  color: var(--muted);
  white-space: pre-wrap;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-actions .btn {
  height: 40px;
  padding: 0 14px;
  font-size: 0.8125rem;
}

/* —— 審查模式工具列（僅 mod=1 + admin） —— */
.admin-review-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(20, 20, 20, 0.96);
  color: #f7f6f2;
  box-shadow: 0 -12px 40px rgba(20, 20, 20, 0.28);
  backdrop-filter: blur(10px);
}

.admin-review-bar--top {
  top: 0;
  bottom: auto;
  padding: 12px 16px;
  box-shadow: 0 12px 40px rgba(20, 20, 20, 0.28);
}

.admin-review-bar-inner {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
}

.admin-review-bar-eyebrow {
  margin: 0 0 2px;
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #e8b4a4;
}

.admin-review-bar-reason {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: #f7f6f2;
}

.admin-review-bar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* 強制實色，避免閱讀頁 theme 的 --ink/--bg 把字跟底塗成同色 */
.admin-review-bar .btn {
  height: 40px;
  padding: 0 14px;
  font-size: 0.8125rem;
  font-weight: 700;
  border-width: 1px;
  border-style: solid;
}

.admin-review-bar .btn-soft {
  background: #3d3d3a;
  border-color: #6a6a64;
  color: #f7f6f2;
}

.admin-review-bar .btn-soft:hover {
  background: #50504c;
  border-color: #8a8a84;
  color: #fff;
}

.admin-review-bar .btn-outline {
  background: transparent;
  border-color: #f7f6f2;
  color: #f7f6f2;
}

.admin-review-bar .btn-outline:hover {
  background: #f7f6f2;
  border-color: #f7f6f2;
  color: #141414;
}

.admin-review-bar .btn-dark {
  background: #f7f6f2;
  border-color: #f7f6f2;
  color: #141414;
}

.admin-review-bar .btn-dark:hover {
  background: #fff;
  border-color: #fff;
  color: #141414;
}

body.has-admin-review-bar {
  padding-bottom: 96px;
}

body.has-admin-review-bar-top {
  padding-bottom: 0;
  padding-top: 88px;
}

body.page-read.has-admin-review-bar-top .read-header {
  top: 88px;
}

body.page-read.has-admin-review-bar-top .read-aside {
  top: calc(96px + 72px);
  max-height: calc(100vh - 192px);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
