/* Game pieces: level badge, XP bar, streak flame, stars, player HUD, level map, podium, the character (Mascot.razor)
   and its speech bubble (SpeechBubble.razor). Motion: transform and opacity only; base.css stops it for reduced motion. */

/* ---------- Level badge: a hexagon with the level number ---------- */
.level-badge {
    --size: 40px;
    display: inline-grid;
    place-items: center;
    flex: none;
    width: var(--size);
    height: calc(var(--size) * 1.1);
    clip-path: polygon(50% 0, 95% 25%, 95% 75%, 50% 100%, 5% 75%, 5% 25%);
    background: linear-gradient(160deg, #FFD983, var(--accent-edge));
}
.level-badge > span {
    display: grid;
    place-items: center;
    width: calc(100% - 6px);
    height: calc(100% - 6px);
    clip-path: inherit;
    background: linear-gradient(170deg, var(--gold-light), var(--amber) 55%, var(--gold-deep));
    color: var(--navy);
    font-family: var(--font-title);
    font-size: calc(var(--size) * .45);
    line-height: 1;
}
.level-badge-lg { --size: 76px; }

/* ---------- XP bar: fills in when it shows; a light runs over it ---------- */
.xp-bar {
    position: relative;
    display: block;
    height: 10px;
    overflow: hidden;
    border-radius: var(--radius-pill);
    background: var(--xp-track);
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, .25);
}
.xp-bar-lg { height: 16px; }
.xp-fill {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: inherit;
    background: var(--xp-fill);
    transform-origin: 100% 50%;   /* RTL: fills from the right */
    transform: scaleX(var(--p, 0));
    animation: bar-fill 1.1s var(--ease-out) .15s both;
}
.xp-fill::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 30%, rgba(255, 255, 255, .55) 50%, transparent 70%);
    transform: translateX(110%);
    animation: xp-shine 3.2s ease-in-out 1.3s infinite;
}
@keyframes xp-shine { 0%, 55% { transform: translateX(110%); } 100% { transform: translateX(-110%); } }

/* ---------- Streak flame ---------- */
.streak .flame { color: var(--flame); transform-origin: 50% 90%; }
.streak.is-lit .flame { animation: flicker 1.6s ease-in-out infinite; }
.streak.is-waiting .flame { opacity: .65; }
.streak.is-cold .flame { color: var(--text-soft); }
.streak.is-cold .flame .flame-inner { opacity: .35; }
@keyframes flicker {
    0%, 100% { transform: scale(1) rotate(0); }
    30% { transform: scale(1.08, .96) rotate(-3deg); }
    60% { transform: scale(.96, 1.06) rotate(2deg); }
}

/* ---------- Stars (1 to 3, for results) ---------- */
.stars { display: inline-flex; gap: 4px; color: var(--surface-3); }
.stars .icon { width: 32px; height: 32px; }
/* An empty star is an outline, so it reads in both themes. */
.stars .icon:not(.is-on) path { fill: none; stroke: var(--text-soft); stroke-width: 1.6; }
.stars .is-on { color: var(--amber); animation: star-pop .5s var(--ease-spring) both; filter: drop-shadow(0 2px 0 var(--accent-edge)); }
.stars .is-on:nth-child(2) { animation-delay: .15s; }
.stars .is-on:nth-child(3) { animation-delay: .3s; }
@keyframes star-pop { from { opacity: 0; transform: scale(.2) rotate(-40deg); } }

/* ---------- Player HUD (PlayerHud.razor) in the header ---------- */
.hud {
    order: 2;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    padding: 6px;
    border-radius: 18px;
    background: var(--console-2);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
}
.hud-level {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding-inline-end: 6px;
    color: var(--on-console);
    text-decoration: none;
}
.hud-level:hover .level-badge { transform: rotate(-6deg) scale(1.06); }
.hud-level .level-badge { transition: transform .2s var(--ease-spring); }
.hud-xp { flex: 1; min-width: 0; display: grid; gap: 3px; }
.hud-xp-text { display: flex; justify-content: space-between; gap: 6px; font-size: .8rem; line-height: 1.2; white-space: nowrap; }
.hud-xp-name { font-family: var(--font-title); font-size: .95rem; }
.hud-xp-count { min-width: 0; color: var(--on-console-muted); overflow: hidden; text-overflow: ellipsis; }
.hud .xp-bar { background: #0A1220; }
.hud-stat {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    padding: 0 10px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .06);
    color: var(--on-console);
    font-family: var(--font-title);
    font-size: 1.05rem;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
}
.hud-stat b { font-weight: 700; }
a.hud-stat { transition: transform .15s var(--ease-out); }
a.hud-stat:hover { background: rgba(255, 255, 255, .12); }
a.hud-stat:active { transform: scale(.94); }
.hud-points .icon { color: var(--primary); }
.hud-rank .icon { color: var(--amber); }
.hud-unit { display: none; font-size: .8rem; color: var(--on-console-muted); }
.hud-none { font-size: .9rem; color: var(--on-console-muted); }

