:root{
  --bg:#0f1117;
  --bg2:#141826;
  --fg:#e8eaf0;
  --muted:#aab2c8;
  --primary:#5aa2ff;
  --accent:#6ce0b0;
  --border:#23283b;
  --card:#171b29;
  --btn:#1e2437;

  --thumb-h: 180px;
  --name-lh: 1.25rem;
  --name-lines: 2;
  --badges-h: 28px;

  --topbar-h: 96px;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:system-ui,Segoe UI,Roboto,Ubuntu,'Helvetica Neue',Arial;
  color:var(--fg);
  background:linear-gradient(180deg,#0d1018,#101425 30%,#0f1117);
}

/* ---------- TOPBAR FIXE ---------- */
.topbar{
  position:fixed;
  top:0; left:0; right:0;
  z-index:1000;
  background:rgba(16,20,37,.9);
  backdrop-filter: blur(6px);
  border-bottom:1px solid var(--border);
}

.top-title-row{
  padding:14px 16px 4px;
}
.top-title-row h1{
  font-size:18px;
  margin:0;
  color:#fff;
}

/* ----- BARRE SUR UNE LIGNE ----- */
.top-actions{
  display:flex;
  flex-wrap:nowrap;
  gap:6px;
  align-items:center;
  padding:8px 16px 10px;
  border-top:1px solid rgba(255,255,255,0.03);
  width:100%;
  overflow-x:auto;
}

/* Barre de recherche stretch */
.search-wrap{
  display:flex;
  flex:1;
  gap:8px;
  align-items:center;
  min-width:300px;
}

#search{
  flex:1;
  width:100%;
  min-width:350px;
  max-width:none;
}

/* ----- INPUTS / SELECTS / BOUTONS ----- */
.top-actions select,
.top-actions input,
.top-actions button{
  height:34px;
  border-radius:8px;
  border:1px solid var(--border);
  background:var(--bg2);
  color:var(--fg);
  padding:0 10px;
  white-space:nowrap;
}
.top-actions button{
  background:var(--btn);
  cursor:pointer;
}
.top-actions button:hover{ filter:brightness(1.1) }

.total-inline{
  color:var(--muted);
  font-size:12px;
  white-space:nowrap;
}

/* ----- MAIN ----- */
main{
  padding: calc(var(--topbar-h) + 16px) 16px 16px;
}

/* ----- GRID ----- */
.grid{
  display:grid;
  gap:12px;
  grid-template-columns:repeat(auto-fill,minmax(260px,1fr));
}

.grid[data-cols="1"]{
  grid-template-columns:repeat(1,minmax(0,1fr)) !important;
}

/* ----- CARDS ----- */
.card{
  background:var(--card);
  border:1px solid var(--border);
  border-radius:14px;
  overflow:hidden;

  display:grid;
  grid-template-rows: var(--thumb-h) 1fr;
  min-height: calc(var(--thumb-h) + 160px);
}

.thumb{
  width:100%;
  height:var(--thumb-h);
  object-fit:cover;
  background:#1c1f2e;
}

/* Fallback (quand l'image distante ne charge pas) */
.thumb.is-fallback{
  object-fit:contain;
  background:#0f0f10;
}

.body{
  padding:12px;
  display:flex;
  flex-direction:column;
  min-height:0;
}

.name{
  margin:0 0 6px 0;
  font-size:1rem;
  line-height:var(--name-lh);
  color:#fff;

  display:-webkit-box;
  -webkit-box-orient:vertical;
  -webkit-line-clamp:var(--name-lines);
  overflow:hidden;
  min-height: calc(var(--name-lh) * var(--name-lines));
}

.badges-line{
  display:flex;
  gap:6px;
  flex-wrap:wrap;
  margin:6px 0 10px 0;
  align-items:flex-start;
  overflow:hidden;
  min-height:var(--badges-h);
  max-height: calc(var(--badges-h) * 2);
}

.badge{
  display:inline-flex;
  align-items:center;
  padding:4px 8px;
  font-size:12px;
  border-radius:999px;
  border:1px solid var(--border);
  white-space:nowrap;
  color:#fff;
}

