/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Color palette */
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --accent-color: #06b6d4;
    --text-dark: #1e293b;
    --text-light: #64748b;
    --sun-color: #ffdf5d;
    --text-white: #ffffff;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-dark: #0f172a;
    --border-color: #e2e8f0;
    /* Typography */
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'Fira Code', 'SF Mono', Monaco, 'Cascadia Code', monospace;
    /* Spacing */
    --container-max-width: 1200px;
    --section-padding: 5rem 0;
    --border-radius: 0.75rem;
}

/* Reusable color/opacity tokens for easier theming and tuning */
:root {
    --shadow-1: rgba(0, 0, 0, 0.1);
    --shadow-2: rgba(0, 0, 0, 0.06);
    --shadow-3: rgba(0, 0, 0, 0.08);
    --shadow-inset: rgba(0, 0, 0, 0.15);

    --overlay-dark-75: rgba(7, 16, 38, 0.75);
    --overlay-dark-85: rgba(7, 16, 38, 0.85);
    --overlay-dark-95: rgba(7, 16, 38, 0.95);

    --nav-border-dark: rgba(255, 255, 255, 0.06);
    --nav-border-light: rgba(0, 0, 0, 0.04);
    --nav-bg-light: rgba(255, 255, 255, 0.98);

    --drop-shadow-sun: rgba(255, 223, 93, 0.18);
    --drop-shadow-primary: rgba(37, 99, 235, 0.14);
}

/* Recompute composite shadows using tokenized colors */
:root {
    --box-shadow: 0 4px 6 -1px var(--shadow-1), 0 2px 4 -1px var(--shadow-2);
    --box-shadow-lg: 0 20px 25 -5px var(--shadow-1), 0 10px 10 -5px var(--shadow-2);
}

body {
    font-family: var(--font-primary);
    line-height: 1.6;
    color: var(--text-dark);
    background-color: var(--bg-primary);
}

html {
    scroll-behavior: smooth;
}

/* Utility Classes */
.container {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 1rem;
}

.gradient-text {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    color: var(--primary-color);
}

.section-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-dark);
    text-align: center;
    margin-bottom: 3rem;
    position: relative;
}

.section-title::after {
    content: '';
    position: absolute;
    bottom: -0.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: 4rem;
    height: 0.25rem;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    border-radius: 2px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    font-size: 1rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: var(--text-white);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--box-shadow-lg);
}

.btn-secondary {
    background: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: var(--text-white);
    transform: translateY(-2px);
}

/* Navigation */
.navbar {
    position: fixed;
    top: 0;
    width: 100%;
    /* Use theme-aware background to avoid flashes when theme changes */
    background: var(--bg-primary);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    transition: all 0.3s ease;
}

.nav-container {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 4rem;
}

.nav-logo a {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
    text-decoration: none;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-menu {
    display: flex;
    gap: 2rem;
    margin-left: auto;
    order: 1;
}

.nav-link {
    color: var(--text-dark);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s ease;
    position: relative;
}

.nav-link.active {
    color: var(--primary-color) !important;
}

.nav-link.active::after {
    width: 100% !important;
}

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

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

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

.hamburger {
    display: none;
    flex-direction: column;
    cursor: pointer;
    order: 3;
}

.hamburger .bar {
    width: 25px;
    height: 3px;
    background: var(--text-dark);
    margin: 3px 0;
    transition: 0.3s;
}

/* Hero Section */
.hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    padding-top: 4rem;
}

.hero-container {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 1rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4rem;
    align-items: center;
}

.hero-title {
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--text-dark);
    margin-bottom: 1rem;
    line-height: 1.1;
}

.hero-subtitle {
    font-size: 1.5rem;
    color: var(--text-light);
    margin-bottom: 1.5rem;
    font-weight: 400;
}

.hero-description {
    font-size: 1.125rem;
    color: var(--text-light);
    margin-bottom: 2rem;
    line-height: 1.7;
}

.hero-buttons {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.hero-image {
    display: flex;
    justify-content: center;
    align-items: center;
}

.profile-image {
    width: 300px;
    height: 300px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 6rem;
    color: var(--text-white);
    box-shadow: var(--box-shadow-lg);
}

/* Projects Section */
.projects {
    padding: var(--section-padding);
    background: var(--bg-primary);
}

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
    width: 100%;
}

.project-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 2rem;
    transition: all 0.5s ease;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.project-card.expanded {
    grid-column: 1 / -1;
    width: 100%;
}

