/* Student answer reactions, reactive avatar motion and session recap. */

.hm-answer-reaction[hidden],
.hm-session-recap[hidden],
.hm-recap-goal[hidden],
.hm-recap-reward[hidden],
.hm-recap-skip[hidden] {
    display: none !important;
}

.hm-answer-reaction {
    --hm-reaction-accent: #f5a623;
    --hm-reaction-deep: #8a4d00;
    position: fixed;
    top: max(18px, env(safe-area-inset-top));
    right: auto;
    left: max(14px, calc((100vw - 1180px) / 2));
    z-index: 1200;
    display: grid;
    grid-template-columns: 76px minmax(0, 1fr);
    align-items: center;
    width: min(286px, calc(100vw - 28px));
    min-height: 104px;
    padding: 10px 14px 10px 8px;
    overflow: hidden;
    pointer-events: none;
    color: #2f2418;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.98), rgba(255, 248, 226, 0.98));
    border: 2px solid var(--hm-reaction-accent);
    border-color: color-mix(in srgb, var(--hm-reaction-accent) 60%, white);
    border-radius: 22px;
    box-shadow: 0 18px 45px rgba(76, 48, 9, 0.2), 0 4px 12px rgba(76, 48, 9, 0.12);
    opacity: 0;
    transform: translate3d(24px, -4px, 0) scale(0.94);
    transition: opacity 180ms ease, transform 220ms cubic-bezier(0.2, 0.9, 0.25, 1.15);
}

.hm-answer-reaction.is-visible {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
}

.hm-answer-reaction.is-correct,
.hm-answer-reaction.is-knew {
    --hm-reaction-accent: #39b873;
    --hm-reaction-deep: #12653a;
}

.hm-answer-reaction.is-partial {
    --hm-reaction-accent: #f2b632;
    --hm-reaction-deep: #795008;
}

.hm-answer-reaction.is-incorrect,
.hm-answer-reaction.is-learning {
    --hm-reaction-accent: #6f8edb;
    --hm-reaction-deep: #304f9d;
}

.hm-answer-reaction::after {
    content: '';
    position: absolute;
    inset: auto -28px -38px auto;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--hm-reaction-accent) 18%, transparent);
}

.hm-answer-reaction__avatar-shell {
    position: relative;
    width: 72px;
    height: 92px;
    z-index: 2;
    filter: drop-shadow(0 8px 7px rgba(46, 36, 24, 0.2));
    transform-origin: 50% 90%;
}

.hm-answer-reaction.is-correct.is-visible .hm-answer-reaction__avatar-shell,
.hm-answer-reaction.is-knew.is-visible .hm-answer-reaction__avatar-shell {
    animation: hm-avatar-celebrate 760ms cubic-bezier(0.2, 0.85, 0.25, 1.2) both;
}

.hm-answer-reaction.is-partial.is-visible .hm-answer-reaction__avatar-shell {
    animation: hm-avatar-think 900ms ease-in-out both;
}

.hm-answer-reaction.is-incorrect.is-visible .hm-answer-reaction__avatar-shell,
.hm-answer-reaction.is-learning.is-visible .hm-answer-reaction__avatar-shell {
    animation: hm-avatar-encourage 880ms ease-in-out both;
}

.hm-delight-avatar-preview {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.hm-delight-avatar-preview .avatar-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: bottom center;
    pointer-events: none;
}

.hm-delight-avatar-preview .hm-delight-avatar-fallback {
    width: 78%;
    height: 78%;
    margin: 12% 11%;
    object-fit: contain;
}

.hm-answer-reaction.is-correct.is-visible .hm-delight-avatar-preview .pet,
.hm-answer-reaction.is-knew.is-visible .hm-delight-avatar-preview .pet {
    animation: hm-pet-hop 620ms 100ms ease-out both;
}

.hm-answer-reaction.is-partial.is-visible .hm-delight-avatar-preview :is(.head, .expression, .glasses, .hair, .hat) {
    transform-origin: 50% 35%;
    animation: hm-head-think 900ms ease-in-out both;
}

.hm-answer-reaction__copy {
    position: relative;
    z-index: 2;
    min-width: 0;
    padding-left: 6px;
}

