/* ============================================
   Ledger layout: a narrow label rail + one reading column.
   MBZUAI navy palette, serif for reading, mono for metadata.
   ============================================ */

:root {
    /* MBZUAI navy (#164678) on white, neutral slate grays */
    --bg: #ffffff;
    --surface: #f7f8fa;
    --ink: #101828;
    --ink-soft: #2b3445;
    --muted: #525c6b;
    --faint: #7a8494;
    --line: #e4e7ec;
    --accent: #164678;
    --accent-bg: #e9eff7;
    --tag-bg: #f1f3f6;

    --serif: 'Newsreader', 'Iowan Old Style', Georgia, serif;
    --mono: 'Geist Mono', 'SF Mono', ui-monospace, Menlo, monospace;

    --rail: 9.5rem;
    --col: 40rem;
    --gap: 2.5rem;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0b1220;
        --surface: #111a2b;
        --ink: #e8edf4;
        --ink-soft: #c8d1de;
        --muted: #9ba6b7;
        --faint: #747f91;
        --line: #1e293b;
        --accent: #8ab4e6;
        --accent-bg: #15284a;
        --tag-bg: #162034;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0b1220;
    --surface: #111a2b;
    --ink: #e8edf4;
    --ink-soft: #c8d1de;
    --muted: #9ba6b7;
    --faint: #747f91;
    --line: #1e293b;
    --accent: #8ab4e6;
    --accent-bg: #15284a;
    --tag-bg: #162034;
    color-scheme: dark;
}

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

html {
    background: var(--bg);
    scroll-behavior: smooth;
    scroll-padding-top: 5rem;
    -webkit-text-size-adjust: 100%;
}

body {
    background: var(--bg);
    color: var(--ink-soft);
    font-family: var(--serif);
    font-size: 1.125rem;
    line-height: 1.6;
    font-optical-sizing: auto;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--faint);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

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

::selection { background: var(--accent-bg); color: var(--ink); }

.skip-link {
    position: absolute;
    left: -999px;
    top: 0.5rem;
    padding: 0.4rem 0.7rem;
    background: var(--ink);
    color: var(--bg);
    font-family: var(--mono);
    font-size: 0.8rem;
}

.skip-link:focus { left: 0.5rem; z-index: 20; }

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

.mono,
.label,
.masthead,
.tag,
.filter-btn,
.date,
footer {
    font-family: var(--mono);
    font-size: 0.78rem;
    letter-spacing: 0.01em;
}

/* ---------- Masthead ---------- */

.masthead {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 6px 18px rgba(16, 24, 40, 0.04);
    font-size: 0.85rem;
}

.masthead-inner {
    max-width: calc(var(--rail) + var(--gap) + var(--col));
    margin: 0 auto;
    padding: 0 1.25rem;
    min-height: 3.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}

.masthead .home {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--ink);
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
}

.home-dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 0.22rem var(--accent-bg);
}

.masthead nav { display: flex; align-items: stretch; gap: 0.25rem; align-self: stretch; }

