*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0d0d0f;
  --surface:      #141417;
  --card:         #1a1a1f;
  --border:       #2a2a32;
  --accent:       #ff4655;
  --accent_dark:  #cc2233;
  --muted:        #555565;
  --text:         #e8e8f0;
  --subtext:      #8888a0;
  --col_official: #2ecc8a;
  --col_fantl:    #5b9cf6;
  --col_aggr:     #f0c040;
  --radius:       6px;
  --font_body:    'DM Sans', sans-serif;
  --font_mono:    'DM Mono', monospace;
  --font_display: 'Bebas Neue', sans-serif;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font_body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Grain overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 999;
  opacity: 0.4;
}

/* ── HEADER ─────────────────────────── */
#site_header {
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
  position: sticky;
  top: 0;
  background: rgba(13,13,15,0.92);
  backdrop-filter: blur(12px);
  z-index: 100;
}

.logo { font-family: var(--font_display); font-size: 1.7rem; letter-spacing: 2px; }
.logo a { color: inherit; text-decoration: none; }
.logo span { color: var(--accent); }
.tagline { font-size: 0.72rem; color: var(--muted); font-family: var(--font_mono); letter-spacing: 1px; text-transform: uppercase; }

/* ── HERO ───────────────────────────── */
.hero {
  padding: 4rem 2rem 2.5rem;
  max-width: 680px;
  margin: 0 auto;
  text-align: center;
}

.hero h1 { font-family: var(--font_display); font-size: clamp(2.4rem, 6vw, 4rem); line-height: 1; letter-spacing: 3px; margin-bottom: 0.75rem; }
.hero h1 em { color: var(--accent); font-style: normal; }
.hero p { color: var(--subtext); font-size: 0.92rem; max-width: 460px; margin: 0 auto 1.5rem; }

/* ── PROXY STATUS BADGE ─────────────── */
.proxy_badge {
  display: inline-block;
  margin-top: 0.75rem;
  font-family: var(--font_mono);
  font-size: 0.65rem;
  letter-spacing: 1px;
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid;
  transition: all 0.3s;
}
.proxy_badge.online  { color: var(--col_official); border-color: rgba(46,204,138,0.3); background: rgba(46,204,138,0.08); }
.proxy_badge.offline { color: var(--muted);        border-color: var(--border);         background: transparent; }

/* ── SEARCH BAR ─────────────────────── */
.search_wrap {
  display: flex;
  max-width: 560px;
  margin: 0 auto;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s;
}
.search_wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,70,85,0.12); }

#search_input {
  flex: 1;
  background: var(--surface);
  border: none;
  outline: none;
  padding: 0.85rem 1.2rem;
  color: var(--text);
  font-family: var(--font_body);
  font-size: 0.95rem;
}
#search_input::placeholder { color: var(--muted); }

#search_btn {
  background: var(--accent);
  border: none;
  padding: 0 1.4rem;
  color: #fff;
  font-family: var(--font_display);
  font-size: 1.05rem;
  letter-spacing: 1.5px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
#search_btn:hover    { background: var(--accent_dark); }
#search_btn:disabled { opacity: 0.5; cursor: default; }

/* ── LAYOUT ─────────────────────────── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 2rem;
  align-items: start;
}
@media (max-width: 780px) { .container { grid-template-columns: 1fr; padding: 1rem; } }

/* ── TABS ───────────────────────────── */
#tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  padding: 0.6rem 0;
  font-size: 0.78rem;
  font-weight: 500;
  font-family: var(--font_mono);
  text-transform: uppercase;
  letter-spacing: 1px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover:not(.active) { color: var(--subtext); }

