:root {
  --bg: #0f1115;
  --surface: #171a20;
  --surface2: #22262e;
  --surface3: #2c313b;
  --primary: #2962FF;
  --primary-soft: rgba(41, 98, 255, 0.15);
  --accent: #2962FF;
  --text: #e8eaed;
  --muted: #9aa0aa;
  --good: #34c47c;
  --bad: #e5484d;
  --warn: #ffb020;
  --radius: 12px;
  --rd-top-h: 52px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  height: 100%;
}
body.theme-light {
  --bg: #f3f4f6; --surface: #ffffff; --surface2: #eceef1; --surface3: #e2e5ea;
  --text: #17191d; --muted: #6b7280;
}
body.reader-open #topbar { display: none; }
body.reader-open #bottom-nav { display: none; }
body.immersive #topbar, body.immersive #bottom-nav { display: none !important; }
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--surface3);
}
#topbar h1 {
  font-size: 1.05rem; font-weight: 700; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#topbar .icon-btn { color: var(--text); }
#topbar-actions { display: flex; gap: 2px; }
.icon-btn {
  background: transparent; border: none;
  color: var(--text); font-size: 1.25rem; cursor: pointer;
  padding: 6px 10px; border-radius: 9px;
}
.icon-btn:hover { background: var(--surface2); color: var(--accent); }
.top-search { display: flex; align-items: center; gap: 4px; flex: 1; }
.top-search input {
  flex: 1; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--surface3); background: var(--surface2);
  color: var(--text); font-size: 0.95rem; outline: none;
}

/* ---------- Bottom nav ---------- */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--surface3); z-index: 20;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; background: transparent; border: none;
  color: var(--muted); font-size: 0.66rem; cursor: pointer;
}
.nav-item .nav-ico { font-size: 1.15rem; font-style: normal; }
.nav-item.active { color: var(--accent); }

/* ---------- Main ---------- */
#view { padding: 12px; padding-bottom: 84px; }

/* ---------- Controls ---------- */
.btn {
  padding: 10px 16px; border: none; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 700;
  font-size: 0.9rem; cursor: pointer; transition: opacity .15s;
}
.btn:active { opacity: .8; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--surface3); }
.btn.danger { background: var(--bad); }
.btn.small { padding: 7px 12px; font-size: 0.8rem; border-radius: 9px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.menu-btn {
  display: block; width: 100%; text-align: left;
  background: var(--surface2); color: var(--text);
  border: none; padding: 12px 14px; border-radius: 10px;
  margin: 5px 0; cursor: pointer; font-size: 0.9rem;
}
.menu-btn:hover { background: var(--surface3); }
.chip-btn {
  background: var(--surface2); color: var(--text); border: 1px solid transparent;
  padding: 8px 12px; border-radius: 999px; font-size: 0.8rem; cursor: pointer;
}
.chip-btn.active, .chip-btn:hover { border-color: var(--accent); color: var(--accent); }
.chip {
  background: var(--surface2); color: var(--muted);
  padding: 3px 10px; border-radius: 999px; font-size: 0.72rem;
}
.chip-chip-ongoing { color: var(--good) !important; }
.chip-chip-completed { color: var(--accent) !important; }
.chip-chip-hiatus { color: var(--warn) !important; }
.chip-chip-cancelled { color: var(--bad) !important; }
.mini-btn {
  background: var(--surface2); color: var(--text);
  border: none; padding: 6px 9px; border-radius: 8px; cursor: pointer; font-size: 0.85rem;
}
.mini-btn:hover { background: var(--surface3); color: var(--accent); }
.input {
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--surface3); background: var(--surface2);
  color: var(--text); font-size: 0.95rem; outline: none; width: 100%;
}
.input:focus { border-color: var(--accent); }
.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.search-row .input { flex: 1; }
.select-box {
  padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--surface3); background: var(--surface2);
  color: var(--text); font-size: 0.85rem; outline: none;
}
.select-box option { background: var(--surface2); color: var(--text); }
.meta { color: var(--muted); font-size: 0.82rem; }
.sec-title {
  font-weight: 800; font-size: 0.95rem; color: var(--accent);
  margin: 18px 0 10px; letter-spacing: .02em;
}
section h2.sec-title:first-child, .page-settings .sec-title:first-child { margin-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; line-height: 1.6; }

