/* ============================================================
   Drizzt Studio 私人書齋 — 書卷氣主題
   ============================================================ */
:root {
  --paper: #f5efe1;
  --paper-deep: #ede4d0;
  --card: #fbf7ec;
  --ink: #3a2f24;
  --ink-soft: #6b5d4b;
  --accent: #8a6d4b;
  --accent-deep: #6f5436;
  --gold: #a8844c;
  --line: rgba(138, 109, 75, 0.25);
  --shadow: 0 6px 24px rgba(90, 70, 40, 0.10);
  --header-bg: rgba(245, 239, 225, 0.92);
  --font-serif: "Noto Serif TC", "Songti TC", "PMingLiU", "STSong", serif;
  --font-sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

[data-theme="dark"] {
  --paper: #191512;
  --paper-deep: #201b16;
  --card: #241e18;
  --ink: #d8ccb6;
  --ink-soft: #a89a83;
  --accent: #b08d57;
  --accent-deep: #c9a76e;
  --gold: #c9a76e;
  --line: rgba(200, 167, 110, 0.22);
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --header-bg: rgba(25, 21, 18, 0.92);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100vh;
  height: 100dvh;
}

body {
  font-family: var(--font-serif);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.9;
  transition: background 0.35s ease, color 0.35s ease;
  overscroll-behavior-y: none;
}

body::before {
  /* 紙紋質感 */
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(138, 109, 75, 0.05), transparent 60%),
    radial-gradient(ellipse at 80% 90%, rgba(138, 109, 75, 0.04), transparent 55%);
  pointer-events: none;
  z-index: 0;
}

a { color: var(--accent); text-decoration: none; }
button { font-family: var(--font-serif); cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: var(--font-serif); }

/* ---------- 頂欄 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.topbar .brand {
  font-size: 15px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--ink); flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .brand small { display: block; font-size: 11px; font-weight: 400; color: var(--ink-soft); letter-spacing: 0.15em; }
.icon-btn {
  width: 38px; height: 38px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; font-size: 17px; color: var(--ink-soft);
  border: 1px solid transparent;
  transition: background 0.2s, border-color 0.2s;
}
.icon-btn:active { background: var(--paper-deep); }

/* ---------- 登入頁 ---------- */
.auth-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; position: relative; z-index: 1;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 44px 32px 36px;
  box-shadow: var(--shadow);
  text-align: center;
  animation: rise 0.5s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.auth-seal {
  width: 64px; height: 64px; margin: 0 auto 18px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #f8f2e4;
  box-shadow: 0 8px 20px rgba(138, 109, 75, 0.35);
}
.auth-card h1 { font-size: 21px; letter-spacing: 0.12em; font-weight: 700; }
.auth-card .sub { font-size: 13px; color: var(--ink-soft); margin: 8px 0 26px; letter-spacing: 0.1em; }
.auth-card .sub::before, .auth-card .sub::after {
  content: "❖"; font-size: 9px; color: var(--gold); margin: 0 10px; vertical-align: middle;
}
.auth-input {
  width: 100%; padding: 14px 16px;
  font-size: 16px; text-align: center; letter-spacing: 0.2em;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: 12px;
  outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
.auth-input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(168, 132, 76, 0.15); }
.auth-btn {
  width: 100%; margin-top: 16px; padding: 14px;
  font-size: 15px; font-weight: 700; letter-spacing: 0.3em;
  color: #f8f2e4; background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  border-radius: 12px; transition: transform 0.15s, box-shadow 0.2s;
  box-shadow: 0 6px 16px rgba(138, 109, 75, 0.3);
}
.auth-btn:active { transform: scale(0.97); }
.auth-err { color: #b34a3a; font-size: 13px; margin-top: 14px; min-height: 20px; }
.auth-foot { font-size: 11px; color: var(--ink-soft); margin-top: 22px; letter-spacing: 0.08em; opacity: 0.7; }

/* ---------- 書庫頁 ---------- */
.library-body { max-width: 760px; margin: 0 auto; padding: 20px 16px 80px; position: relative; z-index: 1; }
.lib-head { text-align: center; padding: 18px 0 22px; }
.lib-head h2 { font-size: 24px; letter-spacing: 0.15em; font-weight: 700; }
.lib-head .orn { color: var(--gold); font-size: 12px; margin-top: 6px; letter-spacing: 0.5em; }

.book-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
  transition: border-color 0.25s;
}
.book-cover {
  padding: 22px 22px 6px;
  display: flex; align-items: flex-start; gap: 16px;
}
.book-cover .spine {
  width: 54px; height: 74px; flex-shrink: 0;
  border-radius: 6px;
  background: linear-gradient(150deg, var(--accent), var(--accent-deep));
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #f8f2e4;
  box-shadow: 2px 4px 10px rgba(90, 70, 40, 0.25);
}
.book-cover .meta { flex: 1; min-width: 0; }
.book-cover .meta h3 { font-size: 18px; letter-spacing: 0.08em; font-weight: 700; }
.book-cover .meta .author { font-size: 12px; color: var(--ink-soft); margin-top: 2px; letter-spacing: 0.1em; }
.book-cover .meta .desc { font-size: 13px; color: var(--ink-soft); margin-top: 8px; line-height: 1.7; }
.resume-btn {
  margin: 10px 22px 4px;
  display: none;
  width: calc(100% - 44px);
  padding: 11px; font-size: 13px; font-weight: 700; letter-spacing: 0.15em;
  color: var(--accent-deep); background: var(--paper);
  border: 1px solid var(--line); border-radius: 10px;
  transition: background 0.2s;
}
.resume-btn.show { display: block; }
.resume-btn:active { background: var(--paper-deep); }

