:root {
  --bg: #0d0d12;
  --bg2: #15151d;
  --bg3: #1e1e28;
  --card: #17171f;
  --border: #262633;
  --text: #e8e8ef;
  --text2: #9a9ab0;
  --accent: #ff7a1a;
  --accent2: #ffb347;
  --danger: #e05252;
  --ok: #3ddc84;
  --radius: 12px;
  --nav-h: 60px;
}
* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html { scroll-behavior:smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100dvh;
}
a { color: var(--accent2); text-decoration: none; }
img { display:block; }
button { font-family: inherit; }

#app { max-width: 860px; margin: 0 auto; padding: 0 14px calc(var(--nav-h) + 30px); }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(13,13,18,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  margin: 0 -14px 16px;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.topbar .logo { font-weight: 800; font-size: 18px; letter-spacing: -0.02em; }
.topbar .logo span { color: var(--accent); }
.topbar .spacer { flex: 1; }
.back-btn {
  background: none; border: none; color: var(--text);
  font-size: 16px; padding: 6px; cursor: pointer; display: flex; align-items: center;
}
.back-btn svg { width: 22px; height: 22px; }

/* ---------- cards grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform .15s ease;
}
.card:active { transform: scale(0.97); }
.card .cover-wrap { position: relative; aspect-ratio: 2/3; background: var(--bg2); }
.card .cover-wrap img { width: 100%; height: 100%; object-fit: cover; }
.card .badge {
  position: absolute; top: 6px; left: 6px;
  background: rgba(0,0,0,0.75); color: #fff;
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px;
  letter-spacing: 0.03em; text-transform: uppercase;
  backdrop-filter: blur(4px);
}
.card .badge.ongoing { color: var(--accent2); }
.card .badge.completed { color: var(--ok); }
.card .type-tag {
  position: absolute; bottom: 6px; right: 6px;
  background: var(--accent); color: #fff;
  font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 4px;
  letter-spacing: 0.02em;
}
.card .color-tag {
  position: absolute; bottom: 6px; left: 6px;
  background: rgba(98, 58, 190, 0.92); color: #fff;
  font-size: 9px; font-weight: 700; padding: 2px 6px; border-radius: 4px;
  letter-spacing: 0.02em;
}
.card .info { padding: 8px 9px 10px; }
.card .title {
  font-size: 12.5px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 34px;
}
.card .meta { margin-top: 4px; font-size: 10.5px; color: var(--text2); display: flex; justify-content: space-between; }
.card .rating { color: var(--accent2); font-weight: 600; }

/* ---------- section ---------- */
.section-title { font-size: 16px; font-weight: 700; margin: 18px 0 10px; display:flex; align-items:center; gap:8px; }
.section-title .bar { width: 4px; height: 16px; background: var(--accent); border-radius: 2px; }

/* ---------- chips / filters ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; background: var(--bg3); color: var(--text2);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 6px 14px; font-size: 13px; cursor: pointer; transition: all .15s;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.genre-picker-btn {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 11px 14px; margin-bottom: 14px; cursor: pointer;
}
.genre-picker-btn b { color: var(--accent2); font-size: 13px; }
.genre-panel {
  position: fixed; inset: 0; z-index: 180; background: var(--bg);
  padding: 16px; overflow-y: auto;
}
.genre-panel-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; font-size:18px; }
.genre-panel-head button { background:none; border:none; color:var(--text); font-size:32px; line-height:1; cursor:pointer; }
.genre-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; padding-bottom:24px; }
.genre-option { text-align:left; background:var(--card); color:var(--text2); border:1px solid var(--border); border-radius:9px; padding:10px; cursor:pointer; }
.genre-option.active { border-color:var(--accent); color:var(--accent2); }

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 14px; margin-bottom: 14px;
}
.search-box svg { width: 18px; height: 18px; color: var(--text2); flex-shrink: 0; }
.search-box input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text); font-size: 15px; font-family: inherit;
}
.search-box input::placeholder { color: var(--text2); }

/* ---------- detail ---------- */
.detail-hero {
  position: relative; border-radius: 16px; overflow: hidden;
  margin-bottom: 16px; background: var(--bg2);
}
.detail-hero .bg-cover {
  position: absolute; inset: 0; background-size: cover; background-position: center top;
  filter: blur(28px) brightness(0.45); transform: scale(1.2);
}
.detail-hero .content {
  position: relative; display: flex; gap: 16px; padding: 18px;
  background: linear-gradient(180deg, rgba(13,13,18,0.1), rgba(13,13,18,0.88) 70%);
}
.detail-hero .cover {
  width: 128px; flex-shrink: 0; border-radius: 10px; overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5); aspect-ratio: 2/3;
}
.detail-hero .cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-hero .meta { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; min-width: 0; }
.detail-hero h1 { font-size: 20px; font-weight: 800; line-height: 1.25; letter-spacing: -0.01em; }
.detail-hero .sub { margin-top: 6px; font-size: 13px; color: var(--text2); display: flex; flex-wrap: wrap; gap: 6px 12px; }
.detail-hero .sub b { color: var(--text); font-weight: 600; }
.detail-hero .sub .rating { color: var(--accent2); font-weight: 700; }
.chips.genres { margin-top: 10px; }

