/* ============================================================
   Ventanas «Todas las medallas» y «Actividades completadas» — Luz y Saber
   Marcado: #medalsModal / #completedModal en front-page.php y page-perfil.php
   (abren con openMedalsModal / openCompletedModal, que ponen la clase .active).

   Solo la ventana: fondo, tarjeta, cabecera, cerrar, títulos de sección y la
   animación (igual que «Tu nivel»). Las tarjetas de medallas y lecciones
   (.modal-medal-card, .completed-lesson-card) mantienen sus estilos.

   Las plantillas traen estilos propios en línea (algunos con !important en
   page-perfil.php), por eso aquí van con html body + !important.
   Se encola en la home y en Perfil (inc/xp-levels.php).
   ============================================================ */

/* ---------- Fondo + animación de entrada y salida ----------
   Siempre en flex y oculta con visibility: así también se anima al cerrar
   sin tocar el JS (que solo pone/quita .active) */
html body .medals-modal {
    display: flex !important;
    align-items: flex-end !important;
    justify-content: center !important;
    position: fixed !important;
    inset: 0 !important;
    width: auto !important;
    height: auto !important;
    z-index: 9999 !important;
    background: rgba(26, 28, 29, 0.45) !important;
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
    animation: none !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.24s ease, visibility 0s linear 0.26s;
}
html body .medals-modal.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity 0.24s ease, visibility 0s linear 0s;
}
@media (min-width: 600px) {
    html body .medals-modal { align-items: center !important; padding: var(--ls-margin-mob, 16px) !important; }
}

