/* =========================================================
   Le Chaudron des Potions Folles d'Arwen — styles principaux
   ========================================================= */
@font-face { font-family: 'Fredoka'; src: url('../assets/fonts/fredoka-latin.woff2') format('woff2'); font-weight: 300 700; font-display: swap; }
@font-face { font-family: 'Grandstander'; src: url('../assets/fonts/grandstander-latin.woff2') format('woff2'); font-weight: 700 900; font-display: swap; }

:root {
  --ink: #2a1838;
  --ink-soft: #4a2f63;
  --night: #1a0f26;
  --cream: #fff4dc;
  --parchment: #f6e3bf;
  --gold: #ffd23f;
  --gold-deep: #c98a1a;
  --rose: #ff6fcf;
  --mint: #6fffc0;
  --cyan: #5ff3ff;
  --violet: #a56bff;
  --wood: #a8603a;
  --wood-dark: #4a2618;
  --potion: #6fffc0;
  --potion-glow: #6fffc0;
  --font: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  --font-title: 'Grandstander', 'Fredoka', 'Comic Sans MS', system-ui, sans-serif;
  --hud: clamp(54px, 9vh, 76px);
  --tray-h: clamp(118px, 20vh, 168px);
  --cw: min(33vw, 47vh);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --radius: 22px;
  color-scheme: dark;
}

@media (orientation: portrait) {
  :root { --cw: min(76vw, 40vh); --tray-h: clamp(132px, 21vh, 184px); --hud: clamp(52px, 7.5vh, 70px); }
}
@media (max-height: 430px) and (orientation: landscape) {
  :root { --tray-h: 96px; --cw: min(30vw, 54vh); --hud: 46px; }
  .tray-families { display: none !important; }
  .speech { font-size: 15px !important; padding: 8px 12px !important; max-width: 46vw !important; }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--night); color: var(--cream); font-family: var(--font); overflow: hidden; overscroll-behavior: none; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-user-select: none; user-select: none; }
