/* =====================================================================
   motion.css — shared motion + UI-polish foundation (loaded once in
   base.html). Everything here is OPT-IN via utility classes / data-attrs,
   plus a few gentle global enhancements (card hover-lift, nav underline).

   Intensity is controlled by `body[data-motion]`:
     - "refined" (default)  → quick, understated motion. Admin/back-office.
     - "playful"            → bigger, springier motion. Learning/games/public.

   ALL motion is disabled when the user prefers reduced motion.
   ===================================================================== */

:root {
    /* Motion tokens — reused everywhere so timing stays consistent. */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --dur-fast: 0.16s;
    --dur-base: 0.28s;
    --dur-slow: 0.5s;
    --lift-shadow: 0 18px 40px rgba(34, 42, 70, 0.16);
}

/* =====================================================================
   Page entrance — content fades/slides up once on load.
   ===================================================================== */
/* Opacity-only on purpose: a lingering transform on .site-main would make it
   a containing block for position:fixed, mispositioning modals (game modal,
   evaluation modal) to the bottom of the page instead of the viewport. */
@keyframes lm-page-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.site-main {
    animation: lm-page-in var(--dur-slow) var(--ease-out) both;
}

body[data-motion="playful"] .site-main {
    animation-duration: 0.6s;
}

/* =====================================================================
   Scroll reveal — elements with .reveal start hidden and animate in when
   they enter the viewport (ui.js adds .is-visible via IntersectionObserver).
   Stagger children with .reveal-stagger on a parent.
   ===================================================================== */
.reveal {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity var(--dur-slow) var(--ease-out),
                transform var(--dur-slow) var(--ease-out);
    /* No `will-change: transform` here: it establishes a containing block for
       position:fixed descendants (even at transform:none), which would anchor
       modals inside a revealed section to the section instead of the viewport. */
}

.reveal.is-visible {
    opacity: 1;
    transform: none;
}

body[data-motion="playful"] .reveal {
    transform: translateY(26px) scale(0.98);
    transition-timing-function: var(--ease-spring);
}

/* Stagger: ui.js sets --reveal-i on each child; delay scales with index. */
.reveal-stagger > .reveal {
    transition-delay: calc(var(--reveal-i, 0) * 70ms);
}

/* =====================================================================
   Hover lift — utility + gentle global card enhancement.
   ===================================================================== */
.hover-lift,
.card {
    transition: transform var(--dur-base) var(--ease-out),
                box-shadow var(--dur-base) var(--ease-out);
}

@media (hover: hover) {
    .hover-lift:hover {
        transform: translateY(-4px);
        box-shadow: var(--lift-shadow);
    }

    /* Cards lift subtly by default; playful pages lift a touch more.
       `.is-interactive` works standalone for bespoke cards without `.card`. */
    body[data-motion="refined"] .is-interactive:hover,
    body[data-motion="refined"] a.card:hover {
        transform: translateY(-3px);
        box-shadow: var(--lift-shadow);
    }

    body[data-motion="playful"] .is-interactive:hover,
    body[data-motion="playful"] a.card:hover {
        transform: translateY(-6px) scale(1.012);
        box-shadow: var(--lift-shadow);
    }
}

/* Press feedback for clickable things. */
@media (hover: hover) {
    .press:active,
    button:active,
    .button-primary:active,
    .button-secondary:active {
        transform: translateY(1px) scale(0.985);
    }
}

/* =====================================================================
   Active nav link — the nav links are pill-shaped (layout.css), so the
   current page reuses the existing white-pill hover treatment rather than
   an underline. Scoped to direct children so dropdown items are untouched.
   ===================================================================== */
.nav-links > a.is-active {
    background: #ffffff;
    color: var(--primary-dark);
    box-shadow: 0 6px 14px rgba(34, 42, 70, 0.08);
}

/* =====================================================================
   Breadcrumbs (partials/breadcrumbs.html).
   ===================================================================== */
.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 2px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
}