.hm-answer-reaction__kicker {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 2px;
    color: var(--hm-reaction-deep);
    font-size: 0.69rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.hm-answer-reaction__title {
    display: block;
    margin-bottom: 2px;
    color: #2f2418;
    font-size: 1.04rem;
    line-height: 1.15;
}

.hm-answer-reaction__detail {
    display: block;
    color: #665746;
    font-size: 0.78rem;
    line-height: 1.28;
}

.hm-feedback-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 208px;
    padding: 8px 10px;
    color: #3f3428;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(104, 80, 42, 0.2);
    border-radius: 14px;
    box-shadow: 0 5px 14px rgba(70, 49, 18, 0.1);
    cursor: pointer;
    user-select: none;
}

.hm-feedback-toggle__label,
.hm-feedback-toggle__control {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.hm-feedback-toggle__label {
    font-size: 0.78rem;
    font-weight: 750;
}

.hm-feedback-toggle__label i {
    color: #bd7b00;
}

.hm-feedback-toggle__control {
    position: relative;
}

.hm-feedback-toggle__control input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.hm-feedback-toggle__track {
    position: relative;
    width: 38px;
    height: 22px;
    background: #87909b;
    border-radius: 999px;
    transition: background 160ms ease;
}

.hm-feedback-toggle__track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.24);
    transition: transform 160ms ease;
}

.hm-feedback-toggle__control input:checked + .hm-feedback-toggle__track {
    background: #2d9e63;
}

.hm-feedback-toggle__control input:checked + .hm-feedback-toggle__track::after {
    transform: translateX(16px);
}

.hm-feedback-toggle__control input:focus-visible + .hm-feedback-toggle__track {
    outline: 3px solid rgba(13, 110, 253, 0.35);
    outline-offset: 2px;
}

.hm-feedback-toggle__state {
    min-width: 20px;
    color: #4c433a;
    font-size: 0.72rem;
}

.hm-delight-particles {
    position: absolute;
    inset: 0;
    z-index: 3;
    overflow: hidden;
    pointer-events: none;
}

.hm-delight-particle {
    position: absolute;
    top: 48%;
    left: 36px;
    width: 7px;
    height: 7px;
    border-radius: 2px;
    background: var(--hm-reaction-accent);
    opacity: 0;
}

.hm-answer-reaction:is(.is-correct, .is-knew).is-visible .hm-delight-particle {
    animation: hm-particle-pop 720ms ease-out both;
}

.hm-delight-particle:nth-child(1) { --hm-particle-x: -32px; --hm-particle-y: -40px; animation-delay: 40ms !important; }
.hm-delight-particle:nth-child(2) { --hm-particle-x: 8px; --hm-particle-y: -52px; animation-delay: 90ms !important; }
.hm-delight-particle:nth-child(3) { --hm-particle-x: 38px; --hm-particle-y: -32px; animation-delay: 20ms !important; }
.hm-delight-particle:nth-child(4) { --hm-particle-x: -40px; --hm-particle-y: 12px; animation-delay: 120ms !important; }
.hm-delight-particle:nth-child(5) { --hm-particle-x: 44px; --hm-particle-y: 14px; animation-delay: 70ms !important; }
.hm-delight-particle:nth-child(6) { --hm-particle-x: 4px; --hm-particle-y: 42px; animation-delay: 130ms !important; }

.hm-completion-card {
    overflow: hidden;
    border: 0;
    border-radius: 24px;
    box-shadow: 0 24px 60px rgba(57, 39, 10, 0.17);
}

.hm-session-recap {
    position: relative;
    margin: -1rem -1rem 1.35rem;
    padding: 1.2rem 1.2rem 1.35rem;
    overflow: hidden;
    color: #30210d;
    background:
        radial-gradient(circle at 14% 18%, rgba(255, 255, 255, 0.96) 0 3%, transparent 20%),
        linear-gradient(145deg, #fff9e8 0%, #ffe8a5 52%, #ffd36a 100%);
    border-bottom: 1px solid rgba(139, 91, 7, 0.18);
}

.hm-session-recap::before,
.hm-session-recap::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
}

.hm-session-recap::before {
    width: 180px;
    height: 180px;
    top: -100px;
    right: -42px;
}

.hm-session-recap::after {
    width: 120px;
    height: 120px;
    bottom: -78px;
    left: -38px;
}

.hm-recap-skip {
    position: absolute;
    top: 10px;
    right: 12px;
    z-index: 5;
    padding: 4px 10px;
    color: #70511c;
    font-size: 0.72rem;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(112, 81, 28, 0.24);
    border-radius: 999px;
}

.hm-recap-skip:hover,
.hm-recap-skip:focus-visible {
    color: #3b290b;
    background: white;
}

.hm-recap-hero {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: 108px minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    min-height: 128px;
    padding-right: 68px;
}

