/* layout.css — la scène de jeu au ratio 9:16, centrée, letterbox autour */

body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
}

#game {
  position: relative;
  aspect-ratio: 9 / 16;
  width: min(100vw, calc(100dvh * 9 / 16));
  height: min(100dvh, calc(100vw * 16 / 9));
  margin: auto;
  overflow: hidden;
  overflow-x: hidden;
  background: var(--plum-deep);
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Transition de scène (fondu). */
#game.is-fading {
  opacity: 0;
}
#game {
  transition: opacity 0.18s ease;
}
#game input,
#game textarea,
#game [contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

/* Couche de fond plein cadre. */
.scene-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 0;
  transform: scale(1);
  transform-origin: 50% 70%;
}

/* Voile sombre par-dessus le fond. */
.scene-dim {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* --- HUD (barre de contrôle haute) --- */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.35rem;
  padding: 0.6rem 0.7rem;
  pointer-events: none;
}
.hud:not(:has(.hud-feathers-slot)) {
  grid-template-columns: auto auto;
  justify-content: space-between;
}
.hud > * {
  pointer-events: auto;
}
.hud-group {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
  align-items: center;
}
.hud-feathers-slot {
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 0;
  pointer-events: none;
}
.hud-btn {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  background: rgba(26, 6, 38, 0.6);
  color: var(--cream);
  font-weight: 800;
  font-size: 1.1rem;
  backdrop-filter: blur(6px);
  border: 1.5px solid rgba(245, 196, 81, 0.45);
}
.hud-lang {
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}
.hud-feathers {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex: 0 1 auto;
  max-width: 100%;
  background: rgba(26, 6, 38, 0.6);
  border: 1.5px solid rgba(255, 79, 151, 0.5);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-weight: 800;
  backdrop-filter: blur(6px);
  white-space: nowrap;
  pointer-events: auto;
}
.hud-feathers.has-gold {
  border-color: rgba(245, 196, 81, 0.55);
  padding-right: 0.85rem;
}
.hud-feather-group {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.hud-feather-group--gold {
  padding-left: 0.35rem;
  padding-right: 0.12rem;
  border-left: 1px solid rgba(255, 246, 233, 0.22);
  gap: 0.38rem;
}
.hud-feathers .feather-pip {
  color: var(--pink);
  filter: drop-shadow(0 0 4px rgba(255, 79, 151, 0.6));
}
.hud-feathers .feather-pip-gold {
  width: 1.05rem;
  height: auto;
  filter: sepia(0.85) saturate(4) hue-rotate(5deg) brightness(1.1)
    drop-shadow(0 0 4px rgba(245, 196, 81, 0.65));
}
.hud-feathers .feather-gold-count {
  color: var(--gold);
  font-size: 0.95em;
}
.map-card-status i,
.map-card .map-card-status {
  color: inherit;
}
/* Drapeaux (flag-icons) : coins arrondis et taille cohérente. */
.fi {
  border-radius: 3px;
  line-height: 1em;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.hud-lang .fi {
  width: 1.4rem;
  height: 1.05rem;
  background-size: cover;
}

/* Sélecteur de langue (menu déroulant) */
.hud-lang-picker {
  position: relative;
}
.hud-lang-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}
.hud-lang-menu {
  position: absolute;
  top: calc(100% + 0.38rem);
  right: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.18rem;
  min-width: 9.5rem;
  max-height: min(52vh, 17rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(245, 196, 81, 0.72) rgba(26, 6, 38, 0.55);
  padding: 0.38rem;
  padding-right: 0.28rem;
  border-radius: 14px;
  background: rgba(26, 6, 38, 0.94);
  border: 1.5px solid rgba(245, 196, 81, 0.45);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(8px);
  visibility: hidden;
  opacity: 0;
  transform: translateY(-8px) scale(0.95);
  pointer-events: none;
  transition:
    opacity 0.22s ease,
    transform 0.24s cubic-bezier(0.22, 1.12, 0.36, 1),
    visibility 0.22s ease;
}
.hud-lang-menu::-webkit-scrollbar {
  width: 6px;
}
.hud-lang-menu::-webkit-scrollbar-track {
  background: rgba(26, 6, 38, 0.55);
  border-radius: 999px;
  margin: 0.35rem 0;
}
.hud-lang-menu::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  border-radius: 999px;
  border: 1.5px solid rgba(20, 6, 30, 0.45);
  box-shadow: 0 0 8px rgba(245, 196, 81, 0.28);
}
.hud-lang-menu::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #ffe08a, var(--gold));
}
.hud-lang-picker.is-open .hud-lang-menu {
  visibility: visible;
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.hud-lang-option {
  display: flex;
  align-items: center;
  gap: 0.48rem;
  width: 100%;
  padding: 0.42rem 0.52rem;
  border-radius: 10px;
  background: transparent;
  color: var(--cream);
  font-weight: 700;
  font-size: 0.82rem;
  text-align: left;
  transition: background 0.15s ease;
}
.hud-lang-option .fi {
  width: 1.28rem;
  height: 0.92rem;
  flex-shrink: 0;
}
.hud-lang-option-label,
.lang-option-label {
  flex: 1 1 auto;
  line-height: 1.1;
}
.hud-lang-option.is-active,
.settings-lang-option.is-active {
  background: rgba(245, 196, 81, 0.16);
  color: var(--gold);
}
.hud-lang-check,
.lang-option-check {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--gold);
}
.hud-decrees {
  position: relative;
  color: var(--gold);
  overflow: visible;
}
.hud-decrees-icon {
  display: block;
  width: 1.55rem;
  height: auto;
  max-height: 1.7rem;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.45));
}
.hud-decrees--new {
  animation: hud-decrees-pulse 1.6s ease-in-out infinite;
}
@keyframes hud-decrees-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(245, 196, 81, 0.45);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(245, 196, 81, 0);
  }
}
.hud-decrees-badge {
  position: absolute;
  top: -0.15rem;
  right: -0.1rem;
  min-width: 1.05rem;
  height: 1.05rem;
  padding: 0 0.18rem;
  border-radius: 999px;
  background: var(--pink);
  color: #fff;
  font-size: 0.58rem;
  font-weight: 900;
  line-height: 1.05rem;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

/* Personnages (PNG transparents ancrés en bas). */
.character {
  position: absolute;
  bottom: 0;
  display: block;
  height: 58%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  z-index: 10;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.45));
  pointer-events: none;
  user-select: none;
  animation: char-in 0.4s ease both;
}
.char-left {
  left: -2%;
}
.char-right {
  right: -2%;
}
.char-center {
  left: 50%;
  transform: translateX(-50%);
  height: 62%;
}
.char-small {
  height: 46%;
}
/* Alcofribas (cellier) : plus grand et remonté pour bien le voir. */
.char-cellar {
  left: -1%;
  bottom: 8%;
  height: 70%;
  z-index: 12;
}
.char-center.character {
  animation: char-in-center 0.4s ease both;
}
.is-dim {
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.45)) brightness(0.5) saturate(0.6);
  transition: filter 0.4s ease;
}

