/* ==========================================================================
   MOBILE OPTIMIZATIONS — Targeted fixes for all visible issues
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. GLOBAL — prevent horizontal overflow, touch defaults
   -------------------------------------------------------------------------- */
@media (max-width: 860px) {
    html, body {
        overflow-x: hidden;
        -webkit-text-size-adjust: 100%;
    }

    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* Minimum 44px tap targets */
    a, button, [role="button"] {
        min-height: 44px;
    }

    /* No hover transforms on touch */
    .project-card-inner:hover,
    .tech-category-card:hover,
    .edu-card:hover,
    .credential-card:hover,
    .contact-card:hover {
        transform: none !important;
    }
}

/* --------------------------------------------------------------------------
   2. BRAND LOGO — fix "Dilshan" color in nav and mobile drawer
   -------------------------------------------------------------------------- */
@media (max-width: 860px) {
    .brand-last {
        color: var(--text-primary);
    }
    .brand-dot {
        color: var(--text-muted);
    }
}

/* --------------------------------------------------------------------------
   3. SITE HEADER — compact, clean
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .site-header {
        padding: 0.65rem 1rem;
    }
    .site-header.scrolled {
        padding: 0.5rem 1rem;
    }
    .brand-logo {
        font-size: 1.1rem;
    }
    .header-actions {
        gap: 0.4rem;
    }
    .theme-toggle-btn {
        width: 40px;
        height: 40px;
        font-size: 0.95rem;
    }
    .hamburger-btn {
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* --------------------------------------------------------------------------
   4. MOBILE NAV DRAWER — gray theme, no blue
   -------------------------------------------------------------------------- */
@media (max-width: 860px) {
    .mobile-nav-panel {
        width: min(88vw, 320px);
        padding: 1.5rem 1.25rem;
        background: var(--bg-surface);
    }

    .mobile-nav-header {
        font-size: 1.1rem;
        padding-bottom: 1.25rem;
    }

    /* Force gray on brand name inside drawer */
    .mobile-nav-header .brand-first,
    .mobile-nav-header .brand-last {
        color: var(--text-primary);
    }
    .mobile-nav-header .brand-dot {
        color: var(--text-muted);
    }

    .mobile-close-btn {
        width: 36px;
        height: 36px;
        font-size: 1.3rem;
        background: var(--bg-card);
        border-color: var(--border-subtle);
        color: var(--text-secondary);
    }

    .mobile-links {
        margin-top: 1rem;
        gap: 0.25rem;
    }

    .mobile-nav-link {
        padding: 0.85rem 1rem;
        font-size: 0.93rem;
        border-radius: 10px;
        min-height: 50px;
        color: var(--text-secondary);
        background: transparent;
    }

    /* Gray icon — no blue */
    .mobile-nav-link i {
        width: 22px;
        font-size: 0.95rem;
        color: var(--text-muted) !important;
        text-align: center;
    }

    /* Active / hover — use theme vars only, no hardcoded blue */
    .mobile-nav-link:hover,
    .mobile-nav-link.active {
        color: var(--text-primary);
        background: var(--bg-card);
        font-weight: 600;
    }

    .mobile-nav-link:hover i,
    .mobile-nav-link.active i {
        color: var(--text-primary) !important;
    }

    .btn-cv-mobile {
        padding: 0.85rem;
        font-size: 0.88rem;
        border-radius: 10px;
        min-height: 48px;
        background: var(--accent-gradient);
        color: var(--text-inverse);
    }

    .mobile-socials {
        gap: 0.5rem;
        justify-content: space-evenly;
    }

    .mobile-socials a {
        font-size: 1.25rem;
        padding: 0.5rem;
        color: var(--text-secondary);
    }
}

/* --------------------------------------------------------------------------
   5. HERO SECTION — photo visible, clean layout
   -------------------------------------------------------------------------- */
@media (max-width: 1100px) {
    .hero-container {
        grid-template-columns: 1fr;
        gap: 2.5rem;
        text-align: center;
    }

    .hero-text-col {
        align-items: center;
        order: 2;
    }

    .hero-visual-col {
        order: 1;
    }

    .hero-eyebrow,
    .hero-subtitle,
    .hero-actions,
    .hero-social-row {
        justify-content: center;
    }

    .hero-description {
        margin: 0 auto;
        max-width: 540px;
    }
}

