/* ==========================================================================
   Varun Nagaraj Rao — personal site (v3)
   Tokens first; every color and font in the site comes from here.
   ========================================================================== */

:root {
    --bg: #fbfaf7;
    --surface: #ffffff;
    --surface-2: #f3f1ec;
    --text: #1a1a1c;
    --muted: #5b5e65;
    --faint: #8d9096;
    --border: #e8e4dc;
    --rule: #dcd6cb;
    --accent: #0d5f61;
    --accent-soft: rgba(13, 95, 97, 0.08);
    --highlight: #a8441c;
    --highlight-soft: rgba(168, 68, 28, 0.09);
    --shadow: 0 1px 2px rgba(20, 20, 20, 0.03), 0 8px 24px rgba(20, 20, 20, 0.04);

    --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
    --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

    --radius: 10px;
    --sidebar-w: 280px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #101214;
        --surface: #16191c;
        --surface-2: #1d2125;
        --text: #ebe8e3;
        --muted: #a5a9af;
        --faint: #7a7f86;
        --border: #262a2f;
        --rule: #33383e;
        --accent: #6cc6c0;
        --accent-soft: rgba(108, 198, 192, 0.1);
        --highlight: #f0956a;
        --highlight-soft: rgba(240, 149, 106, 0.12);
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    }
}

:root[data-theme="dark"] {
    --bg: #101214;
    --surface: #16191c;
    --surface-2: #1d2125;
    --text: #ebe8e3;
    --muted: #a5a9af;
    --faint: #7a7f86;
    --border: #262a2f;
    --rule: #33383e;
    --accent: #6cc6c0;
    --accent-soft: rgba(108, 198, 192, 0.1);
    --highlight: #f0956a;
    --highlight-soft: rgba(240, 149, 106, 0.12);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
}

/* ---------- Base ---------- */

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

html { scroll-behavior: smooth; scroll-padding-top: 32px; }

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

a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: transparent;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    transition: text-decoration-color 0.15s, color 0.15s;
}
a:hover { text-decoration-color: currentColor; }

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

h1, h2, h3 { margin: 0; font-weight: 500; line-height: 1.2; }

p { margin: 0 0 1em; }

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

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

/* ---------- Layout ---------- */

.layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    max-width: 1140px;
    margin: 0 auto;
    gap: 80px;
    padding: 0 40px;
}

/* ---------- Sidebar ---------- */

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 64px 0 36px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
}
.sidebar::-webkit-scrollbar { display: none; }

.profile-photo {
    width: 132px;
    height: 132px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 24px;
    box-shadow: 0 0 0 1px var(--border), 0 0 0 6px var(--bg), 0 0 0 7px var(--border);
}

.sidebar h1 {
    font-family: var(--serif);
    font-size: 2.1rem;
    letter-spacing: -0.015em;
    line-height: 1.08;
    margin-bottom: 14px;
}

.role {
    list-style: none;
    margin: 0 0 22px;
    padding: 0;
    font-size: 0.88rem;
    color: var(--muted);
    line-height: 1.55;
}
.role li + li { margin-top: 2px; }
.role strong { color: var(--text); font-weight: 500; }

.social { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 40px; }

.social a {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    text-decoration: none;
    transition: border-color 0.15s, color 0.15s;
}
.social a:hover { border-color: var(--accent); color: var(--accent); }
.social i { font-size: 0.85em; color: var(--faint); transition: color 0.15s; }
.social a:hover i { color: var(--accent); }

.side-nav ol {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: nav;
}

.side-nav li { counter-increment: nav; }

.side-nav a {
    display: flex;
    align-items: baseline;
    gap: 14px;
    padding: 4px 0;
    font-size: 0.86rem;
    color: var(--muted);
    text-decoration: none;
}
.side-nav a::before {
    content: counter(nav, decimal-leading-zero);
    font-size: 0.68rem;
    font-variant-numeric: tabular-nums;
    color: var(--faint);
    width: 16px;
}
.side-nav a::after {
    content: "";
    height: 1px;
    width: 0;
    background: var(--accent);
    align-self: center;
    transition: width 0.2s ease;
}
.side-nav a:hover { color: var(--text); }
.side-nav a.active { color: var(--text); font-weight: 500; }
.side-nav a.active::before { color: var(--accent); }
.side-nav a.active::after { width: 24px; }

.sidebar-footer { margin-top: auto; padding-top: 32px; }

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font: inherit;
    font-size: 0.78rem;
    color: var(--faint);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: color 0.15s;
}
.theme-toggle:hover { color: var(--text); }

/* ---------- Mobile top bar ---------- */

.topbar { display: none; }

/* ---------- Main ---------- */

main { padding: 64px 0 80px; min-width: 0; max-width: 760px; }

section { padding-bottom: 72px; }

.section-title {
    font-family: var(--serif);
    font-size: 1.85rem;
    letter-spacing: -0.01em;
    margin-bottom: 28px;
    display: flex;
    align-items: baseline;
    gap: 16px;
}
.section-title .num {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.04em;
    transform: translateY(-4px);
}
.section-title::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
    transform: translateY(-8px);
}

