:root {
  --bg: #14101e;
  --panel: #221b33;
  --panel-2: #2d2442;
  --line: #3d3259;
  --text: #f3eefc;
  --muted: #a99fc2;
  --accent: #ffd640;
  --accent-ink: #2a2100;
  --danger: #ff5c7a;
  --hp: #44d17a;
  --hp-mid: #f5c542;
  --hp-low: #ff5c5c;
  --xp: #5cb8ff;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, 'Segoe UI', sans-serif;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  padding: 9px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
  transition: transform .06s, filter .15s;
}

button:hover:not(:disabled) {
  filter: brightness(1.08);
}

button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .35);
}

button:disabled {
  opacity: .45;
  cursor: default;
}

button.secondary {
  background: var(--panel-2);
  color: var(--text);
}

button.danger {
  background: var(--danger);
  color: #fff;
}

button.icon {
  padding: 4px 10px;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

kbd {
  font-size: 11px;
  opacity: .6;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 0 4px;
  margin-left: 4px;
}

input {
  font: inherit;
  color: var(--text);
  background: #120e1b;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Auth ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: radial-gradient(circle at 30% 20%, #3b2a66, transparent 60%), radial-gradient(circle at 80% 90%, #1f4a3a, transparent 50%), var(--bg);
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}

.card h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -.5px;
}

.card h1 span {
  color: var(--accent);
}

.subtitle {
  margin: -8px 0 4px;
  color: var(--muted);
}

.card label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.google-slot {
  display: flex;
  justify-content: center;
  min-height: 44px;
}

.auth-new,
.auth-form {
  display: grid;
  gap: 12px;
}

.auth-hint {
  margin: 0;
  font-size: 14px;
}

.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  justify-self: start;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.row button {
  flex: 1;
}

.error {
  color: var(--danger);
  margin: 0;
  min-height: 1.4em;
  font-size: 14px;
}

/* ---------- HUD ---------- */
#world {
  position: fixed;
  inset: 0;
  display: block;
}

#hud-top {
  position: fixed;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: calc(100% - 220px);
}

#hud-top>span {
  background: rgba(20, 16, 30, .75);
  backdrop-filter: blur(4px);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

#zone-name {
  color: #b8f5a0;
}

#online-count {
  color: var(--muted);
}

#hud-top>.game-clock {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-left: 6px;
  font-variant-numeric: tabular-nums;
}

.game-clock-dial { display: block; }
.game-clock-day { fill: #6fb8ff; }
.game-clock-night { fill: #1d2550; }
.game-clock-rim { fill: none; stroke: rgba(255, 255, 255, .35); stroke-width: 1; }
.game-clock-sun { fill: #ffd84a; stroke: #fff3b0; stroke-width: .8; }
.game-clock-moon { fill: #e8ecff; stroke: #9aa6d8; stroke-width: .8; }
.game-clock.night b { color: #b9c4ff; }

#hud-actions {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
}

#hud-actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#hud-actions kbd {
  margin-left: 0;
}

.touch-only {
  display: none !important;
}

#chat {
  position: fixed;
  left: 12px;
  bottom: 12px;
  width: min(360px, calc(100% - 24px));
  display: grid;
  gap: 6px;
}

#chat-log {
  max-height: 160px;
  overflow-y: auto;
  font-size: 13px;
  display: grid;
  gap: 2px;
}

#chat-log div {
  background: rgba(20, 16, 30, .65);
  padding: 3px 8px;
  border-radius: 6px;
  width: fit-content;
  max-width: 100%;
  overflow-wrap: anywhere;
}

#chat-log b {
  color: var(--accent);
}

#chat-input {
  background: rgba(18, 14, 27, .8);
  padding: 8px 12px;
}

#toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translate(-50%, -20px);
  opacity: 0;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 12px;
  transition: opacity .2s, transform .2s;
  max-width: calc(100% - 32px);
  text-align: center;
  z-index: 50;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#dpad {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: grid;
  grid-template: repeat(3, 56px) / repeat(3, 56px);
  gap: 4px;
  touch-action: none;
}

#dpad button {
  background: rgba(34, 27, 51, .75);
  color: var(--text);
  font-size: 20px;
  padding: 0;
}

#dpad [data-dir=up] {
  grid-area: 1 / 2;
}

#dpad [data-dir=left] {
  grid-area: 2 / 1;
}

#dpad [data-dir=right] {
  grid-area: 2 / 3;
}

#dpad [data-dir=down] {
  grid-area: 3 / 2;
}

/* ---------- Équipe ---------- */
#team-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(400px, 100%);
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 16px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: -20px 0 50px rgba(0, 0, 0, .4);
}

#team-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#team-panel h2 {
  margin: 0;
  font-size: 20px;
}

#team-panel h3 {
  margin: 18px 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.mon-list {
  display: grid;
  gap: 8px;
}

.mon-card {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  background: var(--panel-2);
  border-radius: 12px;
  padding: 10px;
  align-items: center;
}

.mon-card img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  background: rgba(0, 0, 0, .2);
  border-radius: 10px;
}

.mon-card .body {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.mon-card .title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.mon-card small {
  color: var(--muted);
  font-size: 12px;
}

.card-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.card-actions button {
  padding: 5px 10px;
  font-size: 13px;
}

.empty {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}

.rarity-badge {
  --c: #999;
  justify-self: start;
  width: fit-content;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--c);
  border: 1px solid var(--c);
  border-radius: 999px;
  padding: 0 8px;
}

.bar {
  height: 8px;
  background: rgba(0, 0, 0, .4);
  border-radius: 999px;
  overflow: hidden;
}

.bar>div {
  height: 100%;
  width: 100%;
  background: var(--hp);
  border-radius: inherit;
  transition: width .5s ease;
}

.bar.mid>div {
  background: var(--hp-mid);
}

.bar.low>div {
  background: var(--hp-low);
}

.bar.xp {
  height: 4px;
}

.bar.xp>div {
  background: var(--xp);
}

/* ---------- Combat ---------- */
#battle {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-rows: 1fr auto;
  background: linear-gradient(#8fd3ff 0%, #c9ecff 45%, #7cc86a 45%, #5aa84b 100%);
}

/* Fond choisi dans l'admin (pixel art : agrandi sans flou, sans toucher aux sprites des monstres). */
#battle.has-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--battle-bg) center bottom / cover no-repeat, #5aa84b;
  image-rendering: pixelated;
}

#battle.intro {
  animation: battle-in .45s ease-out;
}

@keyframes battle-in {
  from {
    clip-path: circle(0% at 50% 50%);
  }

  to {
    clip-path: circle(75% at 50% 50%);
  }
}

.arena {
  position: relative;
  display: grid;
  grid-template-rows: 1fr 1fr;
  padding: 16px clamp(16px, 5vw, 80px);
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
}

.side {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.side .info {
  background: rgba(20, 16, 30, .85);
  border-radius: 14px;
  padding: 10px 14px;
  width: min(300px, 48vw);
  display: grid;
  gap: 6px;
}

.side .title {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  gap: 8px;
}

.side .hptext {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.pedestal {
  position: relative;
  display: grid;
  place-items: center;
}

.pedestal::after {
  content: '';
  position: absolute;
  bottom: 4%;
  width: 90%;
  height: 18%;
  background: rgba(0, 0, 0, .2);
  border-radius: 50%;
  z-index: -1;
}

.sprite {
  width: clamp(110px, 22vw, 220px);
  height: clamp(110px, 22vw, 220px);
  object-fit: contain;
}

.pedestal .fx {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 130%;
  aspect-ratio: 1;
  translate: -50% -50%;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 2;
}

.pedestal .fx.mirror {
  scale: -1 1;
}

.side.wild .sprite {
  animation: float 2.4s ease-in-out infinite;
}

.side.mine .sprite {
  transform: scaleX(-1);
}

/* Vue de dos (animation « dos ») : pas besoin de retourner l'image vers l'adversaire. */
.side.mine .sprite.back {
  transform: none;
}

@keyframes float {
  50% {
    translate: 0 -8px;
  }
}

.arena .side .sprite.hit {
  animation: hit .4s;
}

.arena .side.mine .sprite.hit {
  animation: hit-mine .4s;
}

@keyframes hit {

  0%,
  100% {
    translate: 0;
    filter: none;
  }

  20% {
    translate: -10px;
    filter: brightness(2.5);
  }

  40% {
    translate: 10px;
  }

  60% {
    translate: -6px;
    filter: brightness(2);
  }

  80% {
    translate: 4px;
  }
}

@keyframes hit-mine {

  0%,
  100% {
    translate: 0;
    filter: none;
  }

  20% {
    translate: 10px;
    filter: brightness(2.5);
  }

  40% {
    translate: -10px;
  }

  60% {
    translate: 6px;
  }
}

#battle .panel {
  background: var(--panel);
  border-top: 3px solid var(--line);
  padding: 14px clamp(16px, 5vw, 80px) 18px;
  display: grid;
  gap: 12px;
}

#battle .log {
  min-height: 72px;
  display: grid;
  gap: 2px;
  align-content: start;
}

#battle .log p {
  margin: 0;
  animation: line-in .2s ease-out;
}

@keyframes line-in {
  from {
    opacity: 0;
    translate: -6px 0;
  }

  to {
    opacity: 1;
    translate: 0;
  }
}

#battle .actions {
  display: grid;
  gap: 8px;
}

#battle .other {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

#battle .other button {
  padding: 7px 10px;
  font-size: 14px;
}

/* Tirage pierre-feuille-ciseaux */
@keyframes shake-mine {
  0% {
    translate: -60px 0;
    opacity: 0;
  }

  60% {
    translate: 6px 0;
    opacity: 1;
  }

  100% {
    translate: 0;
  }
}

@keyframes shake-wild {
  0% {
    translate: 60px 0;
    opacity: 0;
  }

  60% {
    translate: -6px 0;
    opacity: 1;
  }

  100% {
    translate: 0;
  }
}

.choice-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.choice-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
  padding: 8px 12px;
}

.choice-item img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.choice-item small {
  margin-left: auto;
  color: var(--muted);
  font-weight: 500;
}

.choice-hint {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-style: italic;
}

#battle .continue {
  justify-self: end;
  min-width: 160px;
}

img.pixel {
  image-rendering: pixelated;
}