@media (max-width: 640px) {
    .hero-section {
        padding: 5.5rem 1rem 2.5rem;
        min-height: auto;
    }

    .hero-container {
        gap: 2rem;
    }

    /* Photo — prominent on mobile */
    .hero-visual-col {
        order: 1;
    }

    .hero-text-col {
        order: 2;
    }

    .hero-photo-wrapper {
        width: 100%;
        max-width: 220px;
        margin: 0 auto;
    }

    .photo-frame {
        border-radius: 20px;
    }

    .photo-frame-glow {
        display: none;
    }

    /* Status pill */
    .hero-status-pill {
        font-size: 0.75rem;
        padding: 0.3rem 0.75rem;
        gap: 0.5rem;
    }

    /* Eyebrow */
    .hero-eyebrow {
        font-size: 0.72rem;
        letter-spacing: 0.1em;
        gap: 0.5rem;
    }

    /* Title */
    .hero-title {
        font-size: clamp(1.9rem, 8.5vw, 2.5rem);
        line-height: 1.1;
        letter-spacing: -0.02em;
    }

    /* Subtitle */
    .hero-subtitle {
        font-size: clamp(0.85rem, 3.5vw, 1rem);
        line-height: 1.5;
        flex-direction: column;
        align-items: center;
        gap: 0.1rem;
    }

    .hero-subtitle .separator {
        display: none;
    }

    /* Description */
    .hero-description {
        font-size: 0.88rem;
        line-height: 1.65;
        max-width: 100%;
    }

    /* Terminal */
    .hero-terminal {
        font-size: 0.74rem;
        padding: 0.5rem 0.85rem;
        border-radius: 10px;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    /* CTA Buttons — 2-col grid */
    .hero-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.6rem;
        width: 100%;
    }

    .hero-actions .btn {
        padding: 0.75rem 0.5rem;
        font-size: 0.84rem;
        min-height: 46px;
        justify-content: center;
        gap: 0.4rem;
        white-space: nowrap;
    }

    /* Social icons */
    .hero-social-row {
        gap: 0.5rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .social-icon-btn {
        width: 44px;
        height: 44px;
        font-size: 1rem;
    }

    /* Hide decorative */
    .hero-doodle,
    .scroll-down-hint,
    .hero-info-card {
        display: none !important;
    }
}

@media (max-width: 400px) {
    .hero-actions {
        grid-template-columns: 1fr;
    }

    .hero-photo-wrapper {
        max-width: 180px;
    }
}

/* --------------------------------------------------------------------------
   6. ABOUT SECTION — fix stat layout and icon colors
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .about-section {
        padding: 4rem 0;
    }

    .section-container {
        padding: 0 1rem;
    }

    .section-heading {
        font-size: clamp(1.6rem, 7vw, 2rem);
        line-height: 1.2;
    }

    .section-subtext {
        font-size: 0.88rem;
        margin-bottom: 2rem;
    }

    .about-grid {
        gap: 2rem;
    }

    .about-body-text {
        font-size: 0.9rem;
        line-height: 1.7;
    }

    .about-cta-row {
        flex-direction: row;
        gap: 0.75rem;
        flex-wrap: wrap;
    }

    .about-cta-row .btn-outline-dark {
        font-size: 0.84rem;
        padding: 0.65rem 1.1rem;
    }

    /* Stats: 2-col grid */
    .stats-counter-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .stat-counter-card {
        padding: 1rem 0.85rem;
        border-radius: 14px;
        text-align: center;
    }

    .stat-num {
        font-size: 1.75rem;
        line-height: 1.1;
    }

    .stat-label {
        font-size: 0.72rem;
    }

    /* Interests: 2-col */
    .interests-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .interest-pill {
        padding: 0.65rem 0.5rem;
        font-size: 0.8rem;
        border-radius: 10px;
        gap: 0.4rem;
        text-align: center;
    }
}

