/*
 * Tufte-style theme for Hamed Hatami's homepage.
 *
 * Modelled on etiennebacher.com (Calepin "academic" theme + Tufte overlay):
 * warm paper, Palatino, brick-red links, small-caps titles and navigation,
 * italic section headings, a 39rem reading column with a right-hand margin
 * column, flat surfaces, and a quiet middot-separated footer.
 */

/* ------------------------------------------------------------------ */
/* Tokens                                                              */
/* ------------------------------------------------------------------ */

:root {
  --font-body: Palatino, "Palatino Linotype", "Book Antiqua", "TeX Gyre Pagella",
    "URW Palladio L", P052, Georgia, serif;

  --bg: #fffff8;
  --text: #12110f;
  --muted: #5a5650;
  --border: #ded8c8;
  --surface: #fffdf0;
  --accent: #7a2e2a;
  --accent-hover: #5f2520;
  --topbar-bg: rgb(255 255 248 / 0.94);
  --venue: #2b6a3a;

  --content-width: 39rem;
  --margin-width: 16rem;
  --margin-gap: 2rem;
  --page-width: calc(var(--content-width) + var(--margin-gap) + var(--margin-width));

  color-scheme: light;
}

/* Dark: follow the system unless the reader picked a theme with the toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #18130d;
    --text: #f6efe8;
    --muted: #c5baa7;
    --border: #3b3227;
    --surface: #1f1a14;
    --accent: #d58a7f;
    --accent-hover: #f0b7ab;
    --topbar-bg: rgb(24 19 13 / 0.94);
    --venue: #9fcf98;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #18130d;
  --text: #f6efe8;
  --muted: #c5baa7;
  --border: #3b3227;
  --surface: #1f1a14;
  --accent: #d58a7f;
  --accent-hover: #f0b7ab;
  --topbar-bg: rgb(24 19 13 / 0.94);
  --venue: #9fcf98;
  color-scheme: dark;
}

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

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

html {
  font-size: 106.25%; /* 17px, as on the reference site */
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  font-variant-numeric: oldstyle-nums;
  text-rendering: optimizeLegibility;

  /* Keep the footer on the bottom edge of short pages. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

p,
li {
  line-height: 1.6;
}

p {
  margin: 0 0 1rem;
}

strong,
b {
  font-weight: 600;
}

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

a:hover,
a:focus-visible {
  color: var(--accent-hover);
  text-decoration-line: underline;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

blockquote {
  margin: 1.5rem 0;
  padding: 0;
  font-style: italic;
}

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

/* ------------------------------------------------------------------ */
/* Headings: small-caps page title, italic section headings            */
/* ------------------------------------------------------------------ */

h1,
h2,
h3,
h4 {
  color: var(--text);
  font-weight: 400;
  line-height: 1.25;
}

h1 {
  font-size: 2rem;
  font-variant: small-caps;
  letter-spacing: 0.02em;
  margin: 2rem 0 1.15rem;
}

h2 {
  font-size: 1.55rem;
  font-style: italic;
  margin: 2.8rem 0 1rem;
}

h3 {
  font-size: 1.25rem;
  font-style: italic;
  margin: 2rem 0 0.8rem;
}

/* Tufte's subtitle: an italic line directly under the title. */
p.subtitle {
  font-size: 1.2rem;
  font-style: italic;
  line-height: 1.45;
  color: var(--muted);
  margin: -0.4rem 0 1.8rem;
}

/* ------------------------------------------------------------------ */
/* Lists                                                               */
/* ------------------------------------------------------------------ */

ul,
ol {
  margin: 0 0 1rem;
  padding-left: 2.35rem;
}

ul {
  list-style-type: square;
}

li {
  margin-bottom: 0.25rem;
}

li > ul {
  margin: 0.4rem 0 0.4rem;
}

/* Publication lists: one paper per item, a little air between them. */
ul.pubs > li {
  margin-bottom: 1rem;
}

.pubs .venue {
  color: var(--venue);
  font-style: italic;
}

/* Expositions: the title is the link; the source sits on its own line below. */
ul.expositions {
  list-style: none;
  padding-left: 0;
  margin-top: 2rem;
}

ul.expositions > li {
  margin-bottom: 2rem;
}

.expo-title {
  font-size: 1.12rem;
  line-height: 1.4;
}

.expo-source {
  margin: 0.45rem 0 0;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--muted);
}

.pubs .award {
  color: var(--accent);
  font-style: italic;
}

