/* ==========================================================================
   qianfengwen.github.io · tournament board, journal page
   Tokens and rationale: docs/design.md
   ========================================================================== */

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

:root {
  --paper: #FBFAF7;
  --ink: #191C19;
  --muted: #5D635C;
  --accent: #1E5A41;
  --accent-soft: rgba(30, 90, 65, 0.08);
  --buff: #EFEBDD;
  --hairline: #E3E2D9;
  --frame: #D8D6CA;
  --thumb-filter: none;

  --font-display: 'Schibsted Grotesk', 'Helvetica Neue', Arial, sans-serif;
  --font-body: 'STIX Two Text', Georgia, 'Times New Roman', serif;
  --font-mono: 'Spline Sans Mono', 'SFMono-Regular', Consolas, monospace;

  --w-page: 1080px;
  --w-text: 46rem;
  --pad-x: clamp(1.25rem, 4vw, 2.5rem);

  color-scheme: light;
}

[data-theme="dark"] {
  --paper: #101411;
  --ink: #E7E4D8;
  --muted: #9AA096;
  --accent: #7BC49A;
  --accent-soft: rgba(123, 196, 154, 0.10);
  --buff: #1B231D;
  --hairline: #232A24;
  --frame: #2C352E;
  --thumb-filter: brightness(0.9) contrast(0.96);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #101411;
    --ink: #E7E4D8;
    --muted: #9AA096;
    --accent: #7BC49A;
    --accent-soft: rgba(123, 196, 154, 0.10);
    --buff: #1B231D;
    --hairline: #232A24;
    --frame: #2C352E;
    --thumb-filter: brightness(0.9) contrast(0.96);
    color-scheme: dark;
  }
}

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

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 5rem;
}

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

::selection {
  background: var(--accent);
  color: var(--paper);
}

a {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 55%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  transition: color 120ms ease, text-decoration-color 120ms ease;
}

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

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

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

p {
  margin: 0 0 1em;
  max-width: var(--w-text);
}

.wrap {
  max-width: var(--w-page);
  margin: 0 auto;
  padding-left: var(--pad-x);
  padding-right: var(--pad-x);
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.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;
}

/* The skip link surfaces when keyboard focus reaches it. */
a.visually-hidden:focus-visible {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 20;
  width: auto;
  height: auto;
  margin: 0;
  padding: 0.45rem 0.9rem;
  overflow: visible;
  clip: auto;
  background: var(--accent);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 550;
  text-decoration: none;
  border-radius: 999px;
}

/* ---- Header ------------------------------------------------------------ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color 200ms ease;
}

.site-header.scrolled {
  border-bottom-color: var(--hairline);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 3.75rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  font-weight: 650;
  font-size: 1rem;
  letter-spacing: 0.01em;
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
}

.brand:hover {
  color: var(--ink);
}

.brand .mark {
  color: var(--accent);
  display: block;
}

.site-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.site-nav::-webkit-scrollbar {
  display: none;
}

.site-nav a {
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  white-space: nowrap;
}

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

.site-nav a.active {
  color: var(--accent);
}

.theme-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }

[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* ---- Hero -------------------------------------------------------------- */

.hero .wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(15rem, 20rem);
  gap: clamp(2rem, 6vw, 5rem);
  align-items: center;
  padding-top: clamp(3rem, 8vh, 5.5rem);
  padding-bottom: clamp(3rem, 8vh, 5rem);
}

.hero h1 {
  font-size: clamp(2.75rem, 6.5vw, 4.25rem);
  font-weight: 700;
  letter-spacing: -0.022em;
  margin: 0.75rem 0 1.25rem;
}

.hero .lede {
  font-size: 1.1875rem;
  line-height: 1.65;
  max-width: 34rem;
}

.topic-row {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1.4rem 0 0;
  padding: 0;
}

.topic-row li {
  font-family: var(--font-mono);
  font-size: 0.71875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--buff);
  border-radius: 3px;
  padding: 0.22rem 0.55rem;
}

.contact-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.contact-row a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-display);
  font-size: 0.84375rem;
  font-weight: 550;
  text-decoration: none;
  padding: 0.4rem 0.78rem;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  color: var(--ink);
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.contact-row a svg {
  flex: none;
  opacity: 0.8;
}

.contact-row a:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.contact-row a.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper);
}

.contact-row a.primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, var(--ink));
  color: var(--paper);
}

