:root {
    --primary-color: #3b5bdb;
    --primary-light: #eef2ff;
    --primary-dark: #2b4ac7;
    --secondary-color: #f4f6fb;
    --text-color: #0f172a;
    --text-light: #5c6578;
    --white: #ffffff;
    --header-h: 4.5rem;
    --section-y: clamp(3rem, 8vw, 6rem);
    --container-pad: clamp(1rem, 4vw, 2rem);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 20px 50px -12px rgba(15, 23, 42, 0.12);
    --transition: all 0.3s ease;
    --radius-card: 1rem;
    --ring: 0 0 0 1px rgba(59, 91, 219, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    -webkit-text-size-adjust: 100%;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

body {
    color: var(--text-color);
    background-color: var(--secondary-color);
    line-height: 1.6;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding-bottom: env(safe-area-inset-bottom, 0);
    touch-action: manipulation;
}

body.menu-open {
    overflow: hidden;
    touch-action: none;
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

img {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

main {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
}

.container {
    width: 100%;
    min-width: 0;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--container-pad);
}

.section {
    padding: var(--section-y) 0;
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
}

iframe,
video,
canvas,
svg {
    max-width: 100%;
}

.bg-light {
    background-color: var(--white);
}

.bg-primary {
    background-color: var(--primary-color);
    color: var(--white);
}

.section-title {
    text-align: center;
    margin-bottom: 4rem;
}

.section-title h2 {
    font-size: clamp(1.65rem, 3.5vw, 2.5rem);
    font-weight: 700;
    color: var(--text-color);
    padding: 0 0.5rem;
}

.bg-primary .section-title h2 {
    color: var(--white);
}

.underline {
    width: 60px;
    height: 4px;
    background-color: var(--primary-color);
    margin: 1rem auto 0;
    border-radius: 2px;
}

.bg-primary .underline {
    background-color: var(--white);
}

/* Buttons */
.btn {
    display: inline-flex;
    padding: 0.75rem 1.5rem;
    border-radius: 50px;
    font-weight: 600;
    transition: var(--transition);
    cursor: pointer;
    border: none;
    font-size: 1rem;
    -webkit-tap-highlight-color: transparent;
    text-align: center;
    min-height: 44px;
    line-height: 1.25;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--white);
    box-shadow: 0 4px 14px 0 rgba(37, 99, 235, 0.39);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.23);
}

.btn-secondary {
    background-color: var(--white);
    color: var(--primary-color);
    border: 1px solid #e2e8f0;
}

.btn-secondary:hover {
    border-color: var(--primary-color);
    color: var(--primary-dark);
}

/* Hamburger: simple <div> (mobile only) */
.menu-btn {
    display: none;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--text-color);
    cursor: pointer;
    z-index: 1002;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    padding: 0.35rem 0.5rem;
    flex: 0 0 auto;
}

.mobile-only {
    display: none;
}

/* Navbar (no backdrop-filter: avoids position/fixed + clipping bugs on some mobile browsers) */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    background-color: rgba(255, 255, 255, 0.98);
    z-index: 1000;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    padding-top: env(safe-area-inset-top, 0);
    overflow: visible;
    box-sizing: border-box;
}

.navbar.scrolled {
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0));
    padding-bottom: 0.5rem;
    box-shadow: var(--shadow-md);
}

.nav-content {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: var(--header-h);
    height: var(--header-h);
    gap: 0.5rem;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.logo {
    font-size: clamp(1.1rem, 3.2vw, 1.5rem);
    font-weight: 800;
    color: var(--primary-color);
    min-width: 0;
    flex: 0 1 auto;
    line-height: 1.2;
    word-break: break-word;
    hyphens: auto;
}

.logo span {
    color: var(--text-color);
}

.nav-links {
    display: flex;
    gap: 2rem;
}

.nav-links a {
    font-weight: 500;
    color: var(--text-color);
    transition: var(--transition);
    position: relative;
}

.nav-links a::after {
    content: '';
    position: absolute;
    width: 0;
    height: 2px;
    bottom: -4px;
    left: 0;
    background-color: var(--primary-color);
    transition: var(--transition);
}

.nav-links a:hover::after {
    width: 100%;
}

.nav-links a:hover {
    color: var(--primary-color);
}

/* Hero Section */
.hero {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    padding-top: calc(var(--header-h) + env(safe-area-inset-top, 0));
    padding-bottom: 2.5rem;
    background: radial-gradient(1200px 500px at 10% 0%, rgba(59, 91, 219, 0.12), transparent 55%),
        radial-gradient(800px 400px at 100% 20%, rgba(14, 165, 233, 0.08), transparent 50%),
        linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
}

.hero-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(1.5rem, 4vw, 4rem);
    align-items: center;
    min-width: 0;
}

