/* ==========================================================
   REWARD SYSTEM — score rings, reward cards, score companions
   ========================================================== */

/* ── Score ring ──────────────────────────────────────────── */
.score-ring-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.score-ring {
    position: relative;
    width: 120px;
    height: 120px;
}

.score-ring-svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.score-ring-track {
    fill: none;
    stroke: var(--bg-chip-soft, #e8ecf0);
    stroke-width: 10;
}

.score-ring-fill {
    fill: none;
    stroke: var(--score-ring-color, #FFD84D);
    stroke-width: 10;
    stroke-linecap: round;
    stroke-dasharray: 326.73;  /* 2 × π × 52 */
    stroke-dashoffset: calc(326.73 - (326.73 * var(--score-percent, 0)) / 100);
    transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Color by reward tier */
.reward-gold .score-ring-fill    { stroke: #FFD84D; }
.reward-silver .score-ring-fill  { stroke: #B0BEC5; }
.reward-bronze .score-ring-fill  { stroke: #FFAB91; }
.reward-encouragement .score-ring-fill { stroke: #FF6FA5; }

.score-ring-value {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.score-ring-number {
    font-family: "Cooper Black", Georgia, serif;
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--ink);
}

.score-ring-stars {
    display: flex;
    gap: 0.25rem;
    font-size: 1.3rem;
}

.score-star {
    color: var(--bg-chip-soft, #ccc);
    transition: transform 0.3s ease, color 0.3s ease;
}

.score-star.is-earned {
    color: #FFD84D;
    animation: star-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.score-star.is-earned:nth-child(2) { animation-delay: 0.15s; }
.score-star.is-earned:nth-child(3) { animation-delay: 0.3s; }

@keyframes star-pop {
    0%   { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.score-ring-label {
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}


/* ── Score companion (mascot + speech bubble) ────────────── */
.score-companion {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    background: var(--bg-surface, #fff);
    border: 1.5px solid var(--line);
    max-width: 380px;
}

.score-companion-mascot {
    flex-shrink: 0;
}

.score-companion-bubble {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.score-companion-name {
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.score-companion-text {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.45;
    color: var(--ink);
    font-weight: 600;
}

/* Companion tone by band */
.reward-gold .score-companion {
    background: linear-gradient(135deg, rgba(255, 216, 77, 0.16), rgba(255, 255, 255, 0.96));
    border-color: rgba(255, 216, 77, 0.4);
}
.reward-silver .score-companion {
    background: linear-gradient(135deg, rgba(176, 190, 197, 0.12), rgba(255, 255, 255, 0.96));
    border-color: rgba(176, 190, 197, 0.35);
}
.reward-bronze .score-companion {
    background: linear-gradient(135deg, rgba(255, 171, 145, 0.14), rgba(255, 255, 255, 0.96));
    border-color: rgba(255, 171, 145, 0.35);
}
.reward-encouragement .score-companion {
    background: linear-gradient(135deg, rgba(255, 111, 165, 0.10), rgba(255, 255, 255, 0.96));
    border-color: rgba(255, 111, 165, 0.25);
}


/* ── Reward card (collectible badge) ─────────────────────── */
.reward-card {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1.1rem;
    border-radius: 1.1rem;
    background: var(--bg-surface-raised, #fff);
    border: 2px solid var(--line);
    max-width: 380px;
    opacity: 0;
    transform: translateY(12px) scale(0.95);
    animation: reward-reveal 0.6s 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes reward-reveal {
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.reward-card-badge {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
}

.reward-card-icon {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

.reward-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.reward-card-kicker {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.reward-card-title {
    font-size: 1rem;
    font-family: "Cooper Black", Georgia, serif;
    color: var(--ink);
}

.reward-card-mascot-says {
    margin: 0;
    font-size: 0.82rem;
    color: var(--muted);
}

/* Unlocked card shimmers */
.reward-card-unlocked {
    position: relative;
    overflow: hidden;
}

.reward-card-unlocked::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        105deg,
        transparent 40%,
        rgba(255, 255, 255, 0.5) 50%,
        transparent 60%
    );
    animation: reward-shimmer 2.5s 1.4s ease-in-out;
    pointer-events: none;
}

@keyframes reward-shimmer {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Reward tiers */
.reward-card-unlocked.reward-gold {
    border-color: rgba(255, 216, 77, 0.5);
    background: linear-gradient(135deg, rgba(255, 216, 77, 0.10), var(--bg-surface-raised, #fff));
}
.reward-card-unlocked.reward-silver {
    border-color: rgba(176, 190, 197, 0.4);
    background: linear-gradient(135deg, rgba(176, 190, 197, 0.08), var(--bg-surface-raised, #fff));
}
.reward-card-unlocked.reward-bronze {
    border-color: rgba(255, 171, 145, 0.4);
    background: linear-gradient(135deg, rgba(255, 171, 145, 0.10), var(--bg-surface-raised, #fff));
}

.reward-card-encouragement {
    border-color: rgba(255, 111, 165, 0.25);
    background: linear-gradient(135deg, rgba(255, 111, 165, 0.06), var(--bg-surface-raised, #fff));
}


/* ── Result hero layout (mascot + ring + reward) ─────────── */
.result-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
    padding: 1.5rem 0;
}

.result-hero-top {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.result-hero-mascot {
    flex-shrink: 0;
}

.result-hero-score {
    flex-shrink: 0;
}

.result-hero-reward {
    width: 100%;
    display: flex;
    justify-content: center;
}


/* ── Star burst animation for gold scores ────────────────── */
.reward-gold .score-ring::after {
    content: "";
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 216, 77, 0.3) 0%, transparent 70%);
    animation: star-burst 1.5s 0.5s ease-out;
    pointer-events: none;
    opacity: 0;
}

@keyframes star-burst {
    0%   { opacity: 0; transform: scale(0.5); }
    30%  { opacity: 1; transform: scale(1.3); }
    100% { opacity: 0; transform: scale(1.6); }
}


/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 600px) {
    .result-hero-top {
        flex-direction: column;
        gap: 1rem;
    }
    .score-ring {
        width: 100px;
        height: 100px;
    }
    .score-ring-number {
        font-size: 1.3rem;
    }
    .score-companion {
        flex-direction: column;
        text-align: center;
        gap: 0.4rem;
        max-width: 280px;
    }
    .reward-card {
        flex-direction: column;
        text-align: center;
        max-width: 280px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .score-ring-fill { transition: none; }
    .score-star.is-earned { animation: none; }
    .reward-card { animation: none; opacity: 1; transform: none; }
    .reward-card-unlocked::after { animation: none; }
    .reward-gold .score-ring::after { animation: none; }
    .result-title-animated { animation: none; }
    .result-confetti-particle { animation: none; display: none; }
    .result-subtitle { animation: none; opacity: 1; }
}


/* ==========================================================
   RESULT PAGE THEMES — random visual variation per visit
   ========================================================== */

/* ── Themed container ────────────────────────────────────── */
.result-page-themed {
    position: relative;
    overflow: hidden;
}

.result-confetti-canvas {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.result-page-themed > .container {
    position: relative;
    z-index: 1;
}

/* ── Title animation ─────────────────────────────────────── */
.result-title-animated {
    animation: result-title-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes result-title-pop {
    0%   { transform: scale(0.6) translateY(20px); opacity: 0; }
    60%  { transform: scale(1.08) translateY(-4px); opacity: 1; }
    100% { transform: scale(1) translateY(0); opacity: 1; }
}

/* ── Subtitle fade-in ────────────────────────────────────── */
.result-subtitle {
    opacity: 0;
    animation: result-subtitle-in 0.5s 0.4s ease-out forwards;
    font-style: italic;
    color: var(--muted);
    font-size: 1.05rem;
}

@keyframes result-subtitle-in {
    to { opacity: 1; }
}

/* ── Theme emoji badge bounce ────────────────────────────── */
.result-theme-emoji {
    animation: emoji-bounce 0.6s 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes emoji-bounce {
    0%   { transform: scale(0) rotate(-15deg); }
    100% { transform: scale(1) rotate(0deg); }
}


/* ── Confetti particle (injected by JS) ──────────────────── */
.result-confetti-particle {
    position: absolute;
    top: -20px;
    width: var(--p-size, 10px);
    height: var(--p-size, 10px);
    border-radius: var(--p-radius, 50%);
    background: var(--p-color, var(--theme-accent, #FFD84D));
    opacity: 0.85;
    animation: confetti-fall var(--p-duration, 3s) var(--p-delay, 0s) ease-in forwards;
    pointer-events: none;
}

@keyframes confetti-fall {
    0%   { transform: translateY(0) rotate(0deg) scale(1); opacity: 0.9; }
    25%  { transform: translateY(25vh) rotate(120deg) scale(0.95); opacity: 0.8; }
    75%  { transform: translateY(75vh) rotate(300deg) scale(0.7); opacity: 0.5; }
    100% { transform: translateY(105vh) rotate(460deg) scale(0.3); opacity: 0; }
}


/* ── Theme-specific colour accents ───────────────────────── */

/* Space */
[data-result-theme="space"] .hero-badge-sky { background: rgba(123,97,255,0.15); color: #7B61FF; }
[data-result-theme="space"] .score-ring-label { color: #7B61FF; }

/* Jungle */
[data-result-theme="jungle"] .hero-badge-sky { background: rgba(46,204,113,0.15); color: #27ae60; }
[data-result-theme="jungle"] .score-ring-label { color: #27ae60; }

/* Ocean */
[data-result-theme="ocean"] .hero-badge-sky { background: rgba(0,188,212,0.13); color: #0097A7; }
[data-result-theme="ocean"] .score-ring-label { color: #0097A7; }

/* Circus */
[data-result-theme="circus"] .hero-badge-sky { background: rgba(255,107,107,0.15); color: #e74c3c; }
[data-result-theme="circus"] .score-ring-label { color: #e74c3c; }

/* Garden */
[data-result-theme="garden"] .hero-badge-sky { background: rgba(255,179,71,0.15); color: #e67e22; }
[data-result-theme="garden"] .score-ring-label { color: #e67e22; }

/* Candy */
[data-result-theme="candy"] .hero-badge-sky { background: rgba(255,105,180,0.13); color: #d63384; }
[data-result-theme="candy"] .score-ring-label { color: #d63384; }

/* Arctic */
[data-result-theme="arctic"] .hero-badge-sky { background: rgba(129,212,250,0.15); color: #0277bd; }
[data-result-theme="arctic"] .score-ring-label { color: #0277bd; }


/* ── Theme-specific score ring accent override ───────────── */
[data-result-theme="space"]  .score-ring-fill  { stroke: #7B61FF !important; }
[data-result-theme="jungle"] .score-ring-fill  { stroke: #2ECC71 !important; }
[data-result-theme="ocean"]  .score-ring-fill  { stroke: #00BCD4 !important; }
[data-result-theme="circus"] .score-ring-fill  { stroke: #FF6B6B !important; }
[data-result-theme="garden"] .score-ring-fill  { stroke: #FFB347 !important; }
[data-result-theme="candy"]  .score-ring-fill  { stroke: #FF69B4 !important; }
[data-result-theme="arctic"] .score-ring-fill  { stroke: #81D4FA !important; }

/* Keep gold/silver/bronze tiers for score-star colour */
[data-result-theme] .score-star.is-earned { color: var(--theme-accent, #FFD84D); }


/* ── Score-band-specific celebration effects ─────────────── */

/* Gold: pulsing glow behind score ring */
[data-score-band="gold"] .score-ring-wrap::before {
    content: "";
    position: absolute;
    inset: -16px;
    border-radius: 50%;
    background: radial-gradient(circle, color-mix(in srgb, var(--theme-accent) 25%, transparent) 0%, transparent 70%);
    animation: gold-pulse 2s 1s ease-in-out infinite alternate;
    z-index: -1;
}
[data-score-band="gold"] .score-ring-wrap {
    position: relative;
}

@keyframes gold-pulse {
    0%   { transform: scale(1); opacity: 0.4; }
    100% { transform: scale(1.15); opacity: 0.7; }
}

/* Silver: gentle floating sparkles */
[data-score-band="silver"] .result-confetti-canvas::after {
    content: "✦ ✧ ✦";
    position: absolute;
    top: 15%;
    right: 8%;
    font-size: 1.2rem;
    color: var(--theme-accent);
    opacity: 0.4;
    animation: sparkle-float 3s ease-in-out infinite alternate;
}

@keyframes sparkle-float {
    0%   { transform: translateY(0) rotate(0deg); }
    100% { transform: translateY(-12px) rotate(8deg); }
}
