/* static/css/detalle.css */

/* Reset base para el lector */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    scroll-behavior: smooth;
}

.lector-body {
    font-family: 'Lora', serif;
    font-size: var(--lector-font-size, clamp(1.05rem, 1rem + 0.3vw, 1.25rem)); /* Refinado: menos agresivo en móvil */
    line-height: 1.8;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* ==================================
   TEMAS (COLORES Y FONDOS)
================================== */

/* Modo Oscuro (Por defecto) */
.tema-oscuro {
    background-color: #0c0c0c;
    color: #d1d1d1;
}
.tema-oscuro .lector-navbar {
    background-color: #0c0c0c; /* Sólido por defecto */
    border-bottom: 1px solid rgba(229, 172, 68, 0.2);
}
@supports (backdrop-filter: blur(12px)) or (-webkit-backdrop-filter: blur(12px)) {
    .tema-oscuro .lector-navbar {
        background-color: rgba(12, 12, 12, 0.85) !important;
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
    }
}
.tema-oscuro .lector-titulo,
.tema-oscuro .info-arco, 
.tema-oscuro .info-capitulo {
    color: #e5ac44;
}
.tema-oscuro .btn-tema {
    border-color: #555;
}
.tema-oscuro .btn-tema.activo {
    box-shadow: 0 0 10px rgba(229, 172, 68, 0.5);
    border-color: #e5ac44;
}
.tema-oscuro .btn-volver-lector, .tema-oscuro .btn-accion {
    color: #d4a373;
    border-color: #d4a373;
}

/* Modo Sepia (Pergamino) */
.tema-sepia {
    background-color: #f4ecd8;
    color: #433422;
}
.tema-sepia .lector-navbar {
    background-color: #f4ecd8; /* Sólido por defecto */
    border-bottom: 1px solid rgba(107, 38, 11, 0.15);
}
@supports (backdrop-filter: blur(12px)) or (-webkit-backdrop-filter: blur(12px)) {
    .tema-sepia .lector-navbar {
        background-color: rgba(244, 236, 216, 0.85) !important;
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
    }
}
.tema-sepia .lector-titulo {
    color: #6b260b;
}
.tema-sepia .info-arco, 
.tema-sepia .info-capitulo {
    color: #8c5d33;
}
.tema-sepia .progreso-lectura-barra {
    background-color: #6b260b !important;
    box-shadow: 0 0 5px rgba(107, 38, 11, 0.4) !important;
}
.tema-sepia .btn-tema {
    border-color: #a8947b;
    color: #433422;
}
.tema-sepia .btn-tema.activo {
    box-shadow: 0 0 10px rgba(140, 93, 51, 0.3);
    border-color: #6b260b;
}
.tema-sepia .btn-volver-lector, .tema-sepia .btn-accion {
    color: #6b260b;
    border-color: #6b260b;
}

/* Modo Claro */
.tema-claro {
    background-color: #ffffff;
    color: #2a2a2a;
}
.tema-claro .lector-navbar {
    background-color: #ffffff; /* Sólido por defecto */
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
@supports (backdrop-filter: blur(12px)) or (-webkit-backdrop-filter: blur(12px)) {
    .tema-claro .lector-navbar {
        background-color: rgba(255, 255, 255, 0.85) !important;
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
    }
}
.tema-claro .lector-titulo {
    color: #111;
}
.tema-claro .info-arco, 
.tema-claro .info-capitulo {
    color: #555;
}
.tema-claro .progreso-lectura-barra {
    background-color: #e5ac44 !important;
}
.tema-claro .btn-tema {
    border-color: #ccc;
    color: #333;
}
.tema-claro .btn-tema.activo {
    box-shadow: 0 0 8px rgba(0,0,0,0.15);
    border-color: #222;
}
.tema-claro .btn-volver-lector, .tema-claro .btn-accion {
    color: #111;
    border-color: #aaa;
}

/* ==================================
   BARRA DE PROGRESO INMERSIVA
================================== */
.progreso-lectura-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background-color: transparent;
    z-index: 9999; /* Por encima de la navbar */
}

.progreso-lectura-barra {
    width: 0%;
    height: 100%;
    background-color: #e5ac44; /* Oro natural de la web */
    transition: width 0.1s ease-out; /* Sensación fluida instantánea */
    box-shadow: 0 0 10px rgba(229, 172, 68, 0.7);
}

/* ==================================
   UI SUPERIOR (CONTROLES)
================================== */
.lector-navbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    box-sizing: border-box;
    z-index: 1000;
    transition: transform 0.4s ease; /* Para ocultarse si se quiere */
}