/* ── PANEL SHARED ───────────────────── */
.panel_title {
  font-family: var(--font_mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--muted);
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

/* ── MANGA CARDS ────────────────────── */
.manga_card {
  display: flex;
  gap: 0.85rem;
  padding: 0.75rem 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  border-left: 2px solid transparent;
  transition: background 0.12s, border-left-color 0.12s;
  animation: fade_up 0.2s ease both;
}
.manga_card:hover    { background: rgba(255,255,255,0.03); }
.manga_card.selected { background: rgba(255,70,85,0.06); border-left-color: var(--accent); }

.manga_cover       { width: 46px; height: 64px; object-fit: cover; border-radius: 3px; background: var(--border); flex-shrink: 0; }
.cover_placeholder { width: 46px; height: 64px; border-radius: 3px; background: var(--border); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 1.2rem; flex-shrink: 0; }

.manga_info   { flex: 1; min-width: 0; }
.manga_title  { font-weight: 600; font-size: 0.84rem; line-height: 1.3; margin-bottom: 0.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.manga_meta   { font-size: 0.68rem; color: var(--subtext); font-family: var(--font_mono); }

.manga_status { display: inline-block; margin-top: 0.3rem; padding: 1px 6px; border-radius: 20px; font-size: 0.6rem; font-family: var(--font_mono); text-transform: uppercase; letter-spacing: 0.5px; }
.status_ongoing   { background: rgba(46,204,138,0.15); color: var(--col_official); }
.status_completed { background: rgba(91,156,246,0.15); color: var(--col_fantl); }
.status_hiatus    { background: rgba(240,192,64,0.15);  color: var(--col_aggr); }

.card_actions { display: flex; align-items: flex-end; flex-shrink: 0; }
.bm_btn { background: none; border: none; font-size: 1.05rem; cursor: pointer; color: var(--muted); padding: 2px 4px; line-height: 1; transition: color 0.15s, transform 0.1s; }
.bm_btn:hover      { color: var(--accent); transform: scale(1.15); }
.bm_btn.bookmarked { color: var(--accent); }

/* ── CHAPTERS PANEL ─────────────────── */
#chapters_panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

.chapters_header {
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.selected_title { font-family: var(--font_display); font-size: 1.15rem; letter-spacing: 1.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#chapter_search {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  padding: 0.32rem 0.7rem;
  color: var(--text);
  font-family: var(--font_mono);
  font-size: 0.76rem;
  width: 128px;
  transition: border-color 0.15s;
}
#chapter_search:focus { border-color: var(--accent); }
#chapter_search::placeholder { color: var(--muted); }

.chapters_list { max-height: 580px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ── CHAPTER ROWS ───────────────────── */
.chapter_row {
  display: flex;
  align-items: center;
  padding: 0.6rem 1.1rem;
  border-bottom: 1px solid rgba(42,42,50,0.5);
  gap: 0.65rem;
  transition: background 0.1s;
}
.chapter_row:hover { background: rgba(255,255,255,0.02); }
.chapter_row:last-child { border-bottom: none; }

.read_dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--border); transition: background 0.2s; }
.read_dot.read { background: var(--col_official); }

.ch_num   { font-family: var(--font_mono); font-size: 0.76rem; color: var(--accent); min-width: 50px; flex-shrink: 0; }
.ch_title { font-size: 0.8rem; color: var(--subtext); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.find_btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.22rem 0.6rem;
  color: var(--subtext);
  font-family: var(--font_mono);
  font-size: 0.66rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.find_btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(255,70,85,0.07); }

/* ── BOOKMARKS VIEW ─────────────────── */
.bm_item { display: flex; gap: 0.8rem; padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--border); align-items: center; }
.bm_item:last-child { border-bottom: none; }

.bm_info  { flex: 1; min-width: 0; }
.bm_title { font-size: 0.84rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0.2rem; }
.bm_meta  { font-size: 0.68rem; color: var(--muted); font-family: var(--font_mono); }

.progress_bar  { height: 3px; background: var(--border); border-radius: 2px; margin-top: 5px; overflow: hidden; }
.progress_fill { height: 100%; background: var(--col_official); border-radius: 2px; transition: width 0.3s; }

.bm_actions { display: flex; flex-direction: column; gap: 5px; align-items: flex-end; flex-shrink: 0; }
.bm_open    { font-size: 0.66rem; padding: 3px 8px; border: 1px solid var(--border); border-radius: var(--radius); background: none; color: var(--subtext); cursor: pointer; white-space: nowrap; transition: border-color 0.12s, color 0.12s; }
.bm_open:hover { border-color: var(--accent); color: var(--accent); }
.bm_remove  { background: none; border: none; font-size: 0.82rem; cursor: pointer; color: var(--muted); padding: 0 2px; line-height: 1; }
.bm_remove:hover { color: var(--accent); }

/* ── MODAL ──────────────────────────── */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,0.72); backdrop-filter: blur(6px); z-index: 200; display: none; align-items: center; justify-content: center; padding: 1rem; }
#modal.open { display: flex; }

.modal_box { background: var(--card); border: 1px solid var(--border); border-radius: 10px; width: 100%; max-width: 500px; max-height: 88vh; overflow-y: auto; animation: scale_in 0.18s ease; }

.modal_head { padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.modal_chapter_label { font-family: var(--font_mono); font-size: 0.66rem; color: var(--accent); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 0.2rem; }
.modal_title_text    { font-weight: 600; font-size: 0.93rem; }

.close_btn { background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; line-height: 1; padding: 0 0.2rem; flex-shrink: 0; }
.close_btn:hover { color: var(--text); }

.modal_body { padding: 1rem 1.2rem; }

/* ── SOURCE ITEMS ───────────────────── */
.source_item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.55rem;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.12s, background 0.12s;
  gap: 0.7rem;
}
.source_item:hover   { border-color: var(--accent); background: rgba(255,70,85,0.05); }
.source_item.visited { border-color: rgba(46,204,138,0.4); background: rgba(46,204,138,0.04); }
.source_item.checking { opacity: 0.6; pointer-events: none; }
.source_item.not_found { opacity: 0.4; }
.source_item.not_found .source_name::after { content: " - not found"; font-size: 0.65rem; color: var(--muted); font-family: var(--font_mono); }

