/* ─────────────────────────────────────────────────────────────
   Portfolio v2 — "instrument panel" design system + 3 themes.
   Tokens: see portfolio_animation_plan.md §3 and §6.
   ───────────────────────────────────────────────────────────── */

:root,
:root[data-theme="lab"] {
    --bg: #0a0908;
    --surface: rgba(18, 15, 12, 0.74);
    --surface-strong: rgba(24, 20, 16, 0.9);
    --text: #f2ece1;
    --dim: #a09585;
    --line: #2b2521;
    --line-strong: #4a3f35;
    --accent: #35e0ff;
    --accent-2: #a894ff;
    --accent-3: #ffb454;
    --accent-4: #ff6a5e;
    --link: #35e0ff;
    --on-accent: #0a0908;
    --shadow: 0 30px 80px -40px rgba(0, 0, 0, 0.8);
    color-scheme: dark;
}

:root[data-theme="deepfield"] {
    --bg: #121a4d;
    --surface: rgba(16, 22, 70, 0.72);
    --surface-strong: rgba(20, 27, 84, 0.9);
    --text: #eef0ff;
    --dim: #a3abe0;
    --line: #2c3577;
    --line-strong: #46519c;
    --accent: #3fd6f2;
    --accent-2: #a987ff;
    --accent-3: #e8b04a;
    --accent-4: #f26ac4;
    --link: #3fd6f2;
    --on-accent: #0c1340;
    --shadow: 0 30px 80px -40px rgba(4, 6, 30, 0.9);
    color-scheme: dark;
}

:root[data-theme="paper"] {
    --bg: #f2ece1;
    --surface: rgba(251, 247, 239, 0.84);
    --surface-strong: rgba(253, 250, 244, 0.95);
    --text: #1b1712;
    --dim: #6f6557;
    --line: #d8cfbf;
    --line-strong: #b9ab93;
    --accent: #0b6f84;
    --accent-2: #5b3fc8;
    --accent-3: #a85a10;
    --accent-4: #c23a2f;
    --link: #0b6f84;
    --on-accent: #fbf7ef;
    --shadow: 0 30px 70px -45px rgba(60, 45, 20, 0.45);
    color-scheme: light;
}

/* ───────── base ───────── */
html {
    background: var(--bg);
    scroll-behavior: smooth;
    scroll-padding-top: 96px;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 16px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.4s ease, color 0.4s ease;
    overflow-x: hidden;
}

h1, h2, h3, h4 {
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    letter-spacing: -0.02em;
    line-height: 1.08;
    margin: 0;
}

p { margin: 0; }
a { color: inherit; text-decoration: none; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 6px;
}

/* the story canvas sits behind everything */
#story-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    display: block;
    z-index: 0;
    pointer-events: none;
}
.no-webgl #story-canvas { display: none; }

header, main, footer { position: relative; z-index: 2; }

.skip-link {
    position: fixed; top: -100px; left: 16px; z-index: 100;
    padding: 0.7rem 1rem; border-radius: 999px;
    background: var(--surface-strong); color: var(--text); border: 1px solid var(--accent);
    transition: top 0.2s ease;
}
.skip-link:focus { top: 16px; }

/* ───────── type utilities ───────── */
.mono {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 11px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--dim);
}
.display {
    font-family: 'Space Grotesk', 'Inter', sans-serif;
    font-weight: 700;
    font-size: clamp(3rem, 11vw, 7.5rem);
    line-height: 0.95;
    letter-spacing: -0.035em;
}
.h2 {
    font-weight: 700;
    font-size: clamp(2.25rem, 6vw, 4.25rem);
    line-height: 1;
    letter-spacing: -0.03em;
}
.h3 { font-weight: 600; font-size: 1.3rem; line-height: 1.25; }
.lead { font-size: clamp(1.05rem, 1.6vw, 1.25rem); color: var(--text); opacity: 0.92; }
.muted { color: var(--dim); }
.accent { color: var(--accent); }
.link { color: var(--link); border-bottom: 1px solid color-mix(in srgb, var(--link) 40%, transparent); transition: border-color 0.2s ease; }
.link:hover { border-bottom-color: var(--link); }

/* ───────── layout ───────── */
.scene {
    position: relative;
    min-height: 100vh;
    padding: 8rem 1.25rem 6rem;
    box-sizing: border-box;
}
.col {
    width: 100%;
    max-width: 42rem;
    margin: 0 auto;
}
@media (min-width: 1024px) {
    .scene { padding-left: 2.5rem; padding-right: 2.5rem; }
    .col { margin-left: max(2.5rem, calc((100vw - 84rem) / 2)); margin-right: 0; }
    .col-wide { max-width: 46rem; }
}
.stack > * + * { margin-top: 1rem; }
.stack-lg > * + * { margin-top: 1.5rem; }

/* act marker: "ACT I · PROFILE" followed by a hairline */
.act {
    display: flex; align-items: center; gap: 0.9rem;
    margin-bottom: 1.4rem;
}
.act::before {
    content: ""; width: 7px; height: 7px; border-radius: 999px;
    background: var(--accent); box-shadow: 0 0 12px var(--accent);
}
.act::after { content: ""; flex: 1; max-width: 10rem; height: 1px; background: var(--line-strong); }