.greeting {
    font-size: clamp(0.9rem, calc(0.2vw + 0.8rem), 1.2rem);
    color: var(--primary-color);
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.hero-text,
.hero-image {
    min-width: 0;
}

.title {
    font-size: clamp(1.85rem, 5.5vw, 3.5rem);
    font-weight: 800;
    line-height: 1.12;
    margin-bottom: 1rem;
    color: var(--text-color);
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.subtitle {
    font-size: clamp(1.05rem, 2.2vw, 1.4rem);
    color: var(--text-light);
    font-weight: 500;
    margin-bottom: 1.5rem;
}

.description {
    font-size: clamp(0.95rem, calc(0.3vw + 0.9rem), 1.125rem);
    color: var(--text-light);
    margin-bottom: 2rem;
    max-width: 36em;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: center;
    justify-content: flex-start;
}

.image-wrapper {
    position: relative;
    border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
    animation: morph 8s ease-in-out infinite;
    background: linear-gradient(145deg, var(--primary-color), var(--primary-dark));
    padding: 8px;
    box-shadow: var(--shadow-lg), var(--ring);
    overflow: hidden;
    width: 100%;
    max-width: min(420px, 100%);
    margin-inline: auto;
    aspect-ratio: 1/1;
}

.image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

@keyframes morph {
    0% { border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }
    50% { border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%; }
    100% { border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }
}

/* About Section */
.about-grid {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: clamp(2rem, 4vw, 4rem);
    min-width: 0;
    align-items: start;
}

.about-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

.stat-card {
    background: var(--white);
    padding: 1.5rem clamp(1rem, 3vw, 1.5rem);
    border-radius: var(--radius-card);
    text-align: center;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(15, 23, 42, 0.06);
    transition: var(--transition);
    min-width: 0;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.stat-number {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 800;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    line-height: 1.1;
}

.stat-text {
    color: var(--text-light);
    font-weight: 500;
}

.about-skills h3 {
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

.about-skills p {
    color: var(--text-light);
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

.skills-list {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.skill-tag {
    background: var(--primary-light);
    color: var(--primary-color);
    padding: 0.5rem 0.9rem;
    border-radius: 50px;
    font-weight: 600;
    font-size: clamp(0.8rem, calc(0.1vw + 0.78rem), 1rem);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: var(--transition);
    border: 1px solid rgba(37, 99, 235, 0.1);
    max-width: 100%;
    word-break: break-word;
    box-sizing: border-box;
}

.skill-tag:hover {
    background: var(--primary-color);
    color: var(--white);
    transform: translateY(-2px);
}

/* Services */
.services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: 1.5rem;
    min-width: 0;
    width: 100%;
}

.service-card {
    background: var(--white);
    padding: clamp(1.5rem, 3vw, 2.5rem);
    border-radius: var(--radius-card);
    text-align: center;
    transition: var(--transition);
    border: 1px solid rgba(15, 23, 42, 0.06);
    box-shadow: var(--shadow-sm);
    min-width: 0;
}

.service-card:hover {
    transform: translateY(-10px);
    box-shadow: var(--shadow-lg);
    background: var(--white);
}

.service-icon {
    width: 80px;
    height: 80px;
    background: var(--primary-light);
    color: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin: 0 auto 1.5rem;
    transition: var(--transition);
}

.service-card:hover .service-icon {
    background: var(--primary-color);
    color: var(--white);
}

.service-card h3 {
    font-size: clamp(1.2rem, 2vw, 1.4rem);
    margin-bottom: 1rem;
    line-height: 1.3;
    word-wrap: break-word;
}

.service-card p {
    color: var(--text-light);
}

/* Projects Section */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
    gap: clamp(1.5rem, 3vw, 2.5rem);
    min-width: 0;
    width: 100%;
}

.project-card {
    background: var(--white);
    border-radius: var(--radius-card);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(15, 23, 42, 0.06);
    transition: var(--transition);
    min-width: 0;
}

.project-card:hover {
    transform: translateY(-10px);
    box-shadow: var(--shadow-lg);
}

.project-img {
    aspect-ratio: 16 / 9;
    width: 100%;
    min-height: 0;
    overflow: hidden;
    background: #e2e8f0;
}

.project-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.project-card:hover .project-img img {
    transform: scale(1.05);
}

.project-info {
    padding: clamp(1.25rem, 2.5vw, 1.75rem);
}

.project-category {
    font-size: 0.875rem;
    color: var(--primary-color);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.project-info h3 {
    font-size: 1.5rem;
    margin: 0.5rem 0 1rem;
}

.project-info p {
    color: var(--text-light);
    margin-bottom: 1.5rem;
}

.project-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary-color);
    font-weight: 600;
    transition: var(--transition);
}

.project-link:hover {
    gap: 0.75rem;
    color: var(--primary-dark);
}

/* Contact – keep content inside viewport + device safe area (notch / home bar) */
#contact.section {
    max-width: 100%;
    overflow-x: clip;
    padding-top: var(--section-y);
    padding-bottom: calc(var(--section-y) + env(safe-area-inset-bottom, 0px));
}

#contact .container {
    max-width: min(1200px, 100%);
    width: 100%;
    box-sizing: border-box;
    padding-left: max(var(--container-pad), env(safe-area-inset-left, 0px));
    padding-right: max(var(--container-pad), env(safe-area-inset-right, 0px));
}

.contact-text {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: break-word;
}

.contact-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: clamp(2rem, 4vw, 4rem);
    align-items: start;
    min-width: 0;
    max-width: 100%;
}

