/* ============================================
   MOBILE RESPONSIVE STYLES
   Auto-detect and optimize for mobile devices
   ============================================ */

/* Tablet & Small Laptops (< 1024px) */
html,
body {
    overflow-x: hidden;
    width: 100%;
    margin: 0;
    padding: 0;
    position: relative;
}

img {
    max-width: 100%;
    height: auto;
}

@media (max-width: 1024px) {
    .container {
        padding: 40px 20px;
    }

    .header-container {
        padding: 0 20px;
    }

    .story-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 20px;
    }

    .hero h1 {
        font-size: 2.5rem;
    }

    .section-title {
        font-size: 1.8rem;
    }
}

/* Tablets (< 768px) */
@media (max-width: 768px) {

    /* Header optimization for tablets */
    .header {
        padding: 15px 0;
    }

    .header-container {
        padding: 0 15px;
        flex-wrap: nowrap !important;
        gap: 0;
        justify-content: space-between;
    }

    .logo {
        font-size: 1.3rem;
    }

    .nav {
        flex-wrap: wrap;
        gap: 8px;
    }

    .nav a {
        padding: 8px 14px;
        font-size: 0.9rem;
    }

    /* Hero optimization */
    .hero {
        padding: 50px 20px;
    }

    .hero h1 {
        font-size: 2rem;
    }

    .hero p {
        font-size: 1rem;
    }

    /* Container */
    .container {
        padding: 30px 15px;
    }

    /* Section titles */
    .section-title {
        font-size: 1.5rem;
        margin-bottom: 25px;
    }

    .section-title::before {
        width: 4px;
        height: 35px;
    }

    /* Story Grid - 3 columns on tablets */
    .story-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
        margin-bottom: 50px;
    }

    .story-card {
        border-radius: 12px;
    }

    .story-info {
        padding: 15px;
    }

    .story-title {
        font-size: 1rem;
        margin-bottom: 10px;
    }

    .story-meta {
        font-size: 0.8rem;
    }

    /* Carousel adjustments */
    .carousel-container {
        height: 400px;
    }

    .slide-inner {
        padding: 30px 20px;
        gap: 30px;
    }

    .slide-cover-col {
        flex: 0 0 200px;
    }

    .slide-title {
        font-size: 2rem;
    }

    .slide-description {
        font-size: 1rem;
        -webkit-line-clamp: 3;
        line-clamp: 3;
    }

    /* Footer */
    .footer-content {
        grid-template-columns: 1fr 1fr;
        gap: 40px;
    }

    .footer {
        padding: 40px 0 20px 0;
    }
}

