/*
 * WP Flashcard — Animations & Sounds
 * Enhanced animation CSS layered on top of the parent plugin styles.
 */

/* ── Entrance Animation ───────────────────────────────── */

@keyframes wpfc-fx-fade-up {
    0%   { opacity: 0; transform: translateY(20px) scale(0.98); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.wpfc-fx-entrance {
    animation: wpfc-fx-fade-up 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* ── Flip Bounce ──────────────────────────────────────── */
/* Applied to card-outer (not card-inner) to avoid overriding the rotateX flip */

@keyframes wpfc-fx-flip-bounce {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.02); }
    70%  { transform: scale(0.99); }
    100% { transform: scale(1); }
}

.wpfc-fx-enhanced .wpfc-fx-flip-bounce {
    animation: wpfc-fx-flip-bounce 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Star Pop ─────────────────────────────────────────── */

@keyframes wpfc-fx-star-pop {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.4); }
    60%  { transform: scale(0.85); }
    100% { transform: scale(1); }
}

.wpfc-fx-star-pop {
    animation: wpfc-fx-star-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

/* ── Star Sparkle Particles ───────────────────────────── */

@keyframes wpfc-fx-particle-burst {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    50% {
        opacity: 0.9;
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx, 0), var(--ty, 0)) scale(0.2);
    }
}

.wpfc-fx-star-particle {
    width: var(--size, 10px);
    height: var(--size, 10px);
    border-radius: 50%;
    background: radial-gradient(circle, #fff 20%, #ffc107 60%, rgba(255, 193, 7, 0) 100%);
    animation: wpfc-fx-particle-burst 0.65s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    box-shadow: 0 0 6px 2px rgba(255, 193, 7, 0.7), 0 0 12px rgba(255, 193, 7, 0.4);
}

/* ── Poof Particles (unstar) ──────────────────────────── */

@keyframes wpfc-fx-poof {
    0% {
        opacity: 0.8;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx, 0), var(--ty, 0)) scale(0.2);
    }
}

.wpfc-fx-poof-particle {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #c2c2c2;
    pointer-events: none;
    z-index: 99999;
    animation: wpfc-fx-poof 0.4s ease-out forwards;
}

/* ── Shuffle Shake (forward) ──────────────────────────── */

@keyframes wpfc-fx-shuffle-shake {
    0%   { transform: translateX(0) rotate(0deg); }
    12%  { transform: translateX(-6px) rotate(-1deg); }
    24%  { transform: translateX(6px) rotate(1deg); }
    36%  { transform: translateX(-5px) rotate(-0.8deg); }
    48%  { transform: translateX(5px) rotate(0.8deg); }
    60%  { transform: translateX(-3px) rotate(-0.4deg); }
    75%  { transform: translateX(2px) rotate(0.2deg); }
    100% { transform: translateX(0) rotate(0deg); }
}

.wpfc-fx-shuffle-shake {
    animation: wpfc-fx-shuffle-shake 0.7s ease-in-out !important;
}

/* ── Unshuffle Settle (rewind) ───────────────────────── */

@keyframes wpfc-fx-unshuffle-settle {
    0%   { transform: translateX(0) rotate(0deg); }
    20%  { transform: translateX(3px) rotate(0.4deg); }
    50%  { transform: translateX(-2px) rotate(-0.2deg); }
    100% { transform: translateX(0) rotate(0deg); }
}

.wpfc-fx-unshuffle-settle {
    animation: wpfc-fx-unshuffle-settle 0.7s ease-in-out !important;
}

/* ── Ghost Cards (shared base) ───────────────────────── */

.wpfc-fx-ghost-card {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 5px;
    opacity: 0;
    pointer-events: none;
    will-change: transform, opacity;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 1px solid #e0e0e0;
}

/* ── Ghost Fan-Out (shuffle on) ──────────────────────── */