.project-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
}

.project-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--box-shadow-lg);
}

.project-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

/* Ensure project text uses theme-aware, high-contrast colors
   so items remain readable in both light and dark themes. */
.project-card h3,
.project-card .project-description,
.project-card .project-link,
.project-card .project-links a {
    color: var(--text-dark);
}

.project-card .project-description {
    color: var(--text-light);
}

/* Keep action links/icon subtle by default, but readable; use primary on hover */
.project-card .project-links a {
    color: var(--text-dark);
}

.project-card .project-links a:hover {
    color: var(--primary-color);
}

.project-content {
    flex: 1;
}

.project-links {
    display: flex;
    gap: 0.5rem;
}

.project-link {
    color: var(--text-light);
    font-size: 1.125rem;
    transition: color 0.3s ease;
}

.project-link:hover {
    color: var(--primary-color);
}

.project-footer {
    display: flex;
    flex-direction: column;
    margin-top: auto;
}

.toggle-description-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    transition: transform 0.3s ease;
    margin-left: auto;
}

.toggle-description-btn:hover {
    color: var(--primary-dark);
}

.toggle-description-btn.down {
    transform: rotate(180deg);
}

.project-tech {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    justify-content: flex-start;
}

.tag {
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: transform 0.3s ease;
}

.tag:hover {
    transform: scale(1.05);
}

.tag.primary {
    background: var(--primary-color);
    color: var(--text-white);
}

.tag.secondary {
    background: var(--bg-secondary);
    color: var(--text-dark);
    border: 1px solid var(--border-color);
}

