/* ==========================================================================
   Viraj Agrawal — personal site
   ========================================================================== */

/* --- Tokens --------------------------------------------------------------- */
:root {
  color-scheme: light;

  --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --measure: 43rem;

  --bg: #fdfdfc;
  --bg-2: #f2f6f5;
  --surface: #ffffff;
  --ink: #1b1b1b;
  --ink-soft: #3d3d3d;
  --ink-faint: #626262;
  --rule: #dfe1e0;
  --accent: #10635f;
  --accent-2: #1d7f78;
  --accent-soft: #e5efee;
  --shadow: 0 6px 20px rgba(16, 99, 95, .10);

  --ease: cubic-bezier(.22, .61, .36, 1);
}

/* The OS color-scheme preference is applied as the default (with the toggle as
   the override) by the inline script in each page's head, before first paint. */
html[data-theme="dark"] {
  color-scheme: dark;

  --bg: #14161a;
  --bg-2: #171d1e;
  --surface: #1a1d21;
  --ink: #e7e6e3;
  --ink-soft: #c3c2bf;
  --ink-faint: #9a9a99;
  --rule: #32363b;
  --accent: #62c4bb;
  --accent-2: #8ad8d0;
  --accent-soft: #17302e;
  --shadow: 0 6px 22px rgba(0, 0, 0, .45);
}

/* --- Base ----------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

/* Reserve the scrollbar gutter always, so short pages and long pages lay out
   at the same width instead of shifting by the scrollbar's width. */
html { scroll-behavior: smooth; scrollbar-gutter: stable; }

/* Transitions are suspended while the theme swaps, otherwise properties that read
   a custom property keep their old value instead of picking up the new token. */
html.theme-switching, html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after {
  transition: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.6;
  /* Charter has lining figures, but the Windows fallbacks (Sitka, Georgia) default to
     old-style ones, which makes years like 2024 ride up and down the baseline. */
  font-variant-numeric: lining-nums;
  -webkit-text-size-adjust: 100%;
}

/* The page wash lives on a fixed pseudo-element rather than a fixed background
   attachment: iOS Safari ignores background-attachment: fixed, and a fixed layer
   scrolls without repainting the gradients. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60rem 40rem at 12% -10%, var(--accent-soft), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}

::selection { background: var(--accent-soft); color: var(--ink); }

p { margin: 0 0 1rem; }

/* Android draws a filled rectangle over the tapped element, which looks wrong on
   a circular button and on the bordered markers. */
a, button, summary { -webkit-tap-highlight-color: transparent; }

/* Underline grows out from the left instead of snapping on. */
a {
  color: var(--accent);
  text-decoration: none;
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 0% 1px;
  background-repeat: no-repeat;
  background-position: 0 calc(100% - 1px);
  transition: background-size .28s var(--ease), color .2s var(--ease);
}
a:hover { background-size: 100% 1px; color: var(--accent-2); }

h1 {
  font-size: 2rem; font-weight: 600; line-height: 1.15;
  letter-spacing: -0.01em; margin: 0 0 .6rem;
}
h1::after {
  content: ""; display: block;
  width: 2.75rem; height: 2px; margin-top: .65rem;
  background: linear-gradient(90deg, var(--accent), transparent);
}

h2 {
  font-family: var(--sans);
  font-size: .95rem; font-weight: 600;
  font-variant: small-caps; letter-spacing: .06em;
  color: var(--accent);
  margin: 2.75rem 0 .9rem;
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--rule);
}

h3 {
  font-family: var(--sans); font-size: .9rem; font-weight: 650;
  color: var(--ink); margin: 1.6rem 0 .5rem;
}

ul { padding-left: 1.15rem; margin: 0 0 1rem; }
li { margin-bottom: .3rem; }

.muted { color: var(--ink-faint); }

