/* Header and Navigation */
.top-controls {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 100;
}

/* Back to Top Button */
.back-to-top {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.3s,
        visibility 0.3s,
        background-color 0.3s;
    z-index: 1000;
    box-shadow: 0 2px 8px var(--shadow-color);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform, opacity;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    background: var(--button-hover);
}

/* Profile image styles */
.profile-image-front,
.profile-image-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 50%;
    overflow: hidden;
    border: 4px solid var(--primary-color);
    background-color: var(--card-color);
}

.profile-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background-color: var(--card-color);
}

.profile-image-flipper {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.8s;
    transform-style: preserve-3d;
    will-change: transform;
}

/* Theme Toggle Button */
#theme-toggle {
    background: var(--dark-primary); /* Dark theme primary by default */
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    box-shadow: 0 2px 8px var(--shadow-color);
    transition:
        background-color 0.3s ease,
        transform 0.2s ease;
}

/* Light theme toggle styling */
body[data-theme="light"] #theme-toggle {
    background: var(--light-primary);
}

#theme-toggle:hover {
    transform: translateY(-2px);
}

#theme-toggle:active {
    transform: translateY(0);
}

#theme-toggle svg {
    width: 20px;
    height: 20px;
    fill: white; /* Always white fill for better contrast */
}

/* Icon visibility */
.moon-icon {
    display: none;
}

.sun-icon {
    display: block;
}

body[data-theme="light"] .moon-icon {
    display: block;
}

body[data-theme="light"] .sun-icon {
    display: none;
}

/* Hero Section */
.hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
    padding-top: 3rem;
}

/* Flipping Profile Image */
.profile-image-container {
    perspective: 1000px;
    width: 200px;
    height: 200px;
    cursor: pointer;
    margin-bottom: 1rem;
    transition: transform 0.3s ease;
    position: relative;
    will-change: transform;
}

.profile-image-container:hover {
    transform: scale(1.02);
}

.profile-image-container:hover::after {
    content: "";
    position: absolute;
    inset: 0;
    background-color: rgba(var(--primary-color-rgb), 0.1);
    border-radius: 50%;
    pointer-events: none;
}

.profile-image-flipper {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.8s;
    transform-style: preserve-3d;
    will-change: transform;
}

.profile-image-container.flipped .profile-image-flipper {
    transform: rotateY(180deg);
}

.profile-image-front,
.profile-image-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 50%;
    overflow: hidden;
    border: 4px solid var(--primary-color);
    background-color: var(--card-color);
}

.profile-image-back {
    transform: rotateY(180deg);
}

.profile-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-image-container:focus {
    outline-offset: 4px;
}

.subtitle {
    color: var(--accent-color);
    font-size: 1.2rem;
    font-weight: 300;
}

/* Hero Navigation */
.hero-navigation {
    display: flex;
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.nav-link {
    color: var(--primary-color);
    font-weight: 600;
    text-decoration: none;
    padding: 0.5rem 0;
    position: relative;
    transition: color 0.3s ease;
}

.nav-link::after {
    content: "";
    position: absolute;
    width: 0;
    height: 2px;
    bottom: 0;
    left: 0;
    background-color: var(--primary-color);
    transition: width 0.3s ease;
}

.nav-link:hover {
    color: var(--accent-color);
}

.nav-link:hover::after {
    width: 100%;
}

/* Service Cards */
.services-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 2rem;
}

.service-card {
    background-color: var(--card-color);
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 4px 15px var(--shadow-color);
    transition:
        transform 0.3s ease,
        background-color 0.3s ease,
        box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    will-change: transform;
}

.service-card:hover {
    transform: translateY(-10px);
}

.service-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.service-card h3 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.service-card p {
    font-size: 0.9rem;
}

/* About Section */
.about-section {
    padding: 2rem 0;
}

.about-card {
    background-color: var(--card-color);
    border-radius: 10px;
    box-shadow: 0 4px 15px var(--shadow-color);
    padding: 2rem;
    margin: 0 auto;
}

.about-bio {
    margin-bottom: 2rem;
}

.about-bio h3 {
    color: var(--primary-color);
    margin-bottom: 0.75rem;
}

/* Optimized About Details Grid for any number of items */
.about-details-grid {
    display: grid;
    gap: 2rem; /* Increased from 1.5rem to 2rem for more space between cards */
    width: 100%;
    margin-bottom: 2.5rem; /* Added space before references card */
}

/* Base responsive layout (fallback) */
.about-details-grid {
    grid-template-columns: repeat(
        auto-fit,
        minmax(280px, 1fr)
    ); /* Increased minmax size from 250px to 280px */
}

/* Special layouts for specific item counts using :has() */
/* For exactly 1 item */
.about-details-grid:has(:first-child:last-child) {
    grid-template-columns: minmax(280px, 3fr);
    max-width: 600px; /* Increased from 500px */
    margin: 0 auto 2.5rem auto;
}

/* For exactly 2 items */
.about-details-grid:has(:nth-child(2):last-child) {
    grid-template-columns: repeat(2, 1fr);
    max-width: 800px; /* Added max-width for 2 items */
    margin: 0 auto 2.5rem auto;
}

/* For exactly 3 items */
.about-details-grid:has(:nth-child(3):last-child) {
    grid-template-columns: repeat(3, 1fr);
    max-width: 1100px; /* Added max-width for 3 items to prevent excessive stretching */
    margin: 0 auto 2.5rem auto;
}