/* Order inside the header row (layout.css): brand, nav, HUD, actions. The HUD shares the row with the brand. */
.brand { order: 0; }
.top-nav { order: 1; }
.header-actions { order: 3; }

/* Narrow phones: the badge already shows the level, and the XP bar shows the points, so both labels go. */
@media (max-width: 419px) {
    .hud { gap: 4px; padding: 4px; }
    .hud-xp-name, .hud-points { display: none; }
    .hud-stat { padding: 0 8px; }
}
@media (min-width: 420px) {
    .hud-unit { display: inline; }
}
@media (min-width: 900px) {
    .hud { order: 2; flex-basis: auto; flex: 0 1 auto; margin-inline-start: auto; background: transparent; box-shadow: none; padding: 0; }
    .hud-xp { width: 150px; flex: none; }
    .header-actions { margin-inline-start: 0; }
}

/* ---------- Level map: lessons as stops on a winding path ---------- */
.level-map {
    --dot: 52px;
    --row: 80px;
    --shift: 36px;
    list-style: none;
    margin: 0;
    padding: 0;
}
.map-node {
    position: relative;
    height: var(--row);
}
.map-stop {
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--dot);
    color: var(--text);
    text-decoration: none;
}
.map-node:nth-child(4n + 2) { padding-inline-start: var(--shift); }
.map-node:nth-child(4n + 3) { padding-inline-start: calc(var(--shift) * 2); }
.map-node:nth-child(4n) { padding-inline-start: var(--shift); }
/* The path between two stops: a dotted line from this stop's dot to the one before. */
.map-node + .map-node::before {
    content: "";
    position: absolute;
    top: calc(var(--dot) / 2 - var(--row));
    height: calc(var(--row) * 1.08);
    width: 5px;
    border-radius: 3px;
    background: repeating-linear-gradient(to bottom, var(--border-strong) 0 7px, transparent 7px 13px);
    transform-origin: 50% 100%;
    z-index: 0;
}
.map-node:nth-child(4n + 2)::before { inset-inline-start: calc(var(--shift) + var(--dot) / 2 - 2.5px); transform: rotate(24deg); top: calc(var(--dot) / 2 - var(--row) * 1.08); }
.map-node:nth-child(4n + 3)::before { inset-inline-start: calc(var(--shift) * 2 + var(--dot) / 2 - 2.5px); transform: rotate(24deg); top: calc(var(--dot) / 2 - var(--row) * 1.08); }
.map-node:nth-child(4n)::before { inset-inline-start: calc(var(--shift) + var(--dot) / 2 - 2.5px); transform: rotate(-24deg); top: calc(var(--dot) / 2 - var(--row) * 1.08); }
.map-node:nth-child(4n + 1)::before { inset-inline-start: calc(var(--dot) / 2 - 2.5px); transform: rotate(-24deg); top: calc(var(--dot) / 2 - var(--row) * 1.08); }
.map-dot {
    position: relative;
    z-index: 1;
    flex: none;
    display: grid;
    place-items: center;
    width: var(--dot);
    height: var(--dot);
    border-radius: 50%;
    border: 3px solid var(--border-strong);
    background: var(--surface-3);
    color: var(--text-muted);
    box-shadow: 0 4px 0 var(--edge);
    font-size: .95rem;
    transition: transform .2s var(--ease-spring);
}
a.map-stop:hover .map-dot { transform: scale(1.08); }
.map-label {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-width: 0;
    font-size: .95rem;
    line-height: 1.4;
}
.map-label b { display: block; font-family: var(--font-title); font-size: 1.05rem; }
.level-map-steps .map-label { display: block; color: var(--text-muted); font-size: var(--fs-sm); }
.level-map-steps .map-label b { color: var(--text); }
.map-node.is-done .map-dot { background: var(--amber); border-color: var(--accent-edge); color: var(--navy); box-shadow: 0 4px 0 var(--accent-edge); }
.map-node.is-current .map-dot { background: var(--primary); border-color: var(--primary-edge); color: var(--on-primary); box-shadow: var(--glow), 0 4px 0 var(--primary-edge); }
.map-node.is-current .map-dot::after {
    content: "";
    position: absolute;
    inset: -9px;
    border-radius: 50%;
    border: 3px solid var(--primary);
    opacity: 0;
    animation: ring 1.8s var(--ease-out) infinite;
}
.map-node.is-next .map-dot { border-style: dashed; }
.map-node.is-current .map-label { font-weight: 700; }
.map-label .chip { margin-inline-start: 6px; vertical-align: middle; }
@keyframes ring { 0% { opacity: .8; transform: scale(.85); } 100% { opacity: 0; transform: scale(1.25); } }