/* --------------------------------------------------------------------------
   7. PROJECTS — single col, scrollable filter bar
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .projects-section {
        padding: 4rem 0;
    }

    .project-filters {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 0.4rem;
        padding: 0.25rem 0.1rem 0.5rem;
        margin-bottom: 1.5rem;
    }

    .project-filters::-webkit-scrollbar {
        display: none;
    }

    .filter-tab {
        flex-shrink: 0;
        padding: 0.45rem 0.9rem;
        font-size: 0.78rem;
        min-height: 36px;
        white-space: nowrap;
    }

    .projects-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .project-card-inner {
        border-radius: 16px;
    }

    .project-content {
        padding: 1.15rem 1rem;
    }

    .project-title {
        font-size: 1.05rem;
        line-height: 1.3;
    }

    .project-description {
        font-size: 0.84rem;
        line-height: 1.6;
    }

    .project-tech-tags {
        gap: 0.3rem;
        flex-wrap: wrap;
    }

    .tech-tag {
        font-size: 0.72rem;
        padding: 0.25rem 0.55rem;
        border-radius: 6px;
    }

    .project-footer-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .project-footer-actions .btn {
        justify-content: center;
        padding: 0.65rem 0.5rem;
        font-size: 0.8rem;
        min-height: 42px;
        gap: 0.4rem;
    }
}

/* --------------------------------------------------------------------------
   8. TECH STACK — fix blue icons, proper grid
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .techstack-section {
        padding: 4rem 0;
    }

    .tech-sphere-wrapper {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        justify-items: center;
        text-align: center;
    }

    .tech-sphere-canvas {
        width: min(260px, 72vw) !important;
        height: min(260px, 72vw) !important;
        touch-action: pan-y !important;
        margin: 0 auto;
    }

    .tech-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .tech-category-card {
        padding: 1.15rem 1rem;
        border-radius: 16px;
        gap: 1rem;
    }

    .cat-icon-box {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
        border-radius: 10px;
        color: var(--text-secondary);
    }

    .cat-title {
        font-size: 1rem;
    }

    .cat-desc {
        font-size: 0.75rem;
    }

    .tech-items-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .tech-pill {
        padding: 0.6rem 0.5rem;
        border-radius: 10px;
        gap: 0.5rem;
        min-height: 48px;
        justify-content: center;
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .tech-pill span {
        font-size: 0.75rem;
        font-weight: 600;
    }

    /* Keep AWS orange, Linux yellow, HTML red, JS yellow, Git red */
    /* Neutralize only the blue-ish ones */
    .brand-azure, .brand-docker, .brand-python,
    .brand-mysql, .brand-shell, .brand-network,
    .brand-lb, .brand-cicd {
        color: var(--text-secondary);
    }
}

/* --------------------------------------------------------------------------
   9. WORK TIMELINE — fix role title wrapping, date layout
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .work-section {
        padding: 4rem 0;
    }

    .timeline-entry {
        grid-template-columns: 20px 1fr;
        gap: 0.75rem;
    }

    .indicator-dot {
        width: 14px;
        height: 14px;
        border-width: 2.5px;
        margin-top: 4px;
    }

    .timeline-card {
        padding: 1.15rem 1rem;
        border-radius: 14px;
    }

    .timeline-card-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
        flex-wrap: nowrap;
    }

    .role-logo-box {
        width: 44px;
        height: 44px;
        border-radius: 10px;
        flex-shrink: 0;
    }

    .role-logo-box img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .role-title {
        font-size: 1rem;
        line-height: 1.3;
        word-break: break-word;
    }

    .role-company-row {
        display: flex;
        flex-wrap: wrap;
        gap: 0.3rem;
        align-items: center;
    }

    .company-name {
        font-size: 0.84rem;
    }

    .timeline-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem;
        margin-top: 0.25rem;
    }

    .meta-pill {
        font-size: 0.72rem;
        padding: 0.2rem 0.55rem;
    }

    .timeline-highlights {
        font-size: 0.84rem;
        line-height: 1.6;
        padding-left: 1rem;
    }

    .timeline-highlights li {
        margin-bottom: 0.4rem;
    }

    .timeline-tags {
        gap: 0.3rem;
        flex-wrap: wrap;
        margin-top: 0.75rem;
    }

    .timeline-tag {
        font-size: 0.72rem;
        padding: 0.2rem 0.55rem;
        border-radius: 6px;
        color: var(--text-secondary);
        background: var(--bg-card);
        border: 1px solid var(--border-subtle);
    }
}

/* --------------------------------------------------------------------------
   10. EDUCATION & CERTIFICATIONS
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .education-section,
    .cert-section {
        padding: 4rem 0;
    }

    .education-grid,
    .certs-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .edu-card,
    .credential-card {
        padding: 1.15rem 1rem;
        border-radius: 14px;
    }

    .edu-card-header,
    .credential-header {
        gap: 0.75rem;
        align-items: flex-start;
    }

    .edu-logo,
    .cert-logo {
        width: 48px;
        height: 48px;
        border-radius: 10px;
        flex-shrink: 0;
    }

    .edu-degree,
    .credential-name {
        font-size: 0.95rem;
        line-height: 1.35;
        word-break: break-word;
    }

    .edu-institution,
    .credential-org {
        font-size: 0.82rem;
    }

    .edu-period,
    .credential-year {
        font-size: 0.75rem;
    }

    /* Cert action buttons — stack cleanly */
    .credential-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        margin-top: 0.75rem;
    }

    .credential-actions .btn {
        justify-content: center;
        padding: 0.6rem 0.5rem;
        font-size: 0.8rem;
        min-height: 40px;
        gap: 0.35rem;
        white-space: nowrap;
        text-align: center;
    }

    /* Fix "View Certificate" text wrap */
    .credential-actions .btn span {
        white-space: nowrap;
    }

    .cert-id-row {
        font-size: 0.75rem;
        word-break: break-all;
        margin-top: 0.5rem;
    }
}