/* Portrait frame */

.portrait {
  margin: 0;
}

.portrait-frame {
  border: 1px solid var(--frame);
  background: var(--paper);
  padding: 0.75rem;
  aspect-ratio: 4 / 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

.portrait-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.portrait-frame svg {
  width: 100%;
  height: auto;
  display: block;
}

.tour-grid { fill: var(--frame); }
.tour-path { stroke: var(--accent); }
.tour-knight { fill: var(--accent); }

.portrait figcaption {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-align: right;
  margin-top: 0.6rem;
}

/* ---- Sections ---------------------------------------------------------- */

.section {
  border-top: 1px solid var(--hairline);
}

.section .wrap {
  padding-top: clamp(3rem, 7vh, 4.5rem);
  padding-bottom: clamp(3rem, 7vh, 4.5rem);
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  margin-bottom: 2.25rem;
}

.section-head h2 {
  font-size: 1.4rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.section-head .note {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* ---- About ------------------------------------------------------------- */

.about-grid {
  display: grid;
  grid-template-columns: minmax(0, var(--w-text)) minmax(15rem, 1fr);
  gap: clamp(2rem, 5vw, 4rem);
}

.about-aside {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.9;
  color: var(--muted);
  border-left: 1px solid var(--hairline);
  padding-left: 1.5rem;
  align-self: start;
}

.about-aside h3 {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.about-aside ul {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
}

/* ---- Research threads ---------------------------------------------------- */

.research-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.5rem;
}

.thread {
  border: 1px solid var(--hairline);
  padding: 1.5rem 1.4rem 1.3rem;
}

.thread-fig {
  width: 100%;
  height: auto;
  display: block;
  margin-bottom: 1.1rem;
}

.fig-line {
  stroke: var(--accent);
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.fig-quiet {
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-linecap: round;
  opacity: 0.45;
  fill: none;
}

.fig-quiet-line {
  stroke: var(--frame);
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.fig-dot { fill: var(--accent); }

.fig-fill {
  fill: var(--accent-soft);
  stroke: var(--accent);
  stroke-width: 1.5;
}

.thread h3 {
  font-size: 1.0625rem;
  font-weight: 640;
  letter-spacing: -0.005em;
  margin-bottom: 0.5rem;
}

.thread p {
  font-size: 0.9375rem;
  line-height: 1.6;
  margin-bottom: 0.9rem;
}

.thread-papers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.85rem;
  margin: 0;
}

.thread-papers a {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.thread-papers a:hover {
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

/* ---- News -------------------------------------------------------------- */

.news-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: var(--w-text);
}

.news-list li {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr);
  gap: 1.25rem;
  padding: 0.55rem 0;
}

.news-list time {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
  padding-top: 0.15rem;
  white-space: nowrap;
}

/* ---- Publications ------------------------------------------------------ */

.pub-year {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr);
  gap: 1.25rem;
}

.pub-year + .pub-year {
  margin-top: 2.5rem;
}

.pub-year > h3 {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  padding-top: 1.1rem;
}

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

.pub {
  display: grid;
  grid-template-columns: 10.5rem minmax(0, 1fr);
  gap: 1.5rem;
  padding: 1.35rem 1.1rem 1.35rem 0;
  border-top: 1px solid var(--hairline);
}

.pub:first-child {
  border-top: none;
}

.pub-thumb {
  display: block;
  align-self: start;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  border: 1px solid var(--hairline);
  background: #FBFAF7;
  transition: border-color 150ms ease;
}

.pub-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: var(--thumb-filter, none);
  transition: transform 350ms ease;
}

.pub:hover .pub-thumb {
  border-color: var(--accent);
}

.pub:hover .pub-thumb img {
  transform: scale(1.03);
}

.pub-eyebrow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.pub-title {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 620;
  letter-spacing: -0.005em;
  line-height: 1.35;
  margin: 0 0 0.3rem;
}

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

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

.pub-authors {
  margin: 0 0 0.45rem;
  font-size: 0.9375rem;
  color: var(--muted);
  max-width: none;
}

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

.pub-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.venue {
  font-family: var(--font-mono);
  font-size: 0.71875rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--buff);
  border-radius: 3px;
  padding: 0.18rem 0.5rem;
}

.venue.preprint {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--muted);
}

