:root {
  --bg: #17212b;       /* telegram-ish dark */
  --panel: #1e2c3a;
  --panel-2: #243447;
  --text: #e9eef3;
  --muted: #8aa0b2;
  --accent: #5eb5f7;
  --accent-2: #2b8fd6;
  --ok: #4caf50;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: 40px;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  border-bottom: 1px solid #0d1620;
}
.brand { font-weight: 700; }
.spacer { flex: 1; }
.ghost {
  background: transparent; border: 0; color: var(--text);
  font-size: 26px; line-height: 1; cursor: pointer; padding: 0 6px;
}
#site-select, #sort-select, input[type=search], button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid #0d1620; border-radius: 8px;
  padding: 8px 10px; font: inherit;
}
input[type=search] { flex: 1; min-width: 0; }
button { cursor: pointer; }
button:hover { background: #2c4156; }

.search { display: flex; gap: 8px; padding: 12px; }
.filters {
  display: flex; flex-wrap: wrap; gap: 8px 12px;
  padding: 0 12px 10px;
}
.filters label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
}
.filters select { padding: 5px 8px; font-size: 13px; }
.status { padding: 0 12px 8px; color: var(--muted); font-size: 13px; }
/* «Subscriptions» site-select entry: just the grid + sort/order, hide catalog
   search and the catalog-only filters (official/anime/adult). */
body.subs-mode .search,
body.subs-mode .filter-catalog { display: none; }
.sentinel { height: 1px; }

.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(3, 1fr);
  padding: 4px 12px;
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.card {
  background: var(--panel); border-radius: var(--radius); overflow: hidden;
  cursor: pointer; display: flex; flex-direction: column; position: relative;
  border: 1px solid transparent; transition: border-color .12s;
}
.card:hover { border-color: var(--accent); }
.card img { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; background: #0d1620; }
.pill {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  background: var(--accent-2); color: #fff; font-size: 11px; line-height: 1;
  padding: 4px 7px; border-radius: 999px; box-shadow: 0 1px 3px rgba(0,0,0,.45);
}
.card-title {
  padding: 6px 8px; font-size: 12px; line-height: 1.3;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

.loading { padding: 24px; color: var(--muted); text-align: center; }
.title-h { margin: 16px 14px 8px; font-size: 22px; }
.title-body { display: flex; gap: 14px; padding: 0 14px 12px; }
.cover { width: 140px; aspect-ratio: 2/3; object-fit: cover; border-radius: var(--radius); flex: none; background: #0d1620; }
.title-meta { display: flex; flex-direction: column; gap: 10px; }
.synopsis { color: var(--muted); margin: 0; }
.last-updated { color: var(--muted); margin: 0; font-size: 13px; }
.subscribe {
  align-self: flex-start; background: var(--accent-2); border-color: transparent; color: #fff; font-weight: 600;
}
.subscribe.done { background: var(--ok); }
.sub-note { color: var(--muted); font-size: 12px; }

h2 { margin: 18px 14px 8px; font-size: 16px; color: var(--muted); }
.chapter-list { padding: 0 14px; }
.chapter {
  padding: 9px 12px; border-bottom: 1px solid #0d1620;
  background: var(--panel); border-radius: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chapter:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.chapter:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.chapter.more { color: var(--muted); font-style: italic; }
.chapter.downloaded { color: var(--ok); font-weight: 600; }
.chapter.downloaded::after { content: "  ✓"; }

.chapter { cursor: pointer; transition: background .1s; }
.chapter:hover { background: var(--panel-2); }
body.selecting .chapter { padding-left: 34px; position: relative; }
body.selecting .chapter::before {
  content: ""; position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; border-radius: 4px; border: 2px solid var(--muted);
  box-sizing: border-box;
}
.chapter.selected { background: rgba(94, 181, 247, .18); }
.chapter.selected::before {
  content: "✓"; background: var(--accent); border-color: var(--accent); color: #fff;
  font-size: 12px; line-height: 14px; text-align: center; font-weight: 700;
}

.select-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel-2); border-top: 1px solid #0d1620;
  max-width: 720px; margin: 0 auto;
}

.hidden { display: none !important; }