.breadcrumb-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 8px;
    color: var(--muted);
    transition: color var(--dur-fast) var(--ease-out),
                background var(--dur-fast) var(--ease-out);
    white-space: nowrap;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (hover: hover) {
    a.breadcrumb-item:hover {
        color: var(--primary-dark);
        background: var(--accent);
    }
}

.breadcrumb-item.is-current {
    color: var(--text);
    font-weight: 800;
    cursor: default;
}

.breadcrumb-sep {
    color: var(--border);
    font-size: 0.9rem;
    user-select: none;
}

.breadcrumbs-bar {
    padding-top: 16px;
}

/* =====================================================================
   CSS tooltips — add data-tooltip="..." to any element. Optional
   data-tooltip-pos="bottom".
   ===================================================================== */
[data-tooltip] {
    position: relative;
}

/* Tooltips are rendered by the JS engine in ui.js as a single floating
   element appended to <body> (so they escape overflow:hidden ancestors).
   No CSS pseudo-element fallback: a stray, un-positioned ::after would show
   inline for every [data-tooltip] when the engine is active. */

/* ---- Floating tooltip + hover-card (rendered at <body> by ui.js) ---- */
.lm-tooltip {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 200;
    max-width: 260px;
    padding: 6px 10px;
    border-radius: 8px;
    background: #2b3043;
    color: #fff;
    font-size: 0.76rem;
    font-weight: 600;
    line-height: 1.35;
    box-shadow: 0 8px 20px rgba(20, 24, 40, 0.28);
    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;
    transition: opacity var(--dur-fast) var(--ease-out),
                transform var(--dur-fast) var(--ease-out);
}

.lm-tooltip.is-visible {
    opacity: 1;
    transform: none;
}

.lm-hovercard-panel {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 200;
    min-width: 210px;
    max-width: 300px;
    padding: 14px 16px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 18px 44px rgba(34, 42, 70, 0.20);
    opacity: 0;
    /* Hidden state sits to the LEFT and slightly small, so when shown to the
       right of the card it appears to slide/grow out of the card. */
    transform: translateX(-14px) scale(0.96);
    transform-origin: left center;
    pointer-events: none;
    transition: opacity var(--dur-base) var(--ease-out),
                transform var(--dur-base) var(--ease-spring);
}

/* When the card is flipped to the LEFT of the element, it should emerge from
   the right edge instead. */
.lm-hovercard-panel.from-right {
    transform: translateX(14px) scale(0.96);
    transform-origin: right center;
}

.lm-hovercard-panel.is-visible {
    opacity: 1;
    transform: none;
}

/* Hidden source content carried inside a .lm-hovercard trigger. */
.lm-hovercard-content {
    display: none;
}

/* Reusable rich-hovercard interior (used by the volunteer roster chips). */
.lm-hc-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.lm-hc-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: var(--primary-dark);
    font-weight: 800;
    font-size: 0.95rem;
    overflow: hidden;
}

.lm-hc-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.lm-hc-title {
    min-width: 0;
}

