/* Style HUD Terraria : décor de forêt du jeu, panneaux bleus translucides, boutons et onglets
   découpés dans les sprites d'interface (assets/ui), texte blanc détouré de noir.
   Mobile d'abord : tout est pensé pour 375 px, puis centré sur grand écran. */

/* Police : assets/fonts/ui.ttf (Andy Bold), Comic Neue si le fichier manque */
@font-face {
  font-family: "CratariaUI";
  src: url("../assets/fonts/ui.ttf") format("truetype");
  font-display: swap;
}

:root {
  --panel: rgba(63, 82, 151, .78);   /* couleur des panneaux du jeu */
  --panel-edge: #000;
  --panel-light: rgba(140, 160, 240, .3);
  --slot: #4955ba;                    /* fond d'un onglet, si l'image manque */
  --field: rgba(24, 32, 90, .85);
  --text: #ffffff;
  --muted: #c9cdf0;
  --menu: #a7a7a7;
  --gold: #ffe745;
  --font: "CratariaUI", "Comic Neue", "Comic Sans MS", system-ui, sans-serif;
  /* Détourage noir du texte, comme dans le jeu */
  --outline: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000, 0 2px 0 #000;
  /* Onglet du jeu (CategoryPanel), et sa version dorée fabriquée par js/app.js */
  --tab: url("../assets/ui/CategoryPanel.png");
  --tab-on: var(--tab);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  /* Décor de forêt du jeu, du plus proche au plus lointain, puis le dégradé du ciel */
  background:
    url("../assets/bg/Background_11.png") repeat-x left bottom -200px,
    url("../assets/bg/Background_9.png") repeat-x left bottom -90px,
    url("../assets/bg/Background_8.png") repeat-x left bottom -20px,
    url("../assets/bg/Background_7.png") repeat-x left bottom 40px,
    url("../assets/bg/Background_0.png") repeat-x left top / auto 100%,
    linear-gradient(#1d47c9, #7fb6f5);
  background-attachment: fixed;
  image-rendering: pixelated;
  color: var(--text);
  font: 700 17px/1.35 var(--font);
  text-shadow: var(--outline);
  touch-action: manipulation; /* pas de zoom au double tap */
}
/* Sol en bas de l'écran : blocs d'herbe et de terre du jeu (ui/ground.png, assemblé depuis Tiles_2 et Tiles_0), à l'échelle x2 */
body::after {
  content: "";
  position: fixed;
  inset: auto 0 0;
  z-index: -1;
  height: 96px;
  background: url("../assets/ui/ground.png") repeat-x 0 0 / 96px 96px;
}

/* Soleil et nuages qui dérivent */
#sky { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
#sky i { position: absolute; left: 0; animation: drift linear infinite; }
#sky .sun { left: auto; right: 24px; top: 40px; width: 114px; height: 114px; background: url("../assets/ui/Sun.png"); animation: none; }
#sky .c1 { top: 70px;  width: 256px; height: 104px; background: url("../assets/bg/Cloud_0.png");  animation-duration: 140s; animation-delay: -40s; }
#sky .c2 { top: 190px; width: 192px; height: 64px;  background: url("../assets/bg/Cloud_1.png");  animation-duration: 190s; animation-delay: -120s; }
#sky .c3 { top: 20px;  width: 302px; height: 132px; background: url("../assets/bg/Cloud_4.png");  animation-duration: 240s; animation-delay: -10s; }
@keyframes drift { from { transform: translateX(-320px); } to { transform: translateX(110vw); } }

button, input { font: inherit; color: inherit; text-shadow: inherit; }
h2 { margin: 0 0 12px; font-size: 1.5rem; text-align: center; }
h3 { margin: 18px 0 8px; font-size: 1.1rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
canvas, img { image-rendering: pixelated; }
/* Canevas 88×68 (corps 40×56 + place pour les ailes et l'arme), agrandi x2,5 */
.avatar { width: 220px; height: 170px; }

#view {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(110px + env(safe-area-inset-bottom));
}

/* Panneau : bleu translucide à bord noir, comme les fenêtres du jeu */
.card, #menu, #toast {
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 10px;
  box-shadow: inset 0 0 0 2px var(--panel-light), 0 4px 0 #0005;
}
.card { padding: 16px; }
.card + .card { margin-top: 12px; }

