:root {
  --bg: #111317;
  --panel: #191c22;
  --panel-2: #20242c;
  --line: #2a2f39;
  --text: #e6e8ec;
  --muted: #8b93a1;
  --accent: #4f8cff;
  --accent-2: #2f6ae0;
  --danger: #e5534b;
  --warn: #d9a441;
  --ok: #3fa66a;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: rgba(17,19,23,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .5px; color: var(--accent); }
.search { flex: 1; display: flex; gap: 8px; max-width: 520px; }
.search input {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  outline: none;
}
.search input:focus { border-color: var(--accent); }
.search button {
  padding: 8px 14px; border-radius: 8px; border: 0;
  background: var(--accent); color: #fff; cursor: pointer;
}
.nav { display: flex; align-items: center; gap: 14px; color: var(--muted); }
.nav a:hover { color: var(--text); }
.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.ghost:hover { color: var(--text); border-color: var(--accent); }

main { padding: 18px 16px 60px; max-width: 1180px; margin: 0 auto; }

.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; cursor: pointer; transition: transform .12s, border-color .12s;
  display: flex; flex-direction: column;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.cover {
  aspect-ratio: 3/4; background: var(--panel-2); position: relative; overflow: hidden;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .ph {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; color: var(--muted); font-size: 12px; padding: 8px;
  text-align: center;
}
.card-body { padding: 10px; }
.card-title {
  font-weight: 600; font-size: 13px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 36px;
}
.card-meta { color: var(--muted); font-size: 12px; margin-top: 6px; display: flex;
  justify-content: space-between; align-items: center; gap: 6px; }
.badge {
  background: var(--danger); color: #fff; border-radius: 999px;
  padding: 1px 7px; font-size: 11px; font-weight: 700;
}

.row {
  display: flex; gap: 10px; padding: 10px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel); margin-bottom: 8px; align-items: center;
}
.row img { width: 44px; height: 60px; object-fit: cover; border-radius: 6px; background: var(--panel-2); }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; }
.row .m { color: var(--muted); font-size: 12px; margin-top: 2px; }
.btn {
  border: 0; border-radius: 8px; padding: 7px 12px; cursor: pointer;
  background: var(--accent); color: #fff; white-space: nowrap;
}
.btn.sec { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 4px 0 14px;
}
.section-title h2 { font-size: 18px; margin: 0; }
.hint { color: var(--muted); font-size: 12px; }

.detail-head { display: flex; gap: 16px; margin-bottom: 18px; }
.detail-head .cover { width: 130px; flex: 0 0 130px; border-radius: 10px; }
.detail-head h1 { margin: 0 0 6px; font-size: 20px; }
.meta-line { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.chapters { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.ch {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); cursor: pointer; font-size: 13px;
}
.ch:hover { border-color: var(--accent); }
.ch.read { opacity: .55; }
.ch .src { color: var(--muted); font-size: 11px; }

.reader { max-width: 860px; margin: 0 auto; }
.reader img { width: 100%; display: block; background: var(--panel-2); margin: 0 auto; }
.reader .pager {
  display: flex; justify-content: space-between; gap: 10px; padding: 16px 0 40px;
}
.empty {
  text-align: center; color: var(--muted); padding: 60px 20px;
}

.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.login-card {
  width: 320px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 26px; display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 20px; color: var(--accent); }
.login-card .sub { margin: -6px 0 8px; color: var(--muted); font-size: 12px; }
.login-card input {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  padding: 10px; border-radius: 8px; border: 0; background: var(--accent);
  color: #fff; cursor: pointer; font-weight: 600;
}
.login-card .err { color: var(--danger); font-size: 12px; min-height: 16px; margin: 0; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 9px 16px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: all .2s; font-size: 13px; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.health-ok { color: var(--ok); }
.health-degraded { color: var(--warn); }
.health-down { color: var(--danger); }

@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .brand { font-size: 15px; }
  main { padding: 12px 10px 40px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 10px; }
  .detail-head .cover { width: 96px; flex-basis: 96px; }
  .chapters { grid-template-columns: 1fr 1fr; }
  .ch { font-size: 12px; padding: 8px; }
}

.row.clickable { cursor: pointer; }
.row.clickable:hover { border-color: var(--accent); }
.tag {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  border: 1px solid var(--warn); color: var(--warn);
  border-radius: 6px; font-size: 11px; vertical-align: middle;
}
.ch.disabled {
  opacity: .45; cursor: not-allowed; border-style: dashed;
}
.ch.disabled:hover { border-color: var(--line); }
.section-title .hint .ghost { padding: 3px 8px; font-size: 12px; }

body.reader-lock { overflow: hidden; }

.reader-head { margin-bottom: 10px; }

.reader-nav {
  margin-bottom: 12px;
}
.reader-nav .back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
}
.reader-nav .back:hover {
  border-color: var(--accent);
}
.reader-stage {
  background: #0b0c0f;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.reader-stage.paged {
  height: calc(100vh - 196px);
  height: calc(100dvh - 196px);
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  overflow-x: hidden;
}
.reader-stage.paged img {
  width: 100%;
  height: auto;
  display: block;
  margin: auto 0;
}
.reader-stage.paged.two img { max-width: 49.5%; }

