: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); }
.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-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, .side .rarity {
  --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%);
}
#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; }
.side.wild .sprite { animation: float 2.4s ease-in-out infinite; }
.side.mine .sprite { transform: scaleX(-1); }
@keyframes float { 50% { translate: 0 -8px; } }
.sprite.hit { animation: hit .4s; }
.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; } }
@keyframes faint { to { translate: 0 40px; opacity: 0; } }

#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 .rps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
#battle .rps button { display: grid; justify-items: center; gap: 2px; padding: 10px 8px; font-size: 15px; }
#battle .rps button span { font-size: 30px; line-height: 1.1; }
#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 */
.duel { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: clamp(12px, 4vw, 40px); pointer-events: none; z-index: 2; }
.duel .hand { font-size: clamp(44px, 9vw, 84px); line-height: 1; transition: scale .3s, opacity .3s, filter .3s; filter: drop-shadow(0 4px 6px rgba(0,0,0,.3)); }
.duel .hand.mine { transform: scaleX(-1); }
.duel .hand.win { scale: 1.25; }
.duel .hand.lose { opacity: .35; filter: grayscale(1); }
.duel .vs { font-weight: 900; font-size: clamp(18px, 3vw, 28px); color: #fff; background: rgba(20,16,30,.8); border-radius: 999px; padding: 4px 12px; }
.duel.reveal .hand.mine { animation: shake-mine .5s ease-out; }
.duel.reveal .hand.wild { animation: shake-wild .5s ease-out; }
@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; 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 : silhouette noire ; vu : couleurs atténuées ; capturé : couleurs pleines. */
.dex-card.unknown img, .dex-portrait.unknown img { filter: brightness(0); opacity: .55; }
.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 { display: grid; place-items: center; aspect-ratio: 1; border-radius: 12px; background: radial-gradient(circle, rgba(255,255,255,.08), transparent 70%); }
.dex-portrait img { 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-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 { 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; } }

.side.mine .sprite.hit-ally { animation: hit-mine .5s; }
.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); } }
.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 { to { scale: .1; opacity: 0; filter: brightness(4); } }
.bar.hp > div { transition: width .7s ease-in-out, background-color .3s; }

/* Capsule : lancer, secousses, capture ou évasion */
.capsule {
  position: absolute; z-index: 2; right: calc(clamp(16px, 5vw, 80px) + clamp(40px, 8vw, 90px)); top: 22%;
  font-size: clamp(28px, 5vw, 44px); line-height: 1; filter: drop-shadow(0 4px 4px rgba(0,0,0,.35));
}
.capsule.thrown { animation: capsule-throw .7s cubic-bezier(.3,.6,.4,1) forwards; }
@keyframes capsule-throw {
  0% { translate: -45vw 45vh; rotate: -540deg; scale: .6; }
  60% { translate: 0 -30px; rotate: 0deg; scale: 1.1; }
  100% { translate: 0 30px; scale: 1; }
}
.capsule.wobble { translate: 0 30px; animation: capsule-wobble .6s ease-in-out; }
@keyframes capsule-wobble { 25% { rotate: -25deg; } 50% { rotate: 20deg; } 75% { rotate: -10deg; } }
.capsule.sealed { translate: 0 30px; animation: capsule-sealed .7s ease-out forwards; }
@keyframes capsule-sealed { 30% { filter: brightness(2) drop-shadow(0 0 16px var(--accent)); scale: 1.2; } 100% { scale: 1; } }
.capsule.burst { translate: 0 30px; animation: capsule-burst .5s ease-out forwards; }
@keyframes capsule-burst { to { scale: 2; opacity: 0; filter: brightness(3); } }

/* Pierre-feuille-ciseaux : « Chi… fou… mi ! » */
.duel.shaking .hand { animation: hand-shake .36s ease-in-out 3; }
.duel.shaking .hand.mine { transform: scaleX(-1); }
@keyframes hand-shake { 50% { translate: 0 -22px; } }
.duel .hand.win { animation: hand-win .5s ease-out; }
@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 .8s 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 💬, 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 */
#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:active { background: var(--accent); color: var(--accent-ink); }
.touch #hud-actions button, .touch .modal-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% - 380px); }
}

/* Petits écrans (téléphones en portrait) */
@media (max-width: 760px) {
  #hud-actions { left: calc(8px + var(--safe-left)); right: calc(8px + var(--safe-right)); top: calc(8px + var(--safe-top)); justify-content: flex-end; gap: 6px; }
  #hud-actions .label, #hud-actions kbd { display: none; }
  #hud-actions button { padding: 8px 10px; font-size: 18px; }
  #hud-top { top: calc(62px + var(--safe-top)); left: calc(8px + var(--safe-left)); max-width: calc(100% - 16px); gap: 6px; }
  #hud-top > span { font-size: 12px; padding: 4px 10px; }
  #toast { top: calc(104px + var(--safe-top)); font-size: 14px; }

  /* Fenêtres en plein écran */
  .modal-overlay, .dex-overlay { padding: 0; }
  .modal, .dex, .modal.help { width: 100%; height: 100%; max-height: none; border-radius: 0; border: 0;
    padding: calc(14px + var(--safe-top)) calc(14px + var(--safe-right)) calc(14px + var(--safe-bottom)) calc(14px + var(--safe-left)); }
  .modal-head h2, .dex-head h2 { font-size: 19px; }
  #team-panel { width: 100%; padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bottom)); }
  .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: 0; z-index: 26; max-height: none; border-radius: 0; align-content: start;
    padding: calc(14px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  }
  .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 .rps button { padding: 10px 4px; font-size: 14px; }
  #battle .rps button span { font-size: 28px; }
  #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 .rps button { padding: 6px 4px; grid-template-columns: auto auto; align-items: center; justify-content: center; gap: 6px; }
  #battle .rps button span { font-size: 22px; }
  #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-icon { font-size: 18px; }
.touch-key { display: none; }
/* Sur mobile : gros bouton A, à portée de pouce à droite. */
.touch .interact-prompt { left: auto; right: calc(18px + var(--safe-right)); bottom: calc(26px + var(--safe-bottom)); translate: none; padding: 8px 14px 8px 8px; }
.touch .interact-prompt kbd { display: none; }
.touch .touch-key {
  display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 24px; font-weight: 900; box-shadow: 0 3px 0 rgba(0,0,0,.35);
}
.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; } }

/* ---------- Journal de quêtes ---------- */
.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; }
