/** CSS RANKING APP JUEBLO (Producción v33) */

#ranking-view {
    display: flex; flex-direction: column;
    background: #f8f9fa; 
    width: 100%; height: 100%; 
    position: fixed; top: 75px; left: 0; 
    z-index: 2000; overflow: hidden; padding: 0 !important;
}

#ranking-view .rk-master-container { width: 100%; max-width: 600px; margin: 0 auto; padding: 0 15px; box-sizing: border-box; }

/* HEADER Y TÍTULO */
#ranking-view .ranking-fixed-top { flex: 0 0 auto; background: #f8f9fa; width: 100%; z-index: 50; padding-bottom: 5px; border-bottom: 1px solid rgba(0,0,0,0.05); box-shadow: 0 4px 15px rgba(0,0,0,0.02); }
#ranking-view .rk-main-title { position: relative; font-family: 'Crimson Pro', serif; font-size: 2rem; font-weight: 900; color: #2d5a27; text-align: center; margin: 10px 0 2px 0; display: flex; align-items: center; justify-content: center; }
#ranking-view .ranking-subtitle { text-align: center; font-weight: 700; color: #999; font-size: 0.75rem; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 10px; display: flex; align-items: center; justify-content: center; }

/* BOTONES DE ACCIÓN EN CABECERA */
#ranking-view .rk-header-actions { position: absolute; right: 0; display: flex; gap: 15px; align-items: center; }
.rk-refresh { background: transparent; border: none; color: #2d5a27; font-size: 1.3rem; cursor: pointer; transition: color 0.2s, transform 0.1s; padding: 0; display: flex; align-items: center; touch-action: manipulation; }
.rk-refresh:active { color: #e67e22; transform: scale(0.9); }
.rk-refresh.spin i { animation: spinRefresh 1s linear infinite; color: #aaa; }
@keyframes spinRefresh { 100% { transform: rotate(360deg); } }

/* BUSCADOR DESPLEGABLE */
#rk-search-container { overflow: hidden; transition: max-height 0.3s ease, opacity 0.3s ease, margin-bottom 0.3s ease; max-height: 0; opacity: 0; margin-bottom: 0; }
#rk-search-container.show { max-height: 60px; opacity: 1; margin-bottom: 10px; }
.rk-search-box { position: relative; width: 100%; }
.rk-search-box input { width: 100%; padding: 10px 40px 10px 38px; border-radius: 12px; border: 1px solid #ddd; font-family: 'Inter', sans-serif; font-size: 0.9rem; box-sizing: border-box; outline: none; transition: border-color 0.2s; background: #fff; }
.rk-search-box input:focus { border-color: #2d5a27; box-shadow: 0 0 0 3px rgba(45, 90, 39, 0.1); }
.rk-search-box i.fa-search { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: #aaa; font-size: 0.95rem; }
.rk-search-clear { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: #aaa; font-size: 1.1rem; cursor: pointer; display: none; transition: color 0.2s; touch-action: manipulation; }
.rk-search-clear:active { color: #e74c3c; }

/* FILTROS PREMIUM (SEGMENTED CONTROL Y UNDERLINE) CON FIX PARA IOS */
#ranking-view .rk-filter-box { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; width: 100%; }
#ranking-view .rk-pill-row { background: #e9ecef; border-radius: 12px; padding: 4px; display: flex; width: 100%; box-shadow: inset 0 2px 4px rgba(0,0,0,0.03); }
#ranking-view .rk-pill { flex: 1; border: none; background: transparent; padding: 8px 5px; border-radius: 10px; font-size: 0.85rem; font-weight: 700; color: #7f8c8d; cursor: pointer; transition: all 0.1s ease; text-align: center; display: flex; align-items: center; justify-content: center; gap: 6px; z-index: 2; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; will-change: background-color, transform; }
#ranking-view .rk-pill.active { background: #fff; color: #2d5a27; box-shadow: 0 2px 8px rgba(0,0,0,0.08); transform: scale(1.02); }

.rk-pill-time-row { display: flex; border-bottom: 2px solid #eaeaea; overflow-x: auto; scrollbar-width: none; gap: 5px; padding-bottom: 1px; }
.rk-pill-time-row::-webkit-scrollbar { display: none; }
#ranking-view .rk-pill-time { flex: 1; min-width: max-content; background: transparent; border: none; padding: 8px 10px; font-size: 0.75rem; font-weight: 800; color: #999; border-bottom: 3px solid transparent; margin-bottom: -3px; transition: all 0.1s; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; will-change: color, border-color; }
#ranking-view .rk-pill-time.active { color: #2d5a27; border-bottom: 3px solid #2d5a27; }

/* FIX iOS TAPS: Evitar que el clic caiga en los iconos o el texto interno del botón */
#ranking-view .rk-pill > *, #ranking-view .rk-pill-time > * { pointer-events: none; }

/* CABECERA DE LA TABLA (PASTILLA) */
#ranking-view .rk-grid-layout { display: grid; grid-template-columns: 50px 1fr 90px; align-items: center; gap: 10px; }
#ranking-view .rk-col-header { 
    font-size: 0.65rem; font-weight: 800; color: #7f8c8d; text-transform: uppercase; letter-spacing: 1px; 
    padding: 8px 10px; margin-top: 5px; margin-bottom: 2px;
    background: #e9ecef; border-radius: 10px;
}
#ranking-view .rk-col-header span:nth-child(1) { text-align: center; } 
#ranking-view .rk-col-header span:nth-child(2) { text-align: left; }
#ranking-view .rk-col-header span:nth-child(3) { text-align: right; }

/* SCROLL */
#ranking-view .ranking-scroll-area { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-top: 5px; background: #f8f9fa; padding-bottom: 200px; width: 100%; scroll-behavior: smooth; }
#ranking-view .ranking-list-container { display: flex; flex-direction: column; gap: 8px; }

/* SKELETON LOADING PREMIUM */
.rk-skeleton-wrapper { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.rk-skeleton-card { background: #fff; border-radius: 14px; padding: 12px 10px; display: grid; grid-template-columns: 50px 1fr 90px; align-items: center; gap: 10px; border: 1px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.02); }
.sk-anim { background: #eee; background: linear-gradient(110deg, #ececec 8%, #f5f5f5 18%, #ececec 33%); background-size: 200% 100%; animation: 1.5s shine linear infinite; }
@keyframes shine { to { background-position-x: -200%; } }
.sk-pos { width: 22px; height: 22px; border-radius: 6px; margin: 0 auto; }
.sk-shield { width: 32px; height: 32px; border-radius: 8px; margin-right: 10px; flex-shrink: 0; }
.sk-text-1 { width: 65%; height: 12px; border-radius: 4px; margin-bottom: 6px; }
.sk-text-2 { width: 40%; height: 10px; border-radius: 4px; }
.sk-points { width: 50px; height: 16px; border-radius: 4px; margin-left: auto; }

/* TARJETAS Y ANIMACIÓN DE ENTRADA */
@keyframes slideInCard { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }
#ranking-view .rank-card {
    background: #fff; border-radius: 14px; padding: 12px 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02); border: 1px solid #fff;
    width: 100%; box-sizing: border-box; display: grid; grid-template-columns: 50px 1fr 90px; align-items: center; gap: 10px;
    transition: transform 0.1s; opacity: 0; animation: slideInCard 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    touch-action: manipulation; cursor: pointer; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
#ranking-view .rank-card:active { transform: scale(0.98); }

/* PODIO PREMIUM 3D */
#ranking-view .rank-card.gold { 
    background: linear-gradient(135deg, #fffdf5 0%, #fff 100%); 
    border: 1px solid #fae588; border-left: 5px solid #f1c40f;
    transform: scale(1.02); margin-bottom: 4px; margin-top: 4px; box-shadow: 0 6px 15px rgba(241, 196, 15, 0.15); z-index: 1;
}
#ranking-view .rank-card.silver { 
    background: linear-gradient(135deg, #fcfcfc 0%, #fff 100%);
    border: 1px solid #e0e0e0; border-left: 5px solid #bdc3c7;
    transform: scale(1.01); margin-bottom: 2px; box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
#ranking-view .rank-card.bronze { 
    background: linear-gradient(135deg, #fffaf6 0%, #fff 100%);
    border: 1px solid #f5d3b8; border-left: 5px solid #d35400;
    box-shadow: 0 3px 8px rgba(211, 84, 0, 0.08);
}

#ranking-view .rk-pos-badge { width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: 'Crimson Pro', serif; font-weight: 800; font-size: 1.2rem; color: #ccc; line-height: 1; }
#ranking-view .rank-card.gold .rk-pos-badge { color: #f1c40f; font-size: 1.5rem; text-shadow: 0 2px 4px rgba(241, 196, 15, 0.3); }
#ranking-view .rank-card.silver .rk-pos-badge { color: #95a5a6; font-size: 1.35rem; text-shadow: 0 2px 4px rgba(149, 165, 166, 0.3); }
#ranking-view .rank-card.bronze .rk-pos-badge { color: #d35400; font-size: 1.35rem; text-shadow: 0 2px 4px rgba(211, 84, 0, 0.3); }

#ranking-view .rk-info-flex { display: flex; align-items: center; overflow: hidden; width: 100%; }
#ranking-view .rk-shield { width: 32px; height: 32px; object-fit: contain; margin-right: 10px; flex-shrink: 0; }
#ranking-view .rk-shield-fallback { width: 32px; height: 32px; margin-right: 10px; flex-shrink: 0; border-radius: 8px; background: #f0f0f0; color: #aaa; display: flex; align-items: center; justify-content: center; font-size: 0.9rem; }
#ranking-view .rk-shield-fallback.prov-icon { background: #e3f2fd; color: #2196f3; }

#ranking-view .rk-texts { display: flex; flex-direction: column; overflow: hidden; flex: 1; }
#ranking-view .rk-main-txt { font-weight: 700; color: #333; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; display: flex; align-items: center; }
#ranking-view .rk-sub-txt { font-size: 0.75rem; color: #999; display: flex; align-items: center; gap: 4px; }

/* PUNTOS Y DISTANCIA */
#ranking-view .rk-points-wrapper { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; flex-shrink: 0; margin-left: 10px; }
#ranking-view .rk-points { font-family: 'Crimson Pro', serif; font-weight: 900; font-size: 1.1rem; color: #2d5a27; white-space: nowrap; line-height: 1; }
.rk-dist-list { 
    font-size: 0.65rem; color: #d35400; background: #fdf2e9; 
    padding: 3px 6px; border-radius: 6px; font-weight: 800; 
    margin-top: 4px; display: inline-flex; align-items: center; gap: 3px; 
}

/* EXTRAS (ICONOS) */
#ranking-view .rk-gift-icon { color: #e74c3c; margin-left: 6px; font-size: 1rem; cursor: pointer; animation: wobble 2s infinite; flex-shrink: 0; }
@keyframes wobble { 0%,100%{transform:rotate(0)} 25%{transform:rotate(-10deg)} 75%{transform:rotate(10deg)} }
.rk-streak { color: #e67e22; font-size: 1rem; margin-left: 6px; cursor: pointer; animation: pulseStreak 1.5s infinite; flex-shrink: 0; }
@keyframes pulseStreak { 0% { transform: scale(1); } 50% { transform: scale(1.15); } 100% { transform: scale(1); } }

/* FOOTER FLOTANTE */
@keyframes slideUpFooter { 0% { transform: translateX(-50%) translateY(120px); opacity: 0; } 100% { transform: translateX(-50%) translateY(0); opacity: 1; } }
#ranking-view .ranking-footer-wrapper { position: absolute; bottom: 90px; left: 50%; width: 90%; max-width: 450px; z-index: 100; transform: translateX(-50%) translateY(120px); animation: slideUpFooter 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; }
#ranking-view .rk-my-card { display: flex; align-items: center; background: #222; color: white; border-radius: 50px; padding: 8px 15px; box-shadow: 0 15px 40px rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.15); touch-action: manipulation; }
#ranking-view .rk-my-pos { background: #f1c40f; color: #333; width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.9rem; margin-right: 12px; flex-shrink: 0; transition: all 0.3s; }
#ranking-view .rk-my-pos.unranked { background: #555; color: #aaa; box-shadow: inset 0 2px 4px rgba(0,0,0,0.2); }
#ranking-view .rk-my-info { flex: 1; overflow: hidden; display: flex; flex-direction: column; justify-content: center; }
#ranking-view .rk-my-name { font-weight: 800; font-size: 0.9rem; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; line-height: 1.1; }
#ranking-view .rk-my-pts { font-size: 0.75rem; opacity: 0.8; color: #ddd; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1; }
.rk-dist-footer { font-size: 0.7rem; color: #f1c40f; font-weight: 700; margin-top: 3px; display: block; opacity: 0.9; line-height: 1; }
#ranking-view .rk-divider-vert { width: 1px; height: 25px; background: rgba(255,255,255,0.2); margin: 0 10px; }
#ranking-view .rk-action-btn { background: transparent; border: none; color: #fff; width: 35px; height: 35px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; cursor: pointer; transition: 0.2s; touch-action: manipulation; }
#ranking-view .rk-action-btn:active { background: rgba(255,255,255,0.2); }

#ranking-view .rank-card.is-me { border: 2px solid #2d5a27; background-color: #f4fcf6; transform: scale(1.03); box-shadow: 0 4px 15px rgba(45, 90, 39, 0.2); z-index: 2; }

/* EL PUEBLO DUERME (ESTADO VACÍO) */
.rk-empty-state { text-align: center; padding: 60px 20px; color: #888; animation: slideInCard 0.5s ease forwards; }
.rk-empty-state i { font-size: 4.5rem; color: #f39c12; margin-bottom: 15px; text-shadow: 0 4px 10px rgba(243, 156, 18, 0.3); }
.rk-empty-state h3 { font-family: 'Crimson Pro', serif; font-size: 1.8rem; color: #2d5a27; margin-bottom: 10px; line-height: 1.1; }
.rk-empty-state p { font-size: 1rem; line-height: 1.5; color: #666; margin: 0; }

/* BOTÓN VOLVER ARRIBA */
.rk-back-top { position: fixed; bottom: 80px; right: 20px; width: 45px; height: 45px; background: #2d5a27; color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; box-shadow: 0 4px 12px rgba(0,0,0,0.2); cursor: pointer; opacity: 0; visibility: hidden; transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); z-index: 1500; border: none; transform: translateY(20px) scale(0.8); touch-action: manipulation; }
.rk-back-top.show { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.rk-back-top:active { transform: scale(0.9); }

/* --- MODALES --- */
.rk-modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); z-index: 9999; display: flex; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: all 0.3s ease; }
.rk-modal-overlay.show { opacity: 1; visibility: visible; }
.rk-modal-card { background: #fff; border-radius: 20px; padding: 30px 20px 25px 20px; width: 85%; max-width: 340px; text-align: center; position: relative; box-shadow: 0 20px 50px rgba(0,0,0,0.2); transform: translateY(20px); transition: transform 0.3s ease; }
.rk-modal-overlay.show .rk-modal-card { transform: translateY(0); }
.rk-modal-close { position: absolute; top: 12px; right: 15px; background: #f0f0f0; border: none; border-radius: 50%; width: 30px; height: 30px; font-size: 1.2rem; color: #888; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: 0.2s; z-index: 10; touch-action: manipulation; }
.rk-modal-close:hover { background: #e0e0e0; color: #333; }

.rk-modal-shield-container { width: 130px; height: 130px; margin: 0 auto 20px auto; display: flex; align-items: center; justify-content: center; background: #f9f9f9; border-radius: 24px; box-shadow: inset 0 2px 5px rgba(0,0,0,0.05); padding: 10px; }
.rk-modal-shield-container img, .rk-modal-shield-container .rk-shield { width: 100px !important; height: 100px !important; object-fit: contain; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.15)); margin: 0 !important; }
.rk-modal-shield-container .rk-shield-fallback { width: 100% !important; height: 100% !important; border-radius: 18px; font-size: 4rem !important; margin: 0 !important; }
.rk-modal-title { font-family: 'Crimson Pro', serif; font-size: 1.6rem; font-weight: 800; color: #2d5a27; margin-bottom: 5px; line-height: 1.1; }
.rk-modal-subtitle { font-size: 0.95rem; color: #666; font-weight: 600; margin-bottom: 15px; }
.rk-modal-points { display: inline-flex; align-items: center; gap: 8px; background: #fffdf5; border: 1px solid #f1c40f; padding: 8px 20px; border-radius: 50px; font-size: 1.1rem; font-weight: 800; color: #d4ac0d; }

.rk-gift-modal-card { background: #fff; border-radius: 24px; padding: 40px 25px 30px 25px; width: 85%; max-width: 360px; text-align: center; position: relative; box-shadow: 0 25px 60px rgba(0,0,0,0.25); transform: translateY(30px) scale(0.95); transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.rk-modal-overlay.show .rk-gift-modal-card { transform: translateY(0) scale(1); }
.rk-gift-img-wrapper { margin-bottom: 20px; display: flex; justify-content: center; align-items: center; min-height: 120px; }
.rk-gift-img { height: 160px; width: auto; max-width: 100%; object-fit: contain; filter: drop-shadow(0 10px 20px rgba(0,0,0,0.15)); }
.rk-gift-icon-large { font-size: 4rem; color: #f1c40f; filter: drop-shadow(0 5px 10px rgba(241, 196, 15, 0.4)); }
.rk-gift-title { font-family: 'Crimson Pro', serif; font-size: 1.8rem; font-weight: 900; color: #333; margin-bottom: 10px; line-height: 1.2; }
.rk-gift-desc { font-size: 1rem; color: #666; line-height: 1.5; margin-bottom: 0; }

/* BLOQUEO LANDSCAPE */
#landscape-warning { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: #222; color: #fff; z-index: 9999; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; }
@media screen and (orientation: landscape) and (max-height: 500px) {
    #landscape-warning { display: flex !important; }
    #ranking-view > *:not(#landscape-warning) { display: none !important; } 
}