:root {
    --bg: #0b0816;
    --surface: #1d1535;
    --surface-soft: #261b44;
    --input: #120d25;
    --primary: #b388ff;
    --primary-light: #e4d5ff;
    --secondary: #ff6f91;
    --accent: #54e6c2;
    --heading: #fffaff;
    --text: #d1c8e5;
    --muted: #9b91b3;
    --border: rgba(220, 193, 255, .2);
    --border-hover: rgba(179, 136, 255, .8);
    --shadow: 0 15px 40px rgba(0, 0, 0, .28);
    --max-width: 1180px;
    --radius: 22px;
}

body.blue-theme {
    --bg: #07111f;
    --surface: #101f38;
    --surface-soft: #142b4b;
    --input: #09192d;
    --primary: #00b7ff;
    --primary-light: #b9f1ff;
    --secondary: #2979ff;
    --accent: #00e5a8;
    --heading: #f3fbff;
    --text: #c6dceb;
    --muted: #8ca8bd;
    --border: rgba(0, 212, 255, .22);
    --border-hover: rgba(0, 212, 255, .8);
    --shadow: 0 15px 40px rgba(0, 11, 30, .45);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    background: var(--bg);
    scroll-behavior: smooth;
    scroll-padding-top: 100px;
}

body {
    min-height: 100vh;
    overflow-x: hidden;
    isolation: isolate;
    color: var(--heading);
    background:
        radial-gradient(circle at 5% 0%, rgba(179, 136, 255, .13), transparent 28rem),
        radial-gradient(circle at 100% 45%, rgba(255, 111, 145, .09), transparent 30rem),
        var(--bg);
    font-family: "Manrope", sans-serif;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background .35s ease, color .35s ease;
}

body::before {
    position: fixed;
    z-index: -2;
    inset: 0;
    content: "";
    pointer-events: none;
    opacity: .08;
    background-image:
        linear-gradient(rgba(179, 136, 255, .25) 1px, transparent 1px),
        linear-gradient(90deg, rgba(179, 136, 255, .25) 1px, transparent 1px);
    background-size: 80px 80px;
}

::selection {
    color: var(--bg);
    background: var(--primary-light);
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    border: 2px solid var(--bg);
    border-radius: 20px;
    background: var(--primary);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 4px;
}

/* Lightweight background particles */
#particles {
    contain: strict;
    position: fixed;
    z-index: -3;
    inset: 0;
    opacity: .1;
    pointer-events: none;
    background-image:
        radial-gradient(circle, rgba(255, 255, 255, .9) 0 1px, transparent 1.5px),
        radial-gradient(circle, rgba(179, 136, 255, .85) 0 1px, transparent 1.5px),
        radial-gradient(circle, rgba(84, 230, 194, .7) 0 1px, transparent 1.5px);
    background-position: 0 0, 42px 68px, 90px 24px;
    background-size: 155px 155px, 225px 225px, 310px 310px;
    animation: spaceDrift 30s linear infinite;
    will-change: background-position;
}

#motion-graphics {
    mix-blend-mode: screen;
    will-change: contents;
}

@keyframes spaceDrift {
    from {
        background-position: 0 0, 42px 68px, 90px 24px;
    }
    to {
        background-position: 155px 110px, -183px 240px, 260px -180px;
    }
}

/* Header */
header {
    position: fixed;
    z-index: 999;
    top: 0;
    width: 100%;
    border-bottom: 1px solid transparent;
    background: rgba(11, 8, 22, .88);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    transition: border-color .3s ease, background .3s ease, box-shadow .3s ease,
        transform .35s ease, opacity .35s ease;
}

/* Fades out and slides up while scrolling down; slides back in on scroll up */
header.nav-hidden {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}

body.blue-theme header {
    background: rgba(7, 17, 31, .88);
}

header.scrolled {
    border-bottom-color: var(--border);
    background: rgba(11, 8, 22, .96);
    box-shadow: 0 8px 25px rgba(0, 0, 0, .25);
}

nav {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(92%, var(--max-width));
    min-height: 76px;
    margin: auto;
    gap: 22px;
}

.logo {
    color: var(--heading);
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 2px;
    text-decoration: none;
    transition: transform .25s ease, color .25s ease;
}

.logo::first-letter {
    color: var(--secondary);
}

.logo:hover {
    color: var(--primary-light);
    transform: scale(1.05);
}

.nav-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 18px;
    list-style: none;
}

.nav-links a {
    position: relative;
    color: var(--text);
    font-size: .8rem;
    font-weight: 700;
    text-decoration: none;
    transition: color .25s ease;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--primary-light);
}

.nav-links a::after {
    position: absolute;
    right: 0;
    bottom: -7px;
    left: 0;
    width: 0;
    height: 2px;
    margin: auto;
    content: "";
    border-radius: 20px;
    background: var(--primary);
    transition: width .25s ease;
}

.nav-links a:hover::after,
.nav-links a.active::after {
    width: 100%;
}

/* Hamburger toggle (hidden on desktop) */
.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--primary-light);
    background: var(--surface);
    font-size: 1.1rem;
    cursor: pointer;
    transition: border-color .25s ease, transform .2s ease;
}

