/* Mohamed Eldagla — personal site
   No build step. One stylesheet. System fonts only, monochrome.
   Every foreground/background pair here was checked against WCAG AA. */

/* Theme. Light is the base. Dark is applied either because the system asks for
   it and the visitor has not overridden it, or because they explicitly chose
   it — so the dark tokens are declared twice, once per route. Never define a
   color only inside a media query, or the toggle cannot win in both
   directions. */

:root {
  --bg:          #FFFFFF;
  --fg:          #111111;
  --muted:       #5F5F5F;
  --rule:        #E5E5E5;
  --rule-strong: #C4C4C4;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, sans-serif;

  --measure: 780px;
  --gutter: 1.5rem;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #121212;
    --fg:          #E8E8E8;
    --muted:       #9A9A9A;
    --rule:        #2A2A2A;
    --rule-strong: #4A4A4A;

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg:          #121212;
  --fg:          #E8E8E8;
  --muted:       #9A9A9A;
  --rule:        #2A2A2A;
  --rule-strong: #4A4A4A;

  color-scheme: dark;
}

/* ---------- base ---------- */

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}

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

h1, h2, h3 {
  font-family: var(--sans);
  line-height: 1.25;
  margin: 0;
}

/* Links carry no color of their own — the underline does the work. */
a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

a:hover { text-decoration-color: currentColor; }

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

p { margin: 0 0 1rem; }

.sep {
  color: var(--rule-strong);
  padding-inline: 0.4em;
}

.dates { color: var(--muted); }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--bg);
  color: var(--fg);
  padding: 0.75rem 1rem;
  z-index: 10;
}
.skip-link:focus {
  left: 0;
  outline: 2px solid var(--fg);
}

/* ---------- top nav ---------- */

.sectionnav { padding-block: 1.4rem 0; }

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

/* Theme switch. The padding is not decorative — it carries the control past
   the 24px WCAG 2.2 minimum tap target, which the 22px track alone would miss. */
.theme-switch {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  background: none;
  border: 0;
  padding: 0.4rem 0;
  margin-block-end: 0.9rem;
  cursor: pointer;
}

.theme-switch-track {
  position: relative;
  display: block;
  width: 38px;
  height: 22px;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  transition: border-color 0.15s ease;
}

.theme-switch-knob {
  position: absolute;
  top: 50%;
  left: 3px;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.theme-switch[aria-checked="true"] .theme-switch-knob {
  transform: translateX(16px);
}

.theme-switch:hover .theme-switch-track { border-color: var(--fg); }
.theme-switch:hover .theme-switch-knob { background: var(--fg); }

.theme-switch:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
  border-radius: 999px;
}

@media (prefers-reduced-motion: reduce) {
  .theme-switch-track,
  .theme-switch-knob { transition: none; }
}

.sectionnav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.25rem;
  margin: 0;
  padding: 0;
  font-size: 0.875rem;
}

/* inline-block + vertical padding keeps the tap target at/above the 24px
   WCAG 2.2 minimum without changing how the row looks */