/* Slug-pending state (needs user input) */
.source_item.slug_pending { display: block; cursor: default; }
.source_item.slug_pending:hover { border-color: var(--border); background: transparent; }

.source_left { display: flex; align-items: center; gap: 0.65rem; }
.source_icon { width: 28px; height: 28px; border-radius: 5px; background: var(--border); display: flex; align-items: center; justify-content: center; font-size: 0.85rem; flex-shrink: 0; }
.source_name { font-weight: 500; font-size: 0.83rem; }
.source_type { font-family: var(--font_mono); font-size: 0.6rem; margin-top: 1px; }
.type_official { color: var(--col_official); }
.type_fantl    { color: var(--col_fantl); }
.type_aggr     { color: var(--col_aggr); }

.source_right { display: flex; align-items: center; gap: 0.45rem; flex-shrink: 0; }

.visited_badge { font-size: 0.58rem; padding: 1px 5px; background: rgba(46,204,138,0.12); color: var(--col_official); border-radius: 20px; white-space: nowrap; font-family: var(--font_mono); }
.check_badge   { font-size: 0.58rem; padding: 1px 5px; background: rgba(255,255,255,0.06); color: var(--subtext); border-radius: 20px; white-space: nowrap; font-family: var(--font_mono); }
.found_badge   { font-size: 0.58rem; padding: 1px 5px; background: rgba(46,204,138,0.12); color: var(--col_official); border-radius: 20px; white-space: nowrap; font-family: var(--font_mono); }
.browse_badge  { color: var(--muted); font-size: 0.8rem; }
/* Slug input inside source card */
.slug_row { margin-top: 8px; display: flex; gap: 6px; }
.slug_label { font-size: 0.68rem; color: var(--subtext); margin-bottom: 5px; }
.slug_input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.28rem 0.6rem;
  color: var(--text);
  font-size: 0.76rem;
  font-family: var(--font_mono);
  outline: none;
}
.slug_input:focus { border-color: var(--accent); }
.slug_save_btn {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  padding: 0.28rem 0.75rem;
  color: #fff;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.12s;
}
.slug_save_btn:hover { background: var(--accent_dark); }

/* Google link section */
.google_section { margin-top: 0.85rem; padding: 0.75rem 0.95rem; background: rgba(255,255,255,0.03); border-radius: var(--radius); font-size: 0.73rem; }
.ext_link { color: var(--col_fantl); text-decoration: none; }
.ext_link:hover { text-decoration: underline; }

/* ── SPINNER / STATES ───────────────── */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.65s linear infinite; vertical-align: middle; margin-right: 5px; }

.source_checking { text-align: center; padding: 2rem; color: var(--subtext); font-size: 0.83rem; }

.skeleton { background: linear-gradient(90deg, var(--card) 25%, var(--border) 50%, var(--card) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius); height: 80px; margin-bottom: 0.5rem; }

.empty_state { text-align: center; padding: 2.5rem 1rem; color: var(--subtext); font-size: 0.8rem; line-height: 1.7; }
.empty_state .big_icon { font-size: 2rem; margin-bottom: 0.5rem; }

/* ── FOOTER ─────────────────────────── */
footer { text-align: center; padding: 2.5rem 1rem; color: var(--muted); font-size: 0.68rem; font-family: var(--font_mono); letter-spacing: 0.5px; border-top: 1px solid var(--border); margin-top: 4rem; }
footer a { color: var(--subtext); text-decoration: none; }
footer a:hover { color: var(--accent); }

/* ── ANIMATIONS ─────────────────────── */
@keyframes fade_up  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scale_in { from { opacity: 0; transform: scale(0.96); }     to { opacity: 1; transform: scale(1); } }
@keyframes spin     { to { transform: rotate(360deg); } }
@keyframes shimmer  { to { background-position: -200% 0; } }

::-webkit-scrollbar       { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── DEBUG PANEL ─────────────────────── */
#debug_panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  padding: 0.75rem 1.25rem 1rem;
  z-index: 9999;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  max-height: 60vh;
  overflow-y: auto;
}
#debug_panel.open { transform: translateY(0); }

#sort_btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.3rem 0.5rem;
    line-height: 1;
}
#sort_btn:hover { border-color: var(--accent); color: var(--accent); }

.github-link {
  display: inline-flex;
  align-items: center;
  margin-top: 0.6rem;
  gap: 0.25rem;
}