.lm-hc-name {
    display: block;
    font-weight: 800;
    color: var(--text);
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lm-hc-email {
    display: block;
    font-size: 0.76rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lm-hc-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lm-hc-stat {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.84rem;
    color: var(--text);
}

.lm-hc-stat-icon {
    width: 18px;
    text-align: center;
    flex: 0 0 auto;
}

.lm-hc-stat-num {
    font-weight: 800;
    margin-left: auto;
}

.lm-hc-stat-warn .lm-hc-stat-num {
    color: #a52834;
}

.lm-hc-divider {
    display: block;
    height: 1px;
    margin: 12px 0;
    background: var(--border);
}

.lm-hc-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.lm-hc-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
}

.lm-hc-list-name {
    color: var(--text);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lm-hc-list-meta {
    margin-left: auto;
    color: var(--muted);
    font-weight: 600;
    white-space: nowrap;
}

.lm-hc-more {
    display: block;
    margin-top: 4px;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--primary-dark);
}

/* Volunteer mini-avatars inside hover-cards (overlapping row). */
.lm-hc-vols {
    display: inline-flex;
    align-items: center;
}

.lm-hc-vols-right {
    margin-left: auto;
}

.lm-hc-vol {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: var(--primary-dark);
    font-size: 0.6rem;
    font-weight: 800;
    border: 1.5px solid var(--surface);
    margin-left: -5px;
    overflow: hidden;
    flex: 0 0 auto;
}

.lm-hc-vol:first-child {
    margin-left: 0;
}

.lm-hc-vol img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.lm-hc-vol-empty {
    background: #eef0f6;
    color: var(--muted);
}

/* =====================================================================
   Hover-card — rich, data-bearing popover. Markup:
     <span class="hovercard">
        <span class="hovercard-trigger">…</span>
        <span class="hovercard-panel" role="tooltip">…rich content…</span>
     </span>
   ===================================================================== */
.hovercard {
    position: relative;
    display: inline-flex;
}

.hovercard-panel {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translate(-50%, 6px);
    min-width: 220px;
    max-width: 300px;
    padding: 14px 16px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 18px 44px rgba(34, 42, 70, 0.18);
    opacity: 0;
    pointer-events: none;
    z-index: 70;
    transition: opacity var(--dur-base) var(--ease-out),
                transform var(--dur-base) var(--ease-out);
    text-align: left;
}

.hovercard-panel::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    border: 7px solid transparent;
    border-top-color: var(--surface);
    filter: drop-shadow(0 2px 1px rgba(34, 42, 70, 0.06));
}

@media (hover: hover) {
    .hovercard:hover .hovercard-panel,
    .hovercard:focus-within .hovercard-panel {
        opacity: 1;
        transform: translate(-50%, 0);
        pointer-events: auto;
    }
}

/* =====================================================================
   Back-to-top button (injected/used by ui.js).
   ===================================================================== */
.back-to-top {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 12px 28px rgba(98, 95, 160, 0.4);
    opacity: 0;
    transform: translateY(14px) scale(0.85);
    pointer-events: none;
    transition: opacity var(--dur-base) var(--ease-out),
                transform var(--dur-base) var(--ease-spring),
                background var(--dur-fast) var(--ease-out);
    z-index: 80;
}

.back-to-top.is-visible {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

@media (hover: hover) {
    .back-to-top:hover {
        background: var(--primary-dark);
        transform: translateY(-2px);
    }
}

/* =====================================================================
   Alerts / toasts — entrance animation + dismissable.
   ===================================================================== */
@keyframes lm-toast-in {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.alert {
    position: relative;
    padding-right: 42px;
    animation: lm-toast-in var(--dur-base) var(--ease-out) both;
    transition: opacity var(--dur-base) var(--ease-out),
                transform var(--dur-base) var(--ease-out),
                margin var(--dur-base) var(--ease-out),
                max-height var(--dur-base) var(--ease-out);
}

.alert-close {
    position: absolute;
    top: 8px;
    right: 10px;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: inherit;
    opacity: 0.55;
    font-size: 1.25rem;
    line-height: 1;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity var(--dur-fast) var(--ease-out),
                background var(--dur-fast) var(--ease-out);
}

.alert-close:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.06);
}

.alert.is-dismissing {
    opacity: 0;
    transform: translateY(-8px);
    max-height: 0 !important;
    margin: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    overflow: hidden;
}

/* =====================================================================
   Button loading state — ui.js adds .is-loading on submit.
   ===================================================================== */
.is-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.is-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff;
    animation: lm-spin 0.6s linear infinite;
}

.button-secondary.is-loading::after {
    border-color: rgba(98, 95, 160, 0.35);
    border-top-color: var(--primary);
}

@keyframes lm-spin {
    to { transform: rotate(360deg); }
}

/* =====================================================================
   Count-up numbers don't need CSS; ui.js animates textContent.
   Tiny "pop" when a value finishes counting (playful only).
   ===================================================================== */
@keyframes lm-pop {
    0% { transform: scale(1); }
    45% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

body[data-motion="playful"] .lm-counted {
    animation: lm-pop var(--dur-base) var(--ease-spring);
}

/* =====================================================================
   Respect user motion preferences — kill all of the above.
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }

    .reveal {
        opacity: 1 !important;
        transform: none !important;
    }
}