/* Footer */
.footer {
    /* Use theme-aware variables so footer follows the active theme */
    background: var(--bg-primary);
    color: var(--text-dark);
    text-align: center;
    padding: 2rem 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    .hamburger {
        display: flex;
    }

    .nav-menu {
        position: fixed;
        left: -100%;
        top: 4rem;
        flex-direction: column;
        background-color: var(--bg-primary);
        width: 100%;
        text-align: center;
        transition: 0.3s;
        box-shadow: var(--box-shadow);
        padding: 2rem 0;
    }

    .nav-menu.active {
        left: 0;
    }

    .hero-container {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .hero-title {
        font-size: 2.5rem;
    }

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

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

@media (max-width: 480px) {
    .hero-title {
        font-size: 2rem;
    }

    .section-title {
        font-size: 2rem;
    }

    .profile-image {
        width: 200px;
        height: 200px;
        font-size: 4rem;
    }
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

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

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.hero-content,
.about-content,
.project-card {
    animation: fadeInUp 0.6s ease-out;
}

/* Theme: Dark overrides (applies when `data-theme="dark"` is set on <html>) */
:root[data-theme="dark"] {
    /* slightly lighter for contrast */
    --primary-color: #60a5fa;
    --primary-dark: #3b82f6;
    --secondary-color: #94a3b8;
    --accent-color: #06b6d4;
    --text-dark: #e6eef8;
    --text-light: #cbd5e1;
    --text-white: #ffffff;
    /* deep navy */
    --bg-primary: #071026;
    /* slightly lighter */
    --bg-secondary: #0b1524;
    --bg-dark: #020617;
    --border-color: var(--nav-border-dark);
    /* dark-specific shadow tokens */
    --shadow-dark-1: rgba(2, 6, 23, 0.6);
    --shadow-dark-2: rgba(2, 6, 23, 0.7);
    --box-shadow: 0 6px 18px var(--shadow-dark-1);
    --box-shadow-lg: 0 30px 40px var(--shadow-dark-2);
}

:root[data-theme="dark"] {
    /* ensure sun icon remains visible on dark backgrounds */
    --sun-color: #ffd166;
}

/* Navbar and other element adjustments for dark theme */
:root[data-theme="dark"] .navbar {
    background: var(--overlay-dark-75);
    border-bottom: 1px solid var(--nav-border-dark);
}

/* Explicit light-theme navbar rules so the page does not rely on JS
   to render the correct navbar background. If `data-theme="light"` is
   present on the root, these rules take precedence over the prefers-color
   scheme fallback. */
html[data-theme="light"] .navbar,
:root[data-theme="light"] .navbar {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

:root[data-theme="dark"] .nav-logo a {
    color: var(--primary-color);
}

:root[data-theme="dark"] .hamburger .bar {
    background: var(--text-light);
}

/* Make the overall page background consistent in dark mode so the center
   column doesn't show a different gradient from the sides. Use the same
   gradient across the body and make the hero background transparent to
   avoid a hard visual break. */
:root[data-theme="dark"] body {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    color: var(--text-dark);
}

:root[data-theme="dark"] .hero {
    background: transparent;
}

/* Theme toggle switch styles (simple accessible switch) */
.theme-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.theme-switch input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-switch .switch {
    width: 52px;
    height: 28px;
    background: var(--border-color);
    border-radius: 999px;
    position: relative;
    transition: background 200ms ease;
    box-shadow: inset 0 1px 2px var(--shadow-inset);
    display: inline-block;
}

.theme-switch .switch svg.icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    fill: currentColor;
    color: var(--text-light);
    transition: opacity 180ms ease, color 180ms ease, filter 180ms ease;
    opacity: 0.9;
    z-index: 3;
}

.theme-switch .switch svg.icon.sun {
    left: 6px;
}

.theme-switch .switch svg.icon.moon {
    right: 6px;
}

.theme-switch .switch::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 4px;
    width: 20px;
    height: 20px;
    background: var(--text-white);
    border-radius: 50%;
    transition: transform 200ms ease, background 200ms ease;
    z-index: 2;
}

.theme-switch input[type="checkbox"]:checked+.switch {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
}

.theme-switch input[type="checkbox"]:checked+.switch::after {
    transform: translateX(24px);
}

/* Highlight the "future" (target) theme icon — the icon representing
   the theme the switch will change to — and dim the icon for the
   currently active theme. */

/* When checked (dark active), the future theme is light → highlight sun */
.theme-switch input[type="checkbox"]:checked+.switch .icon.sun {
    color: var(--sun-color);
    opacity: 1;
    filter: drop-shadow(0 6px 12px var(--drop-shadow-sun));
}

.theme-switch input[type="checkbox"]:checked+.switch .icon.moon {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    filter: none;
    transition: opacity 180ms ease, visibility 180ms ease;
}

/* When not checked (light active), the future theme is dark → highlight moon */
.theme-switch input[type="checkbox"]:not(:checked)+.switch .icon.moon {
    color: var(--primary-color);
    opacity: 1;
    filter: drop-shadow(0 6px 12px var(--drop-shadow-primary));
}

.theme-switch input[type="checkbox"]:not(:checked)+.switch .icon.sun {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    filter: none;
    transition: opacity 180ms ease, visibility 180ms ease;
}

/* Smooth scrolling for older browsers */
@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

/* Respect system dark preference only when no explicit `data-theme` is set
   (this avoids the OS-level rule overriding an explicit user/site choice). */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .navbar {
        background: var(--overlay-dark-85);
        border-bottom: 1px solid var(--nav-border-dark);
        backdrop-filter: blur(10px);
    }

    :root:not([data-theme]) body {
        background: linear-gradient(135deg, #0b1524 0%, #071026 100%);
        color: #e6eef8;
    }

    :root:not([data-theme]) .hamburger .bar {
        background: #cbd5e1;
    }
}

/* Extra high-specificity navbar overrides to ensure dark theme applies
   (some browsers/caches or ordering can prevent the earlier rules from taking effect) */
html[data-theme="dark"] .navbar,
:root[data-theme="dark"] .navbar {
    background: var(--overlay-dark-85);
    border-bottom: 1px solid var(--nav-border-dark);
    backdrop-filter: blur(10px);
}

html[data-theme="dark"] .nav-link {
    color: var(--text-dark);
}

html[data-theme="dark"] .hamburger .bar {
    background: var(--text-light);
}

/* Scrolled navbar styles — theme-aware */
.navbar.scrolled {
    box-shadow: 0 2px 10px var(--shadow-3);
}

/* Light theme scrolled background */
html[data-theme="light"] .navbar.scrolled,
:root[data-theme="light"] .navbar.scrolled {
    background: var(--nav-bg-light);
    border-bottom: 1px solid var(--nav-border-light);
}

/* Dark theme scrolled background */
html[data-theme="dark"] .navbar.scrolled,
:root[data-theme="dark"] .navbar.scrolled {
    background: var(--overlay-dark-95);
    border-bottom: 1px solid var(--nav-border-dark);
    box-shadow: 0 2px 14px var(--shadow-dark-1);
}
