/* sarahmathre.com: low-density, smooth transitions, light or dark
   depending on the visitor's system setting.
   Sticky sidebar keeps the headshot in view; content animates in.
   Self-contained: no external fonts or assets. */

:root {
  /* Tells the UA to render scrollbars, form controls and the canvas in
     whichever scheme is active, so nothing flashes white on a dark OS. */
  color-scheme: light dark;

  --bg: #ffffff;
  --ink: #1c1c1e;
  --ink-soft: #55555a;
  --ink-faint: #6e6e74; /* 5.07:1 on white, WCAG AA */
  --hairline: #e8e8ea;
  --accent: #2f4f6f;
  --accent-strong: #24405c; /* hover state for accent links and buttons */
  --on-accent: #ffffff;     /* text sitting on an --accent fill */
  --accent-pale: #eef3f7;
  --research-field: #f4f6f8;
  --card: rgba(255, 255, 255, 0.78);
  --card-plain: rgba(255, 255, 255, 0.68);
  --minibar: rgba(255, 255, 255, 0.9);
  --stat-top: #ffffff; /* stat gradient start, falls off to --accent-pale */
  /* Accent tints: card hairlines, hovers and touch feedback. */
  --tint-weak: rgba(47, 79, 111, 0.1);
  --tint-soft: rgba(47, 79, 111, 0.18);
  --tint-medium: rgba(47, 79, 111, 0.25);
  --tint-press: rgba(47, 79, 111, 0.12);
  --tint-chip: rgba(47, 79, 111, 0.07);
  --shadow-rest: 0 0.7rem 2rem rgba(28, 28, 30, 0.035);
  --shadow-lift: 0 1rem 2.5rem rgba(28, 28, 30, 0.07);
  --photo-filter: none;
  --serif: Georgia, "Times New Roman", Times, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Dark mode ----------
   Follows the OS/browser setting; there is no in-page toggle, so the only
   thing that changes below is the palette. Every rule elsewhere in this
   file reads from the tokens above. Contrast on the darkest surface:
   --ink 14.5:1, --ink-soft 8.8:1, --accent 8.5:1, and --ink-faint 5.3:1
   even over the palest section field (WCAG AA). */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --ink: #e6e8ec;
    --ink-soft: #b2b7bf;
    --ink-faint: #8d939c;
    --hairline: #2c323b;
    --accent: #93b7d8; /* the navy inverts to a light blue to stay legible */
    --accent-strong: #b3cde6;
    --on-accent: #12161b;
    --accent-pale: #1b1f26;
    --research-field: #181c22;
    --card: rgba(255, 255, 255, 0.035);
    --card-plain: rgba(255, 255, 255, 0.03);
    --minibar: rgba(21, 24, 28, 0.9);
    --stat-top: #22272f;
    /* Tints re-key to the light accent; shadows read as depth on dark
       only when they are near-black rather than ink-tinted. */
    --tint-weak: rgba(147, 183, 216, 0.14);
    --tint-soft: rgba(147, 183, 216, 0.22);
    --tint-medium: rgba(147, 183, 216, 0.38);
    --tint-press: rgba(147, 183, 216, 0.16);
    --tint-chip: rgba(147, 183, 216, 0.1);
    --shadow-rest: 0 0.7rem 2rem rgba(0, 0, 0, 0.35);
    --shadow-lift: 0 1rem 2.5rem rgba(0, 0, 0, 0.5);
    --photo-filter: brightness(0.9); /* keeps the headshot from glaring */
  }
}

html {
  scrollbar-gutter: stable;
  scroll-behavior: smooth;
}

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


body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ---------- Scroll progress ---------- */

.progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 3px;
  z-index: 60;
  pointer-events: none;
}

.progress__bar {
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- Layout: sticky sidebar + scrolling content ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(290px, 370px) minmax(0, 1fr);
  gap: clamp(3rem, 7vw, 6.5rem);
  max-width: 74rem;
  margin-inline: auto;
  padding-inline: clamp(1.25rem, 4vw, 3rem);
}

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  overflow-y: auto;
}

.side__inner {
  width: 100%;
  /* auto margins center the block but still allow internal scrolling
     on very short viewports (align-items: center would clip the top) */
  margin-block: auto;
  padding-block: 1.5rem;
}

