/* ========================================
   MOBILE POLISH — ThisUncle Technologies
   Comprehensive mobile-responsive overhaul
   Targets: 375px (iPhone SE), 390px (14), 414px (Plus)
   ========================================
   Load this stylesheet LAST to override
   existing desktop-first rules cleanly.
   ======================================== */

/* ========================================
   0. GLOBAL GUARDS — prevent horizontal overflow
   ======================================== */
html {
    overflow-x: hidden;               /* safety net */
}

body {
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;   /* prevent iOS text zoom */
}

*,
*::before,
*::after {
    max-width: 100%;                  /* no child wider than parent */
}

/* Allow positioned elements to exceed via explicit override */
.floating-element,
.hero-graphic,
.code-window {
    max-width: none;
}

/* ========================================
   1. TYPOGRAPHY — fluid sizing with clamp()
   Ensures legibility at every breakpoint.
   ======================================== */
body {
    /* Minimum 16px body text for readability */
    font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
}

/* Section titles — fluid from 1.5rem → 2.5rem */
body .section-title {
    font-size: clamp(1.5rem, 1.1rem + 2vw, 2.5rem);
}

/* Section subtitles */
body .section-subtitle {
    font-size: clamp(0.9rem, 0.85rem + 0.3vw, 1.1rem);
}

/* ========================================
   2. HERO SECTION — responsive title & layout
   Fixes: title overflow, cramped code widget,
   proper vertical spacing.
   ======================================== */