.hm-recap-avatar-shell {
    position: relative;
    width: 104px;
    height: 132px;
    filter: drop-shadow(0 12px 10px rgba(92, 60, 5, 0.2));
    transform-origin: 50% 90%;
}

.hm-session-recap.is-animating .hm-recap-avatar-shell {
    animation: hm-recap-avatar-arrive 1.05s cubic-bezier(0.18, 0.85, 0.25, 1.2) both;
}

.hm-session-recap[data-celebration="true"].is-animating .hm-recap-avatar-shell {
    animation: hm-recap-avatar-celebrate 1.25s cubic-bezier(0.18, 0.85, 0.25, 1.2) both;
}

.hm-session-recap.is-animating .hm-recap-avatar-shell .pet {
    animation: hm-pet-hop 700ms 500ms ease-out both;
}

.hm-recap-copy {
    text-align: left;
}

.hm-recap-kicker {
    display: block;
    margin-bottom: 7px;
    color: #765214;
    font-size: 0.7rem;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.hm-recap-copy strong {
    display: block;
    color: #38270c;
    font-size: clamp(1.3rem, 4vw, 1.9rem);
    line-height: 1.05;
}

.hm-recap-copy p {
    margin: 7px 0 0;
    color: #6d501e;
    font-size: 0.86rem;
}

.hm-recap-stats {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 5px;
}

.hm-recap-stat {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 72px;
    padding: 9px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(117, 79, 14, 0.13);
    border-radius: 14px;
    box-shadow: 0 6px 16px rgba(99, 65, 8, 0.08);
}

.hm-recap-stat__value {
    color: #49310b;
    font-size: 1.18rem;
    line-height: 1.1;
}

.hm-recap-stat__label {
    margin-top: 4px;
    color: #765c31;
    font-size: 0.68rem;
    line-height: 1.2;
}

.hm-recap-goal,
.hm-recap-reward {
    position: relative;
    z-index: 2;
    margin-top: 10px;
    padding: 10px 12px;
    text-align: left;
    background: rgba(68, 45, 7, 0.86);
    border-radius: 14px;
    box-shadow: 0 8px 20px rgba(76, 50, 7, 0.14);
}

.hm-recap-goal__copy {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 7px;
    color: white;
    font-size: 0.76rem;
}

.hm-recap-goal__copy span {
    color: #ffefbd;
}

.hm-recap-goal__track {
    height: 10px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.22);
    border-radius: 999px;
}

.hm-recap-goal__fill {
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, #ffcf4a, #fff1a4);
    border-radius: inherit;
    box-shadow: 0 0 14px rgba(255, 225, 117, 0.65);
    transition: width 1.35s 1.25s cubic-bezier(0.2, 0.8, 0.25, 1);
}