.masthead nav a {
    display: inline-flex;
    align-items: center;
    padding: 0 0.6rem;
    color: var(--ink-soft);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.masthead nav a:hover { color: var(--ink); background: var(--tag-bg); }

.masthead nav a.active {
    color: var(--ink);
    font-weight: 500;
    border-bottom-color: var(--accent);
}

.theme-toggle {
    flex: none;
    display: inline-grid;
    place-items: center;
    width: 2.1rem;
    height: 2.1rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: transparent;
    color: var(--ink-soft);
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.theme-toggle:hover { color: var(--accent); border-color: var(--faint); background: var(--surface); }

.theme-toggle svg {
    width: 1.05rem;
    height: 1.05rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.theme-toggle .icon-moon { fill: currentColor; stroke: none; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

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

/* ---------- Page grid ---------- */

main {
    max-width: calc(var(--rail) + var(--gap) + var(--col));
    margin: 0 auto;
    padding: 0 1.25rem;
}

.row {
    display: grid;
    grid-template-columns: var(--rail) minmax(0, var(--col));
    column-gap: var(--gap);
}

.label {
    color: var(--muted);
    padding-top: 0.35rem;
}

.label .num { color: var(--accent); margin-right: 0.5rem; }

section {
    padding: 4.5rem 0;
    border-top: 1px solid var(--line);
}

section h2 {
    /* Visible heading lives in the rail label; keep a real h2 for outline + crawlers */
    font-family: var(--mono);
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--muted);
}

/* ---------- Intro ---------- */

.intro { padding: 6rem 0 5rem; border-top: 0; }

.portrait {
    width: 4.5rem;
    height: 4.5rem;
    border-radius: 6px;
    object-fit: cover;
    display: block;
    filter: saturate(0.85);
}

.intro h1 {
    font-family: var(--serif);
    font-weight: 400;
    font-size: clamp(2.6rem, 7vw, 4.25rem);
    line-height: 1.02;
    letter-spacing: -0.03em;
    color: var(--ink);
}

.intro h1 em {
    font-style: italic;
    color: var(--accent);
}

.aka {
    margin-top: 1rem;
    color: var(--muted);
    font-size: 1rem;
}

.aka em { color: var(--ink); }

.lede {
    margin-top: 2rem;
    font-size: 1.3rem;
    line-height: 1.5;
    color: var(--ink);
}

.intro p + p { margin-top: 1rem; }

.pull {
    margin: 1.5rem 0;
    padding-left: 1.25rem;
    border-left: 2px solid var(--accent);
}

.pull p {
    font-size: 1.3rem;
    font-style: italic;
    line-height: 1.45;
    letter-spacing: -0.01em;
    color: var(--ink);
}

.pull cite {
    display: block;
    margin-top: 0.5rem;
    font-family: var(--mono);
    font-size: 0.75rem;
    font-style: normal;
    color: var(--muted);
}

.pull cite::before { content: '\2014\00a0'; }

.facts {
    margin-top: 2.5rem;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.25rem;
    border-top: 1px solid var(--line);
    padding-top: 1.25rem;
}

.facts dt { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); }
.facts dd { margin-top: 0.2rem; font-size: 1rem; color: var(--ink); line-height: 1.4; }

.links {
    margin-top: 2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.4rem;
    font-family: var(--mono);
    font-size: 0.82rem;
}

.links a { text-decoration: none; color: var(--ink); }
.links a::after { content: ' \2197'; color: var(--faint); }
.links a:hover::after { color: var(--accent); }

.open-to {
    margin-top: 2.5rem;
    display: inline-flex;
    align-items: baseline;
    gap: 0.6rem;
    font-size: 1rem;
    color: var(--ink-soft);
}

.dot {
    width: 0.5rem;
    height: 0.5rem;
    flex: none;
    border-radius: 50%;
    background: var(--accent);
    transform: translateY(-0.05rem);
    box-shadow: 0 0 0 0.25rem var(--accent-bg);
}

/* \paragraph{...}-style run-in headings (About only) */
.para-head {
    font-weight: 600;
    color: var(--ink);
    margin-right: 0.15rem;
}

/* ---------- Lists (news, timeline, awards) ---------- */

.entries { list-style: none; }

.entry { padding: 1.1rem 0; }
.entry:first-child { padding-top: 0.2rem; }
.entry + .entry { border-top: 1px solid var(--line); }

.date { display: block; color: var(--muted); margin-bottom: 0.2rem; }

.entry h3 {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--ink);
    line-height: 1.4;
}

.entry .org { color: var(--muted); }

.entry ul { list-style: none; margin-top: 0.4rem; }

.entry li {
    position: relative;
    padding-left: 1rem;
    font-size: 1rem;
    color: var(--ink-soft);
}

.entry li + li { margin-top: 0.3rem; }

.entry li::before {
    content: '\2013';
    position: absolute;
    left: 0;
    color: var(--faint);
}

.entry p { font-size: 1.05rem; }
.entry .date + p { margin-top: 0; }

/* Expandable context under an entry */

.more { margin-top: 0.35rem; }

.more summary {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    list-style: none;
    cursor: pointer;
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--muted);
    transition: color 0.2s ease;
}

.more summary::-webkit-details-marker { display: none; }

.more summary::before {
    content: '+';
    display: inline-grid;
    place-items: center;
    width: 0.95rem;
    height: 0.95rem;
    border: 1px solid var(--line);
    border-radius: 3px;
    line-height: 1;
    color: var(--accent);
}