/* Hero title — scales fluidly, never overflows */
body .hero-title {
    font-size: clamp(1.75rem, 1.2rem + 3vw, 3rem);
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

body .hero-title-accent {
    /* Prevent long accented text from causing overflow */
    word-break: break-word;
    display: inline;
}

body .hero-description {
    font-size: clamp(0.95rem, 0.9rem + 0.25vw, 1.1rem);
}

/* ========================================
   3. MOBILE-SPECIFIC RULES (max-width: 768px)
   ======================================== */
@media screen and (max-width: 768px) {

    /* ---- Container breathing room ---- */
    .container {
        padding: 0 1.25rem;
    }

    /* ---- Section vertical rhythm ---- */
    .section {
        padding: 3.5rem 0;
    }

    /* ---- Hero ---- */
    body .hero {
        min-height: auto;              /* don't force full viewport */
        padding-top: 80px;
        padding-bottom: 2rem;
    }

    .hero-container {
        grid-template-columns: 1fr;
        gap: 2rem;
        text-align: center;
        padding: 2rem 0 1rem;
    }

    /* Code window widget — add proper padding, prevent cutoff */
    .hero-visual {
        order: -1;
        height: auto;
        min-height: 280px;
        padding: 1rem 0;
    }

    .hero-graphic {
        position: relative;
        width: 100%;
        min-height: 260px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    body .code-window {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        width: 100%;
        max-width: 340px;
        margin: 0 auto;
        animation: none;              /* kill float on mobile for stability */
    }

    body .code-content {
        padding: 1.25rem;
        font-size: 0.85rem;
        line-height: 1.6;
    }

    body .code-header {
        padding: 0.7rem 1rem;
    }

    .code-filename {
        font-size: 0.78rem;
    }

    .code-indent {
        padding-left: 1.25rem;
    }

    /* Floating elements — shrink and reposition so they don't overflow */
    .floating-element {
        display: none;                 /* hide on mobile for cleanliness */
    }

    /* Scroll indicator */
    body .scroll-indicator {
        display: none;                 /* remove on mobile */
    }

    /* Hero buttons — full width, proper touch targets */
    .hero-buttons {
        flex-direction: column;
        width: 100%;
        gap: 0.75rem;
    }

    .hero-buttons .btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;              /* touch target min */
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    /* ---- BUTTONS (global) — ensure touch-friendly size ---- */
    .btn {
        min-height: 48px;
        padding: 0.875rem 1.5rem;
        font-size: 0.95rem;
        border-radius: 8px;
    }

    .btn-large {
        min-height: 52px;
        padding: 1rem 2rem;
        font-size: 1rem;
    }

    /* ---- ABOUT PREVIEW — left-align text on mobile ---- */
    .about-preview-grid {
        grid-template-columns: 1fr;
        gap: 2.5rem;
        text-align: left;             /* FIX: left-align on mobile */
    }

    body .about-preview-text {
        text-align: left;
    }

    .about-preview-content {
        text-align: left;
    }

    .about-preview-content .section-title {
        text-align: left;
    }

    .about-preview-content .section-title::after {
        left: 0;
        transform: none;              /* remove center transform */
    }

    .about-highlights {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .about-preview .btn-secondary {
        animation: none;               /* disable float-btn on mobile */
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    /* Director card */
    .about-image-wrapper {
        max-width: 280px;
        margin: 0 auto;
    }

    .director-info {
        max-width: 280px;
    }

    /* ---- SERVICE CARDS — consistent padding & spacing ---- */
    .services-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    body .service-card {
        padding: 1.75rem 1.5rem;
        border-radius: 16px;
        /* Subtle hover state for mobile tap feedback */
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    body .service-card:active {
        transform: scale(0.98);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    }

    body .service-icon {
        width: 52px;
        height: 52px;
        border-radius: 12px;
        margin-bottom: 1.25rem;
    }

    body .service-icon i {
        font-size: 1.3rem;
    }

    body .service-title {
        font-size: 1.1rem;
        margin-bottom: 0.5rem;
    }

    body .service-description {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }

    body .service-features li {
        font-size: 0.85rem;
        padding: 0.2rem 0;
    }

    /* ---- PORTFOLIO PREVIEW CARDS — consistent styling ---- */
    .portfolio-preview {
        padding: 3.5rem 0;
    }

    .portfolio-preview-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        margin-top: 2rem;
        margin-bottom: 2rem;
    }

    .portfolio-preview-card {
        height: auto;
        min-height: 300px;
        border-radius: 16px;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    .portfolio-preview-card:active {
        transform: scale(0.98);
    }

    .portfolio-preview-image img {
        padding: 12px 16px 100px 16px;
    }

    .portfolio-preview-content {
        bottom: 12px;
        left: 12px;
        right: 12px;
        padding: 1rem 1.25rem;
        border-radius: 14px;
    }

    .portfolio-preview-title {
        font-size: 1.1rem;
    }

    .portfolio-preview-description {
        font-size: 0.82rem;
    }

    .portfolio-preview-tags span {
        font-size: 0.68rem;
        padding: 3px 8px;
    }

    /* ---- TESTIMONIAL CARDS — consistent padding & spacing ---- */
    .testimonial-track {
        flex-direction: column;
        gap: 1.25rem;
        padding: 0.5rem 0;
    }

    .testimonial-slide {
        flex: 1 1 auto !important;
        max-width: 100% !important;
        min-width: 0 !important;
        padding: 1.75rem 1.5rem;
        border-radius: 16px;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    .testimonial-slide:active {
        transform: scale(0.98);
    }

    .testimonial-text {
        font-size: 0.95rem !important;
        line-height: 1.65 !important;
        padding-left: 1.25rem;
    }

    .testimonial-text::before {
        font-size: 3rem;
        top: -1rem;
        left: -0.25rem;
    }

    .testimonial-author {
        gap: 0.75rem;
        padding-top: 1rem;
    }

    .author-info h4 {
        font-size: 0.95rem;
    }

    .author-info span {
        font-size: 0.8rem;
    }

    /* ---- CTA SECTION ---- */
    body .cta-card {
        padding: 2.5rem 1.5rem;
        border-radius: 20px;
    }

    body .cta-title {
        font-size: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
    }

    body .cta-description {
        font-size: 0.95rem;
        margin-bottom: 1.5rem;
    }

    body .cta-icon {
        width: 64px;
        height: 64px;
        border-radius: 12px;
        margin-bottom: 1.5rem;
    }

    body .cta-icon i {
        font-size: 2rem;
    }

    .cta-buttons {
        flex-direction: column;
        width: 100%;
        gap: 0.75rem;
        margin-bottom: 2rem;
    }

    .cta-buttons .btn {
        width: 100%;
        justify-content: center;
    }

    .cta-features {
        flex-direction: column;
        gap: 0.75rem;
        align-items: center;
    }

    body .cta-feature {
        font-size: 0.88rem;
    }

    /* ---- SECTION CTAs (View Full Portfolio etc.) ---- */
    .section-cta {
        padding-top: 0.5rem;
    }

    .section-cta .btn {
        width: 100%;
        justify-content: center;
    }

    /* ---- FOOTER — more breathing room between stacked sections ---- */
    footer.footer {
        padding: 2.5rem 0 1.5rem;
    }

    .footer-content {
        grid-template-columns: 1fr;
        gap: 2.5rem;                   /* FIX: more breathing room */
    }

    .footer-section {
        padding-bottom: 0;
    }

    /* Separate footer columns with subtle dividers */
    .footer-section + .footer-section {
        padding-top: 2rem;
        border-top: 1px solid #eeeeee;
    }

    .footer-logo img {
        width: 32px;
        height: 32px;
    }

    .footer-description {
        font-size: 0.9rem;
    }

    .footer .footer-title {
        font-size: 0.95rem;
        margin-bottom: 0.75rem;
    }

    .footer-links a {
        font-size: 0.9rem;
        display: inline-block;
        padding: 0.25rem 0;           /* bigger tap area */
    }

    .footer-links li {
        margin-bottom: 0.5rem;
    }

    .footer-contact p {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }

    .social-links {
        gap: 0.75rem;
    }

    .social-link {
        width: 44px;
        height: 44px;
        font-size: 1rem;              /* larger touch target */
    }

    .footer-bottom {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
        padding-top: 1.5rem;
        font-size: 0.83rem;
    }

    /* ---- NAV — ensure touch targets ---- */
    .nav-toggle,
    .nav-close {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ========================================
   4. SMALL MOBILE RULES (max-width: 480px)
   Specifically targeting iPhone SE (375px)
   ======================================== */
@media screen and (max-width: 480px) {

    .container {
        padding: 0 1rem;
    }

    /* Hero title scales down further */
    body .hero-title {
        font-size: clamp(1.5rem, 1rem + 3vw, 2rem);
        line-height: 1.2;
    }

    /* Code window shrinks gracefully */
    body .code-window {
        max-width: 100%;
    }

    body .code-content {
        padding: 1rem;
        font-size: 0.8rem;
    }

    .code-indent {
        padding-left: 1rem;
    }

    /* Service cards */
    body .service-card {
        padding: 1.5rem 1.25rem;
    }

    /* Portfolio preview cards */
    .portfolio-preview-card {
        min-height: 260px;
    }

    .portfolio-preview-image img {
        padding: 10px 14px 90px 14px;
    }

    .portfolio-preview-content {
        bottom: 10px;
        left: 10px;
        right: 10px;
        padding: 0.875rem 1rem;
    }

    .portfolio-preview-title {
        font-size: 1rem;
    }

    /* CTA section */
    body .cta-card {
        padding: 2rem 1.25rem;
        border-radius: 16px;
    }

    /* About section */
    .about-image-wrapper {
        max-width: 240px;
    }

    .director-info {
        max-width: 240px;
        padding: 1.25rem 0.75rem 1rem;
    }

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

    body .stat-card {
        padding: 1.25rem 0.75rem;
    }

    body .stat-number {
        font-size: 1.75rem;
    }

    body .stat-label {
        font-size: 0.8rem;
    }
}

/* ========================================
   5. EXTRA-SMALL SCREENS (max-width: 360px)
   iPhone SE 1st gen edge case
   ======================================== */
@media screen and (max-width: 360px) {

    .container {
        padding: 0 0.875rem;
    }

    body .hero-title {
        font-size: 1.4rem;
    }

    body .hero-description {
        font-size: 0.9rem;
    }

    body .code-content {
        padding: 0.75rem;
        font-size: 0.75rem;
    }

    .code-dots span {
        width: 9px;
        height: 9px;
    }

    body .section-title {
        font-size: 1.35rem;
    }

    body .service-card {
        padding: 1.25rem 1rem;
    }

    body .cta-card {
        padding: 1.75rem 1rem;
    }

    body .cta-title {
        font-size: 1.3rem;
    }
}

/* ========================================
   6. SMOOTH SECTION TRANSITIONS & HOVER STATES
   Subtle polish for both desktop and mobile.
   ======================================== */

/* Smooth fade-in for sections as they enter the viewport.
   If AOS is active this may be overridden, but acts as a
   graceful fallback. */
section {
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

/* Card hover states — desktop only (no hover on touch) */
@media (hover: hover) and (pointer: fine) {
    body .service-card:hover {
        transform: translateY(-6px);
        box-shadow: 0 16px 40px rgba(0, 0, 0, 0.08);
        border-color: #d0d0d0;
    }

    .portfolio-preview-card:hover {
        transform: translateY(-8px) scale(1.01);
        box-shadow:
            0 20px 50px -12px rgba(0, 0, 0, 0.14),
            0 0 0 1px rgba(0, 0, 0, 0.03);
    }

    .testimonial-slide:hover {
        transform: translateY(-6px);
        box-shadow: 0 16px 40px rgba(0, 0, 0, 0.08);
    }
}

/* ========================================
   7. TOUCH-SPECIFIC OPTIMISATIONS
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    /* Disable hover transforms on touch devices to prevent sticky states */
    body .service-card:hover,
    .portfolio-preview-card:hover,
    .testimonial-slide:hover {
        transform: none;
    }

    /* Active/tap feedback instead */
    body .service-card:active,
    .portfolio-preview-card:active,
    .testimonial-slide:active,
    .btn:active {
        transform: scale(0.97);
        transition: transform 0.1s ease;
    }

    /* Ensure all interactive elements meet 48px min */
    .nav-link,
    .footer-links a,
    .social-link,
    .btn,
    .filter-btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
}

/* ========================================
   8. PORTFOLIO PAGE CARDS (carousel)
   Prevent overflow on mobile.
   ======================================== */
@media screen and (max-width: 768px) {
    .portfolio-carousel-container {
        overflow: hidden;              /* prevent horizontal scroll */
    }

    /* Ensure portfolio grid (non-carousel) is single column */
    .portfolio-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .portfolio-card {
        margin: 0;                     /* remove side margins that cause overflow */
    }

    .portfolio-content {
        padding: 1.5rem;
    }

    .portfolio-title {
        font-size: 1.15rem;
    }

    .portfolio-description {
        font-size: 0.9rem;
    }
}

/* ========================================
   9. SERVICES PREVIEW SECTION — fix background
   on mobile for the alternate bg section
   ======================================== */
@media screen and (max-width: 768px) {
    body .services-preview {
        padding: 3rem 0;
    }

    .section-header {
        margin-bottom: 2rem;
    }
}

/* ========================================
   10. TESTIMONIALS SECTION — mobile bg fix
   ======================================== */
@media screen and (max-width: 768px) {
    #testimonials.section,
    .testimonials-section {
        padding: 3rem 0;
    }

    .testimonial-carousel-container {
        padding: 1rem 0;
    }
}
