/* RETRO GAME — direction « Néo-brutal pixel » : fond crème, contours noirs épais, ombres décalées. */
:root {
  --fond: #FFF4D6;
  --carte: #FFFFFF;
  --encre: #111111;
  --texte: #111111;
  --doux: #4A4536;
  --accent: #FF5A36;   /* boutons Jouer */
  --bleu: #3B5BFF;     /* liens, bandeau homebrew */
  --jaune: #FFD23F;
  --vert: #5BE0A0;
  --trait: 3px solid var(--encre);
  --titre: "Archivo Black", "Arial Black", system-ui, sans-serif;
  --corps: "Space Grotesk", system-ui, "Segoe UI", sans-serif;
  --pixel: "Silkscreen", ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--fond);
  color: var(--texte);
  font-family: var(--corps);
  line-height: 1.5;
}
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--bleu); outline-offset: 3px; }

/* Barre du haut : une carte blanche qui reste en haut */
.topbar {
  position: sticky; top: 0; z-index: 10;
  padding: max(12px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 10px max(24px, env(safe-area-inset-left));
  background: #FFF4D6ee; backdrop-filter: blur(6px);
}
.barre {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px 20px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--carte);
  border: var(--trait); border-radius: 16px; box-shadow: 5px 5px 0 var(--encre);
}
.logo {
  display: flex; align-items: center; gap: 10px; text-decoration: none;
  font-family: var(--titre); font-size: 21px; letter-spacing: -0.5px; white-space: nowrap;
}
.logo-icone {
  width: 38px; height: 38px; display: grid; place-items: center; flex: none;
  background: var(--accent); border: var(--trait); border-radius: 10px;
}
.modes { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; flex: 1; }
.modes a {
  font-weight: 500; font-size: 15px; text-decoration: none;
  padding: 9px 13px; border-radius: 999px; white-space: nowrap;
}
.modes a:hover { background: #1111110f; }
.modes a.actif { font-weight: 700; background: var(--encre); color: var(--fond); }
.modes a.ajouter {
  margin-left: auto; font-weight: 700; border-radius: 12px;
  background: var(--jaune); border: var(--trait); box-shadow: 3px 3px 0 var(--encre);
}
.modes a.ajouter:hover { background: var(--jaune); transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--encre); }
.modes a.ajouter.actif { color: var(--encre); }

main { max-width: 1248px; margin: 0 auto; padding: 24px 24px 80px; outline: none; }

h1 {
  font-family: var(--titre); font-weight: 400; font-size: clamp(28px, 4.2vw, 46px);
  line-height: 1.05; letter-spacing: -1px; margin: 0 0 10px;
}
h1.surligne span { background: linear-gradient(transparent 58%, var(--c) 0); padding: 0 4px; }
h2 { font-family: var(--titre); font-weight: 400; font-size: 30px; letter-spacing: -0.5px; margin: 0; line-height: 1.1; }
.intro { color: var(--doux); font-size: 17px; margin: 0 0 26px; max-width: 640px; }
.fil { font-size: 15px; color: var(--doux); margin-bottom: 10px; }
.fil a { color: var(--bleu); font-weight: 700; text-decoration: none; }
.fil a:hover { text-decoration: underline; }.pixel { font-family: var(--pixel); font-size: 13px; letter-spacing: .5px; }