.contact-text h2 {
    font-size: clamp(1.4rem, 4.5vw, 2.75rem);
    margin-bottom: 1.5rem;
    line-height: 1.2;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.contact-text p {
    font-size: clamp(0.95rem, calc(0.2vw + 0.9rem), 1.125rem);
    opacity: 0.95;
}

.contact-info {
    background: var(--white);
    color: var(--text-color);
    padding: clamp(1.5rem, 3vw, 2.5rem);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(15, 23, 42, 0.06);
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.contact-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    font-size: clamp(0.9rem, calc(0.2vw + 0.85rem), 1.1rem);
    font-weight: 500;
    flex-wrap: wrap;
}

.contact-item a {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.contact-item i {
    color: var(--primary-color);
    font-size: 1.5rem;
}

.contact-item a:hover {
    color: var(--primary-color);
}

.social-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    margin-top: 2rem;
    justify-content: flex-start;
}

.social-links a {
    width: 50px;
    height: 50px;
    background: var(--secondary-color);
    color: var(--text-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    transition: var(--transition);
}

.social-links a:hover {
    background: var(--primary-color);
    color: var(--white);
    transform: translateY(-3px);
}

/* Footer */
footer {
    background: #0f172a;
    color: var(--white);
    padding: 2rem 0;
    text-align: center;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-content p {
    opacity: 0.8;
}

/* Responsive */
@media (max-width: 992px) {
    .hero-content,
    .about-grid,
    .contact-wrapper {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .hero-text {
        order: 1;
    }

    .hero-image {
        order: 0;
    }

    .description {
        margin-left: auto;
        margin-right: auto;
    }

    .hero-actions {
        justify-content: center;
    }

    .image-wrapper {
        margin: 0 auto 1.5rem;
    }

    .skills-list {
        justify-content: center;
    }

    .section-title {
        margin-bottom: clamp(2rem, 5vw, 3.5rem);
    }

    .about-skills p {
        max-width: 50ch;
        margin-left: auto;
        margin-right: auto;
    }

    .contact-text {
        text-align: center;
    }

    .contact-text p {
        margin-left: auto;
        margin-right: auto;
    }

    .contact-item {
        justify-content: center;
        align-items: flex-start;
    }

    .contact-item i {
        flex-shrink: 0;
        margin-top: 0.2em;
    }

    .social-links {
        justify-content: center;
    }

    .contact-info {
        max-width: min(26rem, 100%);
        margin-left: auto;
        margin-right: auto;
    }

    .footer-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
}

@media (max-width: 992px) {
    .menu-btn {
        display: block;
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: block;
        width: 100%;
        text-align: center;
        margin-top: 0.5rem;
    }

    .mobile-only .btn {
        width: 100%;
        max-width: 280px;
    }

    .nav-links .mobile-only a.btn.btn-primary,
    .nav-links .mobile-only a.btn.btn-primary:hover,
    .nav-links .mobile-only a.btn.btn-primary:visited {
        color: var(--white) !important;
    }

    /* Dropdown under header: absolute + clip-path (stable on mobile) */
    .nav-links {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        width: 100%;
        max-height: min(70vh, 32rem);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        z-index: 1001;
        background-color: var(--white);
        flex-direction: column;
        align-items: center;
        gap: 1.25rem;
        padding: 1.5rem 1rem 1.5rem;
        box-shadow: var(--shadow-md);
        clip-path: polygon(0 0, 100% 0, 100% 0, 0 0);
        transition: clip-path 0.4s ease-in-out;
    }

    .nav-links a::after {
        display: none;
    }

    .nav-links.active {
        clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
    }

    .nav-links li {
        width: 100%;
        max-width: 20rem;
    }

    .section-title h2 {
        padding: 0;
    }
}

/* Safer single-column layout on narrow phones / old WebViews */
@media (max-width: 480px) {
    .services-grid,
    .projects-grid,
    .about-grid,
    .hero-content {
        grid-template-columns: 1fr;
    }

    .about-stats {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }
}

@media (max-width: 400px) {
    .stat-card {
        padding: 1.25rem 0.75rem;
    }

    .skill-tag {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }

    .hero-actions .btn {
        width: 100%;
        max-width: 20rem;
    }
}

/* Hard mobile safety pass */
@media (max-width: 768px) {
    :root {
        --header-h: 4rem;
        --container-pad: 0.9rem;
        --section-y: 3rem;
    }

    html,
    body {
        font-size: 15px;
    }

    .container,
    .hero-content,
    .about-grid,
    .about-stats,
    .services-grid,
    .projects-grid,
    .contact-wrapper,
    .contact-info,
    .project-card,
    .service-card {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .hero-content,
    .about-grid,
    .services-grid,
    .projects-grid,
    .contact-wrapper {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .about-stats {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .nav-content {
        gap: 0.35rem;
    }

    .logo {
        max-width: 70%;
        font-size: 1.1rem;
    }

    .hero {
        min-height: auto;
        padding-top: calc(var(--header-h) + env(safe-area-inset-top, 0) + 1rem);
        padding-bottom: 1.25rem;
    }

    .title {
        font-size: 1.8rem;
        line-height: 1.2;
    }

    .subtitle {
        font-size: 1rem;
    }

    .description {
        font-size: 0.95rem;
        max-width: 100%;
    }

    .hero-actions {
        gap: 0.6rem;
    }

    .hero-actions .btn {
        width: 100%;
        max-width: none;
    }

    .image-wrapper {
        max-width: min(300px, 100%);
    }

    .service-card,
    .project-info,
    .contact-info {
        padding: 1rem;
    }

    .service-icon {
        width: 64px;
        height: 64px;
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    .project-img {
        aspect-ratio: 16 / 10;
    }

    .contact-text h2 {
        font-size: 1.45rem;
    }

    .contact-item {
        display: block;
        text-align: left;
        margin-bottom: 1rem;
    }

    .contact-item i {
        display: inline-block;
        margin-right: 0.4rem;
        margin-top: 0;
        font-size: 1rem;
    }

    .social-links {
        justify-content: flex-start;
        gap: 0.6rem;
    }

    .social-links a {
        width: 42px;
        height: 42px;
        font-size: 1rem;
    }
}

/* Clean mobile fix for contact section */
@media (max-width: 768px) {
    #contact,
    #contact.section,
    #contact .container,
    #contact .contact-wrapper,
    #contact .contact-text,
    #contact #contact-details {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        margin-left: 0;
        margin-right: 0;
        box-sizing: border-box;
    }

    #contact .container {
        padding-left: var(--container-pad);
        padding-right: var(--container-pad);
    }

    #contact .contact-wrapper {
        display: grid;
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    #contact .contact-text h2 {
        font-size: 1.35rem;
        line-height: 1.2;
        overflow-wrap: anywhere;
    }

    #contact .contact-text p,
    #contact .contact-item a {
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    #contact #contact-details {
        padding: 1rem;
        border-radius: 14px;
    }
}

/* Animation Classes */
.reveal {
    opacity: 0;
    transform: translateY(30px);
    transition: all 0.8s ease-out;
}

.reveal.active {
    opacity: 1;
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .image-wrapper {
        animation: none;
    }

    .reveal {
        opacity: 1;
        transform: none;
        transition: none;
    }
}
