/* Motion for the HUD and the windows: things arrive, react and settle instead of just appearing. */

/* Health: the lost part lingers as a pale strip and drains after a moment. */
#hud .bar.hp { position: relative; }
#hud .bar.hp #hp { position: relative; z-index: 1; transition: width .12s ease-out; }
#hp-lag { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: linear-gradient(#ffe3b0, #e8a060); transition: width .55s cubic-bezier(.5, 0, .7, 1) .3s; }
#hud .bar.xp #xp { transition: width .35s ease-out; background-size: 200% 100%; }
#hud .bar.xp #xp { animation: xp-shine 2.6s linear infinite; }
@keyframes xp-shine { from { filter: brightness(1); } 50% { filter: brightness(1.35); } to { filter: brightness(1); } }

#hud .vitals.hit { animation: vitals-hit .32s ease-out; }
@keyframes vitals-hit {
  20% { translate: -4px 1px; filter: drop-shadow(0 0 10px #ff3a2a); }
  45% { translate: 3px -1px; }
  70% { translate: -1px 0; }
}
#hud .vitals.healed .bar.hp { animation: healed .7s ease-out; }
@keyframes healed { 30% { box-shadow: 0 0 14px 3px #9cff8a, inset 0 0 6px #d8ffc8; } }

/* A new level: the panel flashes gold, the number jumps. */
#hud .vitals.levelup { animation: vitals-level 1.1s ease-out; }
@keyframes vitals-level {
  0% { filter: drop-shadow(0 0 0 #ffe06a); }
  25% { filter: drop-shadow(0 0 22px #ffe06a) brightness(1.25); scale: 1.04; }
  100% { filter: drop-shadow(0 0 0 #ffe06a); scale: 1; }
}
#level.pop, #gold.pop, #keys.pop { display: inline-block; animation: pop .45s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes pop { 0% { scale: 1; } 35% { scale: 1.55; rotate: -6deg; color: #fff2b0; } 100% { scale: 1; } }

/* An ability coming back: a snap and a ring of light. */
#hud #abilities button.ready-pop { animation: ready-pop .5s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes ready-pop {
  0% { box-shadow: 0 0 0 0 #e8ff8aff, 2px 4px 0 #090b078c; }
  40% { scale: 1.18; filter: brightness(1.5); }
  100% { box-shadow: 0 0 0 18px #e8ff8a00, 2px 4px 0 #090b078c; }
}
#hud #abilities button:active:enabled { transform: scale(.9); transition: transform .06s; }
#hud #abilities button { transition: transform .15s ease-out; }

/* The goal caption and the prompt pop in. */
#map-goal.pop { animation: goal-pop .5s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes goal-pop { 0% { scale: .7; opacity: 0; } 100% { scale: 1; opacity: 1; } }
#prompt:not([hidden]) { animation: goal-pop .3s cubic-bezier(.3, 1.6, .5, 1); }

/* Windows: the backdrop fades, the sheet lands. */
#overlay:not([hidden]) { animation: veil-in .25s ease-out; }
@keyframes veil-in { from { background-color: transparent; backdrop-filter: none; } }
#overlay:not([hidden]) > .comic-popup, #overlay:not([hidden]) > h1 { animation: sheet-in .38s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes sheet-in { from { opacity: 0; } }

/* Level-up cards are dealt one after another and lift under the pointer. */
#overlay.pick .cards .card { animation: card-in .5s cubic-bezier(.2, 1.4, .4, 1) backwards; transition: filter .18s ease-out; }
#overlay.pick .cards .card:nth-child(1) { animation-delay: .08s; }
#overlay.pick .cards .card:nth-child(2) { animation-delay: .18s; }
#overlay.pick .cards .card:nth-child(3) { animation-delay: .28s; }
#overlay.pick .cards .card:nth-child(4) { animation-delay: .38s; }
@keyframes card-in { from { opacity: 0; filter: brightness(1.8); } }
#overlay.pick .cards .card:hover:enabled { filter: drop-shadow(0 0 12px #ffe58a) brightness(1.06); }
#overlay.pick .cards .card.chosen { animation: card-chosen .32s ease-in forwards; }
@keyframes card-chosen { 40% { filter: brightness(1.6) drop-shadow(0 0 24px #fff1a0); } 100% { filter: brightness(1.2) drop-shadow(0 0 30px #fff1a0); opacity: 0; } }
#overlay.pick h1 { animation: stamp .55s cubic-bezier(.2, 1.8, .4, 1) backwards; }
@keyframes stamp { from { opacity: 0; letter-spacing: .2em; } }

/* The map unrolls like a scroll. */
#atlas:not([hidden]) { animation: veil-in .25s ease-out; }
#atlas:not([hidden]) #atlas-sheet { animation: unroll .45s cubic-bezier(.2, 1.1, .4, 1); transform-origin: 50% 0; }
@keyframes unroll { from { transform: scaleY(.04); opacity: .4; } 60% { opacity: 1; } }
#atlas:not([hidden]) #atlas-legend span { animation: goal-pop .4s ease-out backwards; }

/* The HUD panels slide in when the run starts. */
#hud:not([hidden]) .panel.vitals { animation: slide-left .6s cubic-bezier(.2, 1.2, .4, 1) backwards; }
#hud:not([hidden]) .panel.tally { animation: slide-right .6s cubic-bezier(.2, 1.2, .4, 1) .1s backwards; }
#hud:not([hidden]) .panel.chapter { animation: slide-down .6s cubic-bezier(.2, 1.2, .4, 1) .05s backwards; }
#hud:not([hidden]) #abilities { animation: slide-up .6s cubic-bezier(.2, 1.2, .4, 1) .15s backwards; }
@keyframes slide-left { from { translate: -120% 0; } }
@keyframes slide-right { from { translate: 120% 0; } }
@keyframes slide-down { from { translate: 0 -160%; } }
@keyframes slide-up { from { translate: 0 160%; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Cards stay put: hover and focus only light them up. */
#overlay:is(.pick, .shop) .card:hover, #overlay:is(.pick, .shop) .card:focus-visible { transform: none; }

/* The hero's fall (main.js, DEATH_SCENE): the world drains to grey and dark, a red dusk closes in, the HUD fades. */
body.dying #view { filter: grayscale(calc(var(--dying) * .85)) brightness(calc(1 - var(--dying) * .35)) contrast(calc(1 + var(--dying) * .15)); }
body.dying #hud { opacity: calc(1 - var(--dying) * 1.6); transition: none; }
body.dying::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 5;
  background: radial-gradient(ellipse at center, transparent 30%, #3a0806 100%);
  opacity: calc(var(--dying) * .85);
}
#overlay.result:not([hidden]) { animation: veil-in 1s ease-out; }
#overlay.result:not([hidden]) h1 { animation: stamp .9s ease-out .15s backwards; }

/* The menu poster fills the whole screen; the menu sheet sits over its quiet left side. */
:root body.menu.illustrated-hero::before {
  inset: 0; height: auto; z-index: 0;
  background: url(assets/poster.webp) 68% 35% / cover no-repeat #0b120e;
  animation: poster-in 1.2s ease-out;
}
:root body.menu.illustrated-hero #overlay.menu { background: linear-gradient(90deg, #0a0f0cd9 0, #0a0f0c99 30%, transparent 55%); }
@keyframes poster-in { from { opacity: 0; scale: 1.06; } }
@media (orientation: portrait) {
  :root body.menu.illustrated-hero::before { background-size: auto 74svh; background-position: 75% 0; }
  :root body.menu.illustrated-hero #overlay.menu { background: linear-gradient(#0a0f0c66 0, #0a0f0ccc 45%, #0a0f0cf2 100%); }
}

/* The flask of living water on the health panel. */
#water-flask { --size: clamp(20px, 1.6vw, 30px); margin: -6px 6px -6px auto; filter: drop-shadow(0 0 6px #7fd8ff) hue-rotate(100deg) saturate(1.3); animation: flask-glow 2.4s ease-in-out infinite; }
#water-flask[hidden] { display: none; }
#water-flask.pop { animation: pop .45s cubic-bezier(.3, 1.8, .5, 1), flask-glow 2.4s ease-in-out .45s infinite; }
@keyframes flask-glow { 50% { filter: drop-shadow(0 0 12px #a8e8ff) hue-rotate(100deg) saturate(1.3) brightness(1.2); } }

/* The badger's poster. */
:root body.menu.illustrated-hero[data-poster="1"]::before { background-image: url(assets/poster-badger.webp); }

/* Cutscenes: the film over the whole screen, letterboxed in black, fading in and out. */
#cutscene { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: #000; animation: cut-in .45s ease-out; }
#cutscene[hidden] { display: none; }
#cutscene video { width: 100%; height: 100%; object-fit: contain; }
#cutscene .skip { position: absolute; right: 24px; bottom: 22px; padding: 8px 16px; border: 2px solid #b9f34f88; border-radius: 6px; background: #0a0f0ccc; color: #e2ff9a; font: 600 14px/1 'Oswald', sans-serif; text-transform: uppercase; cursor: pointer; opacity: .75; }
#cutscene .skip:hover { opacity: 1; }
#cutscene.out { animation: cut-out .6s ease-in forwards; }
@keyframes cut-in { from { opacity: 0; } }
@keyframes cut-out { to { opacity: 0; } }
