/* ==========================================================================
   Shared design system for users.cs.utah.edu/~shankar and varunshankar.com
   Mobile-first. Light/dark via prefers-color-scheme + manual toggle.
   Per-site accent is set with <html data-site="personal|lab">.
   ========================================================================== */

:root {
  --paper: #fbfaf7;
  --paper-2: #f3f1ec;
  --card: #ffffff;
  --ink: #18181b;
  --ink-2: #3f3f46;
  --muted: #6b6b73;
  --line: #e4e1da;
  --accent: #a3101a;          /* Utah red, darkened for AA text contrast */
  --accent-ink: #ffffff;
  --accent-soft: #f7e6e6;
  --accent-2: #0b6e79;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 8px 24px -12px rgb(0 0 0 / .12);

  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --wrap: 1120px;
  --gutter: clamp(16px, 4vw, 40px);
  --radius: 14px;
  --step--1: clamp(.83rem, .8rem + .15vw, .9rem);
  --step-0: clamp(1rem, .96rem + .2vw, 1.075rem);
  --step-1: clamp(1.2rem, 1.1rem + .5vw, 1.45rem);
  --step-2: clamp(1.5rem, 1.3rem + 1vw, 2.1rem);
  --step-3: clamp(2rem, 1.6rem + 2vw, 3.2rem);
  --step-4: clamp(2.4rem, 1.8rem + 3.2vw, 4.4rem);
  color-scheme: light;
}
html[data-site="lab"] {
  --accent: #0b6e79;
  --accent-soft: #e2f1f2;
  --accent-2: #a3101a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1115; --paper-2: #151821; --card: #171a22; --ink: #ecebe8; --ink-2: #c9c8c4;
    --muted: #9a9aa3; --line: #272b36; --accent: #ff6b6b; --accent-ink: #14161b; --accent-soft: #2a1a1d;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 10px 30px -14px rgb(0 0 0 / .6); color-scheme: dark;
  }
  html[data-site="lab"]:not([data-theme="light"]) { --accent: #4fd1c5; --accent-soft: #10292b; --accent-2: #ff6b6b; }
}
:root[data-theme="dark"] {
  --paper: #0f1115; --paper-2: #151821; --card: #171a22; --ink: #ecebe8; --ink-2: #c9c8c4;
  --muted: #9a9aa3; --line: #272b36; --accent: #ff6b6b; --accent-ink: #14161b; --accent-soft: #2a1a1d;
  --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 10px 30px -14px rgb(0 0 0 / .6); color-scheme: dark;
}
html[data-site="lab"][data-theme="dark"] { --accent: #4fd1c5; --accent-soft: #10292b; --accent-2: #ff6b6b; }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition: none !important; animation: none !important; } }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 var(--step-0)/1.65 var(--sans); text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
img, svg, canvas { max-width: 100%; display: block; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: .18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; border-radius: 4px; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 500; line-height: 1.15; letter-spacing: -.01em; margin: 0 0 .5em; text-wrap: balance; }
h1 { font-size: var(--step-4); letter-spacing: -.02em; }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-1); }
p { margin: 0 0 1em; text-wrap: pretty; }
.wrap { width: min(100% - 2 * var(--gutter), var(--wrap)); margin-inline: auto; }
.prose { max-width: 70ch; }
.muted { color: var(--muted); }
.eyebrow { font: 500 var(--step--1)/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin-bottom: .9rem; display: block; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 100; background: var(--card); padding: .5rem 1rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- header / nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap { display: flex; align-items: center; gap: 1rem; min-height: 64px; }
.brand { display: flex; align-items: center; gap: .65rem; color: var(--ink); text-decoration: none; font: 600 1.05rem/1.1 var(--sans); letter-spacing: -.01em; margin-right: auto; }
.brand small { display: block; font: 400 .78rem/1.2 var(--mono); color: var(--muted); letter-spacing: .02em; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.nav { display: none; }
.nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: .25rem; }
.nav a { display: block; padding: .45rem .75rem; border-radius: 999px; color: var(--ink-2); text-decoration: none; font-size: .95rem; }
.nav a:hover { background: var(--paper-2); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.icon-btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 18px; height: 18px; }
.menu-btn { display: grid; }
@media (min-width: 900px) { .nav { display: block; } .menu-btn { display: none; } }

.drawer { display: none; border-top: 1px solid var(--line); }
.drawer.open { display: block; }
.drawer ul { list-style: none; margin: 0; padding: .5rem 0 1rem; }
.drawer a { display: block; padding: .8rem 0; font-size: 1.1rem; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.drawer a[aria-current="page"] { color: var(--accent); }
@media (min-width: 900px) { .drawer, .drawer.open { display: none; } }

/* ---------- sections ---------- */
main { display: block; }
.section { padding-block: clamp(3rem, 7vw, 6rem); }
.section + .section { border-top: 1px solid var(--line); }
.section-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 2rem; }
.section-head h2 { margin: 0; }
.page-head { padding-block: clamp(3rem, 8vw, 5.5rem) clamp(1.5rem, 4vw, 2.5rem); }
.page-head h1 { font-size: var(--step-3); max-width: 22ch; }
.page-head .lede { font-size: var(--step-1); color: var(--ink-2); max-width: 60ch; font-family: var(--serif); line-height: 1.45; }

/* ---------- buttons / pills ---------- */
.btn { display: inline-flex; align-items: center; gap: .5rem; padding: .7rem 1.1rem; border-radius: 999px; font: 500 .95rem/1 var(--sans); text-decoration: none; border: 1px solid var(--line); color: var(--ink); background: var(--card); }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn svg { width: 16px; height: 16px; }
.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; }
.pill { display: inline-flex; align-items: center; gap: .3rem; font: 500 .74rem/1 var(--mono); letter-spacing: .03em; padding: .32rem .55rem; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2); background: var(--paper-2); text-decoration: none; white-space: nowrap; }
a.pill:hover { border-color: var(--accent); color: var(--accent); }
.pill.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---------- grids / cards ---------- */
.grid { display: grid; gap: clamp(1rem, 2.5vw, 1.5rem); grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--min, 280px)), 1fr)); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1.1rem, 2.5vw, 1.6rem); box-shadow: var(--shadow); min-width: 0; }
.card h3 { margin-bottom: .4rem; }
.card p:last-child { margin-bottom: 0; }
a.card { color: inherit; text-decoration: none; transition: transform .2s ease, border-color .2s ease; display: block; }
a.card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.split { display: grid; gap: clamp(2rem, 5vw, 4rem); }
@media (min-width: 860px) { .split { grid-template-columns: 1.35fr 1fr; align-items: start; } .split.rev { grid-template-columns: 1fr 1.35fr; } }