/* ---------- Pokédex ---------- */
.dex-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  /* Ligne et colonne à la taille de l'écran : sinon la ligne prend la hauteur de toute la liste des espèces, et la
     fenêtre est centrée dans cette ligne trop haute (décalée vers le bas). */
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  padding: 16px;
  background: rgba(10, 8, 18, .6);
  backdrop-filter: blur(3px);
}

.dex {
  width: min(980px, 100%);
  height: min(680px, 100%);
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

.dex-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
}

.dex-head h2 {
  margin: 0;
  font-size: 22px;
}

.dex-progress-text {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.dex-progress {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .4);
  overflow: hidden;
}

.dex-progress>div {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: inherit;
  transition: width .5s ease;
}

.dex-progress .seen {
  background: color-mix(in srgb, var(--xp) 45%, transparent);
}

.dex-progress .caught {
  background: var(--accent);
}

.dex-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.dex-filters button {
  background: var(--panel-2);
  color: var(--muted);
  box-shadow: none;
  padding: 6px 12px;
  font-size: 13px;
}

.dex-filters button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.dex-body {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 14px;
  min-height: 0;
}

.dex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  align-content: start;
  overflow-y: auto;
  padding-right: 4px;
}

.dex-card {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 10px 6px 8px;
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid transparent;
  box-shadow: none;
  font-weight: 600;
  font-size: 13px;
}

.dex-card.active {
  border-color: var(--accent);
}

.dex-card img {
  width: 64px;
  height: 64px;
  object-fit: contain;
}

.dex-card .dex-number {
  justify-self: start;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.dex-card .dex-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dex-caught {
  position: absolute;
  top: 6px;
  right: 8px;
  color: var(--accent);
  font-size: 13px;
}

/* Inconnu : un point d'interrogation, sans rien de l'espèce ; vu : couleurs atténuées ; capturé : couleurs pleines. */
.dex-mystery {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  font-size: 30px;
  font-weight: 800;
  color: var(--muted);
  opacity: .5;
}

.dex-portrait .dex-mystery {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  font-size: 96px;
}

.dex-card.unknown .dex-name {
  color: var(--muted);
}

.dex-card.seen img,
.dex-portrait.seen img {
  filter: grayscale(.7) opacity(.8);
}

.dex-back {
  display: none;
  justify-self: start;
}

@media (max-width: 760px) {
  .dex-back {
    display: inline-flex;
  }
}

.dex-detail {
  display: grid;
  gap: 8px;
  align-content: start;
  background: var(--panel-2);
  border-radius: 14px;
  padding: 14px;
  overflow-y: auto;
}

.dex-detail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.dex-status {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
}

.dex-status.caught {
  color: var(--accent);
}

.dex-status.seen {
  color: var(--xp);
}

.dex-portrait {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: radial-gradient(circle, rgba(255, 255, 255, .08), transparent 70%);
}

/* Hors du flux : un grand PNG ne peut pas agrandir le portrait. */
.dex-portrait img {
  position: absolute;
  inset: 15%;
  width: 70%;
  height: 70%;
  object-fit: contain;
}

.dex-detail h3 {
  margin: 0;
  font-size: 20px;
}

.dex-detail h4 {
  margin: 6px 0 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.dex-history {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.dex-description {
  margin: 0;
  line-height: 1.5;
}

.dex-hint {
  margin: 0;
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
}

.dex-habitats {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 2px;
  font-size: 14px;
}

@media (max-width: 720px) {
  .dex {
    height: 100%;
    padding: 14px;
  }

  .dex-body {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .dex-detail {
    max-height: 45vh;
  }
}

/* Progression de capture dans la zone courante */
#zone-name .zone-shiny {
  margin-left: 8px;
  color: #ffe27a;
  font-weight: 700;
}

#zone-name .zone-progress {
  margin-left: 8px;
  padding-left: 8px;
  border-left: 1px solid rgba(255, 255, 255, .2);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

#zone-name.complete .zone-progress {
  color: var(--hp);
}


/* ---------- Types, chromatiques ---------- */
.badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.element-badge {
  --c: #999;
  width: fit-content;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--c) 22%, transparent);
  color: color-mix(in srgb, var(--c) 70%, white);
  border: 1px solid color-mix(in srgb, var(--c) 60%, transparent);
}

img.shiny,
canvas.shiny {
  filter: hue-rotate(150deg) saturate(1.4) brightness(1.1);
}

.sparkles {
  position: absolute;
  top: 4%;
  right: 10%;
  font-size: clamp(18px, 3vw, 30px);
  pointer-events: none;
  animation: sparkle 1.4s ease-in-out infinite;
}

@keyframes sparkle {

  0%,
  100% {
    opacity: .2;
    scale: .7;
    rotate: 0deg;
  }

  50% {
    opacity: 1;
    scale: 1.2;
    rotate: 20deg;
  }
}

.mon-card.is-shiny {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 60%, transparent);
}

.mon-card .title {
  align-items: center;
}

.mon-card .title strong {
  margin-right: auto;
}

.rename {
  font-size: 12px;
  padding: 0 4px;
  opacity: .6;
}

.rename:hover {
  opacity: 1;
}

.rename-input {
  padding: 2px 6px;
  font-size: 14px;
  margin-right: auto;
  max-width: 160px;
}

/* ---------- HUD ---------- */
#coins b {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  padding: 9px 11px;
}

.hint-bubble {
  position: fixed;
  top: 58px;
  right: 12px;
  margin: 0;
  max-width: 260px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(20, 16, 30, .7);
  padding: 6px 10px;
  border-radius: 10px;
  pointer-events: none;
  animation: fade-hint 1s ease 12s forwards;
}

@keyframes fade-hint {
  to {
    opacity: 0;
  }
}

@media (max-width: 720px) {
  .hint-bubble {
    display: none;
  }
}

.player-menu {
  position: fixed;
  z-index: 22;
  display: grid;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 10px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  min-width: 180px;
}

.invite {
  position: fixed;
  z-index: 28;
  left: 50%;
  bottom: 90px;
  translate: -50% 0;
  width: min(380px, calc(100% - 32px));
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 16px;
  padding: 14px 16px;
  display: grid;
  gap: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
  animation: pop-in .25s ease-out;
}

.invite p {
  margin: 0;
}

@keyframes pop-in {
  from {
    scale: .85;
    opacity: 0;
  }
}

/* ---------- Fenêtres modales (boutique, classement) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 8, 18, .6);
  backdrop-filter: blur(3px);
}

.modal {
  width: min(620px, 100%);
  max-height: 100%;
  overflow-y: auto;
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
}

.modal-head h2 {
  margin: 0;
  font-size: 22px;
}

.muted {
  color: var(--muted);
  margin: 2px 0 0;
  font-size: 13px;
}

.muted b {
  color: var(--accent);
}

.shop-list {
  display: grid;
  gap: 8px;
}

.shop-item {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--panel-2);
  border-radius: 12px;
  padding: 10px 12px;
}

.shop-icon {
  font-size: 28px;
  text-align: center;
}

.shop-info {
  display: grid;
  gap: 2px;
}

.shop-info small {
  color: var(--muted);
}

.shop-buy {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: end;
}

.shop-buy button {
  padding: 6px 10px;
  font-size: 13px;
}

@media (max-width: 560px) {
  .shop-item {
    grid-template-columns: 32px 1fr;
  }

  .shop-buy {
    grid-column: 1 / -1;
    justify-content: start;
  }
}

.ranking table {
  width: 100%;
  border-collapse: collapse;
}

.ranking th,
.ranking td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

.ranking th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.online-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--hp);
}

/* ---------- Combat : duel, attente ---------- */
.battle-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  translate: -50% 0;
  z-index: 3;
  background: rgba(20, 16, 30, .85);
  color: var(--accent);
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 999px;
  letter-spacing: .02em;
}

#battle.duel-mode {
  background: linear-gradient(#f7a26b 0%, #f9d29a 45%, #b08be0 45%, #7c5cc4 100%);
}

#battle .waiting {
  margin: 0;
  text-align: center;
  font-weight: 700;
  color: var(--accent);
  animation: blink 1.2s ease-in-out infinite;
}

@keyframes blink {
  50% {
    opacity: .45;
  }
}

.side .badges {
  margin-top: -2px;
}

/* ---------- Évolution ---------- */
.evolution {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 22px;
  background: radial-gradient(circle, #3b2a66, #0b0914 70%);
  color: #fff;
  text-align: center;
  padding: 16px;
}

.evolution-stage {
  position: relative;
  width: clamp(160px, 30vw, 260px);
  aspect-ratio: 1;
}

.evolution-stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.evolution .evo-to {
  opacity: 0;
}

.evolution.evolving .evo-from {
  animation: evo-flash 2.6s ease-in forwards;
}

.evolution.evolving .evo-to {
  animation: evo-reveal .6s ease-out 2.4s forwards;
}

@keyframes evo-flash {
  0% {
    filter: brightness(1);
  }

  15% {
    filter: brightness(4);
  }

  25% {
    filter: brightness(1);
  }

  40% {
    filter: brightness(5);
  }

  50% {
    filter: brightness(1.5);
  }

  65% {
    filter: brightness(8);
  }

  75% {
    filter: brightness(3);
  }

  90% {
    filter: brightness(12);
    scale: 1.1;
  }

  100% {
    filter: brightness(20);
    opacity: 0;
    scale: 1.2;
  }
}

@keyframes evo-reveal {
  from {
    opacity: 0;
    filter: brightness(10);
    scale: .6;
  }

  to {
    opacity: 1;
    filter: none;
    scale: 1;
  }
}

.evolution-text {
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 800;
  margin: 0;
  max-width: 600px;
}

/* ---------- Notice ---------- */
.modal.help {
  width: min(900px, 100%);
  height: min(720px, 100%);
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.help-body {
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 16px;
  min-height: 0;
}

.help-nav {
  display: grid;
  gap: 4px;
  align-content: start;
  overflow-y: auto;
}

.help-nav button {
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  text-align: left;
  padding: 7px 10px;
  font-weight: 600;
}

.help-nav button:hover {
  background: var(--panel-2);
  color: var(--text);
}

.help-content {
  overflow-y: auto;
  padding-right: 6px;
  scroll-behavior: smooth;
}

.help-content section {
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.help-content section:last-child {
  border-bottom: 0;
}

.help-content h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.help-content p,
.help-content li {
  line-height: 1.55;
}

.help-content p {
  margin: 0 0 8px;
}

.help-content ul {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
}

.help-content b {
  color: var(--accent);
  font-weight: 700;
}

.help-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 6px 0 10px;
  font-size: 14px;
}

.help-content th,
.help-content td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.help-content th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.help-content kbd {
  opacity: 1;
  margin: 0;
  padding: 1px 6px;
  font-size: 12px;
  background: var(--panel-2);
  border-color: var(--line);
}

@media (max-width: 720px) {
  .modal.help {
    height: 100%;
  }

  .help-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .help-nav {
    display: flex;
    overflow-x: auto;
  }

  .help-nav button {
    white-space: nowrap;
  }
}

/* ---------- Mise en scène des combats ---------- */
#battle .log {
  min-height: 78px;
  font-size: 16px;
}

#battle .skip-hint {
  margin: -6px 0 0;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
}

