/* ==========================================================================
   Soham Ghosh — personal academic site
   Layout: a slim top bar (name, tabs, CV link, theme toggle) over a two-column
   page: a narrow contact rail on the left, a reading column on the right.
   The columns stack on phones. Light and dark themes share one token set;
   the dark values apply with the system setting or the toggle in the top bar.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Color */
  --bg: #ffffff;
  --bg-rail: #f6f7f9;
  --fg: #1d2129;
  --fg-muted: #5b6472;
  --rule: #dfe3e8;
  --rule-strong: #c8ced6;
  --accent: #1f4e8c;
  --accent-ink: #163a69;
  --on-accent: #ffffff;
  --tag-bg: #eef3fa;

  /* Type */
  --font-serif: "Crimson Pro", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-sans: "Source Sans 3", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;

  /* Layout */
  --wrap: 1040px;
  --gutter: clamp(16px, 4vw, 40px);
  --rail: 232px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14171b;
    --bg-rail: #191d22;
    --fg: #e3e6ea;
    --fg-muted: #9aa3ae;
    --rule: #2a3038;
    --rule-strong: #3b434d;
    --accent: #8fb6ea;
    --accent-ink: #b4ccf2;
    --on-accent: #10141a;
    --tag-bg: #1c2634;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14171b;
  --bg-rail: #191d22;
  --fg: #e3e6ea;
  --fg-muted: #9aa3ae;
  --rule: #2a3038;
  --rule-strong: #3b434d;
  --accent: #8fb6ea;
  --accent-ink: #b4ccf2;
  --on-accent: #10141a;
  --tag-bg: #1c2634;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-serif);
  font-size: 1.15rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 0.14em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

.wrap {
  max-width: var(--wrap);
  margin: 0 auto;
  padding-inline: var(--gutter);
}

.skip-link {
  position: absolute; left: 0; top: -100px;
  padding: .5rem .75rem; background: var(--accent); color: var(--on-accent);
  font-family: var(--font-sans); z-index: 10;
}
.skip-link:focus { top: 0; }

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  font-family: var(--font-sans);
}
.site-header .wrap {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  column-gap: 1.5rem; row-gap: .25rem;
  min-height: 3.5rem;
  padding-block: .5rem;
}
.brand {
  font-family: var(--font-serif);
  font-size: 1.35rem; font-weight: 600; letter-spacing: .01em;
  color: var(--fg);
}
.brand:hover { color: var(--fg); text-decoration: none; }

.site-nav { display: flex; flex-wrap: wrap; gap: .25rem 1.4rem; margin: 0; padding: 0; list-style: none; }
.site-nav a {
  display: inline-block; padding: .35rem 0;
  color: var(--fg-muted); font-size: .98rem; font-weight: 500; letter-spacing: .01em;
  border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--fg); text-decoration: none; }
.site-nav a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); }

/* Theme toggle: shows a moon in light mode, a sun in dark mode. */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.1rem; height: 2.1rem; padding: 0;
  border: 1px solid var(--rule); border-radius: 999px;
  background: transparent; color: var(--fg-muted);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--fg); border-color: var(--rule-strong); }
.theme-toggle svg {
  width: 1.05rem; height: 1.05rem;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.theme-toggle .icon-sun { 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; }
}
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* --------------------------------------------------------------------------
   Page grid
   -------------------------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: 3rem;
  padding-block: 2.5rem 3rem;
}

/* Contact rail -------------------------------------------------------------- */
.rail {
  font-family: var(--font-sans);
  font-size: .95rem;
  line-height: 1.45;
  color: var(--fg-muted);
  align-self: start;
  position: sticky;
  top: 1.5rem;
}
.portrait-wrap { margin-bottom: 1.1rem; }
.portrait {
  width: 100%; max-width: 200px;
  aspect-ratio: 4 / 5; object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--rule);
}
.rail .name {
  font-family: var(--font-serif);
  font-size: 1.55rem; font-weight: 600; line-height: 1.15;
  color: var(--fg);
  margin: 0 0 .3rem;
}
.rail .role { margin: 0 0 1.1rem; }
.rail .role span { display: block; }

