/* ==========================================================
   Nagarathna · site stylesheet

   Tokens live in :root. Fonts: change --font-body /
   --font-display / --font-mono here and the Google Fonts
   <link> in each page's <head>.

   Large screens (>= 1024 x 640): each page fits the window,
   no page scroll. Smaller screens: normal scrolling layout.
   ========================================================== */

:root {
  /* Colour: one crimson accent on cool neutrals */
  --ink: #16181b;
  --ink-2: #3d4248;
  --ink-3: #6a7078;
  --rule: #e3e5e8;
  --paper: #fcfcfc;
  --accent: #a3262e;
  --accent-deep: #821d24;
  --accent-wash: #f4e3e4;
  --on-accent: #ffffff;
  --on-accent-dim: rgba(255, 255, 255, 0.74);

  /* Type */
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: var(--font-body);
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --text-2xs: 0.6875rem;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-md: 1.1875rem;
  --text-lg: 1.5rem;
  --text-xl: 2.25rem;
  --text-2xl: clamp(2.5rem, 2rem + 2.4vw, 4.75rem);

  /* Space: 4px base */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;
  --s8: 4rem;

  --r1: 2px;

  --rail: 100%;
  --pad-x: 1.25rem;
  --pad-y: 1.5rem;

}

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

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, p, ul, ol { margin: 0; }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover { color: var(--accent-deep); text-decoration-thickness: 2px; }

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

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ==========================================================
   Frame: crimson rail + stage
   ========================================================== */

.frame { min-height: 100dvh; }

.rail {
  position: relative;
  background: var(--accent);
  color: var(--on-accent);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--s5);
  padding: var(--s2) var(--pad-x);
  counter-reset: nav;
}

.nav a {
  counter-increment: nav;
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  padding: var(--s2) 0;
  color: var(--on-accent-dim);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.nav a::before {
  content: counter(nav, decimal-leading-zero);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  opacity: 0.7;
}

.nav a:hover { color: var(--on-accent); }

.nav a[aria-current="page"] {
  color: var(--on-accent);
  border-bottom-color: var(--on-accent);
}

.nav a:focus-visible { outline-color: var(--on-accent); }

.stage {
  padding: var(--pad-y) var(--pad-x) var(--s7);
}

/* Page title used on inner pages */
.stage-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s4) var(--s6);
  padding-bottom: var(--s4);
  margin-bottom: var(--s5);
  border-bottom: 1px solid var(--ink);
}

.stage-head h1,
.identity h1 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 0.95;
  overflow-wrap: break-word;
}

/* Section label: small, crimson, with a square marker */
.label {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-bottom: var(--s3);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  line-height: 1.3;
  text-transform: uppercase;
}

.label::before {
  content: "";
  flex: none;
  width: 0.4375rem;
  height: 0.4375rem;
  background: currentColor;
}

/* Mono caption for field names */
.caption,
.contact strong,
.project-meta strong,
.project-desc strong {
  display: block;
  margin-bottom: var(--s1);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ==========================================================
   About
   ========================================================== */

.about-head {
  display: grid;
  gap: var(--s5);
  padding-bottom: var(--s5);
  border-bottom: 1px solid var(--ink);
}

.profile-photo {
  width: 7.5rem;
  height: auto;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  object-position: center top;
  border-radius: var(--r1);
  background: var(--rule);
  box-shadow: 0.375rem 0.375rem 0 var(--accent);
}

.identity h1 { margin-bottom: var(--s4); }

.identity .role {
  max-width: 34ch;
  font-size: var(--text-md);
  line-height: 1.35;
}

.identity .role strong { font-weight: 600; }

.identity .org { margin-top: var(--s2); }
.identity .org strong { font-weight: 500; color: var(--accent); }
.identity .city strong { font-weight: 400; color: var(--ink-3); }

.contact {
  display: grid;
  gap: var(--s3);
  align-content: end;
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--ink-2);
}

.contact p { max-width: 44ch; }

.social-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s5);
  padding-top: var(--s2);
}