.sectionnav a {
  display: inline-block;
  padding-block: 0.3rem;
  color: var(--muted);
  text-decoration: none;
}
.sectionnav a:hover {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sectionnav a[aria-current] {
  color: var(--fg);
  font-weight: 600;
}

/* ---------- masthead ---------- */

/* Home intro: the portrait floats so the opening prose wraps beside it. */
.intro { padding-block: 1.25rem 0; }

.intro::after {
  content: "";
  display: table;
  clear: both;
}

.portrait {
  float: right;
  width: 160px;
  height: auto;
  margin: 0.4rem 0 1rem 1.75rem;
}

/* Subpage headers: title plus a one-line orientation note. */
.pagehead { padding-block: 1.25rem 0.25rem; }

h1 {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}

/* The 2.4rem h1 above is sized for the homepage, where the heading is a
   person's name and carries the page on its own. Every interior heading is a
   section label instead ("Publications", "Teaching"), which reads as oversized
   at that size — so .pagehead, which only interior pages use, takes it down. */
.pagehead h1 { font-size: 1.75rem; }

.position {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.email {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 0.9rem;
}

.lead {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 0.9rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.linkrow {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.25rem;
  margin: 1.25rem 0 0;
  padding: 1rem 0 0;
  border-block-start: 1px solid var(--rule);
  font-size: 0.95rem;
}

/* Keep the contact links a comfortable tap target (WCAG 2.2 target-size). */
.linkrow a {
  display: inline-block;
  padding-block: 0.15rem;
}

/* ---------- sections ---------- */

main { padding-block: 1.5rem 0.5rem; }

section { margin-block-end: 2.1rem; }

h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

/* ---------- publications ---------- */

.pub-list, .entry-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* The role / faculty / institution line under a taught course. Muted and set
   just under the title, so the head line stays the thing you scan. */
.course-affil {
  font-size: 0.92rem;
  color: var(--muted);
  margin-block: 0.1rem 0.25rem;
}

/* Labelled links sit on their own row. These are the one place on the site that
   carries color: everything else is monochrome, so the blue marks them as the
   things to click rather than more prose. Both values are contrast-checked
   against their own background — 6.44:1 on white, 9.02:1 on the dark bg — so
   the color is decoration on top of an underline, never the only signal. */
:root { --link: #0A58CA; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --link: #79B8FF; }
}
:root[data-theme="dark"] { --link: #79B8FF; }

.entry-links {
  font-size: 0.85rem;
  margin-block: 0.15rem 0.35rem;
}

/* No underline at rest. This row holds nothing but links, so color alone
   identifies them without the ambiguity WCAG warns about for links sitting
   inside prose — there is no surrounding body text here to be mistaken for.
   The underline returns on hover and focus, so the affordance is still there
   the moment you go looking for it. */
.entry-links a {
  color: var(--link);
  text-decoration: none;
}

/* Nudged down and set smaller so the arrow reads as a marker beside the label
   rather than part of the word. */
.entry-links .ext {
  font-size: 0.8em;
  margin-inline-start: 0.25em;
  vertical-align: 0.05em;
}

.entry-links a:hover,
.entry-links a:focus-visible {
  text-decoration: underline;
  text-decoration-color: currentColor;
}

/* ---------- category filter ----------
   Built by render.js from the categories present in the data. The pressed
   state is carried by aria-pressed, so the style is driven by the same
   attribute a screen reader reads — they cannot drift apart. */

.pub-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-block-end: 1.75rem;
}

.pub-filter-btn {
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.2;
  /* Vertical padding carries the control past the 24px WCAG 2.2 minimum tap
     target, which the text alone would miss. */
  padding: 0.4rem 0.75rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  cursor: pointer;
}

.pub-filter-btn:hover { color: var(--fg); border-color: var(--fg); }

.pub-filter-btn[aria-pressed="true"] {
  color: var(--bg);
  background: var(--fg);
  border-color: var(--fg);
  font-weight: 600;
}

/* Each category is its own section with its own heading; the last one must
   not add trailing space above the footer. A hidden group is filtered out, and
   must not leave its margin behind. */
.pub-group[hidden] { display: none; }
.pub-group:last-child { margin-block-end: 0; }

.pub { margin-block-end: 1.35rem; }
.pub:last-child { margin-block-end: 0; }

/* The thumbnail column exists only when an entry actually has a thumbnail,
   so a list without images has no dead gutter. */
.pub-list.has-thumbs .pub {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* Pin the columns so an entry with no thumbnail still puts its text in column
   two — leaving the image column empty, rather than flowing into it. */
.pub-list.has-thumbs .pub-thumb-cell { grid-column: 1; }
.pub-list.has-thumbs .pub-body { grid-column: 2; }

/* Teaching entries take the same optional column. It appears only once at
   least one entry has an image, so the list reads correctly while they are
   still being added — and an entry without one leaves the column empty rather
   than showing a placeholder graphic. */
.entry-list.has-thumbs .entry {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.entry-list.has-thumbs .pub-thumb-cell { grid-column: 1; }
.entry-list.has-thumbs .entry-body { grid-column: 2; }

/* Thumbnails are pre-rendered as uniform 2:1 boxes, so rows align and the
   space is reserved before the image arrives. */
.pub-thumb {
  width: 160px;
  height: auto;
  aspect-ratio: 2 / 1;
  display: block;
  border: 1px solid var(--rule);
  border-radius: 2px;
}

.pub-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.pub-authors {
  font-size: 0.95rem;
  margin-bottom: 0.15rem;
}

.pub-authors strong { font-weight: 700; }
.pub-authors sup { font-size: 0.7em; line-height: 0; }
.equal-note { color: var(--muted); font-size: 0.88rem; }

.pub-highlight {
  font-size: 0.92rem;
  margin-block: 0 0.3rem;
}

.pub-meta {
  font-size: 0.92rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

.acceptance-head {
  display: block;
  color: var(--fg);
  font-weight: 600;
}

.acceptance-head strong { font-weight: 700; }
.acceptance-workshop { display: block; }
.acceptance-workshop a { text-decoration-color: currentColor; }

.pub-summary {
  font-size: 0.95rem;
  color: var(--muted);
  margin-block: 0.3rem 0;
}


/* ---------- publication status ----------
   Unpublished statuses are italic and explicitly worded, so "Manuscript in
   preparation" cannot be skimmed as a venue. */

.status.is-published { font-style: normal; }

.status.is-preparation,
.status.is-submission {
  font-style: italic;
}

/* ---------- generic entries ---------- */

.entry { margin-block-end: 1.15rem; }
.entry:last-child { margin-block-end: 0; }

/* Title left, dates pinned right on the first baseline. A long title wraps
   inside its own box rather than pushing the dates onto a line of their own,
   which would break the date column. */
.entry-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0 1rem;
}

.entry-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1rem;
  font-weight: 600;
}

.entry-dates {
  flex: 0 0 auto;
  font-size: 0.9rem;
  color: var(--muted);
  white-space: nowrap;
}

.entry-meta {
  font-size: 0.92rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.entry-desc {
  font-size: 0.95rem;
  margin: 0.1rem 0 0;
}

/* Course descriptions sit below the affiliation line in the hierarchy, so they
   are set smaller than it. Scoped to .entry-body, which only taught courses
   use — the research, honors, and education lists keep the larger size. */
.entry-body .entry-desc { font-size: 0.88rem; }

.selectivity { color: var(--muted); }

/* ---------- dated lists (CV, awards, talks) ----------
   Date in a narrow left column, entry on the right. Year-grouped lists show
   the year once per group, with a hairline between groups. */

.dated {
  display: grid;
  grid-template-columns: 4rem minmax(0, 1fr);
  column-gap: 1.5rem;
  margin-block-end: 0.9rem;
}
.dated:last-child { margin-block-end: 0; }

.dated.group-start:not(:first-child) {
  border-block-start: 1px solid var(--rule);
  padding-block-start: 1rem;
  margin-block-start: 1.1rem;
}

/* CV rows carry month ranges, so their column is wider, and every row starts
   a group of one — separate them with space rather than rules. */
#research-list .dated, #experience-list .dated,
#education-list .dated, #service-list .dated {
  grid-template-columns: 7.5rem minmax(0, 1fr);
  border: 0;
  padding: 0;
  margin-block: 0 1.35rem;
}
#research-list .dated:last-child, #experience-list .dated:last-child,
#education-list .dated:last-child, #service-list .dated:last-child { margin-block-end: 0; }

.date-col {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding-block-start: 0.1rem;
}

.dated .entry-title a {
  color: inherit;
  text-decoration: none;
}
.dated .entry-title a:hover,
.dated .entry-title a:focus-visible {
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
}
.dated .entry-title .ext,
.inline-links .ext {
  font-size: 0.75em;
  margin-inline-start: 0.2em;
  color: var(--muted);
  vertical-align: 0.1em;
}

.entry-sub {
  font-size: 0.92rem;
  color: var(--muted);
  margin: 0.1rem 0 0.25rem;
}

.entry-bullets {
  margin: 0.2rem 0 0;
  padding-inline-start: 1.1rem;
  font-size: 0.95rem;
}
.entry-bullets li { margin-block-end: 0.15rem; }
.entry-bullets li::marker { color: var(--muted); }

.entry-project { margin-block-start: 0.6rem; }
.entry-project-title {
  margin: 0;
  font-size: 0.95rem;
  font-style: italic;
  font-weight: 500;
}

.muted { color: var(--muted); }

.inline-links { font-size: 0.88rem; }
.inline-links a { color: var(--link); text-decoration: none; }
.inline-links a:hover,
.inline-links a:focus-visible { text-decoration: underline; }
.inline-links .ext { color: inherit; }

@media (max-width: 640px) {
  .dated,
  #research-list .dated, #experience-list .dated,
  #education-list .dated, #service-list .dated { grid-template-columns: minmax(0, 1fr); }
  .date-col:empty { display: none; }
  .date-col { padding: 0 0 0.1rem; }
}

.load-error {
  font-size: 0.95rem;
  color: var(--muted);
}

/* ---------- layout-shift reservation ----------
   The lists are filled from JSON after first paint, so without this the page
   paints empty and then jumps as content lands. These hold roughly the space
   the current data occupies, and apply ONLY while the list is still empty —
   the moment items are inserted, :empty stops matching and the reservation
   disappears. Wrong numbers cost a small jump, never a broken layout, so
   they are safe to leave stale. Re-measure if the data changes a lot. */

#research-list:empty   { min-height: 567px; }
#teaching-list:empty   { min-height: 1008px; }
#experience-list:empty { min-height: 177px; }
#education-list:empty  { min-height: 202px; }
#honors-list:empty     { min-height: 701px; }
#pub-list:empty        { min-height: 1344px; }

@media (max-width: 640px) {
  /* Narrow screens wrap far more, so they need their own (taller) numbers.
     Measured at 412px, the viewport Lighthouse audits by default. */
  #research-list:empty   { min-height: 913px; }
  #teaching-list:empty   { min-height: 2463px; }
  #experience-list:empty { min-height: 313px; }
  #education-list:empty  { min-height: 358px; }
  #honors-list:empty     { min-height: 1036px; }
  #pub-list:empty        { min-height: 2638px; }
}

/* ---------- footer ---------- */

footer {
  border-block-start: 1px solid var(--rule);
  padding-block: 1.25rem 2rem;
  font-size: 0.92rem;
  color: var(--muted);
}

footer p { margin: 0; }

/* ---------- narrow screens ---------- */

@media (max-width: 640px) {
  .sectionnav { padding-block: 1.25rem 0; }
  .intro, .pagehead { padding-block: 1rem 0.25rem; }

  .portrait {
    float: none;
    width: 124px;
    margin: 0 0 1.1rem;
  }

  h1 { font-size: 2rem; }
  h2 { font-size: 1.25rem; }

  /* Too narrow to hold a date column — let dates sit under the title. */
  .entry-head { display: block; }
  .entry-dates { display: block; }

  .pub-list.has-thumbs .pub,
  .entry-list.has-thumbs .entry { grid-template-columns: 1fr; }
  .pub-list.has-thumbs .pub-thumb-cell,
  .pub-list.has-thumbs .pub-body,
  .entry-list.has-thumbs .pub-thumb-cell,
  .entry-list.has-thumbs .entry-body { grid-column: 1; }
  .pub-thumb { width: 100%; max-width: 240px; }

  .linkrow, .sectionnav ul { gap: 0 1rem; }
}

/* ---------- print: the page should come out as a clean CV ---------- */

@media print {
  :root {
    --bg: #fff;
    --fg: #000;
    --muted: #333;
    --rule: #bbb;
    --rule-strong: #888;
    --measure: 100%;
  }

  body { font-size: 10.5pt; line-height: 1.4; }

  .skip-link,
  .sectionnav,
  .pub-filter,
  .portrait,
  footer { display: none; }   /* footer only repeats the contact row above */

  /* Print every category regardless of the on-screen filter. The filter is a
     browsing aid, not an editorial choice, and a printed publication list that
     silently omits papers is a worse surprise than one that shows them all. */
  .pub-group[hidden] { display: block !important; }

  .intro, .pagehead { padding-block: 0 0.5rem; }
  main { padding-block: 0.5rem 0; }
  section { margin-block-end: 1.25rem; }

  h1 { font-size: 19pt; }
  h2 { font-size: 12pt; margin-bottom: 0.5rem; }
  .pub-title, .entry-title { font-size: 10.5pt; }

  a { text-decoration: none; }

  /* Show URLs for the contact row only — expanding every link would bloat the page. */
  .linkrow a::after {
    content: " (" attr(href) ")";
    font-size: 8.5pt;
    color: #444;
    word-break: break-all;
  }
  .linkrow a[href^="mailto:"]::after { content: ""; }

  /* Individual entries must not split across pages; whole sections may flow,
     otherwise a long section leaves most of a page blank. */
  .pub, .entry { break-inside: avoid; }
  h2, h3 { break-after: avoid; }
}

/* ---------- teaching groups ---------- */

.teach-group + .teach-group { margin-block-start: 2.25rem; }
.teach-group-h { font-size: 1.2rem; margin: 0; }
.teach-group-role { margin-block: 0.15rem 1rem; }
.teach-group-h + .entry-list { margin-block-start: 1rem; }