.venue-flag {
  font-family: var(--font-mono);
  font-size: 0.71875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 3px;
  padding: 0.18rem 0.5rem;
}

.pub-links {
  display: inline-flex;
  gap: 0.75rem;
}

.pub-links a {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
}

.pub-links a::after {
  content: "\2197";  /* north-east arrow */
  font-size: 0.65em;
  margin-left: 0.15em;
  vertical-align: 0.25em;
}

.pub-links a:hover {
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

.bibtex {
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.bibtex summary {
  color: var(--accent);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

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

.bibtex summary::after {
  content: "+";
  margin-left: 0.25em;
}

.bibtex[open] summary::after {
  content: "\2212";  /* minus sign */
}

.bibtex summary:hover {
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

.bibtex[open] {
  flex-basis: 100%;
}

.bibtex pre {
  margin: 0.6rem 0 0;
  padding: 0.85rem 1rem;
  background: var(--buff);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  font-size: 0.71875rem;
  line-height: 1.6;
  overflow-x: auto;
}

/* ---- Experience -------------------------------------------------------- */

.xp-group + .xp-group {
  margin-top: 3rem;
}

.xp-group > h3 {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1rem;
}

.xp {
  display: grid;
  grid-template-columns: 10rem minmax(0, var(--w-text));
  gap: 1.25rem;
  padding: 1.1rem 0;
  border-top: 1px solid var(--hairline);
}

.xp time {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
  padding-top: 0.2rem;
}

.xp h4 {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 620;
  margin: 0;
  line-height: 1.35;
}

.xp h4 svg {
  flex: none;
  margin-top: 0.2em;
  color: var(--accent);
}

.xp h4 .org-logo {
  flex: none;
  margin-top: 0.15em;
  width: 17px;
  height: 17px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 1px;
}

.xp .role {
  display: block;
  font-family: var(--font-body);
  font-style: italic;
  font-weight: 400;
  font-size: 0.9375rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.xp div > p {
  margin: 0.6rem 0 0;
  font-size: 0.9782rem;
  max-width: 38rem;
}

.xp ul {
  margin: 0.6rem 0 0;
  padding-left: 1.1rem;
}

.xp li {
  margin: 0.25rem 0;
  font-size: 0.9782rem;
}

.xp li::marker {
  color: var(--accent);
}

/* ---- Awards & Service --------------------------------------------------- */

.award-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: var(--w-text);
}

.award-list li {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr);
  gap: 1.25rem;
  padding: 0.55rem 0;
}

.award-list .years {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
  padding-top: 0.15rem;
  white-space: nowrap;
}

.award-list .grantor {
  color: var(--muted);
}

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

.site-footer {
  border-top: 1px solid var(--hairline);
  margin-top: 1rem;
}

.site-footer .wrap {
  padding-top: 2.5rem;
  padding-bottom: 3rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2.5rem;
  justify-content: space-between;
  align-items: baseline;
}

.site-footer p {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.8;
}

.site-footer a {
  color: var(--muted);
}

.site-footer a:hover {
  color: var(--accent);
}

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

@media (max-width: 860px) {
  .hero .wrap {
    grid-template-columns: 1fr;
    padding-top: 2.5rem;
  }

  .portrait {
    order: -1;
    max-width: 15rem;
    margin-inline: auto;
  }

  .about-grid {
    grid-template-columns: 1fr;
  }

  .research-grid {
    grid-template-columns: 1fr;
  }

  .about-aside {
    border-left: none;
    border-top: 1px solid var(--hairline);
    padding-left: 0;
    padding-top: 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: 0 2rem;
  }

  .pub-year {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .pub-year > h3 {
    padding-top: 0;
  }

  .xp {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }
}

@media (max-width: 560px) {
  .site-nav {
    display: none;
  }

  .pub {
    grid-template-columns: 1fr;
    gap: 0.9rem;
  }

  .pub-thumb {
    max-width: 24rem;
  }

  .news-list li,
  .award-list li {
    grid-template-columns: 1fr;
    gap: 0.1rem;
    padding: 0.7rem 0;
  }
}

/* ---- Motion ------------------------------------------------------------- */

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

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

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

@media print {
  .site-header,
  .theme-toggle,
  .portrait,
  .contact-row a.primary {
    display: none;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 10.5pt;
  }

  .section .wrap,
  .hero .wrap {
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
  }

  a {
    text-decoration: none;
    color: #000;
  }
}
