:root {
    --bg: #FBFAF6;
    --surface: #FFFFFF;
    --text: #1A1A1A;
    --muted: #6B6B65;
    --accent: #2A4B8D;
    --accent-soft: #E9EEF7;
    --rule: #E7E3D8;
    --tag: #F3F0E7;
    --glow: rgba(42, 75, 141, 0.10);
    --ok: #3E8E5A;
    --serif: 'Instrument Serif', 'EB Garamond', Georgia, serif;
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

[data-theme="dark"] {
    --bg: #14140F;
    --surface: #1C1C17;
    --text: #EDE9DE;
    --muted: #8F8B7E;
    --accent: #9EB8E9;
    --accent-soft: #1F2A44;
    --rule: #2B2A22;
    --tag: #23221C;
    --glow: rgba(158, 184, 233, 0.12);
    --ok: #6FBF8A;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.65;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "ss01", "cv11";
}

/* Film-grain texture */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    opacity: .028;
    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'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}
[data-theme="dark"] body::after { opacity: .05; }

/* Smooth theme change */
html.theme-fade body,
html.theme-fade .site-header,
html.theme-fade .card,
html.theme-fade .tags span {
    transition: background-color .35s ease, color .35s ease, border-color .35s ease;
}

a {
    color: var(--accent);
    text-decoration: none;
}

/* Animated underline for in-text links */
.lede a, .entry a, .meta a, .see-more a, ul.plain a {
    background-image: linear-gradient(currentColor, currentColor);
    background-size: 0% 1px;
    background-position: 0 100%;
    background-repeat: no-repeat;
    transition: background-size .25s ease, color .15s ease;
}
.lede a:hover, .entry a:hover, .meta a:hover, .see-more a:hover, ul.plain a:hover {
    background-size: 100% 1px;
}

::selection { background: var(--accent-soft); color: var(--text); }

.wrap {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ---------- Reading progress ---------- */
#progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    width: 0;
    z-index: 100;
    background: linear-gradient(90deg, var(--accent), color-mix(in oklab, var(--accent) 55%, var(--bg)));
}

/* ---------- Header ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in oklab, var(--bg) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(12px);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-bottom: 1px solid transparent;
    transition: border-color .3s ease, box-shadow .3s ease;
}
.site-header.scrolled {
    border-bottom-color: var(--rule);
    box-shadow: 0 6px 24px -18px rgba(0, 0, 0, .35);
}
.site-header .wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 14px;
    padding-bottom: 14px;
}
.brand {
    font-family: var(--serif);
    font-size: 20px;
    letter-spacing: .01em;
    color: var(--text);
    transition: color .15s ease;
}
.brand:hover { color: var(--accent); }

.site-header nav {
    display: flex;
    align-items: center;
    gap: 22px;
}
.site-header nav a {
    position: relative;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
    transition: color .15s ease;
}
.site-header nav a::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: -4px;
    width: 100%;
    height: 1px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform .25s ease;
}
.site-header nav a:hover { color: var(--text); }
.site-header nav a.active { color: var(--text); }
.site-header nav a.active::after { transform: scaleX(1); }

#theme-toggle {
    position: relative;
    background: transparent;
    border: 1px solid var(--rule);
    color: var(--muted);
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    transition: color .15s ease, border-color .15s ease, transform .15s ease;
}
#theme-toggle:hover { color: var(--text); border-color: var(--muted); }
#theme-toggle:active { transform: scale(.92); }
#theme-toggle svg {
    position: absolute;
    transition: transform .4s cubic-bezier(.34, 1.56, .64, 1), opacity .25s ease;
}
#theme-toggle .icon-sun { opacity: 0; transform: rotate(90deg) scale(.4); }
#theme-toggle .icon-moon { opacity: 1; transform: rotate(0) scale(1); }
[data-theme="dark"] #theme-toggle .icon-sun { opacity: 1; transform: rotate(0) scale(1); }
[data-theme="dark"] #theme-toggle .icon-moon { opacity: 0; transform: rotate(-90deg) scale(.4); }

/* ---------- Intro ---------- */
.intro {
    position: relative;
    padding: 76px 0 30px;
    border-bottom: 1px solid var(--rule);
}
.intro::before {
    content: 'Cv';
    position: absolute;
    top: 8px;
    right: -40px;
    font-family: var(--serif);
    font-style: italic;
    font-size: 300px;
    line-height: 1;
    color: var(--text);
    opacity: .035;
    pointer-events: none;
    user-select: none;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
    border: 1px solid var(--rule);
    background: var(--surface);
    border-radius: 999px;
    padding: 5px 14px;
    margin-bottom: 26px;
}
.status .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 0 color-mix(in oklab, var(--ok) 45%, transparent);
    animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--ok) 45%, transparent); }
    70% { box-shadow: 0 0 0 7px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

.intro-grid {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 28px;
}
.intro-text { flex: 1; min-width: 0; }

.intro h1 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 56px;
    line-height: 1.05;
    letter-spacing: -.01em;
    margin-bottom: 20px;
}