/* Logo (assets/ui/logo.webp) : image lissée, pas en pixels nets */
.logo, .logo img { image-rendering: auto; }
.logo.big { margin: 0 0 16px; }
.logo.big img { display: block; width: 100%; height: auto; }
.tagline { margin: -8px 0 16px; text-align: center; color: var(--muted); }

form { display: grid; gap: 12px; margin-bottom: 12px; }
label { display: grid; gap: 4px; font-size: 1rem; }
input {
  min-height: 46px;
  padding: 0 12px;
  border: 2px solid #000;
  border-radius: 8px;
  background: var(--field);
  font-size: 17px; /* 16 px minimum : iOS ne zoome pas sur le champ */
}
input:focus { outline: none; border-color: var(--gold); }
/* Texte saisi lisible : pas de détourage noir, et pas de fond clair quand le navigateur pré-remplit */
input { text-shadow: none; color: #fff; caret-color: var(--gold); letter-spacing: .02em; }
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus {
  -webkit-text-fill-color: #fff;
  box-shadow: inset 0 0 0 100px #1b2560;
  transition: background-color 9999s;
}

/* Boutons et cases : l'onglet du jeu étiré en 9 tranches (coins à l'échelle x2),
   doré quand il est survolé ou choisi */
.btn, .seg button, .stepper button, .tabs button, .icon {
  border: 2px solid transparent;
  border-radius: 8px;
  border-image: var(--tab) 8 fill / 16px;
  background: var(--slot) padding-box;
  cursor: pointer;
}
.btn:hover, .btn:focus-visible, .seg button.on, .tabs button.on, .stepper button:hover, .icon:hover {
  border-image-source: var(--tab-on);
  color: var(--gold);
  outline: none;
}
.btn { width: 100%; min-height: 52px; font-size: 1.3rem; }
.btn:active { transform: translateY(1px); }
.btn.primary { color: var(--gold); }
.btn:disabled { opacity: .6; }
.btn img { height: 22px; width: auto; vertical-align: -4px; margin-right: 6px; }
.icon { width: 44px; height: 44px; font-size: 1.3rem; }

/* Liens et entrées de menu : gris, jaunes au survol, comme le menu principal */
.link, #menu button {
  width: 100%;
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--menu);
  font-size: 1.15rem;
  cursor: pointer;
}
.link:hover, #menu button:hover, #menu button:focus-visible { color: var(--gold); outline: none; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 16px; }
.seg button { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; }
/* Classement : 3 boutons sur une ligne, plus compacts */
#r-kind { grid-template-columns: repeat(3, 1fr); gap: 4px; }
#r-kind button { min-height: 40px; padding: 0 4px; font-size: .85rem; }

#topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: rgba(18, 24, 56, .6);
  backdrop-filter: blur(4px);
}
#topbar .logo { height: 40px; width: auto; }

#menu {
  inset: unset;
  top: calc(64px + env(safe-area-inset-top));
  right: 12px;
  margin: 0;
  padding: 8px 12px;
  min-width: 200px;
  color: var(--text);
}
#menu button { display: block; text-align: left; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  opacity: 0;
  transform: translate(-50%, 20px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Création du personnage : l'aperçu reste visible pendant qu'on fait défiler les réglages */
.creator .preview {
  position: sticky;
  top: calc(64px + env(safe-area-inset-top));
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 8px;
  background: #3b4b8c; /* opaque : les réglages défilent dessous */
}
.creator .preview canvas { width: 220px; height: 170px; }
.creator .card:last-child { display: grid; gap: 12px; }
.creator .seg { margin: 0; }

.stepper { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 8px; text-align: center; }
.stepper button { height: 48px; }
.stepper img { width: 32px; height: 32px; }

/* Onglets de couleur : icônes du jeu, teintées avec la couleur choisie (masque + multiply) */
.tabs { display: flex; justify-content: space-between; gap: 4px; }
.tabs button { position: relative; width: 48px; height: 48px; padding: 0; }
.tabs img, .tabs i { position: absolute; inset: 0; margin: auto; width: 30px; height: 30px; }
.tabs i {
  -webkit-mask: center / contain no-repeat; /* image posée par js/creator.js */
  mask: center / contain no-repeat;
  mix-blend-mode: multiply;
}
.target-label { margin: 0; text-align: center; }

/* Curseurs du jeu : barre bordée de noir (teinte = Hue.png), poignée ColorSlider.png.
   --h, --s, --l sont posés par js/creator.js pour colorer les barres saturation et luminosité. */
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
}
/* Hue.png a déjà son cadre (noir puis blanc) : les barres dégradées reprennent le même cadre en ombres internes */
input[type=range]::-webkit-slider-runnable-track { height: 16px; border-radius: 3px; background: var(--track); box-shadow: var(--frame, none); }
input[type=range]::-moz-range-track { height: 16px; border-radius: 3px; background: var(--track); box-shadow: var(--frame, none); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 11px; height: 25px; margin-top: -4.5px; border: 0; background: url("../assets/ui/ColorSlider.png"); }
input[type=range]::-moz-range-thumb { width: 11px; height: 25px; border: 0; border-radius: 0; background: url("../assets/ui/ColorSlider.png"); }
#c-h { --track: url("../assets/ui/Hue.png") 0 0 / 100% 100%; }
#c-s, #c-l { --frame: inset 0 0 0 2px #000, inset 0 0 0 4px #fff; }
#c-s { --track: linear-gradient(90deg, hsl(var(--h) 0% var(--l)), hsl(var(--h) 100% var(--l))); }
#c-l { --track: linear-gradient(90deg, #000, hsl(var(--h) var(--s) 50%), #fff); }