.side__photo img {
  display: block;
  width: min(100%, 28vh);
  height: auto;
  margin-inline: auto;
  /* Rounded-rectangle vignette: an SVG mask (blurred rounded rect)
     feathers edges and corners uniformly, and the fade completes
     inside the bitmap so no straight border is ever visible. */
  -webkit-mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 600"><filter id="f" x="-25%25" y="-25%25" width="150%25" height="150%25"><feGaussianBlur stdDeviation="12"/></filter><rect x="42" y="42" width="396" height="516" rx="46" fill="white" filter="url(%23f)"/></svg>');
          mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 480 600"><filter id="f" x="-25%25" y="-25%25" width="150%25" height="150%25"><feGaussianBlur stdDeviation="12"/></filter><rect x="42" y="42" width="396" height="516" rx="46" fill="white" filter="url(%23f)"/></svg>');
  -webkit-mask-size: 100% 100%;
          mask-size: 100% 100%;
  filter: var(--photo-filter);
}

.side h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.9rem, 2.6vw, 2.4rem);
  line-height: 1.12;
  letter-spacing: 0.01em;
  margin: 1.2rem 0 0.3rem;
  text-align: center;
}

.credentials {
  display: block;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  color: var(--accent);
  margin-top: 0.55rem;
}

.side__tagline {
  color: var(--ink-soft);
  font-size: 0.98rem;
  text-align: center;
  margin: 0.35rem 0 1.4rem;
}

.side__nav {
  margin: 0 0 1.4rem;
}

.side__nav a {
  display: block;
  padding: 0.28rem 0 0.28rem 1rem;
  border-left: 2px solid var(--hairline);
  border-radius: 0 0.45rem 0.45rem 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
  transition: color 0.25s ease, border-color 0.25s ease,
              background-color 0.25s ease, padding-left 0.25s ease;
}

/* Hover only changes paint (colour, border, fill), never box size or
   weight, so the rest of the list stays exactly where it is. */
.side__nav a:hover {
  color: var(--accent);
  border-left-color: var(--accent);
  background-color: var(--tint-weak);
  text-decoration: none;
}

.side__nav a.is-active {
  color: var(--accent);
  border-left-color: var(--accent);
  padding-left: 1.35rem;
}

.side__actions {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.button {
  display: inline-block;
  padding: 0.65rem 1.4rem;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: center;
  transition: background-color 0.25s ease, color 0.25s ease,
              border-color 0.25s ease, transform 0.25s ease;
}

.button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  text-decoration: none;
  transform: translateY(-1px);
}

.button--ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--hairline);
}

.button--ghost:hover {
  background: transparent;
  color: var(--accent-strong);
  border-color: var(--accent);
}

/* Gentle entrance for the sidebar on load (motion-safe only). */
@media (prefers-reduced-motion: no-preference) {
  .side__photo {
    animation: fade-in-up 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .side h1,
  .side__tagline {
    animation: fade-in-up 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.15s both;
  }

  .side__nav,
  .side__actions {
    animation: fade-in-up 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.3s both;
  }

  @keyframes fade-in-up {
    from {
      opacity: 0;
      transform: translateY(16px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }
}

/* ---------- Mobile mini-header (appears after the hero scrolls away) ---------- */

.minibar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 1.25rem;
  background: var(--minibar);
  -webkit-backdrop-filter: blur(10px);
          backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transform: translateY(-100%);
  transition: transform 0.35s ease, background-color 0.25s ease;
}

.minibar:hover {
  text-decoration: none;
}

.minibar:active {
  background-color: var(--tint-press);
}

.minibar.is-shown {
  transform: translateY(0);
}

.minibar img {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  object-fit: cover;
  object-position: 50% 22%;
}

.minibar span {
  font-family: var(--serif);
  font-size: 1.05rem;
}

@media (min-width: 901px) {
  .minibar {
    display: none;
  }
}

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

main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-block: clamp(3rem, 12vh, 7rem) 2rem;
}

.cv-section {
  margin-block: 0 clamp(4.5rem, 10vh, 7.5rem);
  scroll-margin-top: 4.5rem;
  position: relative;
}

/* Alternating fields make each section read as a new chapter. */
#experience,
#research,
#service {
  margin-inline: clamp(-2rem, -3vw, -1rem);
  padding: clamp(1.75rem, 4vw, 3rem);
  border-radius: 1.4rem;
}

#experience,
#service {
  background: var(--accent-pale);
}

#research {
  background: var(--research-field);
}

.cv-section h2 {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 2.4rem;
}

.cv-section h2::before {
  content: attr(data-chapter);
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  flex: 0 0 2rem;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 0.66rem;
  letter-spacing: 0.04em;
}

