:root {
    --font-serif: 'EB Garamond', Georgia, serif;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #232323;
    --bg-card: #2a2a2a;
    --text-primary: #f0ede8;
    --text-secondary: #a8a29e;
    --text-muted: #6b6560;
    --accent: #d4a574;
    --accent-glow: rgba(212, 165, 116, 0.15);
    --border: rgba(255, 255, 255, 0.06);
    --particle-color: 212, 165, 116;
    --particle-secondary: 168, 162, 158;
    --header-bg: rgba(26, 26, 26, 0.85);
}

[data-theme="light"] {
    --bg-primary: #faf8f5;
    --bg-secondary: #f0ede8;
    --bg-card: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #57534e;
    --text-muted: #a8a29e;
    --accent: #9e6b3a;
    --accent-glow: rgba(158, 107, 58, 0.08);
    --border: rgba(0, 0, 0, 0.06);
    --particle-color: 158, 107, 58;
    --particle-secondary: 87, 83, 78;
    --header-bg: rgba(250, 248, 245, 0.85);
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
    /* Prevent iOS text size inflation */
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    transition: background 0.4s ease, color 0.4s ease;
    overflow-x: hidden;
    /* iOS momentum scrolling */
    -webkit-overflow-scrolling: touch;
    /* Respect safe area for notch/dynamic island */
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

#brain-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    /* Prevent iOS canvas flicker during scroll */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: contents;
}

/* Header */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
}

.site-header nav {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: -0.01em;
}

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

.nav-right a {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-secondary);
    text-decoration: none;
    letter-spacing: 0.02em;
    transition: color 0.2s;
}

.nav-right a:hover {
    color: var(--text-primary);
}

#theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s, border-color 0.2s;
}

#theme-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
}

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

/* Container */
.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Hero */
.hero {
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for iOS Safari */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
}

.hero-content {
    text-align: center;
    max-width: 720px;
    padding: 2rem 2.5rem;
    background: radial-gradient(ellipse at center, var(--bg-primary) 0%, transparent 70%);
    border-radius: 24px;
}

.hero-eyebrow {
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 1.5rem;
}

.hero h1 {
    font-family: var(--font-serif);
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    font-weight: 400;
    line-height: 1.15;
    letter-spacing: -0.02em;
    margin-bottom: 1.5rem;
    text-shadow: 0 0 30px var(--bg-primary), 0 0 60px var(--bg-primary);
}

.hero-subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    line-height: 1.8;
    max-width: 580px;
    margin: 0 auto 2.5rem;
}

.scroll-cta {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
    animation: float 3s ease-in-out infinite;
}

.scroll-cta:hover {
    color: var(--accent);
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(6px); }
}

/* Section labels */
.section-label {
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 3rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

/* About */
.about {
    padding: 5rem 0;
    position: relative;
    z-index: 1;
}

.about-content {
    max-width: 680px;
    margin-bottom: 4rem;
}

.about-content p {
    font-size: 1.05rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.85;
}

.about-content p:first-child::first-letter {
    font-family: var(--font-serif);
    font-size: 3.5rem;
    float: left;
    line-height: 0.8;
    margin-right: 0.1em;
    margin-top: 0.05em;
    color: var(--accent);
}

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

.skill-group h3 {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

.skill-group ul {
    list-style: none;
}

.skill-group li {
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
}

.skill-group li:last-child {
    border-bottom: none;
}

/* Certifications */
.certifications {
    padding: 5rem 0;
    position: relative;
    z-index: 1;
}

.certs-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    justify-content: center;
}

.cert-badge {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    padding: 1rem;
    border-radius: 12px;
    transition: transform 0.3s ease;
}

.cert-badge:hover {
    transform: translateY(-4px) scale(1.05);
}

.cert-badge img {
    width: 110px;
    height: 110px;
    object-fit: contain;
    transition: filter 0.3s ease;
}

.cert-badge img[src*="db_trans"] {
    width: 170px;
    height: 170px;
}

.cert-badge:hover img {
    filter: drop-shadow(0 4px 12px rgba(212, 165, 116, 0.35));
}

.cert-badge span {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.cert-badge:hover span {
    opacity: 1;
    transform: translateX(-50%) translateY(calc(100% + 4px));
}

/* Work */
.work {
    padding: 5rem 0;
    position: relative;
    z-index: 1;
}

.projects {
    display: grid;
    gap: 1.5rem;
}

.project-card {
    background: color-mix(in srgb, var(--bg-card) 88%, transparent);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem 2.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    position: relative;
    overflow: hidden;
}

.project-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.3s;
}

.project-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    border-color: rgba(212, 165, 116, 0.2);
}

