/* [新增] 2026-10-03 前後端隔離：原本是 index.html 裡的行內 <style>。
   [修改] 2026-10-26 改用 Django：搬到 reader/app/static/reader/，由 WhiteNoise 提供（檔名帶雜湊、長期快取）。
   [修改] 2026-10-26 介面改版（整份重寫）：深色／淺色主題（theme.js 設 html[data-theme]，沒設就跟系統）、
   桌機頂部導覽＋手機底部分頁列、卡片與頭圖、更新時間軸、閱讀器的上下工具列與設定面板、翻頁模式。
   CSP 仍是 style-src 'self'：不能用行內樣式或 style="" 屬性（JS 用 el.style.x = … 的 CSSOM 操作不受影響）。 */

/* ── 主題 ───────────────────────────────────────────────── */
:root {
  --bg: #0e0f12;
  --bg-2: #121418;
  --panel: #171a1f;
  --panel-2: #1f232a;
  --line: #2a2f37;
  --text: #ecebe8;
  --muted: #9da1a9;
  --faint: #6c717b;
  --accent: #f0a63a;
  --accent-2: #ffbf5e;
  --accent-ink: #1a1204;
  --accent-soft: rgba(240, 166, 58, .14);
  --ok: #5cba80;
  --bad: #e06a61;
  --purple: #b9a3ff;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .35);
  --glass: rgba(14, 15, 18, .82);
  --radius: 12px;
  --bar-h: 56px;
  --tab-h: 62px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f4f0; --bg-2: #efede8; --panel: #ffffff; --panel-2: #f1efea; --line: #e2dfd7;
    --text: #1d1e21; --muted: #5f636b; --faint: #8b8f97; --accent: #d9871a; --accent-2: #c77610;
    --accent-ink: #ffffff; --accent-soft: rgba(217, 135, 26, .12); --ok: #2f9a5b; --bad: #c9473d; --purple: #6d4fd8;
    --shadow: 0 10px 30px rgba(30, 25, 10, .14); --shadow-sm: 0 2px 10px rgba(30, 25, 10, .08);
    --glass: rgba(245, 244, 240, .86); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f5f4f0; --bg-2: #efede8; --panel: #ffffff; --panel-2: #f1efea; --line: #e2dfd7;
  --text: #1d1e21; --muted: #5f636b; --faint: #8b8f97; --accent: #d9871a; --accent-2: #c77610;
  --accent-ink: #ffffff; --accent-soft: rgba(217, 135, 26, .12); --ok: #2f9a5b; --bad: #c9473d; --purple: #6d4fd8;
  --shadow: 0 10px 30px rgba(30, 25, 10, .14); --shadow-sm: 0 2px 10px rgba(30, 25, 10, .08);
  --glass: rgba(245, 244, 240, .86); color-scheme: light;
}

