/* ============================================
   RESPONSIVE Mobile & Tablet
   Breakpoints: 1024px (tablet), 768px (mobile), 480px (small)
   ============================================ */

:root {
    --nav-height: 64px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* ---- Nav overlay (mobile drawer backdrop) ---- */
.nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 999;
}

body.nav-open {
    overflow: hidden;
}

body.nav-open .nav-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Horizontal scroll hint for carousels */
.scroll-row-wrap {
    position: relative;
}

.scroll-row-wrap::after {
    display: none;
}

@media (max-width: 1024px) {
    .scroll-row-wrap::after {
        display: block;
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        width: 2.5rem;
        height: calc(100% - 1rem);
        background: linear-gradient(to left, rgba(14, 17, 22, 0.92), transparent);
        pointer-events: none;
        opacity: 0.9;
    }

    [data-theme="light"] .scroll-row-wrap::after {
        background: linear-gradient(to left, rgba(246, 249, 255, 0.92), transparent);
    }

    .navbar-link {
        font-size: 1.05rem !important;
    }
}

/* ============================================
   TABLET max 1024px
   ============================================ */
@media (max-width: 1024px) {
    :root {
        --section-padding: 4rem;
    }

    html {
        scroll-padding-top: calc(var(--nav-height) + 12px);
    }

    .navbar {
        top: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        padding: calc(0.5rem + var(--safe-top)) calc(0.75rem + var(--safe-right)) 0.5rem calc(0.75rem + var(--safe-left));
    }

    .navbar.scrolled {
        top: 0;
    }

    .navbar .container {
        justify-content: space-between;
        gap: 0.75rem;
    }

    .navbar-logo {
        width: auto;
        height: auto;
        font-size: clamp(1.25rem, 4vw, 1.5rem);
        margin-left: auto;
    }

    /* Hero */
    .hero {
        min-height: auto;
        padding: calc(5.5rem + var(--safe-top)) 0 3rem;
    }

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

    .hero-image {
        order: -1;
        max-width: 340px;
        margin-inline: auto;
    }

    .hero-image::before {
        inset: 12px -12px -12px 12px;
    }

    .hero-text h1 {
        font-size: clamp(2.25rem, 7vw, 3.5rem);
    }

    .hero-text h2 {
        font-size: clamp(1.15rem, 3.5vw, 1.65rem);
    }

    .hero-text p {
        max-width: none;
    }

    /* About */
    .about-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .about-stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .collage-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    /* Grids */
    .projects-grid,
    .news-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }

    .skills-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .bento-card--featured,
    .bento-card:not(.bento-card--featured) {
        grid-column: span 12;
    }

    .cert-preview-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* Page heroes */
    .page-hero {
        min-height: auto;
        padding-top: calc(6rem + var(--safe-top));
        padding-bottom: 1.5rem;
    }

    .page-hero-stats {
        margin-top: 1rem;
    }

    /* Footer */
    .footer-content {
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
    }

    .footer-about {
        grid-column: 1 / -1;
    }

    /* Contact */
    .contact-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    #education,
    #experience {
        padding-top: 2.5rem;
    }
}

/* ============================================
   MOBILE max 768px
   ============================================ */
