/* ==========================================================================
   Ru-Jun Wang — personal site
   Two pages (index.html, publications.html), no build step.
   Edit the HTML files for content; this file for looks.

   Layout: a profile column on the left (photo, name, contact) and the
   content on the right. On phones the profile sits on top.
   ========================================================================== */

/* ---------- Fonts (self-hosted, see fonts/LICENSE.txt) ---------- */

@font-face {
  font-family: "Source Sans 3";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("fonts/source-sans-3-latin-wght-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Source Sans 3";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("fonts/source-sans-3-latin-wght-italic.woff2") format("woff2");
}

/* Noto Sans TC, cut down to the three characters of the name (王如均). */
@font-face {
  font-family: "Name Han";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/noto-sans-tc-name.woff2") format("woff2");
  unicode-range: U+738B, U+5982, U+5747;
}

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

:root {
  --paper: #ffffff;
  --ink: #1d1a22;
  --muted: #625c6c;
  --accent: #6b2a8f;      /* links */
  --rule: #e4dfea;
  --wash: #f3eff8;

  --sans: "Source Sans 3", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --name-font: "Source Sans 3", "Name Han", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;

  --gutter: clamp(1.25rem, 5vw, 3rem);   /* page side margin */
  --profile-width: 15.5rem;              /* left column: wide enough for the e-mail line */
  --content-width: 48rem;                /* right column: make this larger for wider text */

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17141b;
    --ink: #f0ebf5;
    --muted: #aaa2b6;
    --accent: #cfaaf0;
    --rule: #342d3d;
    --wash: #231d2b;
  }
}

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

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.125rem;
  line-height: 1.6;
  font-kerning: normal;
}

h1, h2, p, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }

a {
  color: var(--accent);
  text-decoration-line: underline;
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.2em;
}
a:hover { text-decoration-thickness: 0.12em; }
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); }