/* ---------- Avatar ---------- */
.avatar-wrap {
    flex-shrink: 0;
    width: 200px;
}
.avatar { width: 100%; height: auto; display: block; }

.avatar .skin { fill: #E0A971; }
.avatar .hair { fill: #241C14; }
.avatar .sweater { fill: var(--accent); }
.avatar .sleeve {
    fill: none;
    stroke: var(--accent);
    stroke-width: 14;
    stroke-linecap: round;
}
.avatar .glass {
    fill: rgba(255, 255, 255, .16);
    stroke: var(--text);
    stroke-width: 2.5;
}
.avatar .eye { fill: #1A1A1A; transform-box: fill-box; transform-origin: center; }
[data-theme="dark"] .avatar .eye { fill: #14140F; }
.avatar .smile {
    fill: none;
    stroke: #8C5A33;
    stroke-width: 2.5;
    stroke-linecap: round;
}
.avatar .blush { fill: rgba(214, 108, 91, .35); }
.avatar .cap-top { fill: #23231E; stroke: var(--rule); stroke-width: 1; }
.avatar .cap-base { fill: #2E2E27; }
.avatar .tassel-string { stroke: #D9A93F; stroke-width: 2; fill: none; }
.avatar .tassel { fill: #D9A93F; }
.avatar .ground { fill: rgba(0, 0, 0, .08); }
[data-theme="dark"] .avatar .ground { fill: rgba(0, 0, 0, .35); }
.avatar .bubble-bg { fill: var(--surface); stroke: var(--rule); stroke-width: 1.5; }
.avatar .bubble-text {
    font-family: var(--mono);
    font-size: 19px;
    fill: var(--accent);
    text-anchor: middle;
}

.avatar .arm-wave {
    transform-origin: 150px 160px;
    animation: wave 1.9s ease-in-out infinite;
}
@keyframes wave {
    0%, 100% { transform: rotate(10deg); }
    50% { transform: rotate(-16deg); }
}
.avatar .head {
    transform-origin: 120px 148px;
    animation: head-tilt 5.6s ease-in-out infinite;
}
@keyframes head-tilt {
    0%, 100% { transform: rotate(-1.6deg); }
    50% { transform: rotate(2.2deg); }
}
.avatar .eye { animation: blink 4.4s infinite; }
@keyframes blink {
    0%, 91%, 96%, 100% { transform: scaleY(1); }
    93.5% { transform: scaleY(.08); }
}
.avatar .bubble {
    transform-origin: 190px 44px;
    animation: bubble-bob 1.9s ease-in-out infinite;
}
@keyframes bubble-bob {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-4px) scale(1.05); }
}
.lede {
    font-size: 18px;
    line-height: 1.6;
    color: var(--text);
    max-width: 64ch;
    margin-bottom: 22px;
}
.accent-em {
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.08em;
    color: var(--accent);
}
.meta {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 20px;
    font-size: 14px;
    color: var(--muted);
}
.meta li { position: relative; }
.meta li + li::before {
    content: '·';
    position: absolute;
    left: -13px;
    color: var(--rule);
}
.meta a { color: var(--muted); }
.meta a:hover { color: var(--accent); }
.meta .cv-link {
    color: var(--accent);
    font-weight: 500;
}

/* ---------- Sections ---------- */
main.wrap { counter-reset: sec; }

.section { padding: 52px 0; border-bottom: 1px solid var(--rule); }
.section:last-of-type { border-bottom: none; }

.section h2 {
    display: flex;
    align-items: center;
    gap: 14px;
    font-family: var(--sans);
    font-weight: 500;
    font-size: 12px;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 30px;
    counter-increment: sec;
}
.section h2::before {
    content: counter(sec, decimal-leading-zero);
    font-family: var(--mono);
    font-size: 11px;
    color: var(--accent);
    letter-spacing: 0;
}
.section h2::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--rule);
}

.section h3.minor {
    font-family: var(--sans);
    font-weight: 500;
    font-size: 12px;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 40px 0 16px;
}

/* ---------- Entries ---------- */
.entries { display: flex; flex-direction: column; gap: 30px; }

/* Timeline treatment (work / research / education) */
.timeline .entry {
    position: relative;
    padding-left: 24px;
    border-left: 1px solid var(--rule);
    transition: border-color .25s ease;
}
.timeline .entry::before {
    content: '';
    position: absolute;
    left: -4.5px;
    top: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--bg);
    border: 1.5px solid var(--muted);
    transition: background .25s ease, border-color .25s ease, box-shadow .25s ease;
}
.timeline .entry:hover { border-left-color: var(--accent); }
.timeline .entry:hover::before {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--glow);
}

.entry-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 20px;
    margin-bottom: 10px;
}
.entry h3 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 22px;
    line-height: 1.25;
    color: var(--text);
}
.entry .org {
    font-size: 14px;
    color: var(--muted);
    margin-top: 2px;
}
.entry .org a { color: var(--muted); }
.entry .org a:hover { color: var(--accent); }

.entry .date {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}
.entry .date a { color: var(--accent); }

