/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
    --bg: #0c0a09;
    --text: #f5f5f4;
    --text-muted: #a8a29e;
    --text-faint: #57534e;
    --accent: #60a5fa;
    --border: rgba(245, 245, 244, 0.08);
    --border-strong: rgba(245, 245, 244, 0.16);
    --surface: rgba(245, 245, 244, 0.03);
    --surface-hover: rgba(245, 245, 244, 0.06);

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    --container: 640px;
    --gutter: 24px;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html {
    -webkit-text-size-adjust: 100%;
    background: var(--bg);
}

body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
    font-feature-settings: 'cv11', 'ss01';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

::selection {
    background: rgba(96, 165, 250, 0.3);
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

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

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

/* ==========================================================================
   Background: glow, dot grid, and grain (fixed, covers full viewport)
   ========================================================================== */
.backdrop {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background: radial-gradient(ellipse 60% 40% at 50% -10%, rgba(96, 165, 250, 0.10), transparent 70%);
}

/* Dot grid, fading out toward the edges */
.backdrop::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(255, 255, 255, 0.14) 1px, transparent 1.2px);
    background-size: 22px 22px;
    background-position: 50% 0;
    -webkit-mask-image: radial-gradient(ellipse 90% 85% at 50% 35%, #000 40%, transparent 100%);
    mask-image: radial-gradient(ellipse 90% 85% at 50% 35%, #000 40%, transparent 100%);
}

/* Fine film grain over everything */
.backdrop::after {
    content: '';
    position: absolute;
    inset: 0;
    opacity: 0.05;
    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%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ==========================================================================
   Layout
   ========================================================================== */
.container {
    position: relative;
    z-index: 1;
    max-width: calc(var(--container) + var(--gutter) * 2);
    margin: 0 auto;
    padding: 0 var(--gutter);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.content {
    flex: 1;
}

/* ==========================================================================
   Navigation
   ========================================================================== */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 72px;
    margin-bottom: 56px;
}

.nav-brand {
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--text);
}

.nav-brand span {
    color: var(--text-faint);
    transition: color 0.2s ease;
}

.nav-brand:hover span {
    color: var(--accent);
}

.nav-links {
    display: flex;
    gap: 4px;
}

.nav-links a {
    font-size: 0.9rem;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 6px;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.nav-links a:last-child {
    margin-right: -12px;
}

.nav-links a:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.nav-links a[aria-current='page'] {
    color: var(--text);
}

/* ==========================================================================
   Hero
   ========================================================================== */
.hero {
    margin-bottom: 56px;
}

.hero-title {
    font-size: 2rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.15;
    color: var(--text);
}

.hero-subtitle {
    margin-top: 10px;
    font-size: 1.05rem;
    color: var(--text-muted);
}

/* ==========================================================================
   Sections
   ========================================================================== */
.section {
    margin-bottom: 48px;
}

.section-title {
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-bottom: 16px;
}

/* Reveal on scroll (only when JS is available) */
.js .reveal {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.7s var(--ease), transform 0.7s var(--ease);
}

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

/* ==========================================================================
   Entry list (work / education)
   ========================================================================== */
.entry-list {
    list-style: none;
    border-top: 1px solid var(--border);
}

.entry {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 16px;
    min-height: 52px;
    border-bottom: 1px solid var(--border);
}

.entry-org {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    width: fit-content;
    font-weight: 500;
    color: var(--text);
}

.entry-org .name {
    background-image: linear-gradient(var(--accent), var(--accent));
    background-size: 0% 1px;
    background-position: 0 100%;
    background-repeat: no-repeat;
    transition: background-size 0.35s var(--ease);
}

.entry-org:hover .name {
    background-size: 100% 1px;
}

.entry-role {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: right;
}

/* Company logo chip with monogram fallback */
.logo {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 0 0 1px var(--border-strong);
    overflow: hidden;
}

.logo img {
    width: 16px;
    height: 16px;
    object-fit: contain;
}

.logo:empty {
    background: var(--surface-hover);
}

.logo:empty::after {
    content: attr(data-initial);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* ==========================================================================
   Highlights list
   ========================================================================== */
.highlights {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.highlights li {
    position: relative;
    padding-left: 22px;
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.65;
}

.highlights li::before {
    content: '';
    position: absolute;
    left: 2px;
    top: 0.82em;
    width: 8px;
    height: 1px;
    background: var(--text-faint);
}

.highlights strong {
    font-weight: 500;
    color: var(--text);
}

/* ==========================================================================
   Links
   ========================================================================== */
.text-link {
    color: var(--text);
    font-weight: 500;
    background-image: linear-gradient(var(--border-strong), var(--border-strong));
    background-size: 100% 1px;
    background-position: 0 100%;
    background-repeat: no-repeat;
    transition: background-image 0.2s ease, color 0.2s ease;
}

.text-link:hover {
    background-image: linear-gradient(var(--accent), var(--accent));
}

.contact p {
    color: var(--text-muted);
}

/* ==========================================================================
   Post list (thoughts)
   ========================================================================== */
.post-list {
    list-style: none;
    border-top: 1px solid var(--border);
}

.post-list a {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 24px;
    padding: 18px 0;
    border-bottom: 1px solid var(--border);
}

.post-title {
    display: block;
    font-weight: 500;
    color: var(--text);
    transition: color 0.2s ease;
}

.post-desc {
    display: block;
    margin-top: 4px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.post-date {
    flex-shrink: 0;
    font-size: 0.85rem;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
}

.post-list a:hover .post-title {
    color: var(--accent);
}

/* ==========================================================================
   Article
   ========================================================================== */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 32px;
    transition: color 0.2s ease;
}

.back-link:hover {
    color: var(--text);
}

.back-link span {
    transition: transform 0.2s var(--ease);
}

.back-link:hover span {
    transform: translateX(-3px);
}

.article-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 14px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.article-meta .dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--text-faint);
}

.tag {
    display: inline-block;
    padding: 2px 8px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.prose {
    color: #d6d3d1;
    font-size: 1.025rem;
    line-height: 1.8;
}

.prose p,
.prose ul {
    margin-bottom: 1.4em;
}

.prose h2 {
    margin: 2.2em 0 0.7em;
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    color: var(--text);
}

.prose ul {
    padding-left: 1.2em;
}

.prose li {
    margin-bottom: 0.6em;
    padding-left: 0.3em;
}

.prose li::marker {
    color: var(--text-faint);
}

.prose strong {
    font-weight: 600;
    color: var(--text);
}

/* ==========================================================================
   Project cards
   ========================================================================== */
.card-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.card {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    overflow: hidden;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.card:hover {
    border-color: var(--border-strong);
    background: var(--surface-hover);
}

.card-media {
    aspect-ratio: 16 / 7;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.25);
}

.card-body {
    padding: 20px;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.card-desc {
    margin: 6px 0 14px;
    font-size: 0.925rem;
    color: var(--text-muted);
}

.card-body .text-link {
    font-size: 0.875rem;
}

/* ==========================================================================
   Embedded PDF
   ========================================================================== */
.pdf-frame {
    display: block;
    width: 100%;
    height: 80vh;
    min-height: 500px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}

/* ==========================================================================
   Footer
   ========================================================================== */
footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-top: 80px;
    padding: 28px 0 40px;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-faint);
}

.social-links {
    display: flex;
    gap: 20px;
}

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

.social-links a:hover {
    color: var(--text);
}

/* ==========================================================================
   Easter egg
   ========================================================================== */
.dot-field {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    -webkit-mask-image: radial-gradient(ellipse 90% 85% at 50% 35%, #000 40%, transparent 100%);
    mask-image: radial-gradient(ellipse 90% 85% at 50% 35%, #000 40%, transparent 100%);
}

.dot-field.excited {
    -webkit-mask-image: none;
    mask-image: none;
}

/* Canvas takes over from the static CSS grid once JS is running */
.dots-live .backdrop::before {
    display: none;
}

.egg-toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 10;
    max-width: calc(100% - 40px);
    padding: 10px 16px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: rgba(28, 25, 23, 0.85);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    font-size: 0.85rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    transform: translate(-50%, 8px);
    transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}

.egg-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 600px) {
    :root {
        --gutter: 20px;
    }

    .top-nav {
        height: 64px;
        margin-bottom: 40px;
    }

    .hero {
        margin-bottom: 44px;
    }

    .hero-title {
        font-size: 1.75rem;
    }

    .post-list a {
        flex-direction: column;
        gap: 6px;
    }

    .post-date {
        order: -1;
    }

    footer {
        flex-direction: column-reverse;
        align-items: flex-start;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
    }

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