.skip-link { position: absolute; left: -999px; top: 0; background: var(--bg); padding: .5rem 1rem; }
.skip-link:focus { left: 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Layout --------------------------------------------------------------- */
/* Sidebar track is sized to its widest item, "Competitive Programming", measured at the
   bolder weight the current-page link uses — at 11.5rem it overflowed by 0.35px and wrapped. */
.layout {
  --side: 12.5rem;
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
  gap: 2.5rem;
  max-width: calc(var(--side) + 2.5rem + var(--measure) + 3rem);
  margin: 0 auto;
  padding: 3.5rem 1.5rem 3rem;
  align-items: start;
}

.content { min-width: 0; }

/* Keep prose at a readable line length even when the layout goes full-bleed. */
main { max-width: var(--measure); }

/* --- Sidebar -------------------------------------------------------------- */
.sidebar { position: sticky; top: 3.5rem; }

/* Portrait and site name share one home link, so keyboard users get a single
   tab stop whose accessible name is the visible name. */
/* Portrait and name are separate links: the portrait opens a larger view, the name goes home. */
.sidebar__head { margin-bottom: 1.1rem; }
/* fit-content, or the block link stretches across the column and leaves a clickable
   strip of empty space beside the photo. */
.portrait-link { display: block; width: fit-content; background-image: none; }
.portrait {
  width: 100%; max-width: 145px; height: auto;
  border: 1px solid var(--rule); border-radius: 50%; display: block;
  cursor: zoom-in;
  transition: transform .3s var(--ease), box-shadow .3s var(--ease);
}
.portrait-link:hover .portrait { transform: translateY(-3px); box-shadow: var(--shadow); }
.sitename {
  display: block; margin-top: .85rem;
  font-size: 1.1rem; font-weight: 600; line-height: 1.25;
  color: var(--ink); background-image: none;
}
.sitename:hover { color: var(--accent); }

/* Native <dialog> gives focus trapping, inert background and Esc-to-close for free.
   It spans the viewport so clicks beside the photo land on the dialog and dismiss it. */
.lightbox {
  width: 100%; max-width: 100%;
  height: 100%; max-height: 100%;
  margin: 0; border: 0; padding: 0;
  background: transparent;
  overflow: hidden;
  cursor: zoom-out;
}
.lightbox[open] { display: grid; place-items: center; }
.lightbox::backdrop {
  background: rgba(10, 12, 14, .55);
  backdrop-filter: blur(3px);
}
.lightbox img {
  display: block;
  /* Never exceed the file's intrinsic 360px, or the upscale goes soft. */
  width: min(86vw, 360px); height: auto;
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
  cursor: default;
  animation: lightbox-in .2s var(--ease);
}

@keyframes lightbox-in {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: 1; transform: none; }
}

.sidenav { font-family: var(--sans); font-size: .92rem; }
.sidenav a {
  display: block; padding: .3rem 0; position: relative;
  background-image: none;
  transition: color .2s var(--ease), transform .2s var(--ease);
}
.sidenav a:hover { transform: translateX(3px); }
.sidenav a[aria-current="page"] { color: var(--ink); font-weight: 650; }
.sidenav a[aria-current="page"]::before {
  content: ""; position: absolute; left: -.85rem;
  top: .32rem; bottom: .32rem;
  width: 3px; border-radius: 2px;
  background: linear-gradient(var(--accent), var(--accent-2));
}

/* --- Identity block, About page ------------------------------------------- */
.affil { color: var(--ink-soft); line-height: 1.45; margin-bottom: .5rem; }
.contact, .profiles { font-family: var(--sans); font-size: .9rem; margin-bottom: .3rem; }
.contact { color: var(--ink-soft); }
.profiles { color: var(--ink-faint); margin-bottom: 1.9rem; }

/* --- Publications --------------------------------------------------------- */
.pubs { list-style: none; padding: 0; margin: 0; }
.pubs > li {
  margin: 0 0 1.6rem;
  padding-left: 1rem;
  border-left: 2px solid var(--rule);
  transition: border-color .25s var(--ease);
}
.pubs > li:hover { border-left-color: var(--accent); }
.pubs > li:last-child { margin-bottom: 0; }

.pub-title { font-weight: 600; }
.authors { color: var(--ink-soft); }
.venue { color: var(--ink-faint); }
.pub-links { font-family: var(--sans); font-size: .85rem; color: var(--ink-faint); }
.summary { color: var(--ink-soft); font-size: .96rem; margin: .7rem 0 0; }

/* --- Role entries (experience) -------------------------------------------- */
.role {
  margin-bottom: 2.25rem;
  padding-left: 1rem;
  border-left: 2px solid var(--rule);
  transition: border-color .25s var(--ease);
}
.role:hover { border-left-color: var(--accent); }
.role:last-child { margin-bottom: 0; }
.role h2 { margin-top: 0; }
.role + .role h2 { margin-top: 2.5rem; }
.when {
  font-family: var(--sans); font-size: .85rem; color: var(--ink-faint);
  margin-bottom: .7rem;
}

/* --- Earlier (dated affiliations) ----------------------------------------- */
.earlier { list-style: none; padding: 0; margin: 0; }
.earlier li { margin-bottom: .4rem; color: var(--ink-soft); }
.earlier .yr {
  color: var(--ink-faint);
  font-variant-numeric: lining-nums tabular-nums;
  margin-right: .5rem;
}