/* Funcionalidad futura: ocultar navbar al scrollear abajo */
.lector-navbar.oculta {
    transform: translateY(-100%);
}

.lector-info-barra {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    letter-spacing: 1px;
}

.btn-volver-lector {
    font-family: 'Cinzel', serif;
    text-decoration: none;
    font-size: 0.95rem;
    padding: 6px 14px;
    border-width: 1px;
    border-style: solid;
    border-radius: 4px;
    transition: all 0.3s;
}
.btn-volver-lector:hover {
    background-color: rgba(128,128,128,0.1);
}

.controles-tema {
    display: flex;
    gap: 12px;
}

.btn-tema {
    background: transparent;
    border: 1px solid transparent;
    color: inherit;
    font-size: 1.1rem;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}
.btn-tema:hover {
    transform: scale(1.1);
}

/* ==================================
   CONTENIDO PRINCIPAL
================================== */
.lector-contenedor {
    max-width: 750px;
    margin: 120px auto 80px; 
    padding: 0 25px;
}

.lector-cabecera {
    text-align: center;
    margin-bottom: 60px;
}

.lector-titulo {
    font-family: 'Cinzel', serif;
    font-size: clamp(1.6rem, 1.3rem + 2vw, 3.5rem); /* Refinado: escala más lento */
    margin: 10px 0;
    letter-spacing: 2px;
}

.lector-meta {
    font-size: 0.95rem;
    font-style: italic;
    opacity: 0.7;
}

.lector-info-movil {
    display: none !important;
}

.lector-contenido {
    text-align: justify;
}

.lector-contenido p {
    margin-bottom: 1.8rem;
    /* Sangría clasica literaria de primera linea */
    text-indent: 1.5rem; 
}

/* Estilo para capitular opcional */
.lector-contenido p span.letra-capitular {
    float: left;
    font-family: 'Cinzel', serif;
    font-size: 4rem;
    line-height: 0.8;
    padding-right: 8px;
    color: #e5ac44; 
}

.lector-footer {
    margin-top: 100px;
    padding-top: 40px;
    border-top: 1px solid rgba(128,128,128,0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.4s ease, opacity 0.4s ease, visibility 0.4s ease;
}

.btn-mapa-flotante.hide {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.8);
}

