:root {
    --bg: #f2f3f5;
    --surface: #ffffff;
    --ink: #0f1115;
    --muted: #5f6470;
    --line: rgba(15, 17, 21, 0.12);
    --accent: #3346ff;
    --accent-soft: rgba(51, 70, 255, 0.12);
    --blob-a: #a9b6ff;
    --blob-b: #b5ecdc;
    --blob-c: #d6c4ff;
    --grain-opacity: 0.35;

    --serif: "Instrument Serif", Georgia, "Times New Roman", serif;
    --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --max: 1120px;
    --gutter: clamp(16px, 4vw, 40px);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0b0c10;
        --surface: #14161c;
        --ink: #eef0f4;
        --muted: #9097a3;
        --line: rgba(238, 240, 244, 0.12);
        --accent: #8593ff;
        --accent-soft: rgba(133, 147, 255, 0.16);
        --blob-a: #1c2a8a;
        --blob-b: #0d4a43;
        --blob-c: #3a1f70;
        --grain-opacity: 0.18;
    }
}

:root[data-theme="dark"] {
    --bg: #0b0c10;
    --surface: #14161c;
    --ink: #eef0f4;
    --muted: #9097a3;
    --line: rgba(238, 240, 244, 0.12);
    --accent: #8593ff;
    --accent-soft: rgba(133, 147, 255, 0.16);
    --blob-a: #1c2a8a;
    --blob-b: #0d4a43;
    --blob-c: #3a1f70;
    --grain-opacity: 0.18;
}

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 17px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* Film grain over everything, very subtle */
body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    opacity: var(--grain-opacity);
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.35 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

a {
    color: inherit;
}

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

.wrap {
    width: 100%;
    max-width: var(--max);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

/* ---------- Header ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    background: color-mix(in srgb, var(--bg) 72%, transparent);
    border-bottom: 1px solid transparent;
    transition: border-color 0.3s ease;
}

.site-header.scrolled {
    border-bottom-color: var(--line);
}

.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 68px;
}

.mark {
    font-family: var(--serif);
    font-style: italic;
    font-size: 28px;
    text-decoration: none;
    letter-spacing: -0.02em;
    line-height: 1;
}

.mark span {
    color: var(--accent);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: clamp(14px, 3vw, 32px);
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 15px;
}

.nav-links a {
    text-decoration: none;
    color: var(--muted);
    transition: color 0.2s ease;
}

.nav-links a:hover {
    color: var(--ink);
}

.theme-toggle {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.3s ease;
}

.theme-toggle:hover {
    border-color: var(--ink);
    transform: rotate(-20deg);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

.icon-sun {
    display: none;
}

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

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

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .icon-sun {
        display: block;
    }

    :root:not([data-theme="light"]) .icon-moon {
        display: none;
    }
}

/* ---------- Hero ---------- */
.hero {
    position: relative;
    min-height: calc(100svh - 68px);
    display: flex;
    align-items: center;
    padding: clamp(48px, 10vh, 120px) 0 clamp(56px, 10vh, 120px);
    isolation: isolate;
}

.blobs {
    position: absolute;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

/* Fade the hero background out instead of cutting it off at the bottom edge */
.blobs,
.flight {
    -webkit-mask-image: linear-gradient(to bottom, #000 50%, transparent 100%);
    mask-image: linear-gradient(to bottom, #000 50%, transparent 100%);
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(70px);
    opacity: 0.75;
    will-change: transform;
}

.blob.a {
    width: 46vmax;
    height: 46vmax;
    background: var(--blob-a);
    top: -12vmax;
    right: -10vmax;
    animation: drift-a 22s ease-in-out infinite alternate;
}

.blob.b {
    width: 34vmax;
    height: 34vmax;
    background: var(--blob-b);
    bottom: -14vmax;
    right: 18vw;
    animation: drift-b 26s ease-in-out infinite alternate;
}

.blob.c {
    width: 26vmax;
    height: 26vmax;
    background: var(--blob-c);
    top: 20vh;
    right: 28vw;
    opacity: 0.5;
    animation: drift-c 30s ease-in-out infinite alternate;
}

@keyframes drift-a {
    to {
        transform: translate(-8vmax, 6vmax) scale(1.08);
    }
}

@keyframes drift-b {
    to {
        transform: translate(10vmax, -6vmax) scale(0.92);
    }
}

@keyframes drift-c {
    to {
        transform: translate(-6vmax, -8vmax) scale(1.15);
    }
}

.hero h1 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: clamp(64px, 14.5vw, 196px);
    line-height: 0.88;
    letter-spacing: -0.035em;
    margin: 0;
}

.hero h1 .line {
    display: block;
}

.hero h1 em {
    color: var(--accent);
    padding-left: 0.08em;
}

.hero-foot {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 32px;
    align-items: end;
    margin-top: clamp(32px, 6vh, 64px);
}

.lede {
    max-width: 34ch;
    font-size: clamp(19px, 2.2vw, 24px);
    line-height: 1.45;
    margin: 0;
    letter-spacing: -0.01em;
}

.lede .muted {
    color: var(--muted);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 22px;
    border-radius: 999px;
    background: var(--ink);
    color: var(--bg);
    text-decoration: none;
    font-weight: 500;
    font-size: 16px;
    white-space: nowrap;
    transition: transform 0.25s ease, background-color 0.25s ease;
}

.btn:hover {
    background: var(--accent);
    color: #fff;
    transform: translateY(-2px);
}

.btn svg {
    width: 16px;
    height: 16px;
    transition: transform 0.25s ease;
}

.btn:hover svg {
    transform: translateX(3px);
}

/* ---------- Sections ---------- */
section {
    padding: clamp(80px, 14vh, 140px) 0;
}

section.flush-top {
    padding-top: 0;
}

.section-label {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
    margin-bottom: 28px;
}

.section-label::before {
    content: "";
    width: 28px;
    height: 1px;
    background: currentColor;
}

h2 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: clamp(42px, 6.5vw, 84px);
    line-height: 1;
    letter-spacing: -0.03em;
    margin: 0;
}

h2 em {
    color: var(--accent);
}

/* About */
.about-grid {
    display: grid;
    grid-template-columns: 5fr 6fr;
    gap: clamp(32px, 6vw, 96px);
    align-items: start;
}

.facts {
    list-style: none;
    margin: 0;
    padding: 0;
    border-top: 1px solid var(--line);
}

.facts li {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 24px;
    padding: 26px 0;
    border-bottom: 1px solid var(--line);
    transition: padding-left 0.3s ease;
}

.facts li:hover {
    padding-left: 12px;
}

.facts .k {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--muted);
    padding-top: 6px;
}

.facts .v {
    font-size: clamp(20px, 2.2vw, 26px);
    line-height: 1.35;
    letter-spacing: -0.01em;
}

/* Projects */
.links {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-top: clamp(32px, 6vh, 56px);
}

.link-card {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    min-height: 200px;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--surface);
    text-decoration: none;
    overflow: hidden;
    isolation: isolate;
    transition: transform 0.35s ease, border-color 0.35s ease, color 0.35s ease;
}