/* ------------------------------------------------------------------ */
/* Top bar and navigation                                              */
/* ------------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--topbar-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
}

.nav {
  width: min(100% - 2rem, var(--page-width));
  margin-inline: auto;
  min-height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  gap: 1rem;
}

.brand,
.menu a {
  color: var(--text);
  font-variant: small-caps;
  font-weight: 400;
  letter-spacing: 0.03em;
  text-decoration: none;
}

.brand {
  font-size: 1.2rem;
  white-space: nowrap;
}

.menu {
  display: contents;
}

.menu a {
  font-size: 0.92rem;
  padding: 0.1rem 0;
  border-bottom: 1px solid transparent;
  white-space: nowrap;
}

.brand:hover,
.menu a:hover,
.menu a:focus-visible {
  color: var(--accent);
  text-decoration: none;
}

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

/* "Publications" dropdown (Selected / All). */
.dropdown {
  position: relative;
}

.dropdown summary {
  list-style: none;
  cursor: pointer;
  color: var(--text);
  font-size: 0.92rem;
  font-variant: small-caps;
  letter-spacing: 0.03em;
  padding: 0.1rem 0;
  border-bottom: 1px solid transparent;
  white-space: nowrap;
}

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

.dropdown summary::after {
  content: "";
  display: inline-block;
  width: 0.32em;
  height: 0.32em;
  margin-left: 0.4em;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: translateY(-0.25em) rotate(45deg);
  transition: transform 0.15s;
}

.dropdown[open] summary::after {
  transform: translateY(0.05em) rotate(-135deg);
}

.dropdown summary:hover,
.dropdown summary:focus-visible {
  color: var(--accent);
}

.dropdown summary.is-current {
  border-bottom-color: var(--accent);
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + 0.7rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  min-width: 8rem;
  display: flex;
  flex-direction: column;
  padding: 0.35rem 0;
  background: var(--bg);
  border: 1px solid var(--border);
}

.menu .dropdown-panel a {
  padding: 0.35rem 1.1rem;
  border-bottom: 0;
}

.menu .dropdown-panel a[aria-current="page"] {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover {
  color: var(--accent);
}

.icon-button svg {
  width: 1rem;
  height: 1rem;
}

.nav-toggle {
  display: none;
}

.nav-toggle span {
  display: block;
  width: 1rem;
  height: 1.5px;
  margin: 3.5px auto;
  background: currentColor;
}

/* Narrow screens: brand on the left, menu folds behind a toggle. */
@media (max-width: 54rem) {
  .nav {
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0;
  }

  .nav-toggle {
    display: inline-block;
    margin-left: auto;
  }

  .menu {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    align-items: flex-start;
    padding: 0.75rem 0 0.25rem;
  }

  .topbar.open .menu {
    display: flex;
  }

  .menu a {
    font-size: 1.05rem;
    padding: 0.35rem 0;
  }

  .menu .theme-toggle {
    margin-left: -0.6rem;
  }

  .dropdown summary {
    font-size: 1.05rem;
    padding: 0.35rem 0;
  }

  .dropdown-panel {
    position: static;
    transform: none;
    min-width: 0;
    padding: 0 0 0 1.1rem;
    border: 0;
    background: none;
  }

  .menu .dropdown-panel a {
    padding: 0.35rem 0;
  }
}

/* ------------------------------------------------------------------ */
/* Page shell, reading column, margin column                           */
/* ------------------------------------------------------------------ */

.page {
  flex: 1 0 auto;
  width: min(100% - 2rem, var(--content-width));
  margin-inline: auto;
  padding: 3.2rem 0 4rem;
}

/* Margin material (a portrait, a side note) sits to the right of the reading
   column. Pages that have some widen the shell to make room for it. */
.sidefigure,
.marginnote {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--muted);
}

.sidefigure {
  margin: 1.5rem 0;
}

.sidefigure img {
  display: block;
}

@media (min-width: 59.01rem) {
  .page:has(.sidefigure, .marginnote) {
    width: min(100% - 2rem, var(--page-width));
    padding-right: calc(var(--margin-width) + var(--margin-gap));
  }

  .sidefigure,
  .marginnote {
    float: right;
    clear: right;
    width: var(--margin-width);
    margin-right: calc(-1 * (var(--margin-width) + var(--margin-gap)));
  }

  .sidefigure {
    margin-top: 0.35rem;
  }
}

@media (max-width: 59rem) {
  .sidefigure img {
    max-width: min(100%, var(--margin-width));
    margin-inline: auto;
  }
}

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

.site-footer {
  width: min(100% - 2rem, var(--page-width));
  margin: 2.25rem auto 0;
  padding: 1.3rem 0 1rem;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.site-footer ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  row-gap: 0.25rem;
}

.site-footer li {
  margin: 0;
}

.site-footer li:not(:last-child)::after {
  content: "·";
  margin-inline: 0.5rem;
}

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

@media print {
  .topbar,
  .site-footer {
    display: none;
  }

  .page {
    width: auto;
    padding: 0;
  }
}
