@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700;800&display=swap');

:root {
  --wood-dark: #2b1a0f;
  --wood: #4a3018;
  --parchment: #f4e4c1;
  --parchment-dark: #e5cf9d;
  --ink: #3a2a1a;
  --gold: #e8ab2f;
  --gold-dark: #b6790f;
  --good: #4caf50;
  --bad: #d9463f;

  --rarity-common: #8d8d8d;
  --rarity-rare: #3d8bd9;
  --rarity-epic: #a349d9;
  --rarity-legendary: #f0a020;
  --rarity-mythic: #e0384a;

  --shadow: 0 4px 0 rgba(0,0,0,0.35), 0 10px 24px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; }
body {
  background: radial-gradient(ellipse at top, #5a3a1e, var(--wood-dark) 65%);
  color: var(--ink);
  font-family: 'Baloo 2', 'Comic Sans MS', system-ui, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

.wordmark {
  font-weight: 800; font-size: 22px; color: var(--gold);
  text-shadow: 2px 2px 0 var(--wood-dark);
  margin: 0;
}

/* ── Cadre "planche de bois" reutilise partout (cartes, boutons) ─────────── */
.card {
  background: var(--parchment);
  border: 4px solid var(--wood);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.btn {
  width: 100%; padding: 14px; margin: 10px 0 0;
  background: linear-gradient(180deg, var(--gold), var(--gold-dark));
  border: 3px solid var(--wood-dark);
  border-radius: 12px;
  color: var(--wood-dark);
  font-weight: 800; font-size: 16px; letter-spacing: 0.02em;
  box-shadow: 0 4px 0 var(--wood-dark);
}
.btn:active { transform: translateY(3px); box-shadow: none; }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; box-shadow: 0 4px 0 var(--wood-dark); }
.btn.ghost {
  background: var(--parchment); color: var(--wood);
  border-color: var(--wood); box-shadow: 0 4px 0 var(--wood);
}
.btn.ghost.active { background: var(--gold); border-color: var(--wood-dark); }
.btn-fight { font-size: 19px; padding: 16px; }

.error-msg { color: var(--bad); font-weight: 700; font-size: 13px; margin: 10px 0 0; min-height: 16px; text-align: center; }

/* ── Auth ──────────────────────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; text-align: center; }
.auth-card .wordmark { font-size: 34px; margin-bottom: 4px; }
.auth-card .tag { color: var(--wood); font-weight: 600; font-size: 13px; margin: 0 0 18px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.auth-tab-btn {
  flex: 1; padding: 10px; border: 3px solid var(--wood); border-radius: 10px;
  background: var(--parchment-dark); color: var(--wood); font-weight: 700;
}
.auth-tab-btn.active { background: var(--gold); }
.auth-form .field { text-align: left; margin-bottom: 12px; }
.auth-form label { display: block; font-weight: 700; font-size: 12.5px; margin-bottom: 4px; color: var(--wood); }
.auth-form input {
  width: 100%; padding: 11px 12px; border: 3px solid var(--wood); border-radius: 10px;
  background: #fffaf0; color: var(--ink); font-size: 15px;
}
.auth-form input:focus { outline: none; border-color: var(--gold-dark); }

/* ── Shell ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 12px 18px; background: var(--wood-dark); border-bottom: 4px solid var(--gold-dark);
}
.tabs { display: flex; gap: 6px; flex: 1; }
.tab-btn {
  padding: 9px 16px; border: 2px solid transparent; border-radius: 10px;
  background: transparent; color: #e8d5b0; font-weight: 700; font-size: 14px;
}
.tab-btn.active { background: var(--gold); color: var(--wood-dark); border-color: var(--wood-dark); }
.who { display: flex; align-items: center; gap: 12px; }
.currency { color: var(--gold); font-weight: 800; font-size: 15px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--gold-dark);
  background: var(--wood); color: var(--gold); font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}

main { max-width: 900px; margin: 0 auto; padding: 18px 16px 60px; }

.page-title { font-size: 24px; font-weight: 800; color: var(--parchment); margin: 4px 0 6px; text-shadow: 2px 2px 0 var(--wood-dark); }
.page-sub { color: #d8c2a0; font-size: 13px; margin: 0 0 16px; }
.section-title {
  font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--wood); margin: 14px 0 8px;
}

/* ── Heros ─────────────────────────────────────────────────────────────── */
.hero-layout { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.hero-portrait-card { flex: 1 1 260px; max-width: 320px; text-align: center; }
.hero-name-row { display: flex; align-items: center; justify-content: center; gap: 8px; }
.hero-name { font-size: 20px; font-weight: 800; margin: 0; }
.hero-level { background: var(--gold); border: 2px solid var(--wood-dark); border-radius: 8px; padding: 2px 8px; font-weight: 800; font-size: 12px; }

.xp-bar-wrap {
  position: relative; height: 18px; background: var(--parchment-dark); border: 2px solid var(--wood);
  border-radius: 9px; margin: 8px 0 4px; overflow: hidden;
}
.xp-bar-fill { height: 100%; background: linear-gradient(90deg, #7bd88f, var(--good)); transition: width 0.4s ease; }
.xp-bar-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800; color: var(--wood-dark); text-shadow: 0 1px 0 rgba(255,255,255,0.4);
}

.hero-portrait {
  width: 100%; aspect-ratio: 1 / 1.15; max-width: 220px; margin: 8px auto;
  background: radial-gradient(ellipse at center, #fff8e8, var(--parchment-dark));
  border: 3px solid var(--wood); border-radius: 14px;
  position: relative; overflow: visible;
}
.hero-portrait svg { width: 100%; height: 100%; }
.hero-portrait-img { width: 100%; height: 100%; object-fit: contain; position: relative; z-index: 1; }

.hero-record { font-size: 12.5px; font-weight: 700; color: var(--wood); }

.equip-card { flex: 2 1 380px; }
.equip-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.equip-slot {
  aspect-ratio: 1; border: 3px dashed var(--wood); border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; background: var(--parchment-dark); position: relative; cursor: pointer;
}
.equip-slot.filled { border-style: solid; }
.equip-slot .slot-icon { font-size: 26px; }
.equip-slot .item-icon-img { width: 34px; height: 34px; object-fit: contain; }
.equip-slot .slot-label { font-size: 9px; font-weight: 800; text-transform: uppercase; color: var(--wood); }
.equip-slot .slot-item-level { font-size: 9px; font-weight: 700; color: var(--wood-dark); }
.equip-slot .slot-rarity-dot { position: absolute; top: 5px; right: 5px; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--wood-dark); }

.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.stat-tile {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; background: var(--parchment-dark); border: 2px solid var(--wood); border-radius: 8px;
  font-size: 12.5px; font-weight: 700;
}
.stat-tile .stat-value { color: var(--wood-dark); font-weight: 800; }

.inventory-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; }
.inv-item {
  aspect-ratio: 1; border-radius: 10px; border: 3px solid var(--wood);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer; position: relative;
}
.inv-item .slot-icon { font-size: 22px; }
.inv-item .item-icon-img { width: 30px; height: 30px; object-fit: contain; }
.inv-item .item-level { position: absolute; bottom: 3px; right: 5px; font-size: 10px; font-weight: 800; color: var(--wood-dark); }
.inventory-empty { color: #d8c2a0; font-size: 13px; grid-column: 1 / -1; text-align: center; padding: 20px 0; }

.inventory-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.inventory-tools { display: flex; align-items: center; gap: 8px; }
.inventory-tools select {
  padding: 7px 10px; border-radius: 8px; border: 2px solid var(--wood); background: var(--parchment-dark);
  font-weight: 700; font-size: 12.5px; color: var(--wood-dark);
}

/* Couleurs de rarete -- fond de la tuile + pastille, meme code couleur partout. */
.rarity-common { background: #e2e2e2; border-color: var(--rarity-common) !important; }
.rarity-rare { background: #cfe3f7; border-color: var(--rarity-rare) !important; }
.rarity-epic { background: #ecd6fb; border-color: var(--rarity-epic) !important; }
.rarity-legendary { background: #fbe4bd; border-color: var(--rarity-legendary) !important; }
.rarity-mythic { background: #fad0d3; border-color: var(--rarity-mythic) !important; }
.dot-common { background: var(--rarity-common); }
.dot-rare { background: var(--rarity-rare); }
.dot-epic { background: var(--rarity-epic); }
.dot-legendary { background: var(--rarity-legendary); }
.dot-mythic { background: var(--rarity-mythic); }

/* ── Modale objet ──────────────────────────────────────────────────────── */
.item-modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.item-modal-backdrop { position: absolute; inset: 0; background: rgba(20,10,0,0.6); }
.item-modal-content {
  position: relative; z-index: 1; width: 100%; max-width: 340px;
  background: var(--parchment); border: 4px solid var(--wood); border-radius: 16px;
  box-shadow: var(--shadow); padding: 20px; text-align: center;
}
.item-modal-icon-img { width: 68px; height: 68px; object-fit: contain; }
.item-modal-content h3 { margin: 6px 0 2px; font-size: 19px; }
.item-modal-rarity { font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.item-modal-stats { margin: 12px 0; display: flex; flex-direction: column; gap: 6px; }
.item-modal-stat {
  display: flex; justify-content: space-between; background: var(--parchment-dark);
  border: 2px solid var(--wood); border-radius: 8px; padding: 6px 10px; font-weight: 700; font-size: 13px;
}
.item-modal-actions { display: flex; gap: 8px; }
.item-modal-actions .btn { margin-top: 0; }

.item-compare-title { font-size: 11.5px; font-weight: 800; color: var(--wood); text-transform: uppercase; letter-spacing: 0.03em; margin: 10px 0 4px; }
.item-compare-stats .diff-up { color: var(--good); }
.item-compare-stats .diff-down { color: var(--bad); }
.item-compare-stats .diff-flat { color: var(--wood-dark); }

/* ── Combat ────────────────────────────────────────────────────────────── */
.stage-label {
  font-weight: 800; text-align: center; color: var(--gold); font-size: 15px;
  background: var(--wood-dark); border: 2px solid var(--gold-dark); border-radius: 10px;
  padding: 8px; margin-bottom: 8px;
}
.stage-label.is-boss { color: var(--rarity-mythic); background: #2a1010; border-color: var(--rarity-mythic); }

.battle-btn-row { display: flex; gap: 8px; }
.battle-btn-row .btn { margin-top: 0; }
#fight-btn { flex: 1.4; }
#auto-combat-btn { flex: 1; }
#auto-combat-btn.active { background: var(--gold-dark); color: var(--wood-dark); border-color: var(--gold-dark); }

.battle-arena { display: flex; align-items: center; gap: 14px; margin: 20px 0 10px; }
.battle-side { flex: 1; }

.battle-sprite { width: 100px; height: 130px; margin: 0 auto 6px; position: relative; }

/* Nombre de degats flottant au-dessus du perso touche -- remplace le pave de log texte. */
.dmg-popup {
  position: absolute; top: 6%; left: 50%; transform: translateX(-50%);
  font-weight: 900; font-size: 20px; color: #fff; white-space: nowrap; pointer-events: none;
  text-shadow: 0 2px 0 rgba(0,0,0,0.5), 0 0 6px rgba(0,0,0,0.4);
  animation: dmg-float 0.9s ease-out forwards; z-index: 3;
}
.dmg-popup.dmg-crit { font-size: 25px; color: var(--rarity-legendary); }
.dmg-popup.dmg-dodge { font-size: 15px; font-style: italic; color: #d8d8d8; }
@keyframes dmg-float {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.8); }
  15% { opacity: 1; transform: translate(-50%, -12px) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -54px) scale(1); }
}
.battle-sprite img {
  width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 4px 4px rgba(0,0,0,0.4));
}
.battle-sprite.side-opp img { transform: scaleX(-1); } /* l'adversaire fait face au heros */

@keyframes sprite-attack-hero { 0%,100% { transform: translateX(0); } 45% { transform: translateX(22px) rotate(-8deg); } }
@keyframes sprite-attack-opp { 0%,100% { transform: scaleX(-1) translateX(0); } 45% { transform: scaleX(-1) translateX(22px) rotate(-8deg); } }
@keyframes sprite-hit { 0%,100% { transform: translateX(0); filter: drop-shadow(0 4px 4px rgba(0,0,0,0.4)); } 25% { transform: translateX(-8px); filter: brightness(1.8) saturate(2) drop-shadow(0 4px 4px rgba(220,40,40,0.6)); } 55% { transform: translateX(6px); } }
@keyframes sprite-hit-opp { 0%,100% { transform: scaleX(-1) translateX(0); filter: drop-shadow(0 4px 4px rgba(0,0,0,0.4)); } 25% { transform: scaleX(-1) translateX(-8px); filter: brightness(1.8) saturate(2) drop-shadow(0 4px 4px rgba(220,40,40,0.6)); } 55% { transform: scaleX(-1) translateX(6px); } }
@keyframes sprite-dodge { 0%,100% { transform: translateX(0); } 40% { transform: translateX(-14px) scale(0.94); } }
@keyframes sprite-dodge-opp { 0%,100% { transform: scaleX(-1) translateX(0); } 40% { transform: scaleX(-1) translateX(-14px) scale(0.94); } }

.side-hero.sprite-attack img { animation: sprite-attack-hero 0.32s ease; }
.side-opp.sprite-attack img { animation: sprite-attack-opp 0.32s ease; }
.side-hero.sprite-hit img { animation: sprite-hit 0.3s ease; }
.side-opp.sprite-hit img { animation: sprite-hit-opp 0.3s ease; }
.side-hero.sprite-dodge img { animation: sprite-dodge 0.3s ease; }
.side-opp.sprite-dodge img { animation: sprite-dodge-opp 0.3s ease; }

.battle-name { font-weight: 800; margin: 0 0 4px; text-align: center; color: var(--parchment); }
.battle-hp-bar { height: 20px; background: var(--wood-dark); border: 2px solid var(--gold-dark); border-radius: 10px; overflow: hidden; }
.battle-hp-fill { height: 100%; transition: width 0.35s ease; }
.battle-hp-fill.hero { background: linear-gradient(90deg, #7bd88f, var(--good)); margin-left: auto; }
.battle-hp-fill.opp { background: linear-gradient(90deg, var(--bad), #f08c86); }
.battle-vs { font-weight: 800; color: var(--gold); font-size: 18px; margin: 0; }

.battle-result {
  margin-top: 14px; padding: 16px; border-radius: 12px; text-align: center; font-weight: 800; border: 3px solid;
}
.battle-result.win { background: #dff5e0; border-color: var(--good); color: #1f6b23; }
.battle-result.loss { background: #fbe0df; border-color: var(--bad); color: #8a2620; }
.battle-result .result-rewards { font-size: 14px; margin-top: 6px; font-weight: 700; }

/* ── Coffre ────────────────────────────────────────────────────────────── */
.chest-wrap { text-align: center; padding: 30px 0; }
.chest-icon { font-size: 90px; margin-bottom: 10px; transition: transform 0.15s; }
.chest-icon.shaking { animation: chest-shake 0.5s ease; }
@keyframes chest-shake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-8deg); }
  40% { transform: rotate(8deg); }
  60% { transform: rotate(-6deg); }
  80% { transform: rotate(6deg); }
}
.chest-btn-row { display: flex; gap: 8px; max-width: 340px; margin: 0 auto; }
.chest-btn-row .btn { margin-top: 0; }
#open-chest-btn { flex: 1.4; }
#open-chest-x10-btn { flex: 1; }
.auto-open-toggle {
  display: flex; align-items: center; gap: 8px; max-width: 360px; margin: 14px auto 0;
  font-size: 12px; font-weight: 700; color: var(--wood); text-align: left; cursor: pointer;
}
.auto-open-toggle input { width: 17px; height: 17px; flex-shrink: 0; accent-color: var(--gold-dark); }
.chest-reveal { max-width: 280px; margin: 20px auto 0; }
.chest-reveal-icon-img { width: 76px; height: 76px; object-fit: contain; display: block; margin: 0 auto 8px; }
.chest-bulk-results { max-width: 480px; margin: 20px auto 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 8px; }
.chest-bulk-item {
  aspect-ratio: 1; border-radius: 10px; border: 3px solid var(--wood); display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative;
}
.chest-bulk-item .item-icon-img { width: 28px; height: 28px; object-fit: contain; }
.chest-bulk-item .item-level { position: absolute; bottom: 3px; right: 5px; font-size: 9px; font-weight: 800; color: var(--wood-dark); }

/* ── Arène ─────────────────────────────────────────────────────────────── */
.opponents-list { display: flex; flex-direction: column; gap: 8px; }
.opponent-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--parchment); border: 3px solid var(--wood); border-radius: 12px;
  padding: 10px 14px;
}
.opponent-name { font-weight: 800; margin: 0; }
.opponent-meta { font-size: 12px; color: var(--wood); margin: 2px 0 0; font-weight: 700; }

/* ── Classement ────────────────────────────────────────────────────────── */
.leaderboard-list { display: flex; flex-direction: column; gap: 4px; }
.leaderboard-row {
  display: grid; grid-template-columns: 36px 1fr auto auto; align-items: center; gap: 10px;
  background: var(--parchment); border: 2px solid var(--wood); border-radius: 10px;
  padding: 8px 14px; font-weight: 700; font-size: 13.5px;
}
.leaderboard-row.self { background: var(--gold); }
.leaderboard-rank { font-size: 16px; text-align: center; }
.leaderboard-record { font-size: 12px; color: var(--wood); }
.leaderboard-elo { font-weight: 800; color: var(--wood-dark); min-width: 46px; text-align: right; }

/* ── Toast notification PvP en direct ─────────────────────────────────── */
.pvp-toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 60;
  max-width: 90%; background: var(--wood-dark); color: var(--parchment);
  border: 3px solid var(--gold); border-radius: 12px; padding: 12px 20px;
  font-weight: 700; font-size: 13.5px; box-shadow: var(--shadow); text-align: center;
  animation: toast-in 0.25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 640px) {
  .hero-layout { flex-direction: column; }
  .hero-portrait-card, .equip-card { max-width: 100%; }
  .equip-grid { grid-template-columns: repeat(3, 1fr); }
  .leaderboard-row { grid-template-columns: 28px 1fr auto; font-size: 12px; }
  .leaderboard-record { display: none; }
}