/* Hairline that draws itself across when the heading reveals. */
.cv-section h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--hairline);
  transform-origin: left;
}

html.js h2.reveal::after {
  transform: scaleX(0);
  transition: transform 0.9s cubic-bezier(0.22, 1, 0.36, 1) 0.15s;
}

html.js h2.reveal.is-visible::after {
  transform: scaleX(1);
}

.entry {
  margin-block: 2.4rem;
}

/* Use cards selectively so every content type does not feel identical. */
#education > .entry,
#research > .entry {
  background: var(--card);
  border: 1px solid var(--tint-weak);
  border-radius: 0.9rem;
  padding: clamp(1.15rem, 2.5vw, 1.6rem);
  box-shadow: var(--shadow-rest);
}

#education > article.entry {
  border-top: 3px solid var(--accent);
}

#research > .entry:first-of-type {
  border-left: 4px solid var(--accent);
}

#service > .entry:nth-of-type(2) {
  background: var(--card-plain);
  border-radius: 0.9rem;
  padding: clamp(1.15rem, 2.5vw, 1.6rem);
}

.entry__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem;
}

.entry__head > div {
  flex: 1 1 0;
  min-width: 0;
}

.entry h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.35rem;
  margin: 0;
}

.subhead {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.2rem;
  margin: 0 0 1rem;
}

.entry__org {
  color: var(--ink-soft);
  margin: 0.25rem 0 0;
  font-size: 0.98rem;
}

.entry__dates {
  color: var(--accent);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  margin: 0;
}

.entry ul {
  margin: 1rem 0 0;
  padding-left: 1.2rem;
}

.entry li {
  margin-block: 0.55rem;
  color: var(--ink-soft);
}

.entry li::marker {
  color: var(--ink-faint);
}

.entry li strong {
  color: var(--ink);
  font-weight: 600;
}

ul.compact li {
  margin-block: 0.7rem;
}

.lede {
  color: var(--ink-soft);
  font-size: 1.15rem;
  line-height: 1.75;
  max-width: 40rem;
  margin: 0;
}

.cite {
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.6;
  margin: 0.9rem 0;
  padding-left: 1.4rem;
  text-indent: -1.4rem; /* hanging indent, citation style */
}

.cite strong {
  color: var(--ink);
}

.aside {
  color: var(--ink-soft);
  font-size: 0.95rem;
  margin: 1.2rem 0 0;
}

/* ---------- Stats (About) ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
  margin-top: 2.8rem;
}

.stat {
  position: relative;
  min-height: 8rem;
  padding: 1.25rem 1.1rem;
  overflow: hidden;
  background: linear-gradient(145deg, var(--stat-top) 30%, var(--accent-pale));
  border: 1px solid var(--hairline);
  border-radius: 0.9rem;
}

.stat::after {
  content: "";
  position: absolute;
  width: 4rem;
  height: 4rem;
  right: -1.8rem;
  bottom: -1.8rem;
  border: 1px solid var(--tint-soft);
  border-radius: 50%;
}

.stat__num {
  display: block;
  font-family: var(--serif);
  font-size: 2.3rem;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.stat__label {
  display: block;
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin-top: 0.5rem;
}

/* ---------- Timeline rail for dated roles ---------- */

.timeline {
  position: relative;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.9em;
  bottom: 0.6em;
  width: 1px;
  background: var(--hairline);
}

.timeline .entry {
  position: relative;
  padding-left: 1.9rem;
}

.timeline .entry::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--bg);
}

html.js .timeline .entry.reveal::before {
  transform: scale(0);
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.3s;
}

html.js .timeline .entry.reveal.is-visible::before {
  transform: scale(1);
}

/* On roomy screens, dates form a true timeline gutter. */
@media (min-width: 1150px) {
  .timeline::before {
    left: 9.35rem;
  }

  .timeline .entry {
    padding-left: 11rem;
  }

  .timeline .entry::before {
    left: 9.1rem;
  }

  .timeline .entry__dates {
    position: absolute;
    top: 0.08rem;
    left: 0;
    width: 8.1rem;
    white-space: normal;
    text-align: right;
    line-height: 1.35;
  }
}

@media (prefers-reduced-motion: no-preference) {
  #education > .entry,
  #research > .entry,
  #service > .entry:nth-of-type(2),
  .stat {
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
                box-shadow 0.3s ease,
                border-color 0.3s ease;
  }

  #education > .entry:hover,
  #research > .entry:hover,
  #service > .entry:nth-of-type(2):hover,
  .stat:hover {
    transform: translateY(-3px);
    border-color: var(--tint-medium);
    box-shadow: var(--shadow-lift);
  }
}

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

