/* ═══════════════════════════════════════════════════════════════════
   Effects layer — visual polish (animations, particles, themes)
   Self-contained: no edits to existing files required.
   ═══════════════════════════════════════════════════════════════════ */

/* ── 1. Type-color theme (timer + image-box accent) ──────────────── */
:root {
    --type-accent: #54c43a;
    --type-accent-dark: #2d8a4a;
    --type-accent-glow: rgba(84, 196, 58, 0.45);
}

#timerBar.type-themed #timerFill {
    background: var(--type-accent) !important;
    box-shadow: 0 0 8px var(--type-accent-glow) !important;
}

.image-box.type-themed {
    border-color: var(--type-accent) !important;
    box-shadow: 0 0 18px var(--type-accent-glow), inset 0 2px 8px rgba(0, 0, 0, 0.06) !important;
}

/* ── 2. Wrong-answer particle burst + global shake ───────────────── */
@keyframes shake-screen {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-6px); }
    30% { transform: translateX(7px); }
    45% { transform: translateX(-5px); }
    60% { transform: translateX(4px); }
    80% { transform: translateX(-2px); }
}

.shake-screen {
    animation: shake-screen 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

#wrongParticleCanvas {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9998;
    display: none;
}

/* ── 3. Progressive shadow reveal (gaussian blur fade) ──────────── */
@keyframes reveal-blur {
    0%   { filter: brightness(0) blur(12px); }
    50%  { filter: brightness(0.5) blur(6px); }
    100% { filter: brightness(1) blur(0); }
}

.fx-reveal-progressive {
    animation: reveal-blur 0.6s ease-out forwards;
}

/* ── 4. Pokéball reveal animation on correct answer ──────────────── */
@keyframes pokeball-drop {
    0%   { transform: translate(-50%, -200%) rotate(0); opacity: 1; }
    35%  { transform: translate(-50%, -50%) rotate(360deg); opacity: 1; }
    50%  { transform: translate(-50%, -50%) rotate(360deg) scale(1.1); }
    65%  { transform: translate(-50%, -50%) rotate(360deg) scale(0.95); }
    100% { transform: translate(-50%, -50%) rotate(360deg) scale(1.6); opacity: 0; }
}

@keyframes pokeball-flash {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

.pokeball-reveal {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 64px;
    height: 64px;
    pointer-events: none;
    z-index: 5;
    /* image-box has overflow:hidden — keep peak scale within box */
    animation: pokeball-drop 0.9s cubic-bezier(0.5, -0.3, 0.4, 1.4) forwards;
}

.pokeball-reveal::after {
    content: '';
    position: absolute;
    inset: -20px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.9) 0%, transparent 70%);
    animation: pokeball-flash 0.9s ease-out forwards;
}

/* ── 5. Skeleton loading placeholders ────────────────────────────── */
@keyframes skeleton-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(90deg,
            rgba(200, 200, 220, 0.4) 25%,
            rgba(220, 220, 240, 0.7) 50%,
            rgba(200, 200, 220, 0.4) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: 8px;
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}

[data-theme="dark"] .skeleton {
    background: linear-gradient(90deg,
            rgba(40, 40, 60, 0.6) 25%,
            rgba(70, 70, 95, 0.8) 50%,
            rgba(40, 40, 60, 0.6) 75%);
    background-size: 200% 100%;
}

.skeleton-row {
    height: 48px;
    margin: 6px 0;
    border-radius: 10px;
}

.skeleton-line {
    height: 14px;
    margin: 6px 0;
    border-radius: 4px;
}

.skeleton-circle {
    border-radius: 50%;
}

/* ── 6. Streak flames around the score counter ───────────────────── */
.score-flames-wrap {
    position: relative;
    display: inline-block;
}

.score-flames-wrap::before,
.score-flames-wrap::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 0;
    height: 0;
    opacity: 0;
    transition: opacity 0.3s, width 0.3s, height 0.3s;
    pointer-events: none;
}

.score-flames-wrap::before {
    left: -8px;
    transform: translate(-100%, -50%);
}