/* --- Barre d'onglets du bas : posée sur sa propre bande d'herbe et de terre, opaque,
   pour que le contenu qui défile dessous ne se voie jamais à travers --- */
#tabs {
  position: fixed;
  inset: auto 0 0;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  /* Pleine largeur pour le fond ; boutons centrés sur 480 px max */
  padding: 30px max(8px, calc((100% - 464px) / 2)) calc(6px + env(safe-area-inset-bottom));
  /* Couleur terre seulement sous l'herbe (au-delà des 96 px de l'image, ex. encoche iPhone) :
     les brins d'herbe gardent le ciel en fond */
  background: url("../assets/ui/ground.png") repeat-x 0 0 / 96px 96px,
              linear-gradient(transparent 40px, #8b5a3c 40px);
}
#tabs button {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-height: 60px;
  padding: 6px 0 4px;
  border: 2px solid transparent;
  border-image: var(--tab) 8 fill / 16px;
  background: var(--slot) padding-box;
  border-radius: 8px;
  font-size: .75rem;
  cursor: pointer;
}
#tabs button.on { border-image-source: var(--tab-on); color: var(--gold); }
#tabs img { height: 28px; width: auto; }

/* --- Écran des caisses --- */
.hud-row { display: flex; justify-content: space-between; align-items: center; font-size: 1.2rem; }
.coins { display: flex; align-items: center; gap: 8px; color: var(--gold); }
.coins img { height: 22px; }
.xpbar { position: relative; height: 20px; margin-top: 8px; border-radius: 4px; background: #111a40; box-shadow: inset 0 0 0 2px #000; overflow: hidden; }
.xpbar i { position: absolute; inset: 2px auto 2px 2px; max-width: calc(100% - 4px); background: linear-gradient(#7cf35a, #2f9e2f); transition: width .7s ease-out; }
.xpbar span { position: relative; display: block; font-size: .8rem; line-height: 20px; text-align: center; }

.crate-card { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 12px; }
.crate-card h3 { margin: 0; }
.crate-card p { margin: 2px 0 0; font-size: .9rem; }
.crate-card .btn { width: auto; min-width: 104px; padding: 0 12px; font-size: 1.1rem; }
.crate-img { width: 64px; height: 64px; object-fit: contain; }
.stock { color: var(--gold); white-space: nowrap; }
.coins small { font-size: .75rem; color: var(--muted); }
#k-tabs { margin: 12px 0 0; }

/* Caisses payantes : 2 par ligne, caisse au centre, nom, prix ; progression de collection en coin */
#k-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
#k-list .card { margin: 0; }
.crate-tile { position: relative; display: grid; justify-items: center; align-content: start; gap: 6px; padding: 12px 10px; text-align: center; }
.crate-tile h3 { margin: 0; min-height: 2.6em; display: grid; place-items: center; font-size: 1rem; line-height: 1.3; }
.crate-tile .btn { min-height: 44px; font-size: 1.05rem; }
.crate-tile .dex-link {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 44px;
  min-height: 28px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: .85rem;
  cursor: pointer;
}
.chips { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 4px 0 0; font-size: .85rem; }
.chips span { color: var(--c); white-space: nowrap; }
.chips span::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 4px; border: 2px solid #000; border-radius: 2px; background: var(--c); vertical-align: -1px; }

/* --- Collection : une section par pool, cases d'inventaire du jeu --- */
.dex-pool { margin-top: 12px; scroll-margin-top: 76px; /* sous la barre du haut */ }
.dex-pool.complete { box-shadow: inset 0 0 0 2px var(--gold), 0 4px 0 #0005; }
.dex-head { display: flex; align-items: center; gap: 8px; }
.dex-head h3 { flex: 1; margin: 0; }
.dex-crates img { width: 32px; height: 32px; object-fit: contain; }
.dex-count { color: var(--gold); }
.dex-pool .xpbar { height: 10px; margin: 8px 0 10px; }
.dex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); grid-auto-rows: 56px; gap: 4px; }
.dex-slot {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 6px;
  border: 0;
  border-radius: 6px;
  /* Rareté : halo léger derrière l'objet */
  background:
    radial-gradient(circle closest-side, color-mix(in srgb, var(--rarity, transparent) 55%, transparent), transparent),
    url("../assets/ui/Inventory_Back.png") 0 0 / 100% 100%;
  cursor: pointer;
}
.dex-slot img { max-width: 40px; max-height: 40px; }
.dex-slot.missing img { filter: brightness(0); opacity: .45; }
.dex-slot { position: relative; }
.dex-slot .pts { position: absolute; left: 4px; bottom: 1px; font-size: .7rem; color: var(--gold); }
.equip-grid .dex-slot .pts { top: 2px; bottom: auto; }
.dex-slot.sel { box-shadow: inset 0 0 0 2px #fff; }
.pick-info { margin: 0 0 10px; text-align: center; }
.pick-info .up { color: #7cf35a; }
.pick-info .down { color: #ff7070; }
.dex-slot .qty { position: absolute; right: 4px; bottom: 0; font-size: .85rem; }
#k-bag-card .hud-row { margin-bottom: 8px; }
#k-sell { width: auto; min-height: 44px; padding: 0 12px; font-size: 1rem; }

/* --- Personnage : avatar habillé, 6 emplacements, sélecteur en <dialog> --- */
.power { margin: 0 0 12px; color: var(--muted); }
.power b { color: var(--gold); }
/* Cellules carrées, comme l'inventaire du jeu ; le nom de l'emplacement est écrit en dessous */
.equip-grid { display: grid; grid-template-columns: repeat(3, 72px); justify-content: center; gap: 26px 12px; margin-bottom: 24px; }
.equip-grid .dex-slot { width: 72px; height: 72px; padding: 8px; overflow: visible; }
.equip-grid .dex-slot img { max-width: 44px; max-height: 44px; }
.equip-grid .dex-slot .slot-name { position: absolute; top: 100%; left: -6px; right: -6px; margin-top: 2px; font-size: .7rem; color: var(--muted); text-align: center; }
.equip-grid .dex-slot small { font-size: .7rem; color: var(--muted); }
.equip-grid .dex-slot.empty { opacity: .7; }
.dex-slot.on { box-shadow: inset 0 0 0 2px var(--gold); }
#h-picker { width: min(420px, calc(100% - 32px)); max-height: 80vh; margin: auto; overflow: auto; color: var(--text); }
#h-picker::backdrop { background: rgba(5, 8, 25, .8); }
#h-picker h3 { margin-top: 0; }
#h-picker .dex-grid { margin-bottom: 12px; }

/* --- Bonus actifs : icônes de buff à côté du niveau, détail au toucher --- */
.level { display: flex; align-items: center; gap: 6px; }
.buffs { display: flex; gap: 2px; }
.buffs button { display: grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 0; background: none; cursor: pointer; }
.buffs img { width: 24px; height: 24px; }

/* --- Écran Pêche : canne (bouton pour en changer), appâts, tuiles de poissons 3 par ligne --- */
/* Canne : dans une cellule d'inventaire du jeu, comme un objet qu'on peut remplacer */
.rod-btn { display: grid; place-items: center; width: 64px; height: 64px; padding: 0; border: 0; border-radius: 6px; background: url("../assets/ui/Inventory_Back.png") 0 0 / 100% 100%; cursor: pointer; }
.rod-btn img { max-width: 44px; max-height: 44px; }
#p-bait-card .hud-row { margin-bottom: 8px; font-size: 1rem; }
#p-bait-card .muted { margin: 0; font-size: .85rem; }
#p-rods { width: min(420px, calc(100% - 32px)); margin: auto; color: var(--text); }
#p-rods::backdrop { background: rgba(5, 8, 25, .8); }
#p-rods h3 { margin-top: 0; }
#p-rods .dex-grid { margin-bottom: 12px; }
.buffs .left { position: absolute; right: 0; bottom: -2px; font-size: .65rem; }
.buffs button { position: relative; }
#p-sell-card { padding: 8px 12px; }
#p-sell-all { width: auto; min-height: 44px; padding: 0 12px; font-size: 1rem; }
#p-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
#p-list .card { margin: 0; }
.fish-tile { position: relative; display: grid; justify-items: center; align-content: start; gap: 4px; padding: 10px 6px 8px; text-align: center; }
.fish-tile img { width: 44px; height: 44px; object-fit: contain; }
.fish-tile h3 { margin: 0; min-height: 2.6em; display: grid; place-items: center; font-size: .8rem; line-height: 1.3; color: var(--rarity); }
.fish-tile .qty { position: absolute; top: 4px; right: 6px; font-size: .85rem; color: var(--gold); }
.fish-tile .btn { min-height: 44px; padding: 0 4px; font-size: .9rem; gap: 2px; }
.fish-tile .btn img { width: 16px; height: 16px; }
.fish-tile.missing img { filter: brightness(0); opacity: .45; }
.fish-tile.missing h3 { color: var(--muted); }

/* --- Bandeau d'installation (mobile) et tutoriel --- */
#install-bar {
  position: fixed; inset: auto 8px calc(110px + env(safe-area-inset-bottom)); z-index: 7;
  display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px;
  border: 2px solid #000; border-radius: 8px; background: var(--panel); box-shadow: 0 4px 0 #0005; font-size: .95rem;
}
#install-bar[hidden] { display: none; }
#install-bar span { flex: 1; }
#install-bar .btn { width: auto; min-height: 44px; padding: 0 12px; font-size: 1rem; }
#install-bar .icon { min-width: 44px; min-height: 44px; border: 0; background: none; color: var(--text); font-size: 1.1rem; cursor: pointer; }
#tuto { width: min(420px, calc(100% - 32px)); margin: auto; color: var(--text); }
#tuto::backdrop { background: rgba(5, 8, 25, .85); }
#tuto h2 { margin-top: 0; text-align: center; color: var(--gold); }
.tuto-steps { display: grid; gap: 10px; margin: 0 0 12px; padding: 0; list-style: none; counter-reset: s; }
.tuto-steps li { display: grid; grid-template-columns: 36px 1fr; align-items: center; gap: 10px; }
.tuto-steps img { width: 32px; height: 32px; object-fit: contain; }
.tuto-steps b { color: var(--gold); }

/* --- Choix d'un bonus de niveau --- */
#k-bonus { width: min(420px, calc(100% - 32px)); margin: auto; color: var(--text); }
#k-bonus::backdrop { background: rgba(5, 8, 25, .85); }
#k-bonus h3 { margin: 0; color: var(--gold); font-size: 1.6rem; text-align: center; }
#k-bonus p { text-align: center; }
#k-bonus-list { display: grid; gap: 8px; }
.btn.bonus { display: grid; grid-template-columns: 40px 1fr; gap: 10px; min-height: 64px; padding: 8px 12px; text-align: left; }
.btn.bonus img { width: 36px; height: 36px; object-fit: contain; }
.btn.bonus b { display: block; color: var(--gold); }
.btn.bonus small { display: block; font-size: .8rem; color: var(--text); }

/* --- Classement --- */
.rank-list { list-style: none; margin: 8px 0 0; padding: 0; }
.rank-row { display: grid; grid-template-columns: 32px 66px 1fr auto; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 6px; }
.rank-row:nth-child(odd) { background: rgba(0, 0, 0, .15); }
.rank-row.me { box-shadow: inset 0 0 0 2px var(--gold); }
.rank-row .rank { text-align: center; }
.rank-row:nth-child(1) .rank { color: var(--gold); }
.rank-row canvas { width: 66px; height: 51px; image-rendering: pixelated; }
.rank-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .score { color: var(--gold); }

/* --- Ouverture : plein écran, caisse au centre --- */
#opening {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background: rgba(5, 8, 25, .94);
}
#opening .stage { position: relative; display: grid; place-items: center; }
#opening .glow {
  position: absolute;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--glow) 0%, transparent 60%);
  opacity: .4;
  transition: background .15s, transform .2s, opacity .2s;
}
#opening .crate { width: 128px; height: 128px; object-fit: contain; }
#opening .reveal { position: relative; text-align: center; }
#opening .loot { width: 96px; height: 96px; object-fit: contain; }
#opening .loot-name { margin: 12px 0 4px; font-size: 1.8rem; }
#opening .loot-sub { margin: 0; color: var(--muted); }
#opening .actions { max-width: 448px; width: 100%; margin: 0 auto; }