.btn-accion {
    text-decoration: none;
    font-family: 'Cinzel', serif;
    padding: 12px 24px;
    border-width: 1px;
    border-style: solid;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.btn-accion:hover {
    background-color: rgba(128,128,128,0.1);
}

.btn-siguiente-cap {
    background-color: rgba(0, 0, 0, 0.4);
    color: #e5ac44 !important;
    border: 1px solid #e5ac44;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.btn-siguiente-cap:hover {
    background-color: rgba(229, 172, 68, 0.1);
    box-shadow: 0 0 15px rgba(229, 172, 68, 0.2);
}

/* ==================================
   SEPARADORES DE ESCENA (PLUMAS)
================================== */
.separador-pluma {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 60px auto;
    width: 60px;
    height: 30px;
    background-image: url("../images/glifo_pluma.9140cae0af0b.png");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    filter: drop-shadow(0 0 5px rgba(229, 172, 68, 0.4));
}

.separador-pluma.triple {
    width: 140px;
    background-image: none; /* Quitamos la de fondo para usar los spans */
    gap: 15px;
}

.separador-pluma.triple span {
    display: block;
    width: 40px;
    height: 25px;
    background-image: url("../images/glifo_pluma.9140cae0af0b.png");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.8;
}

.separador-pluma.triple span:nth-child(2) {
    transform: scale(1.3);
    opacity: 1;
}

/* Ajustes para los temas en los separadores */
.tema-sepia .separador-pluma {
    filter: sepia(1) brightness(0.5);
}
.tema-claro .separador-pluma {
    filter: brightness(0.3);
}
/* ==================================
   SISTEMA DE COMENTARIOS (ACORDEÓN PREMIUM)
================================== */
.seccion-comentarios {
    width: 100%;
    margin-top: 60px;
    border: 1px solid rgba(229, 172, 68, 0.2);
    border-radius: 12px;
    background: rgba(20, 20, 20, 0.4);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.seccion-comentarios.open {
    border-color: rgba(229, 172, 68, 0.5);
    box-shadow: 0 15px 40px rgba(0,0,0,0.5), 0 0 20px rgba(229, 172, 68, 0.1);
}

.comentarios-header {
    width: 100%;
    padding: 25px 30px;
    background: transparent;
    border: none;
    color: #e5ac44;
    font-family: 'Cinzel', serif;
    font-size: 1.3rem;
    font-weight: bold;
    letter-spacing: 1px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s;
}

.comentarios-header:hover {
    background: rgba(229, 172, 68, 0.05);
    color: #f3f0df;
}

/* Hint visual para invitar al clic */
.seccion-comentarios:not(.open) .comentarios-header {
    animation: pulseHeader 4s infinite;
}

@keyframes pulseHeader {
    0% { box-shadow: inset 0 0 0 rgba(229, 172, 68, 0); }
    50% { box-shadow: inset 0 0 20px rgba(229, 172, 68, 0.05); }
    100% { box-shadow: inset 0 0 0 rgba(229, 172, 68, 0); }
}

.flecha-acordeon {
    font-size: 0.8rem;
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.seccion-comentarios.open .flecha-acordeon {
    transform: rotate(180deg) scale(1.2);
}

.comentarios-body {
    display: none;
    padding: 0 30px 40px;
    border-top: 1px solid rgba(229, 172, 68, 0.1);
    animation: slideDown 0.5s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.seccion-comentarios.open .comentarios-body {
    display: block;
}

/* Lista de Comentarios */
.lista-comentarios {
    list-style: none;
    padding: 0;
    margin: 0;
}

.comentario-item {
    margin-bottom: 30px;
    padding: 25px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(128, 128, 128, 0.1);
    border-radius: 8px;
    transition: transform 0.3s, border-color 0.3s;
}

.comentario-item:hover {
    border-color: rgba(229, 172, 68, 0.2);
}

.comentario-meta {
    font-size: 0.9rem;
    margin-bottom: 15px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 15px;
}

.comentario-autor {
    color: #e5ac44;
    font-weight: bold;
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.comentario-autor::before {
    content: '◈';
    font-size: 0.7rem;
    opacity: 0.5;
}

/* Badges de Rango */
.badge-comentario {
    font-family: 'Cinzel', serif;
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.badge-autor {
    background: linear-gradient(135deg, #e5ac44 0%, #d4a373 100%);
    color: #1a1a1a;
    border: 1px solid #f3f0df;
}

.badge-moderador {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: #fff;
    border: 1px solid #5dade2;
}

.comentario-fecha {
    font-family: 'Lora', serif;
    font-style: italic;
    opacity: 0.5;
    font-size: 0.8rem;
    margin-left: auto; /* Empujar fecha a la derecha */
}

.comentario-texto {
    font-size: 1.1rem;
    line-height: 1.6;
    color: #d1d1d1;
    margin-bottom: 20px;
}

.comentario-acciones {
    display: flex;
    justify-content: flex-end; /* Alineamos a la derecha */
    gap: 10px;
    border-top: 1px solid rgba(128, 128, 128, 0.05);
    padding-top: 15px;
}

.btn-comentario {
    background: rgba(128, 128, 128, 0.05);
    border: 1px solid rgba(229, 172, 68, 0.2);
    color: #e5ac44;
    font-size: 1rem;
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    border-radius: 20px; /* Más ovalado si crece */
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.btn-like.liked {
    color: #ff4d4d;
    border-color: #ff4d4d;
    background: rgba(255, 77, 77, 0.1);
    animation: heartBeat 0.4s ease;
}

.btn-like.liked .heart-icon {
    text-shadow: 0 0 10px rgba(255, 77, 77, 0.5);
}

@keyframes heartBeat {
    0% { transform: scale(1) translateY(-3px); }
    50% { transform: scale(1.3) translateY(-3px); }
    100% { transform: scale(1.1) translateY(-3px); }
}

.heart-icon {
    font-size: 1.2rem;
    line-height: 1;
}

.like-count {
    font-size: 0.8rem;
    font-weight: bold;
    font-family: 'Cinzel', serif;
}

.btn-comentario:hover {
    transform: translateY(-3px) scale(1.1);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    opacity: 1;
}

.btn-eliminar, .btn-eliminar-ajax { 
    color: #a5a5a5;
}

.btn-eliminar:hover, .btn-eliminar-ajax:hover { 
    color: #ff4d4d !important;
    background: rgba(255, 77, 77, 0.1) !important;
    transform: translateY(-3px) scale(1.1) rotate(8deg) !important;
}

.btn-enviar-comentario:hover {
    transform: translateY(-3px) scale(1.05) rotate(-5deg);
    box-shadow: 0 8px 25px rgba(229, 172, 68, 0.3);
}

/* Respuestas (Hilos) */
.lista-respuestas {
    margin-left: 50px;
    margin-top: 20px;
    padding-left: 20px;
    border-left: 1px solid rgba(229, 172, 68, 0.3);
}

.lista-respuestas .comentario-item {
    padding: 15px 20px;
    background: rgba(229, 172, 68, 0.03);
}

/* Formulario */
.form-comentario {
    margin: 30px 0 40px;
    padding: 30px;
    background: rgba(229, 172, 68, 0.03);
    border: 1px solid rgba(229, 172, 68, 0.1);
    border-radius: 12px;
}

.comment-textarea {
    width: 100%;
    background: rgba(10, 10, 10, 0.6);
    border: 1px solid rgba(229, 172, 68, 0.2);
    color: #f3f0df;
    padding: 20px;
    border-radius: 8px;
    font-family: 'Lora', serif;
    font-size: 1.1rem;
    line-height: 1.5;
    resize: none;
    box-sizing: border-box;
    transition: all 0.3s;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
}

.comment-textarea:focus {
    outline: none;
    border-color: #e5ac44;
    background: rgba(15, 15, 15, 0.8);
    box-shadow: inset 0 2px 15px rgba(0,0,0,0.7), 0 0 15px rgba(229, 172, 68, 0.1);
}

.btn-enviar-comentario {
    margin-top: 10px;
    background: #e5ac44;
    color: #000;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: flex-end;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.form-comentario {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-enviar-comentario:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(229, 172, 68, 0.3);
    color: #000;
}

.reply-form-container {
    display: none;
    border-top: 1px solid rgba(229, 172, 68, 0.1);
    padding-top: 20px;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* --- MEDIA QUERIES (REFINADO MÓVIL) --- */
@media (max-width: 768px) {
    .lector-navbar {
        padding: 0 15px;
    }
    
    .lector-info-barra {
        display: none !important;
    }

    .texto-volver-btn {
        display: none !important;
    }

    .lector-info-movil {
        display: block !important;
        font-family: 'Cinzel', serif;
        font-size: 0.85rem;
        color: #e5ac44;
        margin-top: 10px;
        margin-bottom: 5px;
        letter-spacing: 1px;
    }

    .tema-sepia .lector-info-movil {
        color: #8c5d33;
    }

    .tema-claro .lector-info-movil {
        color: #555;
    }

    .btn-volver-lector {
        padding: 4px 8px !important;
        font-size: 1.1rem !important;
    }

    .controles-tema {
        gap: 5px;
    }

    .btn-tema {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }

    .lector-contenedor {
        margin-top: 100px;
        padding: 0 18px;
    }

    .lector-cabecera {
        margin-bottom: 40px;
    }

    .lector-contenido p {
        text-align: left; /* Mejor legibilidad en móviles */
        text-indent: 1rem;
    }

    .lector-footer {
        flex-direction: column;
        gap: 20px;
        padding-bottom: 40px;
    }

    .comentarios-header {
        padding: 20px 15px;
        font-size: 1.1rem;
    }

    .comentarios-body {
        padding: 0 15px 30px;
    }

    .comentario-item {
        padding: 15px;
    }

    .lista-respuestas {
        margin-left: 15px;
        padding-left: 10px;
    }

    .form-comentario {
        padding: 15px;
    }
}

@media (max-width: 480px) {
    .lector-navbar {
        height: 55px;
    }
    
    .btn-volver-lector {
        font-size: 0.8rem;
        padding: 4px 8px;
    }
    
    .badge-comentario {
        font-size: 0.55rem;
    }
}

/* Eliminación de cuadros azules en móviles */
* { -webkit-tap-highlight-color: transparent; }

/* --- ADAPTACIÓN POR TEMAS (CORRECCIÓN CONTRASTE) --- */
.tema-sepia .seccion-comentarios { 
    background: #e8dec5; 
    border-color: #c4b595;
}
.tema-sepia .comentarios-header { color: #433422; }
.tema-sepia .comentario-item { 
    background: rgba(0, 0, 0, 0.05); 
    border-bottom: 1px solid rgba(67, 52, 34, 0.1); 
}
.tema-sepia .comentario-autor { color: #6b260b; }
.tema-sepia .comentario-texto { color: #2a1e12; }
.tema-sepia .comment-textarea { 
    background: #fdfaf0; 
    border-color: #c4b595; 
    color: #2a1e12; 
}
.tema-sepia .btn-enviar-comentario,
.tema-sepia .btn-comentario {
    background: #6b260b;
    color: #f4ecd8;
    border-color: #6b260b;
}

.tema-claro .seccion-comentarios { 
    background: #f0f0f0; 
    border-color: #d0d0d0; 
}
.tema-claro .comentarios-header { color: #111; }
.tema-claro .comentario-item { 
    background: #ffffff; 
    border-bottom: 1px solid #eeeeee;
}
.tema-claro .comentario-autor { color: #000; }
.tema-claro .comentario-texto { color: #222; }
.tema-claro .comment-textarea { 
    background: #ffffff; 
    border-color: #cccccc; 
    color: #000000; 
}
.tema-claro .btn-enviar-comentario {
    background: #1a1a1a;
    color: #fff;
}
.tema-claro .btn-comentario {
    background: #e0e0e0;
    color: #1a1a1a;
    border-color: #ccc;
}

.tema-oscuro .btn-enviar-comentario {
    background: #e5ac44;
    color: #000;
}
.tema-oscuro .btn-comentario {
    background: rgba(45, 45, 45, 0.5);
    border-color: #e5ac44;
    color: #e5ac44;
}

.avatar-default {
    filter: grayscale(0.8) opacity(0.7);
    transition: filter 0.3s ease, opacity 0.3s ease;
}

.avatar-default:hover {
    filter: grayscale(0.4) opacity(0.9);
}

/* --- NUEVOS ESTILOS SOCIALES (Niveles y Medallas) --- */
.user-avatar-mini {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    border: 1px solid var(--color-oro);
    flex-shrink: 0;
    background: #000;
    display: inline-block;
    vertical-align: middle;
    margin-right: 5px;
}
.user-avatar-mini img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    image-rendering: -webkit-optimize-contrast; /* Recuperando nitidez agresiva por petición */
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* --- SISTEMA DE LOGROS (MEDALLAS) --- */
@keyframes wiggle-medal {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(5deg); }
    50% { transform: rotate(0deg); }
    75% { transform: rotate(-5deg); }
    100% { transform: rotate(0deg); }
}

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 20px;
    margin-top: 15px;
}

.achievement-item {
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    position: relative;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.4);
    padding: 6px;
    box-sizing: border-box;
}

.achievement-item img {
    width: 85%;
    height: 85%;
    object-fit: contain;
    z-index: 2;
    transform-origin: center center;
    display: block;
}

/* Hover y Selección */
.achievement-item:hover { 
    transform: scale(1.18) translateY(-8px) !important; 
    z-index: 100 !important; 
    /* No detenemos animaciones aquí para que mantengan su forma morph */
}

/* Mantener rotación en Raro durante Hover */
.rarity-rare:hover { 
    transform: rotate(45deg) scale(1.18) translateY(-8px) !important; 
}

/* Medalla Destacada en Perfil */
.achievement-item.selected {
    transform: scale(1.1) !important;
    border-color: currentColor !important;
    box-shadow: 0 0 20px currentColor;
    z-index: 5;
    background: rgba(255, 255, 255, 0.05);
}

/* Medalla actualmente viendo en el portal */
.achievement-item.selected-active {
    border-color: currentColor !important;
    box-shadow: 0 0 30px currentColor !important;
    transform: scale(1.3) !important;
    z-index: 10;
    animation-play-state: paused !important; /* Congela la forma actual (especialmente para legendarias) */
}

/* Si es rara (rombo) y está activa o destacada */
.rarity-rare.selected {
    transform: rotate(45deg) scale(0.85) !important;
}
.rarity-rare.selected-active {
    transform: rotate(45deg) scale(1.0) !important;
}

/* Límite adaptativo en perfil colapsado (Dashboard / Perfil Público) */
.collapsed-content-wrapper .achievement-item:nth-child(n+9) {
    display: none !important;
}
@media (max-width: 600px) {
    .collapsed-content-wrapper .achievement-item:nth-child(n+7) {
        display: none !important;
    }
}

/* Controles de Ordenamiento */
.sorting-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
    justify-content: flex-end;
    padding-right: 10px;
    position: relative;
    z-index: 100;
}
.sorting-controls .btn-mistico {
    font-size: 0.85rem !important;
    padding: 8px 15px !important;
    background: rgba(0,0,0,0.5) !important;
    border: 1px solid rgba(229,172,68,0.3) !important;
}
.sorting-controls .btn-mistico:hover {
    background: rgba(229, 172, 68, 0.2) !important;
    border-color: var(--color-oro) !important;
}

/* Mobile responsive for buttons */
@media (max-width: 600px) {
    .sorting-controls {
        gap: 5px;
        justify-content: center;
        padding-right: 0;
        flex-wrap: wrap;
    }
    .sorting-controls .btn-mistico {
        padding: 5px 10px !important;
        font-size: 0.65rem !important;
        min-width: auto;
    }
    .sorting-controls .btn-text {
        display: inline-block;
    }
    .sorting-controls .btn-icon {
        display: none !important;
    }
    .sort-separator {
        display: none;
    }
}

.sorting-controls .btn-icon {
    display: none;
}

/* Contenedores con overflow visible para tooltips */
.achievements-grid, 
.collapsed-content-wrapper, 
.expanded-logros-layout,
.card.expandable {
    overflow: visible !important;
}

.collapsed-content-wrapper {
    padding: 10px 15px; /* Espacio extra para que el tooltip no choque */
}

/* --- FORMAS MÍSTICAS ÚNICAS --- */

.rarity-common { border-radius: 50%; border: 1px solid #8b6b4a; animation: pulse-common 3s infinite; color: #8b6b4a; }
.rarity-uncommon { border-radius: 50% 0 50% 0; border: 1px solid #4caf50; animation: pulse-uncommon 2.5s infinite; color: #4caf50; }
.rarity-rare { border-radius: 10% 10% 10% 10%; transform: rotate(45deg) scale(0.72); border: 2px solid #e5ac44; animation: pulse-rare 2s infinite; color: #e5ac44; }
.achievement-item.rarity-rare img, .achievement-item.rarity-rare span { transform: rotate(-45deg) !important; display: inline-block !important; }
.rarity-epic { border-radius: 50% 50% 10% 10%; border: 2px double #9c27b0; animation: pulse-epic 1.5s infinite; color: #9c27b0; }
.rarity-legendary { 
    border: 2px solid #ff5252; 
    animation: pulse-legendary 1s infinite alternate, morph-legendary 5s infinite linear; 
    color: #ff5252;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease; /* Excluir border-radius del transition para evitar flickering */
}
.rarity-legendary:hover { 
    transform: scale(1.18) translateY(-8px) !important; 
}

/* Tooltip Fix */
.achievements-grid .tooltip {
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 10, 10, 0.98);
    backdrop-filter: blur(8px);
    border: 1px solid var(--color-oro);
    padding: 10px 14px;
    border-radius: 6px;
    width: max-content;
    max-width: 180px;
    pointer-events: none;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    font-size: 0.8rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    line-height: 1.4;
}

/* Hide tooltip on mobile */
@media (max-width: 600px) {
    .achievements-grid .tooltip {
        display: none !important;
    }
}

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 15px;
    margin-top: 15px;
    padding: 20px 10px !important; /* REDUCIDO PARA EVITAR SCROLL HORIZONTAL */
    justify-items: center;
}

/* Contra-rotación estable para amarillas */
.rarity-rare .tooltip {
    transform: translateX(-50%) rotate(-45deg) !important;
    transform-origin: center bottom;
}

.achievement-item:hover .tooltip {
    opacity: 1;
    bottom: 125%;
}

    justify-content: center;
    padding: 20px;
    min-height: 350px; /* Asegurar espacio */
    background: radial-gradient(circle at center, rgba(229,172,68,0.05) 0%, transparent 70%);
}

.mystic-orb {
    position: relative;
    width: 180px;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 30px;
}

.mystic-ring {
    position: absolute;
    border-radius: 50%;
    border: 1px solid var(--color-oro);
    opacity: 0.2;
    pointer-events: none;
}
@keyframes pulse-common {
    0%, 100% { box-shadow: 0 0 5px rgba(139, 107, 74, 0.2); }
    50% { box-shadow: 0 0 15px rgba(139, 107, 74, 0.6); }
}
@keyframes pulse-uncommon {
    0%, 100% { box-shadow: 0 0 8px rgba(76, 175, 80, 0.2); }
    50% { box-shadow: 0 0 20px rgba(76, 175, 80, 0.7); }
}
@keyframes pulse-rare {
    0%, 100% { box-shadow: 0 0 10px rgba(229, 172, 68, 0.3); transform: rotate(45deg) scale(0.72); }
    50% { box-shadow: 0 0 25px rgba(229, 172, 68, 0.8); transform: rotate(45deg) scale(0.72); }
}
@keyframes pulse-epic {
    0%, 100% { box-shadow: 0 0 15px rgba(156, 39, 176, 0.4); }
    50% { box-shadow: 0 0 35px rgba(156, 39, 176, 1); }
}
@keyframes pulse-legendary {
    0% { box-shadow: 0 0 20px rgba(255, 82, 82, 0.5); filter: brightness(1); }
    100% { box-shadow: 0 0 45px rgba(255, 82, 82, 1); filter: brightness(1.2); }
}
@keyframes morph-legendary {
    0% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
    25% { border-radius: 58% 42% 75% 25% / 56% 82% 18% 44%; }
    50% { border-radius: 50% 50% 33% 67% / 55% 27% 73% 45%; }
    75% { border-radius: 33% 67% 58% 42% / 63% 68% 32% 37%; }
    100% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
}

/* --- HERO VIEW (EFECTO TESERACTO) --- */

.medal-hero-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    min-height: 450px;
    perspective: 2000px;
    background: radial-gradient(circle at center, rgba(229,172,68,0.05) 0%, transparent 70%);
}

.mystic-orb {
    position: relative;
    width: 240px;
    height: 240px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 40px;
    transform-style: preserve-3d;
    animation: medal-float 4s ease-in-out infinite;
}

.mystic-ring {
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(229, 172, 68, 0.8);
    pointer-events: none;
    transform-style: preserve-3d;
    transition: all 0.5s ease;
    opacity: 0.9; /* Menos translúcido */
}

/* Rarity Variations for Mystic Orb Rings - MORE VIBRANT */
.orb-common .mystic-ring { border-color: rgba(139, 107, 74, 1); box-shadow: 0 0 20px rgba(139, 107, 74, 0.4); }
.orb-uncommon .mystic-ring { border-color: rgba(76, 175, 80, 1); box-shadow: 0 0 25px rgba(76, 175, 80, 0.5); }
.orb-rare .mystic-ring { border-color: rgba(229, 172, 68, 1); box-shadow: 0 0 30px rgba(229, 172, 68, 0.6); }
.orb-epic .mystic-ring { border-color: rgba(156, 39, 176, 1); box-shadow: 0 0 35px rgba(156, 39, 176, 0.7); }
.orb-legendary .mystic-ring { border-color: rgba(255, 82, 82, 1); box-shadow: 0 0 50px rgba(255, 82, 82, 0.8); }

.ring-1 {
    width: 100%; height: 100%;
    border-width: 2px;
    border-style: dashed;
    animation: tesseract-1 15s linear infinite;
}

.ring-2 {
    width: 80%; height: 80%;
    border-width: 1px;
    border-style: solid;
    animation: tesseract-2 10s linear infinite reverse;
}

.ring-3 {
    width: 120%; height: 120%;
    border: 1px double var(--color-oro);
    opacity: 0.4; /* Más visible */
    animation: tesseract-3 20s linear infinite;
}

.medal-center {
    width: 130px;
    height: 130px;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 0 30px rgba(229, 172, 68, 0.5));
    transform-style: preserve-3d;
    animation: medal-spin 8s linear infinite;
}

@keyframes tesseract-1 {
    0% { transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
    100% { transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg); }
}

@keyframes tesseract-2 {
    0% { transform: rotateX(45deg) rotateY(0deg); }
    100% { transform: rotateX(405deg) rotateY(360deg); }
}

@keyframes tesseract-3 {
    0% { transform: rotateY(0deg) rotateZ(45deg); }
    100% { transform: rotateY(360deg) rotateZ(405deg); }
}

@keyframes medal-spin {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(360deg); }
}

@keyframes medal-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.medal-center img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.medal-center .placeholder-icon {
    font-size: 5rem;
}

.medal-info-hero {
    text-align: center;
    max-width: 450px;
    animation: fadeInHero 0.8s ease-out;
}

.hero-name-el {
    font-family: 'Cinzel', serif;
    color: #fff;
    font-size: 2.2rem;
    margin: 10px 0;
    text-shadow: 0 0 15px rgba(229,172,68,0.3);
    letter-spacing: 2px;
}

.hero-rarity-el {
    font-family: 'Cinzel', serif;
    font-size: 0.7rem;
    padding: 4px 15px;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 20px;
    letter-spacing: 2px;
    margin-bottom: 15px;
    display: inline-block;
    text-transform: uppercase;
}

.hero-date-el {
    font-size: 0.85rem;
    color: var(--color-oro);
    margin-bottom: 15px;
    opacity: 0.8;
    font-style: italic;
    display: block;
}

.hero-desc-el {
    font-size: 1.05rem;
    line-height: 1.6;
    color: var(--color-text);
    margin-bottom: 30px;
    opacity: 0.9;
}

@keyframes fadeInHero {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}
.achievement-detail-card::before { top: -5px; left: -5px; border-right: 0; border-bottom: 0; }
.achievement-detail-card::after { bottom: -5px; right: -5px; border-left: 0; border-top: 0; }

.user-level-badge {
    background: #e5ac44;
    color: #0a0a0a;
    font-family: 'Cinzel', serif;
    font-weight: bold;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(229, 172, 68, 0.2);
    display: inline-block;
    vertical-align: middle;
}

@media (max-width: 600px) {
    .user-level-badge {
        display: none !important;
    }
}

.user-medal-mini {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    vertical-align: middle;
    margin: 0 5px;
    cursor: help;
}

.user-medal-mini img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 0 5px rgba(229, 172, 68, 0.3));
}

.comentario-autor {
    transition: all 0.3s;
}

.comentario-autor:hover {
    color: #fff !important;
    text-shadow: 0 0 10px rgba(229, 172, 68, 0.5);
    text-decoration: underline;
}

/* Adaptación por temas para Social */
.tema-sepia .user-level-badge {
    background: #6b260b;
    color: #f4ecd8;
    box-shadow: none;
}

.tema-claro .user-level-badge {
    background: #1a1a1a;
    color: #fff;
    box-shadow: none;
}

.tema-sepia .comentario-autor:hover {
    color: #000 !important;
    text-shadow: none;
}

.tema-claro .comentario-autor:hover {
    color: #e5ac44 !important;
    text-shadow: none;
}

/* Eliminación de cuadros azules en móviles */
* { -webkit-tap-highlight-color: transparent; }