.badges-line .badge{
  line-height: 1;
}

/* ======= COULEURS EXACTES (comme build_pages.py) ======= */
.badge.cat-vn{ background:#D32F2F; }
.badge.cat-collection{ background:#616161; }

.badge.eng-renpy{ background:#B069E8; }
.badge.eng-rpgm{ background:#2196F3; color:#000; }
.badge.eng-unity{ background:#FE5901; color:#000; }
.badge.eng-others{ background:#8BC34A; color:#000; }
.badge.eng-wolfrpg{ background:#4CAF50; color:#000; }

.badge.status-completed{ background:#2196F3; color:#000; }
.badge.status-abandoned{ background:#FF9800; color:#000; }
.badge.status-onhold{ background:#03A9F4; color:#000; }
.badge.status-encours{ background:#607D8B; }

.actions{
  margin-top:auto;
  display:flex;
  flex-direction:column;
  align-items:stretch;
}

.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:8px 10px;
  border-radius:10px;
  background:#2e3652;
  color:#ffffff;
  border:1px solid #3c466a;
  text-decoration:none;
  transition:0.15s ease;
}

.btn:hover{
  background:#3b4568;
  border-color:#4d5a84;
}

.btn[aria-disabled="true"]{ opacity:.6; pointer-events:none }
.btn:hover{ filter:brightness(1.07) }

/* ----- MODE 1 COLONNE LISTE ----- */
.grid[data-cols="1"] .card{
  display:flex;
  gap:14px;
  align-items:stretch;
  min-height:140px;
}

/* Image ultra large (x2) */
.grid[data-cols="1"] .thumb{
  width:480px;
  height:120px;
  flex:0 0 auto;
  border-radius:10px;
  margin:12px;
}

.grid[data-cols="1"] .body{
  display:flex;
  flex-direction:column;
  padding:12px 12px 12px 0;
}

/* ----- MODE COMPACT >=7 cols ----- */
.grid[data-density="compact"] .card{ border-radius:10px }
/* Réduction de la hauteur minimale en mode compact (>=7) */
.grid[data-density="compact"] .card{
  min-height: calc(var(--thumb-h) + 120px);
}
.grid[data-density="compact"] .body{ padding:10px }
.grid[data-density="compact"] .name{
  font-size:.95rem;
  --name-lh:1.15rem;
}
.grid[data-density="compact"]{
  --thumb-h:140px;
  --badges-h:24px;
}
.grid[data-density="compact"] .badge{
  font-size:11px;
  padding:2px 6px;
}
.grid[data-density="compact"] .btn{
  font-size:12px;
  padding:6px 8px;
}

/* ----- STATES ----- */
.empty{
  margin:16px 0;
  padding:18px;
  border:1px dashed var(--border);
  border-radius:12px;
  color:var(--muted);
  text-align:center;
}
.hidden{ display:none !important }

.load-more-wrap{
  grid-column:1 / -1;
  display:flex;
  justify-content:center;
  margin:18px 0 6px;
}

.load-more-btn{
  padding:12px 26px;
  border-radius:999px;
  border:1px solid var(--border);
  background:var(--btn);
  color:var(--fg);
  font-size:15px;
  font-weight:700;
  cursor:pointer;
  box-shadow:0 8px 18px rgba(0,0,0,.35);
}
.load-more-btn:hover{
  filter:brightness(1.12);
}

/* Curseur main sur le bouton F95 */
a[data-act="f95"] {
  cursor: pointer;
}

.btn.btn-page{
  display:flex;
  width:100%;
  box-sizing:border-box;
  justify-content:center;
  align-items:center;
  text-align:center;
  cursor:pointer;
}

/* ===== Mode 1 colonne : le bouton doit prendre toute la largeur ===== */
.grid[data-cols="1"] .body{
  flex:1;
  width:100%;
}

.grid[data-cols="1"] .actions{
  width:100%;
}

.grid[data-cols="1"] .btn.btn-page{
  width:100%;
}

.grid[data-density="compact"] .badges-line{
  margin-bottom:6px;
}

.grid[data-density="compact"] .btn.btn-page{
  margin-top:6px;
}
