@font-face { font-family: 'Pokemon DP'; src: url(../assets/polices/pkmndp.ttf) format('truetype'); font-weight: 400; font-display: block; }
@font-face { font-family: 'Pokemon DP'; src: url(../assets/polices/pkmndpb.ttf) format('truetype'); font-weight: 700; font-display: block; }

:root {
  --creme: #F8F0D8;
  --encre: #2A2238;
  --nuit: #1A1424;
  --jaune: #F8C030;
  --rouge: #C03048;
  --vert: #48C858;
  --bleu: #385898;
  --texte-cadre: #383838;
  --ombre-cadre: #B8B8B8;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; height: 100dvh; background: var(--nuit); overflow: hidden;
  position: fixed; inset: 0;
  touch-action: none; overscroll-behavior: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}

#scene-ecran { position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh; overflow: hidden; }
#ecran {
  position: absolute;
  left: 0;
  top: 0;
  width: 960px;
  height: 540px;
  overflow: hidden;
  background: var(--encre);
  color: var(--texte-cadre);
  font-family: 'Pokemon DP', monospace;
  font-size: 18px;
  line-height: 1;
  transform-origin: 0 0;
  -webkit-font-smoothing: none;
}
#ecran img { image-rendering: pixelated; }
.cache { display: none !important; }

#monde { position: absolute; left: 0; top: 0; width: 100%; height: 100%; image-rendering: pixelated; }

/* Fenêtres : vraies fenêtres de dialogue de Diamant et Perle, étirées en 9 morceaux. */
.fenetre { border-style: solid; border-width: 4px 21px 4px 10px; border-image-slice: 8 42 8 20 fill; border-image-width: 4px 21px 4px 10px; image-rendering: pixelated; }
.fenetre.large { border-width: 8px 42px 8px 20px; border-image-width: 8px 42px 8px 20px; }
.fenetre-neutre { border-image-source: url(../assets/ui/fenetre-neutre.png); }

/* Mini-icône de Pikachu (menu d'équipe) : deux images qui alternent. */
.mini {
  --t: 32px;
  display: inline-block;
  width: var(--t);
  height: var(--t);
  background: url(../assets/ui/icone-pikachu.png) 0 0 / calc(var(--t) * 2) var(--t) no-repeat;
  image-rendering: pixelated;
  animation: mini-bouge 300ms steps(2) infinite;
}
@keyframes mini-bouge { to { background-position-x: calc(var(--t) * -2); } }

/* ---------- Interface du haut ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; height: 60px; pointer-events: none; z-index: 5; text-shadow: 1px 1px 0 var(--ombre-cadre); }
#hud > * { position: absolute; top: 8px; height: 46px; }
#boite-niveau { left: 8px; width: 230px; padding: 4px 0 0 2px; }
#hud-niveau { font-size: 26px; font-weight: 700; white-space: nowrap; }
#hud-niveau b { color: #A87000; }
#hud-barre { position: relative; height: 8px; margin: 3px 4px 0 0; background: #484848; box-shadow: 0 0 0 2px var(--ombre-cadre); }
#hud-remplissage { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--vert); }
#hud-pikachu { --t: 24px; position: absolute; top: -20px; margin-left: -12px; }
#boite-chrono { left: 50%; transform: translateX(-50%); width: 210px; padding: 6px 0 0 4px; text-align: center; }
#hud-chrono { font-size: 38px; font-weight: 700; letter-spacing: 1px; font-variant-numeric: tabular-nums; }
#boite-chrono.arrete #hud-chrono { color: #2E7A3A; }
#boite-morts { right: 126px; width: 110px; padding: 6px 0 0 0; display: flex; align-items: center; gap: 6px; }
#boite-morts img { width: 24px; height: 24px; }
#hud-morts { font-size: 30px; font-weight: 700; }
#bouton-recommencer, #bouton-auto {
  width: 54px; pointer-events: auto; cursor: pointer;
  font: 700 30px 'Pokemon DP', monospace; color: var(--texte-cadre); background: none; padding: 0 0 4px 0; line-height: 1;
}
#bouton-recommencer { right: 8px; }
#bouton-auto { right: 68px; font-size: 20px; letter-spacing: -3px; color: #8A8A8A; padding: 0 2px 2px 0; }
#bouton-auto.actif { color: #2E7A3A; }
#bouton-recommencer:active, #bouton-auto:active { transform: translate(1px, 1px); }
/* Quitter la partie (retour au menu) : sous les boutons du haut, à côté du son */
#bouton-quitter {
  right: 68px; top: 60px; width: 54px; pointer-events: auto; cursor: pointer; touch-action: manipulation;
  font: 700 30px 'Pokemon DP', sans-serif; color: var(--texte-cadre); background: none; padding: 0 0 4px 0; line-height: 1;
}
#bouton-quitter:active { transform: translate(1px, 1px); }
#ecran.portrait #bouton-quitter { top: 114px; }