.hm-recap-reward {
    color: white;
    background: linear-gradient(135deg, #4b378d, #7454c5);
}

.hm-recap-reward > strong {
    display: block;
    margin-bottom: 7px;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.hm-recap-reward-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.hm-recap-reward-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 9px;
    color: #3f2e07;
    font-size: 0.74rem;
    font-weight: 800;
    background: #fff3bd;
    border-radius: 999px;
}

.hm-session-recap.is-animating .hm-recap-kicker,
.hm-session-recap.is-animating .hm-recap-copy strong,
.hm-session-recap.is-animating .hm-recap-copy p,
.hm-session-recap.is-animating .hm-recap-stat,
.hm-session-recap.is-animating .hm-recap-goal,
.hm-session-recap.is-animating .hm-recap-reward {
    opacity: 0;
    animation: hm-recap-rise 520ms ease-out forwards;
}

.hm-session-recap.is-animating .hm-recap-kicker { animation-delay: 240ms; }
.hm-session-recap.is-animating .hm-recap-copy strong { animation-delay: 380ms; }
.hm-session-recap.is-animating .hm-recap-copy p { animation-delay: 520ms; }
.hm-session-recap.is-animating .hm-recap-stat:nth-child(1) { animation-delay: 700ms; }
.hm-session-recap.is-animating .hm-recap-stat:nth-child(2) { animation-delay: 850ms; }
.hm-session-recap.is-animating .hm-recap-stat:nth-child(3) { animation-delay: 1000ms; }
.hm-session-recap.is-animating .hm-recap-goal { animation-delay: 1160ms; }
.hm-session-recap.is-animating .hm-recap-reward { animation-delay: 1450ms; }

.hm-session-recap.is-complete :is(.hm-recap-kicker, .hm-recap-copy strong, .hm-recap-copy p, .hm-recap-stat, .hm-recap-goal, .hm-recap-reward) {
    opacity: 1;
}

@keyframes hm-avatar-celebrate {
    0% { transform: translateY(8px) scale(0.92); }
    36% { transform: translateY(-12px) scale(1.06, 0.97) rotate(-3deg); }
    62% { transform: translateY(2px) scale(0.98, 1.04) rotate(2deg); }
    100% { transform: translateY(0) scale(1) rotate(0); }
}

@keyframes hm-avatar-think {
    0%, 100% { transform: rotate(0) translateY(0); }
    38% { transform: rotate(-4deg) translateY(1px); }
    68% { transform: rotate(2deg) translateY(0); }
}

@keyframes hm-avatar-encourage {
    0%, 100% { transform: translateX(0) rotate(0); }
    30% { transform: translateX(-3px) rotate(-2deg); }
    58% { transform: translateX(3px) rotate(2deg); }
    78% { transform: translateX(-1px) rotate(-1deg); }
}

@keyframes hm-head-think {
    0%, 100% { transform: rotate(0); }
    45%, 70% { transform: rotate(-3deg); }
}

@keyframes hm-pet-hop {
    0%, 100% { transform: translateY(0) rotate(0); }
    45% { transform: translateY(-7px) rotate(3deg); }
    70% { transform: translateY(1px) rotate(-2deg); }
}

@keyframes hm-particle-pop {
    0% { opacity: 0; transform: translate(0, 0) rotate(0) scale(0.4); }
    25% { opacity: 1; }
    100% { opacity: 0; transform: translate(var(--hm-particle-x), var(--hm-particle-y)) rotate(150deg) scale(1); }
}

@keyframes hm-recap-avatar-arrive {
    0% { opacity: 0; transform: translate(-18px, 14px) rotate(-7deg) scale(0.78); }
    62% { opacity: 1; transform: translate(3px, -4px) rotate(2deg) scale(1.04); }
    100% { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); }
}

@keyframes hm-recap-avatar-celebrate {
    0% { opacity: 0; transform: translate(-18px, 16px) scale(0.78); }
    42% { opacity: 1; transform: translate(2px, -9px) rotate(-3deg) scale(1.06); }
    66% { transform: translate(0, 2px) rotate(2deg) scale(0.98, 1.04); }
    100% { opacity: 1; transform: translate(0, 0) rotate(0) scale(1); }
}

@keyframes hm-recap-rise {
    from { opacity: 0; transform: translateY(9px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 700px) {
    .hm-feedback-toggle {
        width: 100%;
        min-width: 0;
    }

    .hm-answer-reaction {
        top: auto;
        right: auto;
        bottom: max(12px, env(safe-area-inset-bottom));
        left: 8px;
        grid-template-columns: 62px minmax(0, 1fr);
        width: min(248px, calc(100vw - 16px));
        min-height: 88px;
        padding: 8px 11px 8px 6px;
        border-radius: 18px;
    }

    .hm-answer-reaction__avatar-shell {
        width: 60px;
        height: 76px;
    }

    .hm-answer-reaction__detail {
        font-size: 0.72rem;
    }

    .hm-session-recap {
        margin: -1rem -1rem 1.1rem;
        padding: 1rem;
    }

    .hm-recap-hero {
        grid-template-columns: 82px minmax(0, 1fr);
        gap: 9px;
        min-height: 110px;
        padding-right: 0;
    }

    .hm-recap-skip {
        position: relative;
        top: auto;
        right: auto;
        display: block;
        width: max-content;
        margin: 0 0 2px auto;
    }

    .hm-recap-avatar-shell {
        width: 80px;
        height: 104px;
    }

    .hm-recap-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .hm-recap-stat:last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }

    .hm-recap-goal__copy {
        flex-direction: column;
        gap: 2px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .hm-answer-reaction,
    .hm-answer-reaction *,
    .hm-session-recap,
    .hm-session-recap * {
        scroll-behavior: auto !important;
        animation: none !important;
        transition-duration: 0.01ms !important;
        transition-delay: 0ms !important;
    }

    .hm-answer-reaction.is-visible,
    .hm-session-recap :is(.hm-recap-kicker, .hm-recap-copy strong, .hm-recap-copy p, .hm-recap-stat, .hm-recap-goal, .hm-recap-reward) {
        opacity: 1;
        transform: none;
    }
}