.arena.flash {
  animation: arena-flash .35s ease-out;
}

@keyframes arena-flash {
  0% {
    filter: brightness(2.2) saturate(.3);
  }

  100% {
    filter: none;
  }
}

.arena .side.mine .sprite.hit-ally {
  animation: hit-mine .5s;
}

/* Arrêt sur image au moment du coup : tout se fige, la cible blanchit. */
.arena.hitstop,
.arena.hitstop * {
  animation-play-state: paused !important;
}

.sprite.struck {
  filter: brightness(0) invert(1);
}

/* Secousse des deux camps au coup, d'amplitude --shake. */
.side.shake {
  animation: side-shake .32s linear;
}

@keyframes side-shake {
  0%, 100% { translate: 0 0; }
  15% { translate: calc(var(--shake) * -1) calc(var(--shake) * .5); }
  30% { translate: var(--shake) calc(var(--shake) * -.4); }
  45% { translate: calc(var(--shake) * -.7) calc(var(--shake) * .3); }
  60% { translate: calc(var(--shake) * .5) calc(var(--shake) * -.2); }
  80% { translate: calc(var(--shake) * -.25) 0; }
}

/* Jauge de PV en combat : elle tombe vite, la barre fantôme (claire) la rattrape après un temps. */
.side .bar.hp {
  position: relative;
}

.side .bar.hp > div:first-child {
  position: relative;
  z-index: 1;
  transition: width .25s ease-out, background-color .3s;
}

.side .bar.hp > .ghost {
  position: absolute;
  inset: 0 auto 0 0;
  background: rgba(255, 255, 255, .8);
  transition: width .6s ease-in .35s;
}

@media (prefers-reduced-motion: reduce) {
  .side.shake {
    animation: none;
  }
}

.side.wild .sprite.enter-foe {
  animation: enter-foe .6s cubic-bezier(.2, .8, .3, 1.2), float 2.4s ease-in-out .6s infinite;
}

.side.mine .sprite.enter-ally {
  animation: enter-ally .6s cubic-bezier(.2, .8, .3, 1.2);
}

@keyframes enter-foe {
  from {
    translate: 60vw 0;
    opacity: 0;
  }

  to {
    translate: 0;
    opacity: 1;
  }
}

@keyframes enter-ally {
  from {
    translate: -60vw 0;
    opacity: 0;
  }

  to {
    translate: 0;
    opacity: 1;
  }
}

.info.info-in {
  animation: info-in .5s ease-out;
}

@keyframes info-in {
  from {
    opacity: 0;
    translate: 0 -10px;
  }
}

.info.level-up {
  animation: level-up .6s ease-out;
}

@keyframes level-up {
  30% {
    box-shadow: 0 0 0 3px var(--accent), 0 0 24px var(--accent);
  }
}

.arena .side .sprite.healed {
  animation: healed .7s ease-out;
}

@keyframes healed {
  40% {
    filter: brightness(1.6) drop-shadow(0 0 12px #7dffb0);
  }
}

@keyframes leave {
  to {
    translate: -60vw 0;
    opacity: 0;
  }
}

@keyframes leave-foe {
  to {
    translate: 60vw 0;
    opacity: 0;
  }
}

@keyframes absorbed {
  30% {
    filter: brightness(3) drop-shadow(0 0 12px rgba(255, 90, 90, .9));
  }

  to {
    translate: 0 -60px;
    scale: .05;
    opacity: 0;
    filter: brightness(4);
  }
}

.bar.hp>div {
  transition: width .7s ease-in-out, background-color .3s;
}

/* Capsule : lancer en cloche, ouverture (le monstre est aspiré), chute, secousses, puis capture ou évasion */
.capsule {
  --capsule-size: clamp(30px, 5vw, 46px);
  position: absolute;
  z-index: 3;
  right: calc(clamp(16px, 5vw, 80px) + clamp(40px, 8vw, 90px));
  top: 30%;
  width: var(--capsule-size);
  height: var(--capsule-size);
  pointer-events: none;
}

.capsule-body {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transform-origin: 50% 85%;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .35));
}

.capsule-body .icon,
.capsule-body .item-image {
  width: 100%;
  height: 100%;
}

.capsule-shadow {
  position: absolute;
  left: 12%;
  right: 12%;
  bottom: -6px;
  height: 8px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .35);
  opacity: 0;
}

.capsule-fx {
  position: absolute;
  inset: 0;
}

/* Lancer : une cloche depuis le dresseur (en bas à gauche), en tournoyant, jusqu'au-dessus du monstre. */
.capsule.thrown .capsule-body {
  animation: capsule-throw .8s linear forwards;
}

@keyframes capsule-throw {
  0% { translate: -52vw 34vh; rotate: -900deg; scale: .45; }
  25% { translate: -38vw 2vh; rotate: -620deg; scale: .7; }
  50% { translate: -22vw -10vh; rotate: -360deg; scale: .85; }
  75% { translate: -8vw -6vh; rotate: -120deg; scale: .95; }
  100% { translate: 0 -46px; rotate: 0deg; scale: 1; }
}

/* Ouverture au-dessus du monstre : éclair et anneau de lumière. */
.capsule.opening .capsule-body {
  translate: 0 -46px;
  animation: capsule-open .45s ease-out;
}

.capsule.opening .capsule-fx::before {
  content: "";
  position: absolute;
  inset: 0;
  translate: 0 -46px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .9);
  box-shadow: 0 0 18px 6px rgba(255, 90, 90, .7), inset 0 0 12px rgba(255, 255, 255, .8);
  animation: capsule-ring .45s ease-out forwards;
}

@keyframes capsule-open {
  40% { scale: 1.25; filter: brightness(2.2) drop-shadow(0 0 14px #fff); }
}

@keyframes capsule-ring {
  from { scale: .4; opacity: 1; }
  to { scale: 3.2; opacity: 0; }
}

/* Chute sur le sol avec deux rebonds ; l'ombre apparaît. */
.capsule.landed .capsule-body {
  animation: capsule-drop .5s cubic-bezier(.4, 0, .6, 1) forwards;
}

.capsule.landed .capsule-shadow,
.capsule.wobble .capsule-shadow,
.capsule.sealed .capsule-shadow {
  opacity: 1;
}

@keyframes capsule-drop {
  0% { translate: 0 -46px; }
  45% { translate: 0 0; }
  65% { translate: 0 -14px; }
  82% { translate: 0 0; }
  91% { translate: 0 -4px; }
  100% { translate: 0 0; }
}

/* Secousse : la capsule bascule d'un côté puis de l'autre, avec un petit saut. */
.capsule.wobble .capsule-body {
  animation: capsule-wobble .62s ease-in-out;
}

.capsule.wobble .capsule-shadow {
  animation: capsule-shadow-wobble .62s ease-in-out;
}

@keyframes capsule-wobble {
  15% { rotate: -28deg; translate: -3px 0; }
  35% { rotate: 22deg; translate: 3px -3px; }
  55% { rotate: -12deg; translate: -1px 0; }
  75% { rotate: 6deg; }
  100% { rotate: 0deg; translate: 0 0; }
}

@keyframes capsule-shadow-wobble {
  35% { scale: .8 1; }
}

/* Capturé : « clic », éclat doré et gerbe d'étincelles ; la capsule reste, un peu assombrie. */
.capsule.sealed .capsule-body {
  animation: capsule-sealed .9s ease-out forwards;
}

@keyframes capsule-sealed {
  20% { scale: 1.3; filter: brightness(2.4) drop-shadow(0 0 18px #ffd640); }
  45% { scale: .92; }
  100% { scale: 1; filter: brightness(.85) drop-shadow(0 4px 4px rgba(0, 0, 0, .35)); }
}

.capsule-fx .spark {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px;
  border-radius: 50%;
  background: #ffe27a;
  box-shadow: 0 0 8px 2px rgba(255, 214, 64, .9);
  opacity: 0;
  rotate: var(--angle);
}

.capsule.sealed .capsule-fx .spark {
  animation: capsule-spark .8s ease-out var(--delay) forwards;
}

@keyframes capsule-spark {
  0% { opacity: 1; translate: 0 0; scale: 1; }
  100% { opacity: 0; translate: calc(var(--capsule-size) * 1.6) 0; scale: .3; }
}

/* Évasion : la capsule s'ouvre en grand dans un éclair et disparaît. */
.capsule.burst .capsule-body {
  animation: capsule-burst .5s ease-out forwards;
}

.capsule.burst .capsule-fx::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, rgba(255, 255, 255, .6) 40%, transparent 70%);
  animation: capsule-ring .5s ease-out forwards;
}

@keyframes capsule-burst {
  30% { scale: 1.4; filter: brightness(3); }
  to { scale: 2; opacity: 0; filter: brightness(3); }
}

/* Le monstre aspiré par la capsule (au-dessus de lui), puis rendu s'il s'échappe. */
.side.wild .sprite.absorbed {
  animation: absorbed .45s ease-in forwards;
}

@media (prefers-reduced-motion: reduce) {
  .capsule.thrown .capsule-body,
  .capsule.landed .capsule-body {
    animation-duration: .01s;
  }

  .capsule.wobble .capsule-body {
    animation-name: none;
  }
}

/* Pierre-feuille-ciseaux : « Chi… fou… mi ! » */
@keyframes hand-shake {
  50% {
    translate: 0 -22px;
  }
}

@keyframes hand-win {
  50% {
    scale: 1.5;
  }
}

/* États durables d'un sprite : ils l'emportent sur les animations passagères (entrée, coup, soin). */
.arena .side .sprite.faint {
  animation: faint-slow 1.2s cubic-bezier(.5, 0, .9, .6) forwards;
}

.arena .side .arena .side.mine .sprite.leave {
  animation: leave .7s ease-in forwards;
}

.arena .side.wild .sprite.leave {
  animation: leave-foe .7s ease-in forwards;
}

/* Le journal met en avant la dernière ligne. */
#battle .log p:not(:last-child) {
  opacity: .6;
}

/* =====================================================================
   Mobile : écrans tactiles et petits écrans
   ===================================================================== */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

#game {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#game input {
  -webkit-user-select: text;
  user-select: text;
}