/* --- Theme toggle --------------------------------------------------------- */
.theme-toggle {
  position: fixed;
  top: clamp(1rem, 2.4vw, 1.6rem);
  right: clamp(1rem, 2.4vw, 1.6rem);
  z-index: 20;
  display: grid; place-items: center;
  width: 2.3rem; height: 2.3rem;
  padding: 0;
  color: var(--ink-faint);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 50%;
  cursor: pointer;
  transition: color .2s var(--ease), border-color .2s var(--ease),
              transform .2s var(--ease), box-shadow .2s var(--ease);
}
/* Transform-based hovers are gated to real pointers: on a touchscreen they latch
   after a tap and leave the control sitting there rotated or lifted. */
@media (hover: hover) and (pointer: fine) {
  .theme-toggle:hover {
    color: var(--accent); border-color: var(--accent);
    transform: rotate(-12deg); box-shadow: var(--shadow);
  }
}
.theme-toggle .icon { display: block; }
.theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* --- Publication summary disclosure ---------------------------------------- */
/* Inline variant for a single publication entry: no rules, no full-width hit area.
   Animation is scoped to [open] and has no fill mode on purpose: inside a closed
   <details> the content is content-visibility:hidden, where animations never advance,
   and a `both` fill would pin the body at the opening keyframe (opacity 0). */
.pub-abstract { margin-top: .45rem; }
.pub-abstract > summary {
  cursor: pointer; list-style: none; user-select: none;
  display: inline-flex; align-items: center; gap: .4rem;
  font-family: var(--sans); font-size: .8rem; letter-spacing: .02em;
  color: var(--ink-faint);
  background-image: none;
  transition: color .2s var(--ease);
}
.pub-abstract > summary::-webkit-details-marker { display: none; }
.pub-abstract > summary:hover { color: var(--accent); }
.pub-abstract > summary::after {
  content: ""; flex: 0 0 auto;
  width: 5px; height: 5px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-1px) rotate(-45deg);
  transition: transform .22s var(--ease);
  opacity: .75;
}
.pub-abstract[open] > summary::after { transform: translateY(-2px) rotate(45deg); }
.pub-abstract[open] .summary { animation: disclosure-in .24s ease; }
/* When the print handler opens the details, the open-animation must not start:
   the print snapshot would freeze its first keyframe (opacity 0). This has to be
   a screen-media rule — print media sees the beforeprint-time animation state. */
html.printing .pub-abstract[open] .summary { animation: none; }

/* Numbered markers: the link is the evidence, the label carries no claim. */
.marks { font-family: var(--sans); font-size: .88rem; color: var(--ink-soft); margin-bottom: .5rem; }
.marks__role { display: inline-block; min-width: 6.2rem; color: var(--ink-faint); }
.marks a {
  display: inline-block;
  min-width: 1.35rem;
  margin: 0 .1rem;
  padding: .05rem .3rem;
  text-align: center;
  font-size: .8rem;
  color: var(--ink-faint);
  border: 1px solid var(--rule);
  border-radius: 4px;
  background-image: none;
  transition: color .18s var(--ease), border-color .18s var(--ease);
}
.marks a:hover { color: var(--accent); border-color: var(--accent); }
.marks__sep { margin: 0 .45rem; color: var(--ink-faint); }

/* Contest work: role rows that expand into the full list of contests. Same
   chevron and open animation as the publication summary, scoped to [open]. */
.contests { font-family: var(--sans); font-size: .88rem; margin-bottom: .35rem; }
.contests > summary {
  cursor: pointer; list-style: none; user-select: none;
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .2rem 0;
  color: var(--ink-soft);
  transition: color .2s var(--ease);
}
.contests > summary::-webkit-details-marker { display: none; }
.contests > summary:hover { color: var(--accent); }
.contests > summary::after {
  content: ""; flex: 0 0 auto;
  width: 5px; height: 5px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-1px) rotate(-45deg);
  transition: transform .22s var(--ease);
  opacity: .75;
}
.contests[open] > summary::after { transform: translateY(-2px) rotate(45deg); }
.contests__list {
  list-style: none; margin: .2rem 0 .6rem; padding: 0 0 0 .9rem;
  border-left: 2px solid var(--rule);
}
.contests__list li { margin: 0; }
.contests__list a { display: inline-block; padding: .15rem 0; color: var(--ink-soft); }
.contests__list a:hover { color: var(--accent); }
.contests[open] .contests__list { animation: disclosure-in .24s ease; }
html.printing .contests[open] .contests__list { animation: none; }