.link-card::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--accent);
    transform: translateY(101%);
    transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.link-card:hover,
.link-card:focus-visible {
    transform: translateY(-4px);
    border-color: var(--accent);
    color: #fff;
}

.link-card:hover::before,
.link-card:focus-visible::before {
    transform: none;
}

.link-name {
    display: block;
    font-family: var(--serif);
    font-size: clamp(40px, 5vw, 60px);
    line-height: 1;
    letter-spacing: -0.02em;
}

.link-url {
    display: block;
    margin-top: 10px;
    font-size: 15px;
    opacity: 0.65;
    overflow-wrap: anywhere;
}

.link-arrow {
    flex: none;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 999px;
    border: 1px solid currentColor;
    transition: transform 0.35s ease;
}

.link-arrow svg {
    width: 18px;
    height: 18px;
}

.link-card:hover .link-arrow {
    transform: rotate(45deg);
}

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

    .link-card {
        min-height: 150px;
    }
}

/* Contact */
.contact {
    text-align: center;
}

.contact .section-label {
    justify-content: center;
}

.contact .section-label::after {
    content: "";
    width: 28px;
    height: 1px;
    background: currentColor;
}

.contact h2 {
    font-size: clamp(56px, 11vw, 150px);
    line-height: 0.92;
}

.contact p {
    color: var(--muted);
    max-width: 40ch;
    margin: 28px auto 40px;
    font-size: clamp(18px, 1.8vw, 21px);
}

.email {
    position: relative;
    display: inline-block;
    font-family: var(--serif);
    font-size: clamp(30px, 5vw, 56px);
    text-decoration: none;
    letter-spacing: -0.02em;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.email::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: var(--accent);
    transform: scaleX(0.25);
    transform-origin: left;
    transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.email:hover::after {
    transform: scaleX(1);
}

/* 404 */
.not-found {
    min-height: calc(100svh - 68px - 86px);
    display: flex;
    align-items: center;
    text-align: center;
}

.not-found h1 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: clamp(96px, 22vw, 260px);
    line-height: 0.9;
    letter-spacing: -0.04em;
    margin: 0;
}

.not-found h1 em {
    color: var(--accent);
}

.not-found p {
    color: var(--muted);
    margin: 20px auto 36px;
    font-size: clamp(18px, 1.8vw, 21px);
}

/* Footer */
footer {
    border-top: 1px solid var(--line);
    padding: 28px 0;
    font-size: 14px;
    color: var(--muted);
}

.foot {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.foot a {
    text-decoration: none;
}

.foot a:hover {
    color: var(--ink);
}

/* Hero entrance: pure CSS, so it starts on first paint without waiting for JS.
   .rise only moves (the name stays visible, which keeps LCP fast);
   .fade also fades in, for smaller secondary elements. */
.rise {
    animation: rise 0.9s cubic-bezier(0.2, 0.8, 0.2, 1) var(--d, 0s) both;
}

.rise.fade {
    animation-name: rise-fade;
}

@keyframes rise {
    from {
        transform: translateY(24px);
    }
}

@keyframes rise-fade {
    from {
        opacity: 0;
        transform: translateY(24px);
    }
}

/* Reveal on scroll. Only hidden when JS is present (.js is set in <head> before paint). */
.js .reveal {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.9s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.9s cubic-bezier(0.2, 0.8, 0.2, 1);
    transition-delay: var(--d, 0s);
}

.js .reveal.in {
    opacity: 1;
    transform: none;
}

/* ---------- Hero flight path ---------- */
.flight {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    pointer-events: none;
}

.route {
    fill: none;
    stroke: var(--ink);
    stroke-opacity: 0.22;
    stroke-width: 1.6;
    stroke-dasharray: 2 10;
    stroke-linecap: round;
}

.plane {
    fill: var(--ink);
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .about-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    body {
        font-size: 16px;
    }

    .hero-foot {
        grid-template-columns: 1fr;
    }

    .hero-foot .btn {
        justify-self: start;
    }

    .facts li {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .facts .k {
        padding-top: 0;
    }

    .nav-links .hide-sm {
        display: none;
    }
}

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

    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }

    html {
        scroll-behavior: auto;
    }

    .js .reveal {
        opacity: 1;
        transform: none;
    }
}