.more[open] summary::before { content: '\2212'; }
.more summary:hover { color: var(--ink); }

.more-body {
    margin-top: 0.6rem;
    padding: 0.2rem 0 0.2rem 1rem;
    border-left: 1px solid var(--line);
    font-size: 1.02rem;
    color: var(--ink-soft);
}

.more-body p + p { margin-top: 0.5rem; }

.more-body .stat {
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--accent);
}

.more-body .src {
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--faint);
}

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

.filters { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 1.5rem; }

.filter-btn {
    appearance: none;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    padding: 0.3rem 0.65rem;
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.filter-btn:hover { color: var(--ink); border-color: var(--faint); }

.filter-btn[aria-pressed="true"] {
    background: var(--ink);
    border-color: var(--ink);
    color: var(--bg);
}

.filter-btn .count { opacity: 0.6; margin-left: 0.25rem; }

.pubs { list-style: none; }

.pub { padding: 1.25rem 0; }
.pub + .pub { border-top: 1px solid var(--line); }
.pub:first-child { padding-top: 0; }
.pub[hidden] { display: none; }

.pub h3 {
    font-size: 1.15rem;
    font-weight: 500;
    line-height: 1.35;
    color: var(--ink);
}

.pub h3 a { text-decoration: none; }
.pub h3 a:hover { text-decoration: underline; }

.authors { margin-top: 0.35rem; font-size: 1rem; color: var(--muted); }
.authors b { color: var(--ink); font-weight: 600; }

.pub-meta { margin-top: 0.5rem; display: flex; gap: 0.5rem; align-items: center; }

.tag {
    font-size: 0.7rem;
    padding: 0.12rem 0.45rem;
    border-radius: 3px;
    background: var(--tag-bg);
    color: var(--ink-soft);
}

.tag.venue { background: var(--accent-bg); color: var(--accent); }

.note { margin-top: 1.5rem; font-size: 0.95rem; color: var(--muted); }

/* ---------- Contact ---------- */

.contact-big {
    font-size: clamp(1.5rem, 4vw, 2.1rem);
    line-height: 1.25;
    letter-spacing: -0.02em;
    color: var(--ink);
}

.contact-big a { text-decoration-color: var(--accent); text-decoration-thickness: 2px; }

.contact-body { margin-top: 1.5rem; }
.contact-body p + p { margin-top: 0.8rem; }

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

footer {
    max-width: calc(var(--rail) + var(--gap) + var(--col));
    margin: 0 auto;
    padding: 2rem 1.25rem 3rem;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    color: var(--muted);
}

/* ---------- Cat in the rail (sticky) + falling cats ---------- */

main { position: relative; }

.cat-rail {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 1.25rem;
    width: var(--rail);
    pointer-events: none;
    z-index: 2;
}

.cat-btn {
    position: sticky;
    top: 5.5rem;
    margin-top: 6rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.45rem;
    padding: 0 0 0.6rem;
    border: 0;
    background: var(--bg);
    cursor: pointer;
    pointer-events: auto;
}

.cat-btn .portrait { transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1); }
.cat-btn:hover .portrait { transform: rotate(-4deg) scale(1.04); }
.cat-btn:active .portrait { transform: scale(0.94); }

.cat-hint {
    font-family: var(--mono);
    font-size: 0.68rem;
    color: var(--faint);
    transition: opacity 0.3s ease;
}

.cat-btn.used .cat-hint { opacity: 0; }

.falling-cat {
    position: fixed;
    top: -140px;
    z-index: 50;
    pointer-events: none;
    border-radius: 6px;
    will-change: transform;
    animation: cat-fall var(--dur) cubic-bezier(0.5, 0, 0.9, 0.55) var(--delay) forwards;
}

@keyframes cat-fall {
    to { transform: translate(var(--dx), calc(100vh + 240px)) rotate(var(--rot)); }
}

/* ---------- Organization logos ---------- */

.entry.has-logo {
    display: grid;
    grid-template-columns: 2.5rem minmax(0, 1fr);
    column-gap: 1rem;
}

.logo {
    width: 2.5rem;
    height: 2.5rem;
    margin-top: 0.2rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    object-fit: cover;
}

