/* Estilos globales */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Contenedor principal */
.main-content {
    min-height: calc(100vh - 150px);
    padding-top: 20px;
    padding-bottom: 20px;
}

.news-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 300px));
    gap: 15px;
    padding: 15px;
    max-width: 1800px;
    margin: 0 auto;
    justify-content: center;
    min-height: 100%;
    grid-auto-flow: dense;
}

/* Contenedor de tarjeta de noticia */
.news-card-container {
    width: 300px;
    height: 350px;
    position: relative;
    z-index: 1;
    transform-origin: top left;
    will-change: transform;
    perspective: 1000px; /* Mejora el efecto 3D */
    transition: transform 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.news-card-container:hover {
    z-index: 2;
}

/* Tarjeta de noticia */
.news-card {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    cursor: pointer;
    transform: translateZ(0);
    -webkit-font-smoothing: subpixel-antialiased;
    will-change: transform;
}

/* Modificamos este selector para excluir cuando el hover es sobre la imagen o el botón de eliminar */
.news-card-container:hover .news-card:not(.image-hover):not(.delete-hover) {
    transform: rotateY(180deg);
}

/* Agregamos clase para cuando el hover es sobre la imagen o el botón eliminar */
.news-card.image-hover, .news-card.delete-hover {
    transform: rotateY(0deg) !important;
}

/* Frente y reverso de la tarjeta */
.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid rgba(198, 214, 242, 0.16);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.28), 0 8px 20px rgba(0, 0, 0, 0.22);
}

.card-front {
    background: linear-gradient(155deg, rgba(255, 255, 255, 0.14), rgba(20, 31, 48, 0.35) 18%, rgba(9, 16, 28, 0.62) 74%);
    display: flex;
    flex-direction: column;
    transform: rotateY(0deg);
}

.card-back {
    background: linear-gradient(155deg, rgba(255, 255, 255, 0.14), rgba(20, 31, 48, 0.35) 18%, rgba(9, 16, 28, 0.62) 74%);
    transform: rotateY(180deg);
    padding: 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    contain: content;
}

/* Corregir orientación del texto en el reverso */
.card-back * {
    transform: scaleX(-1);
}

.card-back .news-description,
.card-back .news-meta,
.card-back .news-links,
.news-link {
    transform: none; 
}

.card-back .news-links * {
    transform: none !important;
}

/* Elementos de la tarjeta */
.news-card .news-image {
    width: 100%;
    height: 140px !important;
    object-fit: cover;
}