/* ───────── panels / cards ───────── */
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 1.5rem;
    padding: 1.5rem;
    backdrop-filter: blur(16px) saturate(1.15);
    -webkit-backdrop-filter: blur(16px) saturate(1.15);
    box-shadow: var(--shadow);
    transition: border-color 0.3s ease, background-color 0.4s ease, transform 0.3s ease;
}
@media (min-width: 640px) { .panel { padding: 1.9rem; } }
.panel:hover { border-color: var(--line-strong); }
.panel-tight { padding: 1.1rem 1.25rem; }

.index {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px; letter-spacing: 0.14em;
    color: var(--accent);
}

.chip {
    display: inline-flex; align-items: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px; letter-spacing: 0.06em;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    color: var(--text);
    background: color-mix(in srgb, var(--surface-strong) 60%, transparent);
    white-space: nowrap;
}
.chip-accent { border-color: color-mix(in srgb, var(--accent-3) 55%, transparent); color: var(--accent-3); }
.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; }

.rule { height: 1px; background: var(--line); border: 0; margin: 1.4rem 0; }

/* stats (telemetry readouts) */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.stat { padding: 1.1rem 1.2rem; }
.stat-value {
    font-family: 'Space Grotesk', sans-serif; font-weight: 700;
    font-size: clamp(1.8rem, 4vw, 2.4rem); line-height: 1; letter-spacing: -0.02em;
    color: var(--accent);
}
.stat-label { margin-top: 0.55rem; font-size: 0.85rem; color: var(--dim); line-height: 1.4; }

/* lists with ▹ markers */
.ticks { list-style: none; padding: 0; margin: 0; }
.ticks li { position: relative; padding-left: 1.3rem; color: var(--text); opacity: 0.9; font-size: 0.95rem; }
.ticks li + li { margin-top: 0.55rem; }
.ticks li::before { content: "▹"; position: absolute; left: 0; color: var(--accent); }

/* ───────── buttons ───────── */
.btn {
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.75rem 1.3rem;
    border-radius: 999px;
    font-weight: 500; font-size: 0.95rem;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--text);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), border-color 0.25s ease, background-color 0.25s ease, color 0.25s ease;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 85%, white); }
.btn i { font-size: 1.1rem; }

/* ───────── navigation (glass pill) ───────── */
.nav-shell {
    position: fixed; top: 0.9rem; left: 0; right: 0;
    z-index: 50;
    display: flex; justify-content: center;
    padding: 0 0.75rem;
    pointer-events: none;
}
.nav-pill {
    pointer-events: auto;
    display: flex; align-items: center; gap: 0.35rem;
    width: 100%; max-width: 64rem;
    padding: 0.45rem 0.5rem 0.45rem 1rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--surface-strong) 80%, transparent);
    border: 1px solid var(--line);
    backdrop-filter: blur(20px) saturate(1.2);
    -webkit-backdrop-filter: blur(20px) saturate(1.2);
    box-shadow: var(--shadow);
}
.brand { font-family: 'Space Grotesk', sans-serif; font-weight: 700; letter-spacing: -0.02em; margin-right: auto; }
.brand span { color: var(--accent); }
.nav-links { display: none; gap: 0.15rem; }
@media (min-width: 900px) { .nav-links { display: flex; } }
.nav-link {
    position: relative;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
    color: var(--dim);
    padding: 0.5rem 0.7rem;
    border-radius: 999px;
    transition: color 0.2s ease, background-color 0.2s ease;
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--text); background: color-mix(in srgb, var(--accent) 14%, transparent); }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
    height: 2.4rem; padding: 0 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: transparent;
    color: var(--text);
    font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn i { font-size: 1.05rem; }
.theme-label { display: none; }
@media (min-width: 520px) { .theme-label { display: inline; } }
.nav-cta { display: none; }
@media (min-width: 900px) { .nav-cta { display: inline-flex; } }
.menu-btn { width: 2.4rem; padding: 0; }
@media (min-width: 900px) { .menu-btn { display: none; } }

#mobile-menu {
    pointer-events: auto;
    position: absolute; top: calc(100% + 0.5rem); left: 0.75rem; right: 0.75rem;
    display: flex; flex-direction: column; gap: 0.2rem;
    padding: 0.6rem;
    border-radius: 1.3rem;
    background: var(--surface-strong);
    border: 1px solid var(--line);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    opacity: 0; visibility: hidden; transform: translateY(-6px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}
