/* [新增] 2026-10-03 前後端隔離：原本是 index.html 裡的行內 <style>。
   由 web/（Caddy file_server）提供，CSP 是 style-src 'self'，所以不能再回去用行內樣式或 style="" 屬性。 */
:root {
  --bg: #0f1012;
  --panel: #17181b;
  --panel-2: #1f2125;
  --line: #2a2d32;
  --text: #e8e6e3;
  --muted: #9a9ca3;
  --faint: #6b6e75;
  --accent: #e8a33d;
  --accent-ink: #1a1204;
  --ok: #58b37a;
  --bad: #d4645c;
  --radius: 10px;
  --bar-h: 52px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC",
    "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body[data-view="read"] { background: #000; }

a { color: inherit; text-decoration: none; }

button, input, select { font: inherit; color: inherit; }

[hidden] { display: none !important; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.sm { padding: 4px 10px; font-size: 13px; }

.chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11px;
  line-height: 17px;
  color: var(--muted);
  white-space: nowrap;
}
/* [刪除] 2026-10-04 .chip.wt：卡片不再標 WEBTOON，只有 comix 的「機翻」（.chip.cx） */
.chip.cx { color: #f0b36a; border-color: #5c4424; }
.chip.tl { color: var(--ok); border-color: #2b5139; }
.chip.of { color: #c9b3ff; border-color: #4a3a6e; }
.ep.ext { border-style: dashed; }
.ep.ext .sub { color: #c9b3ff; }

.msg { padding: 40px 16px; text-align: center; color: var(--muted); }
.msg.err { color: var(--bad); }
.msg .btn { margin-top: 14px; }
.msg .btn + .btn { margin-left: 8px; }

header.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(15, 16, 18, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
header.top .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; letter-spacing: .02em; white-space: nowrap; }
header.top .brand img { width: 26px; height: 26px; display: block; }
header.top .sp { flex: 1; }
/* [新增] 2026-10-04 手機：標題只留 icon，空間給搜尋框 */
@media (max-width: 520px) {
  header.top { gap: 8px; padding-left: 12px; padding-right: 12px; }
  header.top .brand span { display: none; }
  header.top .sp { display: none; }
}
#lib-sort { appearance: none; -webkit-appearance: none; flex: 0 0 auto; padding-right: 12px; }

/* [新增] 2026-10-04 帳號選單（改密碼／會員管理／登出），用 <details> 開關 */
.menu { position: relative; flex: 0 0 auto; }
.menu > summary { list-style: none; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { border-color: var(--muted); }
.menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 150px;
  display: flex;
  flex-direction: column;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.menu-pop a, .menu-pop button {
  display: block;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 6px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.menu-pop a:hover, .menu-pop button:hover { background: var(--panel-2); }
.menu-pop button { color: var(--bad); }

#q {
  flex: 0 1 260px;
  min-width: 0;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  outline: none;
}
#q:focus { border-color: var(--muted); }

main.wrap { max-width: 1200px; margin: 0 auto; padding: 16px 16px 48px; }

h2.sec { margin: 8px 0 12px; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .04em; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px 14px;
}
@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 14px 10px; }
}

.card { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.card.dim { opacity: .5; }
.card:hover .cover { border-color: var(--muted); }

.cover {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.none::after {
  content: attr(data-initial);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  font-weight: 700;
  color: var(--faint);
}
/* [新增] 2026-10-04 上次看之後有新的話 */
.cover .upd {
  position: absolute;
  right: 6px;
  top: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 700;
}
.cover .prog {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .72);
  font-size: 11px;
  color: #fff;
}

.card .nm {
  font-weight: 600;
  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 { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 12px; color: var(--muted); }

/* [刪除] 2026-10-04 .cont（首頁「繼續閱讀」橫排）：首頁只留一份清單 */

.whead { display: flex; gap: 18px; align-items: flex-start; margin: 4px 0 18px; }
.whead .cover { width: 132px; flex: 0 0 auto; }
.whead .info { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.whead h1 { margin: 0; font-size: 22px; line-height: 1.3; }
.whead .en { color: var(--muted); }
.whead .acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
@media (max-width: 520px) {
  .whead { gap: 12px; }
  .whead .cover { width: 92px; }
  .whead h1 { font-size: 18px; }
}

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

.eptools { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.eptools .sp { flex: 1; }

.eps {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
@media (max-width: 520px) { .eps { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); } }

.ep {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  min-width: 0;
}
a.ep:hover { border-color: var(--muted); }
.ep .no { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.ep .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ep.seen .no { color: var(--muted); font-weight: 500; }
/* [修改] 2026-10-04 看過的話整格變淡（Mihon / WEBTOON），上次看到的那話維持亮的、橘框 */
.ep.seen { opacity: .55; }
.ep.cur { border-color: var(--accent); opacity: 1; }
.ep.cur .sub { color: var(--accent); }
.chip.up { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 700; }

/* [新增] 2026-10-04 手機上作品頁底部固定的主要按鈕（桌機不顯示，用標題旁那顆） */
.wfab { display: none; }
@media (max-width: 640px) {
  .wfab:not([hidden]) {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 15;
    display: flex;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, rgba(15, 16, 18, .98) 70%, rgba(15, 16, 18, 0));
  }
  .wfab .btn { flex: 1; justify-content: center; padding: 11px 16px; font-size: 15px; }
  .whead .acts .btn.primary { display: none; }
  #v-work { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
}
.ep.off { opacity: .45; cursor: not-allowed; }

.rbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--bar-h);
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(12, 12, 14, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  transition: transform .2s ease;
}
.rbar.hide { transform: translateY(-110%); }
/* [新增] 2026-10-04 頁碼與細進度條（MangaDex 的 lightbar）：進度條固定在最上面，工具列收起來也看得到 */
.rbar .pgno { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.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;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + 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: rgba(23, 24, 27, .96);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  font-size: 13px;
  white-space: nowrap;
}
.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: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbar .sp { flex: 1; }
.rbar select.btn { appearance: none; -webkit-appearance: none; padding-right: 14px; }
@media (max-width: 640px) {
  .rbar { flex-wrap: wrap; }
  .rbar .tt { flex: 1 1 calc(100% - 90px); }
  .rbar .sp { display: none; }
  .rbar .wide { display: none; }
}

.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; }        /* [新增] 2026-10-04 高度改由 aspect-ratio（第一張圖的長寬比）撐住 */
.pg img { display: block; width: 100%; height: auto; }
.pg .ph {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--faint);
  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, .94);
  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: 12px;
  padding: 36px 16px calc(56px + env(safe-area-inset-bottom));
  color: var(--muted);
  background: var(--bg);
}
.rend .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.login {
  max-width: 360px;
  margin: 12vh auto 0;
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}
.login h1 { margin: 0 0 6px; font-size: 20px; }
.login p { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.login input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  outline: none;
}
.login input:focus { border-color: var(--muted); }
.login .btn { width: 100%; justify-content: center; }
.login .err { min-height: 20px; margin-top: 10px; color: var(--bad); font-size: 13px; }
.login .ok { color: var(--ok); }

.adm-new { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.adm-new input, .adm-new select {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  outline: none;
}
.adm-new input { flex: 1 1 260px; min-width: 0; }
.notice {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid #5c4424;
  border-radius: 8px;
  background: #241c10;
  word-break: break-all;
}
.notice code { font-size: 15px; color: var(--accent); user-select: all; }
.tbl { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 24px; }
.tbl .row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.tbl .row:first-child { border-top: 0; }
.tbl .row .nm { font-weight: 600; min-width: 120px; }
.tbl .row .m { color: var(--muted); font-size: 12px; }
.tbl .row .sp { flex: 1; }
.tbl .row.off .nm { color: var(--faint); text-decoration: line-through; }
.tbl .empty { padding: 16px; color: var(--muted); text-align: center; }
#me-form { margin-top: 6vh; }

/* ── [新增] 2026-10-04 管理後台（admin.js）：總覽／人員／漫畫／紀錄 ── */
.chip.bad { color: var(--bad); border-color: #5e2b28; }
.chip.warn { color: var(--accent); border-color: #5c4424; }
.chip.tag { color: var(--text); border-color: var(--line); background: var(--panel-2); }
a.chip:hover { border-color: var(--muted); }
.whead .meta { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.btn.danger { color: var(--bad); }
.btn.danger:hover:not(:disabled) { border-color: var(--bad); }

.adm-tabs { display: flex; gap: 4px; margin: 0 0 18px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.adm-tabs a {
  padding: 8px 14px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.adm-tabs a:hover { color: var(--text); }
.adm-tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 24px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  min-width: 0;
}
a.tile:hover { border-color: var(--muted); }
.tile .lb { font-size: 12px; color: var(--muted); }
.tile .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .m { font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.adm-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 12px; }
.adm-head h2.sec { margin: 0; flex: 1 1 auto; }
.adm-head input, .adm-head select, .adm-new input, .adm-new select, .adm-form input, .adm-form textarea {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  outline: none;
  min-width: 0;
}
.adm-head input { flex: 0 1 240px; }
.adm-head input:focus, .adm-new input:focus, .adm-form input:focus, .adm-form textarea:focus { border-color: var(--muted); }
.adm-new input[type="date"] { flex: 0 0 auto; }
.adm-new input[type="date"]:disabled { opacity: .4; }
.m.hint { color: var(--faint); font-size: 12px; margin: -4px 0 12px; }

.btn.back { margin-bottom: 14px; }
.adm-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.adm-title h1 { margin: 0; font-size: 22px; }
.m.sub { color: var(--muted); font-size: 13px; margin: 6px 0 18px; }
.adm-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 640px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.adm-form .fld { display: flex; flex-direction: column; gap: 4px; }
.adm-form .fld .lb { font-size: 12px; color: var(--muted); }
.adm-form .fld .m { font-size: 12px; color: var(--faint); }
.adm-form textarea { min-height: 72px; resize: vertical; font: inherit; }
.adm-form input[type="date"] { max-width: 200px; }
.adm-form input:disabled { opacity: .4; }
.adm-form .acts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.adm-form .acts .m { color: var(--faint); font-size: 12px; }
.chk { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 2px 0; }
.chk input { width: 16px; height: 16px; accent-color: var(--accent); }
.adm-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.btn.more { display: block; margin: -12px auto 24px; }

.tbl .row a.nm:hover { color: var(--accent); }
.tbl .row .m.note { color: var(--text); opacity: .75; }
.tbl .row .m.tm { min-width: 76px; }
.tbl .row.work { flex-wrap: nowrap; align-items: center; }
.tbl .row.work .thumb {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  overflow: hidden;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.tbl .row.work .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tbl .row.work .thumb.none::after {
  content: attr(data-initial);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--faint);
}
.tbl .row.work .wi { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.tbl .row.work .wl { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.tbl .row.work .wi .m { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tbl .row.work .acts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; flex: 0 0 auto; }
@media (max-width: 620px) {
  .tbl .row.work { flex-wrap: wrap; }
  .tbl .row.work .acts { width: 100%; justify-content: flex-start; }
}