#hud-top {
  top: calc(12px + var(--safe-top));
  left: calc(12px + var(--safe-left));
}

#hud-actions {
  top: calc(12px + var(--safe-top));
  right: calc(12px + var(--safe-right));
}

/* Écran tactile : pas de raccourcis clavier, chat replié derrière un bouton, croix directionnelle. */
.touch .touch-only {
  display: inline-flex !important;
}

.touch kbd,
.touch .hint-bubble {
  display: none;
}

.touch #chat {
  left: auto;
  right: calc(10px + var(--safe-right));
  bottom: calc(12px + var(--safe-bottom));
  width: min(280px, calc(100% - 230px));
  min-width: 150px;
  pointer-events: none;
}

.touch #chat-log {
  max-height: 96px;
  font-size: 12px;
  justify-items: end;
}

.touch #chat-input {
  display: none;
  pointer-events: auto;
}

.touch #chat.open {
  left: calc(10px + var(--safe-left));
  width: auto;
  z-index: 21;
}

.touch #chat.open #chat-input {
  display: block;
  font-size: 16px;
}

/* 16px : évite le zoom automatique d'iOS */

/* Bouton du chat : petit, au milieu du bord droit ; en surbrillance quand le champ est ouvert. */
.touch .chat-button {
  position: fixed;
  top: 50%;
  right: calc(10px + var(--safe-right));
  transform: translateY(-50%);
  z-index: 5;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: rgba(34, 27, 51, .75);
  color: var(--text);
  border: 2px solid var(--line);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
}

.touch .chat-button .icon {
  width: 20px;
  height: 20px;
}

.touch .chat-button.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
#dpad {
  left: calc(16px + var(--safe-left));
  right: auto;
  bottom: calc(16px + var(--safe-bottom));
  grid-template: repeat(3, 60px) / repeat(3, 60px);
  gap: 6px;
  z-index: 5;
}

#dpad button {
  font-size: 22px;
  border-radius: 16px;
  background: rgba(34, 27, 51, .72);
  backdrop-filter: blur(4px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
}

#dpad button.held {
  background: var(--accent);
  color: var(--accent-ink);
}

#dpad button {
  pointer-events: none;
}

/* le doigt est suivi par la croix entière */
#dpad {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Croix de fermeture : pastille rouge, repérable d'un coup d'œil. */
button.modal-close,
#team-close,
#dex-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-width: 38px;
  min-height: 38px;
  padding: 6px;
  border-radius: 12px;
  background: var(--danger);
  color: #fff;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .35), 0 0 0 2px rgba(255, 255, 255, .15);
}

button.modal-close:hover,
#team-close:hover,
#dex-close:hover {
  filter: brightness(1.12);
}

button.modal-close .icon,
#team-close .icon,
#dex-close .icon {
  width: 20px;
  height: 20px;
}

.touch #hud-actions button,
.touch .modal-close,
.touch #dex-close,
.touch #team-close {
  min-width: 44px;
  min-height: 44px;
  justify-content: center;
}

/* Barre d'outils : icônes seules dès que la place manque (tablettes, paysage). */
@media (max-width: 1200px),
(max-height: 500px) {

  #hud-actions .label,
  #hud-actions kbd {
    display: none;
  }

  #hud-actions button {
    padding: 8px 11px;
    font-size: 17px;
  }

  #hud-top {
    max-width: calc(100% - 140px);
  }
}

/* Petits écrans (téléphones en portrait) */
@media (max-width: 760px) {
  #hud-actions {
    right: calc(8px + var(--safe-right));
    top: calc(8px + var(--safe-top));
    gap: 6px;
  }

  #hud-actions .label,
  #hud-actions kbd {
    display: none;
  }

  #hud-actions button {
    padding: 8px 10px;
    font-size: 18px;
  }

  /* Les infos restent en haut : seul le bouton Menu est à côté. */
  #hud-top {
    top: calc(12px + var(--safe-top));
    left: calc(8px + var(--safe-left));
    max-width: calc(100% - 80px - var(--safe-left) - var(--safe-right));
    gap: 6px;
  }

  #hud-top>span {
    font-size: 12px;
    padding: 4px 10px;
  }

  #toast {
    top: calc(104px + var(--safe-top));
    font-size: 14px;
  }

  /* Fenêtres : presque tout l'écran, avec une marge pour voir qu'on est dans une fenêtre. */
  .modal-overlay,
  .dex-overlay {
    padding: calc(10px + var(--safe-top)) calc(10px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(10px + var(--safe-left));
  }

  /* Hauteur du contenu, sans dépasser l'écran : au-delà, toute la fenêtre défile. */
  .modal,
  .dex,
  .modal.help {
    width: 100%;
    height: auto;
    max-height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    grid-template-rows: none;
    align-content: start;
    border-radius: 16px;
    padding: 12px;
    gap: 12px;
  }

  /* Les zones qui défilaient seules suivent le défilement de la fenêtre. */
  .dex-body,
  .help-body {
    grid-template-rows: none;
    min-height: auto;
  }

  .dex-grid,
  .help-content {
    overflow: visible;
  }

  /* Fiche : l'en-tête ne porte que la croix, par-dessus l'image ; il reste transparent. */
  .modal.sheet > .modal-head {
    background: transparent;
    pointer-events: none;
  }

  .modal.sheet .modal-close {
    pointer-events: auto;
  }

  /* Un lien de la notice ne cache pas le début de la section sous l'en-tête. */
  .help-content section {
    scroll-margin-top: 72px;
  }

  /* L'en-tête (titre et croix) reste en haut quand le contenu défile. */
  .modal > .modal-head,
  .dex > .dex-head {
    position: sticky;
    top: -12px;
    z-index: 2;
    margin: -12px -12px 0;
    padding: 12px;
    background: var(--panel);
    border-radius: 16px 16px 0 0;
  }

  /* Cartes de monstre réduites à leur image : un appui ouvre la fiche, qui reprend les actions. */
  .mon-list {
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 6px;
  }

  .mon-card {
    grid-template-columns: 1fr;
    padding: 4px;
    border-radius: 10px;
  }

  .mon-card img {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
  }

  .mon-card .body,
  .mon-card .card-actions {
    display: none;
  }

  .modal-head h2,
  .dex-head h2 {
    font-size: 19px;
  }

  #team-panel {
    top: calc(10px + var(--safe-top));
    right: calc(10px + var(--safe-right));
    bottom: calc(10px + var(--safe-bottom));
    width: calc(100% - 20px - var(--safe-left) - var(--safe-right));
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
  }

  .invite {
    top: calc(110px + var(--safe-top));
    bottom: auto;
  }

  .ranking th,
  .ranking td {
    padding: 8px 6px;
  }

  .dex-grid {
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  }

  /* Fiche détaillée : plein écran à la demande plutôt qu'un panneau étroit. */
  .dex-body {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .dex-detail {
    display: none;
  }

  .show-detail .dex-detail {
    display: grid;
    position: fixed;
    inset: calc(10px + var(--safe-top)) calc(10px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(10px + var(--safe-left));
    z-index: 26;
    max-height: none;
    border: 1px solid var(--line);
    border-radius: 16px;
    align-content: start;
    padding: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  }

  .show-detail .dex-portrait {
    max-width: 260px;
    justify-self: center;
    width: 70%;
  }

  .dex-card img {
    width: 52px;
    height: 52px;
  }

  /* Combat */
  .arena {
    padding: 10px 12px;
  }

  .side {
    gap: 8px;
  }

  .side .info {
    width: min(300px, 54vw);
    padding: 8px 10px;
    gap: 4px;
  }

  .side .title {
    font-size: 14px;
  }

  .sprite {
    width: clamp(96px, 32vw, 200px);
    height: clamp(96px, 32vw, 200px);
  }

  .battle-banner {
    top: calc(8px + var(--safe-top));
    font-size: 13px;
  }

  #battle .arena {
    padding-top: calc(10px + var(--safe-top));
  }

  #battle .panel {
    padding: 10px 12px calc(12px + var(--safe-bottom));
    gap: 8px;
  }

  #battle .log {
    min-height: 64px;
    font-size: 14px;
  }

  #battle .other {
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  }

  #battle .other button {
    padding: 10px 4px;
    font-size: 13px;
  }

  .choice-list {
    grid-template-columns: 1fr;
  }

  .capsule {
    right: 18vw;
  }
}

/* Téléphones en paysage : peu de hauteur */
@media (max-height: 500px) and (orientation: landscape) {
  #battle {
    grid-template-rows: 1fr auto;
  }

  .arena {
    grid-template-rows: 1fr 1fr;
    padding: 6px clamp(16px, 6vw, 80px);
  }

  .sprite {
    width: 24vh;
    height: 24vh;
  }

  .side .info {
    padding: 6px 10px;
    gap: 3px;
  }

  #battle .panel {
    grid-template-columns: 1fr 1.2fr;
    align-items: center;
    padding: 8px calc(16px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(16px + var(--safe-left));
    gap: 8px 14px;
  }

  #battle .log {
    min-height: 0;
    font-size: 13px;
  }

  #battle .skip-hint {
    grid-column: 1;
  }

  #battle .actions,
  #battle .choice-list,
  #battle .waiting,
  #battle .continue {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  #battle .other {
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  }

  #battle .other button {
    padding: 6px 4px;
    font-size: 13px;
  }

  #hud-top {
    top: calc(10px + var(--safe-top));
  }

  #hud-actions {
    left: auto;
  }

  #dpad {
    grid-template: repeat(3, 52px) / repeat(3, 52px);
  }
}

/* ---------- Interactions (borne de soin, comptoir) ---------- */
.interact-prompt {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  translate: -50% 0;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(20, 16, 30, .88);
  color: var(--text);
  border: 2px solid var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}

.interact-prompt.pop {
  animation: pop-in .25s ease-out;
}

.interact-prompt kbd {
  opacity: 1;
  margin: 0;
  padding: 2px 8px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  font-weight: 800;
}

