/* ==========================================================================
   Kelvin Kan, personal site. One stylesheet for every page.
   Colours, fonts and the column grid are defined once in :root;
   dark mode overrides the colours further down.
   ========================================================================== */

/* Fonts: self-hosted, SIL Open Font License (see fonts/LICENSE-*.txt) */
@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-latin-wght-normal.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Source Serif 4";
  src: url("../fonts/source-serif-4-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
/* Accented letters beyond basic Latin (such as the ň in Drgoňa).
   Browsers only download this file on pages that use one. */
@font-face {
  font-family: "Source Serif 4";
  src: url("../fonts/source-serif-4-latin-ext-wght-normal.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C4,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Source Serif 4";
  src: url("../fonts/source-serif-4-latin-wght-italic.woff2") format("woff2");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  --paper: #ffffff;
  --panel: #f1f6fb;
  --ink: #13233a;
  --ink-2: #4a5c72;
  --link: #0f5596;
  --underline: #a9c3dc;
  --rule: #dde5ee;
  --accent: #e0902a;

  --sans: "Instrument Sans", "Helvetica Neue", Arial, "PingFang HK", "Noto Sans TC",
    "Microsoft JhengHei", sans-serif;
  --serif: "Source Serif 4", "Source Serif Pro", Georgia, "Noto Serif TC", "Songti TC",
    serif;

  --side: 9rem;      /* the left margin column: section names, years */
  --measure: 38rem;  /* reading width of the main column */
  --gutter: clamp(1.25rem, 4vw, 3rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0b1727;
    --panel: #10213a;
    --ink: #e3eaf3;
    --ink-2: #9db0c6;
    --link: #9fd0f6;
    --underline: #3d6283;
    --rule: #22354d;
    --accent: #f0b25c;
  }
}

/* --- 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: 400 1.125rem/1.65 var(--serif);
  font-kerning: normal;
}

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

h1,
h2,
h3,
p,
figure,
dl,
dd {
  margin: 0;
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

a {
  color: var(--link);
  text-decoration-line: underline;
  text-decoration-color: var(--underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
}

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

var {
  font-style: italic;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 10;
  padding: 0.5rem 0.9rem;
  background: var(--paper);
  font: 500 1rem/1.4 var(--sans);
}

.skip:focus {
  top: 1rem;
}

.wrap {
  width: 100%;
  max-width: 76rem;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* --- Header and footer --------------------------------------------------- */

.site-header {
  border-bottom: 1px solid var(--rule);
}

.site-header .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 2rem;
  padding-block: 1.1rem;
}

.site-name {
  font: 600 1.0625rem/1.4 var(--sans);
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
}

.site-nav ul {
  display: flex;
  gap: 1.75rem;
}

.site-nav a {
  display: block;
  padding-block: 0.2rem;
  font: 500 1rem/1.4 var(--sans);
  color: var(--ink-2);
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--ink);
}

.site-nav a[aria-current="page"] {
  color: var(--ink);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.site-footer {
  margin-top: clamp(2rem, 5vw, 3.5rem);
  border-top: 1px solid var(--rule);
}

.site-footer .wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 2rem;
  padding-block: 1.5rem 2.25rem;
  font: 400 0.875rem/1.5 var(--sans);
  color: var(--ink-2);
}

/* --- Home ----------------------------------------------------------------- */

.hero {
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
  grid-template-areas:
    "photo name"
    "photo meta";
  grid-template-rows: auto 1fr;
  column-gap: var(--gutter);
  row-gap: 1.5rem;
  align-items: start;
  padding-block: clamp(2.5rem, 6vw, 4.5rem) clamp(2.25rem, 4vw, 3rem);
}

.about {
  border-top: 1px solid var(--rule);
}

.portrait {
  grid-area: photo;
  width: 100%;
  max-width: var(--side);
  border-radius: 3px;
}

.hero h1 {
  grid-area: name;
  font: 600 clamp(2.25rem, 1.4rem + 2.5vw, 3.25rem)/1.04 var(--sans);
  letter-spacing: -0.022em;
  text-wrap: balance;
}

