:root {
  --bg: #14111f;
  --bg-2: #1d1930;
  --card: #252040;
  --line: #3a335c;
  --text: #ece8f7;
  --muted: #9a93b8;
  --accent: #f0b43c;
  --hp: #4fcf6f;
  --hp-enemy: #e0524f;
  --xp: #7b6cf6;
  --common: #c9c5d8;
  --rare: #4ea3ff;
  --epic: #b46bff;
  --legendary: #ff9b2f;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* l'attribut hidden doit toujours gagner, même sur un élément stylé en flex/grid */
[hidden] { display: none !important; }

html, body { margin: 0; }

/* pas de zoom au double tap (le pincement reste possible) */
html, body, button, select, input, label { touch-action: manipulation; }

body {
  background: radial-gradient(ellipse at top, #241d3d 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  max-width: 720px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(16px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: transform .08s, background .15s, opacity .15s;
}
button:active:not(:disabled) { transform: scale(.96); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: #1a1405; border-color: transparent; font-weight: 700; }

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

/* ---------- En-tête ---------- */

.top { display: flex; justify-content: space-between; align-items: center; padding: 14px 0 8px; }
.who { display: flex; gap: 10px; align-items: baseline; font-weight: 700; font-size: 17px; }
.lvl { color: var(--muted); font-weight: 500; font-size: 14px; }
.lvl b { color: var(--text); }
.gold { font-size: 17px; }
.gold b { color: var(--accent); }

.xp { position: relative; height: 16px; background: var(--bg-2); border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.xp > div { height: 100%; background: linear-gradient(90deg, #5b4ce0, var(--xp)); width: 0; transition: width .4s; }
.xp span { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 14px; color: #fff; text-shadow: 0 1px 2px #000; }

/* ---------- Arène ---------- */

.arena { margin-top: 14px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }

.zone-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; margin-top: 10px; }
.zone-progress { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.zone-progress .bar { width: 110px; }
.boss-btn { background: #5b1f2b; border-color: #a33a4c; font-weight: 700; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px #a33a4c44; } }

.bar { height: 10px; background: #0e0c17; border-radius: 6px; overflow: hidden; }
.bar.small { height: 6px; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.bar.hp > div { background: var(--hp); }
.bar.hp.enemy > div { background: var(--hp-enemy); }

/* ---------- Scène ---------- */

.scene {
  --px: 5px;           /* taille d'un pixel du héros */
  --horizon: 72%;      /* hauteur du sol */
  position: relative; height: 250px; border-radius: 10px; overflow: hidden;
  background: #000; user-select: none; isolation: isolate;
}
.scene.shake { animation: shake .3s; }
.scene.shake-big { animation: shake-big .4s; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translate(-3px, 1px); } 50% { transform: translate(3px, -1px); } 75% { transform: translate(-2px, 0); } }
@keyframes shake-big { 0%,100% { transform: none; } 20% { transform: translate(-6px, 3px) rotate(-.4deg); } 40% { transform: translate(6px, -2px) rotate(.4deg); } 60% { transform: translate(-4px, 2px); } 80% { transform: translate(3px, -1px); } }

.sky { position: absolute; inset: 0; background: linear-gradient(var(--sky-top, #6fb7e8), var(--sky-bottom, #bfe3f7)); transition: background 1s; }
.ground {
  position: absolute; left: 0; right: 0; top: var(--horizon); bottom: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 34px, #0002 34px 40px),
    linear-gradient(var(--ground, #4f9a3c), var(--ground-dark, #3b7a2c));
  background-size: 80px 100%, 100% 100%;
  box-shadow: inset 0 6px 0 #0002;
}
.walking .ground { animation: ground-scroll .6s linear infinite; }
@keyframes ground-scroll { to { background-position: -80px 0, 0 0; } }

/* parallaxe : deux copies côte à côte pour un défilement sans couture */
.layer { position: absolute; left: 0; width: 200%; display: flex; pointer-events: none; }
.layer > div { flex: 1 0 50%; position: relative; height: 100%; }
.layer span { position: absolute; bottom: 0; transform: translateX(-50%); line-height: 1; }
.layer.far { top: calc(var(--horizon) - 38px); height: 40px; font-size: 34px; opacity: .55; filter: blur(.4px) saturate(.7); }
.layer.near { top: calc(var(--horizon) - 30px); height: 34px; font-size: 26px; z-index: 1; }
.walking .layer.far { animation: scroll 9s linear infinite; }
.walking .layer.near { animation: scroll 3s linear infinite; }
@keyframes scroll { to { transform: translateX(-50%); } }

.particles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.particles span { position: absolute; bottom: -10%; font-size: 14px; opacity: 0; animation: drift 7s linear infinite; }
@keyframes drift {
  0% { transform: translate(0, 0) rotate(0); opacity: 0; }
  10% { opacity: .8; }
  90% { opacity: .5; }
  100% { transform: translate(var(--dx, 20px), -260px) rotate(180deg); opacity: 0; }
}

.actor { position: absolute; top: var(--horizon); width: 110px; transform: translate(-50%, -100%); z-index: 2; }
.actor.hero { left: 27%; }
.actor.monster { left: 74%; }
.actor .shadow { position: absolute; left: 50%; bottom: -5px; width: 60px; height: 10px; transform: translateX(-50%); background: #0005; border-radius: 50%; filter: blur(2px); }
.actor .sprite-wrap { position: relative; display: flex; justify-content: center; align-items: flex-end; height: 88px; }

/* héros en pixel art : un carré de --px dont les box-shadow forment le dessin */
.pixel { position: relative; }
.pixel::before { content: ''; position: absolute; left: 0; top: 0; width: var(--px); height: var(--px); box-shadow: var(--frame); }
.pixel { width: calc(var(--px) * 14); height: calc(var(--px) * 16); }
.hero .sprite-wrap { transform-origin: 50% 100%; }
.hero.attacking .sprite-wrap { animation: lunge .3s ease-out; }
@keyframes lunge { 30% { transform: translateX(26px); } 100% { transform: none; } }
.hero.hurt .pixel::before { animation: hurt .35s; }
@keyframes hurt { 0%,100% { filter: none; } 30% { filter: brightness(2.5) sepia(1) saturate(6) hue-rotate(-40deg); transform: translateX(-6px); } }
.hero.dead .sprite-wrap { transform: translateY(16px) rotate(-82deg); filter: grayscale(1) brightness(.7); transition: transform .5s ease-in, filter .5s; }
.hero.dead .shadow { width: 90px; }
.hero.walking .sprite-wrap, .scene.walking .hero .sprite-wrap { animation: bob .3s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-3px); } }

.actor .emoji { font-size: 60px; line-height: 1; transition: filter .3s; transform-origin: 50% 100%; animation: idle-bob 1.4s ease-in-out infinite alternate; }
@keyframes idle-bob { to { transform: translateY(-4px) scale(1.02, .98); } }
.monster.boss .emoji { font-size: 82px; filter: drop-shadow(0 0 12px #e0524faa); }
.monster.boss .shadow { width: 80px; }
.monster.attacking .emoji { animation: monster-lunge .35s ease-out; }
@keyframes monster-lunge { 35% { transform: translateX(-30px) rotate(-10deg); } }
.monster.hurt .emoji { animation: monster-hurt .3s; }
@keyframes monster-hurt { 30% { filter: brightness(3); transform: translateX(8px) skewX(6deg); } }
.monster.dying .emoji { animation: die .6s ease-in forwards; }
@keyframes die { to { transform: translateY(20px) rotate(90deg); opacity: 0; filter: grayscale(1); } }
.monster.dying .shadow, .monster.gone .shadow, .monster.gone .emoji, .monster.gone .hp-float, .monster.gone .name { opacity: 0; }
.monster.spawn .emoji { animation: spawn .5s cubic-bezier(.2,.9,.3,1.2); }
@keyframes spawn { from { transform: translateX(120px) scale(.6); opacity: 0; } }
.monster.spawn.boss .emoji { animation: spawn-boss .7s ease-out; }
@keyframes spawn-boss { from { transform: translateY(-160px); } 70% { transform: translateY(6px) scale(1.1, .9); } }

.hp-float { position: absolute; left: 50%; bottom: calc(100% + 6px); width: 90px; transform: translateX(-50%); text-align: center; transition: opacity .3s; }
.hp-float .bar { height: 7px; border: 1px solid #0008; }
.hp-float span { display: block; font-size: 11px; color: #fff; text-shadow: 0 1px 2px #000, 0 0 4px #000; font-variant-numeric: tabular-nums; margin-top: 2px; }
.actor .name { position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%); font-size: 12px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #000, 0 0 6px #000; white-space: nowrap; transition: opacity .3s; }
.monster.boss .name { color: #ffb3a7; }

.banner {
  position: absolute; left: 50%; top: 40%; z-index: 3; transform: translateX(-50%);
  padding: 6px 14px; border-radius: 999px; background: #0008; backdrop-filter: blur(4px);
  color: #fff; font-weight: 800; font-size: 15px; white-space: nowrap; text-shadow: 0 1px 2px #000;
  opacity: 0; transition: opacity .3s; pointer-events: none;
}
.banner.show { opacity: 1; }
.banner.pop { animation: pop .5s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: translateX(-50%) scale(.4); } }
.banner.boss-alert { background: #a33a4ccc; letter-spacing: 1px; }

.zone-tag {
  position: absolute; z-index: 3; left: 10px; top: 10px; padding: 4px 10px; border-radius: 8px;
  background: #0007; color: #fff; font-size: 13px; font-weight: 700; text-shadow: 0 1px 2px #000; backdrop-filter: blur(4px);
}

.fx-layer { position: absolute; left: 0; right: 0; bottom: 20px; height: 80px; pointer-events: none; }
.dmg {
  position: absolute; left: 50%; top: 30%;
  font-weight: 800; font-size: 18px; color: #fff;
  text-shadow: 0 2px 3px #000, 0 0 6px #000;
  animation: float 0.9s ease-out forwards;
  white-space: nowrap;
}
.dmg.crit { color: var(--accent); font-size: 26px; }
.dmg.taken { color: #ff7b7b; }
@keyframes float {
  from { transform: translate(-50%, 0) scale(.8); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx, 0px)), -50px) scale(1.1); opacity: 0; }
}

.update {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px;
  background: var(--card); border: 1px solid var(--accent); border-radius: 12px; box-shadow: 0 6px 20px #0008; z-index: 10;
  max-width: calc(100vw - 32px);
}

/* ---------- Combat tactique ---------- */

.fight-row { display: flex; gap: 8px; margin-top: 10px; }
.fight-row button { flex: 1; }
.fight-row small { font-weight: 600; opacity: .75; }
.switch { font-size: 13px; white-space: nowrap; }

.buffs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.buffs:empty { display: none; }
.chip { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); white-space: nowrap; }
.chip.buff { border-color: #4fcf6f88; }

.intent {
  position: absolute; left: 50%; top: -14px; transform: translateX(-50%); z-index: 4;
  padding: 3px 9px; border-radius: 10px; background: #000b; border: 1px solid #fff3;
  color: #fff; font-weight: 800; font-size: 14px; white-space: nowrap; text-shadow: 0 1px 2px #000;
}
.intent::after { content: ''; position: absolute; left: 50%; top: 100%; transform: translateX(-50%); border: 6px solid transparent; border-top-color: #000b; }
.intent.heavy { background: #a3203acc; border-color: #ff8a8a; animation: throb .8s ease-in-out infinite; }
.intent.heavy::after { border-top-color: #a3203acc; }
.intent.heal { background: #1e6b3acc; }
.intent.heal::after { border-top-color: #1e6b3acc; }
.intent.defend { background: #2d4a8acc; }
.intent.defend::after { border-top-color: #2d4a8acc; }
.intent.enrage { background: #8a4a10cc; }
.intent.enrage::after { border-top-color: #8a4a10cc; }
@keyframes throb { 50% { transform: translateX(-50%) scale(1.12); } }

.camp { position: absolute; left: 48%; top: var(--horizon); transform: translate(-50%, -100%); font-size: 34px; z-index: 2; animation: flicker 1.2s ease-in-out infinite alternate; }
@keyframes flicker { to { transform: translate(-50%, -100%) scale(1.08, .94); filter: brightness(1.2); } }

.tactic { margin-top: 10px; display: grid; gap: 8px; }
.tactic-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.intent-hint { font-size: 13px; color: var(--muted); }
.intent-hint b { color: var(--text); }
.energy { font-size: 15px; letter-spacing: 2px; white-space: nowrap; color: var(--accent); }
.energy .off { color: var(--line); }
.tactic-lines { font-size: 13px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 52px; }
.tactic-lines div + div { margin-top: 2px; }
.moves { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.moves button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; font-weight: 700; }
.moves button small { font-weight: 500; font-size: 11px; color: var(--muted); }
.moves button.hint { border-color: var(--accent); box-shadow: 0 0 0 2px #f0b43c33; }
.moves .flee { grid-column: span 1; }

.tactic-result { margin-top: 10px; }
.tactic-result h3 { margin: 0 0 6px; }
.tactic-result .lines { font-size: 13px; color: var(--muted); display: grid; gap: 2px; margin-bottom: 10px; }
.tactic-result.win { border-color: #4fcf6f88; }
.tactic-result.lose { border-color: #e0524f88; }

/* ---------- Événements ---------- */

.events { display: grid; gap: 8px; margin-top: 10px; }
.events:empty { display: none; }
.event-btn { display: flex; align-items: center; gap: 10px; text-align: left; border-color: var(--accent); background: linear-gradient(90deg, #3a2e10, var(--card)); animation: glow 2s ease-in-out infinite; }
.event-btn .emo { font-size: 26px; }
.event-btn .txt { flex: 1; min-width: 0; }
.event-btn .txt b { display: block; }
.event-btn .txt small { color: var(--muted); }
@keyframes glow { 50% { box-shadow: 0 0 0 3px #f0b43c33; } }

.encounter-dialog .emo { font-size: 48px; text-align: center; }
.encounter-dialog h2 { text-align: center; }
.encounter-dialog p { color: var(--muted); text-align: center; margin: 6px 0 14px; }
.encounter-dialog .opts { display: grid; gap: 8px; }
.encounter-dialog .opts button { text-align: left; display: grid; gap: 2px; }
.encounter-dialog .opts button small { color: var(--muted); }
.encounter-dialog .opts button .cost { color: var(--accent); font-weight: 700; }
.encounter-dialog .close { margin-top: 10px; background: transparent; }

/* ---------- Compétences ---------- */

.skills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.skill { position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 4px; }
.skill .ico { font-size: 22px; line-height: 1.1; }
.skill .lbl { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.skill .cd { font-size: 12px; font-variant-numeric: tabular-nums; }
.skill:disabled { opacity: 1; }
.skill.cd .ico, .skill.locked .ico { filter: grayscale(1); opacity: .5; }
.skill.locked { opacity: .55; }
.skill.ready { border-color: var(--accent); box-shadow: 0 0 0 2px #f0b43c33; }
.skill.ready .cd { color: var(--accent); font-weight: 700; }
.skill.active { border-color: var(--hp); background: #1d3a28; }
.skill.active .cd { color: var(--hp); font-weight: 700; }
.skill .fill { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); transition: width 1s linear; }
.skill.active .fill { background: var(--hp); }

/* ---------- Onglets ---------- */

.tabs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin: 14px 0 10px; }
.tabs button { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; font-size: 18px; background: var(--bg-2); }
.tabs button span { font-size: 11px; color: var(--muted); }
.tabs button.active { border-color: var(--accent); background: var(--card); }
.tabs button.active span { color: var(--text); }
.badge { position: absolute; top: 4px; right: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }

main { display: grid; gap: 10px; }

.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px 14px; }
.stat { display: flex; justify-content: space-between; gap: 8px; }
.stat span { color: var(--muted); }
.stat b { font-variant-numeric: tabular-nums; }

.row { display: flex; align-items: center; gap: 10px; }
.row + .row { margin-top: 10px; }
.row .grow { flex: 1; min-width: 0; }
.row .desc { font-size: 12px; color: var(--muted); }

.points-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.points-head b { color: var(--accent); }

/* 16px minimum : sinon iOS zoome automatiquement au focus du champ */
select, input[type=text] {
  font: inherit; font-size: 16px; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px;
}

.forge-cost { font-size: 13px; white-space: nowrap; }

.item { border-left: 4px solid var(--common); padding-left: 10px; }
.item .name { font-weight: 700; }
.item.rare { border-color: var(--rare); } .item.rare .name { color: var(--rare); }
.item.epic { border-color: var(--epic); } .item.epic .name { color: var(--epic); }
.item.legendary { border-color: var(--legendary); } .item.legendary .name { color: var(--legendary); }
.item .props { font-size: 13px; color: var(--muted); }

.zones { display: grid; gap: 6px; }
.zones button { display: flex; justify-content: space-between; align-items: center; text-align: left; gap: 10px; }
.zones button.current { border-color: var(--accent); }
.zones small { color: var(--muted); }

.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.log li { display: flex; gap: 8px; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.log .level { color: var(--xp); }
.log .boss, .log .zone { color: var(--accent); }
.log .death { color: var(--hp-enemy); }
.log .loot-rare { color: var(--rare); }
.log .loot-epic { color: var(--epic); }
.log .loot-legendary { color: var(--legendary); font-weight: 700; }

.bag { display: grid; gap: 8px; }
.bag .row + .row { margin-top: 0; }
.bag .actions { display: flex; gap: 6px; flex: none; }
.bag .actions button { padding: 6px 9px; font-size: 13px; }
.up { color: var(--hp); font-weight: 700; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 10px; }

.big-num { font-size: 32px; font-weight: 800; color: var(--accent); }
.prestige-cta { width: 100%; padding: 12px; font-size: 16px; margin-top: 10px; }

.checks { display: grid; gap: 8px; margin: 10px 0; }

.danger { background: #3a1820; border-color: #7a2d3b; }

dialog {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog ul { padding-left: 18px; }
dialog button { width: 100%; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 20px #0008;
  max-width: calc(100vw - 32px);
}
.offline { position: fixed; top: 0; left: 0; right: 0; text-align: center; background: #5b1f2b; padding: 4px; font-size: 13px; }

@media (max-width: 420px) {
  .scene { --px: 4px; height: 220px; }
  .actor.hero { left: 24%; }
  .actor.monster { left: 76%; }
  .actor .emoji { font-size: 52px; }
  .monster.boss .emoji { font-size: 70px; }
  .tabs { gap: 4px; }
  .tabs button span { font-size: 10px; }
}