.interact-text {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.interact-icon {
  font-size: 18px;
}

.touch-key {
  display: none;
}

/*
 * Sur mobile : boutons A et B toujours affichés à droite, comme sur une manette (A plus haut, B à sa gauche).
 * A s'allume quand une action est possible ; ce qu'elle fait s'écrit en petit juste au-dessus.
 */
.touch .interact-prompt {
  left: auto;
  right: calc(18px + var(--safe-right));
  bottom: calc(64px + var(--safe-bottom));
  translate: none;
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.touch .interact-prompt kbd,
.touch .interact-icon {
  display: none;
}

.touch .interact-text {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  /* Jamais sur la croix directionnelle (à gauche, 3 × 60 px + marges). */
  max-width: calc(100vw - 240px - var(--safe-left) - var(--safe-right));
  width: max-content;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  text-align: right;
  color: rgba(255, 255, 255, .8);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .9);
  pointer-events: none;
}

.touch .touch-key,
.run-button {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  font-size: 22px;
  font-weight: 900;
}

/* A au repos : discret, comme B */
.touch .touch-key,
.run-button {
  background: rgba(34, 27, 51, .75);
  color: var(--muted);
  border: 2px solid var(--line);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35);
}

/* A quand une action est possible : en surbrillance */
.touch .interact-prompt.ready .touch-key {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35), 0 0 16px color-mix(in srgb, var(--accent) 70%, transparent);
}

.run-button {
  position: fixed;
  right: calc(86px + var(--safe-right));
  bottom: calc(20px + var(--safe-bottom));
  z-index: 6;
  padding: 0;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.run-button.held {
  background: var(--xp);
  color: #0b1a2a;
  border-color: var(--xp);
}

/* Très petits écrans : A et B plus petits pour laisser la place à la croix. */
@media (max-width: 350px) {
  .touch .touch-key,
  .run-button {
    width: 48px;
    height: 48px;
    font-size: 19px;
  }

  .touch .interact-prompt {
    right: calc(12px + var(--safe-right));
    bottom: calc(58px + var(--safe-bottom));
  }

  .run-button {
    right: calc(68px + var(--safe-right));
  }
}

.touch #chat {
  bottom: calc(100px + var(--safe-bottom));
}

.heal-flash {
  position: fixed;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  background: radial-gradient(circle, rgba(255, 143, 181, .75), rgba(255, 143, 181, 0) 70%);
}

.heal-flash.flashing {
  animation: heal-flash 1.2s ease-out forwards;
}

@keyframes heal-flash {
  0% {
    opacity: 0;
  }

  20% {
    opacity: 1;
  }

  45% {
    opacity: .3;
  }

  65% {
    opacity: .9;
  }

  100% {
    opacity: 0;
  }
}

/* ---------- Dialogues ---------- */
.dialogue {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 24;
  display: grid;
  justify-items: center;
  padding: 0 12px calc(16px + var(--safe-bottom));
  pointer-events: none;
}

.dialogue-box {
  position: relative;
  pointer-events: auto;
  cursor: pointer;
  width: min(760px, 100%);
  min-height: 112px;
  background: #fbf8f0;
  color: #1d1a24;
  border: 4px solid #2d2442;
  border-radius: 16px;
  padding: 14px 18px 18px;
  box-shadow: 0 0 0 3px #fbf8f0, 0 12px 40px rgba(0, 0, 0, .45);
  animation: pop-in .2s ease-out;
}

.dialogue-speaker {
  position: absolute;
  top: -16px;
  left: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 2px 12px;
  border-radius: 999px;
  font-size: 14px;
  border: 3px solid #2d2442;
}

.dialogue-text {
  margin: 6px 0 0;
  font-size: 17px;
  line-height: 1.5;
  min-height: 2.8em;
  white-space: pre-wrap;
}

.dialogue-next {
  position: absolute;
  right: 16px;
  bottom: 8px;
  color: #2d2442;
  animation: bob .8s ease-in-out infinite;
}

@keyframes bob {
  50% {
    translate: 0 4px;
  }
}

.dialogue-choices {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
  flex-wrap: wrap;
}

.dialogue-choices button.selected {
  outline: 3px solid #2d2442;
  outline-offset: 2px;
}

.touch .dialogue {
  padding-bottom: calc(12px + var(--safe-bottom));
}

@media (max-width: 760px) {
  .dialogue-text {
    font-size: 16px;
  }
}

/* ---------- Options ---------- */
.options-body {
  display: grid;
  gap: 18px;
}

.option-row {
  display: grid;
  gap: 8px;
}

.option-row span {
  display: flex;
  justify-content: space-between;
}

.option-row b {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.option-row input[type=range] {
  width: 100%;
  accent-color: var(--accent);
}

.option-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Sac à dos ---------- */
.bag-body {
  display: grid;
  gap: 16px;
}

.bag-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

.bag-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.bag-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel-2);
  border-radius: 12px;
  padding: 10px 12px;
  border-left: 4px solid transparent;
}

.bag-item.equipped {
  border-left-color: var(--accent);
}

.bag-item .bag-visual {
  flex: none;
  width: 36px;
  height: 36px;
}

.bag-text {
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.bag-text p {
  margin: 0;
  font-size: 13px;
}

.bag-count {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ---------- Succès ---------- */
.modal.achievements {
  width: min(820px, 100%);
}

.achievement-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
  overflow-y: auto;
}

.achievement {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--panel-2);
  border-radius: 12px;
  padding: 10px 12px;
  opacity: .7;
}

.achievement.unlocked {
  opacity: 1;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.achievement-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .06);
  color: var(--muted);
  font-size: 22px;
}

.achievement.unlocked .achievement-icon {
  background: var(--accent);
  color: var(--accent-ink);
}

.achievement-text {
  display: grid;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.achievement-text small {
  color: var(--muted);
}

.achievement-date {
  color: var(--accent) !important;
}

.achievement-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.achievement-progress .bar {
  flex: 1;
}

/* ---------- Journal de quêtes ---------- */
.quest-filters {
  margin-bottom: 10px;
}

.quest-list {
  display: grid;
  gap: 10px;
}

.quest-entry {
  display: grid;
  gap: 6px;
  background: var(--panel-2);
  border-radius: 12px;
  padding: 12px 14px;
  border-left: 4px solid var(--accent);
}

.quest-entry.done {
  border-left-color: var(--hp);
  opacity: .75;
}

.quest-entry header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.quest-entry p {
  margin: 0;
  color: var(--text);
}

.quest-entry small {
  color: var(--muted);
}

.quest-count {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.quest-bar>div {
  background: var(--accent);
}

/* ---------- Badges ---------- */
.arena-badge {
  --c: #ffd640;
  position: absolute;
  left: 50%;
  top: 45%;
  z-index: 4;
  translate: -50% -50%;
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  font-size: 48px;
  background: radial-gradient(circle at 35% 30%, #fff8, transparent 60%), var(--c);
  border: 4px solid #fff;
  box-shadow: 0 0 0 4px var(--c), 0 0 40px var(--c);
  animation: badge-spin 1.2s cubic-bezier(.2, .8, .3, 1.2);
}

@keyframes badge-spin {
  from {
    scale: 0;
    rotate: -540deg;
  }

  to {
    scale: 1;
    rotate: 0deg;
  }
}

/* Cérémonie de remise de badge */
.badge-ceremony {
  background: radial-gradient(circle, #3a5a2a, #0b0914 70%);
}

.ceremony-badge {
  --c: #ffd640;
  display: grid;
  place-items: center;
  width: clamp(140px, 30vw, 200px);
  aspect-ratio: 1;
  border-radius: 50%;
  font-size: clamp(64px, 14vw, 100px);
  background: radial-gradient(circle at 35% 30%, #fff9, transparent 55%), var(--c);
  border: 6px solid #fff;
  box-shadow: 0 0 0 6px var(--c), 0 0 60px var(--c);
}

.badge-ceremony.celebrating .ceremony-badge {
  animation: badge-spin 1.4s cubic-bezier(.2, .8, .3, 1.2), badge-glow 2s ease-in-out 1.4s infinite;
}

@keyframes badge-glow {
  50% {
    box-shadow: 0 0 0 6px var(--c), 0 0 100px var(--c);
  }
}

.ceremony-description {
  margin: -8px 0 0;
  color: #d8d2e8;
  max-width: 480px;
}

/* Vitrine des badges (panneau d'équipe) */
.badge-case {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.badge-slot {
  --c: #555;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 26px;
  background: radial-gradient(circle at 35% 30%, #fff6, transparent 55%), var(--c);
  border: 3px solid #fff;
  box-shadow: 0 0 0 3px var(--c);
}

.badge-slot.locked {
  background: var(--panel-2);
  border-color: var(--line);
  box-shadow: none;
  color: var(--muted);
  font-size: 20px;
}

.badge-count {
  color: var(--muted);
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}

.quest-objective {
  font-weight: 600;
}

/* Choix du monstre de départ */
.starter-overlay {
  z-index: 40;
}

.modal.starter {
  width: min(820px, 100%);
}

.starter-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.starter-card {
  display: grid;
  justify-items: center;
  gap: 6px;
  text-align: center;
  padding: 14px;
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid transparent;
  border-radius: 14px;
  font-weight: 400;
}

.starter-card img {
  width: 112px;
  height: 112px;
  object-fit: contain;
  image-rendering: pixelated;
  transition: transform .2s;
}

.starter-card strong {
  font-size: 18px;
}

.starter-card p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.starter-card .badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.starter-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 214, 64, .25), 0 3px 0 rgba(0, 0, 0, .35);
}

.starter-card.selected img {
  transform: scale(1.12) translateY(-4px);
}

.starter-confirm {
  justify-self: center;
  min-width: 220px;
}

/* Ordre de l'équipe et PC de stockage */
.team-hint,
.box-info {
  margin: 0 0 8px;
  font-size: 12px;
}

.box-info {
  margin-top: 12px;
}

.mon-card[draggable=true] {
  cursor: grab;
}

.mon-card.dragging {
  opacity: .45;
}

.mon-card.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

.modal.storage {
  width: min(980px, 100%);
}

.storage-columns {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
}

.storage-columns h3 {
  margin: 0 0 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

@media (max-width: 700px) {
  .storage-columns {
    grid-template-columns: 1fr;
  }
}

/* Fiche d'un monstre */
.sheet-overlay {
  z-index: 30;
}

/* Sac ouvert depuis la fiche d'un monstre (pour lui donner un objet) : par-dessus la fiche. */
#bag.giving {
  z-index: 35;
}

.modal.sheet {
  width: min(560px, 100%);
  gap: 12px;
}

.modal.sheet .modal-head {
  margin-bottom: -40px;
}

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

.sheet-head {
  display: grid;
  grid-template-columns: 128px 1fr;
  gap: 14px;
  align-items: center;
}

.sheet-image {
  width: 128px;
  height: 128px;
  object-fit: contain;
  image-rendering: pixelated;
  background: var(--panel-2);
  border-radius: 14px;
}

.sheet-id h2 {
  margin: 0;
  font-size: 22px;
}

.sheet-id p {
  margin: 2px 0 6px;
}

.sheet-id .badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.sheet-field {
  display: grid;
  gap: 2px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.sheet-rename {
  font: inherit;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}

.sheet-bars {
  display: grid;
  gap: 4px;
}

.bar.xp>div {
  background: var(--xp);
}

.sheet-stats table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.sheet-stats th,
.sheet-stats td {
  padding: 5px 6px;
  text-align: right;
  border-bottom: 1px solid var(--line);
}

.sheet-stats th:first-child {
  text-align: left;
}

.sheet-stats thead th {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}

.sheet-stats td.total {
  font-weight: 800;
  font-size: 16px;
}

.sheet-stats td.bonus {
  color: var(--hp);
}

.sheet-stats td.bonus>div {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.bonus-meter {
  width: 60px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, .1);
  overflow: hidden;
}

.bonus-meter i {
  display: block;
  height: 100%;
  background: var(--hp);
}

.sheet-potential {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.sheet-potential .stars {
  color: var(--accent);
  letter-spacing: 2px;
}

.sheet-info {
  margin: 0;
  font-size: 13px;
}

.mon-card.openable {
  cursor: pointer;
}

.mon-card.openable:hover {
  outline: 1px solid var(--line);
}

.modal .hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

.sheet-follow {
  display: flex;
}

/* Attaques en combat */
#battle .moves {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

#battle .moves button {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 8px;
  text-align: left;
  padding: 9px 12px;
  background: color-mix(in srgb, var(--c, var(--accent)) 30%, var(--panel-2));
  color: var(--text);
  border-left: 5px solid var(--c, var(--accent));
}

#battle .moves button strong {
  font-size: 15px;
}

#battle .moves button small {
  color: var(--muted);
  font-size: 11px;
}

#battle .moves button .pp {
  grid-row: span 2;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text);
  opacity: .85;
}

#battle .moves button.empty-pp .pp {
  color: var(--danger);
}

#battle .moves .struggle {
  grid-column: 1 / -1;
}