.site-footer {
  margin-top: auto; /* pins to the bottom when the section is short */
  border-top: 1px solid var(--hairline);
  padding-top: 2rem;
  color: var(--ink-faint);
  font-size: 0.9rem;
}

.site-footer p {
  margin: 0;
}

/* ---------- Scroll-reveal (progressive enhancement) ----------
   Content is hidden only once script.js has added the `js` class,
   so the page is fully readable without JavaScript. Each item can
   carry a small --reveal-delay for a staggered cascade. */

html.js .reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.6s ease, transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: var(--reveal-delay, 0ms);
}

html.js .reveal.is-visible {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  html.js .reveal,
  html.js h2.reveal::after,
  html.js .timeline .entry.reveal::before {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .progress__bar {
    transition: none;
  }

  .minibar {
    transition: none;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .layout {
    display: block;
  }

  .credentials {
    display: inline;
    margin-top: 0;
    margin-left: 0.25rem;
    font-size: 0.82rem;
    letter-spacing: 0.06em;
  }

  .side {
    position: static;
    height: auto;
    padding-top: clamp(2rem, 6vh, 4rem);
  }

  .side__inner {
    padding-block: 1.25rem;
  }

  .side__photo img {
    width: min(78%, 320px);
  }

  .side__nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem 0.4rem;
    margin: 0 0 1.6rem;
  }

  .side__nav a {
    overflow: hidden;
    border: 1px solid var(--hairline);
    border-radius: 999px;
    background-clip: padding-box;
    padding: 0.3rem 0.85rem;
    font-size: 0.88rem;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.25s ease, border-color 0.25s ease, background-color 0.25s ease;
  }

  .side__nav a:hover {
    border-color: var(--accent);
    background-color: var(--tint-weak);
  }

  .side__nav a:active {
    background-color: var(--tint-press);
  }

  .side__nav a.is-active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--tint-chip);
    padding-left: 0.85rem;
  }

  .side__actions {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  main {
    padding-top: clamp(3rem, 8vh, 5rem);
  }

  .entry__head {
    flex-direction: column;
    gap: 0.15rem;
  }

  #experience,
  #research,
  #service {
    margin-inline: -0.65rem;
    padding: 1.5rem 1rem;
    border-radius: 1rem;
  }

  .cv-section h2 {
    gap: 0.75rem;
  }
}

@media (min-width: 620px) and (max-width: 900px) {
  #education {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
  }

  #education > h2,
  #education > .entry:last-child {
    grid-column: 1 / -1;
  }

  #education > .entry {
    margin-block: 0;
  }
}

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

@media print {
  /* A dark screen must not print light-on-white text, so the palette is
     forced back to paper values here. This block is last in the file, so
     it wins over the prefers-color-scheme override above. */
  :root {
    color-scheme: light;
    --bg: #ffffff;
    --ink: #000000;
    --ink-soft: #303030;
    --ink-faint: #505050;
    --hairline: #cccccc;
    --accent: #2f4f6f;
    --accent-strong: #24405c;
    --on-accent: #ffffff;
    --accent-pale: transparent;
    --research-field: transparent;
    --card: transparent;
    --card-plain: transparent;
    --minibar: transparent;
    --stat-top: transparent;
    --tint-weak: #cccccc;
    --tint-soft: #cccccc;
    --tint-medium: #cccccc;
    --tint-press: transparent;
    --tint-chip: transparent;
    --shadow-rest: none;
    --shadow-lift: none;
    --photo-filter: none;
  }

  .progress,
  .minibar,
  .side__nav,
  .side__actions {
    display: none;
  }

  .layout {
    display: block;
  }

  #experience,
  #research,
  #service {
    margin-inline: 0;
    padding: 0;
    background: transparent;
  }

  #education > .entry,
  #research > .entry,
  #service > .entry:nth-of-type(2),
  .stat {
    background: transparent;
    box-shadow: none;
  }

  .side {
    position: static;
    height: auto;
  }

  .side__photo img {
    -webkit-mask-image: none;
            mask-image: none;
    max-width: 200px;
  }

  html.js .reveal,
  html.js h2.reveal::after,
  html.js .timeline .entry.reveal::before {
    opacity: 1;
    transform: none;
  }
}
