:root {
  --bg: #fafbfe;
  --surface: #ffffff;
  --ink: #1f2430;
  --muted: #7a8294;
  --brand: #e84393;
  --brand-2: #fd79a8;
  --accent: #6c5ce7;
  --accent-2: #a29bfe;
  --mint: #00b894;
  --sun: #fdcb6e;
  --line: #e6e9f2;
  --radius: 16px;
  --shadow: 0 4px 20px rgba(31, 36, 48, 0.08);
  --shadow-lg: 0 12px 40px rgba(31, 36, 48, 0.18);
  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: inherit; }
img { max-width: 100%; }
.muted { color: var(--muted); }

/* ---------- Header app ---------- */
.app-header {
  background: linear-gradient(120deg, var(--brand), var(--accent));
  color: #fff;
  padding: 18px 24px 22px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 16px rgba(108, 92, 231, 0.35);
}
.app-header.slim {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
}
.header-title { font-size: 1.05rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back-link {
  color: #fff; text-decoration: none; font-size: 1.4rem; line-height: 1;
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.15); border-radius: 50%; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 30px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2)); }
.brand h1 { font-size: 1.35rem; font-weight: 700; }
.brand-sub { font-size: 0.78rem; opacity: 0.85; }

/* ---------- Recherche + chips ---------- */
.search-bar { max-width: 1200px; margin: 0 auto; padding: 16px 18px 0; }
.search {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 0.95rem;
  outline: none;
  box-shadow: var(--shadow);
}
.search:focus { border-color: var(--accent-2); }
.chips { max-width: 1200px; margin: 12px auto 0; padding: 0 18px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}
.chip:hover { border-color: var(--accent-2); color: var(--accent); }
.chip.active { background: linear-gradient(120deg, var(--brand), var(--accent)); color: #fff; border-color: transparent; }
.chip-count { font-weight: 400; opacity: 0.75; margin-left: 3px; font-size: 0.78rem; }

/* ---------- Grille de livres ---------- */
.books-grid {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 18px 100px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
}
.book-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  animation: fadeIn 0.3s ease both;
}
.book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.book-card.hidden { display: none; }
.book-cover { position: relative; aspect-ratio: 3 / 4; background: linear-gradient(150deg, #fdf2f8, #eef2ff); display: flex; align-items: center; justify-content: center; }
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-placeholder { font-size: 3rem; opacity: 0.5; }
.book-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(31,36,48,0.75); color: #fff;
  font-size: 0.72rem; font-weight: 700; padding: 4px 8px; border-radius: 999px;
}
.book-badge.done { background: var(--mint); }
.book-info { padding: 10px 12px 12px; }
.book-info h3 { font-size: 0.9rem; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-meta { color: var(--muted); font-size: 0.76rem; margin-top: 4px; }

/* ---------- Détail livre ---------- */
.tome-hero {
  max-width: 1000px; margin: 0 auto; padding: 20px 18px 10px;
  display: flex; gap: 20px; align-items: flex-start;
}
.tome-cover { width: 140px; border-radius: var(--radius); box-shadow: var(--shadow-lg); flex-shrink: 0; }
.tome-info { flex: 1; min-width: 0; }
.tome-info h2 { font-size: 1.4rem; }
.tome-desc { color: var(--muted); font-size: 0.9rem; margin-top: 8px; }
.progress-wrap { margin-top: 12px; }
.progress-bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent)); border-radius: 999px; transition: width 0.4s; }
.progress-label { font-size: 0.8rem; color: var(--muted); margin-top: 6px; display: block; }