/* ---------- personal hero ---------- */
.hero-personal { padding-block: clamp(2.5rem, 7vw, 5.5rem); }
.hero-personal .split { align-items: center; }
.hero-personal h1 { margin-bottom: .25em; }
.hero-personal .role { font: 400 var(--step-1)/1.4 var(--serif); color: var(--ink-2); margin-bottom: 1.4rem; }
.portrait { position: relative; justify-self: center; width: min(100%, 360px); }
.portrait .frame { aspect-ratio: 4 / 5; border-radius: 20px; overflow: hidden; background: linear-gradient(140deg, var(--accent-soft), var(--paper-2)); border: 1px solid var(--line); display: grid; place-items: center; }
.portrait img { width: 100%; height: 100%; object-fit: cover; }
.portrait .initials { font: 500 5rem/1 var(--serif); color: var(--accent); }
.portrait::after { content: ""; position: absolute; inset: auto -14px -14px auto; width: 60%; height: 60%; border: 1px solid var(--accent); border-radius: 20px; z-index: -1; opacity: .5; }
.contact-list { list-style: none; padding: 0; margin: 1.5rem 0 0; display: grid; gap: .4rem; font-size: .95rem; color: var(--ink-2); }
.contact-list li { display: flex; gap: .6rem; align-items: baseline; }
.contact-list span:first-child { font: 500 .72rem/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); min-width: 4.5rem; }

/* ---------- lab hero ---------- */
.hero-lab { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); isolation: isolate; }
.hero-lab canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; }
.hero-lab::after { content: ""; position: absolute; inset: 0; z-index: -1; background: radial-gradient(120% 90% at 0% 50%, var(--paper) 30%, color-mix(in srgb, var(--paper) 55%, transparent) 65%, transparent); pointer-events: none; }
.hero-lab .wrap { padding-block: clamp(4rem, 13vw, 9rem); }
.hero-lab h1 { max-width: 16ch; }
.hero-lab .lede { font: 400 var(--step-1)/1.45 var(--serif); color: var(--ink-2); max-width: 46ch; margin-bottom: 2rem; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-top: 3rem; max-width: 720px; }
.stats div { background: var(--card); padding: 1rem 1.2rem; }
.stats b { display: block; font: 500 var(--step-2)/1 var(--serif); color: var(--ink); }
.stats span { font: 400 .8rem/1.3 var(--mono); color: var(--muted); }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }

/* ---------- research thrusts ---------- */
.thrust-card .num { font: 500 .8rem/1 var(--mono); color: var(--accent); letter-spacing: .08em; }
.thrust-card h3 { margin-top: .6rem; }
.thrust { padding-block: clamp(2rem, 5vw, 3.5rem); border-top: 1px solid var(--line); scroll-margin-top: 80px; }
.thrust:first-of-type { border-top: 0; }
.thrust .math { background: var(--paper-2); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.2rem; overflow-x: auto; margin: 1.2rem 0; }
.thrust ul.keys { padding-left: 1.1rem; margin: 0 0 1rem; }
.thrust ul.keys li { margin-bottom: .35rem; }
.thrust aside h4 { font: 500 .78rem/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 .8rem; }
.mini-list { list-style: none; padding: 0; margin: 0 0 1.5rem; display: grid; gap: .7rem; font-size: .93rem; }
.mini-list li { padding-left: .9rem; border-left: 2px solid var(--line); line-height: 1.45; }
.mini-list .v { color: var(--muted); font-size: .85rem; display: block; }

/* ---------- grants ---------- */
.grant { display: flex; flex-direction: column; gap: .7rem; }
.grant .top { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.sponsor { font: 600 .8rem/1 var(--mono); letter-spacing: .06em; padding: .38rem .6rem; border-radius: 6px; background: var(--ink); color: var(--paper); }
.grant h3 { font-size: 1.12rem; line-height: 1.35; margin: 0; }
.grant .prog { font-size: .88rem; color: var(--muted); margin: 0; }
.grant .meta { margin-top: auto; display: flex; flex-wrap: wrap; justify-content: space-between; gap: .5rem; font: 400 .8rem/1.3 var(--mono); color: var(--muted); }
.bar { height: 6px; background: var(--paper-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; width: var(--p, 0%); background: var(--accent); border-radius: 99px; }
.sponsor-strip { display: flex; flex-wrap: wrap; gap: .6rem 1.4rem; align-items: center; font: 600 clamp(1rem, .9rem + .6vw, 1.35rem)/1 var(--mono); color: var(--muted); letter-spacing: .06em; }

/* ---------- publications ---------- */
.pub-tools { display: grid; gap: .8rem; margin-bottom: 1.5rem; position: sticky; top: 64px; z-index: 5; background: var(--paper); padding-block: .8rem; border-bottom: 1px solid var(--line); }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink-2); font: 500 .85rem/1 var(--sans); padding: .5rem .8rem; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip .n { font-family: var(--mono); font-size: .75rem; opacity: .65; margin-left: .25rem; }
.search { display: flex; gap: .6rem; align-items: center; }
.search input { flex: 1; min-width: 0; font: inherit; font-size: 1rem; padding: .65rem .9rem; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.search .count { font: 400 .8rem/1 var(--mono); color: var(--muted); white-space: nowrap; }
.pub-year { font: 500 var(--step-1)/1 var(--serif); color: var(--muted); margin: 2rem 0 .6rem; padding-top: .4rem; }
.pubs { list-style: none; padding: 0; margin: 0; }
.pub { padding: 1rem 0; border-bottom: 1px solid var(--line); display: grid; gap: .3rem; }
.pub .t { font: 500 1.06rem/1.4 var(--sans); color: var(--ink); }
.pub .a { font-size: .92rem; color: var(--ink-2); }
.pub .a b { color: var(--ink); font-weight: 600; }
.pub .a u { text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.pub .v { font-size: .9rem; color: var(--muted); font-style: italic; }
.pub .links { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .25rem; }
.pub[hidden] { display: none; }
.legend { font-size: .85rem; color: var(--muted); }
.legend u { text-decoration-color: var(--accent); text-decoration-thickness: 2px; }

/* ---------- people ---------- */
.person { display: flex; gap: 1rem; align-items: center; }
.avatar { width: 64px; height: 64px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font: 500 1.3rem/1 var(--serif); overflow: hidden; border: 1px solid var(--line); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.person h3 { font-size: 1.1rem; margin: 0 0 .15rem; font-family: var(--sans); font-weight: 600; letter-spacing: 0; }
.person p { margin: 0; font-size: .88rem; color: var(--muted); line-height: 1.4; }
.pi-card { display: grid; gap: 1.5rem; align-items: center; }
.pi-card .avatar { width: 120px; height: 120px; font-size: 2.4rem; }
@media (min-width: 640px) { .pi-card { grid-template-columns: auto 1fr; } }
.alumni { columns: 1; column-gap: 2.5rem; padding: 0; list-style: none; margin: 0; }
@media (min-width: 720px) { .alumni { columns: 2; } }
.alumni li { break-inside: avoid; padding: .7rem 0; border-bottom: 1px solid var(--line); font-size: .95rem; }
.alumni li span { display: block; color: var(--muted); font-size: .85rem; }

/* ---------- timeline / cv ---------- */
.tl { list-style: none; padding: 0; margin: 0; }
.tl li { display: grid; gap: .2rem 1.5rem; padding: .8rem 0; border-bottom: 1px solid var(--line); }
.tl .when { font: 400 .82rem/1.5 var(--mono); color: var(--muted); }
@media (min-width: 640px) { .tl li { grid-template-columns: 9.5rem 1fr; } .tl .when { order: -1; } }
.news li { grid-template-columns: 1fr; }
@media (min-width: 640px) { .news li { grid-template-columns: 6.5rem 1fr; } }
.toc { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding-block: 2.5rem; font-size: .9rem; color: var(--muted); background: var(--paper-2); }
.site-footer .wrap { display: grid; gap: 1.2rem; }
.site-footer a { color: var(--ink-2); }
.site-footer .row { display: flex; flex-wrap: wrap; gap: .5rem 1.4rem; align-items: center; justify-content: space-between; }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }

/* ---------- misc ---------- */
.callout { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 1rem 1.2rem; border-radius: 0 12px 12px 0; }
.callout p:last-child { margin: 0; }
.katex { font-size: 1.05em; }
.katex-display { margin: .2rem 0 !important; overflow-x: auto; overflow-y: hidden; padding-block: .2rem; }
.js .reveal { opacity: 0; transform: translateY(12px); transition: opacity .6s ease, transform .6s ease; }
.js .reveal.in { opacity: 1; transform: none; }
@media print { .site-header, .site-footer, .pub-tools, .hero-lab canvas { display: none !important; } body { background: #fff; color: #000; } }
@media (max-width: 859px) {
  .hero-personal .portrait { order: -1; width: min(55%, 210px); justify-self: start; }
  .hero-personal .portrait::after { inset: auto -8px -8px auto; }
}

/* ---------- fixes (Oct 2026) ---------- */
/* grid/flex children must be allowed to shrink, or wide math/long words blow out the column */
.split > *, .grid > *, .thrust .math { min-width: 0; }
/* timeline rows without a date span the full width */
.tl li > span:only-child { grid-column: 1 / -1; }
/* contact list: label column + free-flowing text (no flex splitting of inline links) */
.contact-list li { display: grid; grid-template-columns: 4.5rem 1fr; gap: .6rem; align-items: baseline; }
.contact-list li > span:first-child { min-width: 0; }
/* publication chips wrap on wider screens instead of hiding off-edge */
@media (min-width: 720px) { .chips { flex-wrap: wrap; overflow: visible; } }
/* eyebrow: keep phrases together */
.eyebrow { text-wrap: balance; }
/* lab home: director block */
.director { border-top: 1px solid var(--line); }
.director-card { display: grid; gap: clamp(1.5rem, 4vw, 3rem); align-items: center; }
.director-photo { display: block; width: min(100%, 260px); aspect-ratio: 1; border-radius: 50%; overflow: hidden; border: 1px solid var(--line); background: var(--accent-soft); box-shadow: 0 0 0 8px var(--paper), 0 0 0 9px color-mix(in srgb, var(--accent) 40%, var(--line)); display: grid; place-items: center; }
.director-photo img { width: 100%; height: 100%; object-fit: cover; }
.director-photo span { font: 500 3rem/1 var(--serif); color: var(--accent); }
.director-card h2 { font-size: var(--step-3); margin-bottom: .4rem; }
.director-card .lede-sm { color: var(--ink-2); max-width: 60ch; font-size: var(--step-0); }
@media (min-width: 760px) { .director-card { grid-template-columns: 260px 1fr; } }
@media (max-width: 759px) { .director-photo { width: 180px; } }
/* keep scroll-reveal subtle so content never looks missing */
.js .reveal { opacity: 1; transform: translateY(8px); }
.js .reveal.in { transform: none; }