.nav-toggle:hover {
    border-color: var(--primary);
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--primary-light);
    background: var(--surface);
    cursor: pointer;
    transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease;
}

.theme-toggle:hover {
    border-color: var(--primary);
    transform: rotate(20deg) scale(1.08);
    box-shadow: 0 0 18px rgba(179, 136, 255, .3);
}

/* Hero */
.hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(92%, var(--max-width));
    min-height: 100vh;
    gap: clamp(40px, 8vw, 100px);
    margin: auto;
    padding-top: 105px;
}

.hero-left,
.hero-right {
    flex: 1;
}

.hero-left {
    animation: slideLeft .8s ease both;
}

.hero-left h1 {
    max-width: 720px;
    color: var(--heading);
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: clamp(2.7rem, 6vw, 5rem);
    font-weight: 800;
    line-height: 1.08;
    letter-spacing: -2.5px;
}

.hero-left h1 span {
    color: var(--secondary);
    text-shadow: 0 0 18px rgba(255, 111, 145, .45);
}

.hero-left h2 {
    min-height: 38px;
    margin: 22px 0 13px;
    color: var(--primary);
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
}

.hero-left p {
    max-width: 620px;
    margin-bottom: 32px;
    color: var(--text);
    font-size: 1rem;
    line-height: 1.9;
}

.hero-right {
    display: flex;
    justify-content: center;
    animation: slideRight .8s .1s ease both;
}

.hero-right img {
    width: min(380px, 78vw);
    aspect-ratio: 1;
    border: 4px solid var(--primary);
    border-radius: 50%;
    object-fit: cover;
    box-shadow:
        0 0 0 10px rgba(179, 136, 255, .08),
        0 0 35px rgba(179, 136, 255, .35);
    animation: profileFloat 6s ease-in-out infinite;
    transition: transform .35s ease, filter .35s ease;
}

.hero-right img:hover {
    transform: scale(1.04);
    filter: brightness(1.08) saturate(1.15);
}

/* Buttons */
.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 50px;
    padding: 13px 28px;
    border: 1px solid rgba(255, 255, 255, .25);
    border-radius: 999px;
    color: var(--bg);
    background: linear-gradient(110deg, var(--primary), var(--primary-light), var(--secondary));
    background-size: 200% 100%;
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: .86rem;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(179, 136, 255, .22);
    transition: transform .25s ease, box-shadow .25s ease, filter .25s ease;
}

.btn:hover {
    transform: translateY(-4px);
    filter: brightness(1.08);
    box-shadow: 0 15px 32px rgba(179, 136, 255, .35);
}

.btn:active {
    transform: translateY(-1px);
}

/* Sections */
section {
    width: min(92%, var(--max-width));
    margin: auto;
    padding: 105px 0;
    /* Keep content visible if JavaScript or a third-party script fails. */
    opacity: 1;
    transform: translateY(0);
    transition: opacity .7s ease, transform .7s ease;
}

/* Enable reveal animations only after the page script has loaded. */
html.js-enabled section:not(.hero):not(.show) {
    opacity: 0;
    transform: translateY(25px);
}

section.hero,
section.show {
    opacity: 1;
    transform: translateY(0);
}

section h2 {
    margin-bottom: 45px;
    color: var(--heading);
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: clamp(2rem, 5vw, 2.7rem);
    font-weight: 800;
    text-align: center;
}

section h2::after {
    display: block;
    width: 65px;
    height: 4px;
    margin: 13px auto 0;
    content: "";
    border-radius: 20px;
    background: linear-gradient(90deg, var(--secondary), var(--primary), var(--accent));
}

/* Cards */
.card,
.skill,
.project-card,
.contact-container {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    background: linear-gradient(145deg, var(--surface-soft), var(--surface));
    box-shadow: var(--shadow);
    contain: layout paint;
    transition: transform .3s ease, border-color .3s ease, box-shadow .3s ease;
}

.card:hover,
.skill:hover,
.project-card:hover,
.contact-container:hover {
    border-color: var(--border-hover);
    box-shadow: 0 20px 45px rgba(0, 0, 0, .35);
}

.card {
    padding: 34px;
    border-radius: var(--radius);
}

.card p,
.project-card p,
.contact-email {
    color: var(--text);
    line-height: 1.85;
}

.skills-grid,
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(225px, 1fr));
    gap: 22px;
}

.skill {
    padding: 30px 20px;
    border-radius: var(--radius);
    text-align: center;
}

.skill i {
    display: inline-block;
    margin-bottom: 14px;
    color: var(--secondary);
    font-size: 34px;
    transition: transform .3s ease, color .3s ease;
}

.skill:hover i {
    color: var(--accent);
    transform: scale(1.15) rotate(6deg);
}

.skill h3,
.project-card h3 {
    color: var(--heading);
    font-family: "Plus Jakarta Sans", sans-serif;
    font-weight: 700;
}

.skill h3 {
    font-size: 1rem;
}

.project-card {
    display: block;
    min-height: 150px;
    padding: 28px;
    border-radius: var(--radius);
    color: inherit;
    text-decoration: none;
}

.project-card h3 {
    margin-bottom: 10px;
    color: var(--primary-light);
    font-size: 1.08rem;
    transition: color .25s ease, transform .25s ease;
}