/* Fallbacks for browsers without :has() support */
@supports not (selector(:has(*))) {
    /* Count-based layouts will be handled by media queries instead */

    /* Large screens - 3 columns */
    @media (min-width: 950px) {
        /* Increased from 800px */
        .about-details-grid {
            grid-template-columns: repeat(3, 1fr);
            max-width: 1100px;
            margin: 0 auto 2.5rem auto;
        }
    }

    /* Medium screens - 2 columns */
    @media (min-width: 650px) and (max-width: 949px) {
        /* Adjusted ranges */
        .about-details-grid {
            grid-template-columns: repeat(2, 1fr);
            max-width: 800px;
            margin: 0 auto 2.5rem auto;
        }
    }

    /* Small screens - single column */
    @media (max-width: 649px) {
        /* Adjusted from 549px */
        .about-details-grid {
            grid-template-columns: 1fr;
            max-width: 500px;
            margin: 0 auto 2.5rem auto;
        }
    }
}

/* Make cards stretch to fill their grid area */
.about-detail-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 1.8rem; /* Increased padding from 1.5rem */
    background-color: var(--background-color);
    border-radius: 8px;
    transition: transform 0.3s ease;
    will-change: transform;
}

.about-detail-card:hover {
    transform: translateY(-5px);
}

.about-detail-card h3 {
    color: var(--primary-color);
    font-size: 1.2rem; /* Increased from 1.1rem */
    margin-bottom: 0.8rem; /* Increased from 0.5rem */
}

.about-detail-card p,
.about-detail-card li {
    font-size: 1rem; /* Increased from 0.95rem */
    line-height: 1.5;
}

.about-detail-card ul {
    padding-left: 1.2rem;
}

.about-detail-card li {
    margin-bottom: 0.7rem;
}

/* Additional enhancement for single-item case */
.about-detail-card:only-child {
    text-align: center;
}

/* Enhancement for 2-item case on smaller screens */
@media (max-width: 650px) {
    .about-details-grid:has(:nth-child(2):last-child) {
        grid-template-columns: 1fr;
        max-width: 500px;
        margin: 0 auto 2rem auto;
    }
}

/* References Card */
.about-references-card {
    background-color: var(--background-color);
    padding: 1.8rem; /* Increased from 1.5rem */
    border-radius: 8px;
    margin-top: 0; /* Removed top margin since we added bottom margin to grid */
    transition: transform 0.3s ease;
    will-change: transform;
}

.about-references-card:hover {
    transform: translateY(-5px);
}

.about-references-card h3 {
    color: var(--primary-color);
    font-size: 1.2rem; /* Increased from 1.1rem */
    margin-bottom: 0.8rem; /* Increased from 0.5rem */
}

.about-references-card ul {
    padding-left: 1.2rem; /* Adjusted for better readability */
}

.about-references-card li {
    margin-bottom: 0.7rem; /* Increased from 0.5rem */
    line-height: 1.5;
}

/* Buttons */
.button {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white !important;
    text-decoration: none;
    border-radius: 4px;
    font-weight: 600;
    text-align: center;
    border: none;
    cursor: pointer;
    transition:
        background-color 0.3s ease,
        transform 0.2s ease;
    box-shadow: 0 2px 8px var(--shadow-color);
}

.button:hover {
    background-color: var(--button-hover);
    transform: translateY(-2px);
}

.button:active {
    transform: translateY(0);
}

.button-center {
    display: block;
    margin: 0 auto;
    max-width: 200px;
}

/* Contact Section */
.contact-container {
    text-align: center;
    margin: 4rem 0;
}

.contact-description {
    margin-bottom: 2rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* Email styling */
.email-container {
    margin: 2rem auto;
    max-width: 400px;
    background-color: var(--card-color);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 4px 15px var(--shadow-color);
    text-align: center;
    transition: all 0.3s ease;
}

.email-container.hidden {
    display: none;
}

.protected-email {
    font-family: monospace;
    font-size: 1.2rem;
    margin: 1rem 0;
    padding: 0.5rem;
    background-color: var(--background-color);
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    position: relative;
}

.protected-email:hover {
    background-color: var(--primary-color);
    color: white;
}

.protected-email:hover::after {
    opacity: 1;
}

#email-copy-instruction {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.email-copied {
    background-color: var(--secondary-color) !important;
    color: white;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    margin-top: 2rem;
    background-color: var(--footer-bg);
    color: var(--footer-text);
}

.footer-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.footer-links {
    display: flex;
    gap: 2rem;
}

.footer-links a {
    color: var(--secondary-color);
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer-links a:hover {
    color: var(--accent-color);
}

/* Fade in animation for scroll effects */
.fade-in {
    opacity: 1 !important;
    transform: translateY(0) !important;
    transition:
        opacity 0.8s cubic-bezier(0.165, 0.84, 0.44, 1),
        transform 0.8s cubic-bezier(0.165, 0.84, 0.44, 1);
}

/* Responsive component adjustments */
@media (max-width: 768px) {
    .top-controls {
        position: absolute;
        top: 1rem;
        right: 1rem;
    }

    .profile-image-container {
        width: 150px;
        height: 150px;
    }

    .services-grid,
    .about-details-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }

    .hero-navigation {
        flex-wrap: wrap;
        justify-content: center;
    }

    .button-center {
        max-width: 80%;
    }

    header .top-controls {
        position: relative;
        top: 0;
        right: 0;
    }

    .section {
        margin: 2rem 0;
    }

    .hero {
        padding-top: 2rem;
    }
}

@media (max-width: 480px) {
    .profile-image-container {
        width: 120px;
        height: 120px;
    }

    .services-grid,
    .about-details-grid {
        grid-template-columns: 1fr;
    }

    .about-card,
    .service-card {
        padding: 1.5rem;
    }

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

    h1 {
        font-size: clamp(1.6rem, 5vw, 2.2rem);
    }

    .subtitle {
        font-size: 1.1rem;
    }
}