.group { border-top: 1px dashed var(--line); }
.group-head {
  width: 100%; padding: 13px 22px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; font-weight: 600; letter-spacing: 0.12em; color: var(--accent);
}
.group-head .cnt { font-size: 11px; color: var(--ink-soft); font-weight: 400; letter-spacing: 0.05em; }
.group-head .chev { font-size: 10px; color: var(--gold); transition: transform 0.25s; }
.group.open .chev { transform: rotate(180deg); }
.group-chapters { display: none; }
.group.open .group-chapters { display: block; animation: fadein 0.25s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

.chapter-row {
  width: 100%; padding: 11px 22px 11px 34px;
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; color: var(--ink);
  border-top: 1px solid rgba(138, 109, 75, 0.08);
  transition: background 0.15s, color 0.15s;
  text-align: left;
}
.chapter-row:active { background: var(--paper-deep); }
.chapter-row .dot { font-size: 8px; color: var(--gold); flex-shrink: 0; }
.chapter-row .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-row .tag { font-size: 10px; color: var(--ink-soft); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; flex-shrink: 0; }

/* ---------- 閱讀頁 ---------- */
.reader-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.reader-top {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.reader-top .ttl { flex: 1; min-width: 0; }
.reader-top .ttl .book { font-size: 11px; color: var(--ink-soft); letter-spacing: 0.1em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-top .ttl .ch { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.font-ctl {
  display: flex; align-items: center; gap: 2px;
  border: 1px solid var(--line); border-radius: 9px; padding: 2px; flex-shrink: 0;
}
.font-ctl button { width: 30px; height: 30px; font-size: 13px; color: var(--ink-soft); border-radius: 7px; }
.font-ctl button:active { background: var(--paper-deep); }

.reader-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.reader-article {
  max-width: 660px; margin: 0 auto;
  padding: 34px 24px 60px;
  font-size: var(--fs, 17px);
  position: relative; z-index: 1;
}
.reader-article .ch-title {
  text-align: center;
  font-size: 1.35em; font-weight: 700; letter-spacing: 0.08em;
  padding-bottom: 20px; margin-bottom: 26px;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.reader-article .ch-title::after {
  content: "❖";
  position: absolute; bottom: -11px; left: 50%; transform: translateX(-50%);
  background: var(--paper); color: var(--gold);
  padding: 0 12px; font-size: 11px;
}
[data-theme="dark"] .reader-article .ch-title::after { background: var(--paper); }

.reader-article p { margin: 0 0 1.35em; text-align: justify; }
.reader-article blockquote {
  border-left: 3px solid var(--gold);
  padding: 6px 16px; margin: 0 0 1.35em;
  color: var(--ink-soft); font-size: 0.92em;
  background: rgba(138, 109, 75, 0.05);
  border-radius: 0 8px 8px 0;
}
.reader-article h1, .reader-article h2, .reader-article h3 {
  margin: 1.6em 0 0.8em; letter-spacing: 0.06em;
}
.reader-article h2 { font-size: 1.2em; color: var(--accent-deep); }
.reader-article h3 { font-size: 1.08em; }
.reader-article hr { border: none; border-top: 1px dashed var(--line); margin: 2.2em 0; }
.reader-article strong { color: var(--accent-deep); font-weight: 700; }
.reader-article em { color: var(--ink-soft); }
.reader-article ul, .reader-article ol { margin: 0 0 1.35em 1.6em; }

.reader-nav {
  display: flex; gap: 10px;
  padding: 16px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  max-width: 660px; margin: 0 auto;
  width: 100%;
}
.nav-btn {
  flex: 1; padding: 13px 10px;
  font-size: 14px; font-weight: 600; letter-spacing: 0.08em;
  color: var(--accent); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.nav-btn small { font-size: 10px; color: var(--ink-soft); font-weight: 400; letter-spacing: 0.05em; }
.nav-btn:active { transform: scale(0.96); }
.nav-btn.disabled { opacity: 0.35; pointer-events: none; }

/* 目錄抽屜 */
.drawer-mask {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(20, 15, 8, 0.5);
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 95;
  width: min(320px, 88vw);
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 30px rgba(0, 0, 0, 0.2);
  transform: translateX(105%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.drawer.show { transform: none; }
.drawer-head {
  padding: calc(16px + env(safe-area-inset-top, 0px)) 20px 14px;
  font-size: 15px; font-weight: 700; letter-spacing: 0.15em;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 10px 0 30px; }
.drawer-group-title {
  padding: 16px 20px 6px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.15em; color: var(--gold);
}
.drawer-ch {
  width: 100%; text-align: left;
  padding: 9px 20px; font-size: 13px; color: var(--ink);
  border-left: 2px solid transparent;
}
.drawer-ch.active { border-left-color: var(--gold); color: var(--accent-deep); font-weight: 700; background: rgba(168, 132, 76, 0.07); }
.drawer-ch small { color: var(--ink-soft); font-size: 11px; }

/* 載入狀態 */
.loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 80px 0; color: var(--ink-soft); font-size: 14px; letter-spacing: 0.15em;
  gap: 14px;
}
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 小提示 */
.toast {
  position: fixed; left: 50%; bottom: 30px; z-index: 120;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30, 24, 16, 0.92); color: #f0e8d8;
  padding: 10px 20px; border-radius: 10px;
  font-size: 13px; letter-spacing: 0.08em;
  opacity: 0; pointer-events: none; transition: all 0.3s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 18+ 成人內容警告 ===== */
.adult-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 14, 6, 0.88);
  backdrop-filter: blur(4px);
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
}
.adult-overlay.hidden { display: none; }
.adult-card {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 16px;
  max-width: 420px;
  width: 100%;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}
.adult-badge {
  display: inline-block;
  font-size: 44px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  letter-spacing: 2px;
  margin-bottom: 14px;
}
.adult-card h2 {
  font-family: var(--serif);
  font-size: 20px;
  margin: 0 0 14px;
  color: var(--ink);
}
.adult-card p {
  font-size: 14px;
  line-height: 1.8;
  color: var(--ink-soft);
  margin: 0 0 10px;
}
.adult-card p strong { color: var(--accent); }
.adult-card .adult-note { font-size: 12.5px; color: var(--ink-faint); margin-bottom: 22px; }
.adult-btn {
  width: 100%;
  padding: 13px 0;
  font-size: 15.5px;
  font-family: var(--serif);
  font-weight: 700;
  color: var(--paper);
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.2s;
}
.adult-btn:hover { opacity: 0.88; }
body.modal-lock { overflow: hidden; }