.detail-section { margin: 18px 0; }
.detail-section h2 { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.detail-section .desc { color: var(--text2); font-size: 13.5px; white-space: pre-line; }

.chapter-list { list-style: none; }
.chapter-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px;
  cursor: pointer; transition: border-color .15s;
}
.chapter-list li:active { border-color: var(--accent); }
.chapter-list .c-title { font-size: 14px; font-weight: 500; }
.chapter-list .c-date { font-size: 11.5px; color: var(--text2); margin-top: 2px; }
.chapter-list .c-read { color: var(--ok); font-size: 11px; font-weight: 600; }

/* ---------- reader ---------- */
.reader-top {
  position: sticky; top: 0; z-index: 60;
  background: rgba(8,8,11,0.9); backdrop-filter: blur(12px);
  border-bottom: 1px solid #1c1c24;
  margin: 0 -14px; padding: 10px 14px;
  display: flex; align-items: center; gap: 10px;
}
.reader-top .r-title { font-size: 13.5px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-top button {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 12px; font-size: 12.5px; cursor: pointer; font-weight: 600;
}
.reader-top button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.reader-body { padding-top: 14px; }
.reader-body .page-img {
  width: 100%; margin-bottom: 4px; background: #0a0a0e; min-height: 60px; cursor: pointer;
}
.reader-body .page-img img { width: 100%; height: auto; opacity: 0; transition: opacity .25s ease; }
.reader-body .page-img img.loaded { opacity: 1; }

.reader-nav { display: flex; gap: 10px; margin: 18px 0; }
.reader-nav button {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: 10px; padding: 13px; font-size: 14px;
  font-weight: 600; cursor: pointer;
}
.reader-nav button:disabled { opacity: 0.35; cursor: default; }
.reader-nav button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

.reader-loading { text-align: center; padding: 60px 0; color: var(--text2); }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 14px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- bookmarks ---------- */
.bm-item {
  display: flex; gap: 12px; padding: 12px; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; cursor: pointer;
}
.bm-item img { width: 52px; height: 72px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.bm-item .bm-info { flex: 1; min-width: 0; }
.bm-item .bm-title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-item .bm-sub { font-size: 12px; color: var(--text2); margin-top: 4px; }
.bm-item .bm-sub b { color: var(--accent2); }
.bm-item .bm-actions { display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.bm-item .bm-del {
  background: none; border: none; color: var(--danger); font-size: 11px; cursor: pointer; padding: 4px;
}

/* ---------- misc ---------- */
.empty { text-align: center; padding: 60px 16px; color: var(--text2); }
.empty svg { width: 48px; height: 48px; margin: 0 auto 12px; opacity: 0.4; }
.load-more {
  display: block; width: 100%; margin: 16px 0 8px; padding: 13px;
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.load-more:disabled { opacity: 0.5; }

#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: rgba(17,17,23,0.92); backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: flex; height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1; background: none; border: none; color: var(--text2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10.5px; font-weight: 600; cursor: pointer; transition: color .15s;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn.active { color: var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%) translateY(20px);
  background: #2a2a36; color: var(--text); padding: 10px 20px; border-radius: 24px;
  font-size: 13px; font-weight: 500; z-index: 200; opacity: 0; pointer-events: none;
  transition: all .25s ease; box-shadow: 0 6px 24px rgba(0,0,0,0.4);
  max-width: 90%; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hidden { display: none !important; }