/* Effets qui montent en puissance avec la rareté (data-tier : 1 commun → 4 légendaire) */
#opening .fx, #opening .rays, #opening .flash { position: absolute; pointer-events: none; }
#opening .fx { inset: 50% auto auto 50%; }
#opening .fx i {
  position: absolute;
  width: 6px;
  height: 6px;
  margin: -3px;
  background: var(--glow);
  box-shadow: 0 0 8px var(--glow);
  animation: fly .9s ease-out forwards;
}
#opening .rays {
  width: 440px;
  height: 440px;
  border-radius: 50%;
  background: repeating-conic-gradient(var(--glow) 0 7deg, transparent 7deg 22deg);
  -webkit-mask: radial-gradient(circle, #000 15%, transparent 68%);
  mask: radial-gradient(circle, #000 15%, transparent 68%);
  opacity: 0;
  transition: opacity .4s;
}
#opening .flash { inset: 0; background: #fff; opacity: 0; }
#opening.flash-on .flash { animation: flash .7s ease-out; }
#opening.quake .stage { animation: quake .5s; }
#opening[data-tier="2"].revealed .rays { opacity: .2; animation: spin 14s linear infinite; }
#opening[data-tier="3"].revealed .rays { opacity: .4; animation: spin 8s linear infinite; }
#opening[data-tier="4"].revealed .rays { opacity: .6; animation: spin 5s linear infinite, rainbow 2s linear infinite; }
#opening[data-tier="3"] .glow, #opening[data-tier="4"] .glow { width: 320px; height: 320px; }
#opening[data-tier="3"].revealed .loot, #opening[data-tier="4"].revealed .loot { width: 128px; height: 128px; filter: drop-shadow(0 0 10px var(--glow)); }
#opening[data-tier="4"].revealed .loot-name { animation: rainbow 2s linear infinite; }
@keyframes fly { from { transform: translate(0, 0) scale(1.4); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(.3); opacity: 0; } }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }
@keyframes quake { 20%, 60% { transform: translate(-6px, 3px); } 40%, 80% { transform: translate(6px, -3px); } }
@keyframes rainbow { to { filter: hue-rotate(360deg); } }