/* Accueil : titre + bandeau homebrew */
.accueil {
  display: grid; gap: 24px; align-items: stretch; margin: 12px 0 40px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
.accueil-texte { display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.accueil-texte h1 { font-size: clamp(44px, 7vw, 78px); line-height: .95; letter-spacing: -2px; margin: 0; }
.accueil-texte .intro { font-size: 19px; color: var(--texte); margin: 0; }
.bandeau-homebrew {
  display: flex; flex-direction: column; gap: 14px; text-decoration: none;
  padding: 22px; background: var(--bleu); color: #fff;
  border: var(--trait); border-radius: 20px; box-shadow: 8px 8px 0 var(--encre);
  transition: transform .12s, box-shadow .12s;
}
.bandeau-homebrew:hover { transform: translate(-3px, -3px); box-shadow: 11px 11px 0 var(--encre); }
.bandeau-homebrew .etiquette { background: var(--jaune); }
.bandeau-ecran {
  height: 150px; display: grid; place-items: center; text-align: center; padding: 10px;
  border: var(--trait); border-radius: 14px; background-color: var(--encre);
  background-image: linear-gradient(#ffffff14 1px, transparent 1px), linear-gradient(90deg, #ffffff14 1px, transparent 1px);
  background-size: 16px 16px; color: var(--jaune);
}
.bandeau-bas { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.bandeau-bas strong { display: block; font-family: var(--titre); font-weight: 400; font-size: 28px; line-height: 1.05; }
.bandeau-bas span { font-size: 15px; }
.rond-jouer {
  width: 56px; height: 56px; flex: none; display: grid; place-items: center;
  background: #fff; border: var(--trait); border-radius: 50%;
}

.section-tete { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.pastilles-themes { display: flex; flex-wrap: wrap; gap: 8px; }
.pastilles-themes a {
  font-weight: 700; font-size: 14px; text-decoration: none; padding: 7px 12px;
  background: var(--c); border: 2px solid var(--encre); border-radius: 999px;
}
.pastilles-themes a:hover { box-shadow: 3px 3px 0 var(--encre); transform: translate(-1px, -1px); }

/* Grille de cartes (consoles et thèmes) */
.grille { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.case {
  display: flex; flex-direction: column; gap: 10px; min-height: 200px;
  padding: 16px 18px 18px; text-decoration: none; color: var(--encre);
  background: var(--c, var(--carte)); border: var(--trait); border-radius: 18px;
  box-shadow: 5px 5px 0 var(--encre);
  transition: transform .12s, box-shadow .12s;
}
.case:hover, .case:focus-visible { transform: translate(-3px, -3px); box-shadow: 8px 8px 0 var(--encre); }
.case.sombre { color: var(--fond); }
.case-haut { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.compte {
  font-family: var(--pixel); font-size: 13px; padding: 3px 8px; white-space: nowrap;
  background: #fff; color: var(--encre); border: 2px solid var(--encre); border-radius: 8px;
}
.case[style*="#FFFFFF"] .compte { background: var(--fond); }
.case svg { width: 100%; height: 100px; }
.case .nom { margin-top: auto; font-family: var(--titre); font-size: 25px; line-height: 1.05; }
.case .meta { font-size: 15px; font-weight: 500; }
.case .icone-theme {
  width: 64px; height: 64px; margin: 8px 0; display: grid; place-items: center;
  font-size: 30px; color: var(--encre); background: #fff; border: var(--trait); border-radius: 14px;
  box-shadow: 3px 3px 0 var(--encre);
}

/* Barre de filtres */
.filtres { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 14px; }
.puce {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 700; font-size: 14px; padding: 7px 12px;
  background: #fff; border: 2px solid var(--encre); border-radius: 999px;
}
.puce[style]::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  background: var(--c); border: 2px solid var(--encre);
}
.puce:hover { box-shadow: 3px 3px 0 var(--encre); transform: translate(-1px, -1px); }
.puce[aria-pressed="true"] { background: var(--encre); color: var(--fond); }
.puce[aria-pressed="true"]::before { border-color: var(--fond); }
.puce small { font-family: var(--pixel); font-size: 11px; opacity: .8; }

.outils { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 24px; }
.outils input, .outils select, .champ select, .champ input, .champ textarea {
  font: inherit; font-size: 16px; color: var(--texte); background: #fff;
  border: var(--trait); border-radius: 12px; padding: 9px 12px;
}
.outils input { flex: 1 1 260px; }

/* Cartes de jeux */
.jeux { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.jeu {
  position: relative; display: flex; flex-direction: column; gap: 8px; text-align: left;
  padding: 14px 16px 14px; background: #fff;
  border: var(--trait); border-radius: 14px; box-shadow: 4px 4px 0 var(--encre);
  transition: transform .12s, box-shadow .12s;
}
.jeu:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--encre); }
.jeu .ouvrir { all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.jeu .ouvrir::after { content: ""; position: absolute; inset: 0; }
.jeu .ouvrir:focus-visible { outline: none; }
.jeu:has(.ouvrir:focus-visible) { outline: 3px solid var(--bleu); outline-offset: 3px; }
.jeu .titre { font-weight: 700; font-size: 17px; line-height: 1.25; padding-right: 84px; }
.jeu .meta { color: var(--doux); font-size: 14px; }
.etiquettes { display: flex; flex-wrap: wrap; gap: 6px; }
.etiquette {
  align-self: flex-start; font-family: var(--pixel); font-size: 12px; line-height: 1.3;
  padding: 3px 8px; color: var(--encre); background: var(--c, #fff);
  border: 2px solid var(--encre); border-radius: 8px;
}
.etiquette-perso { background: #7FD1FF; }
.etiquette-rom { background: var(--vert); }
.actions { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; z-index: 1; }
.btn-icone {
  width: 34px; height: 34px; display: grid; place-items: center; font-size: 16px; font-weight: 700;
  background: #fff; border: 2px solid var(--encre); border-radius: 10px;
}
.btn-icone:hover { box-shadow: 2px 2px 0 var(--encre); transform: translate(-1px, -1px); }
.btn-icone[aria-pressed="true"].fav { background: var(--jaune); }
.btn-icone[aria-pressed="true"].possede { background: var(--vert); }

.vide {
  padding: 40px; text-align: center; color: var(--doux);
  border: 3px dashed var(--encre); border-radius: 18px; background: #ffffff80;
}
.vide p:first-child { font-family: var(--titre); font-size: 22px; color: var(--texte); }

/* Fiche d'un jeu */
dialog {
  width: min(540px, calc(100% - 32px)); padding: 0;
  color: var(--texte); background: #fff;
  border: var(--trait); border-radius: 20px; box-shadow: 8px 8px 0 var(--encre);
}
dialog::backdrop { background: #111111b3; }
.fiche-close { position: absolute; top: 12px; right: 12px; margin: 0; }
.fiche-close button {
  width: 40px; height: 40px; display: grid; place-items: center; font-size: 24px; line-height: 1;
  background: #fff; border: 2px solid var(--encre); border-radius: 10px;
}
.fiche-close button:hover { background: var(--jaune); }
#ficheContenu { padding: 24px 24px 22px; border-top: 14px solid var(--c, var(--accent)); }
#ficheContenu h2 { font-size: 28px; margin: 12px 44px 12px 0; }
#ficheContenu dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 16px; font-size: 15px; }
#ficheContenu dt { color: var(--doux); }
#ficheContenu dd { margin: 0; font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
#ficheContenu dd a { color: var(--bleu); font-weight: 700; }
.fiche-boutons { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

/* Boutons */
.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--corps); font-weight: 700; font-size: 15px; line-height: 1.2;
  padding: 10px 14px; color: var(--encre); text-decoration: none;
  background: #fff; border: var(--trait); border-radius: 12px; box-shadow: 3px 3px 0 var(--encre);
  cursor: pointer;
}
.bouton:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--encre); }
.bouton:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--encre); }
.bouton[aria-pressed="true"] { background: var(--c, var(--jaune)); }
.bouton-jouer { justify-self: start; background: var(--accent); }
.bouton-danger:hover { background: #FF6B6B; }
a.bouton { text-decoration: none; }

.titre-ligne { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.titre-ligne h1 { margin: 0; }
.titre-ligne + .filtres { margin-top: 16px; }

/* Formulaires (page Jouer, ajout d'un jeu) */
.lanceur {
  display: grid; gap: 18px; max-width: 580px; padding: 22px;
  background: #fff; border: var(--trait); border-radius: 18px; box-shadow: 6px 6px 0 var(--encre);
}
.champ { display: grid; gap: 6px; }
.champ > span, .controles legend { font-family: var(--pixel); font-size: 13px; color: var(--encre); }
.champs-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.champ small { color: var(--doux); font-size: 14px; }
.champ input[type=file] { padding: 8px; }
.champ, .lanceur > * { min-width: 0; }
.champ > select, .champ > input, .champ > textarea { width: 100%; max-width: 100%; }
.fiche-gestion { margin-top: 14px; padding-top: 16px; border-top: 3px dashed var(--encre); }
.fiche-gestion .bouton { font-size: 14px; padding: 8px 12px; }
.pret { margin-bottom: 18px; }
.pret p { margin: 0; }
.pret .ou { color: var(--doux); font-size: 14px; }
.case-cocher { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.champ select:disabled { opacity: .7; }
.controles { border: 0; padding: 0; margin: 0; gap: 10px; }
.controles legend { padding: 0; margin-bottom: 8px; }
.controles .case-cocher { font-size: 16px; font-weight: 500; }
.controles input[type=radio], .case-cocher input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--encre); }
.etat-manette { color: #11663F; font-weight: 700; font-size: 14px; }
.aide {
  max-width: 580px; margin-top: 24px; padding: 14px 18px; font-size: 15px;
  background: #fff; border: 2px solid var(--encre); border-radius: 14px;
}
.aide summary { cursor: pointer; font-weight: 700; }

/* Partie en cours */
.partie-barre { display: flex; justify-content: space-between; align-items: center; gap: 8px 12px; margin-bottom: 10px; flex-wrap: wrap; }
.partie-barre .fil { margin: 0; font-weight: 700; color: var(--encre); }
#ecran {
  width: 100%; aspect-ratio: 4 / 3; max-height: calc(100vh - 170px); background: #000;
  border: var(--trait); border-radius: 14px; overflow: hidden; box-shadow: 6px 6px 0 var(--c, var(--encre));
}

/* Pendant une partie : l'écran de jeu prend toute la place (barre du haut masquée) */
body.en-partie .topbar { display: none; }
body.en-partie main {
  max-width: none;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
body.en-partie #ecran { max-height: calc(100vh - 70px); max-height: calc(100dvh - 70px); box-shadow: none; }

/* Manettes à l'écran dessinées par jouer.js (MANETTES) : zone de droite 180 × 180, boutons de 60 px */
#ecran { position: relative; isolation: isolate; }
#ecran.manette-perso .ejs_virtualGamepad_left,
#ecran.manette-perso .ejs_virtualGamepad_right { width: 180px; height: 180px; bottom: 10px; }
#ecran.manette-perso .ejs_virtualGamepad_right .ejs_virtualGamepad_button {
  width: 60px; height: 60px; line-height: 60px; font-size: 26px;
  background-color: rgba(255, 255, 255, .2); border: 2px solid rgba(255, 255, 255, .55);
}
#ecran.manette-perso .ejs_virtualGamepad_top { bottom: 230px; }
#ecran.manette-perso .ejs_virtualGamepad_top .ejs_virtualGamepad_button { width: 90px; }
#ecran.manette-perso .ejs_virtualGamepad_bottom { bottom: -44px; }
#ecran.manette-perso .ejs_virtualGamepad_bottom .ejs_virtualGamepad_button { width: 64px; opacity: .75; }

/* Écran tactile (téléphone, tablette) : le jeu prend tout l'écran, les boutons Accueil / Changer flottent en haut */
@media (pointer: coarse) {
  body.en-partie { background: #000; }
  body.en-partie main { padding: 0; }
  body.en-partie .partie-barre {
    position: fixed; z-index: 20; margin: 0;
    top: max(6px, env(safe-area-inset-top)); left: max(6px, env(safe-area-inset-left));
  }
  body.en-partie .partie-barre .fil { display: none; }
  body.en-partie .partie-barre .fiche-boutons { margin: 0; gap: 6px; }
  body.en-partie .partie-barre .bouton { padding: 6px 10px; font-size: 13px; opacity: .8; box-shadow: 2px 2px 0 var(--encre); }
  body.en-partie #ecran { aspect-ratio: auto; height: 100vh; height: 100dvh; max-height: none; border-width: 0; border-radius: 0; box-shadow: none; }
  .btn-icone { width: 42px; height: 42px; font-size: 18px; }
  .jeu .titre { padding-right: 100px; }
  .puce { padding: 10px 14px; }
  .bouton { padding: 12px 16px; }
}

/* Petits écrans */
@media (max-width: 720px) {
  .topbar { padding: max(8px, env(safe-area-inset-top)) 12px 8px; }
  /* nowrap obligatoire : en colonne avec wrap, la ligne prend la largeur du menu et la page déborde */
  .barre { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 8px; padding: 10px; border-radius: 14px; box-shadow: 4px 4px 0 var(--encre); }
  .barre > * { min-width: 0; }
  .logo { font-size: 18px; }
  .logo-icone { width: 32px; height: 32px; }
  .modes { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -10px; padding: 0 10px 4px; }
  .modes::-webkit-scrollbar { display: none; }
  .modes a { font-size: 14px; padding: 8px 11px; flex: none; }
  .modes a.ajouter { margin-left: 0; box-shadow: 2px 2px 0 var(--encre); }
  main { padding: 16px 14px 60px; }
  .accueil { margin: 4px 0 30px; gap: 20px; }
  .accueil-texte .intro { font-size: 17px; }
  .bandeau-ecran { height: 90px; }
  .bandeau-bas strong { font-size: 22px; }
  .grille { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .case { min-height: 160px; padding: 12px; gap: 6px; border-radius: 14px; box-shadow: 4px 4px 0 var(--encre); }
  .case svg { height: 64px; }
  .case .nom { font-size: 18px; }
  .case .meta { font-size: 13px; }
  .case .icone-theme { width: 50px; height: 50px; font-size: 24px; }
  .compte { font-size: 11px; padding: 2px 6px; }
  .case-haut .pixel { font-size: 11px; }
  h2 { font-size: 24px; }
  .jeux { grid-template-columns: minmax(0, 1fr); }
  .outils select { flex: 1 1 45%; }
  .filtres { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 4px -14px 14px; padding: 2px 14px 6px; }
  .filtres::-webkit-scrollbar { display: none; }
  .puce { flex: none; }
  .titre-ligne .fiche-boutons { width: 100%; margin-top: 4px; }
  #ficheContenu { padding: 20px 18px 18px; }
  #ficheContenu h2 { font-size: 23px; }
  dialog { max-height: calc(100dvh - 24px); overflow-y: auto; }
  .lanceur { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .case, .jeu, .bandeau-homebrew { transition: none; }
}