@keyframes wpfc-fx-fan-1 {
    0%   { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(1); }
    20%  { opacity: 1; transform: translateX(-45px) translateY(-10px) rotate(-6deg) scale(0.99); }
    50%  { opacity: 0.9; transform: translateX(15px) translateY(-6px) rotate(2deg) scale(0.99); }
    75%  { opacity: 0.6; transform: translateX(-8px) translateY(-3px) rotate(-0.5deg) scale(1); }
    100% { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(1); }
}
@keyframes wpfc-fx-fan-2 {
    0%   { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(0.99); }
    18%  { opacity: 1; transform: translateX(55px) translateY(-22px) rotate(8deg) scale(0.98); }
    45%  { opacity: 0.9; transform: translateX(-20px) translateY(-14px) rotate(-3deg) scale(0.99); }
    70%  { opacity: 0.55; transform: translateX(8px) translateY(-5px) rotate(1deg) scale(0.99); }
    100% { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(0.99); }
}
@keyframes wpfc-fx-fan-3 {
    0%   { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(0.99); }
    15%  { opacity: 0.95; transform: translateX(-18px) translateY(-30px) rotate(-3deg) scale(0.98); }
    40%  { opacity: 0.85; transform: translateX(40px) translateY(-18px) rotate(6deg) scale(0.98); }
    65%  { opacity: 0.5; transform: translateX(-12px) translateY(-8px) rotate(-1.5deg) scale(0.99); }
    100% { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(0.99); }
}
@keyframes wpfc-fx-fan-4 {
    0%   { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(0.98); }
    22%  { opacity: 0.9; transform: translateX(30px) translateY(-35px) rotate(10deg) scale(0.97); }
    50%  { opacity: 0.8; transform: translateX(-50px) translateY(-20px) rotate(-7deg) scale(0.98); }
    75%  { opacity: 0.45; transform: translateX(10px) translateY(-8px) rotate(1.5deg) scale(0.99); }
    100% { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(0.98); }
}

.wpfc-fx-fan-1 { animation: wpfc-fx-fan-1 0.85s ease-in-out forwards; }
.wpfc-fx-fan-2 { animation: wpfc-fx-fan-2 0.85s ease-in-out 0.06s forwards; }
.wpfc-fx-fan-3 { animation: wpfc-fx-fan-3 0.8s ease-in-out 0.03s forwards; }
.wpfc-fx-fan-4 { animation: wpfc-fx-fan-4 0.9s ease-in-out 0.1s forwards; }

/* ── Ghost Rewind (shuffle off) ──────────────────────── */

@keyframes wpfc-fx-rewind-1 {
    0%   { opacity: 0; transform: translateX(-40px) translateY(-12px) rotate(-5deg) scale(0.99); }
    15%  { opacity: 1; transform: translateX(-40px) translateY(-12px) rotate(-5deg) scale(0.99); }
    55%  { opacity: 0.9; transform: translateX(-12px) translateY(-4px) rotate(-1.5deg) scale(1); }
    80%  { opacity: 0.7; transform: translateX(2px) translateY(1px) rotate(0.2deg) scale(1); }
    100% { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(1); }
}
@keyframes wpfc-fx-rewind-2 {
    0%   { opacity: 0; transform: translateX(50px) translateY(-20px) rotate(7deg) scale(0.98); }
    15%  { opacity: 1; transform: translateX(50px) translateY(-20px) rotate(7deg) scale(0.98); }
    55%  { opacity: 0.9; transform: translateX(14px) translateY(-5px) rotate(2deg) scale(0.99); }
    80%  { opacity: 0.65; transform: translateX(-2px) translateY(1px) rotate(-0.2deg) scale(1); }
    100% { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(0.99); }
}
@keyframes wpfc-fx-rewind-3 {
    0%   { opacity: 0; transform: translateX(35px) translateY(-28px) rotate(5deg) scale(0.98); }
    15%  { opacity: 0.95; transform: translateX(35px) translateY(-28px) rotate(5deg) scale(0.98); }
    55%  { opacity: 0.85; transform: translateX(10px) translateY(-8px) rotate(1.2deg) scale(0.99); }
    80%  { opacity: 0.6; transform: translateX(-1px) translateY(0px) rotate(-0.1deg) scale(1); }
    100% { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(0.99); }
}
@keyframes wpfc-fx-rewind-4 {
    0%   { opacity: 0; transform: translateX(-45px) translateY(-32px) rotate(-8deg) scale(0.97); }
    15%  { opacity: 0.9; transform: translateX(-45px) translateY(-32px) rotate(-8deg) scale(0.97); }
    55%  { opacity: 0.8; transform: translateX(-12px) translateY(-9px) rotate(-2deg) scale(0.99); }
    80%  { opacity: 0.5; transform: translateX(1px) translateY(0px) rotate(0.1deg) scale(1); }
    100% { opacity: 0; transform: translateX(0) translateY(0) rotate(0deg) scale(0.98); }
}

