/* Le donjon des multiples : vue à la première personne, ambiance rétro chaleureuse.
   Deux styles (classe sur <body>) : « style-net » (image lissée, nombres en Fredoka) et
   « style-retro » (gros pixels et police pixel). */

@font-face {
  font-family: 'Fredoka Donjon';
  src: url(themes/fredoka-latin.woff2) format('woff2');
  font-weight: 300 700;
  font-display: swap;
}

.page-donjon {
  --nuit: #1c1229;
  --pierre: #5a4636;
  --pierre-claire: #8a6c52;
  --pierre-sombre: #2e2219;
  --or: #ffe9a8;
  background: radial-gradient(ellipse at 50% 0%, #3a2550 0%, var(--nuit) 70%) fixed;
  color: #f7e7c6;
  min-height: 100vh;
  overscroll-behavior: none;
}

/* barre du haut, assortie au donjon */
.page-donjon .barre { background: #2a1d3a; box-shadow: 0 2px 0 #120b1a; }
.page-donjon .barre h1 { color: var(--or); text-shadow: 2px 2px 0 #120b1a; letter-spacing: 0.5px; }
.page-donjon .etiquette { background: #4a3466; color: var(--or); }
.page-donjon .barre button, .page-donjon .barre .icone { background: #3c2a52; border-color: #5d4680; color: #f7e7c6; }
.page-donjon .barre button.principal { background: #e69f00; border-color: #b87d00; color: #1a1a1a; }

.donjon { margin: 6px auto 0; display: flex; flex-direction: column; gap: 8px; }

/* --- Vue --- */

.vue {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  background: #22163a;
  box-shadow: 0 0 0 3px var(--pierre-sombre), 0 0 0 6px var(--pierre), 0 10px 30px rgba(0, 0, 0, 0.5);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#ecran {
  display: block;
  width: 100%;
  height: 100%;
}
.style-retro #ecran { image-rendering: pixelated; image-rendering: crisp-edges; }

/* style net : une police ronde et grasse partout, nombres du HUD en vrai texte */
.style-net, .style-net button { font-family: 'Fredoka Donjon', system-ui, sans-serif; }
.style-net .lib { font-family: 'Fredoka Donjon', system-ui, sans-serif; font-weight: 600; font-size: 0.8rem; letter-spacing: 1.5px; }
.style-net canvas.pixel { display: none; }
.style-retro .hud-nombre { display: none; }
.hud-nombre {
  font: 700 2.1rem/1 'Fredoka Donjon', system-ui, sans-serif;
  color: var(--or);
  white-space: nowrap;
  text-shadow: 0 2px 0 #1a0f08, 2px 0 0 #1a0f08, -2px 0 0 #1a0f08, 0 -2px 0 #1a0f08, 2px 2px 0 #1a0f08, -2px 2px 0 #1a0f08, 3px 4px 4px rgba(0, 0, 0, 0.5);
}
.symbole-hud { margin-left: 4px; font-size: 0.85em; }
.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 55%, transparent 55%, rgba(20, 8, 30, 0.55) 100%);
}
/* style net : vignette et lueur de la lanterne sont calculées dans l'image (moins de calques) */
.style-net .vignette { display: none; }

.message-vue {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 92%;
  padding: 6px 14px;
  border-radius: 8px;
  background: rgba(28, 18, 41, 0.82);
  border: 2px solid #e69f00;
  color: var(--or);
  font-weight: 800;
  font-size: 1.1rem;
  text-align: center;
  text-shadow: 1px 1px 0 #000;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 2;
}
.message-vue.vide { opacity: 0; }

.carte {
  position: absolute;
  top: 10px;
  right: 10px;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}
.carte[hidden] { display: none; }

.fondu { position: absolute; inset: 0; background: #0d0814; opacity: 0; pointer-events: none; transition: opacity 0.26s ease; }
.fondu.noir { opacity: 1; }

/* secousse sur une erreur ; éclair rouge doux si les mouvements sont réduits */
.secousse-vue { animation: secousse-vue 0.32s; }
@keyframes secousse-vue {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-5px, 1px); }
  40% { transform: translate(5px, -1px); }
  60% { transform: translate(-3px, 0); }
  80% { transform: translate(3px, 0); }
}
.eclair-vue::after { content: ''; position: absolute; inset: 0; background: rgba(255, 90, 90, 0.35); animation: eclair-vue 0.4s forwards; pointer-events: none; }
@keyframes eclair-vue { to { opacity: 0; } }

/* écran de choix du départ */
.choix {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(20, 10, 32, 0.6);
}
.choix[hidden] { display: none; }
.carte-choix {
  width: min(100%, 440px);
  max-height: 100%;
  overflow-y: auto;
  padding: 16px 18px;
  border-radius: 12px;
  background: #f6e7c1;
  color: #2b1a0e;
  text-align: center;
  box-shadow: 0 0 0 4px #5a3a22, 0 12px 30px rgba(0, 0, 0, 0.5);
}
.carte-choix h2 { margin: 0 0 6px; font-size: 1.35rem; }
.carte-choix p { margin: 4px 0; font-size: 1.05rem; }
.carte-choix p[hidden] { display: none; }
.carte-choix .petit { margin-top: 10px; font-weight: 700; }
.liste-departs { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 8px 0 6px; }
.depart-choix {
  font: inherit;
  font-weight: 800;
  font-size: 1.1rem;
  min-height: 56px;
  min-width: 150px;
  padding: 6px 16px;
  border: none;
  border-radius: 10px;
  background: var(--coul);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25), 0 3px 0 #3a2414;
  cursor: pointer;
}
.depart-choix:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25), 0 1px 0 #3a2414; }
.depart-choix .symbole { margin-right: 4px; }
.aide-touches { color: #6b4a2e; font-size: 0.9rem !important; }
.aide-touches .tactile { display: none; }
@media (hover: none) and (pointer: coarse) {
  .aide-touches .clavier { display: none; }
  .aide-touches .tactile { display: inline; }
}

/* --- Bas : HUD et croix de déplacement --- */

.bas { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; justify-content: center; }

.hud {
  flex: 1 1 520px;
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 6px;
  background: var(--pierre);
  box-shadow: inset 2px 2px 0 var(--pierre-claire), inset -2px -2px 0 var(--pierre-sombre), 0 4px 0 #120b1a;
}
.panneau-hud {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 4px;
  border-radius: 4px;
  background: #3b2c22;
  box-shadow: inset 2px 2px 0 var(--pierre-sombre), inset -2px -2px 0 #6e5644;
}
.lib {
  font: 800 0.72rem/1 ui-monospace, 'Courier New', monospace;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #e3b25a;
  text-shadow: 1px 1px 0 #000;
}
canvas.pixel {
  height: calc(var(--px, 5px) * 9);
  width: calc(var(--px, 5px) * var(--l, 1));
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.panneau-hud.visage { flex: 0 0 auto; padding: 4px; background: #2a1d3a; }
/* pixel art 24 × 24 agrandi d'un facteur entier : net, sans flou */
#visage { width: 72px; height: 72px; image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
.page-donjon #nouvelle .court { display: none; }
.panneau-hud.chemins { flex-grow: 1.8; }
.pions { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.pion {
  font: inherit;
  font-weight: 900;
  font-size: 0.95rem;
  line-height: 1;
  min-width: 40px;
  min-height: 40px;
  padding: 2px 4px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: var(--coul);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3);
  cursor: pointer;
}
.pion small { font-size: 0.68rem; font-weight: 800; }
.style-net .pion small { font-size: 0.8rem; font-weight: 700; }
.pion.actif { outline: 3px solid var(--or); outline-offset: 1px; }
.pion.fini { opacity: 0.6; cursor: default; }
.bouton-carte { flex: 0 0 74px; font: inherit; color: inherit; border: none; cursor: pointer; }
.bouton-carte .picto { font-size: 1.6rem; line-height: 1; }
.bouton-carte[aria-pressed='true'] { background: #5d4680; box-shadow: inset 2px 2px 0 #2a1d3a, 0 0 0 2px var(--or); }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: 0; }

.croix {
  display: grid;
  grid-template-areas: 'g h d' '. b .';
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 58px);
  gap: 5px;
  flex: 0 0 auto;
}
.fleche {
  font: inherit;
  font-size: 1.9rem;
  font-weight: 900;
  line-height: 1;
  min-width: 56px;
  min-height: 56px;
  border: none;
  border-radius: 10px;
  background: #e69f00;
  color: #1a1a1a;
  box-shadow: inset 0 -5px 0 #a86f00, 0 3px 0 #120b1a;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.fleche:active { transform: translateY(2px); box-shadow: inset 0 -3px 0 #a86f00, 0 1px 0 #120b1a; }
.fleche[data-action='avancer'] { background: #ffc23d; }

/* carte de victoire : au-dessus du HUD, pour voir le grand sourire */
.page-donjon .victoire { bottom: calc(var(--bas-h, 0px) + 12px); background: #f6e7c1; color: #2b1a0e; box-shadow: 0 0 0 4px #5a3a22, 0 12px 32px rgba(0, 0, 0, 0.5); }

@media (max-width: 600px) {
  .donjon { margin-top: 4px; gap: 6px; }
  .hud { flex-basis: 100%; gap: 4px; padding: 4px; }
  .panneau-hud { padding: 4px 2px; gap: 3px; }
  canvas.pixel { --px: 3px; }
  #visage { width: 48px; height: 48px; }
  .hud-nombre { font-size: 1.6rem; }
  .style-net .lib { font-size: 0.68rem; letter-spacing: 1px; }
  .lib { font-size: 0.62rem; letter-spacing: 1px; }
  .pion { min-width: 34px; min-height: 34px; font-size: 0.85rem; }
  .bouton-carte { flex-basis: 52px; }
  .page-donjon #nouvelle .long { display: none; }
  .page-donjon #nouvelle .court { display: inline; }
  .pions { gap: 3px; }
  .pion { min-width: 30px; padding: 2px 2px; }
  .croix { grid-template-columns: repeat(3, 66px); grid-template-rows: repeat(2, 56px); gap: 4px; }
  .message-vue { font-size: 1rem; top: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .fondu { transition-duration: 0.2s; }
  .secousse-vue { animation: none; }
}