@keyframes disclosure-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* --- Entrance ------------------------------------------------------------- */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* Entrances run only on the first page of a session (html[data-entrance] is set
   by the inline head script), so internal navigation doesn't replay them. */
html[data-entrance] .sidebar { animation: fade-in .5s var(--ease) both; }
html[data-entrance] main { animation: rise .55s var(--ease) .06s both; }

/* --- Responsive ----------------------------------------------------------- */
/* Narrow the side panel before giving up on it. */
@media (max-width: 900px) {
  .layout { --side: 11.5rem; gap: 2rem; padding-top: 3rem; }
  .sidebar { top: 3rem; } /* match the reduced layout padding, or it sits 8px low */
  .portrait { max-width: 118px; }
  .sidenav { font-size: .88rem; }
}

@media (max-width: 660px) {
  /* Phones use overlay scrollbars, so the reserved gutter is dead space that
     also pushes the layout visibly off-centre on a narrow screen. */
  html { scrollbar-gutter: auto; }
  /* Block rather than grid: a sticky grid item only sticks within its own grid
     area, so the bar would scroll away as soon as the content row began. */
  .layout {
    display: block;
    padding-top: 0;
  }
  .content { margin-top: 1.4rem; }
  /* Compact bar so the photo, name and nav stay reachable while scrolling. */
  .sidebar {
    position: sticky; top: 0; z-index: 30;
    margin: 0 -1.5rem;
    padding: .45rem 1.5rem .5rem;
    background: var(--bg);
    border-bottom: 1px solid var(--rule);
    display: flex; align-items: center; flex-wrap: wrap;
    column-gap: 1rem; row-gap: .1rem;
  }
  .sidebar__head { margin-bottom: 0; display: flex; align-items: center; gap: .6rem; }
  .sitename { margin-top: 0; font-size: .98rem; padding: .25rem 0; }
  .portrait { max-width: 34px; }
  .theme-toggle { position: fixed; width: 2.75rem; height: 2.75rem; top: .3rem; right: .55rem; z-index: 31; }
  /* Touch targets: 44px tall nav rows, and markers lifted over the 24x24 minimum.
     The nav is sized to stay on one line so the sticky bar keeps a low profile. */
  .sidenav { font-size: .82rem; }
  .sidenav a { display: inline-block; margin-right: .8rem; padding: .4rem 0; }
  .marks a { min-width: 1.75rem; padding: .3rem .45rem; }
  .contests > summary { padding: .4rem 0; }
  .contests__list a { padding: .3rem 0; }
  .pub-abstract > summary { padding: .3rem 0; }
  .pub-links a { display: inline-block; padding: .25rem .15rem; }
  /* The vertical marker would hang into the page padding once links flow inline.
     The bolder weight is dropped too: it widens the row enough to wrap the nav
     onto a second line, which would change the bar's height per page. */
  .sidenav a[aria-current="page"] { border-bottom: 2px solid var(--accent); font-weight: 400; }
  .sidenav a[aria-current="page"]::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  html[data-entrance] main, html[data-entrance] .sidebar { animation: none; }
  .pub-abstract[open] .summary { animation: none; }
  .contests[open] .contests__list { animation: none; }
  .theme-toggle:hover { transform: none; }
  .sidenav a:hover { transform: none; }
  .portrait-link:hover .portrait { transform: none; }
  .lightbox img { animation: none; }
  *, *::before, *::after { transition-duration: .01ms !important; }
}

@media print {
  .skip-link, .sidenav, .theme-toggle { display: none; }  .layout { display: block; max-width: none; }
  body { color: #000; background: #fff; }
  body::before { display: none; }
  a { color: #000; }

  /* Printing while the dark theme is active would otherwise put pale dark-theme
     grays on white paper; force the light ink tokens back. */
  html[data-theme="dark"] {
    --ink: #000;
    --ink-soft: #3d3d3d;
    --ink-faint: #626262;
    --rule: #dfe1e0;
    --accent: #10635f;
  }

  /* On paper the links are the evidence, so print their destinations. */
  .marks a[href]::after,
  .contests__list a[href]::after,
  .pub-links a[href]::after { content: " (" attr(href) ")"; font-size: .7em; }

  /* Print snapshots freeze running animations at their current keyframe; the
     entrance animations start at opacity 0 and would print the page blank. */
  html[data-entrance] main,
  html[data-entrance] .sidebar,
  .contests[open] .contests__list,
  .pub-abstract[open] .summary { animation: none; }
}