#battle .info .status {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--c);
  color: #111;
  margin-left: 4px;
}

#battle .sprite.attack-ally {
  animation: attack-ally .38s ease-out;
}

#battle .sprite.attack-foe {
  animation: attack-foe .38s ease-out;
}

@keyframes attack-ally {
  40% {
    translate: 18% -12%;
    filter: drop-shadow(0 0 10px var(--move-color));
  }
}

@keyframes attack-foe {
  40% {
    translate: -18% 12%;
    filter: drop-shadow(0 0 10px var(--move-color));
  }
}

@media (max-width: 520px) {
  #battle .moves button {
    padding: 7px 8px;
  }

  #battle .moves button strong {
    font-size: 13px;
  }
}

/* Attaques dans la fiche */
.sheet-moves-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.sheet-moves-head h3 {
  margin: 0;
  font-size: 14px;
  flex: 1;
}

.sheet-moves-head button {
  padding: 5px 10px;
  font-size: 13px;
}

.move-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.move-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 6px;
  text-align: left;
  padding: 7px 9px;
  border-radius: 10px;
  font-weight: 500;
  background: color-mix(in srgb, var(--c) 18%, var(--panel-2));
  color: var(--text);
  border: 2px solid transparent;
  border-left: 5px solid var(--c);
  box-shadow: none;
}

.move-card strong {
  font-size: 14px;
}

.move-card .move-pp {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.move-card small {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--muted);
}

button.move-card.selected {
  border-color: var(--accent);
  border-left-color: var(--c);
}

@media (max-width: 520px) {
  .move-grid {
    grid-template-columns: 1fr;
  }
}

/* Efficacité des attaques contre le monstre d'en face */
#battle .moves button {
  position: relative;
}

#battle .moves .efficacy {
  grid-column: 1 / -1;
  justify-self: start;
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 6px;
  margin-top: 2px;
}

#battle .moves button.strong .efficacy {
  background: #22c55e;
  color: #052e14;
}

#battle .moves button.weak .efficacy {
  background: #ef4444;
  color: #fff;
}

#battle .moves button.neutral .efficacy {
  background: rgba(255, 255, 255, .14);
  color: var(--text);
}

#battle .moves button.strong:not(:disabled) {
  box-shadow: 0 0 0 2px #22c55e inset, 0 3px 0 rgba(0, 0, 0, .35);
}

/* Énergie en combat */
#battle .bar.energy {
  height: 5px;
  margin-top: 3px;
}

#battle .bar.energy>div {
  background: linear-gradient(90deg, #facc15, #fde68a);
  transition: width .4s;
}

#battle .energytext {
  display: block;
  font-size: 11px;
  color: #a16207;
  font-weight: 700;
  text-align: right;
}

#battle .moves .rest {
  grid-column: 1 / -1;
  --c: #94a3b8;
}

/* Fiche d'un monstre : onglets */
.sheet-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.sheet-tabs button {
  margin: 12px 0px;
  padding: 8px 6px;
  font-size: 13px;
}

.sheet-tab {
  display: grid;
  gap: 12px;
  align-content: start;
}

.sheet-id .sheet-bars {
  margin-top: 6px;
}

@media (max-width: 520px) {
  .sheet-head {
    grid-template-columns: 84px 1fr;
    gap: 10px;
  }

  .sheet-image {
    width: 84px;
    height: 84px;
  }

  .sheet-id h2 {
    font-size: 18px;
  }
}
/* Choix de l'apparence */
#btn-appearance {
  margin: 0 8px 0 auto;
  padding: 6px 10px;
  font-size: 13px;
}

.modal.appearance {
  width: min(640px, 100%);
}

.modal.appearance .outfit-editor { margin-top: 12px; }
.outfit-row select { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font: inherit; }

.appearance-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.appearance-card {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 10px;
  background: var(--panel-2);
  color: var(--text);
  border: 2px solid transparent;
  border-radius: 14px;
  font-weight: 400;
}

.appearance-card canvas,
.appearance-classic {
  width: 96px;
  height: 96px;
}

.appearance-classic {
  display: grid;
  place-items: center;
  font-size: 44px;
}

.appearance-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 214, 64, .25);
}