.reader-stage.scroll {
  height: auto;
  display: block;
  border: none;
  border-radius: 0;
  background: transparent;
}
.reader-stage.scroll img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 0.7;
  margin: 0 auto;
  background: var(--panel-2);
}
.reader-stage.scroll img.broken {
  min-height: 160px;
  background: var(--panel-2);
}
.pager {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 0 40px;
}

.reader-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 10px;
}
.reader-nav .btn { min-width: 92px; }
.reader-nav .hint { min-width: 72px; text-align: center; font-variant-numeric: tabular-nums; }

.fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(32, 36, 44, .92);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .45);
  backdrop-filter: blur(6px);
}
.fab:hover { border-color: var(--accent); color: var(--accent); }

@media (max-width: 640px) {
  .reader-stage.paged { height: calc(100vh - 172px); height: calc(100dvh - 172px); }
  .reader-nav .btn { min-width: 76px; padding: 7px 10px; }
}

.row.dim { opacity: .5; }
.row.dim:hover { border-color: var(--line); }
.row .latest { color: var(--muted); font-size: 12px; margin-top: 2px; }

.reader-stage.paged { cursor: pointer; }
.reader-counter {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 30;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(17, 19, 23, .88);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px);
  pointer-events: none;
}
@media (max-width: 640px) {
  .reader-counter { bottom: 12px; }
}

/* ---- Google Drive download button on card ---- */
.gdrive-btn {
  position: absolute;
  bottom: 6px;
  right: 6px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(17,19,23,.82);
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  backdrop-filter: blur(6px);
  transition: color .15s, border-color .15s, background .15s;
  overflow: hidden;
}
.gdrive-btn:hover { color: var(--accent); border-color: var(--accent); }
.gdrive-btn svg { flex-shrink: 0; }
.gdrive-label { white-space: nowrap; }
.gdrive-progress {
  position: absolute; left: 0; bottom: 0; width: 100%; height: 3px;
  background: rgba(255,255,255,.08); border-radius: 0 0 8px 8px;
  overflow: hidden; opacity: 0; transition: opacity .2s;
}
.gdrive-btn.active .gdrive-progress { opacity: 1; }
.gdrive-progress-bar {
  width: 0; height: 100%;
  background: var(--accent);
  border-radius: 0 0 8px 8px;
  transition: width .4s ease;
}
.gdrive-btn.active { color: var(--accent); border-color: var(--accent); pointer-events: none; }
.gdrive-btn.done { color: var(--ok); border-color: var(--ok); }
.gdrive-btn.done .gdrive-progress { opacity: 1; }
.gdrive-btn.done .gdrive-progress-bar { background: var(--ok); }

/* ---- Inline progress on series detail button ---- */
.gdrive-inline-icon { font-weight: 700; }
.gdrive-inline-pct { font-variant-numeric: tabular-nums; }
.gdrive-inline-bar-wrap {
  position: absolute; left: 0; bottom: 0; width: 100%; height: 3px;
  background: rgba(255,255,255,.06); border-radius: 0 0 8px 8px;
  overflow: hidden;
}
.gdrive-inline-bar {
  width: 0; height: 100%;
  background: var(--accent);
  transition: width .4s ease;
}
#gdrive-dl { position: relative; overflow: hidden; }