.wpfc-fx-rewind-1 { animation: wpfc-fx-rewind-1 0.8s ease-in-out forwards; }
.wpfc-fx-rewind-2 { animation: wpfc-fx-rewind-2 0.8s ease-in-out 0.04s forwards; }
.wpfc-fx-rewind-3 { animation: wpfc-fx-rewind-3 0.75s ease-in-out 0.08s forwards; }
.wpfc-fx-rewind-4 { animation: wpfc-fx-rewind-4 0.85s ease-in-out 0.02s forwards; }

/* ── Switch Flip ──────────────────────────────────────── */

@keyframes wpfc-fx-switch-flip {
    0%   { transform: perspective(800px) rotateY(0deg); }
    50%  { transform: perspective(800px) rotateY(8deg) scale(0.98); }
    100% { transform: perspective(800px) rotateY(0deg) scale(1); }
}

.wpfc-fx-switch-flip {
    animation: wpfc-fx-switch-flip 0.3s ease-in-out !important;
}

/* ── Complete Entrance ────────────────────────────────── */

@keyframes wpfc-fx-complete-entrance {
    0%   { opacity: 0; transform: scale(0.85) translateY(10px); }
    50%  { opacity: 1; transform: scale(1.03) translateY(-2px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.wpfc-fx-complete-entrance {
    animation: wpfc-fx-complete-entrance 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards !important;
}

/* ── Enhanced Hover States ────────────────────────────── */

.wpfc-fx-enhanced .wp-flashcard-nav-btn {
    transition: transform 0.15s ease, color 0.15s ease !important;
}

.wpfc-fx-enhanced .wp-flashcard-nav-btn:hover:not(:disabled) {
    transform: scale(1.15);
}

.wpfc-fx-enhanced .wp-flashcard-nav-btn:active:not(:disabled) {
    transform: scale(0.9);
}

.wpfc-fx-enhanced .wp-flashcard-tool-btn {
    transition: transform 0.15s ease !important;
}

.wpfc-fx-enhanced .wp-flashcard-tool-btn:hover {
    transform: scale(1.1);
}

.wpfc-fx-enhanced .wp-flashcard-tool-btn:active {
    transform: scale(0.9);
}

.wpfc-fx-enhanced .wp-flashcard-star {
    transition: transform 0.15s ease, color 0.15s ease, background-color 0.15s ease !important;
}

.wpfc-fx-enhanced .wp-flashcard-star:hover {
    transform: scale(1.15);
}

/* ── Button Press Animation ───────────────────────────── */

.wpfc-fx-enhanced .wp-flashcard-btn {
    transition: transform 0.12s ease, background 0.15s ease !important;
}

.wpfc-fx-enhanced .wp-flashcard-btn:hover {
    transform: translateY(-1px);
}

.wpfc-fx-enhanced .wp-flashcard-btn:active {
    transform: translateY(1px) scale(0.97);
}

/* ── Confetti Canvas ──────────────────────────────────── */

.wpfc-fx-confetti-canvas {
    pointer-events: none;
    border: 0;
    background: transparent;
}

/* ── Counter Bump (on navigation) ─────────────────────── */

@keyframes wpfc-fx-counter-bump {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.wpfc-fx-enhanced .wp-flashcard-counter {
    transition: transform 0.15s ease;
}

/* ── Respect Reduced Motion ───────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .wpfc-fx-entrance,
    .wpfc-fx-flip-bounce,
    .wpfc-fx-star-pop,
    .wpfc-fx-star-particle,
    .wpfc-fx-poof-particle,
    .wpfc-fx-shuffle-shake,
    .wpfc-fx-unshuffle-settle,
    .wpfc-fx-fan-1, .wpfc-fx-fan-2, .wpfc-fx-fan-3, .wpfc-fx-fan-4,
    .wpfc-fx-rewind-1, .wpfc-fx-rewind-2, .wpfc-fx-rewind-3, .wpfc-fx-rewind-4,
    .wpfc-fx-switch-flip,
    .wpfc-fx-complete-entrance {
        animation: none !important;
    }

    .wpfc-fx-enhanced .wp-flashcard-nav-btn,
    .wpfc-fx-enhanced .wp-flashcard-tool-btn,
    .wpfc-fx-enhanced .wp-flashcard-star,
    .wpfc-fx-enhanced .wp-flashcard-btn {
        transition: none !important;
    }
}

/* ── Text-to-Speech Speaker Button ───────────────────── */

.wpfc-fx-tts-wrap {
    position: absolute;
    bottom: 12px;
    left: 12px;
    z-index: 99;
}

.wpfc-fx-tts-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.06);
    color: #999;
    border: 0;
    outline: 0;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

.wpfc-fx-tts-btn svg {
    width: 16px;
    height: 16px;
    display: block;
}

.wpfc-fx-tts-btn:hover {
    background-color: rgba(0, 0, 0, 0.1);
    color: #666;
    transform: scale(1.1);
}

.wpfc-fx-tts-btn:active {
    transform: scale(0.9);
}

/* Speaking state — pulsing highlight */
.wpfc-fx-tts-btn.is-speaking {
    background-color: #3ccfcf;
    color: #fff;
    animation: wpfc-fx-tts-pulse 1s ease-in-out infinite;
}

@keyframes wpfc-fx-tts-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(60, 207, 207, 0.4); }
    50%      { box-shadow: 0 0 0 6px rgba(60, 207, 207, 0); }
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .wpfc-fx-tts-wrap {
        bottom: 10px;
        left: 10px;
    }

    .wpfc-fx-tts-btn {
        width: 36px;
        height: 36px;
    }

    .wpfc-fx-tts-btn svg {
        width: 18px;
        height: 18px;
    }
}

/* Theme compatibility — reset button styles */
.wp-flashcard-set .wpfc-fx-tts-btn,
.wp-flashcard-set .wpfc-fx-tts-btn:hover,
.wp-flashcard-set .wpfc-fx-tts-btn:focus {
    box-shadow: none;
    outline: none;
    letter-spacing: normal;
    text-transform: none;
    border: 0 !important;
    padding: 0 !important;
}

.wp-flashcard-set .wpfc-fx-tts-btn::after,
.wp-flashcard-set .wpfc-fx-tts-btn::before {
    display: none !important;
    content: none !important;
}


/* ── Voice Picker ────────────────────────────────────── */

.wpfc-fx-voice-wrap {
    position: relative;
    margin-left: 10px;
}

.wpfc-fx-voice-btn {
    cursor: pointer;
}

.wpfc-fx-voice-panel {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.06);
    padding: 14px 16px;
    width: 280px;
    z-index: 1000;
    font-size: 13px;
    color: #333;
    font-weight: normal;
}