/* Icônes (voir public/assets/icons) */
.stars .icon.star-off { opacity: .25; }
/* Bonus parfaits (15 partout) : les 5 étoiles brillent, l'une après l'autre. */
.stars.perfect .icon { color: #ffe680; animation: star-shine 1.6s ease-in-out infinite; }
.stars.perfect .icon:nth-child(2) { animation-delay: .12s; }
.stars.perfect .icon:nth-child(3) { animation-delay: .24s; }
.stars.perfect .icon:nth-child(4) { animation-delay: .36s; }
.stars.perfect .icon:nth-child(5) { animation-delay: .48s; }
@keyframes star-shine {
  0%, 100% { filter: drop-shadow(0 0 1px rgba(255, 214, 64, .6)); transform: scale(1); }
  50% { filter: drop-shadow(0 0 5px #ffd640) brightness(1.35); transform: scale(1.15); }
}
@media (prefers-reduced-motion: reduce) {
  .stars.perfect .icon { animation: none; filter: drop-shadow(0 0 4px #ffd640); }
}
.appearance-classic .icon { width: 56px; height: 56px; }
.shop-icon .icon { width: 36px; height: 36px; }
/* Image téléversée d'un objet : occupe la place d'une icône. */
.item-image { display: inline-block; flex: none; width: 1.2em; height: 1.2em; vertical-align: -0.22em; object-fit: contain; image-rendering: pixelated; }
.shop-icon .item-image { width: 36px; height: 36px; }
.shop-empty { color: var(--muted); text-align: center; padding: 16px; margin: 0; }
.side .name .caught-mark { width: .9em; height: .9em; vertical-align: -0.1em; }
.arena-badge .icon, .ceremony-badge .icon, .badge-slot .icon { width: .9em; height: .9em; vertical-align: -0.1em; }
button.icon > .icon { vertical-align: middle; }
#dpad button .icon { width: 26px; height: 26px; }

/* ---------- Carte du monde ---------- */
.modal.world-map {
  width: min(900px, 100%);
}

.world-map-frame.can-fly { cursor: pointer; }
.world-map-fly { margin: 8px 0 0; text-align: center; }

.world-map-frame {
  position: relative;
  margin-inline: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.world-map-drawing {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.world-map-areas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  pointer-events: none;
}

.world-map-player {
  position: absolute;
  translate: -50% -50%;
  border-radius: 50%;
  width: 14px;
  height: 14px;
  /* Rouge sur contour blanc : se détache de la zone surlignée en jaune. */
  background: #ff4d6d;
  border: 2px solid #fff;
  animation: world-map-pulse 1.4s ease-out infinite;
}

@keyframes world-map-pulse {
  from { box-shadow: 0 0 0 0 rgb(255 77 109 / .8); }
  to { box-shadow: 0 0 0 14px rgb(255 77 109 / 0); }
}

@media (prefers-reduced-motion: reduce) {
  .world-map-player { animation: none; }
}

/* Actions de la carte d'où la fiche a été ouverte (équipe, boîte, soin…) */
.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sheet-actions button {
  padding: 8px 12px;
  font-size: 14px;
}

/* PC : équipe et boîte en cases */
.storage-box-head,
.storage-sort-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.storage-box-head {
  margin-bottom: 8px;
}

.storage-box-head .storage-box-count {
  margin: 0 0 0 auto;
}

.storage-sort-row {
  margin-top: 10px;
}

.storage-sort {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.storage-sort select {
  width: auto;
  padding: 6px 8px;
}

.storage-box-head button.icon,
button.storage-sort-dir {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 36px;
  padding: 6px;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
}

.slot-grid {
  display: grid;
  gap: 6px;
}

.storage-team {
  grid-template-columns: repeat(2, 64px);
}

.storage-box {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.slot {
  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 10px;
  background: rgba(0, 0, 0, .25);
  border: 1px dashed var(--line);
}

.slot.drop-target {
  border: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.slot-monster {
  position: absolute;
  inset: 0;
  display: grid;
  /* Une seule cellule à la taille de la case : un grand sprite ne l'agrandit pas, il est réduit dedans. */
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  overflow: hidden;
  padding: 2px;
  border-radius: 9px;
  background: var(--panel-2);
  box-shadow: none;
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.slot-monster img {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  pointer-events: none;
}

.slot-monster.lifted {
  opacity: .3;
}

.slot-level {
  position: absolute;
  right: 3px;
  bottom: 2px;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .55);
  color: var(--text);
}

.slot-shiny {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  color: #ffe27a;
}

/* Monstre soulevé : il suit le pointeur */
.slot-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  width: 64px;
  height: 64px;
  padding: 4px;
  border-radius: 12px;
  border: 2px solid var(--accent);
  background: var(--panel-2);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  pointer-events: none;
}

.slot-ghost img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@media (max-width: 700px) {
  .storage-team {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

/* Fiche : passer au monstre voisin */
.sheet-browse {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.sheet-browse button {
  min-width: 44px;
  min-height: 40px;
  padding: 6px 10px;
}

/* ---------- Menu du jeu ---------- */
#btn-menu.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.hud-menu {
  position: fixed;
  top: calc(62px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  z-index: 21;
  width: min(580px, calc(100vw - 24px - var(--safe-left) - var(--safe-right)));
  max-height: calc(100vh - 80px - var(--safe-top) - var(--safe-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: 12px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);
  animation: pop-in .18s ease-out;
}

.hud-menu-grid,
.hud-menu-footer {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.hud-menu-footer {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

button.hud-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--panel-2);
  color: var(--text);
  text-align: left;
  box-shadow: none;
}

button.hud-menu-item:hover {
  filter: brightness(1.15);
}

.hud-menu-item > .icon {
  flex: none;
  width: 28px;
  height: 28px;
}

.hud-menu-text {
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.hud-menu-text strong {
  font-size: 16px;
}

.hud-menu-text small {
  font-size: 12px;
  font-weight: 400;
  line-height: 1.25;
  color: var(--muted);
}

.hud-menu-item kbd {
  flex: none;
  margin-left: auto;
}

button.hud-menu-item.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

button.hud-menu-item.primary small {
  color: rgba(42, 33, 0, .75);
}

button.hud-menu-item.danger {
  background: color-mix(in srgb, var(--danger) 16%, var(--panel-2));
  color: var(--text);
}

button.hud-menu-item.danger > .icon {
  color: var(--danger);
}

@media (max-width: 760px) {
  .hud-menu {
    top: calc(60px + var(--safe-top));
    right: calc(10px + var(--safe-right));
    width: calc(100vw - 20px - var(--safe-left) - var(--safe-right));
    padding: 12px;
  }

  button.hud-menu-item {
    gap: 10px;
    min-height: 64px;
    padding: 10px 12px;
  }

  .hud-menu-text strong {
    font-size: 15px;
  }
}

@media (max-width: 340px) {
  .hud-menu-grid {
    grid-template-columns: 1fr;
  }
}

/* Classement : progression générale */
.ranking-progress {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
}

.ranking-bar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .4);
  overflow: hidden;
}

.ranking-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.ranking-progress b {
  min-width: 3.2em;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Inspecter un autre dresseur : son équipe */
.inspect-team {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.inspect-card {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  background: var(--panel-2);
}

.inspect-card img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  border-radius: 10px;
  background: rgba(0, 0, 0, .2);
}

.inspect-body {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.inspect-body small {
  margin: 0;
}

/* Tenue d'un personnage à l'apparence personnalisable (PNJ, joueur) : aperçu animé et une pièce par emplacement. */
.outfit-editor { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.outfit-editor[hidden] { display: none; }
.outfit-stage { display: grid; gap: 6px; justify-items: center; }
.outfit-preview { width: 96px; height: 96px; image-rendering: pixelated; background: repeating-conic-gradient(#2f5d3a 0% 25%, #346842 0% 50%) 0 0 / 24px 24px; border-radius: 8px; }
.outfit-actions { display: grid; gap: 4px; width: 100%; }
.outfit-actions button { font-size: 12px; padding: 3px 6px; }
.outfit-rows { display: grid; gap: 6px; min-width: 0; }
.outfit-row { display: grid; grid-template-columns: 90px 1fr auto; gap: 6px; align-items: center; font-size: 13px; }
.outfit-row select { min-width: 0; width: 100%; }
.outfit-row input[type=color] { width: 36px; height: 28px; padding: 0 2px; }
.outfit-row input[type=color][hidden] { display: none; }

/* ---------- Mise en scène des combats : voile, zoom, réactions, statuts, particules ---------- */

/* Le zoom déborde de l'arène : le panneau du bas reste au-dessus. */
#battle {
  overflow: hidden;
}

#battle .panel {
  position: relative;
  z-index: 2;
}

.arena {
  isolation: isolate;
  transition: scale .25s ease-out;
}

/* Zoom sur un monstre (grosse attaque, K.O. final), autour de son socle (transform-origin posé par le script). */
.arena.zoomed {
  scale: 1.14;
  transition: scale .12s ease-out;
}

/* Voile de la couleur d'une grosse attaque : les bords de l'arène se teintent. */
.arena-tint {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 25%, var(--tint, transparent) 120%);
  opacity: 0;
  transition: opacity .6s ease-out;
}

.arena-tint.on {
  opacity: .7;
  transition-duration: .3s;
}

/* Bandes noires des attaques les plus puissantes. */
.letterbox {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  z-index: 3;
  background: #000;
  pointer-events: none;
  transition: height .12s ease-out;
}

.letterbox.top {
  top: 0;
}

#battle.cinematic .letterbox {
  height: 7vh;
}

/* Gros coup : la cible est projetée en arrière (loin du lanceur), puis revient. */
.side.wild .sprite.knockback {
  animation: knockback-foe .55s cubic-bezier(.2, .9, .3, 1);
}

.side.mine .sprite.knockback-ally {
  animation: knockback-ally .55s cubic-bezier(.2, .9, .3, 1);
}

@keyframes knockback-foe {
  0% { translate: 0 0; rotate: 0deg; filter: brightness(2.5); }
  25% { translate: 26px -10px; rotate: 8deg; filter: none; }
  100% { translate: 0 0; rotate: 0deg; }
}

@keyframes knockback-ally {
  0% { translate: 0 0; rotate: 0deg; filter: brightness(2.5); }
  25% { translate: -26px 10px; rotate: -8deg; filter: none; }
  100% { translate: 0 0; rotate: 0deg; }
}

/* Statistique qui monte : le monstre se redresse ; qui baisse : il se tasse. */
.arena .side .sprite.stat-up {
  animation: stat-up .7s ease-out;
}

.arena .side .sprite.stat-down {
  animation: stat-down .7s ease-out;
}

@keyframes stat-up {
  0%, 100% { scale: 1; translate: 0 0; }
  30% { scale: 1.1; translate: 0 -10px; }
  55% { scale: .97; translate: 0 0; }
  75% { scale: 1.03; }
}

@keyframes stat-down {
  0%, 100% { scale: 1 1; translate: 0 0; }
  30% { scale: 1.1 .82; translate: 0 10px; }
  60% { scale: .96 1.04; }
}

/* K.O. : chute au ralenti, le monstre bascule en tombant. */
@keyframes faint-slow {
  0% { translate: 0 0; opacity: 1; rotate: 0deg; }
  20% { translate: 0 -6px; }
  100% { translate: 0 50px; opacity: 0; rotate: 6deg; }
}

/* Statut infligé : le monstre luit de la couleur du statut et réagit à sa façon. */
.arena .side .sprite.afflicted {
  filter: drop-shadow(0 0 3px var(--status-color)) drop-shadow(0 0 10px var(--status-color));
}

.arena .side .sprite.afflicted-poison { animation: afflict-poison .75s ease-in-out; }
.arena .side .sprite.afflicted-burn { animation: afflict-burn .75s steps(6); }
.arena .side .sprite.afflicted-paralysis { animation: afflict-paralysis .75s steps(12); }
.arena .side .sprite.afflicted-sleep { animation: afflict-sleep .75s ease-in-out; }
.arena .side .sprite.afflicted-freeze { animation: afflict-freeze .75s ease-out; }

@keyframes afflict-poison {
  0%, 100% { scale: 1 1; }
  25% { scale: 1.08 .92; }
  50% { scale: .94 1.06; }
  75% { scale: 1.05 .95; }
}

@keyframes afflict-burn {
  0%, 100% { translate: 0 0; }
  20% { translate: -2px -6px; }
  40% { translate: 2px -2px; }
  60% { translate: -1px -7px; }
  80% { translate: 1px -3px; }
}

@keyframes afflict-paralysis {
  0%, 100% { translate: 0 0; }
  25% { translate: -4px 0; }
  50% { translate: 4px 1px; }
  75% { translate: -3px -1px; }
}

@keyframes afflict-sleep {
  0%, 100% { rotate: 0deg; translate: 0 0; }
  50% { rotate: -9deg; translate: 0 6px; }
}

@keyframes afflict-freeze {
  0% { scale: 1; }
  30% { scale: 1.06 .96; }
  100% { scale: 1; }
}

/* Particules qui restent après une attaque, autour du monstre touché. */
.pedestal .particle {
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 2;
  width: 6px;
  height: 6px;
  background: var(--c);
  pointer-events: none;
  opacity: 0;
  animation: var(--anim, particle-rise) var(--d) ease-out var(--delay) forwards;
}

.particle.ember { --anim: particle-rise; border-radius: 50%; box-shadow: 0 0 6px var(--c); }
.particle.wisp { --anim: particle-rise; width: 9px; height: 9px; border-radius: 50%; filter: blur(1.5px); }
.particle.bubble { --anim: particle-rise; width: 9px; height: 9px; border-radius: 50%; background: transparent; border: 2px solid var(--c); }
.particle.flake { --anim: particle-fall; background: #fff; box-shadow: 0 0 4px var(--c); clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); width: 9px; height: 9px; }
.particle.drop { --anim: particle-fall; width: 4px; height: 7px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; }
.particle.leaf { --anim: particle-fall; width: 10px; height: 5px; border-radius: 0 100% 0 100%; }
.particle.pebble { --anim: particle-drop; width: 5px; height: 5px; }
.particle.spark { --anim: particle-blink; width: 3px; height: 10px; box-shadow: 0 0 6px var(--c); }
.particle.twinkle { --anim: particle-blink; width: 10px; height: 10px; background: #fff8d7; clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%); }
.particle.streak { --anim: particle-drift; width: 18px; height: 2px; border-radius: 2px; }
.particle.dust { --anim: particle-puff; width: 10px; height: 10px; border-radius: 50%; background: color-mix(in srgb, var(--c) 60%, #fff); }

@keyframes particle-rise {
  0% { opacity: 0; translate: 0 0; }
  15% { opacity: .95; }
  100% { opacity: 0; translate: var(--dx) -70px; }
}

@keyframes particle-fall {
  0% { opacity: 0; translate: 0 -30px; rotate: 0deg; }
  15% { opacity: .95; }
  100% { opacity: 0; translate: var(--dx) 50px; rotate: var(--spin); }
}

@keyframes particle-drop {
  0% { opacity: 1; translate: 0 0; }
  100% { opacity: 0; translate: var(--dx) 60px; rotate: var(--spin); }
}

@keyframes particle-blink {
  0%, 30%, 60%, 100% { opacity: 0; }
  15%, 45%, 75% { opacity: 1; }
  100% { translate: var(--dx) 0; rotate: var(--spin); }
}

@keyframes particle-drift {
  0% { opacity: 0; translate: -30px 0; }
  20% { opacity: .9; }
  100% { opacity: 0; translate: 60px var(--dx); }
}

@keyframes particle-puff {
  0% { opacity: .8; scale: .4; translate: 0 0; }
  100% { opacity: 0; scale: 2.2; translate: var(--dx) -12px; }
}

@media (prefers-reduced-motion: reduce) {
  .arena.zoomed { scale: 1; }
  .pedestal .particle { display: none; }
  .arena .side .sprite.knockback,
  .arena .side .sprite.knockback-ally { animation: hit .4s; }
}

/* ---------- Lisibilité, tension, ambiance, fin de combat ---------- */

/* L'adversaire entre en silhouette noire, puis se colore. */
.arena .side .sprite.shadowed {
  filter: brightness(0);
}

.arena .side .sprite.reveal {
  transition: filter .45s ease-out;
}

/* Esquive : un pas de côté, avec des images rémanentes. */
.arena .side.wild .sprite.dodge {
  animation: dodge-foe .45s ease-out;
}

.arena .side.mine .sprite.dodge-ally {
  animation: dodge-ally .45s ease-out;
}

@keyframes dodge-foe {
  0%, 100% { translate: 0 0; filter: none; }
  30%, 65% { translate: 34px -6px; filter: drop-shadow(-14px 3px 0 rgba(255, 255, 255, .35)) drop-shadow(-28px 6px 0 rgba(255, 255, 255, .15)); }
}

@keyframes dodge-ally {
  0%, 100% { translate: 0 0; filter: none; }
  30%, 65% { translate: -34px 6px; filter: drop-shadow(14px -3px 0 rgba(255, 255, 255, .35)) drop-shadow(28px -6px 0 rgba(255, 255, 255, .15)); }
}

/* Attaque sans effet : en gris, elle se dissout. */
.pedestal .fx.fizzle {
  filter: grayscale(1) brightness(.8);
  animation: fizzle-out .6s ease-in forwards;
}

@keyframes fizzle-out {
  0% { opacity: 1; }
  100% { opacity: 0; scale: .7; }
}

/* Énergie : la jauge se vide en clignotant, ou se remplit en luisant (repos). */
#battle .bar.energy.drain {
  animation: energy-drain .5s ease-out;
}

#battle .bar.energy.refill {
  animation: energy-refill .9s ease-out;
}

@keyframes energy-drain {
  0% { box-shadow: 0 0 0 2px rgba(255, 255, 255, .9); }
  100% { box-shadow: none; }
}

@keyframes energy-refill {
  0%, 100% { box-shadow: none; }
  40% { box-shadow: 0 0 10px 2px #7dd3fc; }
}

/* Repos : le monstre respire profondément. */
.arena .side .sprite.resting {
  animation: resting .9s ease-in-out;
}

@keyframes resting {
  0%, 100% { scale: 1; filter: none; }
  45% { scale: 1.06 1.1; filter: drop-shadow(0 0 8px #7dd3fc); }
}

/* Crans de statistique à côté des types. */
.side .stages {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-left: 6px;
  vertical-align: middle;
}

.side .stage {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 6px;
  line-height: 1.3;
  animation: pop-in .25s ease-out;
}

.side .stage.up {
  background: rgba(74, 222, 128, .22);
  color: #86efac;
}

.side .stage.down {
  background: rgba(248, 113, 113, .22);
  color: #fca5a5;
}

/* Votre monstre en danger : jauge qui clignote, bords de l'écran qui battent en rouge. */
#battle.danger .side.mine .bar.hp > div:first-child {
  animation: danger-blink .55s steps(2) infinite;
}

@keyframes danger-blink {
  50% { opacity: .35; }
}

.danger-vignette {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 70px 10px rgba(220, 30, 30, .55);
  transition: opacity .4s;
}

#battle.danger .danger-vignette {
  animation: danger-pulse 1.1s ease-in-out infinite;
}

@keyframes danger-pulse {
  0%, 100% { opacity: .25; }
  15% { opacity: .9; }
  30% { opacity: .4; }
  45% { opacity: .75; }
}

/* Météo de la carte, au-dessus du fond. */
.arena-weather {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

/* La météo renforce un coup : l'arène luit de la couleur du type renforcé. */
.arena.weather-boost {
  animation: weather-boost .7s ease-out;
}

@keyframes weather-boost {
  0% { box-shadow: inset 0 0 0 0 transparent; }
  30% { box-shadow: inset 0 0 90px 20px var(--boost); }
  100% { box-shadow: inset 0 0 0 0 transparent; }
}

/* Écran « VS » des combats contre un dresseur ou un joueur. */
.versus {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  pointer-events: none;
  background: linear-gradient(100deg, rgba(37, 99, 235, .85) 0 49%, rgba(0, 0, 0, .9) 49% 51%, rgba(220, 38, 38, .85) 51%);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, .4);
}

.versus.show {
  animation: versus-in 1.8s ease-in-out forwards;
}

.versus .me,
.versus .them {
  font-size: clamp(20px, 4vw, 40px);
  padding: 0 4vw;
}

.versus .me {
  text-align: right;
  animation: versus-left .45s cubic-bezier(.2, .9, .3, 1.2);
}

.versus .them {
  animation: versus-right .45s cubic-bezier(.2, .9, .3, 1.2);
}

.versus strong {
  font-size: clamp(40px, 9vw, 96px);
  color: #fde047;
  animation: versus-slam .5s cubic-bezier(.3, 1.6, .5, 1) .25s both;
}

@keyframes versus-in {
  0% { opacity: 0; }
  10%, 80% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes versus-left {
  from { translate: -60vw 0; }
}

@keyframes versus-right {
  from { translate: 60vw 0; }
}

@keyframes versus-slam {
  from { scale: 3; opacity: 0; }
}

/* Montée de niveau : gerbe de lumière et « Niveau N ! ». */
.levelup-burst {
  position: absolute;
  inset: -20%;
  z-index: 3;
  display: grid;
  place-items: center;
  pointer-events: none;
  background: repeating-conic-gradient(from 0deg, rgba(253, 224, 71, .55) 0 8deg, transparent 8deg 24deg);
  mask-image: radial-gradient(circle, #000 20%, transparent 65%);
  animation: levelup-burst 1.2s ease-out forwards;
}

.levelup-burst span {
  font-weight: 900;
  font-size: clamp(16px, 3vw, 26px);
  color: #fde047;
  text-shadow: 0 2px 0 #92400e, 0 0 10px rgba(253, 224, 71, .8);
  animation: pop-in .35s cubic-bezier(.3, 1.6, .5, 1);
}

@keyframes levelup-burst {
  0% { opacity: 0; rotate: 0deg; scale: .5; }
  20% { opacity: 1; scale: 1; }
  100% { opacity: 0; rotate: 40deg; scale: 1.2; }
}

/* Pièces qui s'envolent vers le compteur. */
.flying-coin {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 40;
  font-size: 22px;
  color: #facc15;
  pointer-events: none;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .35));
}

.coin-gain {
  position: fixed;
  z-index: 40;
  translate: -50% -50%;
  font-weight: 900;
  font-size: 26px;
  color: #fde047;
  text-shadow: 0 2px 0 #92400e;
  pointer-events: none;
  animation: coin-gain 1.1s ease-out forwards;
}

@keyframes coin-gain {
  0% { opacity: 0; scale: .5; }
  20% { opacity: 1; scale: 1.15; }
  100% { opacity: 0; translate: -50% -130%; }
}

/* Ombre au sol : elle suit le monstre (flottement, élan, projection, esquive, K.O.). */
.side.wild .pedestal::after {
  animation: shadow-float 2.4s ease-in-out infinite;
}

.pedestal::after {
  transition: opacity .6s;
}

.pedestal:has(.sprite.attack-foe)::after,
.pedestal:has(.sprite.attack-ally)::after {
  animation: shadow-lunge .38s ease-out;
}

.side.wild .pedestal:has(.sprite.knockback)::after,
.side.wild .pedestal:has(.sprite.dodge)::after {
  animation: shadow-away-right .5s ease-out;
}

.side.mine .pedestal:has(.sprite.knockback-ally)::after,
.side.mine .pedestal:has(.sprite.dodge-ally)::after {
  animation: shadow-away-left .5s ease-out;
}

.pedestal:has(.sprite.faint)::after,
.pedestal:has(.sprite.absorbed)::after,
.pedestal:has(.sprite.leave)::after {
  opacity: 0;
}

@keyframes shadow-float {
  50% { scale: .85; opacity: .7; }
}

@keyframes shadow-lunge {
  40% { scale: 1.15 .8; opacity: .6; }
}

@keyframes shadow-away-right {
  30% { translate: 26px 0; scale: .8; }
}

@keyframes shadow-away-left {
  30% { translate: -26px 0; scale: .8; }
}

@media (prefers-reduced-motion: reduce) {
  .versus .me, .versus .them, .versus strong { animation: none; }
  .levelup-burst { animation-duration: .01s; }
  #battle.danger .danger-vignette { animation: none; opacity: .5; }
}