.hero h1 .zh {
  display: block;
  margin-top: 0.5em;
  font-size: 0.48em;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: var(--ink-2);
}

.hero-meta {
  grid-area: meta;
}

.role {
  font-size: 1.25rem;
  line-height: 1.45;
}

.role span {
  color: var(--ink-2);
}

.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  margin-top: 1.5rem;
  font: 500 1rem/1.5 var(--sans);
}

/* --- Rows: a label in the left column, content in the main column -------- */

.row {
  display: grid;
  grid-template-columns: var(--side) minmax(0, var(--measure));
  column-gap: var(--gutter);
  align-items: baseline;
  padding-block: 2.25rem;
}

.row > h2 {
  font: 500 1rem/1.4 var(--sans);
  color: var(--ink-2);
}

.prose p + p {
  margin-top: 1em;
}

.contact {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.35rem 1.5rem;
  align-items: baseline;
}

.contact dt {
  font: 500 1rem/1.4 var(--sans);
  color: var(--ink-2);
}

/* --- Inner pages: title block ------------------------------------------- */

.page-head {
  padding-block: clamp(2.5rem, 6vw, 4rem) 0.75rem;
}

.page-head > * {
  grid-column: 2;
}

.page-head h1 {
  font: 600 clamp(2rem, 1.5rem + 1.6vw, 2.75rem)/1.1 var(--sans);
  letter-spacing: -0.02em;
}

.lead {
  margin-top: 0.75rem;
  color: var(--ink-2);
}

/* --- Research: publications grouped by year ------------------------------ */

/* Citations scan rather than read, so this page gets a wider main column. */
.list-page {
  --measure: 46rem;
}

.year > h2 {
  position: sticky;
  top: 1.25rem;
  font-variant-numeric: tabular-nums lining-nums;
}

.year {
  padding-block: 1.6rem;
}

.pubs > li + li {
  margin-top: 1.6rem;
}

.pub h3 {
  font: 600 1.125rem/1.45 var(--serif);
}

.pub h3 a {
  text-decoration: none;
}

.pub h3 a:hover {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
}

.authors,
.venue {
  margin-top: 0.2rem;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink-2);
}

.authors .me {
  font-weight: 600;
  color: var(--ink);
}

.venue i {
  color: var(--ink);
}

.code {
  margin-left: 0.55em;
  font: 500 0.875rem/1 var(--sans);
  white-space: nowrap;
}

/* --- Teaching: courses grouped by role and institution ------------------- */

.inst + .inst {
  margin-top: 2rem;
}

.inst h3 {
  margin-bottom: 0.65rem;
  font: 600 1rem/1.4 var(--sans);
}

.course {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  column-gap: 1rem;
  align-items: baseline;
}

.course + .course {
  margin-top: 0.8rem;
}

.course-code {
  font: 500 0.9375rem/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  white-space: nowrap;
}

.course-title {
  line-height: 1.45;
}

.course-terms {
  grid-column: 2;
  font: 400 0.9375rem/1.5 var(--sans);
  color: var(--ink-2);
}

/* --- Smaller screens ------------------------------------------------------ */

@media (max-width: 719px) {
  .hero {
    grid-template-columns: 5.75rem minmax(0, 1fr);
    grid-template-areas:
      "photo name"
      "meta meta";
    align-items: center;
    column-gap: 1.25rem;
    row-gap: 1.75rem;
  }

  .hero h1 {
    font-size: clamp(1.75rem, 1rem + 4vw, 2.25rem);
  }

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

  .page-head > * {
    grid-column: 1;
  }

  .year > h2 {
    position: static;
  }

  .course {
    grid-template-columns: 5.25rem minmax(0, 1fr);
  }
}

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

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

  .site-header {
    border: 0;
  }

  body {
    font-size: 10.5pt;
  }

  .hero {
    grid-template-columns: 6rem minmax(0, 1fr);
    padding-block: 0 1rem;
  }

  .year > h2 {
    position: static;
  }

  a {
    color: inherit;
    text-decoration: none;
  }
}