/* --------------------------------------------------------------------------
   11. GITHUB SECTION
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .github-section {
        padding: 4rem 0;
    }

    .github-card-wrapper {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    .github-graph-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
    }

    .github-graph-container img {
        min-width: 460px;
        max-width: none;
    }
}

/* --------------------------------------------------------------------------
   12. CONTACT — fix overflow, text truncation
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .contact-section {
        padding: 4rem 0 2.5rem;
    }

    .contact-grid {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .availability-bar {
        padding: 1rem;
        gap: 0.75rem;
        flex-direction: column;
        align-items: flex-start;
        border-radius: 14px;
        margin-bottom: 2rem;
    }

    .contact-card {
        padding: 0.9rem 1rem;
        gap: 0.75rem;
        border-radius: 12px;
        min-height: 60px;
        align-items: center;
        overflow: hidden;
    }

    .contact-card-icon {
        width: 38px;
        height: 38px;
        font-size: 1rem;
        flex-shrink: 0;
        color: var(--text-secondary);
        background: var(--bg-card);
    }

    .contact-card-content {
        flex: 1;
        min-width: 0;      /* crucial for text-overflow to work */
        overflow: hidden;
    }

    .contact-card-label {
        font-size: 0.7rem;
        display: block;
    }

    /* Truncate long URLs — no overflow */
    .contact-card-link {
        font-size: 0.84rem;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
    }

    /* Contact form */
    .form-wrapper {
        padding: 1.25rem 1rem;
        border-radius: 16px;
    }

    .form-heading {
        font-size: 1.1rem;
        line-height: 1.3;
    }

    .form-subtext {
        font-size: 0.84rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 0.85rem;
    }

    .form-label {
        font-size: 0.8rem;
    }

    .form-input,
    .form-textarea {
        font-size: 16px !important; /* Prevents iOS auto-zoom */
        min-height: 48px;
        padding: 0.75rem;
        border-radius: 10px;
    }

    .form-textarea {
        min-height: 120px;
        resize: vertical;
    }

    .submit-btn {
        min-height: 50px;
        font-size: 0.95rem;
        border-radius: 12px;
        width: 100%;
        justify-content: center;
    }
}

/* --------------------------------------------------------------------------
   13. FOOTER
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .site-footer {
        padding: 2.5rem 0 1.5rem;
    }

    .footer-inner {
        grid-template-columns: 1fr;
        gap: 2rem;
        text-align: center;
    }

    .footer-links {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.5rem 1.25rem;
    }

    .footer-link {
        font-size: 0.84rem;
    }

    .footer-bottom {
        font-size: 0.78rem;
        flex-direction: column;
        gap: 0.4rem;
        text-align: center;
    }
}

/* --------------------------------------------------------------------------
   14. FLOATING UI — back-to-top (gray, not blue), modal, toast
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .back-to-top {
        bottom: 1rem;
        right: 1rem;
        width: 40px;
        height: 40px;
        font-size: 0.95rem;
        border-radius: 12px;
        background: var(--bg-card);
        color: var(--text-primary);
        border: 1px solid var(--border-card);
        box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    }

    .back-to-top:hover {
        background: var(--accent-primary);
        color: var(--text-inverse);
    }

    .toast-notification {
        font-size: 0.82rem;
        padding: 0.6rem 1.25rem;
        bottom: 1.5rem;
        max-width: 90vw;
    }

    .modal {
        padding: 0.75rem;
        align-items: flex-end;
    }

    .modal-dialog {
        margin: 0;
        padding: 1.25rem 1rem;
        border-radius: 20px 20px 0 0;
        max-width: 100%;
        width: 100%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .open-work-banner {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
        gap: 0.75rem;
        border-radius: 14px;
    }
}

/* --------------------------------------------------------------------------
   15. TABLET (641px–1100px) — balanced layout
   -------------------------------------------------------------------------- */
@media (min-width: 641px) and (max-width: 1100px) {
    .section-container {
        padding: 0 1.5rem;
    }

    .hero-section {
        padding: 5.5rem 1.5rem 3.5rem;
    }

    .hero-container {
        gap: 3rem;
        text-align: center;
    }

    .hero-title {
        font-size: clamp(2.2rem, 5vw, 3rem);
    }

    .hero-photo-wrapper {
        max-width: 300px;
        margin: 0 auto;
    }

    .projects-grid {
        grid-template-columns: 1fr;
    }

    .education-grid,
    .certs-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .tech-items-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .stats-counter-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