/* ── 基本 ───────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1 { font-size: 22px; line-height: 1.3; margin: 0; letter-spacing: .01em; }
h1 small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 6px; }
h2.sec { margin: 26px 0 10px; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .06em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--faint); font-size: 13px; margin: 8px 0 0; }
.sp { flex: 1; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.ic { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.ic.fill { fill: currentColor; }
.ic.inline { width: 15px; height: 15px; }

/* ── 按鈕、chip、分段控制 ──────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel-2); cursor: pointer; white-space: nowrap;
  transition: border-color .15s, background .15s, transform .1s;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn.sm { padding: 5px 12px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.danger { color: var(--bad); }
.btn.danger:hover:not(:disabled) { border-color: var(--bad); }
.btn .ic { width: 16px; height: 16px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 3px;
  min-width: 38px; height: 38px; padding: 0 8px; border: 0; border-radius: 10px;
  background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--panel-2); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.icon-btn .ic { width: 20px; height: 20px; }
.icon-btn .n { font-size: 11px; font-weight: 700; }

.chip {
  display: inline-block; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line);
  font-size: 11px; line-height: 17px; color: var(--muted); white-space: nowrap; font-weight: 500;
}
.chip.cx { color: #f0b36a; border-color: rgba(240, 179, 106, .4); }
.chip.tl { color: var(--ok); border-color: rgba(92, 186, 128, .4); }
.chip.of { color: var(--purple); border-color: rgba(185, 163, 255, .4); }
.chip.bad { color: var(--bad); border-color: rgba(224, 106, 97, .45); }
.chip.warn { color: var(--accent); border-color: rgba(240, 166, 58, .45); }
.chip.tag { color: var(--text); border-color: var(--line); background: var(--panel-2); }
.chip.up { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 700; }
a.chip:hover { border-color: var(--muted); }

.seg { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); flex-wrap: wrap; }
.seg > a, .seg > button {
  display: inline-flex; align-items: center; gap: 5px; padding: 5px 13px; border: 0; border-radius: 999px;
  background: none; color: var(--muted); font-size: 13px; cursor: pointer; white-space: nowrap;
}
.seg > .on { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.seg .ic { width: 15px; height: 15px; }

.pill {
  flex: 0 0 auto; padding: 6px 14px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); color: var(--muted); font-size: 13px; cursor: pointer; white-space: nowrap;
  transition: all .15s;
}
.pill:hover { color: var(--text); border-color: var(--muted); }
.pill.on { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }

/* ── [修改] 2026-10-26 外框：電腦版側邊欄（body.ui-d）、手機版標題列＋分頁列（body.ui-m）── */
/* 版本由伺服器決定（app/ui.py：看裝置，「我的」可以強制切換），不是看螢幕寬度；電腦版視窗變窄時側邊欄縮成圖示列 */
:root { --side-w: 232px; }
.side ~ .shell { margin-left: var(--side-w); min-height: 100vh; }
.side {
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 20; width: var(--side-w);
  display: flex; flex-direction: column; gap: 4px; padding: 18px 12px; overflow-y: auto;
  background: var(--bg-2); border-right: 1px solid var(--line);
}
.side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; font-weight: 800; font-size: 17px; white-space: nowrap; }
.side .brand img { width: 30px; height: 30px; display: block; }
.sidenav { display: flex; flex-direction: column; gap: 2px; }
.sidenav a, .side-foot a, .side-foot button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border: 0; border-radius: 10px;
  background: none; color: var(--muted); font-size: 14.5px; font-weight: 550; text-align: left; cursor: pointer; white-space: nowrap;
}
.sidenav .ic, .side-foot .ic { width: 20px; height: 20px; }
.sidenav a:hover, .side-foot a:hover, .side-foot button:hover { color: var(--text); background: var(--panel-2); }
.sidenav a.on { color: var(--text); background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.sidenav a.on .ic { color: var(--accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; padding-top: 12px; border-top: 1px solid var(--line); }
.side-foot form { margin: 0; }
.side-foot .who { gap: 10px; padding: 8px 10px; }
.side-foot .who-t { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.side-foot .who-t b { color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.side-foot .who-t small { font-size: 12px; color: var(--faint); }
.side-foot .out { color: var(--bad); }
@media (max-width: 980px) {
  :root { --side-w: 72px; }
  .side { padding: 14px 10px; align-items: center; }
  .side .brand { padding: 4px 0 16px; }
  .side .brand span, .sidenav span, .side-foot button span, .side-foot a > span:not(.avatar), .side-foot .who-t { display: none; }
  .sidenav a, .side-foot a, .side-foot button { justify-content: center; padding: 11px; }
}

.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #c9622b); color: #1a1204; font-weight: 800; font-size: 15px;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--line);
}
.avatar.lg { width: 64px; height: 64px; font-size: 26px; }

.appbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px;
  height: calc(var(--bar-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0 12px;
  background: var(--glass); backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.appbar .brand img { width: 28px; height: 28px; display: block; }
.appbar .apptitle { margin-left: 4px; font-size: 19px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--glass); backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--faint); font-size: 11px; font-weight: 600;
}
.tabbar a .ic { width: 23px; height: 23px; }
.tabbar a.on { color: var(--accent); }
body.ui-m:not([data-view="read"]):not([data-view="login"]) { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); }
.ui-m .shell { max-width: 760px; margin: 0 auto; }          /* 電腦上強制用手機版時，置中成手機寬 */
.ui-m .tabbar { max-width: 760px; margin: 0 auto; }
.ui-m .pagehead h1 { display: none; }                         /* 標題已經在上面的標題列 */
.ui-m .libbar { flex: 1 1 100%; }
.ui-m .search { flex: 1 1 auto; height: 42px; }
.ui-m .btn, .ui-m .pill { min-height: 38px; }

/* ── 提示訊息 ──────────────────────────────────────────── */
.flash { position: fixed; left: 50%; top: calc(var(--bar-h) + env(safe-area-inset-top) + 12px); z-index: 40; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; }
.flash-msg {
  padding: 10px 18px; border-radius: 999px; background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); white-space: nowrap;
  animation: flash-in .25s ease-out;
}
.flash.out { opacity: 0; transition: opacity .4s; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-8px); } }
.ui-d .flash { top: 18px; left: calc(50% + var(--side-w) / 2); }