.project-card:hover h3 {
    color: var(--secondary);
    transform: translateX(5px);
}

.achievement-image {
    width: 100%;
    height: 210px;
    margin-bottom: 18px;
    border: 1px solid var(--border);
    border-radius: 14px;
    object-fit: cover;
    transition: transform .35s ease, filter .35s ease;
}

.achievement-card:hover .achievement-image {
    filter: brightness(1.08) saturate(1.12);
    transform: scale(1.04);
}

/* Reveal animation */
.reveal-item {
    opacity: 0;
    transform: translateY(22px);
    transition: opacity .55s ease, transform .55s ease;
}

.reveal-item.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Contact */
.contact-container {
    max-width: 850px;
    margin: auto;
    padding: 40px !important;
    border-radius: var(--radius) !important;
}

.contact-intro {
    margin-bottom: 28px;
    color: var(--text);
    line-height: 1.8;
    text-align: center;
}

.contact-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group.full-width,
.submit-btn {
    grid-column: 1 / -1;
}

.form-group label {
    color: var(--primary-light);
    font-size: .88rem;
    font-weight: 700;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    outline: none;
    color: var(--heading);
    background: var(--input);
    font: .92rem "Manrope", sans-serif;
    transition: border-color .25s ease, box-shadow .25s ease;
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--muted);
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(84, 230, 194, .12);
}

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

.submit-btn {
    justify-self: center;
    border: 0;
}

.contact-email {
    margin-top: 24px;
    text-align: center;
}

.contact-email a {
    color: var(--accent);
    text-decoration: none;
}

.scroll-progress {
    position: fixed;
    z-index: 1001;
    top: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--secondary), var(--primary), var(--accent));
    box-shadow: 0 0 10px var(--primary);
}

/* Animations */
@keyframes slideLeft {
    from {
        opacity: 0;
        transform: translateX(-35px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideRight {
    from {
        opacity: 0;
        transform: translateX(35px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes profileFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* Responsive layout */
@media (max-width: 900px) {
    nav {
        min-height: 68px;
    }

    .nav-toggle {
        display: inline-flex;
    }

    .theme-toggle {
        order: 2;
    }

    .nav-links {
        position: absolute;
        top: calc(100% + 12px);
        right: 0;
        left: 0;
        display: none;
        flex-direction: column;
        gap: 4px;
        padding: 18px;
        border: 1px solid var(--border);
        border-radius: 18px;
        background: var(--surface);
        box-shadow: var(--shadow);
    }

    .nav-links.open {
        display: flex;
    }

    .nav-links a {
        display: block;
        padding: 10px 6px;
        font-size: .9rem;
    }

    .hero {
        flex-direction: column;
        gap: 45px;
        padding-top: 150px;
        text-align: center;
    }

    .hero-left p {
        margin-right: auto;
        margin-left: auto;
    }

    .hero-right img {
        width: min(310px, 70vw);
    }
}

@media (max-width: 600px) {
    html {
        scroll-padding-top: 130px;
    }

    section {
        width: min(90%, 520px);
        padding: 78px 0;
    }

    .hero {
        width: min(90%, 520px);
        min-height: auto;
        padding-top: 170px;
        padding-bottom: 75px;
    }

    .hero-left h1 {
        font-size: 2.35rem;
        letter-spacing: -1px;
    }

    .card {
        padding: 25px 20px;
    }

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

    .contact-container {
        padding: 25px 18px !important;
    }

    .contact-form {
        grid-template-columns: 1fr;
    }

    .form-group.full-width,
    .submit-btn {
        grid-column: auto;
    }

    .submit-btn {
        width: 100%;
    }

    .achievement-image {
        height: auto;
        max-height: 270px;
    }
}

@media (prefers-reduced-motion: reduce) {

    #motion-graphics,
    #particles {
        display: none !important;
    }

    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation: none !important;
        transition: none !important;
    }

    section,
    section.show,
    section.hero,
    .reveal-item,
    .reveal-item.visible {
        opacity: 1;
        transform: none;
    }
}

/* Signed-in user badge (nav) */
.user-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 30px;
    height: 30px;
    border: 1px solid var(--border);
    border-radius: 50%;
    object-fit: cover;
}

#user-name {
    color: var(--text);
    font-size: .82rem;
    font-weight: 600;
    max-width: 130px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.signout-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--primary-light);
    background: var(--surface);
    font-size: .78rem;
    font-weight: 700;
    cursor: pointer;
    transition: border-color .25s ease;
}

.signout-btn:hover {
    border-color: var(--primary);
}

[hidden] {
    display: none !important;
}

@media (max-width: 900px) {
    .user-badge {
        order: 3;
    }

    #user-name {
        display: none;
    }
}

/* ==========================================================
   NEW ADDITIONS: Stats, Certificate Lightbox, Project Filters,
   Contact Auth Modal, and AI Floating Chatbot Widget
   ========================================================== */

/* Hero Actions & Badges */
.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 18px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(179, 136, 255, .08);
    backdrop-filter: blur(8px);
    color: var(--primary-light);
    font-size: .84rem;
    font-weight: 700;
    box-shadow: 0 4px 15px rgba(0, 0, 0, .15);
}

.hero-badge i {
    color: var(--accent);
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    margin-bottom: 15px;
}