.eyebrow {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--faint);
    margin: 40px 0 16px;
}

/* ---------- About ---------- */

.bio p:first-child {
    font-family: var(--serif);
    font-size: 1.3rem;
    line-height: 1.5;
    letter-spacing: -0.005em;
}

.interests {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0 28px;
    counter-reset: interest;
}
.interests li {
    counter-increment: interest;
    border-top: 1px solid var(--rule);
    padding: 16px 0 22px;
}
.interests li::before {
    content: counter(interest, upper-roman) ".";
    display: block;
    font-family: var(--serif);
    font-style: italic;
    font-size: 0.95rem;
    color: var(--accent);
    margin-bottom: 6px;
}
.interests .i-title { font-weight: 600; font-size: 0.95rem; line-height: 1.35; margin-bottom: 4px; }
.interests .i-desc { color: var(--muted); font-size: 0.85rem; line-height: 1.5; }

/* ---------- News (scrollable) ---------- */

.news-frame {
    position: relative;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.news-frame::after {
    content: "";
    position: absolute;
    left: 1px;
    right: 1px;
    bottom: 1px;
    height: 72px;
    border-radius: 0 0 var(--radius) var(--radius);
    background: linear-gradient(to bottom, transparent, var(--surface));
    pointer-events: none;
    transition: opacity 0.2s;
}
.news-frame.at-end::after { opacity: 0; }

.news {
    list-style: none;
    margin: 0;
    padding: 6px 24px;
    max-height: 460px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--rule) transparent;
}
.news::-webkit-scrollbar { width: 8px; }
.news::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 8px; border: 2px solid var(--surface); }

.news > li {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 20px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.93rem;
}
.news > li:last-child { border-bottom: none; }

.news-date {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--faint);
    font-variant-numeric: tabular-nums;
    padding-top: 2px;
}

.news-body ul { margin: 0; padding-left: 16px; }
.news-body li { margin-bottom: 6px; }
.news-body li::marker { color: var(--faint); }
.news-body li:last-child, .news-body p:last-child { margin-bottom: 0; }

.scroll-hint { font-size: 0.78rem; color: var(--faint); margin-top: 10px; display: flex; align-items: center; gap: 6px; }

/* ---------- Badges & small links ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
}
.badge.award { color: var(--highlight); background: var(--highlight-soft); }
.badge.muted { color: var(--muted); background: var(--surface-2); }

.tags { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.tags a {
    font-size: 0.74rem;
    font-weight: 500;
    line-height: 1;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--muted);
    text-decoration: none;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.tags a:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Publications ---------- */

.filters { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; padding: 4px; background: var(--surface-2); border-radius: 999px; width: fit-content; max-width: 100%; }
.filters button {
    font: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 999px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s;
}
.filters button:hover { color: var(--text); }
.filters button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }

.pub-group[hidden] { display: none; }

.pubs { list-style: none; margin: 0; padding: 0; }

.pub {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 16px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
}
.pub:last-child { border-bottom: none; }

.pub-year {
    font-size: 0.8rem;
    color: var(--faint);
    font-variant-numeric: tabular-nums;
    padding-top: 2px;
}
.pub-year.review { font-size: 0.68rem; letter-spacing: 0.04em; text-transform: uppercase; line-height: 1.3; }

.pub-title { font-family: var(--serif); font-size: 1.1rem; line-height: 1.35; margin-bottom: 4px; }
.pub-authors { color: var(--muted); font-size: 0.86rem; line-height: 1.55; margin-bottom: 8px; }
.pub-authors b { color: var(--text); font-weight: 600; }
.pub-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; font-size: 0.84rem; }
.venue { color: var(--text); font-weight: 500; }

.footnote { font-size: 0.8rem; color: var(--faint); margin-top: 16px; }

/* ---------- Timeline ---------- */

.timeline { list-style: none; margin: 0; padding: 0; }

.tl-item {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 20px;
    padding: 18px 0;
    border-bottom: 1px solid var(--border);
}
.tl-item:last-child { border-bottom: none; }

.tl-logo {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    object-fit: contain;
    background: #fff;
    border: 1px solid var(--border);
    padding: 5px;
}
.tl-logo.text {
    display: grid;
    place-items: center;
    font-family: var(--serif);
    font-size: 0.95rem;
    color: var(--accent);
    background: var(--accent-soft);
    border-color: transparent;
    padding: 0;
}