.entry ul {
    list-style: none;
    padding-left: 0;
    margin-top: 8px;
}
.entry ul li {
    position: relative;
    padding-left: 18px;
    margin-bottom: 6px;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
}
.entry ul li::before {
    content: '';
    position: absolute;
    left: 2px;
    top: 12px;
    width: 6px;
    height: 1px;
    background: var(--muted);
}

.entry.compact ul { display: none; }

/* Project cards */
.cards .entry.card {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 14px;
    padding: 26px 28px;
    transition: transform .3s cubic-bezier(.2, .8, .3, 1), box-shadow .3s ease, border-color .3s ease;
}
.cards .entry.card:hover {
    transform: translateY(-4px);
    border-color: color-mix(in oklab, var(--accent) 45%, var(--rule));
    box-shadow: 0 18px 40px -24px rgba(0, 0, 0, .35), 0 0 0 4px var(--glow);
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 14px;
}
.tags span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .01em;
    color: var(--muted);
    background: var(--tag);
    border: 1px solid var(--rule);
    border-radius: 999px;
    padding: 3px 10px;
    transition: color .2s ease, border-color .2s ease;
}
.tags .ti {
    display: inline-block;
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    background-color: currentColor;
    -webkit-mask: var(--i) center / contain no-repeat;
    mask: var(--i) center / contain no-repeat;
}
.cards .entry.card:hover .tags span {
    color: var(--text);
    border-color: color-mix(in oklab, var(--accent) 30%, var(--rule));
}

/* Hover CTA (live demo) */
.card-cta {
    position: absolute;
    right: 20px;
    bottom: 20px;
    z-index: 2;
    font-family: var(--mono);
    font-size: 12px;
    padding: 7px 14px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--bg);
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity .25s ease, transform .25s cubic-bezier(.2, .8, .3, 1);
    box-shadow: 0 10px 24px -12px var(--glow);
}
.cards .entry.card:hover .card-cta,
.card-cta:focus-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.coursework {
    margin-top: 6px;
    font-size: 14px;
    color: var(--muted);
    font-style: italic;
}
.see-more { margin-top: 28px; font-size: 14px; }

/* ---------- Skills ---------- */
.skills {
    display: grid;
    grid-template-columns: 160px 1fr;
    row-gap: 12px;
    column-gap: 24px;
    font-size: 15px;
}
.skills dt {
    font-weight: 500;
    color: var(--muted);
    font-size: 13px;
    padding-top: 2px;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.skills dd { color: var(--text); }

ul.plain {
    list-style: none;
    padding: 0;
}
ul.plain li {
    font-size: 15px;
    color: var(--text);
    margin-bottom: 8px;
    line-height: 1.5;
}
ul.plain li strong { font-weight: 600; }

/* ---------- Footer ---------- */
.footer {
    padding: 64px 0 80px;
    font-size: 14px;
    color: var(--muted);
}
.footer-title {
    font-family: var(--serif);
    font-weight: 400;
    font-size: 44px;
    color: var(--text);
    margin-bottom: 14px;
}
.accent-dot { color: var(--accent); }
.footer-mail {
    font-family: var(--mono);
    font-size: 15px;
    color: var(--accent);
}
.footer-mail .arrow {
    display: inline-block;
    transition: transform .25s ease;
}
.footer-mail:hover .arrow { transform: translateX(6px); }
.footer .fine { margin-top: 28px; font-size: 12px; color: var(--muted); }

/* ---------- Scroll reveal ---------- */
.reveal {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity .6s ease, transform .6s cubic-bezier(.2, .8, .3, 1);
}
.reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
    background: var(--rule);
    border-radius: 5px;
    border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .wrap { padding: 0 20px; }
    .intro { padding: 40px 0 24px; }
    .intro::before { display: none; }
    .status {
        display: flex;
        justify-content: center;
        width: fit-content;
        max-width: 100%;
        margin: 0 auto 20px;
        text-align: center;
        font-size: 11px;
    }
    .intro-grid { flex-direction: column; align-items: center; gap: 22px; }
    .avatar-wrap { width: 172px; order: -1; }
    .intro-text { width: 100%; }
    .intro h1 { font-size: 40px; text-align: center; }
    .lede { text-align: left; }
    .meta { justify-content: center; }
    .lede { font-size: 16px; }
    .section { padding: 40px 0; }
    .entry-head { flex-direction: column; gap: 4px; align-items: flex-start; }
    .entry .date { font-size: 11px; }
    .entry h3 { font-size: 20px; }
    .cards .entry.card { padding: 20px; }
    .timeline .entry { padding-left: 18px; }
    .skills { grid-template-columns: 1fr; row-gap: 4px; }
    .skills dt { margin-top: 12px; }
    .footer-title { font-size: 34px; }
    .site-header nav { gap: 14px; }
    .site-header nav a { display: none; }
    .site-header nav a[href="#work"], .site-header nav a[href="#research"] { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; scroll-behavior: auto; }
    .reveal { opacity: 1; transform: none; }
}