.btn-secondary {
    border: 1px solid var(--border);
    color: var(--heading);
    background: rgba(255, 255, 255, .05);
    box-shadow: 0 4px 18px rgba(0, 0, 0, .2);
}

.btn-secondary:hover {
    border-color: var(--primary);
    background: rgba(179, 136, 255, .15);
    box-shadow: 0 8px 25px rgba(179, 136, 255, .25);
}

.btn-sm {
    min-height: 38px;
    padding: 8px 18px;
    font-size: .78rem;
    border-radius: 999px;
}

.hero-image-frame {
    position: relative;
    display: inline-block;
}

.hero-floating-tag {
    position: absolute;
    bottom: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(11, 8, 22, .9);
    backdrop-filter: blur(10px);
    color: var(--accent);
    font-size: .8rem;
    font-weight: 700;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
    animation: profileFloat 5s ease-in-out infinite reverse;
}

/* Stats Section */
.stats-section {
    width: min(92%, var(--max-width));
    margin: 20px auto 40px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 24px 20px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: linear-gradient(145deg, rgba(29, 21, 53, .65), rgba(38, 27, 68, .45));
    backdrop-filter: blur(12px);
    transition: transform .3s ease, border-color .3s ease, box-shadow .3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 12px 30px rgba(179, 136, 255, .18);
}

.stat-number {
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: 2.2rem;
    font-weight: 800;
    background: linear-gradient(120deg, var(--heading), var(--primary-light), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.1;
    margin-bottom: 6px;
}

.stat-label {
    color: var(--heading);
    font-weight: 700;
    font-size: .95rem;
    margin-bottom: 4px;
}

.stat-sub {
    color: var(--muted);
    font-size: .78rem;
}

/* Certificate Cards & Grid */
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
}

.cert-card-trigger {
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: transform .3s ease, border-color .3s ease, box-shadow .3s ease;
}

.cert-card-trigger:hover {
    border-color: var(--primary);
    box-shadow: 0 15px 35px rgba(179, 136, 255, .25);
}

.cert-image-container {
    position: relative;
    width: 100%;
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: 14px;
    background: #000;
}

.cert-image-container img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
    transition: transform .4s ease, filter .4s ease;
}

.cert-card-trigger:hover .cert-image-container img {
    transform: scale(1.05);
    filter: brightness(1.05);
}

.cert-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 800;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
    z-index: 2;
}

.google-badge {
    background: rgba(66, 133, 244, .25);
    border: 1px solid rgba(66, 133, 244, .6);
    color: #8ab4f8;
}

.openai-badge {
    background: rgba(16, 163, 127, .25);
    border: 1px solid rgba(16, 163, 127, .6);
    color: #54e6c2;
}

.anthropic-badge {
    background: rgba(217, 119, 87, .25);
    border: 1px solid rgba(217, 119, 87, .6);
    color: #ff9b82;
}

.cloud-badge {
    background: rgba(251, 188, 4, .25);
    border: 1px solid rgba(251, 188, 4, .6);
    color: #fdd663;
}

.cert-zoom-hint {
    position: absolute;
    bottom: 10px;
    right: 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(11, 8, 22, .8);
    border: 1px solid var(--border);
    color: var(--primary-light);
    font-size: .72rem;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity .25s ease, transform .25s ease;
    z-index: 2;
}

.cert-card-trigger:hover .cert-zoom-hint {
    opacity: 1;
    transform: translateY(0);
}

/* Certificate Lightbox Modal */
.cert-lightbox {
    position: fixed;
    z-index: 3000;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.cert-lightbox[hidden] {
    display: none !important;
}

.lightbox-overlay {
    position: absolute;
    inset: 0;
    background: rgba(5, 3, 12, .88);
    backdrop-filter: blur(14px);
    animation: fadeIn .3s ease;
}

.lightbox-content {
    position: relative;
    z-index: 2;
    width: min(94%, 780px);
    max-height: 92vh;
    overflow-y: auto;
    background: linear-gradient(145deg, var(--surface-soft), var(--surface));
    border: 1px solid var(--border-hover);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, .6);
    animation: zoomInModal .3s cubic-bezier(0.16, 1, 0.3, 1);
}

.lightbox-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--heading);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, transform .2s, border-color .2s;
    z-index: 3;
}

.lightbox-close-btn:hover {
    background: var(--primary);
    color: var(--bg);
    transform: rotate(90deg);
}

.lightbox-image-wrapper {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    background: #06040d;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

.lightbox-image-wrapper img {
    max-width: 100%;
    max-height: 55vh;
    object-fit: contain;
    display: block;
}

.lightbox-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lightbox-details h3 {
    font-size: 1.3rem;
    color: var(--heading);
    margin: 4px 0;
}

.lightbox-details p {
    color: var(--text);
    font-size: .92rem;
    line-height: 1.6;
}

.lightbox-actions {
    margin-top: 12px;
}

/* Project Filter Tabs */
.project-filter-tabs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin: 25px 0 35px;
}

.filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: .84rem;
    font-weight: 700;
    cursor: pointer;
    transition: all .25s ease;
}

.filter-btn:hover {
    border-color: var(--primary);
    color: var(--heading);
    transform: translateY(-2px);
}