.social-links a {
  font-weight: 500;
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.about-body {
  display: grid;
  gap: var(--s6);
  padding-top: var(--s5);
}

.about-foot { padding-top: var(--s5); }

.about-foot .social-links {
  padding-top: var(--s3);
  border-top: 1px solid var(--rule);
  font-size: var(--text-sm);
}

.about-body p {
  max-width: 62ch;
  color: var(--ink-2);
}

.contributions {
  padding: 0;
  list-style: none;
}

.contributions li {
  padding: var(--s2) 0;
  border-top: 1px solid var(--rule);
  color: var(--ink-2);
  font-size: var(--text-sm);
  line-height: 1.45;
}

.contributions li:first-child { padding-top: 0; border-top: 0; }

.contributions strong {
  display: block;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--ink);
}

.interests .caption { margin-bottom: var(--s2); }

.areas {
  margin-bottom: var(--s4);
  padding: 0;
  list-style: none;
}

.areas li {
  font-family: var(--font-display);
  font-size: var(--text-md);
  line-height: 1.35;
  color: var(--ink);
}

.applications {
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
  line-height: 1.4;
}

.applications li {
  position: relative;
  padding: 0.2rem 0 0.2rem var(--s4);
  color: var(--ink-2);
}

.applications li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 0.375rem;
  height: 0.375rem;
  background: var(--accent);
}

/* ==========================================================
   Publications
   ========================================================== */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s2);
}

.tab {
  display: inline-flex;
  align-items: baseline;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  border: 0;
  border-radius: var(--r1);
  background: none;
  color: var(--ink-3);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.tab:hover { color: var(--ink); background: var(--accent-wash); }

.tab[aria-selected="true"],
.tab[aria-selected="true"]:hover {
  color: var(--on-accent);
  background: var(--accent);
}

.tab[aria-selected="true"] .tab-count { color: var(--on-accent-dim); }

.tab-count {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--accent);
}

.pub-panel + .pub-panel { margin-top: var(--s6); }
.is-tabbed .pub-panel { margin-top: 0; }
.pub-panel:focus-visible { outline-offset: -2px; }

/* Page controls for long publication lists (large screens only) */
.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s3);
  padding-top: var(--s3);
  border-top: 1px solid var(--rule);
}

.pager[hidden] { display: none; }

.pager-status {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--ink-3);
  min-width: 4.5rem;
  text-align: center;
}

.pager button {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s4);
  border: 1px solid var(--accent);
  border-radius: var(--r1);
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.pager button:hover:not(:disabled) { background: var(--accent); color: var(--on-accent); }

.pager button:disabled {
  border-color: var(--rule);
  color: var(--ink-3);
  cursor: default;
}

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

.pub-list {
  padding: 0;
  list-style: none;
  counter-reset: pub;
  font-size: var(--text-sm);
  line-height: 1.5;
}

.pub-list li {
  position: relative;
  counter-increment: pub;
  padding: 0 0 var(--s4) 2.25rem;
  color: var(--ink-2);
  overflow-wrap: anywhere;
  break-inside: avoid;
}

.pub-list li::before {
  content: counter(pub, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.15em;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--accent);
}

/* The author's own name, marked in every entry */
.pub-list b {
  font-weight: 600;
  color: var(--ink);
  background: linear-gradient(transparent 62%, var(--accent-wash) 62%);
}


@media (min-width: 40rem) {
  .pub-list {
    columns: 21rem auto;
    column-gap: var(--s7);
    column-rule: 1px solid var(--rule);
  }
}

/* ==========================================================
   Projects
   ========================================================== */

.project-list { padding: 0; list-style: none; counter-reset: project; }

.project-item {
  counter-increment: project;
  display: grid;
  gap: var(--s5);
}

.is-paged .project-item[hidden] { display: none; }

.project-lead::before {
  content: counter(project, decimal-leading-zero);
  display: block;
  margin-bottom: var(--s3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--accent);
}

