:root {
    --bg: #f8f9fc;
    --surface: #ffffff;
    --text: #1a2332;
    --text-muted: #5c6778;
    --border: #e2e8f0;
    --primary: #1e3a5f;
    --primary-light: #2d5a8a;
    --accent: #c9a227;
    --accent-soft: rgba(201, 162, 39, 0.12);
    --shadow: 0 4px 24px rgba(30, 58, 95, 0.08);
    --shadow-lg: 0 12px 40px rgba(30, 58, 95, 0.12);
    --radius: 12px;
    --radius-lg: 20px;
    --nav-height: 72px;
    --font-body: 'Inter', system-ui, sans-serif;
    --font-display: 'Playfair Display', Georgia, serif;
    --transition: 0.25s ease;
    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #0f1419;
    --surface: #1a2332;
    --text: #eef2f7;
    --text-muted: #94a3b8;
    --border: #2d3a4d;
    --primary: #7eb8ff;
    --primary-light: #a8d0ff;
    --accent: #e8c547;
    --accent-soft: rgba(232, 197, 71, 0.15);
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    line-height: 1.65;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    transition: background-color var(--transition), color var(--transition);
}

body.modal-open {
    overflow: hidden;
}

::selection {
    background: var(--accent);
    color: #fff;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

a {
    color: var(--primary);
}

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 4px;
}

.skip-link {
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 3000;
    padding: 0.65rem 0.9rem;
    background: var(--surface);
    color: var(--primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    font-weight: 700;
    text-decoration: none;
    transform: translateY(-160%);
    transition: transform var(--transition);
}

.skip-link:focus {
    transform: translateY(0);
}

/* Navigation */
.nav-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: var(--nav-height);
    background: rgba(248, 249, 252, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    transition: background var(--transition), border-color var(--transition);
}

[data-theme="dark"] .nav-bar {
    background: rgba(15, 20, 25, 0.9);
}

.nav-brand {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.35rem;
    color: var(--primary);
    text-decoration: none;
    letter-spacing: 0.02em;
}

.nav-links {
    display: flex;
    list-style: none;
    margin: 0;
    padding: 0;
    gap: 0.25rem;
}

.nav-links a {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.925rem;
    font-weight: 500;
    border-radius: 8px;
    transition: color var(--transition), background var(--transition);
}

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

.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
}

.nav-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: var(--transition);
}

.theme-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    margin-left: 1rem;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.theme-slider {
    width: 48px;
    height: 26px;
    background: var(--border);
    border-radius: 26px;
    transition: background var(--transition);
    position: relative;
}

.theme-slider::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    background: var(--surface);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform var(--transition);
}

.theme-switch input:checked + .theme-slider {
    background: var(--primary);
}

.theme-switch input:checked + .theme-slider::after {
    transform: translateX(22px);
}

/* Hero */
.hero {
    min-height: 100vh;
    padding: calc(var(--nav-height) + 3rem) 2rem 4rem;
    background:
        radial-gradient(ellipse at 20% 50%, var(--accent-soft) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(30, 58, 95, 0.06) 0%, transparent 40%),
        var(--bg);
}

.hero-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 3.5rem;
    align-items: center;
}

.hero-photo-wrap {
    position: relative;
}

.hero-photo-wrap::before {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    opacity: 0.25;
    z-index: 0;
}

.hero-photo {
    position: relative;
    z-index: 1;
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    object-position: center top;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 3px solid var(--surface);
}

.hero-eyebrow {
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    margin: 0 0 0.75rem;
}

.hero-text h1 {
    font-family: var(--font-display);
    font-size: clamp(2.25rem, 5vw, 3.25rem);
    font-weight: 700;
    line-height: 1.15;
    margin: 0 0 1rem;
    color: var(--text);
}

.hero-tagline {
    font-size: 1.125rem;
    color: var(--text-muted);
    max-width: 540px;
    margin: 0 0 2rem;
}

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

/* Layout */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 2rem 4rem;
}

.section {
    padding: 5rem 0;
    scroll-margin-top: var(--nav-height);
}

.theme-switch:focus-within .theme-slider {
    outline: 3px solid var(--accent);
    outline-offset: 4px;
}

.container .section:first-child {
    padding-top: 4rem;
}

.section-header {
    margin-bottom: 2.5rem;
}

.section-label {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.section-header h2 {
    font-family: var(--font-display);
    font-size: clamp(1.75rem, 3vw, 2.25rem);
    font-weight: 700;
    margin: 0;
    color: var(--text);
}

/* About */
.about-grid {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 3rem;
    align-items: start;
}

.about-photo-card {
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.about-photo-card img {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    object-position: center top;
}

.about-content p {
    margin: 0 0 1.25rem;
    color: var(--text-muted);
}

.about-content p:last-child {
    margin-bottom: 0;
}

/* Skills */
.skills-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
}

.skill-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem;
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
}

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