.project-card:hover::before {
    opacity: 1;
}

.project-number {
    font-family: var(--font-serif);
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.project-card h3 {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    letter-spacing: -0.01em;
}

.project-org {
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 500;
    margin-bottom: 0.75rem;
}

.project-desc {
    font-size: 0.92rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 1rem;
}

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

.project-tags span {
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    padding: 0.3rem 0.75rem;
    border-radius: 100px;
    background: var(--accent-glow);
    color: var(--accent);
    border: 1px solid rgba(212, 165, 116, 0.15);
}

/* Cool Projects */
.cool-projects {
    padding: 5rem 0;
    position: relative;
    z-index: 1;
}

.subsection-label {
    font-family: var(--font-serif);
    font-size: 1.3rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    margin-top: 2.5rem;
}

.subsection-label:first-of-type {
    margin-top: 0;
}

.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.25rem;
}

.projects-grid.single-row {
    grid-template-columns: repeat(4, 1fr);
}

.cool-project-card {
    display: block;
    text-decoration: none;
    color: inherit;
    background: color-mix(in srgb, var(--bg-card) 88%, transparent);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.75rem 2rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.cool-project-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    border-color: rgba(212, 165, 116, 0.2);
}

.cool-project-type {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.cool-project-card h3 {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    letter-spacing: -0.01em;
}

.cool-project-card p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Contact */
.contact {
    padding: 5rem 0;
    position: relative;
    z-index: 1;
}

.contact h2 {
    font-family: var(--font-serif);
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 400;
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
}

.contact-desc {
    font-size: 1rem;
    color: var(--text-secondary);
    max-width: 480px;
    margin-bottom: 2.5rem;
    line-height: 1.7;
}

.contact-links {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.contact-links a {
    font-size: 1.1rem;
    color: var(--text-primary);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    transition: color 0.2s, padding-left 0.2s;
}

.contact-links a:hover {
    color: var(--accent);
    padding-left: 0.5rem;
}

.contact-links a span {
    transition: transform 0.2s;
}

.contact-links a:hover span {
    transform: translateX(4px);
}

/* Footer */
footer {
    padding: 2rem 0;
    border-top: 1px solid var(--border);
    position: relative;
    z-index: 1;
}

footer .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

footer span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.footer-tagline {
    font-family: var(--font-serif);
    font-style: italic;
}

/* Fade-in animations */
.about, .certifications, .work, .cool-projects, .contact {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.about.visible, .certifications.visible, .work.visible, .cool-projects.visible, .contact.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Responsive */
@media (max-width: 768px) {
    .site-header nav {
        padding: 0.75rem 1.25rem;
    }

    .nav-right {
        gap: 1.25rem;
    }

    .nav-right a {
        font-size: 0.8rem;
    }

    .container {
        padding: 0 1.25rem;
    }

    .hero-content {
        padding: 1rem;
    }

    .about, .work, .contact, .cool-projects {
        padding: 3.5rem 0;
    }

    .project-card {
        padding: 1.5rem;
    }

    .skills-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }

    .projects-grid.single-row {
        grid-template-columns: repeat(2, 1fr);
    }

    footer .container {
        flex-direction: column;
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    .skills-grid {
        grid-template-columns: 1fr;
    }

    .nav-right a:not(:last-child) {
        display: none;
    }
}

/* iOS-specific safe area and touch adjustments */
@supports (padding: env(safe-area-inset-bottom)) {
    footer {
        padding-bottom: calc(2rem + env(safe-area-inset-bottom));
    }

    .site-header nav {
        padding-top: calc(1rem + env(safe-area-inset-top));
    }
}

/* Tap target sizing for touch devices */
@media (pointer: coarse) {
    .nav-right a {
        padding: 0.5rem;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

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

    .contact-links a {
        min-height: 48px;
        display: flex;
        align-items: center;
    }

    .scroll-cta {
        padding: 0.75rem;
        min-height: 44px;
    }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .scroll-cta {
        animation: none;
    }

    .about, .certifications, .work, .cool-projects, .contact {
        opacity: 1;
        transform: none;
        transition: none;
    }
}
