/* ==========================================================================
   JLearn Online 2.0 — Student Study Buddy
   --------------------------------------------------------------------------
   A student-only companion for the video lesson and active assessment.
   No chat, no inputs, no AI calls. It only cheers, encourages, and reminds
   the student of the honesty/anti-cheat rules. Drag it anywhere.
   ========================================================================== */

#jlearn-student-pet {
    --jsp-bubble-bg: #ffffff;
    --jsp-bubble-fg: #0f172a;
    --jsp-bubble-border: rgba(15, 23, 42, 0.14);
    position: fixed;
    left: 12px;
    top: 78px;
    bottom: auto;
    z-index: 8500;
    width: 68px;
    height: 78px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
    pointer-events: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

#jlearn-student-pet.is-visible {
    opacity: 0.96;
    visibility: visible;
    transform: translateY(0);
}

#jlearn-student-pet.is-visible.is-interacting,
#jlearn-student-pet.is-visible:hover {
    opacity: 1;
}

#jlearn-student-pet.is-dragging {
    opacity: 1;
}

#jlearn-student-pet .jsp-pet-btn {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 22px;
    background: transparent;
    overflow: visible !important;
    pointer-events: auto;
    cursor: grab;
    touch-action: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

#jlearn-student-pet .jsp-pet-btn:focus-visible {
    outline: 3px solid #818cf8;
    outline-offset: 4px;
}

#jlearn-student-pet.is-dragging .jsp-pet-btn {
    cursor: grabbing;
}

#jlearn-student-pet .jsp-float {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    transform-origin: 50% 92%;
    animation: jspFloat 4.2s ease-in-out infinite;
}

#jlearn-student-pet .jsp-svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
    filter: drop-shadow(0 10px 16px rgba(49, 46, 129, 0.28));
    transform: rotate(var(--jsp-tilt, 0deg));
    transition: transform 0.25s ease-out;
}

#jlearn-student-pet.is-dragging .jsp-svg {
    transform: scale(1.04, 0.96) rotate(var(--jsp-tilt, 0deg));
    transition: none;
}

/* ── Face / mood layers ───────────────────────────────────────────────── */
#jlearn-student-pet .jsp-eye-open {
    animation: jspBlink 5.6s infinite;
    transform-box: fill-box;
    transform-origin: center;
}

#jlearn-student-pet .jsp-eye-happy,
#jlearn-student-pet .jsp-eye-sleep,
#jlearn-student-pet .jsp-eye-heart,
#jlearn-student-pet .jsp-brow,
#jlearn-student-pet .jsp-mouth-o,
#jlearn-student-pet .jsp-mouth-happy,
#jlearn-student-pet .jsp-note,
#jlearn-student-pet .jsp-pencil,
#jlearn-student-pet .jsp-idea,
#jlearn-student-pet .jsp-exclaim,
#jlearn-student-pet .jsp-sparks i,
#jlearn-student-pet .jsp-hearts i {
    opacity: 0;
}

#jlearn-student-pet[data-mood="cheer"] .jsp-eye-open,
#jlearn-student-pet[data-mood="love"] .jsp-eye-open,
#jlearn-student-pet[data-mood="sleepy"] .jsp-eye-open {
    opacity: 0;
}

#jlearn-student-pet[data-mood="cheer"] .jsp-eye-happy,
#jlearn-student-pet[data-mood="love"] .jsp-eye-heart,
#jlearn-student-pet[data-mood="sleepy"] .jsp-eye-sleep {
    opacity: 1;
}

#jlearn-student-pet[data-mood="cheer"] .jsp-mouth-smile,
#jlearn-student-pet[data-mood="love"] .jsp-mouth-smile,
#jlearn-student-pet[data-mood="worried"] .jsp-mouth-smile {
    opacity: 0;
}

#jlearn-student-pet[data-mood="cheer"] .jsp-mouth-happy,
#jlearn-student-pet[data-mood="love"] .jsp-mouth-happy,
#jlearn-student-pet[data-mood="worried"] .jsp-mouth-o {
    opacity: 1;
}