.wpfc-fx-voice-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f0f0;
}

.wpfc-fx-voice-panel-title {
    font-weight: 600;
    font-size: 14px;
    color: #222;
}

.wpfc-fx-voice-close {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    color: #999;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    padding: 0;
    transition: background 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.wpfc-fx-voice-close:hover {
    background: #f0f0f0;
    color: #333;
}

.wpfc-fx-voice-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.wpfc-fx-voice-row:last-child {
    margin-bottom: 0;
}

.wpfc-fx-voice-label {
    font-size: 12px;
    font-weight: 600;
    color: #666;
    min-width: 62px;
    flex-shrink: 0;
    margin: 0;
    line-height: normal;
}

.wpfc-fx-voice-select {
    flex: 1;
    min-width: 0;
    height: 30px;
    margin: 0;
    box-sizing: border-box;
    font-size: 12px;
    line-height: normal;
    padding: 4px 26px 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23666' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 10px 6px;
    color: #333;
    cursor: pointer;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

.wpfc-fx-voice-select:focus {
    border-color: #3ccfcf;
    box-shadow: 0 0 0 2px rgba(60, 207, 207, 0.2);
}

.wpfc-fx-voice-preview {
    width: 30px;
    height: 30px;
    min-width: 30px;
    margin: 0;
    box-sizing: border-box;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fafafa;
    color: #666;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    padding: 0;
    line-height: 1;
}

.wpfc-fx-voice-preview:hover {
    background: #3ccfcf;
    color: #fff;
    border-color: #3ccfcf;
}

/* Theme compatibility resets for voice panel */
.wp-flashcard-set .wpfc-fx-voice-panel,
.wp-flashcard-set .wpfc-fx-voice-select,
.wp-flashcard-set .wpfc-fx-voice-preview {
    box-shadow: none;
    letter-spacing: normal;
    text-transform: none;
    text-decoration: none;
}

.wp-flashcard-set .wpfc-fx-voice-panel {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.06);
}

/* Keep theme form styles from breaking row alignment or re-adding
   a second dropdown arrow on top of ours. !important is required here:
   themes commonly style selects with ID-scoped selectors (#top select,
   #main-content select) that outrank any class chain. These classes only
   ever match plugin-owned elements, so this can't leak into the theme. */
.wp-flashcard-set .wpfc-fx-voice-row {
    align-items: center !important;
}

.wp-flashcard-set .wpfc-fx-voice-label,
.wp-flashcard-set .wpfc-fx-voice-select,
.wp-flashcard-set .wpfc-fx-voice-preview {
    margin: 0 !important;
    float: none !important;
    vertical-align: middle !important;
}

.wp-flashcard-set .wpfc-fx-voice-select {
    height: 30px !important;
    box-sizing: border-box !important;
    font-size: 12px !important;
    line-height: normal !important;
    padding: 4px 26px 4px 8px !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    background-color: #fff !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23666' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 8px center !important;
    background-size: 10px 6px !important;
}

.wp-flashcard-set .wpfc-fx-voice-preview {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
    box-sizing: border-box !important;
}

/* The compat reset above wipes box-shadow — restore the focus ring
   (outline is disabled, so this is the keyboard focus indicator). */
.wp-flashcard-set .wpfc-fx-voice-select:focus {
    border-color: #3ccfcf !important;
    box-shadow: 0 0 0 2px rgba(60, 207, 207, 0.2) !important;
}

.wp-flashcard-set .wpfc-fx-voice-preview::after,
.wp-flashcard-set .wpfc-fx-voice-preview::before,
.wp-flashcard-set .wpfc-fx-voice-close::after,
.wp-flashcard-set .wpfc-fx-voice-close::before {
    display: none !important;
    content: none !important;
}

/* Mobile: panel goes full width above the toolbar */
@media (max-width: 768px) {
    .wpfc-fx-voice-panel {
        width: 260px;
        right: -10px;
    }
}

/* Touch devices: iOS Safari auto-zooms the page when a form control
   with font-size < 16px gains focus, so bump the selects to 16px.
   Must come after (and match the importance of) the compat block above
   so it wins the cascade. */
@media (hover: none) and (pointer: coarse) {
    .wpfc-fx-voice-select,
    .wp-flashcard-set .wpfc-fx-voice-select {
        font-size: 16px !important;
        height: 34px !important;
    }

    .wpfc-fx-voice-preview,
    .wp-flashcard-set .wpfc-fx-voice-preview {
        width: 34px !important;
        height: 34px !important;
        min-width: 34px !important;
    }
}