.tl-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 16px; align-items: baseline; }
.tl-head h3 { font-size: 0.98rem; font-weight: 600; }
.tl-date { font-size: 0.8rem; color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tl-org { color: var(--muted); font-size: 0.88rem; }
.tl-item p, .tl-item ul { font-size: 0.9rem; margin: 8px 0 0; }
.tl-item ul { padding-left: 16px; }
.tl-item li { margin-bottom: 4px; }
.tl-item li::marker { color: var(--faint); }

/* ---------- Ledger (talks, awards, policy) ---------- */

.ledger { list-style: none; margin: 0; padding: 0; }
.ledger > li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 24px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.ledger > li:last-child { border-bottom: none; }
.ledger .l-title { font-weight: 500; line-height: 1.45; }
.ledger .l-meta { grid-column: 1; color: var(--muted); font-size: 0.86rem; }
.ledger .l-year {
    grid-column: 2;
    grid-row: 1;
    font-size: 0.8rem;
    color: var(--faint);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    padding-top: 2px;
}
.ledger .tags { margin-top: 6px; }

/* ---------- Definition table (service) ---------- */

.dtable { margin: 0; }
.dtable > div {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 24px;
    padding: 20px 0;
    border-top: 1px solid var(--border);
}
.dtable > div:last-child { border-bottom: 1px solid var(--border); }
.dtable dt {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--faint);
    padding-top: 4px;
}
.dtable dd { margin: 0; }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; justify-content: space-between; gap: 16px; padding: 3px 0; font-size: 0.92rem; }
.rows .r-year { color: var(--faint); font-size: 0.8rem; font-variant-numeric: tabular-nums; white-space: nowrap; padding-top: 2px; }
.rows .r-note { color: var(--muted); }

.venues { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 0; padding: 0; }
.venues li {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    font-size: 0.85rem;
    padding: 5px 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
}
.venues b { font-weight: 600; }
.venues span { color: var(--faint); font-size: 0.78rem; font-variant-numeric: tabular-nums; }

.people { display: flex; flex-wrap: wrap; gap: 6px 8px; list-style: none; padding: 0; margin: 0; }
.people li {
    font-size: 0.86rem;
    padding: 5px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
}

/* ---------- Press ---------- */

.press { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.press a {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.press a:hover { border-color: var(--rule); transform: translateY(-2px); box-shadow: var(--shadow); }
.press .outlet { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.press .headline { font-family: var(--serif); font-size: 1.08rem; line-height: 1.35; }
.press .year { font-size: 0.78rem; color: var(--faint); margin-top: auto; }

/* ---------- Footer ---------- */

footer {
    border-top: 1px solid var(--border);
    padding-top: 24px;
    color: var(--faint);
    font-size: 0.8rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 1040px) {
    :root { --sidebar-w: 240px; }
    .layout { gap: 48px; padding: 0 28px; }
    .interests { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
    html { scroll-padding-top: 72px; }

    .layout { display: block; padding: 0 16px; }

    .topbar {
        display: flex;
        position: sticky;
        top: 0;
        z-index: 20;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 10px 16px;
        background: color-mix(in srgb, var(--bg) 88%, transparent);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-bottom: 1px solid var(--border);
    }
    .topbar .name { font-family: var(--serif); font-size: 1.15rem; color: var(--text); text-decoration: none; }
    .topbar button {
        font: inherit;
        font-size: 0.85rem;
        background: var(--surface);
        border: 1px solid var(--border);
        color: var(--text);
        border-radius: 999px;
        padding: 6px 14px;
        cursor: pointer;
    }

    .sidebar { position: static; height: auto; padding: 36px 0 0; overflow: visible; }
    .profile-photo { width: 104px; height: 104px; }
    .social { margin-bottom: 20px; }

    .side-nav {
        display: none;
        position: fixed;
        top: 53px;
        left: 0;
        right: 0;
        z-index: 19;
        background: var(--bg);
        border-bottom: 1px solid var(--border);
        padding: 12px 16px 16px;
        box-shadow: var(--shadow);
    }
    .side-nav.open { display: block; }
    .side-nav ol { display: grid; grid-template-columns: repeat(2, 1fr); }
    .side-nav a { padding: 8px 0; font-size: 0.95rem; }
    .side-nav a::after { display: none; }

    .sidebar-footer { padding-top: 0; margin-bottom: 8px; }

    main { padding-top: 40px; }
    section { padding-bottom: 56px; }

    .interests, .press { grid-template-columns: minmax(0, 1fr); }
    .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    .filters::-webkit-scrollbar { display: none; }
    .filters button { white-space: nowrap; }
    .news { padding: 4px 16px; max-height: 420px; }
    .news > li { grid-template-columns: minmax(0, 1fr); gap: 4px; }
    .pub { grid-template-columns: minmax(0, 1fr); gap: 2px; }
    .dtable > div { grid-template-columns: minmax(0, 1fr); gap: 10px; }
    .badge { white-space: normal; line-height: 1.3; }
    .tl-item { grid-template-columns: 36px minmax(0, 1fr); gap: 14px; }
    .tl-logo { width: 36px; height: 36px; padding: 4px; }
    .tl-logo.text { font-size: 0.8rem; }
}

@media (max-width: 400px) {
    body { font-size: 15px; }
    .sidebar h1 { font-size: 1.85rem; }
    .section-title { font-size: 1.6rem; }
    .news > li { padding: 14px 0; }
    .rows li { flex-direction: column; gap: 0; }
    .side-nav ol { grid-template-columns: 1fr 1fr; }
}
