:root {
  --bg: var(--tg-theme-bg-color, #0f0f0f);
  --text: var(--tg-theme-text-color, #fff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #888);
  --link: var(--tg-theme-link-color, #4a9eff);
  --button: var(--tg-theme-button-color, #4a9eff);
  --button-text: var(--tg-theme-button-text-color, #fff);
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  min-height: 100vh;
}

/* ---------- loading ---------- */
#loading-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg); z-index: 1000; transition: opacity .3s;
}
.shimmer-logo {
  width: 60px; height: 60px; border-radius: 12px; margin-bottom: 16px;
  background: linear-gradient(90deg, var(--secondary-bg) 25%, var(--hint) 50%, var(--secondary-bg) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
}
.loading-text { color: var(--hint); font-size: 14px; text-transform: lowercase; }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* ---------- header ---------- */
#main-header { padding: 16px 20px 12px; display: flex; justify-content: space-between; align-items: flex-start; }
.greeting h1 { margin: 0; font-size: 28px; font-weight: 700; text-transform: lowercase; }
.greeting .subtitle { margin: 4px 0 0; color: var(--hint); font-size: 14px; }
.header-actions { display: flex; gap: 10px; }
.icon-btn {
  background: var(--secondary-bg); border: none; color: var(--text);
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: transform .1s; font-size: 17px;
}
.icon-btn:active { transform: scale(.92); }

/* ---------- genre chips ---------- */
#genre-bar {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 0 20px 6px; margin-bottom: 10px;
  scrollbar-width: none;
}
#genre-bar::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; background: var(--secondary-bg); border: 1px solid transparent;
  color: var(--text); padding: 7px 14px; border-radius: 20px;
  font-size: 13px; cursor: pointer; transition: all .15s;
}
.chip:active { transform: scale(.95); }
.chip.active { background: var(--button); color: var(--button-text); border-color: var(--button); }

/* ---------- sections & cards ---------- */
.section { margin-bottom: 24px; }
.section-title { font-size: 18px; font-weight: 600; margin: 0 0 12px 20px; text-transform: lowercase; }
.rail-ico { margin-right: 8px; color: var(--link); font-size: 15px; }

.horizontal-scroll {
  display: flex; gap: 12px; overflow-x: auto; padding: 0 20px;
  scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.horizontal-scroll::-webkit-scrollbar { display: none; }

.manga-card { flex: 0 0 140px; scroll-snap-align: start; cursor: pointer; transition: transform .2s; }
.manga-card:active { transform: scale(.98); }
.card-poster {
  width: 140px; height: 200px; background: var(--secondary-bg);
  border-radius: var(--radius); overflow: hidden; position: relative; margin-bottom: 8px;
}
.card-poster img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .3s; }
.card-poster img.loaded { opacity: 1; }
.card-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,.72); color: #fff; padding: 2px 7px;
  border-radius: 5px; font-size: 11px; font-weight: 600;
}
.card-title {
  font-size: 13px; font-weight: 600; margin: 0; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { font-size: 11px; color: var(--hint); margin-top: 2px; }
.card-meta i { margin-right: 4px; font-size: 10px; }

/* ---------- skeletons ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--secondary-bg) 25%, #2a2a2a 50%, var(--secondary-bg) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius);
}
.skeleton-card { flex: 0 0 140px; }
.skeleton-poster { width: 140px; height: 200px; margin-bottom: 8px; }
.skeleton-title { height: 14px; width: 120px; margin-bottom: 4px; }
.skeleton-meta { height: 10px; width: 80px; }

/* ---------- load more ---------- */
.more-btn {
  display: block; margin: 14px auto 0;
  background: var(--secondary-bg); border: none; color: var(--text);
  padding: 10px 20px; border-radius: 10px; font-size: 14px; cursor: pointer;
}
.more-btn:active { opacity: .8; }
.more-btn i { margin-right: 7px; color: var(--link); }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; transition: opacity .3s; }
.modal.hidden { opacity: 0; pointer-events: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.modal-content {
  position: relative; background: var(--bg); border-radius: 20px 20px 0 0;
  width: 100%; max-height: 92vh; overflow-y: auto; padding: 20px;
  transform: translateY(0); transition: transform .3s;
}
.modal.hidden .modal-content { transform: translateY(100%); }
.modal-close {
  position: absolute; top: 12px; right: 12px; z-index: 10;
  background: var(--secondary-bg); border: none; color: var(--text);
  width: 36px; height: 36px; border-radius: 50%; font-size: 16px; cursor: pointer;
}

/* ---------- manga detail ---------- */
.manga-hero { background-size: cover; background-position: center; padding: 50px 0 20px; margin: -20px -20px 20px; }
.manga-title { font-size: 24px; margin: 0; padding: 0 20px; }
.manga-meta { display: flex; gap: 16px; font-size: 14px; color: var(--hint); margin-bottom: 16px; }
.manga-meta i { margin-right: 5px; color: var(--link); }
.manga-synopsis { font-size: 14px; line-height: 1.6; margin-bottom: 16px; }
.manga-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tag { background: var(--secondary-bg); padding: 4px 12px; border-radius: 20px; font-size: 12px; }
.primary-btn {
  width: 100%; background: var(--button); color: var(--button-text); border: none;
  padding: 14px; border-radius: var(--radius); font-size: 16px; font-weight: 600;
  cursor: pointer; margin-bottom: 20px;
}
.primary-btn i { margin-right: 8px; }
.primary-btn:active { opacity: .9; }
.chapters-list h3 { font-size: 16px; margin: 0 0 12px; }
.chapters-list h3 i { margin-right: 7px; color: var(--link); }
.chapter-item {
  padding: 12px; border-bottom: 1px solid var(--secondary-bg);
  display: flex; justify-content: space-between; cursor: pointer; font-size: 14px;
}
.chapter-item:active { background: var(--secondary-bg); }
.dot { color: var(--link); }

/* ---------- search ---------- */
.search-content { padding: 0; }
.search-input-wrapper {
  display: flex; align-items: center; gap: 10px; padding: 16px 20px;
  border-bottom: 1px solid var(--secondary-bg); position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.search-ico { color: var(--hint); }
#search-input {
  flex: 1; background: var(--secondary-bg); border: none; color: var(--text);
  padding: 12px 16px; border-radius: 10px; font-size: 16px; outline: none;
}
.search-close { background: none; border: none; color: var(--text); font-size: 18px; cursor: pointer; }
#search-results { padding: 8px 20px; }
.search-result { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--secondary-bg); cursor: pointer; }
.search-result:active { opacity: .7; }
.search-poster { width: 60px; height: 85px; border-radius: 8px; overflow: hidden; flex-shrink: 0; background: var(--secondary-bg); }
.search-poster img { width: 100%; height: 100%; object-fit: cover; }
.search-info h3 { margin: 0 0 4px; font-size: 15px; }
.search-info p { margin: 0; font-size: 12px; color: var(--hint); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- settings ---------- */
.setting-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--secondary-bg); font-size: 15px;
}
.setting-row input { width: 22px; height: 22px; accent-color: var(--button); }
.setting-hint { color: var(--hint); font-size: 12px; margin: 10px 0 0; }