.news-title {
    flex: 0 0 auto;
    font-size: 1.05em;
    margin: 10px 15px 5px 15px;
    color: #f2f5fb;
    line-height: 1.28;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.news-title.is-title-overflow-4 {
    font-size: 0.9em;
    line-height: 1.22;
}

.news-meta {
    color: rgba(227, 233, 245, 0.58);
    font-size: 0.85em;
    padding: 10px 15px;
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.meta-info {
    flex-grow: 1;
}

.similarity-score {
    margin-left: 8px;
    font-weight: bold;
    color: #aaa;
}

.news-description {
    color: rgba(227, 233, 245, 0.86);
    font-size: 0.9em;
    line-height: 1.5;
    text-align: justify;
    flex: 1;
    margin: 10px 0;
    display: block;
    overflow-y: auto;
    hyphens: auto;
    word-break: break-word;
    overscroll-behavior: contain;
}

.news-description br {
    display: block;
    margin: 8px 0;
    content: "";
}

.news-description strong {
    color: #f2f5fb;
}

/* Estilo para los bulletpoints */
.news-description::before {
    content: none;
}

/* Ajustar el espacio para los bulletpoints personalizados */
.news-description {
    padding-left: 5px;
}

.news-description img {
    max-width: 100%;
    max-height: 15px;
    object-fit: cover;
    margin: 5px auto;
    display: block;
}

/* Enlaces */
.news-links {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: auto;
}

.news-link {
    text-decoration: none;
    color: #c6d6f5;
    font-size: 0.9em;
    font-weight: bold;
    padding: 6px 12px;
    border: 1px solid #c6d6f5;
    border-radius: 15px;
    transition: all 0.3s ease;
}

.news-link.icon-only {
    width: 34px;
    min-width: 34px;
    height: 30px;
    padding: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.news-link .news-icon {
    width: 17px;
    height: 17px;
    display: block;
    transform: none !important;
    pointer-events: none;
}

.news-link.share-opener {
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 30px;
    padding: 6px 9px;
    line-height: 1;
    color: #c6d6f5;
}

.news-link.share-opener .share-icon {
    width: 16px;
    height: 16px;
    display: block;
    fill: currentColor;
    transform: none !important;
    pointer-events: none;
}

.news-link.share-opener * {
    transform: none !important;
}

.news-link.share-opener.copied {
    color: #22c55e;
    border-color: #22c55e;
}

.news-link:hover {
    background: #8fb4e8;
    color: #06101f;
}

/* Estilo específico para el botón eliminar */
.news-link.delete-btn {
    border: 1px solid #ff4444;
    color: #ff4444;
    background-color: rgba(28, 14, 22, 0.72);
}

.news-link.delete-btn:hover {
    background-color: #ff4444;
    color: #06101f;
}

.news-link.save-btn {
    border: 1px solid #8fb4e8;
    color: #8fb4e8;
    background-color: rgba(15, 27, 43, 0.72);
}

.news-link.save-btn:hover {
    background-color: #8fb4e8;
    color: #06101f;
}

.news-link.save-btn.is-saved {
    border-color: #35b56a;
    color: #35b56a;
}

.news-link.save-btn.is-saved:hover {
    background-color: #35b56a;
    color: #06101f;
}

/* Paginación */
.pagination {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 15px auto;
    background-color: rgba(9, 16, 28, 0.62);
    padding: 15px 30px;
    border-radius: 12px;
    border: 1px solid rgba(207, 220, 241, 0.27);
    box-shadow: 0 14px 28px rgba(2, 8, 18, 0.45);
    max-width: 20%;
}

.pagination a, .pagination .active {
    padding: 8px 16px;
    text-decoration: none;
    color: #f2f5fb;
    font-size: 16px;
    border: none;
    transition: color 0.3s ease;
}

.pagination a:hover {
    color: #c6d6f5;
}

.pagination .active {
    background: none;
    color: #c6d6f5;
}

/* Botón de actualización */
.update-feed-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.22), rgba(143, 180, 232, 0.86));
    color: #f2f5fb;
    border: 1px solid rgba(207, 220, 241, 0.3);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(2, 8, 18, 0.45);
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.update-feed-btn:hover {
    transform: scale(1.1);
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.3), rgba(143, 180, 232, 0.94));
}

.update-feed-btn:disabled {
    background: #666;
    cursor: not-allowed;
    transform: none;
}

.update-feed-btn svg {
    width: 20px;
    height: 20px;
    transition: transform 0.5s ease;
}