/* When the deck is paged, the number comes from the item's real
   position rather than from the count of rendered items. */
.is-paged .project-lead::before { content: attr(data-index); }

.project-deck .pager { margin-top: var(--s5); }

.project-item h2 {
  max-width: 18ch;
  margin-bottom: var(--s5);
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.project-meta {
  display: grid;
  gap: var(--s4);
  padding-left: var(--s4);
  border-left: 2px solid var(--accent);
}

.project-meta p { font-size: var(--text-sm); }

.project-desc {
  color: var(--ink-2);
  font-size: var(--text-md);
  line-height: 1.6;
  white-space: pre-line;
}

.project-desc strong { margin-bottom: var(--s2); }

/* ==========================================================
   Team
   ========================================================== */

.team-body {
  display: grid;
  gap: var(--s6);
}

.member-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: var(--s5) var(--s4);
  padding: 0;
  list-style: none;
  counter-reset: member;
}

.member {
  counter-increment: member;
  max-width: 13rem;
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr);
  align-content: start;
}

.member-photo { grid-column: 1 / -1; }

/* Photo frame. Each member's photo is named after them in team/
   (e.g. team/ragesh-m.jpg); until the file is added, the frame
   simply shows as an empty grey panel. */
.member-photo {
  width: 100%;
  aspect-ratio: 4 / 5;
  border-radius: var(--r1);
  background-color: var(--rule);
  background-position: center top;
  background-size: cover;
  background-repeat: no-repeat;
}

.member-name {
  grid-column: 2;
  margin-top: var(--s2);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.35;
  color: var(--ink);
}

.member-role {
  grid-column: 2;
  margin-top: var(--s1);
  font-size: var(--text-xs);
  line-height: 1.4;
  color: var(--ink-2);
}

.member-name::before {
  content: counter(member, decimal-leading-zero);
  position: absolute;
  margin-left: -1.5rem;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 400;
  line-height: 1.75;
  color: var(--accent);
}

/* ==========================================================
   Opportunities
   ========================================================== */

.opps-list { counter-reset: opp; }

.opp {
  counter-increment: opp;
  display: grid;
  gap: var(--s3);
  padding: var(--s5) 0;
  border-top: 1px solid var(--rule);
}

.opp:first-child { border-top: 0; padding-top: 0; }

.opp h2 {
  display: flex;
  gap: var(--s4);
  align-items: baseline;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 500;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.opp h2::before {
  content: counter(opp, decimal-leading-zero);
  flex: none;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0;
  color: var(--accent);
}

.opp p {
  max-width: 58ch;
  color: var(--ink-2);
  font-size: var(--text-md);
  line-height: 1.55;
}

/* ==========================================================
   Medium screens: wider layouts, still scrolling
   ========================================================== */

@media (min-width: 48rem) {
  :root { --pad-x: 2.5rem; --pad-y: 2.5rem; }

  .about-head { grid-template-columns: auto minmax(0, 1fr); align-items: end; }
  .contact { grid-column: 1 / -1; grid-template-columns: repeat(3, auto); justify-content: start; gap: var(--s6); }
  .about-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "about contrib"
      "edu contrib"
      "interests interests";
  }
  .b-about { grid-area: about; }
  .b-contrib { grid-area: contrib; }
  .b-edu { grid-area: edu; }
  .interests { grid-area: interests; }

  .project-item { grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); gap: var(--s7); }

  .opp { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); gap: var(--s6); }

  .member-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s5); }
}

/* ==========================================================
   Large screens: full window, no page scroll
   ========================================================== */