@media (max-width: 768px) {
    :root {
        --section-padding: 3rem;
    }

    .container {
        width: min(100% - 1.5rem, var(--container-max-width));
        padding: 0 0.25rem;
    }

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

    .section-title {
        font-size: clamp(1.65rem, 6vw, 2.25rem);
    }

    .section-subtitle {
        font-size: 0.95rem;
    }

    /* Mobile nav drawer base rules; madison.css extends */
    .navbar-toggle {
        min-width: 44px;
        min-height: 44px;
        align-items: center;
        justify-content: center;
    }

    .navbar-menu {
        width: min(88vw, 340px);
        padding: calc(1rem + var(--safe-top)) 1.25rem calc(1.25rem + var(--safe-bottom));
        gap: 0.15rem;
        align-items: stretch;
        justify-content: flex-start;
        overflow-y: auto;
    }

    .navbar-link {
        font-size: 1.05rem !important;
        padding: 0.85rem;
        border-radius: 8px;
        width: 100%;
        text-align: left;
    }

    .navbar-link.active::after {
        display: none;
    }

    .theme-toggle {
        width: 44px;
        height: 44px;
    }

    /* Hero */
    .hero {
        padding: calc(5rem + var(--safe-top)) 0 2.5rem;
    }

    .hero-content {
        text-align: left;
    }

    .hero-meta {
        gap: 0.4rem;
    }

    .meta-chip {
        font-size: 0.75rem;
        padding: 0.35rem 0.65rem;
    }

    .hero-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .hero-actions .btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;
    }

    .hero-social {
        width: 100%;
        justify-content: flex-start;
    }

    .social-link {
        min-width: 44px;
        min-height: 44px;
    }

    /* About */
    .about-stats {
        grid-template-columns: 1fr;
        gap: 0.65rem;
    }

    .stat-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        text-align: left;
        padding: 0.85rem 1rem;
    }

    .stat-number {
        font-size: 1.75rem;
        margin-bottom: 0;
    }

    .collage-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* Single-column grids */
    .projects-grid,
    .news-grid,
    .skills-grid {
        grid-template-columns: 1fr;
    }

    /* Horizontal scroll rows see mobile-scroll.css */

    /* Bento & certs */
    .cert-preview-grid {
        grid-template-columns: 1fr;
        gap: 0.85rem;
    }

    .cert-preview {
        flex-direction: row;
        align-items: center;
        text-align: left;
        gap: 0.85rem;
        padding: 0.75rem;
    }

    .cert-preview img {
        width: 88px;
        min-width: 88px;
        aspect-ratio: 4 / 3;
        margin-bottom: 0;
    }

    .bento-card__actions,
    .update-card__actions,
    .card-links,
    .news-card-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .bento-card__actions .btn,
    .update-card__actions .btn,
    .card-links .btn,
    .news-card-actions .btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    .view-all-actions .btn {
        width: 100%;
        max-width: none;
        min-height: 48px;
    }

    /* Timeline */
    .timeline {
        padding-left: 1.25rem;
    }

    .timeline-item {
        padding-left: 0.5rem;
    }

    .timeline-date {
        font-size: 0.78rem;
    }

    /* Contact form touch targets */
    .form-input,
    .form-textarea {
        min-height: 48px;
        font-size: 16px; /* prevents iOS zoom on focus */
    }

    .form-textarea {
        min-height: 140px;
    }

    .contact-item {
        padding: 0.85rem;
    }

    /* News page */
    .news-filter-bar {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 0.35rem;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
    }

    .news-filter-btn {
        flex-shrink: 0;
        scroll-snap-align: start;
        min-height: 40px;
    }

    .news-toolbar-inner {
        gap: 0.65rem;
    }

    .news-stats,
    .page-hero-stats {
        flex-direction: column;
        align-items: stretch;
    }

    .page-stat,
    .news-stats span {
        justify-content: center;
    }

    .news-card--featured {
        grid-column: auto;
    }

    /* Footer */
    .footer {
        padding: 2.5rem 0 calc(1.5rem + var(--safe-bottom));
    }

    .footer-content {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .footer-links-sub {
        margin-top: 0.75rem;
    }

    .footer-bottom {
        flex-direction: column;
        text-align: center;
    }

    /* CTA bands */
    .cta-actions,
    .news-cta-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .cta-actions .btn,
    .news-cta-actions .btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;
    }

    /* Project cards */
    .project-card .card-links {
        flex-direction: column;
    }

    .card-image,
    .bento-card__media,
    .update-card__media {
        aspect-ratio: 16 / 10;
    }

    /* Disable hover lift on touch */
    .card:hover,
    .skill-category:hover,
    .bento-card:hover,
    .cert-preview:hover,
    .news-card:hover {
        transform: none;
    }
}

/* ============================================
   SMALL MOBILE max 480px
   ============================================ */
@media (max-width: 480px) {
    :root {
        --section-padding: 2.5rem;
    }

    .hero-text h1 {
        font-size: clamp(1.85rem, 9vw, 2.35rem);
    }

    .hero-image {
        max-width: 280px;
    }

    .section-eyebrow {
        font-size: 0.72rem;
    }

    .navbar-menu {
        width: 100%;
        max-width: 100%;
    }

    .preloader-logo {
        font-size: 2.5rem;
    }
}

/* Touch devices reduce motion on scroll-snap auto-scroll conflict */
@media (hover: none) and (pointer: coarse) {
    .btn:hover,
    .social-link:hover,
    .skill-badge:hover,
    .contact-item:hover {
        transform: none;
    }
}