img, svg { -webkit-user-drag: none; user-select: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 4px solid var(--gold); outline-offset: 3px; border-radius: 16px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app { position: fixed; inset: 0; }

/* ---------- Scène et parallaxe ---------- */
.stage { position: absolute; inset: 0; overflow: hidden; background: #1a0f26; contain: strict; }
.lab-layer { position: absolute; inset: -2.5%; will-change: transform; pointer-events: none; }
.lab-layer > svg { width: 100%; height: 100%; display: block; }
.lab-layer .hot { pointer-events: auto; cursor: pointer; }
.lab-layer .hot:focus-visible { outline: none; }
.lab-layer .hot:focus-visible > * { filter: drop-shadow(0 0 6px #ffd23f) drop-shadow(0 0 2px #fff); }
.stage.is-inverted .lab-layer, .stage.is-inverted .cauldron { filter: hue-rotate(180deg) saturate(1.25); }
.lab-layer, .cauldron { transition: filter 1.4s ease; }

.spectacle-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.spectacle-layer .sprite { position: absolute; overflow: visible; }
.fx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* ---------- Chaudron ---------- */
.cauldron {
  position: absolute; left: 50%; bottom: calc(var(--tray-h) + var(--safe-b) - var(--cw) * 0.025);
  width: var(--cw); aspect-ratio: 1; transform: translateX(-50%); transform-origin: 50% 90%;
}
.cauldron > div, .cauldron > canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.cauldron-back svg, .cauldron-front svg { width: 100%; height: 100%; display: block; overflow: visible; }
.cauldron-front { pointer-events: none; }
.cauldron-glow {
  inset: -38% -30% 10% -30% !important; width: auto !important; height: auto !important;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--potion-glow) 55%, transparent), transparent 75%);
  opacity: .55; pointer-events: none; mix-blend-mode: screen;
}
.cauldron-hit { position: absolute; left: 10%; right: 10%; top: 12%; bottom: 3%; background: none; border: 0; border-radius: 45%; padding: 0; touch-action: none; }
.magic-name {
  position: absolute; left: 50%; top: 30%; transform: translateX(-50%); display: flex; gap: .05em;
  font-family: var(--font-title); font-size: clamp(64px, 16vh, 160px); color: var(--gold);
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; text-shadow: 0 0 30px rgba(255, 210, 63, .8), 0 8px 0 var(--ink);
}
.magic-name span { display: inline-block; }
.cauldron.is-target .cauldron-glow { opacity: .95; }
.cauldron.is-target .cauldron-front svg { filter: drop-shadow(0 0 calc(var(--cw) * .04) var(--potion-glow)); }
.cauldron-slots {
  position: absolute; left: 50%; top: 4%; transform: translateX(-50%);
  display: flex; gap: calc(var(--cw) * .02); margin: 0; padding: 0; list-style: none; pointer-events: none;
}
.cauldron-slots li {
  width: calc(var(--cw) * .13); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8, #fff1 60%), rgba(42, 24, 56, .55);
  border: 3px solid rgba(255, 244, 220, .75); box-shadow: 0 0 12px rgba(255, 210, 63, .45);
  display: grid; place-items: center;
}
.cauldron-slots li img { width: 82%; height: 82%; }
.cauldron-slots li.empty { background: rgba(42, 24, 56, .35); border-style: dashed; border-color: rgba(255, 244, 220, .35); box-shadow: none; }

/* ---------- Familier ---------- */
.familiar {
  position: absolute; width: calc(var(--cw) * .44); aspect-ratio: 200 / 220;
  left: calc(50% - var(--cw) * .5 - var(--cw) * .40); bottom: calc(var(--tray-h) + var(--safe-b) + var(--cw) * .0);
  cursor: pointer; transform-origin: 50% 100%; touch-action: manipulation;
}
.familiar svg { width: 100%; height: 100%; display: block; overflow: visible; }
@media (orientation: portrait) {
  .familiar { width: calc(var(--cw) * .34); left: 2vw; bottom: calc(var(--tray-h) + var(--safe-b) + var(--cw) * 1.02); }
}

/* ---------- HUD ---------- */
.hud {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20; pointer-events: none;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  padding: calc(var(--safe-t) + 10px) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
}
.hud-group { display: flex; gap: clamp(8px, 1.4vw, 14px); pointer-events: auto; }
.hud-btn {
  width: var(--hud); height: var(--hud); padding: calc(var(--hud) * .12); border-radius: 50%;
  border: 4px solid var(--ink);
  background: radial-gradient(circle at 35% 28%, #f7c48a, #b86a3c 55%, #6e3a22);
  box-shadow: inset 0 -5px 0 rgba(42, 24, 56, .35), inset 0 3px 0 rgba(255, 255, 255, .35), 0 6px 0 rgba(26, 11, 46, .55), 0 0 18px rgba(255, 179, 71, .25);
  position: relative;
}
.hud-btn svg { width: 100%; height: 100%; display: block; transition: transform .15s ease; }
.hud-btn:active svg { transform: translateY(3px) scale(.92); }
.hud-btn .badge {
  position: absolute; top: -6px; right: -6px; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px;
  background: var(--rose); color: #fff; border: 3px solid var(--ink); font-weight: 700; font-size: 14px; line-height: 20px; text-align: center;
}
.mission-banner {
  pointer-events: auto; flex: 0 1 auto; max-width: min(560px, 54vw); margin-top: 2px;
  display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 10px;
  background: url('../assets/images/ui/parchment.svg') center / 100% 100% no-repeat;
  color: var(--ink); font-weight: 600; font-size: clamp(14px, 2vh, 18px);
  filter: drop-shadow(0 6px 0 rgba(26, 11, 46, .45));
}
.mission-banner .mb-icons { display: flex; gap: 6px; }
.mission-banner .mb-icons > * { width: clamp(34px, 6vh, 48px); height: clamp(34px, 6vh, 48px); }
.mission-banner .mb-close { width: 40px; height: 40px; padding: 4px; border: 0; background: none; flex: none; }
.mission-banner .mb-icons > span, .mission-banner .mb-slot { position: relative; display: inline-block; width: clamp(34px, 6vh, 48px); height: clamp(34px, 6vh, 48px); }
.mission-banner .mb-icons svg, .mission-banner .mb-icons img { width: 100%; height: 100%; display: block; }
.mission-banner .mb-slot.mystery i { position: absolute; right: -6px; bottom: -6px; width: 24px; height: 24px; }
.mission-banner .mb-slot.mystery i svg { width: 100%; height: 100%; }
.folie { display: flex; align-items: center; gap: 8px; }
.folie-gauge { width: clamp(120px, 22vw, 240px); height: 24px; border-radius: 12px; border: 3px solid var(--ink); background: #fff8e6; overflow: hidden; }
.folie-gauge i { display: block; height: 100%; background: linear-gradient(90deg, #6fffc0, #ffd23f, #ff6fcf, #a56bff); border-radius: 8px; }
.ing-btn.is-hint .ing-socle { animation: hint-glow 1.1s ease-in-out infinite; }
@keyframes hint-glow { 0%, 100% { box-shadow: 0 0 0 3px var(--gold), 0 0 12px #ffd23f; } 50% { box-shadow: 0 0 0 6px var(--gold), 0 0 28px #ffd23f; } }
.hidden-sparkle {
  position: absolute; width: 54px; height: 54px; margin: -27px 0 0 -27px; padding: 0; border: 0; background: none; pointer-events: auto; cursor: pointer;
  filter: drop-shadow(0 0 10px #ffd23f) drop-shadow(0 0 4px #fff); z-index: 5;
}
.hidden-sparkle svg { width: 100%; height: 100%; }
@media (prefers-reduced-motion: reduce) { .ing-btn.is-hint .ing-socle { animation: none; box-shadow: 0 0 0 5px var(--gold); } }
@media (orientation: portrait) { .mission-banner { position: absolute; top: calc(var(--safe-t) + var(--hud) + 18px); left: 50%; transform: translateX(-50%); max-width: 92vw; } }

/* ---------- Boutons mélanger / vider ---------- */
.brew-actions { position: absolute; z-index: 15; left: calc(50% + var(--cw) * .46); bottom: calc(var(--tray-h) + var(--safe-b) + var(--cw) * .38); display: flex; flex-direction: column; align-items: center; gap: 10px; }
@media (orientation: portrait) { .brew-actions { left: auto; right: 3vw; bottom: calc(var(--tray-h) + var(--safe-b) + var(--cw) * .9); } }
.brew-btn, .empty-btn { border: 0; background: none; padding: 0; filter: drop-shadow(0 6px 0 rgba(26, 11, 46, .5)); }
.brew-btn { width: clamp(84px, calc(var(--cw) * .34), 140px); aspect-ratio: 1; }
.empty-btn { width: clamp(52px, calc(var(--cw) * .18), 74px); aspect-ratio: 1; }
.brew-btn svg, .empty-btn svg { width: 100%; height: 100%; }

/* ---------- Étagère d'ingrédients ---------- */
.tray {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 12;
  height: calc(var(--tray-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto 1fr; align-items: center;
  background:
    linear-gradient(to bottom, transparent 0 12%, rgba(26, 11, 46, .35) 100%),
    url('../assets/images/ui/plank.svg') left top / auto 100% repeat-x;
  filter: drop-shadow(0 -8px 14px rgba(10, 4, 20, .55));
}
.tray-families {
  grid-column: 1 / -1; display: flex; gap: 6px; justify-content: center; padding: 0 12px;
  transform: translateY(-48%); height: 0; align-items: center;
}
.fam-chip {
  width: clamp(38px, 6vh, 50px); height: clamp(38px, 6vh, 50px); border-radius: 50%; padding: 5px;
  border: 3px solid var(--ink); background: radial-gradient(circle at 35% 30%, #fff8e6, #e8cfa6);
  box-shadow: 0 4px 0 rgba(26, 11, 46, .45); transition: transform .15s ease;
}
.fam-chip svg { width: 100%; height: 100%; display: block; }
.fam-chip[aria-pressed="true"] { background: radial-gradient(circle at 35% 30%, #fff, var(--gold)); transform: translateY(-4px) scale(1.08); }
.fam-chip.all { font-weight: 700; color: var(--ink); font-size: 13px; line-height: 1; }
.tray-arrow {
  width: clamp(40px, 6vh, 54px); height: clamp(40px, 6vh, 54px); margin: 0 6px; padding: 6px; border-radius: 50%;
  border: 3px solid var(--ink); background: radial-gradient(circle at 35% 30%, #f7c48a, #a8603a); align-self: center;
  box-shadow: 0 4px 0 rgba(26, 11, 46, .45);
}
.tray-arrow svg { width: 100%; height: 100%; display: block; }
.tray-list {
  grid-row: 2; grid-column: 2; display: flex; gap: clamp(8px, 1.4vw, 16px); margin: 0; list-style: none;
  padding: calc(var(--tray-h) * .1) 8px calc(var(--tray-h) * .06);
  overflow-x: auto; overflow-y: hidden; scroll-snap-type: x proximity; scroll-behavior: smooth;
  scrollbar-width: none; touch-action: pan-x; overscroll-behavior-x: contain; height: 100%; align-items: center;
}
.tray-list::-webkit-scrollbar { display: none; }
.ing-btn {
  position: relative; flex: 0 0 auto; scroll-snap-align: center;
  width: calc(var(--tray-h) * .64); height: calc(var(--tray-h) * .64); max-width: 108px; max-height: 108px;
  padding: 0; border: 0; background: none; border-radius: 50%; touch-action: none;
}
.ing-btn::before {
  content: ''; position: absolute; inset: 8% 4% -2%; border-radius: 50%;
  background: radial-gradient(ellipse at 50% 85%, rgba(26, 11, 46, .55), transparent 65%);
}
.ing-btn .ing-socle {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--c) 38%, #fff4dc) 0%, color-mix(in srgb, var(--c) 18%, #3a2853) 62%, #2a1838 100%);
  border: 3px solid var(--ink);
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, .25), inset 0 -6px 10px rgba(26, 11, 46, .5), 0 0 14px color-mix(in srgb, var(--c) 45%, transparent);
}
.ing-btn[data-rarity="2"] .ing-socle { border-color: #c9d4ff; box-shadow: inset 0 4px 0 rgba(255,255,255,.25), inset 0 -6px 10px rgba(26,11,46,.5), 0 0 0 3px var(--ink), 0 0 16px #c9d4ff88; }
.ing-btn[data-rarity="3"] .ing-socle { border-color: var(--gold); box-shadow: inset 0 4px 0 rgba(255,255,255,.25), inset 0 -6px 10px rgba(26,11,46,.5), 0 0 0 3px var(--ink), 0 0 20px #ffd23faa; }
.ing-btn img { position: absolute; inset: 6%; width: 88%; height: 88%; filter: drop-shadow(0 4px 2px rgba(26, 11, 46, .45)); transition: transform .2s ease; pointer-events: none; }
.ing-btn:hover img { transform: translateY(-4px) rotate(-4deg) scale(1.06); }
.ing-btn.is-new::after {
  content: ''; position: absolute; top: -4px; right: -4px; width: 30%; height: 30%;
  background: url('../assets/images/ui/sparkle.svg') center / contain no-repeat;
  animation: twinkle 1.6s ease-in-out infinite;
}
.ing-btn .ing-name {
  position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); white-space: nowrap;
  font-size: 12px; font-weight: 600; color: var(--ink); background: var(--cream); border: 2px solid var(--ink);
  border-radius: 10px; padding: 1px 8px; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.ing-btn:hover .ing-name, .ing-btn:focus-visible .ing-name { opacity: 1; }
.ing-btn.is-dragging { opacity: .35; }
@media (orientation: portrait) {
  .ing-btn { width: min(84px, calc(var(--tray-h) * .5)); height: min(84px, calc(var(--tray-h) * .5)); }
  .tray-list { gap: 10px; }
}
.ing-missing {
  position: absolute; inset: 14%; display: grid; place-items: center; text-align: center; border-radius: 50%;
  border: 3px dashed var(--rose); color: #ffd6f2; background: #2a1838; font-size: 10px; font-weight: 700; line-height: 1.1; padding: 4px;
}
@keyframes twinkle { 0%, 100% { transform: scale(.7) rotate(0); opacity: .6; } 50% { transform: scale(1.1) rotate(30deg); opacity: 1; } }

.drag-ghost { position: fixed; left: 0; top: 0; width: 96px; height: 96px; z-index: 60; pointer-events: none; display: none; filter: drop-shadow(0 10px 8px rgba(10, 4, 20, .55)); }
.drag-ghost img { width: 100%; height: 100%; }
.flying-ing { position: fixed; z-index: 30; pointer-events: none; filter: drop-shadow(0 8px 6px rgba(10, 4, 20, .5)); }

/* ---------- Bulle de parole ---------- */
.speech {
  position: absolute; z-index: 25; max-width: min(380px, 70vw);
  left: calc(50% - var(--cw) * .5 - var(--cw) * .40); bottom: calc(var(--tray-h) + var(--safe-b) + var(--cw) * .62);
  padding: 14px 18px; border-radius: 26px; background: var(--cream); color: var(--ink);
  border: 4px solid var(--ink); font-size: clamp(16px, 2.4vh, 21px); font-weight: 600; line-height: 1.25;
  box-shadow: 0 6px 0 rgba(26, 11, 46, .5); transform-origin: 20% 100%; pointer-events: none;
}
.speech::after {
  content: ''; position: absolute; left: 34px; bottom: -22px; width: 30px; height: 26px;
  background: var(--cream); border-right: 4px solid var(--ink); border-bottom: 4px solid var(--ink);
  transform: skewX(-25deg) rotate(36deg); border-bottom-right-radius: 10px;
}
.speech p { margin: 0; position: relative; z-index: 1; }
.speech[data-anchor="cauldron"] { left: calc(50% + var(--cw) * .18); bottom: calc(var(--tray-h) + var(--safe-b) + var(--cw) * .82); background: #f3ecff; transform-origin: 10% 100%; }
.speech[data-anchor="cauldron"]::after { background: #f3ecff; }
@media (orientation: portrait) { .speech[data-anchor="cauldron"] { left: 6vw; bottom: calc(var(--tray-h) + var(--safe-b) + var(--cw) * 1.0); } }
@media (orientation: portrait) { .speech { left: 4vw; bottom: calc(var(--tray-h) + var(--safe-b) + var(--cw) * 1.42); max-width: 88vw; } }

.toast-zone { position: absolute; z-index: 70; left: 50%; top: calc(var(--safe-t) + 6px); transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: max-content; max-width: min(560px, 64vw); }
.toast {
  display: flex; align-items: center; gap: 8px; padding: 4px 14px 4px 6px; border-radius: 999px;
  background: linear-gradient(#fff8e6, #f6e3bf); color: var(--ink); border: 3px solid var(--ink);
  font-weight: 700; font-size: clamp(13px, 1.9vh, 16px); box-shadow: 0 4px 0 rgba(26, 11, 46, .5);
}
.toast img, .toast svg { width: 32px; height: 32px; flex: none; }
@media (orientation: portrait) { .toast-zone { top: calc(var(--safe-t) + var(--hud) + 16px); max-width: 92vw; } }

.tutorial-hand { position: fixed; left: 0; top: 0; z-index: 80; width: 86px; height: 86px; pointer-events: none; filter: drop-shadow(0 8px 6px rgba(10, 4, 20, .55)); }
.tutorial-hand svg { width: 100%; height: 100%; }

.missing-asset { width: 100%; height: 100%; }
.asset-warning {
  position: fixed; left: 8px; bottom: calc(var(--tray-h) + 8px); z-index: 90; max-width: 320px; padding: 8px 12px; border-radius: 12px;
  background: #2a1838ee; border: 2px dashed var(--rose); color: #ffd6f2; font-size: 13px;
}

/* ---------- Écran d'accueil ---------- */
.intro { position: absolute; inset: 0; z-index: 100; display: grid; place-items: center; overflow: hidden; background: #160c24; }
.intro-sky {
  position: absolute; inset: -10%;
  background:
    radial-gradient(ellipse at 50% 120%, rgba(255, 159, 74, .55), transparent 55%),
    radial-gradient(circle at 70% 20%, rgba(255, 243, 196, .35), transparent 18%),
    radial-gradient(ellipse at 30% 30%, rgba(165, 107, 255, .35), transparent 45%),
    linear-gradient(#0d1542, #2c1d52 60%, #4a2a5e);
}
.intro-content { position: relative; text-align: center; padding: 20px; }
.intro-title { margin: 0 0 4vh; font-family: var(--font-title); line-height: .95; color: var(--gold); text-shadow: 0 5px 0 var(--ink), 0 0 30px rgba(255, 210, 63, .5); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
.intro-title span { display: block; }
.intro-title .t-small { font-size: clamp(26px, 5.5vh, 48px); color: var(--cream); }
.intro-title .t-big { font-size: clamp(48px, 13vh, 120px); background: linear-gradient(#fff1a8, #ffd23f 45%, #ff9a3a); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 5px 0 var(--ink)); -webkit-text-stroke: 3px var(--ink); }
.intro-loading { font-size: 20px; opacity: .8; }
.intro-buttons { display: flex; gap: 20px; justify-content: center; flex-wrap: wrap; }
.big-btn {
  display: inline-flex; align-items: center; gap: 12px; min-height: 84px; padding: 10px 30px 10px 16px; border-radius: 999px;
  border: 5px solid var(--ink); background: linear-gradient(#9dffcf, #3fd69a); color: var(--ink);
  font-weight: 700; font-size: clamp(20px, 3.2vh, 28px); box-shadow: 0 8px 0 rgba(26, 11, 46, .6), inset 0 4px 0 rgba(255, 255, 255, .5);
}
.big-btn.alt { background: linear-gradient(#f3e6ff, #b9a2e8); }
.big-btn:active { box-shadow: 0 3px 0 rgba(26, 11, 46, .6), inset 0 4px 0 rgba(255, 255, 255, .5); }
.big-btn svg { width: 60px; height: 60px; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; padding: 30px; text-align: center; font-size: 24px; background: var(--night); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
  .ing-btn.is-new::after { animation: none; }
}