@media (min-width: 64rem) and (min-height: 40rem) {
  html { font-size: clamp(12px, 0.5vw + 0.85vh, 17.5px); }

  :root { --pad-x: 3.5vw; --pad-y: 4.5vh; --rail: clamp(11rem, 15vw, 17rem); }

  body { height: 100dvh; overflow: hidden; }

  .frame {
    display: grid;
    grid-template-columns: var(--rail) minmax(0, 1fr);
    height: 100dvh;
    min-height: 0;
  }

  .rail {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: var(--pad-y) 0;
  }


  .nav {
    flex-direction: column;
    gap: 0;
    padding: 0;
  }

  .nav a {
    gap: var(--s4);
    padding: var(--s3) var(--s6);
    font-size: var(--text-base);
    border-bottom: 0;
    border-left: 3px solid transparent;
  }

  .nav a[aria-current="page"] {
    border-left-color: var(--on-accent);
    background: var(--accent-deep);
  }

  .stage {
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: var(--pad-y) var(--pad-x);
    overflow: auto;
  }

  /* About: head band, then three unequal columns */
  .about-head {
    grid-template-columns: auto minmax(0, 1fr) minmax(16rem, 0.9fr);
    gap: var(--s6);
  }

  .profile-photo { width: clamp(6.5rem, 17vh, 10rem); }

  .contact { grid-column: auto; grid-template-columns: 1fr; gap: var(--s3); }

  .about-body {
    flex: 1;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.2fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "about contrib interests"
      "edu contrib interests";
    gap: 0;
    min-height: 0;
  }

  .b-about, .b-edu { padding-right: var(--s6); }
  .b-edu { padding-top: var(--s5); }
  .b-contrib, .interests { padding: 0 var(--s6); border-left: 1px solid var(--rule); }
  .interests { padding-right: 0; }

  .about-foot { padding-top: var(--s3); }
  .about-foot .social-links { justify-content: flex-end; }

  /* Publications: one panel at a time, list fills the width */
  .pubs .stage-head { margin-bottom: var(--s5); }

  /* Each tab fills the remaining height. Entries flow into columns;
     columns that do not fit move to the next page (see .pager). */
  .pub-panels { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .pub-panel:not([hidden]) {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
  }
  .pub-list {
    height: 100%;
    font-size: var(--text-base);
    line-height: 1.55;
    columns: 18rem auto;
    column-gap: var(--s7);
    column-fill: auto;
    transition: transform 0.3s ease;
  }
  .pub-list li { padding-bottom: var(--s4); padding-left: 2.25rem; }

  /* Projects: one project fills the stage; Previous / Next moves through them */
  .project-deck {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .project-deck .pager { margin-top: 0; }
  .project-list { min-height: 0; display: flex; align-items: center; overflow: auto; }
  .project-item {
    flex: 1;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr);
    align-items: start;
    gap: var(--s8);
    padding-bottom: var(--s7);
  }
  .project-item h2 { font-size: calc(var(--text-xl) * 1.35); }
  .project-desc { font-size: calc(var(--text-md) * 1.08); max-width: 60ch; }

  /* Team: the two groups sit side by side, sized by how many people are in them */
  .team-body {
    flex: 1;
    min-height: 0;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    gap: var(--s7);
    align-content: start;
  }

  .team-group + .team-group { padding-left: var(--s7); border-left: 1px solid var(--rule); }

  .member-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s6) var(--s5);
  }

  /* Six associates read best as three across, two down */
  .team-group:last-child .member-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .member { max-width: 12rem; }

  /* Opportunities: three bands share the height */
  .opps-list {
    flex: 1;
    display: grid;
    grid-template-rows: repeat(3, 1fr);
  }
  .opp { align-content: center; padding: var(--s5) 0; }
  .opp:first-child { padding-top: var(--s5); }
  .opp h2 { font-size: var(--text-xl); }
}


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

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

/* ---------- Print ---------- */

@media print {
  body { height: auto; overflow: visible; background: #fff; font-size: 11pt; }
  .frame { display: block; height: auto; }
  .rail { display: none; }
  .stage { overflow: visible; padding: 0; }
  .tabs { display: none; }
  .pub-panel[hidden] { display: block; }
  .pub-panel .label.sr-only { position: static; width: auto; height: auto; margin: 0 0 0.5rem; clip-path: none; }
  a { color: inherit; text-decoration: none; }
  .pub-list b { background: none; }
}
