* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
  --bg: #14151a; --bg2: #1d1f26; --bg3: #262933; --fg: #e8e8ec; --fg2: #9a9aa5;
  --accent: #6c5ce7; --accent2: #8f7ff2; --danger: #e05555; --line: #2e313c;
  --topbar: 48px; --tabbar: 56px;
}
html.night { --bg: #000; --bg2: #0b0b0d; --bg3: #17171a; --fg: #c8c8cc; --fg2: #6a6a72; --line: #1e1e22; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none; touch-action: manipulation;
}
#app { max-width: 640px; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column; position: relative; overflow: hidden; }

/* topbar */
#topbar {
  height: calc(var(--topbar) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  display: flex; align-items: center; justify-content: space-between; padding-left: 16px; padding-right: 12px;
  background: var(--bg2); border-bottom: 1px solid var(--line); flex-shrink: 0; z-index: 20;
}
.tb-title { font-size: 17px; font-weight: 600; }
.tb-btn { background: none; border: none; font-size: 18px; color: var(--fg); padding: 8px; cursor: pointer; }

/* pages */
.page { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 8px); }
.page.hidden { display: none; }

/* tabbar */
#tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--bg2); border-top: 1px solid var(--line); z-index: 20;
}
.tab { flex: 1; background: none; border: none; color: var(--fg2); font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; }
.tab span { font-size: 11px; }
.tab.active { color: var(--accent2); }
.tab:first-child { font-size: 19px; }
.tab:nth-child(2) { font-size: 18px; }
.tab:nth-child(3) { font-size: 18px; }
.tab:nth-child(4) { font-size: 17px; }

/* searchbar */
.searchbar { display: flex; gap: 8px; padding: 12px 14px 6px; }
.searchbar input {
  flex: 1; height: 40px; border: none; border-radius: 10px; background: var(--bg3);
  color: var(--fg); padding: 0 14px; font-size: 15px; outline: none;
}
.searchbar button {
  height: 40px; padding: 0 18px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 15px; cursor: pointer;
}