.filter-btn.active {
    background: linear-gradient(110deg, var(--primary), var(--secondary));
    color: var(--bg);
    border-color: transparent;
    box-shadow: 0 6px 20px rgba(179, 136, 255, .35);
}

/* Rich Project Cards */
.rich-project-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform .3s ease, border-color .3s ease, opacity .3s ease;
}

.rich-project-card.filter-hidden {
    display: none !important;
}

.project-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.project-icon-box {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.ai-icon {
    background: rgba(179, 136, 255, .15);
    color: var(--primary);
    border: 1px solid rgba(179, 136, 255, .3);
}

.hardware-icon {
    background: rgba(84, 230, 194, .15);
    color: var(--accent);
    border: 1px solid rgba(84, 230, 194, .3);
}

.book-icon {
    background: rgba(255, 111, 145, .15);
    color: var(--secondary);
    border: 1px solid rgba(255, 111, 145, .3);
}

.web-icon {
    background: rgba(100, 181, 246, .15);
    color: #64b5f6;
    border: 1px solid rgba(100, 181, 246, .3);
}

.project-badge {
    font-size: .72rem;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .06);
    border: 1px solid var(--border);
    color: var(--primary-light);
    letter-spacing: .5px;
}

.project-tech-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 14px 0 16px;
}

.tech-tag {
    padding: 3px 10px;
    border-radius: 6px;
    background: rgba(255, 255, 255, .04);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: .72rem;
    font-weight: 600;
}

.project-actions {
    margin-top: auto;
    padding-top: 10px;
}

/* Contact Auth Status Banner */
.contact-auth-banner {
    margin-bottom: 24px;
    padding: 14px 20px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(29, 21, 53, .4);
    backdrop-filter: blur(8px);
}

.contact-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: .9rem;
    color: var(--heading);
}

.contact-user-info .signout-link {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--secondary);
    font-size: .82rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: underline;
}

.contact-guest-prompt {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.prompt-text {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-size: .88rem;
}

.prompt-text i {
    color: var(--accent);
}

.auth-signin-btn-sm {
    padding: 9px 18px;
    font-size: .8rem;
    min-height: 38px;
    background: linear-gradient(110deg, #fff, #e4d5ff);
    color: #120d25;
}

/* Google Sign-in Modal (triggered for contact form) */
.auth-modal {
    position: fixed;
    z-index: 2500;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-modal[hidden] {
    display: none !important;
}

.auth-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(5, 3, 12, .82);
    backdrop-filter: blur(12px);
    animation: fadeIn .25s ease;
}

.auth-modal-card {
    position: relative;
    z-index: 2;
    width: min(92%, 420px);
    padding: 38px 30px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(145deg, var(--surface-soft), var(--surface));
    box-shadow: var(--shadow);
    text-align: center;
    animation: zoomInModal .28s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-close-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--heading);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s ease;
}

.modal-close-btn:hover {
    background: var(--secondary);
    color: #fff;
}

.auth-logo {
    margin-bottom: 12px;
    color: var(--heading);
    font-family: "Plus Jakarta Sans", sans-serif;
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 3px;
}

.auth-modal-card h3 {
    margin-bottom: 8px;
    color: var(--heading);
    font-size: 1.15rem;
}

.auth-modal-card p {
    margin-bottom: 24px;
    color: var(--text);
    font-size: .88rem;
    line-height: 1.6;
}

.auth-signin-btn {
    width: 100%;
    gap: 10px;
}

.auth-error {
    margin-top: 14px;
    color: var(--secondary);
    font-size: .84rem;
}

/* Floating AI Chatbot Widget */
.chatbot-widget {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 2000;
}

.chatbot-toggle {
    position: relative;
    width: 76px;
    height: 104px;
    border: none;
    background: transparent;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    cursor: pointer;
    filter: drop-shadow(0 10px 18px rgba(179, 136, 255, .35));
    transition: transform .3s cubic-bezier(0.34, 1.56, 0.64, 1), filter .3s ease;
}

.chatbot-toggle:hover {
    transform: scale(1.06);
    filter: drop-shadow(0 14px 26px rgba(179, 136, 255, .5));
}

.chatbot-toggle:active .codex-figure {
    animation: codexPop .45s ease;
}

/* ===== Codex, the COSMOS companion pet ===== */
.codex-pet {
    width: 76px;
    height: 100%;
    overflow: visible;
}

.codex-figure {
    transform-box: fill-box;
    transform-origin: 50% 90%;
    animation: codexHover 3.2s ease-in-out infinite;
}

.chatbot-toggle:hover .codex-figure {
    animation-duration: 1.3s;
}

.codex-thruster {
    fill: var(--accent);
    opacity: .4;
    transform-box: fill-box;
    transform-origin: center;
    animation: codexThrusterPulse 3.2s ease-in-out infinite;
}

.codex-torso {
    filter: none;
}

.codex-body {
    fill: url(#codexBodyGrad);
}

.codex-fin {
    fill: var(--secondary);
    transform-box: fill-box;
    transform-origin: center;
    animation: codexFinWag 2.8s ease-in-out infinite;
}

.codex-head {
    transform-box: fill-box;
    transform-origin: 50% 100%;
    animation: codexHeadTilt 5.4s ease-in-out infinite;
}

.codex-pupils {
    transform-box: fill-box;
    transform-origin: center;
    animation: codexGlance 7s ease-in-out infinite;
}

.codex-fin-right {
    fill: var(--accent);
    animation-delay: .35s;
}

.codex-eye {
    transform-box: fill-box;
    transform-origin: center;
    animation: codexBlink 4.6s ease-in-out infinite;
}

.codex-smile {
    transform-box: fill-box;
    transform-origin: center;
    transition: transform .3s ease;
}

.chatbot-toggle:hover .codex-smile {
    transform: scaleX(1.15) scaleY(1.1);
}

.codex-antenna-tip {
    fill: var(--accent);
    animation: codexGlow 1.9s ease-in-out infinite;
}

.codex-emblem-ring {
    transform-box: fill-box;
    transform-origin: center;
    animation: codexEmblemSpin 6s linear infinite;
}

.codex-arm {
    transform-box: fill-box;
}

.codex-arm-right {
    transform-origin: 90% 10%;
}

.chatbot-toggle:hover .codex-arm-right {
    animation: codexWave .6s ease-in-out 2;
}

@keyframes codexHover {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

@keyframes codexThrusterPulse {
    0%, 100% { transform: scaleX(1); opacity: .35; }
    50% { transform: scaleX(.8); opacity: .55; }
}

@keyframes codexFinWag {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(-7deg); }
}

@keyframes codexHeadTilt {
    0%, 100% { transform: rotate(0deg); }
    30% { transform: rotate(-4deg); }
    60% { transform: rotate(3deg); }
}

@keyframes codexGlance {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(0); }
    28% { transform: translateX(-0.8px); }
    40% { transform: translateX(-0.8px); }
    48% { transform: translateX(0.8px); }
    60% { transform: translateX(0.8px); }
    68% { transform: translateX(0); }
}

@keyframes codexBlink {
    0%, 90%, 100% { transform: scaleY(1); }
    94% { transform: scaleY(0.12); }
}

@keyframes codexGlow {
    0%, 100% { opacity: .55; filter: none; }
    50% { opacity: 1; filter: drop-shadow(0 0 5px var(--accent)); }
}

@keyframes codexEmblemSpin {
    0% { transform: rotate(-18deg); }
    100% { transform: rotate(342deg); }
}

@keyframes codexWave {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(-25deg); }
}