.logo-mono {
    display: grid;
    place-items: center;
    background: var(--surface);
    color: var(--ink);
    font-family: var(--serif);
    font-size: 1.15rem;
}

/* ---------- Tabs: one section at a time ---------- */

.tabs main section { display: none; }
.tabs main section.is-active {
    display: grid;
    border-top: 0;
    min-height: calc(100vh - 3.75rem - 7rem);
    align-content: start;
    animation: tab-in 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes tab-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.next-section {
    grid-column: 2;
    margin-top: 3rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--line);
    font-family: var(--mono);
    font-size: 0.8rem;
}

.next-section a { text-decoration: none; color: var(--ink); }
.next-section a span { color: var(--accent); transition: margin-left 0.2s ease; }
.next-section a:hover span { margin-left: 0.3rem; }

html:not(.tabs) .next-section { display: none; }

/* ---------- Blog: under construction ---------- */

.wip {
    display: grid;
    grid-template-columns: 11rem minmax(0, 1fr);
    gap: 2rem;
    align-items: center;
    padding: 2rem;
    border: 1px dashed var(--line-strong, var(--faint));
    border-radius: 8px;
    background: var(--surface);
}

.wip-sign { width: 100%; height: auto; }

.wip-light { animation: wip-blink 1.4s steps(2, jump-none) infinite; }

@keyframes wip-blink {
    0% { opacity: 1; }
    100% { opacity: 0.25; }
}

.wip-tag {
    display: inline-block;
    margin-bottom: 0.6rem;
    padding: 0.15rem 0.5rem;
    border-radius: 3px;
    background: #f4b400;
    color: #1c1b19;
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.wip-title {
    font-size: 1.4rem;
    line-height: 1.3;
    color: var(--ink);
    margin-bottom: 0.5rem;
}

/* ---------- Motion ---------- */

.js .reveal {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1), transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

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

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .falling-cat { display: none; }
    .wip-light { animation: none; }
    .tabs main section.is-active { animation: none; }
    .js .reveal { opacity: 1; transform: none; transition: none; }
}

/* ---------- Small screens ---------- */

@media (max-width: 760px) {
    :root { --gap: 0; }

    .masthead-inner { flex-direction: column; align-items: stretch; gap: 0; padding: 0; min-height: 0; }

    .masthead .home { padding: 0.8rem 1.25rem 0.4rem; }

    .masthead nav {
        overflow-x: auto;
        scrollbar-width: none;
        padding: 0 0.75rem;
        min-height: 2.6rem;
    }

    .masthead nav::-webkit-scrollbar { display: none; }

    .next-section { grid-column: 1; }

    .wip { grid-template-columns: minmax(0, 1fr); padding: 1.5rem; }

    .wip-sign { max-width: 11rem; }

    .row { grid-template-columns: minmax(0, 1fr); }

    .label { padding: 0 0 1.25rem; }

    section { padding: 3.25rem 0; }

    .intro { padding: 3rem 0 3.5rem; }

    .intro .label { display: none; }

    .cat-rail { position: static; width: auto; padding-top: 2.25rem; }

    .cat-btn { position: static; margin: 0; flex-direction: row; align-items: center; gap: 0.75rem; }

    .intro { padding-top: 1.5rem; }

    .facts { grid-template-columns: minmax(0, 1fr); gap: 0.9rem; }

    footer { flex-direction: column; }
}

/* Keep the cat clear of the section label on every tab except About */
.tabs main .cat-btn { margin-top: 8.5rem; }
.tabs main:has(#about.is-active) .cat-btn { margin-top: 6rem; }

@media (max-width: 760px) {
    .tabs main .cat-btn,
    .tabs main:has(#about.is-active) .cat-btn { margin-top: 0; }

    .tabs main:not(:has(#about.is-active)) .cat-rail { display: none; }
}

/* Masthead: name left, tabs + theme toggle right */
.masthead nav { margin-left: auto; }

@media (max-width: 760px) {
    .masthead-inner { position: relative; }
    .masthead nav { margin-left: 0; }
    .theme-toggle { position: absolute; top: 0.55rem; right: 1rem; width: 1.9rem; height: 1.9rem; }
}