@keyframes char-in {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes char-in-center {
  from { opacity: 0; transform: translateX(-50%) translateY(18px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Animation de plume gagnée (générique). */
.feather-award {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 26%;
  transform: translate(-50%, -50%);
  z-index: 50;
  pointer-events: none;
  animation: feather-pop 1.7s ease forwards;
  filter: drop-shadow(0 0 18px var(--pink));
}
@keyframes feather-pop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.4) rotate(-20deg); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(6deg); }
  70% { opacity: 1; transform: translate(-50%, -52%) scale(1) rotate(-3deg); }
  100% { opacity: 0; transform: translate(20%, -120%) scale(0.7) rotate(15deg); }
}

/* Plume qui vole vers le compteur du HUD. */
.feather-fly {
  position: absolute;
  left: 50%;
  top: 44%;
  width: 26%;
  transform: translate(-50%, -50%);
  z-index: 50;
  pointer-events: none;
  filter: drop-shadow(0 0 18px var(--pink));
}
.feather-fly.is-flying {
  animation: feather-fly 1.25s cubic-bezier(0.5, 0, 0.35, 1) forwards;
}
.feather-fly--gold {
  filter: sepia(0.85) saturate(4) hue-rotate(5deg) brightness(1.15)
    drop-shadow(0 0 18px rgba(245, 196, 81, 0.75));
}
@keyframes feather-fly {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.4) rotate(-20deg); }
  16% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(6deg); }
  42% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  100% {
    opacity: 0.25;
    transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(0.16) rotate(24deg);
  }
}

/* Pulsation du compteur quand une plume arrive. */
.hud-feathers.is-bumping {
  animation: hud-bump 0.5s ease;
}
@keyframes hud-bump {
  0%, 100% { transform: scale(1); }
  35% { transform: scale(1.28); border-color: var(--gold); }
}

/* Secousse (mauvaise réponse). */
.shake {
  animation: shake 0.4s ease;
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

/* --- Particules dorées (repère plume en or) --- */
.has-golden-sparkle {
  position: relative;
}
.golden-particles {
  position: absolute;
  inset: -18%;
  pointer-events: none;
  overflow: visible;
  z-index: 2;
}
.golden-particle {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff8dc, var(--gold));
  box-shadow: 0 0 6px var(--gold), 0 0 14px rgba(245, 196, 81, 0.55);
  animation: gold-sparkle var(--dur) ease-in-out infinite;
  animation-delay: var(--delay);
  opacity: 0;
}
@keyframes gold-sparkle {
  0%, 100% {
    opacity: 0;
    transform: scale(0.4) translateY(0);
  }
  45% {
    opacity: 1;
    transform: scale(1.15) translateY(var(--drift));
  }
}

/* --- Particules blanches (faisan) --- */
.has-white-sparkle {
  position: relative;
}
.white-particles {
  position: absolute;
  inset: -12%;
  pointer-events: none;
  overflow: visible;
  z-index: 2;
}
.white-particle {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 5px;
  height: 8px;
  border-radius: 50% 50% 50% 0;
  background: linear-gradient(160deg, #fff, rgba(255, 246, 233, 0.85));
  box-shadow: 0 0 5px rgba(255, 255, 255, 0.7);
  transform: rotate(35deg);
  animation: white-sparkle var(--dur) ease-in-out infinite;
  animation-delay: var(--delay);
  opacity: 0;
}
.white-particle-burst {
  position: absolute;
  left: var(--bx);
  top: var(--by);
  width: 6px;
  height: 9px;
  border-radius: 50% 50% 50% 0;
  background: #fff;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.85);
  transform: rotate(25deg);
  pointer-events: none;
  z-index: 3;
  animation: white-burst 0.7s ease-out forwards;
}
@keyframes white-sparkle {
  0%, 100% { opacity: 0; transform: rotate(35deg) scale(0.5); }
  50% { opacity: 0.95; transform: rotate(35deg) scale(1) translateY(var(--drift)); }
}
@keyframes white-burst {
  0% {
    opacity: 1;
    transform: rotate(25deg) translate(0, 0) scale(0.6);
  }
  100% {
    opacity: 0;
    transform: rotate(25deg) translate(var(--drift), var(--fly)) scale(1);
  }
}