@keyframes codexPop {
    0% { transform: scale(1) rotate(0deg); }
    45% { transform: scale(1.14) rotate(-6deg); }
    100% { transform: scale(1) rotate(0deg); }
}


.chatbot-window {
    position: absolute;
    bottom: 112px;
    right: 0;
    width: min(92vw, 380px);
    height: min(540px, calc(100dvh - 150px));
    max-height: calc(100dvh - 150px);
    border-radius: 22px;
    border: 1px solid var(--border);
    background: linear-gradient(155deg, rgba(29, 21, 53, .96), rgba(18, 13, 37, .98));
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 50px rgba(0, 0, 0, .55);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatOpen .32s cubic-bezier(0.16, 1, 0.3, 1);
    transform-origin: bottom right;
}

.chatbot-window[hidden] {
    display: none !important;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: rgba(11, 8, 22, .6);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.online-indicator {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg);
}

.chat-header h4 {
    color: var(--heading);
    font-size: .92rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.chat-subtitle {
    color: var(--muted);
    font-size: .72rem;
}

.chat-header-actions {
    display: flex;
    gap: 6px;
}

.chat-action-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, .08);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .76rem;
    transition: background .2s, color .2s;
}

.chat-action-btn:hover {
    background: var(--primary);
    color: var(--bg);
}

.chat-quick-prompts {
    display: flex;
    gap: 6px;
    padding: 10px 14px;
    overflow-x: auto;
    white-space: nowrap;
    border-bottom: 1px solid rgba(220, 193, 255, .08);
    scrollbar-width: none;
}

.chat-quick-prompts::-webkit-scrollbar {
    display: none;
}

.quick-chip {
    flex-shrink: 0;
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, .05);
    color: var(--primary-light);
    font-size: .72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s ease;
}

.quick-chip:hover {
    background: var(--primary);
    color: var(--bg);
    border-color: var(--primary);
}

.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeInMsg .25s ease;
}

.chat-msg.bot {
    align-self: flex-start;
}

.chat-msg.user {
    align-self: flex-end;
}

.chat-bubble {
    padding: 11px 15px;
    border-radius: 16px;
    font-size: .84rem;
    line-height: 1.5;
}

.chat-msg.bot .chat-bubble {
    background: rgba(255, 255, 255, .07);
    border: 1px solid var(--border);
    color: var(--heading);
    border-bottom-left-radius: 4px;
}

.chat-msg.user .chat-bubble {
    background: linear-gradient(120deg, var(--primary), var(--secondary));
    color: var(--bg);
    font-weight: 600;
    border-bottom-right-radius: 4px;
}

.chat-actions-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.chat-action-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(179, 136, 255, .2);
    border: 1px solid var(--border);
    color: var(--accent);
    font-size: .74rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: all .2s ease;
}

.chat-action-link:hover {
    background: var(--accent);
    color: #07111f;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, .05);
    width: fit-content;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-light);
    animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

.chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    background: rgba(11, 8, 22, .7);
}

.chat-input-area input {
    flex: 1;
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--input);
    color: var(--heading);
    font-size: .84rem;
    outline: none;
}

.chat-input-area input:focus {
    border-color: var(--primary);
}

.chat-input-area button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: var(--bg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease, background .2s ease;
}

.chat-input-area button:hover {
    transform: scale(1.06);
    background: var(--secondary);
}

/* Animation Keyframes */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes zoomInModal {
    from { opacity: 0; transform: scale(.92); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes chatOpen {
    from { opacity: 0; transform: scale(.8) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes fadeInMsg {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); opacity: .4; }
    40% { transform: scale(1); opacity: 1; }
}

@keyframes ping {
    75%, 100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

body.modal-open {
    overflow: hidden;
}

@media (max-width: 900px) {
    .hero-actions {
        justify-content: center;
    }

    .chatbot-widget {
        right: max(18px, env(safe-area-inset-right));
        bottom: max(18px, env(safe-area-inset-bottom));
    }

    .chatbot-window {
        right: 0;
        bottom: 108px;
        width: min(94vw, 380px);
        height: min(70vh, 540px, calc(100dvh - 150px));
    }
}

/* Small-screen refinements */
@media (max-width: 600px) {
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }

    nav {
        width: min(94%, 520px);
        gap: 10px;
    }

    .logo {
        font-size: 1.05rem;
        letter-spacing: 1.5px;
    }

    .nav-toggle,
    .theme-toggle {
        width: 40px;
        height: 40px;
    }

    .nav-links {
        right: 0;
        left: 0;
        padding: 12px;
    }

    .nav-links a {
        padding: 12px 10px;
    }

    .user-badge {
        gap: 6px;
    }

    .signout-btn {
        padding: 7px 10px;
        font-size: .72rem;
    }

    .hero-badge {
        max-width: 100%;
        justify-content: center;
        padding: 7px 12px;
        font-size: .75rem;
        line-height: 1.35;
        text-align: center;
    }

    .hero-left h2 {
        font-size: 1.05rem;
    }

    .hero-left p {
        font-size: .92rem;
        line-height: 1.75;
    }

    .hero-actions {
        width: 100%;
        gap: 10px;
    }

    .hero-actions .btn {
        flex: 1 1 145px;
        min-width: 0;
        padding: 12px 15px;
        font-size: .78rem;
    }

    .hero-floating-tag {
        right: 0;
        bottom: 8px;
        padding: 7px 11px;
        font-size: .7rem;
    }

    .stats-section {
        width: min(90%, 520px);
        margin: 0 auto;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .stat-card {
        min-width: 0;
        padding: 18px 8px;
        border-radius: 15px;
    }

    .stat-number {
        font-size: 1.65rem;
    }

    .stat-label {
        font-size: .78rem;
        line-height: 1.3;
    }

    .stat-sub {
        font-size: .68rem;
        line-height: 1.35;
    }

    section h2 {
        margin-bottom: 30px;
        font-size: clamp(1.7rem, 8vw, 2.2rem);
        line-height: 1.2;
    }

    .card,
    .project-card,
    .skill {
        border-radius: 17px;
    }

    .achievements-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 16px;
    }

    .achievement-image,
    .cert-image-container img {
        height: auto;
        aspect-ratio: 400 / 210;
    }

    .cert-zoom-hint {
        opacity: 1;
        transform: none;
    }

    .project-filter-tabs {
        justify-content: flex-start;
        flex-wrap: nowrap;
        margin: 18px 0 25px;
        padding: 2px 2px 10px;
        overflow-x: auto;
        scrollbar-width: thin;
    }

    .filter-btn {
        flex: 0 0 auto;
        padding: 9px 14px;
        font-size: .76rem;
    }

    .project-card-header {
        gap: 10px;
    }

    .project-badge {
        text-align: right;
    }

    .project-actions .btn {
        width: 100%;
    }

    .contact-auth-banner {
        padding: 14px;
    }

    .contact-user-info,
    .contact-guest-prompt {
        align-items: flex-start;
    }

    .contact-guest-prompt {
        flex-direction: column;
    }

    .prompt-text {
        align-items: flex-start;
        font-size: .8rem;
        line-height: 1.5;
    }

    .auth-signin-btn-sm {
        width: 100%;
    }

    .lightbox-content {
        width: 100%;
        max-height: calc(100dvh - 24px);
        padding: 16px;
        border-radius: 16px;
    }

    .lightbox-image-wrapper img {
        max-height: 44dvh;
    }

    .lightbox-actions .btn {
        width: 100%;
    }

    .chatbot-window {
        right: 0;
        width: min(calc(100vw - 24px), 380px);
        height: min(72dvh, 540px);
        border-radius: 18px;
    }

    .chat-header {
        padding: 12px 14px;
    }

    .chat-header h4 {
        font-size: .82rem;
    }

    .chat-subtitle {
        display: block;
        max-width: 175px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-messages {
        padding: 12px;
    }

    .chat-bubble {
        font-size: .8rem;
    }

    footer {
        padding: 24px 16px !important;
        font-size: .78rem;
    }
}

@media (max-width: 380px) {
    .hero-left h1 {
        font-size: 2.05rem;
    }

    .hero-actions {
        flex-direction: column;
    }

    .hero-actions .btn {
        width: 100%;
        flex-basis: auto;
    }

    .hero-right img {
        width: min(250px, 72vw);
    }

    .stats-grid {
        gap: 8px;
    }

    .stat-card {
        padding-right: 5px;
        padding-left: 5px;
    }

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

/* ==========================================================
   Device compatibility fixes
   ========================================================== */

/* Remove the gray tap-flash on touch devices; buttons already show their own feedback */
a, button {
    -webkit-tap-highlight-color: transparent;
}

/* Prevent iOS Safari from auto-zooming the page when a form field is focused
   (Safari zooms in on any input/textarea with a computed font-size under 16px) */
@media (max-width: 900px) {
    .form-group input,
    .form-group textarea,
    .chat-input-area input {
        font-size: 16px;
    }
}

/* Keep the nav's touch targets at a comfortable minimum size */
.nav-toggle,
.theme-toggle,
.chat-action-btn,
.modal-close-btn,
.lightbox-close-btn {
    min-width: 40px;
    min-height: 40px;
}

/* Don't let the nav-badge/theme-toggle cluster overflow on very narrow phones */
@media (max-width: 400px) {
    nav {
        gap: 6px;
    }

    .user-badge {
        gap: 4px;
    }

    #signout-btn {
        padding: 6px 8px;
        font-size: 0;
    }

    #signout-btn::before {
        content: "\2716";
        font-size: .78rem;
    }

    .user-avatar {
        width: 26px;
        height: 26px;
    }
}

/* Short landscape viewports (phones rotated sideways): don't force a full
   100vh hero when there isn't 100vh of usable height to give it */
@media (max-height: 480px) and (orientation: landscape) {
    .hero {
        min-height: auto;
        padding-top: 90px;
        padding-bottom: 40px;
    }

    .chatbot-window {
        height: min(80vh, 420px);
    }
}

/* Respect the device's safe areas (notches / home indicator) for fixed UI */
header, .chatbot-widget {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Mobile polish */
@media (max-width: 900px) {
    body {
        overflow-x: clip;
    }

    nav {
        min-height: 64px;
        width: min(94%, var(--max-width));
    }

    .nav-links {
        top: calc(100% + 8px);
        max-height: calc(100dvh - 84px);
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .nav-links a,
    .nav-toggle,
    .theme-toggle,
    .signout-btn {
        min-height: 44px;
    }

    .hero {
        width: min(92%, 560px);
        gap: 34px;
    }

    .hero-left h1 {
        max-width: 100%;
        text-wrap: balance;
    }

    .hero-left p {
        max-width: 48rem;
    }

    .hero-image-frame,
    .hero-right {
        max-width: 100%;
    }

    .hero-floating-tag {
        max-width: calc(100% - 16px);
        white-space: nowrap;
    }

    .card,
    .skill,
    .project-card,
    .contact-container {
        contain: layout;
    }

    .project-card h3,
    .skill h3,
    .stat-label {
        overflow-wrap: anywhere;
    }
}

@media (max-width: 600px) {
    html {
        scroll-padding-top: 88px;
    }

    section {
        padding: 64px 0;
    }

    .hero {
        padding-top: 112px;
        padding-bottom: 52px;
    }

    .hero-badge {
        display: flex;
        width: 100%;
        margin-bottom: 16px;
    }

    .hero-left h1 {
        font-size: clamp(2.05rem, 11vw, 3rem);
        line-height: 1.12;
    }

    .hero-left h2 {
        margin: 16px 0 10px;
    }

    .hero-actions {
        align-items: stretch;
    }

    .hero-actions .btn {
        flex: 1 1 100%;
        width: 100%;
    }

    .hero-right img {
        width: min(280px, 70vw);
    }

    .stats-section {
        padding-top: 8px;
    }

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

    .stat-number {
        font-size: clamp(1.45rem, 8vw, 1.8rem);
    }

    .stat-label,
    .stat-sub {
        overflow-wrap: anywhere;
    }

    .contact-form {
        gap: 16px;
    }

    .form-group textarea {
        min-height: 130px;
    }

    .chatbot-widget {
        right: max(12px, env(safe-area-inset-right));
        bottom: max(12px, env(safe-area-inset-bottom));
    }

    .chatbot-toggle {
        width: 62px;
        height: 86px;
    }

    .codex-pet {
        width: 62px;
    }

    .chatbot-window {
        position: fixed;
        right: max(12px, env(safe-area-inset-right));
        bottom: max(92px, calc(env(safe-area-inset-bottom) + 92px));
        left: max(12px, env(safe-area-inset-left));
        width: auto;
        height: min(70dvh, 540px);
        max-height: calc(100dvh - 116px);
    }

    .chat-input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .lightbox-content,
    .auth-modal-card {
        max-width: calc(100vw - 24px);
    }
}

@media (max-width: 380px) {
    .logo {
        font-size: .95rem;
    }

    .hero {
        width: min(92%, 340px);
    }

    .stats-card {
        min-height: 112px;
    }

    .stats-grid {
        gap: 7px;
    }

    .stat-card {
        padding: 15px 5px;
    }

    .stat-sub {
        font-size: .64rem;
    }
}