/* ---------- Grid / cards ---------- */
.grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
@media (min-width: 720px) { .grid { grid-template-columns: repeat(6, 1fr); } }
.manga-card {
  background: var(--surface); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: transform .12s ease;
  position: relative;
}
.manga-card:active { transform: scale(.97); }
.manga-card img { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; }
.manga-card .card-title {
  position: relative; padding: 6px 6px 8px; font-size: 0.78rem; font-weight: 600;
  line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}
.badge {
  background: var(--accent); color: #fff; border-radius: 999px;
  font-size: 0.62rem; padding: 1px 6px; line-height: 1.5;
  margin-left: 6px; display: inline-block;
}

/* ---------- Liste (ligne) ---------- */
.list-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
}
.list-row:hover { background: var(--surface2); }
.row-cover {
  width: 52px; aspect-ratio: 2/3; object-fit: cover; border-radius: 8px;
}
.list-mid { flex: 1; min-width: 0; }
.list-title {
  font-size: 0.92rem; font-weight: 700; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.list-sub { color: var(--muted); font-size: 0.76rem; margin-top: 2px; }
.list-arrow { color: var(--muted); font-size: 1.1rem; }
.row-btns { display: flex; gap: 6px; }

/* ---------- Bibliothèque ---------- */
.lib-layout { display: flex; gap: 10px; }
.lib-side { width: 148px; flex-shrink: 0; }
.lib-main { flex: 1; min-width: 0; }
@media (max-width: 560px) {
  .lib-side { width: 110px; }
}
.cat-item {
  display: flex; align-items: center; gap: 6px; width: 100%;
  background: transparent; border: none; color: var(--muted);
  padding: 10px 10px; border-radius: 10px; font-size: 0.85rem; cursor: pointer;
}
.cat-item:hover { background: var(--surface2); color: var(--text); }
.cat-item.active { background: var(--primary-soft); color: var(--accent); }
.cat-name { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-count { font-size: 0.72rem; color: var(--muted); background: var(--surface3); padding: 1px 7px; border-radius: 999px; }
.cat-add { color: var(--accent); }
.cat-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.cat-mgmt { display: flex; align-items: center; gap: 8px; padding: 8px 2px; border-bottom: 1px solid var(--surface3); color: var(--text); }
.cat-mgmt:last-child { border-bottom: none; }
.cat-mgmt .cat-name { flex: 1; }
.cat-add-row,
.cat-add-row input { margin-top: 8px; }
.lib-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.lib-search { flex: 1; min-width: 120px; }
.lib-counts { color: var(--muted); font-size: 0.78rem; margin-bottom: 12px; }

/* ---------- Explorer / sources ---------- */
.sources-grid { display: flex; flex-direction: column; gap: 10px; }
.source-card {
  background: var(--surface); border-radius: 14px; padding: 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.source-name { font-weight: 800; font-size: 1rem; }
.source-meta { color: var(--muted); font-size: 0.75rem; }
.source-btns { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.source-link { display: inline-block; margin-top: 10px; color: var(--accent); text-decoration: underline; font-size: 0.85rem; cursor: pointer; }
.source-link:hover { opacity: 0.8; }
.more-row { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }

/* ---------- Updates ---------- */
.update-list { display: flex; flex-direction: column; gap: 8px; }
.update-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border-radius: 12px; padding: 10px 12px;
}
.update-row img { width: 46px; aspect-ratio: 2/3; object-fit: cover; border-radius: 8px; }

/* ---------- Téléchargements ---------- */
.dl-card {
  background: var(--surface); border-radius: 14px; padding: 14px; margin-bottom: 12px;
}
.dl-head { display: flex; justify-content: space-between; align-items: center; }
.dl-title { font-weight: 800; }
.dl-pct { color: var(--accent); font-weight: 800; }
.progress {
  height: 8px; background: var(--surface3); border-radius: 999px;
  overflow: hidden; margin: 10px 0;
}
.progress-bar {
  height: 100%; background: linear-gradient(90deg, var(--accent), #7aa2ff);
  border-radius: 999px; transition: width .3s;
}
.dl-items { display: flex; flex-direction: column; gap: 3px; font-size: 0.78rem; color: var(--muted); max-height: 150px; overflow-y: auto; margin-bottom: 10px; }

/* ---------- Détail manga ---------- */
.detail-head { display: flex; gap: 14px; margin-bottom: 14px; }
.detail-head img { width: 122px; aspect-ratio: 2/3; object-fit: cover; border-radius: var(--radius); }
.detail-info { min-width: 0; }
.detail-title { font-size: 1.3rem; margin-bottom: 6px; line-height: 1.2; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.desc { color: #c9cdd4; font-size: 0.9rem; line-height: 1.55; margin-bottom: 14px; }
body.theme-light .desc { color: #4b5563; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.ch-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.ch-bar .sec-title { margin: 0; }
.chapters { display: flex; flex-direction: column; margin: 8px 0; background: var(--surface); border-radius: 12px; overflow: hidden; }
.chapter-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; cursor: pointer; font-size: 0.9rem;
  border-bottom: 1px solid var(--surface3);
}
.chapter-row:last-child { border-bottom: none; }
.chapter-row:hover { background: var(--surface2); }
.ch-left { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.ch-ctrl { display: flex; gap: 6px; }
.read-dot { color: var(--muted); font-size: 0.82rem; }
.read-dot.done { color: var(--good); }
.read-dot.dl { color: var(--accent); }
.num { color: var(--muted); font-size: 0.72rem; }

/* ---------- Drawer ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 280px;
  background: var(--surface); z-index: 45;
  padding: 16px; box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  display: flex; flex-direction: column; gap: 6px;
  animation: slideIn .18s ease;
}
@keyframes slideIn { from { transform: translateX(-100%); } to { transform: none; } }
.drawer-head { font-weight: 900; font-size: 1.1rem; padding: 6px 4px 14px; color: var(--accent); }
#drawer-ver { font-size: 0.7rem; color: var(--muted); font-weight: 500; }
.drawer-item {
  background: transparent; border: none; color: var(--text);
  text-align: left; padding: 12px 10px; border-radius: 10px;
  font-size: 0.95rem; cursor: pointer;
}
.drawer-item:hover { background: var(--surface2); color: var(--accent); }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  z-index: 60; display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--surface); border-radius: 16px;
  width: 100%; max-width: 460px; max-height: 84dvh;
  overflow-y: auto; padding: 14px;
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.5);
}
.modal.wide { max-width: 640px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.modal-title { font-size: 1.05rem; font-weight: 800; }
.modal-msg { color: var(--muted); font-size: 0.85rem; margin: 4px 0 12px; line-height: 1.5; }
.modal-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.modal-body { padding: 2px 0; }

/* ---------- Réglages ---------- */
.set-group { font-weight: 800; font-size: 0.9rem; margin: 14px 0 6px; color: var(--accent); }
.set-sub { color: var(--muted); font-size: 0.75rem; line-height: 1.45; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--surface3); color: var(--text);
}
.set-left { min-width: 0; flex: 1; color: var(--text); }
.set-label { font-size: 0.92rem; font-weight: 600; color: var(--text); }
.set-row .switch, .set-row > .select-box, .set-row > input,
.set-row > input:first-child { flex-shrink: 0; }
.page-settings > .set-row:last-child { border-bottom: none; }
.page-settings .meta { color: var(--muted); }
.page-settings .desc { color: var(--text); }

/* ---------- Switch ---------- */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: var(--surface3);
  border-radius: 999px; transition: background .2s; cursor: pointer;
}
.slider::before {
  content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch-label { margin-left: 12px; }

/* ---------- Segmented ---------- */
.seg { display: inline-flex; background: var(--surface2); border-radius: 10px; padding: 3px; gap: 2px; flex-shrink: 0; }
.seg-btn {
  padding: 7px 14px; border: none; background: transparent; color: var(--muted);
  font-size: 0.82rem; border-radius: 8px; cursor: pointer;
}
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 700; }

/* ---------- Toasts ---------- */
#toast-root {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: max-content; max-width: 92vw;
}
.toast {
  background: var(--surface3); color: var(--text);
  padding: 11px 18px; border-radius: 12px; font-size: 0.86rem;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.45);
  opacity: 0; transform: translateY(10px); transition: all .25s;
}
.toast.show { opacity: 1; transform: none; }

/* ---------- Lecteur ---------- */
#reader-app {
  position: fixed; inset: 0; z-index: 1000;
  background: #0b0b0e;
  display: flex; flex-direction: column;
  overflow: hidden;
  touch-action: none;
}
.rd-top {
  height: var(--rd-top-h); flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px; background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
}
.rd-btn { color: #fff; }
.rd-btn:hover { background: rgba(255, 255, 255, 0.12); }
.rd-title { flex: 1; font-weight: 700; font-size: 0.95rem; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.rd-canvas {
  flex: 1; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.rd-canvas.scrollable { overflow-y: auto; justify-content: flex-start; display: block; }
.rd-scroll-col { display: flex; flex-direction: column; align-items: center; }
.rd-page {
  display: block; max-width: 100%; max-height: 82dvh; margin: 3px auto;
  user-select: none; -webkit-user-drag: none;
  transform-origin: center center;
  transition: opacity .28s ease, transform .0s;
}
.rd-page.half { max-width: 50%; max-height: none; width: 49.6%; }
.rd-page.scroll { max-width: 100%; max-height: none; width: 100%; height: auto; }
.rd-canvas.paged .rd-page {
  width: auto; max-width: 100%;
}
.rd-canvas.paged .rd-page.half { width: 49.6vw; max-width: 49.6vw; }
.rd-canvas.trans-slide .rd-page { animation: rdSlide .3s ease; }
.rd-canvas.trans-fade .rd-page { animation: rdFade .32s ease; }
@keyframes rdSlide { from { opacity: .35; transform: scale(.97) translateX(4%); } to { opacity: 1; transform: none; } }
@keyframes rdFade { from { opacity: 0; } to { opacity: 1; } }
.rd-bottom {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; gap: 18px;
  background: rgba(0, 0, 0, 0.65); backdrop-filter: blur(8px);
}
.rd-label { color: #fff; font-size: 0.9rem; min-width: 70px; text-align: center; }
.rd-tools {
  position: absolute; left: 0; right: 0; bottom: 56px;
  display: flex; justify-content: center; gap: 6px;
  padding: 6px; flex-wrap: wrap;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none; transition: opacity .22s; z-index: 5;
}
#reader-app.show-tools .rd-tools { opacity: 1; pointer-events: auto; }
.rd-tools:hover { opacity: 1; pointer-events: auto; }

body.rot-landscape {
  transform: rotate(-90deg);
  transform-origin: left top;
  width: 100vh; height: 100vw;
  position: fixed; top: 0; left: 0;
  overflow: hidden;
}
body.rot-portrait {
  transform: rotate(90deg);
  transform-origin: left top;
  width: 100vh; height: 100vw;
  position: fixed; left: 0;
  overflow: hidden;
}

/* ---------- Divers ---------- */
.page-settings > .btn { margin-bottom: 12px; }
input[type="color"] { background: var(--surface2); border: 1px solid var(--surface3); border-radius: 8px; padding: 3px; height: 40px; width: 52px; cursor: pointer; }