.contact { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.contact li { display: grid; grid-template-columns: 1.1rem 1fr; gap: .55rem; align-items: start; }
.contact svg { width: 1rem; height: 1rem; margin-top: .22rem; stroke: var(--fg-muted); fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.contact .label { display: block; font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--fg-muted); }
.contact .value { color: var(--fg); }
.contact .value a { color: var(--accent); }

/* Reading column ------------------------------------------------------------ */
.content { min-width: 0; }
.content > section + section { margin-top: 2.6rem; }

h1 {
  font-size: 2rem; font-weight: 600; line-height: 1.15;
  margin: 0 0 1rem;
  text-wrap: balance;
}
h2 {
  display: flex; align-items: center; gap: .85rem;
  margin: 0 0 1rem;
  font-family: var(--font-sans);
  font-size: .82rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
  color: var(--fg-muted);
}
h2::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
* + h2 { margin-top: 2.2rem; }
h3 {
  font-size: 1.2rem; font-weight: 600; line-height: 1.3;
  margin: 1.6rem 0 .5rem;
}
h3:first-of-type { margin-top: 0; }
h3 .muted { font-weight: 400; }

p { margin: 0 0 1rem; max-width: 68ch; }
p:last-child { margin-bottom: 0; }
.lede { font-size: 1.22rem; }
.muted { color: var(--fg-muted); }
.small { font-size: .95rem; }
.highlight { color: var(--accent); font-weight: 600; }
p.highlight { margin-top: -.35rem; }

ul.plain { list-style: none; margin: 0; padding: 0; }
ul.bullets { margin: 0; padding-left: 1.2rem; max-width: 70ch; }
ul.bullets li + li { margin-top: .4rem; }

/* Publications ---------------------------------------------------------------- */
.pubs { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.1rem; }
.pub { display: grid; grid-template-columns: 2rem minmax(0, 1fr); gap: .5rem; }
.pub-num {
  font-family: var(--font-sans); font-variant-numeric: tabular-nums;
  color: var(--fg-muted); font-size: .95rem; padding-top: .18rem;
}
.pub-title { font-weight: 600; font-size: 1.12rem; line-height: 1.35; display: block; }
.pub-meta { display: block; margin-top: .15rem; }
.pub-venue { font-style: italic; }
.pub-links {
  display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .5rem;
  margin-top: .4rem;
  font-family: var(--font-sans); font-size: .82rem;
}
.pub-links a {
  display: inline-block; padding: .1rem .5rem;
  border: 1px solid var(--rule); border-radius: 999px;
  background: var(--tag-bg); color: var(--accent-ink);
  letter-spacing: .01em;
}
.pub-links a:hover { text-decoration: none; border-color: var(--accent); }

/* Abstract disclosure: a pill in the links row; when open it takes the full
   width and the abstract appears beneath it. */
.abstract { min-width: 0; }
.abstract[open] { flex-basis: 100%; }
.abstract summary {
  list-style: none; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .1rem .55rem .1rem .5rem;
  border: 1px solid var(--rule); border-radius: 999px;
  color: var(--fg-muted); letter-spacing: .01em;
}
.abstract summary::-webkit-details-marker { display: none; }
.abstract summary::after {
  content: ""; width: .4em; height: .4em; margin-top: -.2em;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
}
.abstract[open] summary::after { transform: rotate(225deg); margin-top: .2em; }
.abstract summary:hover { color: var(--fg); border-color: var(--rule-strong); }
.abstract p {
  font-family: var(--font-serif); font-size: 1.02rem; line-height: 1.5;
  color: var(--fg);
  margin: .6rem 0 .2rem; padding: .05rem 0 .05rem .85rem;
  border-left: 2px solid var(--rule);
  max-width: 68ch;
}
/* MathJax's hidden assistive MathML is wider than the drawn formula; keep it
   inside its container so it cannot widen the page on narrow screens. */
mjx-assistive-mml { max-width: 100% !important; }

/* Compact lists (talks, conferences) ---------------------------------------- */
ul.compact { margin: 0; padding-left: 1.15rem; max-width: 72ch; }
ul.compact li { margin: 0 0 .3rem; }
ul.compact .note { color: var(--fg-muted); }
.content h2 + ul.compact { margin-top: -.25rem; }

/* Course table -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.courses {
  width: 100%; border-collapse: collapse;
  font-size: 1.05rem; line-height: 1.4;
}
table.courses th, table.courses td { text-align: left; vertical-align: top; padding: .5rem .75rem .5rem 0; border-top: 1px solid var(--rule); }
table.courses tr:last-child td { border-bottom: 1px solid var(--rule); }
table.courses th {
  font-family: var(--font-sans); font-size: .78rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--fg-muted); border-top: 0; padding-top: 0;
}
table.courses td.term { font-family: var(--font-sans); font-size: .92rem; color: var(--fg-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
table.courses td.code { white-space: nowrap; font-variant-numeric: tabular-nums; }
table.courses .sections { font-family: var(--font-sans); font-size: .82rem; color: var(--fg-muted); white-space: nowrap; }

/* Footer --------------------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans); font-size: .88rem; color: var(--fg-muted);
}
.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .35rem 1.5rem; padding-block: 1.25rem; }
.site-footer a { color: var(--fg-muted); }
.site-footer a:hover { color: var(--fg); }

/* --------------------------------------------------------------------------
   Narrow screens
   -------------------------------------------------------------------------- */
@media (max-width: 760px) {
  body { font-size: 1.08rem; }
  .site-header .wrap { grid-template-columns: 1fr auto; }
  .site-header .brand { grid-column: 1; grid-row: 1; }
  .site-header .theme-toggle { grid-column: 2; grid-row: 1; }
  .site-header nav { grid-column: 1 / -1; grid-row: 2; }
  .layout { grid-template-columns: 1fr; gap: 2rem; padding-block: 1.75rem 2.5rem; }
  .rail {
    position: static;
    display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .25rem 1.25rem; align-items: start;
  }
  .portrait-wrap { grid-row: 1 / span 3; margin: 0; }
  .portrait { width: 112px; aspect-ratio: 1 / 1; border-radius: 50%; }
  .rail .name { font-size: 1.4rem; }
  .rail .role { margin-bottom: .6rem; }
  .contact { grid-column: 1 / -1; margin-top: .75rem; padding-top: .9rem; border-top: 1px solid var(--rule); }
  .pub-title { font-size: 1.05rem; }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

@media print {
  .site-header, .site-footer, .skip-link { display: none; }
  .layout { grid-template-columns: 1fr; }
  .rail { position: static; }
  a { color: inherit; }
}