#jlearn-student-pet[data-mood="worried"] .jsp-brow {
    opacity: 1;
}

#jlearn-student-pet[data-mood="worried"] .jsp-eye-open {
    transform: scale(0.86);
}

#jlearn-student-pet[data-mood="cheer"] .jsp-sparks i,
#jlearn-student-pet[data-antic="sparkle"] .jsp-sparks i {
    opacity: 1;
    animation: jspSpark 0.9s ease-out 2;
}

#jlearn-student-pet[data-mood="love"] .jsp-hearts i,
#jlearn-student-pet[data-antic="love"] .jsp-hearts i {
    opacity: 1;
    animation: jspHeart 1.5s ease-out 2;
}

/* ── Tap antics ───────────────────────────────────────────────────────── */
#jlearn-student-pet[data-antic="hop"] .jsp-float { animation: jspHop 0.75s ease-in-out; }
#jlearn-student-pet[data-antic="spin"] .jsp-float { animation: jspSpin 0.9s cubic-bezier(0.5, 0, 0.5, 1); }
#jlearn-student-pet[data-antic="wiggle"] .jsp-float { animation: jspWiggle 0.8s ease-in-out; }
#jlearn-student-pet[data-antic="cheer"] .jsp-float { animation: jspCheer 0.9s ease-in-out; }
#jlearn-student-pet[data-antic="wave"] .jsp-arm-right {
    animation: jspWave 0.6s ease-in-out 3;
    transform-box: fill-box;
    transform-origin: top center;
}
#jlearn-student-pet[data-antic="cheer"] .jsp-arm-left,
#jlearn-student-pet[data-mood="cheer"] .jsp-arm-left {
    animation: jspArmUp 0.7s ease-in-out 2;
    transform-box: fill-box;
    transform-origin: top center;
}
#jlearn-student-pet[data-antic="cheer"] .jsp-arm-right,
#jlearn-student-pet[data-mood="cheer"] .jsp-arm-right {
    animation: jspArmUp 0.7s ease-in-out 2;
    transform-box: fill-box;
    transform-origin: top center;
}
#jlearn-student-pet[data-antic="study"] .jsp-note,
#jlearn-student-pet[data-antic="study"] .jsp-pencil {
    opacity: 1;
    animation: jspPropIn 0.28s ease-out both;
}
#jlearn-student-pet[data-antic="study"] .jsp-arm-left {
    animation: jspHold 2.4s ease-in-out infinite;
    transform-box: fill-box;
    transform-origin: top center;
}
#jlearn-student-pet[data-antic="idea"] .jsp-idea {
    opacity: 1;
    animation: jspPropIn 0.3s ease-out both, jspIdeaPulse 1.1s ease-in-out infinite;
}
#jlearn-student-pet[data-antic="idea"] .jsp-exclaim {
    opacity: 1;
    animation: jspExclaim 0.9s ease-out;
}

/* ── Props ────────────────────────────────────────────────────────────── */
#jlearn-student-pet .jsp-sparks,
#jlearn-student-pet .jsp-hearts {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
}

#jlearn-student-pet .jsp-sparks i,
#jlearn-student-pet .jsp-hearts i {
    position: absolute;
    font-style: normal;
    font-size: 13px;
    line-height: 1;
    color: #fbbf24;
}

#jlearn-student-pet .jsp-sparks i:nth-child(1) { left: 8%; top: 26%; }
#jlearn-student-pet .jsp-sparks i:nth-child(2) { right: 6%; top: 18%; animation-delay: 0.18s; }
#jlearn-student-pet .jsp-sparks i:nth-child(3) { right: 12%; bottom: 22%; animation-delay: 0.36s; }

#jlearn-student-pet .jsp-hearts i {
    color: #f43f5e;
    font-size: 12px;
}

#jlearn-student-pet .jsp-hearts i:nth-child(1) { left: 6%; top: 30%; }
#jlearn-student-pet .jsp-hearts i:nth-child(2) { right: 8%; top: 22%; animation-delay: 0.2s; }
#jlearn-student-pet .jsp-hearts i:nth-child(3) { right: 18%; top: 10%; animation-delay: 0.4s; }