.update-feed-btn.loading svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* Botón de deshacer (encima del de actualizar) */
.undo-btn {
    position: fixed;
    bottom: 76px;
    right: 20px;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.2), rgba(214, 188, 143, 0.85));
    color: #06101f;
    border: 1px solid rgba(207, 220, 241, 0.26);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(2, 8, 18, 0.45);
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.undo-btn:hover { transform: scale(1.1); background: linear-gradient(165deg, rgba(255, 255, 255, 0.3), rgba(214, 188, 143, 0.95)); }
.undo-btn:disabled { background: #666; color: #ccc; cursor: not-allowed; }
.undo-btn svg { width: 20px; height: 20px; }

/* Botón cambio de orden (encima del deshacer) */
.order-btn {
    position: fixed;
    bottom: 132px;
    right: 20px;
    background: linear-gradient(165deg, rgba(255, 255, 255, 0.18), rgba(123, 139, 185, 0.9));
    color: #f2f5fb;
    border: 1px solid rgba(207, 220, 241, 0.26);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(2, 8, 18, 0.45);
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.order-btn:hover { transform: scale(1.1); background: linear-gradient(165deg, rgba(255, 255, 255, 0.26), rgba(109, 128, 178, 0.95)); }
.order-btn:disabled { background: #666; cursor: not-allowed; }
.order-btn svg { width: 20px; height: 20px; }

/* Media Queries */
@media (max-width: 1080px) {
    .pagination {
        max-width: 90%;
        padding: 10px 15px;
    }

    .pagination a, .pagination .active {
        font-size: 14px;
        padding: 6px 12px;
    }
}

@media (max-width: 767px) {
    .main-content {
        min-height: calc(100vh - 100px);
    }

    /* Deshabilitar resaltado azul al tocar en móviles */
    .news-card-container {
        -webkit-tap-highlight-color: transparent; /* iOS/Safari */
        -webkit-user-select: none; /* Safari */
        -moz-user-select: none; /* Firefox */
        -ms-user-select: none; /* Internet Explorer/Edge */
        user-select: none; /* Standard */
        contain: layout paint style;
    }
    .news-card .news-image { filter: saturate(0.95) contrast(0.98); }
    .card-front, .card-back { box-shadow: 0 4px 8px rgba(0,0,0,0.22), 0 6px 14px rgba(0,0,0,0.18); }
}

/* Animación de eliminación (shrink + fade, barato en GPU) */
@keyframes deleteCard {
    0% {
        transform: translateZ(0) scale(1);
        opacity: 1;
    }
    60% {
        transform: translateZ(0) scale(0.92);
        opacity: 0.55;
    }
    100% {
        transform: translateZ(0) scale(0.85);
        opacity: 0;
    }
}

.news-card-container.deleting {
    pointer-events: none !important;
    z-index: 10 !important;
}

/* Colapso con reflow: altura reduce y vecinos ocupan el espacio */
.news-card-container.collapsing {
    overflow: hidden;
    will-change: height, width, margin, opacity, transform;
    transition: height 0.45s ease, width 0.45s ease, margin 0.45s ease, opacity 0.35s ease, transform 0.45s ease;
}
.news-card-container.collapsing .news-card {
    box-shadow: none !important;
}

/* Animación para la nueva tarjeta que entra */
@keyframes insertCard {
    0% {
        transform: scale(0.8) translateY(20px);
        opacity: 0;
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.news-card-container.inserting {
    animation: insertCard 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
    z-index: 5;
}

/* Notificación de nuevas noticias */
.notification {
    position: fixed;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(143, 180, 232, 0.9);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    z-index: 1001;
    box-shadow: 0 16px 30px rgba(2, 8, 18, 0.5);
    display: flex;
    align-items: center;
    gap: 15px;
    transition: top 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.5s ease;
    font-weight: bold;
    font-size: 16px;
    opacity: 0;
}

.notification.show {
    top: 110px; 
    opacity: 1;
}

.notification.hiding {
    opacity: 0;
}

.close-notification {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 0 0 10px;
    margin-left: auto;
}

.close-notification:hover {
    transform: scale(1.2);
}

/* Animación para nuevas noticias */
@keyframes newNewsHighlight {
    0% {
        transform: scale(0.8);
        opacity: 0;
        box-shadow: 0 0 30px rgba(0, 168, 255, 0.8);
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
        box-shadow: 0 0 40px rgba(0, 168, 255, 0.9);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.news-card-container.new-news {
    animation: newNewsHighlight 1.2s ease-out forwards;
    z-index: 5;
}

/* Animación para el contador actualizado */
@keyframes counterPulse {
    0% {
        transform: scale(1);
        color: #f2f5fb;
    }
    50% {
        transform: scale(1.3);
        color: #c6d6f5;
    }
    100% {
        transform: scale(1);
        color: #f2f5fb;
    }
}

.header-counter.counter-updated {
    animation: counterPulse 1s ease-in-out;
    display: inline-block;
}

/* Botón de eliminación para móvil */
.mobile-delete-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.3);
    transition: all 0.2s ease;
    opacity: 0.9;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    padding: 0;
    margin: 0;
    appearance: none;
    -webkit-appearance: none;
    outline: none;
}

.mobile-delete-btn::before,
.mobile-delete-btn::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 2px;
    background-color: #f2f5fb;
    border-radius: 1px;
}

.mobile-delete-btn::before {
    transform: rotate(45deg);
}

.mobile-delete-btn::after {
    transform: rotate(-45deg);
}

.mobile-delete-btn:hover,
.mobile-delete-btn:active {
    background-color: rgba(255, 68, 68, 0.8);
    transform: scale(1.1);
}

.mobile-delete-btn:active {
    transform: scale(0.95);
}

/* Modificar la media query para mostrar el botón en escritorio durante hover */
@media (min-width: 768px) {
    .mobile-delete-btn {
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease, transform 0.2s ease;
    }
    
    .news-card-container:hover .mobile-delete-btn {
        display: flex;
        opacity: 0.9;
    }
}

/* Animación de pulsación para el botón móvil */
@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    }
    50% {
        transform: scale(1.15); /* Slightly larger pulse */
        box-shadow: 0 4px 10px rgba(255, 68, 68, 0.5); /* Red shadow during pulse */
    }
    100% {
        transform: scale(1);
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    }
}

.mobile-delete-btn.pulse {
    animation: pulse 0.3s ease-in-out;
}

.short-answer {
    font-size: 0.8em;
    color: rgba(227, 233, 245, 0.68);
    margin: 0 15px 6px 15px;
    margin-top: auto;
    line-height: 1.4;
    font-style: italic;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    text-overflow: ellipsis;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Botón de modo lectura (encima del order-btn) */
.reader-btn {
    position: fixed;
    bottom: 188px;
    right: 20px;
    background: #10ac84;
    color: #f2f5fb;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(2, 8, 18, 0.45);
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reader-btn:hover {
    transform: scale(1.1);
    background: #0e9872;
}

.reader-btn:disabled {
    background: #666;
    cursor: not-allowed;
}

.reader-btn svg {
    width: 20px;
    height: 20px;
}

.reader-btn.active {
    background: #ee5a6f;
}

.reader-btn.active:hover {
    background: #d64456;
}

/* Overlay de modo lectura */
.reader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    width: 100vw;
    height: 100vh;
    background: #000 !important; /* Negro puro forzado */
    background-color: #000 !important;
    z-index: 10000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    overflow: hidden;
    touch-action: pan-y; /* Solo gestos verticales/horizontales, no scroll */
    -webkit-tap-highlight-color: transparent;
    color-scheme: dark;
}

.reader-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
}

/* Bloquear scroll del body cuando modo lectura está activo */
body.reader-active {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
    height: 100%;
    background: #000 !important; /* Forzar negro también en body */
}

.reader-content {
    color: #f2f5fb;
    text-align: center;
    padding: 40px 20px;
    max-width: 90%;
    user-select: none;
}

.reader-title {
    font-size: 1.8em;
    font-weight: bold;
    margin-bottom: 30px;
    line-height: 1.4;
    color: #333333; /* Gris tenue como la descripción para AMOLED */
}

.reader-text {
    font-size: 1.2em;
    line-height: 1.6;
    margin-bottom: 50px;
    color: #333333; /* Gris muy tenue para ahorrar batería AMOLED */
}

.reader-remaining {
    font-size: 1em;
    margin-bottom: 35px;
    color: #333333; /* Igual que el texto principal */
    opacity: 0.8;
}

.reader-gestures-hint {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85em;
    opacity: 0.4;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.reader-gestures-hint > div {
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

/* Ocultar hints después de 5 segundos */
.reader-overlay.hide-hints .reader-gestures-hint {
    opacity: 0;
    transition: opacity 0.5s ease;
}

@media (max-width: 768px) {
    .reader-btn {
        width: 48px;
        height: 48px;
        bottom: 188px; /* Encima del resto de botones, no centrado */
        right: 20px;
    }

    .reader-title {
        font-size: 1.5em;
        color: #2a2a2a; /* Aún más tenue en móvil */
    }

    .reader-text {
        font-size: 1.1em;
        color: #2a2a2a; /* Aún más tenue en móvil */
    }

    .reader-remaining {
        color: #2a2a2a;
    }

    .reader-gestures-hint {
        font-size: 0.75em;
        gap: 10px;
        color: #06101f; /* Hints muy oscuros para AMOLED */
    }

    .reader-gestures-hint > div {
        background: rgba(255, 255, 255, 0.05); /* Fondo casi imperceptible */
    }
}