/* ---------- Podium: first in the middle ---------- */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 8px; height: 180px; }
.podium-step {
    position: relative;
    flex: 1;
    max-width: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    padding: 26px 6px 8px;
    border-radius: 14px 14px 6px 6px;
    background: var(--surface-3);
    border: 2px solid var(--border);
    border-bottom-width: 5px;
    text-align: center;
    transform-origin: 50% 100%;
    animation: podium-rise .7s var(--ease-spring) both;
}
.podium-1 { height: 100%; background: linear-gradient(var(--accent-soft), var(--surface-3)); border-color: var(--accent); animation-delay: .25s; }
.podium-2 { height: 74%; animation-delay: .1s; }
.podium-3 { height: 56%; animation-delay: .4s; }
.medal {
    position: absolute;
    top: -18px;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--silver);
    border: 3px solid var(--surface);
    color: var(--navy);
    font-family: var(--font-title);
    font-size: 1.1rem;
    box-shadow: 0 3px 0 var(--edge);
}
.podium-1 .medal { background: var(--gold); width: 42px; height: 42px; top: -22px; }
.podium-3 .medal { background: var(--bronze); }
.podium-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.podium-points { font-family: var(--font-title); color: var(--accent-text); }
.podium-mini { height: 96px; gap: 6px; }
.podium-mini .podium-step { padding: 0; }
@keyframes podium-rise { from { transform: scaleY(.2); opacity: 0; } }