#jlearn-student-pet .jsp-note {
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 38px;
    height: 26px;
    transform: translateX(-50%) rotate(-4deg);
    border-radius: 4px;
    background: #fefce8;
    border: 1.5px solid #c7d2fe;
    box-shadow: 0 4px 10px rgba(15, 23, 42, 0.16);
    z-index: 4;
}

#jlearn-student-pet .jsp-note i {
    position: absolute;
    left: 6px;
    right: 6px;
    height: 1.5px;
    border-radius: 2px;
    background: #cbd5e1;
}

#jlearn-student-pet .jsp-note i:nth-child(1) { top: 7px; }
#jlearn-student-pet .jsp-note i:nth-child(2) { top: 12px; }
#jlearn-student-pet .jsp-note i:nth-child(3) { top: 17px; right: 14px; }

#jlearn-student-pet .jsp-pencil {
    position: absolute;
    right: 13px;
    bottom: 8px;
    width: 4px;
    height: 21px;
    border-radius: 2px;
    background: linear-gradient(#f59e0b 0 72%, #fde68a 72% 84%, #1f2937 84%);
    transform: rotate(28deg);
    z-index: 5;
}

#jlearn-student-pet .jsp-idea {
    position: absolute;
    top: 8%;
    right: 6%;
    width: 12px;
    height: 14px;
    border-radius: 50% 50% 42% 42%;
    background: #fde047;
    box-shadow: 0 0 10px rgba(253, 224, 71, 0.9);
    z-index: 5;
}

#jlearn-student-pet .jsp-idea::after {
    content: '';
    position: absolute;
    left: 34%;
    bottom: -5px;
    width: 34%;
    height: 5px;
    border-radius: 2px;
    background: #a16207;
}

#jlearn-student-pet .jsp-exclaim {
    position: absolute;
    top: -2px;
    right: 0;
    font: 900 18px/1 'Inter', system-ui, sans-serif;
    color: #6366f1;
    text-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
    z-index: 5;
}

/* ── Speech bubble ────────────────────────────────────────────────────── */
#jlearn-student-pet .jsp-bubble {
    --jsp-bubble-shift: 0px;
    position: absolute;
    left: 50%;
    bottom: calc(100% + 9px);
    width: max-content;
    max-width: min(258px, 70vw);
    padding: 9px 12px;
    border-radius: 14px;
    border: 1px solid var(--jsp-bubble-border);
    background: var(--jsp-bubble-bg);
    color: var(--jsp-bubble-fg);
    font-size: 12.5px;
    line-height: 1.42;
    font-weight: 650;
    text-align: left;
    white-space: normal;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
    opacity: 0;
    visibility: hidden;
    transform: translateX(calc(-50% + var(--jsp-bubble-shift))) translateY(4px) scale(0.97);
    transform-origin: 50% 100%;
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
    pointer-events: none;
    z-index: 6;
}

#jlearn-student-pet .jsp-bubble::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -6px;
    width: 11px;
    height: 11px;
    margin-left: -5.5px;
    transform: rotate(45deg);
    background: var(--jsp-bubble-bg);
    border-right: 1px solid var(--jsp-bubble-border);
    border-bottom: 1px solid var(--jsp-bubble-border);
}

#jlearn-student-pet .jsp-bubble.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(calc(-50% + var(--jsp-bubble-shift))) translateY(0) scale(1);
}

#jlearn-student-pet .jsp-bubble.is-below {
    bottom: auto;
    top: calc(100% + 9px);
    transform-origin: 50% 0;
}

#jlearn-student-pet .jsp-bubble.is-below::after {
    top: -6px;
    bottom: auto;
    border: 0;
    border-left: 1px solid var(--jsp-bubble-border);
    border-top: 1px solid var(--jsp-bubble-border);
}

[data-theme="dark"] #jlearn-student-pet {
    --jsp-bubble-bg: #111a2e;
    --jsp-bubble-fg: #e7ecf7;
    --jsp-bubble-border: rgba(148, 163, 184, 0.34);
}