#opening.shaking .crate { animation: shake .12s infinite; }
#opening.shaking .glow { animation: pulse .5s infinite alternate; }
#opening.tease .glow { transform: scale(1.35); opacity: .9; }
#opening.burst .crate { transform: scale(1.6); opacity: 0; transition: transform .25s, opacity .25s; }
#opening.burst .glow { transform: scale(1.6); opacity: .9; }
#opening.silhouette .loot { filter: brightness(0) drop-shadow(0 0 6px var(--glow)); }
#opening.silhouette .loot-name, #opening.silhouette .loot-sub { visibility: hidden; }
#opening.revealed .reveal { animation: pop-in .35s ease-out; }
#opening.revealed .glow { opacity: .55; animation: spin 6s linear infinite; }
@keyframes shake { 25% { transform: translate(calc(var(--amp) * -1), 1px) rotate(-3deg); } 75% { transform: translate(var(--amp), -1px) rotate(3deg); } }
@keyframes pulse { to { transform: scale(1.15); opacity: .8; } }
@keyframes pop-in { from { transform: scale(.4); } 70% { transform: scale(1.15); } }
@keyframes spin { to { transform: rotate(360deg) scale(1.1); } }

/* --- Pêche : canne en haut à gauche, fil jusqu'au bouchon qui flotte sur l'eau --- */
#fishing {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  padding: 32px 16px calc(24px + env(safe-area-inset-bottom));
  background: rgba(5, 8, 25, .94);
  text-align: center;
}
.fish-head { min-height: 4.2em; }
.fish-msg { margin: 0; font-size: 1.4rem; }
.fish-sub { margin: 2px 0 0; font-size: 1rem; }
#fishing.bite .fish-msg { color: var(--gold); }
/* Largeur fixe : le fil relie la pointe de la canne (100, 8) au bouchon (186, 172) */
.pond { position: relative; width: 340px; height: 300px; margin: auto; }
.pond .rod { position: absolute; left: 8px; top: 0; width: 96px; height: 96px; }
.pond .line { position: absolute; left: 100px; top: 8px; width: 2px; height: 185px; background: #ddd; transform-origin: top; transform: rotate(-27.7deg); }
.pond .bobber, .pond .alert, .pond .fish-crate { position: absolute; left: 50%; }
/* Bouchon de la canne en bois (Projectile_360), à l'échelle x2 ; le fil arrive sur son sommet */
.pond .bobber {
  top: 152px;
  width: 60px;
  height: 60px;
  margin-left: -14px;
  animation: bob 1.6s ease-in-out infinite;
}
.pond .alert { top: 120px; margin-left: 6px; font-size: 2.6rem; color: var(--gold); opacity: 0; }
.pond .fish-crate { top: 170px; width: 68px; height: 68px; margin-left: -18px; object-fit: contain; image-rendering: pixelated; opacity: 0; }
.pond .water {
  position: absolute;
  inset: 186px 0 0;
  /* --water : tuile de surface de l'eau du jeu (js/fishing.js), x2 en pixels nets, sur un fond qui fonce avec la profondeur */
  background: var(--water, none) 0 0 / 32px 32px repeat-x, linear-gradient(rgb(40, 90, 210), rgba(10, 25, 90, .95));
  image-rendering: pixelated;
  animation: flow 4s linear infinite;
}
@keyframes flow { to { background-position: 32px 0, 0 0; } }
#fishing.bite .bobber { animation: dip .25s ease-in-out infinite alternate; }
#fishing.bite .alert { opacity: 1; animation: pop-in .25s; }
#fishing.caught .bobber { opacity: 0; }
#fishing.caught .fish-crate { opacity: 1; animation: reel .7s ease-out forwards; }
.fish-actions { display: grid; gap: 4px; max-width: 360px; width: 100%; margin: 0 auto; }
#f-reel { min-height: 64px; font-size: 1.6rem; }
/* Prise : halo de la couleur de rareté, rayons à partir de « rare », flash et tremblement pour le légendaire */
.pond .catch-rays {
  position: absolute; left: 50%; top: 130px; width: 260px; height: 260px; margin: -130px 0 0 -130px;
  border-radius: 50%; pointer-events: none; opacity: 0;
  background: repeating-conic-gradient(var(--glow) 0 8deg, transparent 8deg 24deg);
  -webkit-mask: radial-gradient(circle, #000 10%, transparent 65%);
  mask: radial-gradient(circle, #000 10%, transparent 65%);
}
#fishing.caught .fish-crate { filter: drop-shadow(0 0 6px var(--glow)); }
#fishing.caught[data-tier="1"] .fish-crate { filter: drop-shadow(0 0 10px var(--glow)); }
#fishing.caught[data-tier="2"] .catch-rays { opacity: .35; animation: spin 8s linear infinite; }
#fishing.caught[data-tier="3"] .catch-rays { opacity: .55; animation: spin 5s linear infinite; }
#fishing.caught[data-tier="4"] .catch-rays { opacity: .75; animation: spin 3s linear infinite, rainbow 2s linear infinite; }
#fishing.caught[data-tier="3"] .fish-crate, #fishing.caught[data-tier="4"] .fish-crate { animation: reel-big .9s ease-out forwards; filter: drop-shadow(0 0 14px var(--glow)); }
#fishing.caught[data-tier="4"] .pond { animation: quake .5s; }
#fishing.caught .fish-head { animation: pop-in .4s ease-out; }
@keyframes reel-big { to { transform: translateY(-140px) scale(2.2); } }
@keyframes bob { 50% { transform: translateY(-4px); } }
@keyframes dip { to { transform: translateY(12px); } }
@keyframes reel { to { transform: translateY(-140px) scale(1.4); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
