:root {
  --bg: #0f1220;
  --panel: #191d30;
  --panel2: #222741;
  --line: #2e3450;
  --text: #e8eaf2;
  --muted: #8b91ad;
  --accent: #4f7cff;
  --ok: #2fbf71;
  --warn: #e8a33d;
  --danger: #e05252;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input { font: inherit; }
img { display: block; }

#app { max-width: 560px; margin: 0 auto; }

/* ---------- écran code ---------- */
.auth {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; padding: 24px;
}
.auth .logo { font-size: 56px; }
.auth h1 { font-size: 20px; font-weight: 700; }
.auth p { color: var(--muted); text-align: center; font-size: 14px; }
.auth form { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 300px; }
.auth input {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius); padding: 13px 14px; text-align: center; letter-spacing: 2px;
}
.auth input:focus { outline: none; border-color: var(--accent); }
.auth .err { color: var(--danger); font-size: 14px; min-height: 20px; text-align: center; }

.btn {
  background: var(--accent); color: #fff; border-radius: var(--radius);
  padding: 13px 18px; font-weight: 600; text-align: center;
}
.btn:disabled { opacity: 0.5; }
.btn.ghost { background: var(--panel); border: 1px solid var(--line); color: var(--text); }
.btn.danger { background: var(--danger); }

/* ---------- entêtes ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 17px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn {
  min-width: 40px; min-height: 40px; border-radius: 10px; font-size: 19px;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.iconbtn:active { background: var(--panel); }

.syncdot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; transition: background 0.3s; }
.syncdot.ok { background: var(--ok); }
.syncdot.saving { background: var(--warn); }
.syncdot.offline { background: var(--muted); }
.synclabel { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ---------- accueil ---------- */
.sets { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px; }
.setcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 8px; text-align: left; min-height: 118px;
}
.setcard:active { background: var(--panel2); }
.setcard .logo { height: 44px; display: flex; align-items: center; }
.setcard .logo img { max-height: 44px; max-width: 100%; object-fit: contain; }
.setcard .logo .noimg { font-weight: 800; font-size: 20px; color: var(--muted); }
.setcard .name { font-weight: 600; font-size: 14px; }
.setcard .count { color: var(--muted); font-size: 12px; }
.mini-progress { height: 5px; background: var(--panel2); border-radius: 3px; overflow: hidden; }
.mini-progress > div { height: 100%; background: var(--ok); border-radius: 3px; }
.offline-note { text-align: center; color: var(--warn); font-size: 13px; padding: 4px 14px 10px; }

/* ---------- vue set ---------- */
.toolbar { display: flex; gap: 8px; padding: 10px 14px 0; align-items: center; }
.search {
  flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 10px 12px; min-width: 0;
}
.search:focus { outline: none; border-color: var(--accent); }
.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: none; }
.seg button { padding: 10px 12px; font-size: 13px; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--accent); color: #fff; }

.progresswrap { padding: 10px 14px 4px; }
.progressbar { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; }
.progressbar > div { height: 100%; background: var(--ok); border-radius: 4px; transition: width 0.25s; }
.progresstext { font-size: 12px; color: var(--muted); margin-top: 5px; display: flex; justify-content: space-between; }

.cardlist { padding: 8px 10px 90px; }
.row {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; margin-bottom: 8px;
}
.row.done { opacity: 0.45; }
.row .thumb { width: 44px; height: 61px; border-radius: 4px; background: var(--panel2); object-fit: contain; flex: none; }
.row .info { flex: 1; min-width: 0; }
.row .num { color: var(--muted); font-size: 12px; }
.row .name { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pills { display: flex; gap: 6px; flex: none; }
.pill {
  min-width: 40px; min-height: 40px; border-radius: 10px;
  border: 1.5px solid var(--line); color: var(--muted);
  font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, border-color 0.12s;
}
.pill.s1 { background: var(--ok); border-color: var(--ok); color: #08331c; }
.pill.s2 { text-decoration: line-through; opacity: 0.4; border-style: dashed; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- vue grille (page de classeur) ---------- */
/* colonnes automatiques : ~2 sur téléphone, 3-4 sur tablette, 6+ sur desktop */
.cardlist.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.cardlist.grid .row { flex-direction: column; align-items: stretch; gap: 6px; padding: 8px; margin-bottom: 0; }
.cardlist.grid .thumb { width: 100%; height: auto; aspect-ratio: 63/88; }
.cardlist.grid .info { text-align: center; }
.cardlist.grid .num { font-size: 11px; }
.cardlist.grid .name { font-size: 12px; }
/* pastilles : toujours sur UNE ligne, largeur partagée équitablement */
.cardlist.grid .pills { flex-wrap: nowrap; gap: 4px; }
.cardlist.grid .pill { flex: 1 1 0; min-width: 0; padding: 0 2px; min-height: 38px; font-size: 11px; }
.cardlist.grid .empty { grid-column: 1 / -1; }

/* ---------- aperçu grand format ---------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.88); z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; }

/* ---------- menu / modales ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--panel); border-radius: 16px 16px 0 0; width: 100%; max-width: 560px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px; max-height: 85dvh; overflow-y: auto;
}
.sheet h2 { font-size: 16px; }
.sheet .menuitem {
  text-align: left; padding: 13px 12px; border-radius: 10px; background: var(--panel2);
  font-weight: 600; font-size: 14px;
}
.sheet .menuitem:active { background: var(--line); }
.sheet .menuitem.danger { color: var(--danger); }
.sheet .check {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px;
  background: var(--panel2); border-radius: 10px; font-weight: 600; font-size: 14px;
}
.sheet input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
.sheet input[type="text"] {
  background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 12px; width: 100%;
}
.sheet .check input[type="text"] { flex: 1; width: auto; padding: 8px 10px; background: var(--panel); }
.sheet .hint { color: var(--muted); font-size: 12px; }
.sheet .btnrow { display: flex; gap: 10px; margin-top: 4px; }
.sheet .btnrow .btn { flex: 1; }

.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 16px; font-size: 14px; z-index: 60;
  display: flex; gap: 12px; align-items: center; white-space: nowrap;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}
.toast button { color: var(--accent); font-weight: 700; }

.spinner { text-align: center; color: var(--muted); padding: 40px; }

/* ---------- desktop : conteneur plus large ---------- */
@media (min-width: 760px) {
  #app { max-width: 760px; }
  .sets { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1100px) {
  #app { max-width: 1100px; }
  .sets { grid-template-columns: repeat(4, 1fr); }
  .cardlist.grid { gap: 10px; }
  /* la vue liste, la barre d'outils et la progression restent lisibles au centre */
  .toolbar, .progresswrap, .offline-note, .cardlist:not(.grid) {
    max-width: 760px; margin-left: auto; margin-right: auto;
  }
}