#mobile-menu.open { opacity: 1; visibility: visible; transform: none; }
#mobile-menu .nav-link { padding: 0.8rem 0.9rem; font-size: 12px; }
@media (min-width: 900px) { #mobile-menu { display: none; } }

/* ───────── hero ───────── */
.hero {
    display: flex; flex-direction: column; justify-content: flex-end;
    padding-bottom: 4.5rem;
}
.hero .display .line2 { color: transparent; -webkit-text-stroke: 1.5px var(--text); }
.hero-cta { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 2rem; }

.ticker {
    position: absolute; left: 0; right: 0; bottom: 0;
    overflow: hidden;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 70%, transparent);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.ticker-track {
    display: flex; width: max-content; gap: 2.5rem;
    padding: 0.7rem 0;
    animation: ticker 60s linear infinite;
}
.ticker-track span::after { content: "✦"; margin-left: 2.5rem; color: var(--accent); }
@keyframes ticker { to { transform: translateX(-50%); } }

.scroll-cue {
    display: inline-flex; align-items: center; gap: 0.6rem;
    margin-top: 2.5rem;
}
.scroll-cue i { animation: cue 2.2s ease-in-out infinite; color: var(--accent); }
@keyframes cue { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(5px); } }

/* ───────── timeline (experience / education) ───────── */
.timeline { position: relative; padding-left: 1.4rem; }
.timeline::before { content: ""; position: absolute; left: 0.3rem; top: 0.4rem; bottom: 0.4rem; width: 1px; background: var(--line-strong); }
.timeline-item { position: relative; }
.timeline-item + .timeline-item { margin-top: 1.25rem; }
.timeline-item::before {
    content: ""; position: absolute; left: -1.38rem; top: 1.9rem;
    width: 9px; height: 9px; border-radius: 999px;
    background: var(--bg); border: 2px solid var(--accent);
}

/* publications */
.pub { display: grid; grid-template-columns: 3.4rem 1fr; gap: 0.9rem; align-items: start; }
.pub-year { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 1.25rem; color: var(--accent-3); }
.pub-title { font-weight: 600; line-height: 1.35; }
.pub-title:hover { color: var(--accent); }

/* ───────── progress + back-to-top ───────── */
#scroll-progress {
    position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 60;
    background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent-3));
    transform-origin: 0 50%; transform: scaleX(0); pointer-events: none;
}
#back-to-top {
    position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 50;
    width: 2.9rem; height: 2.9rem; padding: 0; justify-content: center;
    opacity: 0; visibility: hidden; transform: translateY(12px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease, border-color 0.2s ease;
}
#back-to-top.visible { opacity: 1; visibility: visible; transform: none; }

/* ───────── preloader ───────── */
#preloader {
    position: fixed; inset: 0; z-index: 90;
    display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 1rem;
    background: var(--bg);
    transition: opacity 0.6s ease;
}
.spinner {
    width: 44px; height: 44px; border-radius: 999px;
    border: 2px solid color-mix(in srgb, var(--accent) 25%, transparent);
    border-top-color: var(--accent);
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────── custom cursor (fine pointers only) ───────── */
#custom-cursor, #cursor-trail {
    position: fixed; top: 0; left: 0; z-index: 95;
    border-radius: 999px; pointer-events: none;
    opacity: 0; display: none;
}
.has-custom-cursor #custom-cursor, .has-custom-cursor #cursor-trail { display: block; }
.cursor-visible #custom-cursor, .cursor-visible #cursor-trail { opacity: 1; }
#custom-cursor { width: 7px; height: 7px; background: var(--accent); transition: width 0.2s, height 0.2s, background-color 0.2s, opacity 0.2s; }
#cursor-trail { width: 30px; height: 30px; border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); transition: width 0.2s, height 0.2s, border-color 0.2s, opacity 0.2s; }
.cursor-hover #custom-cursor { width: 11px; height: 11px; background: var(--accent-2); }
.cursor-hover #cursor-trail { width: 44px; height: 44px; border-color: color-mix(in srgb, var(--accent-2) 60%, transparent); }
body.has-custom-cursor, body.has-custom-cursor * { cursor: none !important; }

/* ───────── magnetic buttons ───────── */
.magnetic-btn { will-change: transform; }

/* ───────── reveal ───────── */
.reveal-up { opacity: 0; transform: translateY(26px); }
.no-gsap .reveal-up { transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), transform 0.6s cubic-bezier(0.16, 1, 0.3, 1); }
.reveal-up.active { opacity: 1; transform: none; }

/* ───────── footer ───────── */
.footer {
    padding: 2rem 1.25rem 2.5rem;
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg) 70%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* ───────── recording mode (video export): canvas only ───────── */
.is-recording body > *:not(#story-canvas):not(script) { display: none !important; }
.is-recording #story-canvas { position: static; width: 100%; height: auto; }
.is-recording, .is-recording body { overflow: hidden; background: #000; }

/* ───────── reduced motion ───────── */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
    .reveal-up { opacity: 1; transform: none; }
    .ticker-track { animation: none; }
}

/* ───────── print ───────── */
@media print {
    #story-canvas, .nav-shell, #preloader, #scroll-progress, #back-to-top, #custom-cursor, #cursor-trail, .ticker { display: none !important; }
    body { background: #fff; color: #000; }
    .panel { background: #fff !important; box-shadow: none !important; border-color: #ccc; backdrop-filter: none; }
    .reveal-up { opacity: 1 !important; transform: none !important; }
}