.skill-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 1rem;
    color: var(--primary);
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tag {
    display: inline-block;
    padding: 0.35rem 0.85rem;
    font-size: 0.825rem;
    font-weight: 500;
    background: var(--accent-soft);
    color: var(--text);
    border-radius: 999px;
    border: 1px solid var(--border);
}

.highlight-list {
    margin: 0;
    padding-left: 1.25rem;
    color: var(--text-muted);
}

.highlight-list li {
    margin-bottom: 0.5rem;
}

.highlight-list li:last-child {
    margin-bottom: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.4rem;
    font-family: inherit;
    font-size: 0.925rem;
    font-weight: 600;
    color: #fff;
    background: var(--primary);
    border: 2px solid var(--primary);
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn:hover {
    background: var(--primary-light);
    border-color: var(--primary-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

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

.btn-secondary {
    background: transparent;
    color: var(--primary);
}

.btn-secondary:hover {
    background: var(--accent-soft);
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border-color: var(--border);
}

.btn-outline:hover {
    background: var(--surface);
    border-color: var(--primary);
}

/* Projects */
.project {
    margin-bottom: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.project-list {
    display: grid;
    gap: 1rem;
}

.project.open,
.project:has(.dropdown-btn[aria-expanded="true"]) {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
}

.dropdown-btn {
    width: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.25rem;
    padding: 1.35rem 1.5rem 0.65rem;
    background: transparent;
    border: none;
    border-radius: 0;
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    text-align: left;
    box-shadow: none;
    transition: background var(--transition);
}

.dropdown-btn:hover {
    background: var(--accent-soft);
}

.dropdown-btn:focus-visible {
    outline-offset: -5px;
}

.dropdown-btn[aria-expanded="true"] {
    background: var(--accent-soft);
}

.project-heading {
    display: grid;
    gap: 0.25rem;
    flex: 1;
}

.project-title {
    display: block;
}

.project-summary {
    display: block;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.45;
}

.dropdown-icon {
    width: 10px;
    height: 10px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(45deg);
    transition: transform var(--transition);
    margin-left: 1rem;
    flex-shrink: 0;
}

.dropdown-btn[aria-expanded="true"] .dropdown-icon {
    transform: rotate(-135deg);
}

.project-preview {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: center;
    padding: 0.9rem 1.5rem 1.25rem;
}

.dropdown-container {
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-radius: 0;
    padding: 1.5rem;
    margin: 0;
}

.dropdown-container p {
    color: var(--text-muted);
    margin: 0 0 1.25rem;
}

.project-features {
    margin: 0 0 1.25rem;
    padding-left: 1.25rem;
    color: var(--text-muted);
}

.project-features li {
    margin-bottom: 0.4rem;
}

.project-features li:last-child {
    margin-bottom: 0;
}

.project-tech {
    font-size: 0.925rem;
    color: var(--text-muted);
    margin: 0 0 1.25rem !important;
}

.project-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: flex-end;
}

.dropdown-container .project-links {
    justify-content: flex-start;
    margin-top: 1.25rem;
}

.hidden {
    display: none !important;
}

/* Resume */
.resume-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
}

.resume-item {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.resume-item:last-of-type {
    border-bottom: none;
    margin-bottom: 2rem;
    padding-bottom: 0;
}

.resume-item h3 {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
    margin: 0 0 0.5rem;
}

.resume-item p {
    margin: 0;
    color: var(--text-muted);
}

.resume-entry {
    margin-bottom: 1.5rem;
}

.resume-entry:last-child {
    margin-bottom: 0;
}

.resume-entry-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem 1rem;
    margin-bottom: 0.25rem;
}

.resume-entry-header strong {
    color: var(--text);
    font-size: 1rem;
}

.resume-date {
    font-size: 0.875rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.resume-org {
    font-size: 0.925rem;
    font-weight: 500;
    color: var(--primary);
    margin: 0 0 0.5rem !important;
}

.resume-bullets {
    margin: 0;
    padding-left: 1.25rem;
    color: var(--text-muted);
}

.resume-bullets li {
    margin-bottom: 0.4rem;
}

.resume-bullets li:last-child {
    margin-bottom: 0;
}

/* Contact */
.contact-intro {
    color: var(--text-muted);
    margin: -1rem 0 2rem;
    max-width: 560px;
}

.contact-group {
    margin-bottom: 2rem;
}

.contact-group:last-child {
    margin-bottom: 0;
}

.contact-group h3 {
    margin: 0 0 1rem;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.contact-group-secondary {
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.contact-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
}

.contact-grid-secondary {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.contact-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow);
    transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.contact-link:hover {
    transform: translateY(-3px);
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
}

.contact-icon {
    width: 28px;
    height: 28px;
    filter: brightness(0) saturate(100%) invert(18%) sepia(30%) saturate(1200%) hue-rotate(182deg) brightness(95%) contrast(95%);
}

[data-theme="dark"] .contact-icon {
    filter: brightness(0) saturate(100%) invert(78%) sepia(21%) saturate(600%) hue-rotate(182deg) brightness(103%) contrast(101%);
}

/* Popups */
.popup {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(15, 20, 25, 0.6);
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.popup-content {
    background: var(--surface);
    color: var(--text);
    padding: 2rem;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    position: relative;
}

.popup-content h2 {
    font-family: var(--font-display);
    margin: 0 0 1.25rem;
}

.popup-content label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-muted);
}

.popup-content select,
.popup-content input[type="text"] {
    width: 100%;
    padding: 0.65rem 0.85rem;
    margin-bottom: 1rem;
    font-family: inherit;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
}

.popup .close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.75rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    border-radius: 6px;
}

.popup .close:hover {
    color: var(--text);
}

#puzzleContainer {
    display: grid;
    gap: 5px;
    margin: 1.25rem 0;
}

.tile {
    aspect-ratio: 1;
    background: var(--primary);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.25rem;
    font-weight: 600;
    min-height: 44px;
    cursor: pointer;
    border-radius: 8px;
    user-select: none;
    touch-action: manipulation;
    transition: background var(--transition);
}

.tile.correct {
    background: #2d8a5e;
}

.tile.finished {
    background: var(--accent);
    color: var(--text);
}

.tile:hover {
    filter: brightness(1.1);
}

/* Back to top */
#backToTop {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 44px;
    height: 44px;
    padding: 0;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition), transform var(--transition);
    z-index: 999;
}