.page {
  max-width: calc(var(--profile-width) + 4.5rem + var(--content-width) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ---------- Page navigation ---------- */

.site-nav {
  display: flex;
  align-items: baseline;
  gap: 2rem;
  padding-block: 1.15rem;
  border-bottom: 1px solid var(--rule);
  font-size: 1.0625rem;
}
.site-nav a {
  color: var(--muted);
  text-decoration: none;
}
.site-nav a:hover { color: var(--ink); }
.site-nav a[aria-current="page"] { color: var(--ink); }
.site-nav .brand {
  color: var(--ink);
  font-weight: 700;
}

/* ---------- Two columns: profile + content ---------- */

.layout {
  display: grid;
  grid-template-columns: var(--profile-width) minmax(0, 1fr);
  column-gap: clamp(2.5rem, 5vw, 4.5rem);
  align-items: start;
  padding-top: clamp(2rem, 4vw, 3rem);
}

/* ---------- Profile (left column) ---------- */

.profile {
  position: sticky;
  top: 2rem;
}

.portrait {
  width: 10.5rem;
  aspect-ratio: 1;
  border-radius: 50%;
  overflow: hidden;
  background: var(--wash);
  box-shadow: 0 0 0 1px var(--rule);
}
.portrait img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 30%;
}

.profile-name {
  margin-top: 1.15rem;
  font-family: var(--name-font);
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.005em;
}
.profile-name .han { white-space: nowrap; }

.profile-role {
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.45;
}

.profile-links {
  margin-top: 1rem;
  font-size: 1rem;
}
.profile-links li + li { margin-top: 0.35rem; }
/* Each entry is an icon plus text. The e-mail address is plain text on purpose (not a link). */
.profile-links a,
.profile-links .email {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.5rem;
  color: var(--ink);
  text-decoration: none;
  overflow-wrap: anywhere;
}
.profile-links a:hover {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 0.06em;
  text-underline-offset: 0.2em;
}
.profile-links svg {
  flex: none;
  width: 1.05em;
  height: 1.05em;
  margin-top: 0.275em;   /* centred on the first line of text, also when the text wraps */
  color: var(--muted);
}

/* ---------- Content (right column) ---------- */

.content { min-width: 0; }

.page-title {
  font-size: clamp(1.75rem, 1.4rem + 1.4vw, 2.25rem);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

/* The one sentence a visitor should remember, then the background. */
.pitch {
  font-size: clamp(1.375rem, 1.2rem + 0.8vw, 1.625rem);
  line-height: 1.38;
  letter-spacing: -0.008em;
  text-wrap: pretty;
}
.about {
  margin-top: 1.2rem;
  text-wrap: pretty;
}
.open-to { margin-top: 0.9rem; }

h2 {
  margin: 2.75rem 0 0.9rem;
  font-size: 1.375rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.005em;
}
.page-title + section > h2,
.remark + section > h2 { margin-top: 1.75rem; }

/* Honors (and any dated list): the year sits at the right end of the line. */
.entries > li + li { margin-top: 0.6rem; }

@media (min-width: 34rem) {
  .entries > li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 1.5rem;
    align-items: baseline;
  }
  .entries > li > * { grid-column: 1; }
  .entries > li > .when { grid-area: 1 / 2; }
}

.when {
  color: var(--muted);
  font-size: 1rem;
}
.what { line-height: 1.45; }
/* Chinese name after the English one: slightly smaller, and it moves to the next line as a whole. */
.what .zh {
  color: var(--muted);
  font-size: 0.89em;
  white-space: nowrap;
}
.detail {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
  text-wrap: pretty;
}

/* Publications */
.papers {
  padding-left: 1.9rem;
  list-style: decimal outside;
}
.papers > li + li { margin-top: 1.15rem; }
.papers > li::marker { color: var(--muted); }

.title {
  font-weight: 600;
  line-height: 1.4;
  text-wrap: pretty;
}
.authors {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
  text-wrap: balance;
}
/* A name never breaks across lines ("Ru-Jun Wang" would split at the hyphen). */
.authors b,
.authors u,
.authors .name,
.about .name { white-space: nowrap; }
.authors b {
  color: var(--ink);
  font-weight: 600;
}
/* Advisor and co-advisor are underlined (see the note under the page title). */
.authors u {
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
}

.remark {
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 1rem;
}
/* The asterisk stays with its explanation when the note wraps on a phone. */
.remark span { white-space: nowrap; }
.venue {
  font-size: 1rem;
  font-style: italic;
  line-height: 1.5;
}
.venue a,
.venue .status { font-style: normal; }
.venue a { margin-left: 0.3em; }
.venue .status { color: var(--muted); }

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

.colophon {
  margin-top: clamp(3rem, 6vw, 4rem);
  padding-block: 1.25rem 2.5rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.9375rem;
}

/* ---------- Tablets and phones: profile on top ---------- */

@media (max-width: 56rem) {
  body { font-size: 1.0625rem; }

  .layout {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 2rem;
    padding-top: 1.75rem;
  }

  .profile {
    position: static;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 1.25rem;
    align-items: center;
    padding-bottom: 1.75rem;
    border-bottom: 1px solid var(--rule);
  }
  .portrait {
    grid-row: 1 / span 3;
    width: clamp(5.5rem, 24vw, 7.5rem);
  }
  .profile-name { margin-top: 0; align-self: end; }
  .profile-role { margin-top: 0.3rem; }
  .profile-links { margin-top: 0.6rem; align-self: start; }

  /* No photo file: the text takes the full width. */
  .profile.no-photo { display: block; }

  /* On pages other than the home page, skip the profile: the name is in the navigation. */
  .profile-secondary { display: none; }
}

/* ---------- Phones: contact details get their own row under the photo and name ---------- */

@media (max-width: 30rem) {
  .portrait {
    grid-row: 1 / span 2;
    width: clamp(4.5rem, 20vw, 6rem);
  }
  .profile-role { align-self: start; }
  .profile-links {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1.5rem;
    margin-top: 1rem;
  }
  .profile-links li + li { margin-top: 0; }
}

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

@media print {
  :root {
    --paper: #fff;
    --ink: #000;
    --muted: #333;
    --accent: #000;
    --rule: #999;
  }
  body { font-size: 10.5pt; }
  .page { max-width: none; padding: 0; }
  .site-nav { display: none; }
  .profile { position: static; }
  a { text-decoration: none; }
  .papers > li, .entries > li { break-inside: avoid; }
  h2 { break-after: avoid; }
}