/* ---------- Portrait (téléphone tenu à la verticale) : cadre 540x960, interface sur deux lignes ---------- */
#ecran.portrait #hud { height: 116px; }
#ecran.portrait #boite-chrono { top: 8px; }
#ecran.portrait #boite-niveau { top: 62px; width: 220px; }
#ecran.portrait #boite-morts { top: 62px; }
#ecran.portrait #bouton-auto, #ecran.portrait #bouton-recommencer { top: 62px; }
#ecran.portrait #bandeau { top: 230px; width: 440px; margin-left: -220px; }
#ecran.portrait #bandeau-titre { font-size: 38px; }


/* ---------- Annonces ---------- */
#bandeau {
  position: absolute; left: 50%; top: 150px; width: 480px; margin-left: -240px;
  padding: 12px 0 10px 6px; text-align: center; z-index: 8; pointer-events: none;
  text-shadow: 1px 1px 0 var(--ombre-cadre);
}
#bandeau-titre { font-size: 44px; font-weight: 700; }
#bandeau-texte { margin-top: 8px; font-size: 24px; color: var(--bleu); }
#bandeau.reussi #bandeau-titre { color: #2E7A3A; }
#bandeau.entre { animation: bandeau-entre 240ms steps(6) both; }
@keyframes bandeau-entre { from { transform: translateY(-30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Écrans de menu : accueil, fin, classement ---------- */
.ecran-menu {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 12px; text-align: center; text-shadow: 1px 1px 0 var(--ombre-cadre);
}
#ecran-accueil, #ecran-classement { background: rgba(26, 20, 36, 0.35); }
.titre-jeu, #fin-titre, .titre-classement {
  font-weight: 700; color: #FFFFFF; line-height: 1;
  text-shadow: 4px 4px 0 var(--rouge), -4px -4px 0 #2860B8;
}
.titre-ligne1 { font-size: 72px; animation: titre-saute 900ms steps(3) infinite alternate; }
.titre-ligne2 { margin-top: 10px; font-size: 26px; letter-spacing: 3px; text-shadow: 2px 2px 0 var(--rouge), -2px -2px 0 #2860B8; }
#fin-titre { font-size: 64px; animation: titre-saute 900ms steps(3) infinite alternate; }
.titre-classement { font-size: 52px; }
@keyframes titre-saute { to { transform: translateY(-8px); } }

.cadre-menu { width: 500px; max-width: 100%; padding: 14px 4px 14px 2px; }
.cadre-accueil label { display: block; font-size: 24px; font-weight: 700; margin-bottom: 8px; }
#champ-pseudo {
  width: 330px; max-width: 90%; padding: 6px 10px; border: 3px solid #484848; border-radius: 0; outline: none;
  background: #FFFFFF; color: var(--texte-cadre); font: 700 28px 'Pokemon DP', monospace; text-align: center;
  user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
#champ-pseudo:focus { border-color: #2860B8; box-shadow: 0 0 0 2px #A0C0F0; }
#champ-pseudo.invalide { border-color: var(--rouge); }
.message-erreur { min-height: 22px; margin-top: 6px; font-size: 18px; color: var(--rouge); }
#accueil-record { min-height: 22px; font-size: 20px; color: var(--bleu); }
.boutons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 10px; }
.bouton-menu {
  min-width: 150px; padding: 7px 14px 5px 6px; cursor: pointer; background: none;
  font: 700 26px 'Pokemon DP', monospace; color: var(--texte-cadre); text-shadow: 1px 1px 0 var(--ombre-cadre);
  touch-action: manipulation;
}
.bouton-menu::before { content: '▶'; display: inline-block; width: 22px; color: transparent; font-size: 20px; }
.bouton-menu:hover, .bouton-menu:focus-visible { color: #A87000; outline: none; }
.bouton-menu:hover::before, .bouton-menu:focus-visible::before { color: var(--texte-cadre); }
.bouton-menu:active { transform: translate(1px, 1px); }
.bouton-menu:disabled { opacity: 0.5; cursor: default; }
.cadre-controles { width: 640px; max-width: 100%; padding: 8px 4px 6px 2px; font-size: 17px; line-height: 1.45; text-align: left; }
.cadre-controles b { color: var(--bleu); }
.lien-credits {
  margin-top: -4px; padding: 2px 8px; border: none; background: rgba(26, 20, 36, 0.55); cursor: pointer;
  font: 16px 'Pokemon DP', monospace; color: var(--creme); text-shadow: none; text-decoration: underline;
}
.lien-credits:hover, .lien-credits:focus-visible { color: var(--jaune); outline: none; }
#ecran-credits { z-index: 25; background: rgba(26, 20, 36, 0.6); }
.cadre-credits { width: 560px; }
.titre-credits { font-size: 30px; font-weight: 700; margin-bottom: 10px; }
#credits-texte { font-size: 18px; line-height: 1.5; padding: 0 10px; }
#credits-texte .noms { font-weight: 700; color: var(--bleu); }

#fin-cadre { width: 520px; }
#fin-temps { font-size: 68px; font-weight: 700; }
#fin-morts { margin-top: 6px; font-size: 24px; color: var(--bleu); }
#fin-record { margin-top: 10px; font-size: 26px; font-weight: 700; color: #2E7A3A; animation: clignote 600ms steps(2) infinite; }
@keyframes clignote { 50% { opacity: 0.35; } }
#fin-rang { min-height: 30px; margin-top: 10px; font-size: 26px; font-weight: 700; }
#fin-rang small { display: block; margin-top: 4px; font-size: 17px; font-weight: 400; color: var(--gris, #50485C); }

.cadre-classement { width: 620px; padding: 10px 4px 10px 2px; }
#classement-etat { min-height: 20px; margin-bottom: 6px; font-size: 18px; color: var(--bleu); }
#classement-etat.hors-ligne { color: var(--rouge); }
#classement-liste { max-height: 290px; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; scrollbar-width: thin; }
.ligne-score {
  display: grid; grid-template-columns: 64px 1fr 130px 112px; align-items: center; gap: 4px;
  height: 32px; padding: 0 8px; font-size: 22px; text-align: left; border-bottom: 2px solid #E0E0E0;
}
.ligne-score > :nth-child(3) { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.ligne-score > :nth-child(4) { font-size: 17px; text-align: right; color: #707070; }
.ligne-score > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne-score.entete { height: 26px; font-size: 17px; color: var(--bleu); border-bottom: 3px solid #A8A8A8; }
.ligne-score .rang { display: flex; align-items: center; gap: 4px; font-weight: 700; }
.ligne-score .rang img { width: 22px; height: 22px; }
.ligne-score.or { background: linear-gradient(90deg, #F8E070, #FFF4C0); }
.ligne-score.argent { background: linear-gradient(90deg, #D8D8E8, #F4F4FA); }
.ligne-score.bronze { background: linear-gradient(90deg, #E8B888, #FAE6D4); }
.ligne-score.moi { box-shadow: inset 0 0 0 3px var(--vert); background-color: #DFF8D0; }
.ligne-score.moi:not(.or):not(.argent):not(.bronze) { background: #DFF8D0; }
.classement-vide { padding: 30px 0; font-size: 22px; color: #707070; }

/* Portrait : écrans empilés, un peu plus serrés en largeur. */
#ecran.portrait .titre-ligne1 { font-size: 56px; }
#ecran.portrait .titre-ligne2 { font-size: 20px; }
#ecran.portrait .cadre-controles { font-size: 16px; }
#ecran.portrait #fin-titre { font-size: 56px; }
#ecran.portrait #fin-cadre { width: 500px; }
#ecran.portrait .ligne-score { grid-template-columns: 56px 1fr 112px 92px; font-size: 20px; }
#ecran.portrait #classement-liste { max-height: none; flex: 1; }
#ecran.portrait .cadre-classement { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: 120px; }
#ecran.portrait #ecran-classement { justify-content: flex-start; padding-bottom: 40px; }
#ecran.portrait #ecran-classement .titre-classement { position: absolute; top: 40px; }

/* ---------- Boutons tactiles (hors du cadre du jeu) ---------- */
#tactile { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.bouton-tactile {
  position: absolute; bottom: max(4vh, env(safe-area-inset-bottom));
  width: min(20vmin, 120px); height: min(20vmin, 120px); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font: 700 min(8vmin, 44px) 'Pokemon DP', sans-serif; color: rgba(255, 255, 255, 0.75);
  background: rgba(26, 20, 36, 0.22); border: 3px solid rgba(248, 240, 216, 0.45);
  pointer-events: auto; touch-action: none;
}
.bouton-tactile.appuye { background: rgba(248, 192, 48, 0.4); border-color: rgba(248, 240, 216, 0.85); }
#tactile-gauche { left: max(2.5vw, env(safe-area-inset-left)); }
#tactile-droite { left: calc(max(2.5vw, env(safe-area-inset-left)) + min(20vmin, 120px) + 2vw); }
#tactile-saut { right: max(3vw, env(safe-area-inset-right)); width: min(25vmin, 140px); height: min(25vmin, 140px); }

#chargement { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; background: var(--nuit); color: var(--creme); font: 700 32px 'Pokemon DP', monospace; }

/* ---------- Accueil : contrôles + encart Twitch ---------- */
.ligne-accueil { display: flex; gap: 10px; align-items: stretch; justify-content: center; max-width: 100%; }
.ligne-accueil .cadre-controles { width: 400px; font-size: 16px; line-height: 1.4; }
.cadre-twitch { width: 230px; padding: 8px 4px 8px 2px; display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.twitch-titre { font-size: 18px; font-weight: 700; color: #6441A5; line-height: 1.2; }
.bouton-twitch {
  display: inline-block; padding: 6px 8px; background: #9146FF; color: #FFFFFF; text-decoration: none;
  font: 700 18px 'Pokemon DP', monospace; text-shadow: 1px 1px 0 #4B2A88; border: 3px solid #4B2A88; touch-action: manipulation;
}
.bouton-twitch:hover, .bouton-twitch:focus-visible { background: #A970FF; outline: none; }
#ecran.portrait .ligne-accueil { flex-direction: column; align-items: center; }
#ecran.portrait .ligne-accueil .cadre-controles, #ecran.portrait .cadre-twitch { width: 500px; max-width: 100%; }

/* ---------- Hub ---------- */
#ecran-hub { justify-content: flex-start; padding-top: 14px; background: rgba(26, 20, 36, 0.35); }
.hub-entete { width: 640px; max-width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bouton-menu.petit { min-width: 0; font-size: 18px; padding: 5px 10px 3px 4px; }
.hub-dresseur { font-size: 22px; color: var(--creme); text-shadow: 2px 2px 0 var(--nuit); }
.hub-dresseur b { color: var(--jaune); }
.onglets { display: flex; gap: 6px; }
.onglet {
  padding: 6px 14px 4px; cursor: pointer; border: 3px solid #484848; border-bottom: none; background: #C8C0D8;
  font: 700 22px 'Pokemon DP', monospace; color: var(--texte-cadre); touch-action: manipulation;
}
.onglet.actif { background: #F8F8F8; color: #A87000; transform: translateY(3px); }
.onglet:focus-visible { outline: 3px solid var(--jaune); }
.cadre-hub { width: 640px; max-width: 100%; padding: 12px 4px 12px 2px; min-height: 0; }
.panneau-hub { display: grid; gap: 10px; }
#hub-mondes { grid-template-columns: repeat(3, 1fr); }
#hub-pokemon { grid-template-columns: repeat(4, 1fr); }
.carte-monde, .carte-pkm {
  position: relative; border: 3px solid #A8A8A8; background: #FFFFFF; padding: 8px 6px; text-align: center;
  font: 16px 'Pokemon DP', monospace; color: var(--texte-cadre); text-shadow: none;
}
button.carte-monde { cursor: pointer; touch-action: manipulation; }
button.carte-monde:hover, button.carte-monde:focus-visible { border-color: var(--jaune); outline: none; background: #FFF8E0; }
.carte-monde .numero { font-size: 15px; color: var(--bleu); }
.carte-monde .nom-monde { margin: 4px 0; font-size: 22px; font-weight: 700; }
.carte-monde .desc { font-size: 14px; color: #707070; line-height: 1.3; min-height: 36px; }
.carte-monde .record { margin-top: 6px; font-size: 15px; color: #2E7A3A; min-height: 18px; }
.carte-monde .jouer { margin-top: 6px; font-size: 20px; font-weight: 700; color: #A87000; }
.verrouille { opacity: 0.55; filter: grayscale(1); cursor: not-allowed; }
.carte-pkm canvas { display: block; margin: 0 auto; image-rendering: pixelated; height: 72px; }
.carte-pkm .nom-pkm { margin-top: 2px; font-size: 18px; font-weight: 700; }
.carte-pkm .etat-pkm { font-size: 13px; color: #707070; min-height: 16px; }
.carte-pkm.choisi { border-color: #48C858; background: #EFFBEA; }
.carte-pkm.choisi .etat-pkm { color: #2E7A3A; }
#ecran.portrait #hub-mondes { grid-template-columns: 1fr; }
#ecran.portrait #hub-pokemon { grid-template-columns: repeat(2, 1fr); }
#ecran.portrait .cadre-hub, #ecran.portrait .hub-entete { width: 500px; }

/* Icône du Pokémon utilisé, dans le classement */
.icone-pkm { width: 24px; height: 24px; object-fit: contain; vertical-align: -6px; margin-right: 6px; image-rendering: pixelated; }
.ligne-score .mini { --t: 24px; vertical-align: -6px; margin-right: 6px; }

/* ---------- Bouton son (toujours visible) ---------- */
#bouton-son {
  position: absolute; z-index: 30; right: 8px; top: 8px; width: 54px; height: 46px; padding: 0 0 2px 0;
  background: none; cursor: pointer; font-size: 22px; line-height: 1; touch-action: manipulation;
}
#bouton-son:active { transform: translate(1px, 1px); }
#ecran[data-phase="jeu"] #bouton-son { top: 60px; }
#ecran.portrait[data-phase="jeu"] #bouton-son { top: 114px; }

/* Accueil en paysage : tout doit tenir dans 540 px de haut. */
#ecran:not(.portrait) #ecran-accueil { gap: 8px; padding-top: 8px; padding-bottom: 6px; }
#ecran:not(.portrait) .titre-ligne1 { font-size: 58px; }
#ecran:not(.portrait) .titre-ligne2 { margin-top: 6px; font-size: 22px; }
#ecran:not(.portrait) .cadre-accueil { padding-top: 10px; padding-bottom: 10px; }
#ecran:not(.portrait) .cadre-accueil .boutons { margin-top: 4px; }
.cadre-twitch { width: 250px; }
.bouton-twitch { font-size: 16px; white-space: nowrap; }
/* Hub : laisser la place au bouton son en haut à droite. */
.hub-entete { padding-right: 64px; }

/* ---------- Accueil : pseudo + code ---------- */
.ligne-identite { display: flex; gap: 10px; justify-content: center; align-items: flex-end; }
.ligne-identite .champ { display: flex; flex-direction: column; align-items: center; }
.ligne-identite label { margin-bottom: 6px; }
#ecran-accueil .ligne-identite #champ-pseudo { width: 300px; }
#champ-code {
  width: 120px; padding: 6px 8px; border: 3px solid #484848; border-radius: 0; outline: none; background: #FFFFFF;
  color: var(--texte-cadre); font: 700 28px 'Pokemon DP', monospace; text-align: center; letter-spacing: 4px;
  user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
#champ-code:focus { border-color: #2860B8; box-shadow: 0 0 0 2px #A0C0F0; }
#champ-code.invalide { border-color: var(--rouge); }
#champ-code::placeholder { font-size: 16px; letter-spacing: 0; font-weight: 400; }
.aide-code { margin-top: 6px; font-size: 14px; color: #707070; line-height: 1.3; }
#ecran.portrait .ligne-identite { flex-direction: column; align-items: center; }
#ecran.portrait #ecran-accueil .ligne-identite #champ-pseudo { width: 330px; }
/* Hub : message (profil créé, mode local…) */
.hub-message { width: 640px; max-width: 100%; padding: 6px 10px; background: #FFF4C0; border: 3px solid #F8C030; font-size: 17px; color: var(--texte-cadre); text-shadow: none; }
.hub-message.local { background: #F8E0E4; border-color: var(--rouge); }
#ecran.portrait .hub-message { width: 500px; }

/* ---------- Déblocages ---------- */
#fin-deblocage { margin-top: 8px; padding: 4px 8px; background: #FFF4C0; border: 3px solid #F8C030; font-size: 24px; font-weight: 700; color: #A87000; }
.carte-pkm .etat-pkm.condition { color: #A87000; }
/* Panneau de debug (local seulement) : simuler la fin de Route Paisible. */
.hub-debug { width: 640px; max-width: 100%; padding: 6px 10px; background: #2A2238; color: #F8F0D8; font: 15px 'Pokemon DP', monospace; text-shadow: none; display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; }
.hub-debug input { width: 80px; font: inherit; padding: 2px 4px; }
.hub-debug button { font: inherit; padding: 2px 8px; cursor: pointer; }
#ecran.portrait .hub-debug { width: 500px; }
/* Le panneau de debug reste toujours visible, dans le coin bas gauche. */
.hub-debug { position: absolute; left: 8px; bottom: 8px; width: auto; z-index: 26; }

/* Classement : un onglet par monde */
.onglets-monde { justify-content: center; margin-bottom: -3px; position: relative; z-index: 1; }
.onglets-monde .onglet { font-size: 18px; }
.onglets-monde:empty { display: none; }
#ecran.portrait .onglets-monde { margin-top: 110px; }
#ecran.portrait .onglets-monde + .cadre-classement { margin-top: 0; }