#backToTop.visible {
    opacity: 1;
    visibility: visible;
}

#backToTop:hover {
    transform: translateY(-3px);
}

/* Footer */
footer {
    background: var(--primary);
    color: rgba(255, 255, 255, 0.85);
    text-align: center;
    padding: 2rem;
    font-size: 0.875rem;
}

[data-theme="dark"] footer {
    background: #0a0e14;
    border-top: 1px solid var(--border);
}

footer p {
    margin: 0;
}

/* Responsive */
@media (max-width: 900px) {
    .hero {
        min-height: auto;
        padding-top: calc(var(--nav-height) + 2rem);
        padding-bottom: 3rem;
    }

    .hero-inner {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 1.5rem;
    }

    .hero-photo-wrap {
        max-width: 220px;
        margin: 0 auto;
    }

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

    .hero-actions {
        justify-content: center;
    }

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

    .about-photo-card {
        max-width: 240px;
        margin: 0 auto 1rem;
    }

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

    .project-preview {
        grid-template-columns: 1fr;
        align-items: start;
    }

    .project-links {
        justify-content: flex-start;
    }
}

@media (max-width: 768px) {
    .nav-toggle {
        display: flex;
    }

    .nav-links {
        position: fixed;
        top: var(--nav-height);
        left: 0;
        right: 0;
        flex-direction: column;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        padding: 1rem;
        gap: 0;
        transform: translateY(-120%);
        opacity: 0;
        visibility: hidden;
        transition: transform var(--transition), opacity var(--transition), visibility var(--transition);
        box-shadow: var(--shadow-lg);
    }

    .nav-links.open {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }

    .nav-links a {
        padding: 0.85rem 1rem;
    }

    .nav-bar {
        padding: 0 1.25rem;
    }

    .container {
        padding: 0 1.25rem 3rem;
    }

    .section {
        padding: 3.5rem 0;
    }

    .container .section:first-child {
        padding-top: 2.5rem;
    }

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

    .dropdown-btn {
        padding: 1.15rem 1.25rem 0.6rem;
    }

    .project-preview,
    .dropdown-container {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }
}

@media (max-width: 480px) {
    .hero {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }

    .hero-photo-wrap {
        max-width: 180px;
    }

    .hero-tagline {
        font-size: 1rem;
        margin-bottom: 1.25rem;
    }

    .hero-actions {
        gap: 0.75rem;
    }

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

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

    .contact-link {
        padding: 1rem 0.75rem;
    }

    .tile {
        min-height: 36px;
        font-size: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