/* ── 版面 ─────────────────────────────────────────────── */
main.wrap { max-width: 1240px; margin: 0 auto; padding: 22px 20px 56px; }
main.wrap.narrow { max-width: 820px; }
.ui-d main.wrap { max-width: 1440px; padding: 28px 32px 56px; }
.ui-d main.wrap.narrow { max-width: 900px; }
.ui-m main.wrap { padding: 14px 14px 28px; }
.pagehead { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 14px; }
.libbar { display: flex; align-items: center; gap: 8px; flex: 1 1 320px; justify-content: flex-end; }
.search {
  display: flex; align-items: center; gap: 8px; flex: 0 1 300px; min-width: 0;
  padding: 0 14px; height: 38px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
  color: var(--faint); transition: border-color .15s;
}
.search:focus-within { border-color: var(--accent); color: var(--text); }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: none; color: var(--text); }
.search.sm { height: 32px; flex: 0 1 140px; padding: 0 10px; font-size: 13px; }
.search.sm .ic { width: 15px; height: 15px; }
select.btn { appearance: none; -webkit-appearance: none; padding-right: 30px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 14px; margin-bottom: 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters .sep { flex: 0 0 1px; background: var(--line); margin: 4px 2px; }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty.big { padding: 72px 16px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty.big > .ic { width: 44px; height: 44px; color: var(--faint); stroke-width: 1.5; }
.empty p { margin: 0; }
.empty .btn { margin-top: 8px; }
.err { color: var(--bad); }
.ok { color: var(--ok); }

/* ── 作品卡 ───────────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); gap: 30px 20px; }
.card { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card .ct { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.prog-t { display: none; font-size: 12.5px; color: var(--accent); font-weight: 600; }
@media (max-width: 980px) { .ui-d .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 20px 12px; } }
/* [新增] 2026-10-26 手機版：格狀小一號；預設清單（封面＋標題橫排，像 Mihon 的 list），標題列的按鈕切換 */
.ui-m .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 16px 10px; }
.ui-m .grid.as-list { grid-template-columns: 1fr; gap: 0; }
.ui-m .grid.as-list .card { flex-direction: row; align-items: center; gap: 14px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.ui-m .grid.as-list .card:last-child { border-bottom: 0; }
.ui-m .grid.as-list .cover { width: 70px; flex: 0 0 auto; border-radius: 8px; box-shadow: none; }
.ui-m .grid.as-list .cover .prog { display: none; }
.ui-m .grid.as-list .cover .upd { right: 3px; top: 3px; padding: 1px 6px; font-size: 10px; }
.ui-m .grid.as-list .cover.none::after { font-size: 26px; }
.ui-m .grid.as-list .ct { flex: 1; }
.ui-m .grid.as-list .nm { font-size: 15.5px; }
.ui-m .grid.as-list .prog-t { display: block; }
.ui-m .card:hover .cover { transform: none; }
.card.dim { opacity: .5; }
.cover {
  position: relative; aspect-ratio: 3 / 4; border-radius: var(--radius); overflow: hidden;
  background: var(--panel-2); box-shadow: var(--shadow-sm); transition: transform .2s, box-shadow .2s;
}
.card:hover .cover { transform: translateY(-3px); box-shadow: var(--shadow); }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.none::after, .thumb.none::after {
  content: attr(data-initial); position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 44px; font-weight: 800; color: var(--faint);
  background: linear-gradient(135deg, var(--panel-2), var(--panel));
}
.cover .upd { position: absolute; right: 7px; top: 7px; padding: 2px 9px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 800; box-shadow: var(--shadow-sm); }
.cover .fav { position: absolute; left: 7px; top: 7px; display: flex; padding: 4px; border-radius: 50%; background: rgba(0, 0, 0, .55); color: var(--accent); }
.cover .fav .ic { width: 13px; height: 13px; }
.cover .prog {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 9px 7px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .85)); color: #fff; font-size: 11.5px; font-weight: 600;
}
.card .nm { font-weight: 650; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .en { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta, .work-side .meta { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 12px; color: var(--muted); }
.card .when { font-size: 11.5px; color: var(--faint); }
.card .when.fresh { color: var(--accent); }

/* ── 作品頁 ───────────────────────────────────────────── */
/* [修改] 2026-10-26 同一份結構：電腦版左右分欄（左 .work-side 固定、右 .work-main 話清單），手機版上下疊 */
.work { position: relative; overflow: hidden; }
.work > .hero-bg {
  position: absolute; left: -60px; right: -60px; top: -60px; width: calc(100% + 120px); height: 520px; object-fit: cover;
  filter: blur(48px) saturate(140%); opacity: .36; pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, #000 25%, transparent); mask-image: linear-gradient(to bottom, #000 25%, transparent);
}
.work-side, .work-main { position: relative; z-index: 1; min-width: 0; }
.work-side .info { min-width: 0; display: flex; flex-direction: column; gap: 9px; }
.work-side .en { color: var(--muted); }
.work-side .cover { box-shadow: var(--shadow); }
.byline { color: var(--muted); font-size: 13.5px; }
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(62px, 1fr)); gap: 8px; margin: 4px 0; }
.statgrid div { padding: 8px 6px; border: 1px solid var(--line); border-radius: 10px; background: color-mix(in srgb, var(--panel) 85%, transparent); text-align: center; }
.statgrid dt { font-size: 11.5px; color: var(--muted); }
.statgrid dd { margin: 0; font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.work-side .acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.work-side .acts form { margin: 0; }

.ui-d .work { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 40px; align-items: start; max-width: 1440px; margin: 0 auto; padding: 34px 32px 60px; }
.ui-d .work-side { position: sticky; top: 24px; display: flex; flex-direction: column; gap: 18px; }
.ui-d .work-side .cover { width: 100%; }
.ui-d .work-side h1 { font-size: 26px; }
.ui-d .work-side .acts { flex-direction: column; }
.ui-d .work-side .acts .btn, .ui-d .work-side .acts form { width: 100%; }
.ui-d .work-side .acts form .btn { width: 100%; }
.ui-d .work-main { padding-top: 6px; }
@media (max-width: 1180px) { .ui-d .work { grid-template-columns: 240px minmax(0, 1fr); gap: 26px; padding: 24px 22px 48px; } }

.ui-m .work-side { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; padding: 22px 16px 18px; }
.ui-m .work-side .cover { width: 140px; }
.ui-m .work-side h1 { font-size: 21px; }
.ui-m .work-side .info { align-items: center; }
.ui-m .work-side .meta, .ui-m .work-side .acts { justify-content: center; }
.ui-m .statgrid { width: 100%; max-width: 360px; }
.ui-m .work-side .acts .btn.primary { display: none; }      /* 手機版用底部固定的那顆 */
.ui-m .work-main { padding: 0 14px 96px; }

.resume {
  display: flex; align-items: center; gap: 14px; margin: 0 0 20px; padding: 14px 16px;
  border: 1px solid var(--accent); border-radius: 16px; box-shadow: var(--shadow-sm);
  background: linear-gradient(120deg, var(--accent-soft), transparent 65%), var(--panel);
  transition: transform .15s;
}
.resume:hover { transform: translateY(-1px); }
.resume-ic { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; width: 46px; height: 46px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); }
.resume-ic .ic { width: 22px; height: 22px; }
.resume-t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.resume-t small { font-size: 12px; font-weight: 700; color: var(--accent); letter-spacing: .04em; }
.resume-t b { font-size: 17px; }
.resume-t > span { font-size: 13px; color: var(--muted); }
.resume-t progress { margin-top: 7px; max-width: 380px; }
.resume .btn .ic { width: 15px; height: 15px; }
.eptools { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.eptitle { margin: 0; font-size: 18px; font-weight: 750; color: var(--text); }
.eptitle small { margin-left: 6px; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.ui-m .eptitle { flex-basis: 100%; }
.eprow { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0 0 14px; }
.seg.sm > button { padding: 4px 12px; font-size: 12.5px; }
.seg .n { margin-left: 2px; font-size: 11.5px; opacity: .75; font-weight: 500; }
.ranges { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.ranges::-webkit-scrollbar { display: none; }
.ranges .pill { padding: 4px 12px; font-size: 12.5px; font-variant-numeric: tabular-nums; }
progress {
  -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 4px; border: 0; border-radius: 99px;
  background: var(--panel-2); overflow: hidden; color: var(--accent);
}
progress::-webkit-progress-bar { background: var(--panel-2); border-radius: 99px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; }
.selbar {
  position: sticky; top: 12px; z-index: 15; display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 0 0 12px; padding: 8px 10px 8px 16px; border: 1px solid var(--accent); border-radius: 999px;
  background: var(--panel); box-shadow: var(--shadow); font-size: 14px;
}
.ui-m .selbar { top: calc(var(--bar-h) + env(safe-area-inset-top) + 8px); border-radius: 16px; }
.eps { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 8px; }
.ep {
  position: relative; display: flex; align-items: center; gap: 12px; min-width: 0;
  padding: 9px 12px 9px 9px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  transition: border-color .15s, background .15s, transform .1s;
}
a.ep:hover { border-color: var(--muted); }
a.ep:active { transform: scale(.985); }
.ep-n {
  position: relative; flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
  min-width: 44px; height: 44px; padding: 0 6px; border-radius: 10px; background: var(--panel-2);
  font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums;
}
.ep-n .dot { position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--panel); }
.ep-b { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ep .no { font-weight: 650; font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ep .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ep .added { color: var(--faint); }
.ep progress { margin-top: 4px; }
.ep-s { flex: 0 0 auto; display: flex; color: var(--faint); }
.ep-s .ic { width: 18px; height: 18px; }
.ep.seen { opacity: .62; }
.ep.seen .no { font-weight: 500; }
.ep.seen .ep-n { color: var(--faint); }
.ep.seen .ep-s { color: var(--ok); }
.ep.cur { border-color: var(--accent); background: var(--accent-soft); opacity: 1; }
.ep.cur .ep-n { background: var(--accent); color: var(--accent-ink); }
.ep.cur .ep-s, .ep.cur .sub { color: var(--accent); }
.ep.ext { border-style: dashed; }
.ep.ext .sub, .ep.ext .ep-s { color: var(--purple); }
.ep.off { opacity: .4; cursor: not-allowed; }
.ep .tick { display: none; flex: 0 0 auto; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--faint); align-items: center; justify-content: center; }
.eps.selecting .ep-s { display: none; }
.ep .tick .ic { width: 13px; height: 13px; stroke-width: 3; opacity: 0; }
.eps.selecting .ep:not(.off) { cursor: pointer; opacity: 1; }
.eps.selecting .ep:not(.off) .tick { display: flex; }
.eps.selecting .ep.sel { border-color: var(--accent); background: var(--accent-soft); }
.eps.selecting .ep.sel .tick { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.eps.selecting .ep.sel .tick .ic { opacity: 1; }
.ep.hit { animation: hit 1.4s ease-out; }
@keyframes hit { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
/* 手機版：話清單是整列的大按鈕 */
.ui-m .eps { grid-template-columns: 1fr; gap: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--panel); }
.ui-m .ep { gap: 12px; min-height: 62px; padding: 10px 14px 10px 12px; border: 0; border-radius: 0; border-bottom: 1px solid var(--line); background: none; }
.ui-m .ep-n { min-width: 40px; height: 40px; font-size: 15px; }
.ui-m .ep:last-child { border-bottom: 0; }
.ui-m .ep.cur { box-shadow: inset 3px 0 0 var(--accent); background: var(--accent-soft); }
.ui-m .resume { margin: 0 0 18px; }
.ui-m .eps.selecting .ep.sel { border-color: var(--line); }

.wfab { display: none; }
.ui-m .wfab:not([hidden]) {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom)); z-index: 25;
  display: flex; max-width: 760px; margin: 0 auto; padding: 10px 14px; background: linear-gradient(to top, var(--bg) 60%, transparent);
}
.ui-m .wfab .btn { flex: 1; padding: 13px 16px; font-size: 15.5px; }

/* ── 更新、紀錄（清單列）────────────────────────────────── */
.rows { display: flex; flex-direction: column; gap: 6px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 8px; min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel);
}
.row.seen { opacity: .62; }
.row form { margin: 0; }
.thumb { position: relative; flex: 0 0 auto; width: 46px; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; background: var(--panel-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.none::after { font-size: 18px; }
.ri { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ri b { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ri > span { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .when { font-size: 12px; color: var(--faint); white-space: nowrap; }
@media (max-width: 520px) { .row .when { display: none; } }
.day + .day { margin-top: 6px; }

/* ── 我的 ─────────────────────────────────────────────── */
.profile { display: flex; align-items: center; gap: 16px; margin: 6px 0 20px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
a.tile:hover { border-color: var(--muted); }
.tile .v { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.tile .lb { font-size: 12.5px; color: var(--muted); }
.panel { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.panel.links { padding: 6px; display: flex; flex-direction: column; }
.panel > .field + .field { margin-top: 14px; }
.panel form.field { margin-bottom: 0; }
.panel.links a, .panel.links button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px; border: 0; border-radius: 8px;
  background: none; text-align: left; cursor: pointer;
}
.panel.links a:hover, .panel.links button:hover { background: var(--panel-2); }
.panel.links .end { margin-left: auto; color: var(--faint); }
.panel.links form { margin: 0; }
.panel.links .danger { color: var(--bad); }
.field { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.panel.form { display: flex; flex-direction: column; gap: 14px; }
.fld { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.fld input {
  padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  color: var(--text); font-size: 15px; outline: none; transition: border-color .15s;
}
.fld input:focus { border-color: var(--accent); }

/* ── 登入 ─────────────────────────────────────────────── */
.auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background: radial-gradient(ellipse at top, var(--accent-soft), transparent 60%), var(--bg);
}
.login {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px;
  padding: 32px 28px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow);
}
.login .logo { width: 52px; height: 52px; align-self: center; }
.login h1 { text-align: center; font-size: 22px; }
.login p { margin: -6px 0 4px; color: var(--muted); font-size: 13.5px; text-align: center; }
.login code { display: block; margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: var(--bg); color: var(--accent); font-size: 12px; word-break: break-all; user-select: all; text-align: left; }
.login .btn.primary { padding: 11px; font-size: 15px; margin-top: 4px; }
.login .err, .panel .err { min-height: 20px; font-size: 13.5px; text-align: center; }
.panel .err { text-align: left; }

/* ── 閱讀器 ───────────────────────────────────────────── */
body[data-view="read"] { background: #000; }
body[data-view="read"][data-bg="gray"] { background: #2b2d31; }
body[data-view="read"][data-bg="white"] { background: #f4f3ef; }
.rbar, .rbot {
  position: fixed; left: 0; right: 0; z-index: 20; display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; background: rgba(12, 13, 16, .9); color: #ecebe8;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); transition: transform .22s ease;
}
.rbar { top: 0; min-height: var(--bar-h); padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid rgba(255, 255, 255, .08); }
.rbot { bottom: 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 1px solid rgba(255, 255, 255, .08); }
.rbar.hide { transform: translateY(-110%); }
.rbot.hide { transform: translateY(110%); }
.rbar .icon-btn:hover:not(:disabled), .rbot .icon-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .1); }
.rbar .tt { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.rbar .tt b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbar .tt span { font-size: 12px; color: #9da1a9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eps-btn {
  flex: 0 1 auto; min-width: 0; max-width: 46vw; display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 13px;
  border: 1px solid rgba(255, 255, 255, .16); border-radius: 999px; background: rgba(255, 255, 255, .07); color: #ecebe8; cursor: pointer;
}
.eps-btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13.5px; font-weight: 600; }
.eps-btn .ic { width: 16px; height: 16px; }
.eps-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
.epsheet { left: 12px; right: auto; top: auto; bottom: calc(66px + env(safe-area-inset-bottom)); width: 360px; max-height: 66vh; }
.sheet-h small { margin-left: 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
/* 集數面板捲到目前那一話時，標題列不要跟著捲走（-16px＝面板的 padding） */
.epsheet .sheet-h { position: sticky; top: -16px; z-index: 1; margin: -16px -16px 0; padding: 14px 16px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.eplist { display: flex; flex-direction: column; gap: 2px; margin: 0 -6px; }
.eplist a { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; }
.eplist a:hover { background: var(--panel-2); }
.eplist .n { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; min-width: 38px; height: 32px; padding: 0 5px; border-radius: 8px; background: var(--panel-2); font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }
.eplist .t { flex: 1; min-width: 0; font-size: 14px; }
.eplist .st { margin-left: auto; }
.eplist .ic.st { width: 16px; height: 16px; color: var(--ok); }
.eplist span.st { font-size: 12px; font-weight: 700; color: var(--accent); }
.eplist a.seen { color: var(--muted); }
.eplist a.seen .n { color: var(--faint); }
.eplist a.cur { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.eplist a.cur .n { background: var(--accent); color: var(--accent-ink); }
#rd-range { flex: 1; min-width: 60px; accent-color: var(--accent); }
.rbot .pgno { font-size: 12px; color: #9da1a9; font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 54px; text-align: right; }
.rprog { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 25; pointer-events: none; }
.rprog i { display: block; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform .15s linear; }
[dir="rtl"] .rprog i, .rtl .rprog i { transform-origin: right; }

.strip { margin: 0 auto; padding-top: calc(var(--bar-h) + env(safe-area-inset-top)); }
.pg { position: relative; container-type: inline-size; min-height: 60vh; background: #0b0b0c; }
.pg.done { min-height: 0; background: none; }
.pg.sized { min-height: 0; }
.pg img { display: block; width: 100%; height: auto; }
.gap-8 .pg + .pg { margin-top: 8px; }
.gap-24 .pg + .pg { margin-top: 24px; }
.pg .ph { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: #6c717b; font-size: 13px; }
.pg.bad .ph { color: var(--bad); }
.pg .tl {
  position: absolute; display: flex; align-items: center; justify-content: center; padding: 2px 4px;
  background: rgba(255, 255, 255, .95); color: #111; border: 1px solid rgba(0, 0, 0, .18); border-radius: 4px;
  font-size: 13px; font-size: clamp(10px, 2.3cqw, 20px); line-height: 1.25; text-align: center;
  overflow: visible; word-break: break-all; line-break: anywhere;
}
.pg .tl.empty { background: rgba(255, 255, 255, .55); color: #555; font-style: italic; }
.rend {
  display: flex; flex-direction: column; align-items: center; gap: 14px; color: #9da1a9;
  padding: 44px 16px calc(96px + env(safe-area-inset-bottom));
}
.rend-t { font-size: 18px; font-weight: 700; color: #ecebe8; }
.rend .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; border: 0; background: none; }
body[data-bg="white"] .rend, body[data-bg="white"] .rend-t { color: #1d1e21; }
#v-read .empty { color: #9da1a9; }

/* 翻頁模式：一次一頁，點左右兩側或左右滑動翻頁 */
.paged .strip { padding-top: 0; min-height: 100vh; display: flex; flex-direction: column; justify-content: center; }
.paged .pg, .paged .rend { display: none; }
/* width: 100% 不能省：.pg 有 container-type（譯文字級用），在 flex 裡沒給寬度會被算成 0、整頁看不到 */
.paged .pg.on { display: block; width: 100%; min-height: 0; background: none; }
.paged .pg.on img { width: auto; max-width: 100%; max-height: 100vh; margin: 0 auto; object-fit: contain; }
.paged .rend.on { display: flex; }
.paged .pg .ph { position: static; min-height: 60vh; }
.paged .pg.done .ph { display: none; }

.sheet {
  position: fixed; z-index: 35; right: 12px; top: calc(var(--bar-h) + 10px); width: 360px; max-width: calc(100vw - 24px);
  max-height: calc(100vh - var(--bar-h) - 90px); overflow: auto; display: flex; flex-direction: column; gap: 14px;
  padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); box-shadow: var(--shadow);
}
@media (max-width: 640px) {
  .sheet { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-width: none; max-height: 78vh; border-radius: 18px 18px 0 0; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
}
.sheet-h { display: flex; align-items: center; justify-content: space-between; }
.sheet .field { align-items: center; }
.sheet .field > span { font-size: 13.5px; color: var(--muted); }
.sheet .field input[type="range"] { flex: 1 1 160px; accent-color: var(--accent); }
.sheet .keys summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
.sheet .keys dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 10px 0 0; font-size: 13px; }
.sheet .keys dt { font-family: ui-monospace, Consolas, monospace; color: var(--accent); }
.sheet .keys dd { margin: 0; color: var(--muted); }
.sheet .hint { margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 30; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--text);
  box-shadow: var(--shadow); font-size: 13px; white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