/* ---------- The character (Mascot.razor) ---------- */
/* The whole svg moves (one layer), the bottom of the hoodie fades out, and only the arms and the eyes move inside. */
.mascot {
    display: block;
    overflow: visible;
    flex: none;
    -webkit-mask-image: linear-gradient(#000 84%, transparent);
    mask-image: linear-gradient(#000 84%, transparent);
    animation: m-float 3.4s ease-in-out infinite alternate;
}
.m-shell { fill: #E8EEF6; stroke: #B4C3D6; stroke-width: 3; }
.m-shine { fill: none; stroke: #FFFFFF; stroke-width: 5; stroke-linecap: round; opacity: .9; }
.m-screen { fill: #0B1626; stroke: #22344F; stroke-width: 2; }
.m-glare { fill: none; stroke: rgba(255, 255, 255, .16); stroke-width: 6; stroke-linecap: round; }
.m-band { fill: none; stroke: #17243A; stroke-width: 8; stroke-linecap: round; }
.m-cup { fill: #17243A; stroke: var(--turquoise); stroke-width: 3.5; }
.m-cup-light { fill: var(--amber); }
.m-antenna { fill: none; stroke: #B4C3D6; stroke-width: 5; stroke-linecap: round; }
.m-light { fill: var(--amber); animation: m-light 2.2s ease-in-out infinite; }
.m-neck { fill: #B4C3D6; }
.m-hoodie { fill: var(--turquoise); }
.m-zip { fill: none; stroke: #128779; stroke-width: 3; }
.m-collar { fill: none; stroke: #128779; stroke-width: 8; stroke-linecap: round; }
.m-strings { fill: none; stroke: var(--amber); stroke-width: 3.5; stroke-linecap: round; }
.m-string-end { fill: var(--amber); }
.m-patch { fill: var(--amber); }
.m-sleeve { fill: none; stroke: #1CA595; stroke-width: 20; stroke-linecap: round; }
.m-hand { fill: #E8EEF6; stroke: #B4C3D6; stroke-width: 3; }
.m-thumb { fill: none; stroke: #B4C3D6; stroke-width: 6; stroke-linecap: round; }
.m-face { fill: #5FF5E0; filter: drop-shadow(0 0 4px rgba(95, 245, 224, .75)); }
.m-line, .m-brow { fill: none; stroke: #5FF5E0; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
.m-brow { stroke-width: 4.5; }
.m-line-thick { stroke-width: 6.5; }
.m-mouth { fill: #5FF5E0; }
.m-sparkle-eye { fill: #0B1626; }
.m-eyes { transform-box: fill-box; transform-origin: 50% 50%; animation: m-blink 4.6s infinite; }
.m-dots circle { animation: m-dot 1.2s ease-in-out infinite; }
.m-dots circle:nth-child(2) { animation-delay: .2s; }
.m-dots circle:nth-child(3) { animation-delay: .4s; }
.m-sparkles path { fill: var(--amber); transform-box: fill-box; transform-origin: 50% 50%; animation: m-twinkle 1.4s ease-in-out infinite; }
.m-sparkles path:nth-child(2) { animation-delay: .45s; }
.m-sparkles path:nth-child(3) { animation-delay: .9s; }
.m-arm { transform-box: view-box; }
.m-arm-end { transform-origin: 150px 176px; }
.m-arm-start { transform-origin: 50px 176px; }
.mascot--wave .m-arm-end { animation: m-wave 1.3s ease-in-out infinite; }
.mascot--celebrate { animation: m-jump .8s ease-in-out infinite; }
.mascot--celebrate .m-arm-end { animation: m-cheer .8s ease-in-out infinite; }
.mascot--celebrate .m-arm-start { animation: m-cheer-start .8s ease-in-out infinite; }
.mascot--surprised { animation: m-pop .5s var(--ease-spring) both; }
.mascot--sad { animation: m-sink 4s ease-in-out infinite alternate; }

@keyframes m-float { from { transform: translateY(0); } to { transform: translateY(-6px); } }
@keyframes m-blink { 0%, 90%, 96%, 100% { transform: scaleY(1); } 93% { transform: scaleY(.1); } }
@keyframes m-light { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes m-dot { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
@keyframes m-twinkle { 0%, 100% { transform: scale(.4); opacity: .2; } 50% { transform: scale(1.15); opacity: 1; } }
@keyframes m-wave { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(14deg); } }
@keyframes m-jump { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-10px); } }
@keyframes m-cheer { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(10deg); } }
@keyframes m-cheer-start { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-10deg); } }
@keyframes m-pop { from { transform: scale(.85); } }
@keyframes m-sink { from { transform: translateY(0); } to { transform: translateY(4px); } }

/* ---------- Speech bubble (SpeechBubble.razor) ---------- */
.bubble {
    position: relative;
    display: inline-block;
    max-width: 300px;
    margin: 0;
    padding: 10px 16px;
    border: 2px solid var(--primary);
    border-radius: 18px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 4px 0 var(--primary-edge);
    font-family: var(--font-title);
    font-size: 1.1rem;
    line-height: 1.45;
    animation: bubble-in .5s var(--ease-spring) .2s both;
}
.bubble::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--surface);
    border: 2px solid var(--primary);
    border-top: 0;
    border-inline-start: 0;
}
.bubble--bottom::after { bottom: -9px; inset-inline-start: calc(50% - 7px); transform: rotate(45deg); }
.bubble--start::after { top: calc(50% - 7px); inset-inline-start: -9px; transform: rotate(135deg); }
.bubble--end::after { top: calc(50% - 7px); inset-inline-end: -9px; transform: rotate(-45deg); }
@keyframes bubble-in { from { opacity: 0; transform: scale(.7) translateY(8px); } }

/* ---------- Little "+3 XP" chip that pops up ---------- */
.pop-chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    background: var(--amber);
    color: var(--navy);
    font-family: var(--font-title);
    font-size: .95rem;
    box-shadow: 0 3px 0 var(--accent-edge);
    animation: pop-up 2.4s var(--ease-out) infinite;
}
@keyframes pop-up {
    0% { opacity: 0; transform: translateY(10px) scale(.8); }
    15%, 70% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-14px) scale(.95); }
}