[data-theme="dark"] #jlearn-student-pet .jsp-note {
    background: #e2e8f0;
    border-color: #818cf8;
}

[data-theme="dark"] #jlearn-student-pet .jsp-note i {
    background: #94a3b8;
}

/* ── Focus stays on the lesson while overlays are open ────────────────── */
body:has(.modal.active) #jlearn-student-pet,
body:has(.modal-overlay.active) #jlearn-student-pet,
body:has(.pwa-modal-overlay.active) #jlearn-student-pet,
body:has(.asg-overlay.is-open) #jlearn-student-pet,
body.pseudo-fullscreen-active #jlearn-student-pet {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transition: none !important;
}

/* ── Phones and tablets ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
    #jlearn-student-pet {
        width: 62px;
        height: 72px;
    }
    #jlearn-student-pet .jsp-bubble {
        max-width: min(240px, 66vw);
    }
}

@media (max-width: 768px) {
    #jlearn-student-pet {
        width: 58px;
        height: 67px;
    }
    #jlearn-student-pet .jsp-bubble {
        max-width: min(224px, 68vw);
        font-size: 12px;
        padding: 8px 11px;
    }
}

@media (max-width: 400px) {
    #jlearn-student-pet {
        width: 54px;
        height: 62px;
    }
    #jlearn-student-pet .jsp-bubble {
        max-width: 70vw;
        font-size: 11.5px;
    }
}

/* ── Reduced motion ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    #jlearn-student-pet,
    #jlearn-student-pet *,
    #jlearn-student-pet .jsp-bubble {
        animation: none !important;
        transition: none !important;
    }
}

/* ── Keyframes ────────────────────────────────────────────────────────── */
@keyframes jspFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

@keyframes jspBlink {
    0%, 92%, 100% { transform: scaleY(1); }
    95% { transform: scaleY(0.12); }
}

@keyframes jspHop {
    0%, 100% { transform: translateY(0); }
    35% { transform: translateY(-16px); }
    65% { transform: translateY(0); }
    82% { transform: translateY(-7px); }
}

@keyframes jspSpin {
    from { transform: rotate(0); }
    to { transform: rotate(360deg); }
}

@keyframes jspWiggle {
    0%, 100% { transform: rotate(0); }
    25% { transform: rotate(-9deg); }
    55% { transform: rotate(8deg); }
    80% { transform: rotate(-4deg); }
}

@keyframes jspCheer {
    0%, 100% { transform: translateY(0) scale(1); }
    30% { transform: translateY(-14px) scale(1.04); }
    55% { transform: translateY(0) scale(0.98); }
    75% { transform: translateY(-6px) scale(1.02); }
}

@keyframes jspWave {
    0%, 100% { transform: rotate(0); }
    50% { transform: rotate(-34deg); }
}

@keyframes jspArmUp {
    0%, 100% { transform: rotate(0); }
    50% { transform: rotate(-48deg); }
}

@keyframes jspHold {
    0%, 100% { transform: rotate(-12deg); }
    50% { transform: rotate(-22deg); }
}

@keyframes jspSpark {
    0% { opacity: 0; transform: translateY(4px) scale(0.7); }
    30% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-12px) scale(1.15); }
}

@keyframes jspHeart {
    0% { opacity: 0; transform: translateY(4px) scale(0.7); }
    25% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-20px) scale(1.05); }
}

@keyframes jspPropIn {
    from { opacity: 0; transform: translateY(4px) scale(0.85); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes jspIdeaPulse {
    0%, 100% { box-shadow: 0 0 8px rgba(253, 224, 71, 0.7); }
    50% { box-shadow: 0 0 16px rgba(253, 224, 71, 1); }
}

@keyframes jspExclaim {
    0% { opacity: 0; transform: translateY(6px) scale(0.7); }
    35% { opacity: 1; transform: translateY(-4px) scale(1.15); }
    100% { opacity: 0; transform: translateY(-10px) scale(1); }
}