/* Mobile devices (< 480px) */
@media (max-width: 480px) {

    /* ===== HEADER MOBILE MENU ===== */
    .header {
        padding: 12px 0;
    }

    .header-container {
        padding: 0 15px;
        position: relative;
    }

    /* Logo mobile */
    .logo {
        font-size: 1.1rem;
        gap: 8px;
    }

    .logo::before {
        font-size: 1.4rem;
    }

    .logo-text {
        letter-spacing: 0;
    }

    /* Hide desktop nav on mobile */
    .nav {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 300px;
        height: 100vh;
        background: linear-gradient(135deg, rgba(26, 26, 46, 0.98) 0%, rgba(22, 33, 62, 0.98) 100%);
        backdrop-filter: blur(20px);
        flex-direction: column;
        align-items: flex-start;
        padding: 80px 0 30px 0;
        gap: 0;
        z-index: 9999;
        transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
        border-right: 1px solid rgba(0, 212, 255, 0.2);
        overflow-y: auto;
    }

    .nav.active {
        left: 0;
    }

    .nav a {
        width: 100%;
        padding: 18px 30px;
        border-radius: 0;
        border-left: 4px solid transparent;
        font-size: 1rem;
    }

    .nav a::before {
        display: none;
    }

    .nav a:hover,
    .nav a.active {
        background: rgba(0, 212, 255, 0.1);
        border-left-color: #00d4ff;
    }

    /* Responsive mobile menu toggle button - HIDDEN */
    .mobile-menu-toggle {
        display: none !important;
    }

    /* Commenting out the toggle button animation styles
    .mobile-menu-toggle {
        display: flex;
        flex-direction: column;
        gap: 5px;
        width: 30px;
        height: 24px;
        cursor: pointer;
        position: relative;
        z-index: 10001;
    }

    .mobile-menu-toggle span {
        display: block;
        width: 100%;
        height: 3px;
        background: linear-gradient(135deg, #00d4ff, #00ff88);
        border-radius: 2px;
        transition: all 0.3s ease;
    }

    .mobile-menu-toggle.active span:nth-child(1) {
        transform: translateY(8px) rotate(45deg);
    }

    .mobile-menu-toggle.active span:nth-child(2) {
        opacity: 0;
    }

    .mobile-menu-toggle.active span:nth-child(3) {
        transform: translateY(-8px) rotate(-45deg);
    }
    */

    /* Mobile overlay when menu is open */
    .mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(0, 0, 0, 0.7);
        backdrop-filter: blur(5px);
        z-index: 9998;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

    .mobile-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* User menu adjustments for mobile */
    .user-menu {
        position: relative;
        z-index: 10000;
    }

    .user-trigger {
        padding: 6px 12px;
        gap: 8px;
    }

    .user-avatar {
        width: 30px;
        height: 30px;
        font-size: 0.8rem;
    }

    .user-info {
        display: none;
    }

    .user-dropdown {
        position: fixed !important;
        top: auto !important;
        bottom: 0;
        left: 0;
        right: 0;
        min-width: 100%;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
        max-height: 80vh;
        overflow-y: auto;
        z-index: 10001;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    }

    .user-menu.active .user-dropdown {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }

    /* Dropdown backdrop overlay on mobile */
    .user-menu::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(3px);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        z-index: 9999;
        pointer-events: none;
    }

    .user-menu.active::before {
        opacity: 1;
        visibility: visible;
        pointer-events: all;
    }

    /* ===== HERO SECTION ===== */
    .hero {
        padding: 40px 15px;
    }

    .hero h1 {
        font-size: 1.8rem;
        margin-bottom: 15px;
        letter-spacing: 0;
    }

    .hero p {
        font-size: 0.95rem;
        margin-bottom: 20px;
    }

    /* ===== CONTAINER ===== */
    .container {
        padding: 30px 15px;
    }

    /* ===== SECTION TITLES ===== */
    .section-title {
        font-size: 1.3rem;
        margin-bottom: 20px;
        gap: 10px;
    }

    .section-title::before {
        width: 4px;
        height: 30px;
    }

    /* Featured Carousel Header */
    .featured-carousel {
        margin-bottom: 40px;
    }

    .featured-header {
        margin-bottom: 20px;
    }

    .featured-header h2 {
        font-size: 1.3rem;
        gap: 8px;
    }

    /* ===== STORY GRID - 2 COLUMNS ON MOBILE ===== */
    .story-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-bottom: 40px;
    }

    .story-card {
        border-radius: 10px;
    }

    .story-cover {
        aspect-ratio: 2/3;
    }

    .story-status {
        top: 8px;
        right: 8px;
        padding: 4px 10px;
        font-size: 0.65rem;
    }

    .story-info {
        padding: 12px;
    }

    .story-title {
        font-size: 0.9rem;
        margin-bottom: 8px;
        -webkit-line-clamp: 2;
        line-clamp: 2;
    }

    .story-meta {
        font-size: 0.75rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    .card-stats {
        margin-top: 8px;
        padding-top: 8px;
        font-size: 0.7rem;
    }

    .stat-icon-group {
        gap: 8px;
    }

    /* ===== CAROUSEL MOBILE - HORIZONTAL LAYOUT LIKE PC ===== */
    .carousel-container {
        height: 280px !important;
        min-height: 280px !important;
        border-radius: 12px;
    }

    .slide-inner {
        flex-direction: row !important;
        padding: 20px 15px !important;
        gap: 15px !important;
        align-items: center !important;
        justify-content: flex-start !important;
    }

    .slide-cover-col {
        flex: 0 0 120px !important;
        width: 120px !important;
        height: auto !important;
    }

    .slide-cover {
        aspect-ratio: 2/3 !important;
        border-radius: 8px !important;
    }

    .slide-info-col {
        flex: 1 !important;
        align-items: flex-start !important;
        text-align: left !important;
        padding-right: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
    }

    .slide-title {
        font-size: 1.2rem !important;
        margin-bottom: 10px !important;
        line-height: 1.3 !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 2 !important;
        line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
    }

    .slide-badges {
        justify-content: flex-start !important;
        gap: 8px !important;
        margin-bottom: 12px !important;
        flex-wrap: wrap !important;
    }

    .badge {
        padding: 4px 10px !important;
        font-size: 0.7rem !important;
    }

    .slide-description {
        font-size: 0.8rem !important;
        margin-bottom: 12px !important;
        -webkit-line-clamp: 2 !important;
        line-clamp: 2 !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        display: -webkit-box !important;
        -webkit-box-orient: vertical !important;
    }

    .slide-meta {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 10px !important;
        margin-bottom: 15px !important;
        font-size: 0.75rem !important;
    }

    .meta-item {
        font-size: 0.75rem !important;
    }

    .btn-read-now {
        padding: 8px 20px !important;
        font-size: 0.85rem !important;
        border-radius: 20px !important;
    }

    /* Carousel navigation buttons */
    .carousel-nav-btn,
    .carousel-arrow {
        width: 35px;
        height: 35px;
        font-size: 0.9rem;
    }

    .carousel-prev,
    .carousel-arrow-left {
        left: 10px;
    }

    .carousel-next,
    .carousel-arrow-right {
        right: 10px;
    }

    /* ===== FOOTER MOBILE - COMPACT & CLEAN (VERTICAL STACK) ===== */
    .footer {
        padding: 20px 0 !important;
        margin-top: 30px !important;
    }

    .footer-content {
        display: flex !important;
        flex-direction: column !important;
        gap: 25px !important;
        padding: 0 20px;
        text-align: center !important;
    }

    /* Brand Section */
    .footer-column:first-child {
        margin-bottom: 10px;
        order: 1;
    }

    .footer-brand h3 {
        font-size: 1.5rem;
        margin-bottom: 10px;
        background: linear-gradient(135deg, #00d4ff 0%, #00ff88 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        display: inline-block;
    }

    .footer-description {
        display: none;
    }

    /* Social Icons */
    .social-links {
        display: flex;
        justify-content: center;
        gap: 15px;
        margin-bottom: 15px;
    }

    .social-icon {
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        background: rgba(0, 212, 255, 0.1);
        transition: all 0.3s ease;
    }

    .social-icon svg {
        width: 20px;
        height: 20px;
    }

    /* Footer Columns (Categories) - Stacked Vertically */
    .footer-column {
        width: 100% !important;
        text-align: center !important;
        order: 2;
    }

    .footer-column h4 {
        font-size: 1.1rem !important;
        margin-bottom: 15px !important;
        color: #00d4ff;
        font-weight: 700;
        text-transform: uppercase;
        border: none !important;
        display: block !important;
    }

    /* Aggressively override specific column styles from index.php */
    .footer-column .footer-links,
    .footer-column:nth-child(2) .footer-links,
    .footer-column:nth-child(3) .footer-links,
    .footer-column:nth-child(4) .footer-links {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: none !important;
        gap: 12px !important;
        align-items: center !important;
        margin-top: 0 !important;
    }

    /* Reset Link Styles (No Buttons!) */
    .footer-links a,
    .footer-column:nth-child(2) .footer-links a,
    .footer-column:nth-child(3) .footer-links a,
    .footer-column:nth-child(4) .footer-links a {
        background: none !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        width: auto !important;
        height: auto !important;
        border-radius: 0 !important;
        font-size: 0.95rem !important;
        font-weight: 400 !important;
        color: rgba(255, 255, 255, 0.7) !important;
        display: inline-block !important;
        text-align: center !important;
        justify-content: center !important;
    }

    .footer-links a:hover,
    .footer-column:nth-child(2) .footer-links a:hover,
    .footer-column:nth-child(3) .footer-links a:hover,
    .footer-column:nth-child(4) .footer-links a:hover {
        background: none !important;
        color: #00d4ff !important;
        transform: translateY(-2px) !important;
    }

    /* Hide Icons in links */
    .footer-links a::before,
    .footer-column:nth-child(2) .footer-links a::before,
    .footer-column:nth-child(3) .footer-links a::before,
    .footer-column:nth-child(4) .footer-links a::before {
        display: none !important;
    }

    /* Footer Bottom */
    .footer-bottom {
        margin-top: 30px !important;
        padding-top: 20px !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        text-align: center;
        order: 3;
    }

    .footer-bottom-content {
        font-size: 0.8rem !important;
        color: rgba(255, 255, 255, 0.5);
    }

    /* ===== RANKINGS SECTION ===== */
    .rankings-placeholder {
        padding: 40px 20px;
        border-radius: 15px;
    }

    .placeholder-icon {
        font-size: 3rem;
        margin-bottom: 15px;
    }

    .placeholder-title {
        font-size: 1.2rem;
        margin-bottom: 10px;
    }

    .placeholder-text {
        font-size: 0.95rem;
    }

    /* ===== UTILITIES ===== */
    .btn-upload {
        padding: 8px 16px;
        font-size: 0.85rem;
        border-radius: 8px;
    }

    /* Hide elements on mobile */
    .hide-mobile {
        display: none !important;
    }

    /* Show only on mobile */
    .show-mobile {
        display: block !important;
    }
}

/* Small mobile devices (< 375px) */
@media (max-width: 375px) {
    .hero h1 {
        font-size: 1.5rem;
    }

    .section-title {
        font-size: 1.2rem;
    }

    .story-grid {
        gap: 10px;
    }

    .story-title {
        font-size: 0.85rem;
    }

    .slide-title {
        font-size: 1.3rem;
    }

    .carousel-container {
        min-height: 450px;
    }
}

/* Landscape mode for mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .hero {
        padding: 30px 15px;
    }

    .hero h1 {
        font-size: 1.5rem;
    }

    .carousel-container {
        height: 350px;
        min-height: 350px;
    }

    .slide-inner {
        flex-direction: row;
        padding: 20px;
        gap: 20px;
    }

    .slide-cover-col {
        width: 120px;
    }

    .slide-info-col {
        text-align: left;
        align-items: flex-start;
    }

    .slide-title {
        font-size: 1.2rem;
    }

    .slide-description {
        -webkit-line-clamp: 2;
        line-clamp: 2;
    }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {

    /* Larger tap targets for touch devices */
    .nav a {
        min-height: 44px;
    }

    .story-card {
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .carousel-nav-btn,
    .carousel-arrow {
        min-width: 44px;
        min-height: 44px;
    }

    /* Remove hover effects on touch devices */
    .story-card:hover {
        transform: none;
    }

    .nav a:hover {
        background: transparent;
    }

    /* Active states for touch */
    .story-card:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    .nav a:active {
        background: rgba(0, 212, 255, 0.15);
    }

    /* ===== FEATURED CAROUSEL MOBILE REDESIGN ===== */
    .featured-section {
        padding: 0 15px;
        margin-top: 20px;
    }

    .carousel-container {
        height: auto !important;
        min-height: 700px !important;
        /* Increased again to fit button */
        border-radius: 16px !important;
        margin-bottom: 40px !important;
    }

    .slide-inner {
        flex-direction: column !important;
        padding: 20px 15px !important;
        /* Reduced top/side padding, tight fit */
        gap: 15px !important;
        justify-content: center !important;
        text-align: center !important;
        padding-bottom: 30px !important;
        /* Extra bottom clearance */
    }

    .slide-cover-col {
        width: 100% !important;
        display: flex !important;
        justify-content: center !important;
        margin-bottom: 10px !important;
    }

    .slide-cover {
        width: 150px !important;
        /* Slightly smaller to save space */
        height: 225px !important;
        border-radius: 12px !important;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5) !important;
    }

    .slide-info-col {
        width: 100% !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }

    .slide-title {
        font-size: 1.5rem !important;
        /* Slightly smaller text */
        line-height: 1.3 !important;
        margin-bottom: 10px !important;
        text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5) !important;
    }

    .slide-badges {
        justify-content: center !important;
        gap: 10px !important;
        margin-bottom: 20px !important;
        flex-wrap: wrap !important;
    }

    .badge {
        font-size: 0.75rem !important;
        padding: 6px 12px !important;
    }

    .slide-description {
        font-size: 0.9rem !important;
        line-height: 1.5 !important;
        margin-bottom: 25px !important;
        display: -webkit-box !important;
        -webkit-line-clamp: 3 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
        color: rgba(255, 255, 255, 0.8) !important;
    }

    .slide-meta {
        justify-content: center !important;
        margin-bottom: 25px !important;
        font-size: 0.85rem !important;
    }

    .btn-read-now {
        padding: 12px 35px !important;
        font-size: 1rem !important;
        width: auto !important;
        min-width: 180px !important;
        margin-bottom: 10px !important;
    }

    /* Adjust Navigation Arrows */
    .carousel-nav-btn {
        width: 35px !important;
        height: 35px !important;
        background: rgba(0, 0, 0, 0.5) !important;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
    }

    .carousel-prev {
        left: 10px !important;
    }

    .carousel-next {
        right: 10px !important;
    }

    /* Section Title Fix */
    .featured-header h2 {
        font-size: 1.5rem !important;
        padding-left: 10px !important;
        margin-bottom: 20px !important;
        display: flex !important;
        align-items: center !important;
    }

    .featured-header h2 span {
        margin-right: 10px !important;
    }

    /* ===== COMMENTS SECTION RESPONSIVE ===== */
    .comments-section {
        padding: 20px 15px !important;
        margin: 20px 0 !important;
    }

    .comments-header {
        flex-direction: row !important;
        gap: 10px !important;
        margin-bottom: 20px !important;
    }

    .comments-header h3 {
        font-size: 1.2rem !important;
    }

    .comments-count {
        font-size: 0.8rem !important;
        padding: 3px 10px !important;
    }

    /* Comment Form Mobile */
    .comment-form {
        flex-direction: column !important;
        gap: 12px !important;
        margin-bottom: 25px !important;
    }

    .comment-avatar {
        width: 40px !important;
        height: 40px !important;
        font-size: 1rem !important;
        align-self: flex-start !important;
    }

    .comment-input-wrapper {
        width: 100% !important;
    }

    .comment-textarea {
        min-height: 80px !important;
        padding: 12px !important;
        font-size: 0.9rem !important;
    }

    .comment-submit-btn {
        padding: 10px 20px !important;
        font-size: 0.9rem !important;
        width: 100% !important;
    }

    /* Comments List Mobile */
    .comments-list {
        gap: 15px !important;
    }

    .comment-item {
        gap: 12px !important;
        flex-direction: row !important;
    }

    .comment-content {
        padding: 12px !important;
        font-size: 0.9rem !important;
    }

    .comment-author {
        font-size: 0.95rem !important;
    }

    .comment-time {
        font-size: 0.75rem !important;
        display: block !important;
        margin-left: 0 !important;
        margin-top: 2px !important;
    }

    .comment-text {
        font-size: 0.9rem !important;
        margin-top: 8px !important;
    }

    /* Comment Actions Mobile */
    .comment-actions {
        gap: 12px !important;
        margin-top: 8px !important;
        flex-wrap: wrap !important;
    }

    .btn-like,
    .btn-reply {
        font-size: 0.85rem !important;
        padding: 6px 12px !important;
    }

    /* Reply Form Mobile */
    .reply-form {
        margin-top: 12px !important;
        padding: 12px !important;
    }

    .reply-form textarea {
        min-height: 70px !important;
        padding: 10px !important;
        font-size: 0.85rem !important;
    }

    .reply-form button {
        padding: 8px 16px !important;
        font-size: 0.85rem !important;
        width: 100% !important;
    }

    /* Replies Mobile */
    .replies {
        margin-top: 15px !important;
        margin-left: 15px !important;
        padding-left: 12px !important;
    }

    .reply-item {
        gap: 10px !important;
        margin-bottom: 12px !important;
    }

    .reply-item .comment-avatar {
        width: 32px !important;
        height: 32px !important;
        font-size: 0.85rem !important;
    }

    .reply-item .comment-content {
        padding: 10px !important;
    }

    /* No Comments Mobile */
    .no-comments {
        padding: 30px 15px !important;
    }

    .no-comments-icon {
        font-size: 2.5rem !important;
    }

    .comment-login-prompt {
        padding: 25px 15px !important;
        font-size: 0.9rem !important;
    }
}

/* High DPI screens (Retina) */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {

    .story-cover img,
    .slide-cover img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Force override of inline styles for footer links */
@media (max-width: 480px) {
    .footer-links a {
        background: none !important;
        border: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
        border-radius: 0 !important;
        padding: 8px 0 !important;
        justify-content: flex-start !important;
        box-shadow: none !important;
        min-width: 0 !important;
        text-align: left !important;
        font-weight: 400 !important;
        color: rgba(255, 255, 255, 0.7) !important;
    }

    .footer-links a:hover {
        background: none !important;
        color: #00d4ff !important;
        transform: translateX(5px) !important;
    }

    .footer-column:nth-child(2) .footer-links a::before,
    .footer-column:nth-child(3) .footer-links a::before,
    .footer-column:nth-child(4) .footer-links a::before {
        display: none !important;
    }

    .footer-column h4 {
        font-size: 1rem !important;
        margin-bottom: 5px !important;
        text-transform: none !important;
        letter-spacing: 0 !important;
        color: #fff !important;
        border-bottom: none !important;
    }

    /* Adjust grid to look like a list if needed, or keep compact grid */
    .footer-links {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0 15px !important;
    }
}