.score-flames-wrap::after {
    right: -8px;
    transform: translate(100%, -50%);
}

/* Tier 1: étincelles (3-4) */
.score-flames-wrap.streak-spark::before,
.score-flames-wrap.streak-spark::after {
    width: 12px;
    height: 12px;
    opacity: 1;
    background: radial-gradient(circle, #ffeb3b 0%, #ff9800 70%, transparent 100%);
    border-radius: 50%;
    box-shadow: 0 0 8px #ff9800;
    animation: spark-pulse 0.6s ease-in-out infinite alternate;
}

/* Tier 2: flammes (5-9) */
.score-flames-wrap.streak-flame::before,
.score-flames-wrap.streak-flame::after {
    width: 18px;
    height: 26px;
    opacity: 1;
    background: radial-gradient(ellipse at 50% 80%, #fff176 0%, #ffb300 40%, #f4511e 75%, transparent 100%);
    border-radius: 50% 50% 50% 50% / 70% 70% 30% 30%;
    box-shadow: 0 0 14px rgba(244, 81, 30, 0.7);
    animation: flame-flicker 0.4s ease-in-out infinite alternate;
}

/* Tier 3: inferno (10+) */
.score-flames-wrap.streak-inferno::before,
.score-flames-wrap.streak-inferno::after {
    width: 26px;
    height: 38px;
    opacity: 1;
    background: radial-gradient(ellipse at 50% 80%,
            #fffde7 0%,
            #ffd700 30%,
            #ff5722 65%,
            #b71c1c 90%,
            transparent 100%);
    border-radius: 50% 50% 50% 50% / 80% 80% 30% 30%;
    box-shadow: 0 0 20px #ff5722, 0 0 40px #ffd700;
    animation: flame-flicker 0.3s ease-in-out infinite alternate;
}

@keyframes spark-pulse {
    from { transform: translate(-100%, -50%) scale(0.8); }
    to   { transform: translate(-100%, -50%) scale(1.2); }
}

.score-flames-wrap::after {
    /* override transform origin for right side */
}

.score-flames-wrap.streak-spark::after { animation-name: spark-pulse-r; }
.score-flames-wrap.streak-flame::after,
.score-flames-wrap.streak-inferno::after { animation-name: flame-flicker-r; }

@keyframes spark-pulse-r {
    from { transform: translate(100%, -50%) scale(0.8); }
    to   { transform: translate(100%, -50%) scale(1.2); }
}

@keyframes flame-flicker {
    0%   { transform: translate(-100%, -50%) scaleY(1) rotate(-2deg); }
    100% { transform: translate(-100%, -50%) scaleY(1.15) rotate(2deg); }
}

@keyframes flame-flicker-r {
    0%   { transform: translate(100%, -50%) scaleY(1) rotate(2deg); }
    100% { transform: translate(100%, -50%) scaleY(1.15) rotate(-2deg); }
}

/* ── 7. Day/night dynamic background ─────────────────────────────── */
body[data-tod="dawn"] {
    background: linear-gradient(180deg, #ffb88c 0%, #ffd6a5 35%, #fcd5b5 70%, #f5e6d3 100%) fixed;
}

body[data-tod="day"] {
    background: linear-gradient(180deg, #87ceeb 0%, #b3e0ff 50%, #e8f4ff 100%) fixed;
}

body[data-tod="dusk"] {
    background: linear-gradient(180deg, #4a3e7a 0%, #c66b6b 40%, #f0935b 75%, #ffc78a 100%) fixed;
}

body[data-tod="night"] {
    background: linear-gradient(180deg, #0c1445 0%, #1a1a3e 50%, #2a1a4a 100%) fixed;
}

/* Dark mode overrides daytime tints to keep night ambiance */
[data-theme="dark"] body[data-tod] {
    background: linear-gradient(180deg, #0c0c1e 0%, #1a1a2e 100%) fixed !important;
}

/* ── 8. Player mini-avatar (top-left of game screens, under timer) ─── */
.player-mini-avatar {
    position: absolute;
    top: 36px;
    left: 8px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--border, #2e2e2e);
    background: white;
    object-fit: cover;
    z-index: 4;
    pointer-events: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.25s ease;
    animation: avatar-idle 2.4s ease-in-out infinite;
}

.player-mini-avatar.mood-happy {
    animation: avatar-bounce 0.6s ease;
}

.player-mini-avatar.mood-sad {
    animation: avatar-shake 0.5s ease;
    filter: grayscale(0.5);
}

@keyframes avatar-idle {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-3px); }
}

@keyframes avatar-bounce {
    0%, 100% { transform: translateY(0) scale(1); }
    30% { transform: translateY(-10px) scale(1.12); }
    60% { transform: translateY(0) scale(0.95); }
}

@keyframes avatar-shake {
    0%, 100% { transform: translateX(0) rotate(0); }
    25% { transform: translateX(-4px) rotate(-6deg); }
    75% { transform: translateX(4px) rotate(6deg); }
}

@media (max-width: 480px) {
    .player-mini-avatar { width: 36px; height: 36px; top: 30px; left: 4px; }
}

/* ── 9. Holographic shiny effect (Pokédex cards) ─────────────────── */
@keyframes holo-shine {
    0%   { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

.pokedex-item.shiny.holo {
    position: relative;
    overflow: hidden;
}

.pokedex-item.shiny.holo::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
            115deg,
            rgba(255, 0, 150, 0.55) 0%,
            rgba(0, 200, 255, 0.55) 18%,
            rgba(120, 255, 50, 0.55) 36%,
            rgba(255, 255, 0, 0.55) 54%,
            rgba(255, 0, 150, 0.55) 72%,
            rgba(0, 200, 255, 0.55) 90%);
    background-size: 250% 100%;
    mix-blend-mode: overlay;
    pointer-events: none;
    animation: holo-shine 3.5s linear infinite;
    z-index: 1;
    opacity: 0.85;
    border-radius: inherit;
}

.pokedex-item.shiny.holo img,
.pokedex-item.shiny.holo span {
    position: relative;
    z-index: 2;
}

/* ── 10. Circular timer (SVG ring) ───────────────────────────────── */
.circular-timer {
    width: 70px;
    height: 70px;
    margin: 0 auto 6px;
    position: relative;
    display: none;
}

body.timer-circular .circular-timer { display: block; }
body.timer-circular #timerBar { display: none; }
body.timer-circular #timerLabel,
body.timer-circular #globalTimerLabel { display: none; }

.circular-timer svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.circular-timer .ct-bg {
    fill: none;
    stroke: rgba(0, 0, 0, 0.15);
    stroke-width: 6;
}

.circular-timer .ct-fill {
    fill: none;
    stroke: var(--hp-high);
    stroke-width: 6;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s linear, stroke 0.3s;
}

.circular-timer .ct-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-pixel, monospace);
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--text);
}

/* ── 11. Ditto reveal as a real sprite (replaces emoji overlay) ──── */
.ditto-overlay.ditto-sprite {
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 0;
    font-size: 0;
}

.ditto-overlay.ditto-sprite img {
    width: 160px;
    height: 160px;
    image-rendering: pixelated;
    animation: ditto-bounce 0.7s ease-in-out infinite alternate;
    filter: drop-shadow(0 4px 12px rgba(255, 105, 180, 0.6));
}

@keyframes ditto-bounce {
    0%   { transform: translateY(0) scale(1); }
    100% { transform: translateY(-12px) scale(1.05); }
}

.ditto-overlay.ditto-sprite::after {
    content: 'Métamorph !';
    color: white;
    font-family: var(--font-pixel, monospace);
    font-size: 1rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

/* ── Reduce motion for accessibility ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .shake-screen,
    .pokeball-reveal,
    .fx-reveal-progressive,
    .score-flames-wrap::before,
    .score-flames-wrap::after,
    .player-mini-avatar,
    .pokedex-item.shiny.holo::before,
    .ditto-overlay.ditto-sprite img {
        animation: none !important;
        transition: none !important;
    }
}