/* ---------- Tarjeta ---------- */
html body .medals-modal-content {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    max-width: 760px !important;
    max-height: calc(100vh - 12px) !important;
    max-height: calc(100dvh - 12px) !important;
    overflow: hidden !important;
    background: var(--ls-surface-lowest, #fff) !important;
    border: 1px solid var(--ls-surface-container, #edeef0) !important;
    border-bottom: none !important;
    border-radius: var(--ls-radius-xl, 1.5rem) var(--ls-radius-xl, 1.5rem) 0 0 !important;
    box-shadow: var(--ls-shadow-dropdown, 0 8px 24px rgba(0, 0, 0, 0.1)) !important;
    font-family: var(--ls-font-body, 'Inter', sans-serif);
    color: var(--ls-on-surface, #1a1c1d);
    animation: none !important;
    transform: translateY(24px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
html body .medals-modal.active .medals-modal-content { transform: translateY(0); }
@media (min-width: 600px) {
    html body .medals-modal-content {
        max-height: min(85vh, 760px) !important;
        border-bottom: 1px solid var(--ls-surface-container, #edeef0) !important;
        border-radius: var(--ls-radius-xl, 1.5rem) !important;
        transform: translateY(12px) scale(0.96);
    }
    html body .medals-modal.active .medals-modal-content { transform: translateY(0) scale(1); }
}

/* ---------- Cabecera ---------- */
html body .medals-modal-header {
    flex-shrink: 0;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 12px;
    padding: 18px 20px 16px 24px !important;
    background: var(--ls-surface-lowest, #fff) !important;
    border-bottom: 1px solid var(--ls-surface-container, #edeef0) !important;
}
html body .medals-modal-header h2 {
    margin: 0 !important;
    font-family: var(--ls-font-headline, 'Manrope', sans-serif) !important;
    font-size: 1.125rem !important;
    font-weight: 800 !important;
    letter-spacing: -0.02em !important;
    line-height: 1.25 !important;
    color: var(--ls-on-surface, #1a1c1d) !important;
}
html body .medals-modal-header h2 svg { flex-shrink: 0; width: 20px; height: 20px; }

/* Cerrar: mismo botón que «Tu nivel» y el aviso de sesiones */
html body .medals-modal-close {
    flex-shrink: 0;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 30px !important;
    height: 30px !important;
    padding: 0 !important;
    border: none !important;
    border-radius: var(--ls-radius-md, 0.75rem) !important;
    background: var(--ls-surface-low, #f3f3f5) !important;
    color: var(--ls-on-surface-variant, #444748) !important;
    font-size: 18px !important;
    line-height: 1 !important;
    cursor: pointer;
    transform: none !important;
    transition: var(--ls-transition, all 0.25s ease) !important;
}
html body .medals-modal-close:hover {
    background: var(--ls-surface-container, #edeef0) !important;
    color: var(--ls-on-surface, #1a1c1d) !important;
}
html body .medals-modal-close:focus-visible { outline: 2px solid var(--ls-primary, #000); outline-offset: 2px; }

/* ---------- Cuerpo ---------- */
html body .medals-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none !important;
    overflow-y: auto !important;
    padding: 20px 24px calc(24px + env(safe-area-inset-bottom, 0px)) !important;
    background: var(--ls-surface-lowest, #fff);
}

/* Títulos de sección («Medallas conseguidas», «Has completado…»): estilo
   etiqueta de Luz y Saber; los iconos conservan su color */
html body .medals-modal-body > h3 {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    margin: 0 0 12px !important;
    font-family: var(--ls-font-body, 'Inter', sans-serif) !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    letter-spacing: 0.08em !important;
    text-transform: uppercase !important;
    line-height: 1.4 !important;
    color: var(--ls-on-surface-variant, #444748) !important;
}
html body .medals-modal-body > h3 ~ h3 { margin-top: 24px !important; }
html body .medals-modal-body > h3 svg { width: 16px; height: 16px; }

html body .medals-modal-grid { gap: 10px !important; margin-bottom: 0 !important; }

/* ---------- XP de cada medalla (junto al nombre) ---------- */
html body .modal-medal-xp {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 7px;
    border-radius: var(--ls-radius-full, 9999px);
    background: var(--ls-surface-low, #f3f3f5);
    font-family: var(--ls-font-body, 'Inter', sans-serif);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.5;
    letter-spacing: 0;
    color: var(--ls-on-surface-variant, #444748);
    vertical-align: 2px;
    white-space: nowrap;
}

/* ---------- Medallas nuevas (conseguidas hace < 7 días): doradas ----------
   hsc_medal_is_new() en inc/medals.php pone .is-new; las nuevas van primero */
html body .modal-medal-card.earned.is-new {
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #fffaeb 0%, #fdeeb5 55%, #fbe08a 100%) !important;
    border-color: #e9b949 !important;
    box-shadow: 0 0 0 1px rgba(233, 185, 73, 0.35), 0 8px 22px rgba(180, 120, 10, 0.18) !important;
}
/* Brillo que cruza la tarjeta de vez en cuando */
html body .modal-medal-card.earned.is-new::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.65) 48%, transparent 66%);
    transform: translateX(-120%);
    animation: hscMedalShine 3.2s ease-in-out 0.4s infinite;
    pointer-events: none;
}
@keyframes hscMedalShine {
    0%, 55% { transform: translateX(-120%); }
    100%    { transform: translateX(120%); }
}
html body .modal-medal-card.earned.is-new .modal-medal-icon {
    flex: 0 0 48px;
    width: 48px !important;
    height: 48px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: #fff !important;
    border-radius: 50%;
    box-shadow: 0 0 0 2px #f3c74f, 0 4px 12px rgba(217, 119, 6, 0.25);
}
html body .modal-medal-card.earned.is-new .modal-medal-xp {
    background: rgba(255, 255, 255, 0.75);
    color: #8a5a00;
}
html body .modal-medal-new {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 8px;
    border-radius: var(--ls-radius-full, 9999px);
    background: linear-gradient(135deg, #f6c343, #d98a06);
    font-family: var(--ls-font-body, 'Inter', sans-serif);
    font-size: 10px;
    font-weight: 800;
    line-height: 1.6;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #fff;
    vertical-align: 2px;
    box-shadow: 0 2px 6px rgba(217, 138, 6, 0.35);
}

@media (prefers-reduced-motion: reduce) {
    html body .medals-modal,
    html body .medals-modal-content { transition: none !important; transform: none !important; }
    html body .modal-medal-card.earned.is-new::after { animation: none; display: none; }
}