.hidden { display: none !important; }

/* ---------- chapter sort button ---------- */
.chapters-list h3 { display: flex; align-items: center; }
.sort-btn {
  margin-left: auto;
  background: var(--secondary-bg); border: none; color: var(--text);
  padding: 6px 12px; border-radius: 8px; font-size: 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.sort-btn:active { transform: scale(.95); }
.sort-btn i { color: var(--link); }

/* ---------- hot picks overlays ---------- */
.hot-card { position: relative; }
.hot-card .card-poster::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, rgba(255,0,0,0.15), transparent 60%);
  z-index: 1;
  pointer-events: none;
}
.hot-flag {
  position: absolute;
  top: 8px; left: 8px;
  background: #ff3b30;
  color: #fff;
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  z-index: 2;
  box-shadow: 0 2px 6px rgba(255,59,48,0.4);
}
.hot-fire {
  position: absolute;
  top: 8px; right: 8px;
  color: #ff9500;
  font-size: 18px;
  z-index: 2;
  filter: drop-shadow(0 1px 3px rgba(255,149,0,0.6));
}

/* ---------- leaderboard ---------- */
.leaderboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px 12px;
  margin-bottom: 0;
}
.leaderboard-header .section-title {
  margin: 0;
}
.time-tabs {
  display: flex;
  gap: 6px;
  background: var(--secondary-bg);
  padding: 4px;
  border-radius: 10px;
}
.time-tab {
  background: transparent;
  border: none;
  color: var(--hint);
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: lowercase;
}
.time-tab.active {
  background: var(--button);
  color: var(--button-text);
}
.time-tab:active { transform: scale(0.95); }

#leaderboard-list {
  padding: 0 20px;
}
.rank-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--secondary-bg);
  cursor: pointer;
  transition: background 0.15s;
}
.rank-item:active { background: var(--secondary-bg); }
.rank-badge {
  flex: 0 0 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  background: var(--secondary-bg);
  color: var(--hint);
}
.rank-badge.gold { background: linear-gradient(135deg, #ffd700, #ffed4e); color: #7a5900; }
.rank-badge.silver { background: linear-gradient(135deg, #c0c0c0, #e8e8e8); color: #555; }
.rank-badge.bronze { background: linear-gradient(135deg, #cd7f32, #e8a87c); color: #5c3a1e; }

.rank-poster {
  width: 50px;
  height: 70px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--secondary-bg);
}
.rank-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s;
}
.rank-poster img.loaded { opacity: 1; }

.rank-info {
  flex: 1;
  min-width: 0;
}
.rank-info h3 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.rank-meta {
  font-size: 12px;
  color: var(--hint);
  display: flex;
  gap: 12px;
}
.rank-meta i {
  margin-right: 4px;
  font-size: 11px;
}

/* ---------- section heads + clear/shuffle buttons ---------- */
.section-head { display: flex; justify-content: space-between; align-items: center; padding: 0 20px 12px; }
.section-head .section-title { margin: 0; }

.clear-btn {
  background: transparent; border: none; color: var(--hint);
  font-size: 12px; cursor: pointer; display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 8px;
}
.clear-btn:active { background: var(--secondary-bg); color: #ff3b30; }

.shuffle-btn {
  background: var(--secondary-bg); border: none; color: var(--link);
  width: 34px; height: 34px; border-radius: 50%; font-size: 14px; cursor: pointer;
  transition: transform .15s;
}
.shuffle-btn:active { transform: scale(.9) rotate(120deg); }

/* ---------- recommendation genre tabs ---------- */
.reco-tabs {
  margin: 0 20px 12px; display: flex; gap: 6px;
  overflow-x: auto; scrollbar-width: none;
  background: transparent; padding: 0;
}
.reco-tabs::-webkit-scrollbar { display: none; }
.reco-tabs .time-tab { background: var(--secondary-bg); }

.clear-btn.armed { background: var(--secondary-bg); color: #ff3b30; }