.pages-list { max-width: 1000px; margin: 0 auto; padding: 16px 18px 60px; display: flex; flex-direction: column; gap: 8px; }
.page-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 16px;
  text-decoration: none; transition: transform 0.12s;
}
.page-row:hover { transform: translateX(3px); border-color: var(--accent-2); }
.page-num {
  width: 42px; height: 42px; flex-shrink: 0;
  background: linear-gradient(135deg, #fdf2f8, #eef2ff);
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
}
.page-codes { flex: 1; min-width: 0; }
.code-dots { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.dot { width: 20px; height: 20px; border-radius: 6px; border: 1px solid rgba(0,0,0,0.08); display: inline-block; }
.more { font-size: 0.78rem; color: var(--muted); }
.page-state { display: flex; gap: 8px; flex-shrink: 0; }
.st-done { color: var(--mint); font-weight: 700; font-size: 1.2rem; }
.st-fav { color: var(--brand); font-weight: 700; }

/* ---------- Page vue ---------- */
.page-view { max-width: 900px; margin: 0 auto; padding: 18px 18px 100px; }
.page-img-wrap { position: relative; text-align: center; }
.page-img { max-height: 68vh; border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.page-img-wrap .zoom {
  position: absolute; bottom: 12px; right: 12px;
  background: rgba(31,36,48,0.7); color: #fff; font-size: 0.8rem;
}
.page-actions { display: flex; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.page-actions form { flex: 1; min-width: 140px; }
.page-actions form button { width: 100%; justify-content: center; }
.btn.done-btn { background: var(--mint); color: #fff; }
.btn.fav-btn { background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.btn.fav-btn.active { background: #fff0f6; border-color: var(--brand); color: var(--brand); }

.codes-card, .works-section, .stats-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin: 16px 0; padding: 18px; }
.codes-card h2, .works-section h2 { font-size: 1.05rem; margin-bottom: 12px; }
.codes-table { display: flex; flex-direction: column; gap: 6px; }
.code-row { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.swatch { width: 30px; height: 30px; border-radius: 8px; border: 1px solid rgba(0,0,0,0.1); flex-shrink: 0; }
.code-hex { font-family: monospace; font-weight: 700; font-size: 0.9rem; width: 80px; }
.code-brand { flex: 1; font-size: 0.9rem; }
.code-ref { font-weight: 600; color: var(--accent); }

.page-nav { display: flex; justify-content: space-between; gap: 12px; margin: 18px 0; }
.btn.ghost-dark { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }

.works-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; margin-bottom: 14px; }
.works-grid img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 10px; box-shadow: var(--shadow); }
.works-grid.big { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.work-card { position: relative; display: block; text-decoration: none; }
.work-card img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 12px; box-shadow: var(--shadow); }
.work-author, .work-tome {
  position: absolute; left: 8px; right: 8px; bottom: 8px;
  background: rgba(31,36,48,0.75); color: #fff;
  font-size: 0.72rem; padding: 4px 8px; border-radius: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.work-tome { bottom: 34px; background: rgba(108,92,231,0.85); }

.work-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.work-form input[type="text"], .work-form input[type="file"] {
  flex: 1; min-width: 160px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 0.9rem; background: var(--bg);
}

/* ---------- Tracker ---------- */
.stats-card { display: flex; justify-content: space-around; text-align: center; }
.stat strong { display: block; font-size: 1.8rem; color: var(--accent); }
.stat span { font-size: 0.78rem; color: var(--muted); }
.tracker-list { max-width: 800px; margin: 0 auto; padding: 16px 18px 100px; display: flex; flex-direction: column; gap: 14px; }
.tracker-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.tracker-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.tracker-head h3 { font-size: 1rem; }
.tracker-pct { font-weight: 700; color: var(--accent); }
.tracker-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 10px; flex-wrap: wrap; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex; z-index: 60;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 0 8px; text-decoration: none;
  font-size: 0.7rem; font-weight: 600; color: var(--muted);
}
.nav-item span { font-size: 1.25rem; }
.nav-item.active { color: var(--accent); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 12px; padding: 10px 18px;
  font-size: 0.9rem; font-weight: 600; cursor: pointer; text-decoration: none;
  font-family: inherit; transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(120deg, var(--brand), var(--accent)); color: #fff; }
.btn.ghost { background: rgba(255,255,255,0.15); color: #fff; border: 1px solid rgba(255,255,255,0.35); }
.btn.small { padding: 6px 12px; font-size: 0.8rem; border-radius: 10px; }
.btn.danger { background: #ff7675; color: #fff; }

/* ---------- Admin ---------- */
.admin-body { background: var(--bg); }
.admin-wrap { max-width: 900px; margin: 0 auto; padding: 26px 18px 80px; }
.admin-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 10px; }
.admin-head h1 { font-size: 1.4rem; }
.admin-head .inline { display: inline; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card h2 { font-size: 1.05rem; margin-bottom: 14px; }
.form-card label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 14px; color: var(--ink); }
.form-card input[type="text"], .form-card input[type="password"], .form-card input[type="number"], .form-card input[type="file"], .form-card select, .form-card textarea {
  display: block; width: 100%; margin-top: 6px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 0.9rem; background: var(--bg); font-family: inherit;
}
.form-card input:focus, .form-card textarea:focus, .form-card select:focus { outline: none; border-color: var(--accent-2); }
.form-card textarea { resize: vertical; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.slim-form select { width: 100%; }
.alert { padding: 12px 16px; border-radius: 10px; font-size: 0.9rem; margin-bottom: 16px; }
.alert.error { background: #ffe5e5; color: #b33939; }
.alert.ok { background: #e3faf2; color: #0b8a63; }

.admin-tabs { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.admin-tab {
  padding: 8px 16px; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--line); text-decoration: none; font-weight: 600; font-size: 0.88rem;
}
.admin-tab.active { background: linear-gradient(120deg, var(--brand), var(--accent)); color: #fff; border-color: transparent; }

.admin-list { display: flex; flex-direction: column; gap: 10px; }
.admin-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; border: 1px solid var(--line); border-radius: 12px;
  flex-wrap: wrap;
}
.admin-item img { width: 48px; height: 60px; object-fit: cover; border-radius: 8px; background: #f1f3f9; flex-shrink: 0; }
.admin-info { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 3px; }
.admin-info strong { font-size: 0.9rem; }
.admin-info .muted { font-size: 0.78rem; }
.admin-item .inline { display: inline; }
.page-edit { flex-basis: 100%; margin-top: 6px; }
.page-edit summary { cursor: pointer; list-style: none; }
.page-edit summary::-webkit-details-marker { display: none; }
.page-edit form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.page-edit textarea { flex: 1; min-width: 200px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; font-family: monospace; font-size: 0.82rem; }
.page-edit input[type="file"] { font-size: 0.8rem; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); grid-column: 1 / -1; }
.empty-state p { margin-bottom: 6px; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 640px) {
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
@media (max-width: 560px) {
  .tome-hero { flex-direction: column; align-items: center; text-align: center; }
  .tome-cover { width: 180px; }
  .row-2 { grid-template-columns: 1fr; }
}
/* ---------- Grille de pages (01..100) ---------- */
.pages-grid {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px 18px 100px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 12px;
}
.page-tile {
  position: relative;
  aspect-ratio: 3 / 4;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-decoration: none;
  overflow: hidden;
  transition: transform 0.12s, box-shadow 0.12s;
  animation: fadeIn 0.3s ease both;
}
.page-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.page-tile.done { border-color: var(--mint); }
.page-tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile-num { font-weight: 700; font-size: 1rem; }
.tile-empty { color: var(--muted); font-size: 0.8rem; }
.tile-works {
  position: absolute; bottom: 4px; left: 4px; right: 4px;
  background: rgba(31,36,48,0.75); color: #fff;
  font-size: 0.68rem; padding: 3px 6px; border-radius: 6px;
  text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-check {
  position: absolute; top: 4px; left: 4px;
  width: 22px; height: 22px;
  background: var(--mint); color: #fff;
  border-radius: 50%; font-size: 0.75rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.tile-fav {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px;
  background: var(--brand); color: #fff;
  border-radius: 50%; font-size: 0.72rem;
  display: flex; align-items: center; justify-content: center;
}

/* ---------- Œuvre + codes ---------- */
.work-block { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin: 16px 0; padding: 16px; }
.work-img { width: 100%; border-radius: 12px; box-shadow: var(--shadow); }
.work-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin: 12px 0; font-size: 0.88rem; }
.work-author-name { font-weight: 700; }
.work-markers { color: var(--accent); font-weight: 600; }
.codes-pre {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  font-family: 'Consolas', monospace;
  font-size: 0.85rem;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-x: auto;
}
.codes-card { margin: 14px 0 0; }

@media (max-width: 560px) {
  .pages-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; }
}
/* image des codes quand pas de texte */
.code-img { width: 100%; max-width: 100%; border-radius: 12px; box-shadow: var(--shadow); cursor: zoom-in; }