/* chips */
.chip-row { display: flex; gap: 8px; padding: 8px 14px; overflow-x: auto; }
.chip {
  flex-shrink: 0; padding: 6px 16px; border-radius: 999px; border: none;
  background: var(--bg3); color: var(--fg2); font-size: 13px; cursor: pointer;
}
.chip.active { background: var(--accent); color: #fff; }

/* comic cards */
.list { padding: 8px 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 12px; }
.card { cursor: pointer; }
.card .cover { width: 100%; aspect-ratio: 3/4; border-radius: 10px; background: var(--bg3); object-fit: cover; display: block; }
.card .name { font-size: 13px; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .author { font-size: 11px; color: var(--fg2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* shelf list (wide) */
#shelfList { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
.badge {
  position: absolute; top: 6px; right: 6px; background: var(--danger); color: #fff;
  font-size: 10px; padding: 2px 6px; border-radius: 999px;
}
.src-tag {
  position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.65); color: #ffd166;
  font-size: 10px; padding: 2px 6px; border-radius: 6px; letter-spacing: .5px;
}
.card-wrap { position: relative; }

/* empty */
.empty { text-align: center; padding: 80px 20px; color: var(--fg2); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty .sub { font-size: 13px; margin-top: 6px; }

/* pager */
.pager { display: flex; justify-content: center; gap: 10px; padding: 14px; }
.pager button {
  padding: 8px 20px; border: none; border-radius: 10px; background: var(--bg3);
  color: var(--fg); font-size: 14px; cursor: pointer;
}
.pager button:disabled { opacity: .35; }

/* detail */
#detailBody { padding-bottom: 80px; }
.d-head { display: flex; gap: 14px; padding: 16px 14px; }
.d-cover { width: 110px; aspect-ratio: 3/4; border-radius: 10px; object-fit: cover; background: var(--bg3); flex-shrink: 0; }
.d-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.d-title { font-size: 18px; font-weight: 700; }
.d-meta { font-size: 12px; color: var(--fg2); line-height: 1.7; }
.d-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.d-tag { font-size: 11px; padding: 3px 10px; border-radius: 999px; background: var(--bg3); color: var(--fg2); }
.d-desc { padding: 0 14px 12px; font-size: 13px; color: var(--fg2); line-height: 1.8; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.d-desc.open { -webkit-line-clamp: unset; }
.d-actions { display: flex; gap: 10px; padding: 4px 14px 14px; }
.d-btn { flex: 1; height: 44px; border: none; border-radius: 10px; font-size: 15px; cursor: pointer; }
.d-btn.primary { background: var(--accent); color: #fff; }
.d-btn.ghost { background: var(--bg3); color: var(--fg); }
.ch-section { padding: 6px 14px 4px; font-size: 14px; font-weight: 600; }
.ch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; padding: 8px 14px; }
.ch-item {
  padding: 9px 4px; text-align: center; border-radius: 8px; background: var(--bg3);
  font-size: 12px; color: var(--fg); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ch-item.read { color: var(--fg2); opacity: .6; }
.ch-item.current { background: var(--accent); color: #fff; }

/* reader */
#pageRead { padding-bottom: 0; display: flex; flex-direction: column; }
#readerBar {
  position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 8px;
  height: var(--topbar); padding: 0 10px; background: rgba(20,21,26,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); transition: transform .25s;
}
html.night #readerBar { background: rgba(0,0,0,.92); }
#readerBar.hide { transform: translateY(-110%); }
.rb-btn { background: none; border: none; color: var(--fg); font-size: 14px; padding: 8px; cursor: pointer; flex-shrink: 0; }
.rb-title { flex: 1; text-align: center; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#readerBody { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; background: #000; }
#readerBody img { width: 100%; display: block; min-height: 100px; background: #0a0a0a; }
#readerBody .load-tip { color: #666; text-align: center; padding: 30px; font-size: 13px; }
#readFooter {
  position: sticky; bottom: 0; z-index: 15; display: flex; align-items: center; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); background: rgba(20,21,26,.92);
  backdrop-filter: blur(8px); border-top: 1px solid var(--line); transition: transform .25s;
}
html.night #readFooter { background: rgba(0,0,0,.92); }
#readFooter.hide { transform: translateY(110%); }
.rf-btn { background: var(--bg3); border: none; color: var(--fg); font-size: 12px; padding: 8px 10px; border-radius: 8px; cursor: pointer; flex-shrink: 0; }
#pageSlider { flex: 1; accent-color: var(--accent); }
#pageLabel { font-size: 12px; color: var(--fg2); min-width: 44px; text-align: center; }
.read-end { text-align: center; padding: 40px 20px 60px; color: #888; font-size: 14px; }
.read-end .btns { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.read-end button { padding: 10px 22px; border: none; border-radius: 10px; background: var(--accent); color: #fff; font-size: 14px; cursor: pointer; }

/* drawer */
#drawerMask { position: absolute; inset: 0; background: rgba(0,0,0,.55); z-index: 30; }
#drawer {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 70%; z-index: 31;
  background: var(--bg2); border-radius: 16px 16px 0 0; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); font-size: 15px; font-weight: 600; }
.drawer-head button { background: none; border: none; color: var(--accent2); font-size: 13px; cursor: pointer; }
#drawerList { overflow-y: auto; padding: 10px 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }

/* settings */
.settings { padding: 16px; }
.settings h3 { font-size: 15px; margin: 18px 0 8px; }
.settings h3:first-child { margin-top: 4px; }
.settings .sub { font-size: 12px; color: var(--fg2); margin-bottom: 8px; }
.settings textarea {
  width: 100%; background: var(--bg3); color: var(--fg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px; font-size: 12px; font-family: monospace; resize: vertical;
}
.wide-btn {
  width: 100%; height: 42px; margin-top: 10px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 14px; cursor: pointer;
}
.wide-btn.danger { background: var(--danger); }
.row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.version { margin-top: 24px; text-align: center; }
.local-actions { padding: 14px; text-align: center; }
.file-btn {
  display: inline-block; padding: 10px 24px; background: var(--accent); color: #fff;
  border-radius: 10px; font-size: 14px; cursor: pointer;
}
.local-actions .sub { margin-top: 8px; }

/* toast & loading */
#toast {
  position: absolute; top: 68px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: rgba(0,0,0,.8); color: #fff; padding: 9px 18px; border-radius: 999px; font-size: 13px;
  max-width: 80%; text-align: center;
}
#loading { position: absolute; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.25); }
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.2); border-top-color: var(--accent2); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }
img { -webkit-user-drag: none; user-select: none; }
