/* alanknguyen.com */

:root {
  --bg: #f3f3f3;
  --bg-elev: #fafafa;
  --text: #1c1c1c;
  --text-2: #4a4a4a;
  --muted: #6e6e6e;
  --rule: #dcdcdc;
  --accent: #3760e6;
  --accent-hover: #2a49b8;
  --thumb-bg: #e7e7e7;
  --tag-bg: #e8e8e8;
  --font-text: Verdana, Geneva, Tahoma, sans-serif;
  --font-mono: "Courier New", Courier, monospace;
  --col: 760px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #171717;
  --bg-elev: #1f1f1f;
  --text: #e4e4e4;
  --text-2: #b8b8b8;
  --muted: #929292;
  --rule: #2c2c2c;
  --accent: #94adff;
  --accent-hover: #b3c4ff;
  --thumb-bg: #222222;
  --tag-bg: #262626;
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.6 var(--font-text);
}

.page {
  max-width: var(--col);
  margin: 0 auto;
  padding: clamp(40px, 8vh, 80px) 20px 56px;
}

a { color: var(--accent); text-decoration: none; }
a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

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

/* quiet links (footer credits) read as plain text until hovered */
a.plain { color: inherit; }
a.plain:hover { color: var(--accent); }

.skip { position: absolute; left: -999px; top: 12px; }
.skip:focus {
  left: 20px;
  z-index: 10;
  padding: 8px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--rule);
}

/* Masthead */

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 28px;
}

.masthead h1 {
  margin: 0 0 6px;
  font: 400 2rem/1.2 var(--font-text);
}

.masthead h1 .aka { color: var(--text-2); white-space: nowrap; }
/* "(Alan)" flips to the Han-Nôm name on hover, focus or tap.
   The faces swap at the halfway point (card edge-on), so the two names never show together. */
.flip { --flip: 0.5s; display: inline-block; perspective: 600px; cursor: default; outline: none; }
.flip-inner {
  display: inline-grid;
  transition: transform var(--flip) cubic-bezier(0.45, 0, 0.55, 1);
  transform-style: preserve-3d;
}
.flip-front, .flip-back {
  grid-area: 1 / 1;
  justify-self: center;
  align-self: center;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transition: opacity 0s linear calc(var(--flip) / 2);
}
.flip-front { transform: rotateY(0deg); }
.flip-back {
  opacity: 0;
  transform: rotateY(180deg);
  font-family: "Noto Serif TC", "Songti TC", "Source Han Serif TC", "Noto Serif CJK TC", serif;
  font-size: 0.8em;
  font-weight: 500;
  letter-spacing: 0.08em;
}
.flip:hover .flip-inner, .flip:focus-visible .flip-inner, .flip.flipped .flip-inner { transform: rotateY(180deg); }
.flip:hover .flip-front, .flip:focus-visible .flip-front, .flip.flipped .flip-front { opacity: 0; }
.flip:hover .flip-back, .flip:focus-visible .flip-back, .flip.flipped .flip-back { opacity: 1; }
.flip:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
/* the full name flips to its katakana reading */
.name-flip { max-width: 100%; }
/* the back face is mirrored by the 180° turn, so "end" lands on the left */
.name-flip .flip-front { justify-self: start; }
.name-flip .flip-back { justify-self: end; }
.name-flip .flip-back {
  font-family: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  font-size: 0.78em;
  font-weight: 400;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
  .flip { --flip: 0s; }
}

.role { margin: 0 0 4px; color: var(--text-2); }

.email {
  margin: 0 0 14px;
  color: var(--text-2);
  font: 400 0.95rem/1.5 var(--font-mono);
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  font: 400 0.82rem/1.4 var(--font-text);
}
.links a {
  color: var(--text-2);
  padding-bottom: 2px;
  border-bottom: 1px solid var(--rule);
}
.links a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }

.portrait {
  flex: none;
  width: 168px;
  height: 168px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--rule);
  background: var(--thumb-bg);
}

.bio p { margin: 0 0 1em; }
.bio p:last-child { margin-bottom: 0; }

/* Sections */

.section {
  margin-top: 48px;
  padding-top: 28px;
  border-top: 1px solid var(--rule);
}

.section h2 {
  margin: 0 0 18px;
  font: 400 1.45rem/1.3 var(--font-text);
}

.placeholder { margin: 0; color: var(--text-2); }
.section-note { margin: 0 0 18px; color: var(--text-2); }

/* Research entries: thumbnail left, text right */

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

.entry {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 10px 26px;
  padding: 22px 0;
  border-top: 1px solid var(--rule);
}
.entry:first-child { border-top: 0; padding-top: 4px; }

.thumb {
  display: block;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--thumb-bg);
  transition: border-color 0.2s ease;
}
.entry:hover .thumb { border-color: var(--muted); }
.thumb video, .thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.entry-body h3 { margin: 0 0 6px; font: 700 0.97rem/1.45 var(--font-text); }
.entry-body h3 a { color: var(--text); }
.entry-body h3 a:hover { color: var(--accent); text-decoration: none; }
.entry-body h3 .kind { color: var(--muted); font-weight: 400; font-size: 0.85em; }

.authors { margin: 0 0 2px; color: var(--text-2); font-size: 0.93rem; }
.authors .me { color: var(--text); font-weight: 700; }

.venue { margin: 0 0 8px; color: var(--muted); font: 400 0.8rem/1.5 var(--font-text); }

.entry-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 0 0 10px;
  font: 400 0.8rem/1.4 var(--font-text);
}

.summary { margin: 0; color: var(--text-2); font-size: 0.93rem; line-height: 1.6; }

/* Notes: one row per course */

.courses { list-style: none; margin: 0; padding: 0; }
.courses li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 16px;
  align-items: baseline;
  padding: 12px 0;
  border-top: 1px solid var(--rule);
}
.courses li:first-child { border-top: 0; padding-top: 0; }
.course-code {
  margin-right: 8px;
  color: var(--muted);
  font: 400 0.75rem/1.4 var(--font-text);
}
.course-title { font-weight: 700; }

.tag {
  grid-row: 1;
  grid-column: 2;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--tag-bg);
  color: var(--muted);
  font: 400 0.7rem/1 var(--font-text);
  white-space: nowrap;
}

/* Compact CV rows: date left, one line right */

.cv { list-style: none; margin: 0; padding: 0; }
.cv li {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 0 16px;
  padding: 5px 0;
}
.cv-when {
  color: var(--muted);
  font: 400 0.8rem/1.75 var(--font-text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cv-what { font-size: 0.93rem; line-height: 1.55; }
.cv-what b { font-weight: 700; }
.cv-note { color: var(--text-2); font-size: 0.87rem; }

/* Footer */

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 16px;
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font: 400 0.78rem/1.5 var(--font-text);
}
/* light/dark switch, top right */
.theme-toggle {
  position: absolute;
  top: 18px;
  right: 18px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.theme-toggle:hover { background: var(--accent); color: #fff; transform: scale(1.06); }
.theme-toggle svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .moon { fill: currentColor; stroke: none; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }

/* Small screens */

@media (max-width: 640px) {
  .page { padding-top: 60px; }
  .theme-toggle { top: 12px; right: 12px; }
  .masthead { gap: 18px; }
  .masthead h1 { font-size: 1.7rem; }
  .portrait { width: 104px; height: 104px; border-radius: 8px; }
  .entry { grid-template-columns: 1fr; gap: 12px; }
  .thumb { max-width: 420px; }
  .cv li { grid-template-columns: 78px 1fr; }
}

@media (max-width: 400px) {
  .masthead { flex-direction: column-reverse; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

@media print {
  .theme-toggle, .skip { display: none; }
}

/* Per-entry extras: wide thumbs, figure strips, BibTeX */

.thumb.wide { aspect-ratio: 2 / 1; background: #fff; }
.thumb.wide img { object-fit: contain; }
.thumb.fill { background: #081424; }
.thumb.fill img { object-fit: cover; }

.entry-links button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}
.entry-links button:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }
.entry-links button::after { content: "▾"; display: inline-block; margin-left: 3px; font-size: 0.95em; line-height: 1; transition: transform 0.15s ease; }
.entry-links button[aria-expanded="true"]::after { transform: rotate(180deg); }

.entry-extra { grid-column: 1 / -1; margin: 6px 0 0; }
.more-info {
  margin: -2px 0 12px;
  padding: 6px 0 6px 12px;
  border-left: 2px solid var(--rule);
  color: var(--text-2);
  font-size: 0.86rem;
  line-height: 1.55;
}
.more-info[hidden] { display: none; }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; margin: 0 0 8px; }
.info-list div { display: contents; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; }
.more-info p { margin: 0 0 6px; }
.more-info p:last-child { margin-bottom: 0; }
.entry-extra[hidden] { display: none; }

.figures figure { margin: 0 0 18px; }
.figures figure:last-child { margin-bottom: 0; }
.figures img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fff;
}
.figures figcaption {
  margin-top: 6px;
  color: var(--muted);
  font: 400 0.78rem/1.5 var(--font-text);
}

.bibtex {
  overflow-x: auto;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg-elev);
  color: var(--text-2);
  font: 400 0.76rem/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre;
}

/* Dated lists (teaching), after jessezhang.net */

.org { margin: 0 0 2px; font-weight: 700; }
.dated { list-style: none; margin: 0; padding: 0; }
.dated li { padding: 1px 0; line-height: 1.55; }
.dated b { font-variant-numeric: tabular-nums; }

/* Notes list on the home page */

.entries + .courses { margin-top: 6px; padding-top: 14px; border-top: 1px solid var(--rule); }

/* Note picker: one entry, several notes */

.note-picker { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font: 400 0.8rem/1.4 var(--font-text); }
.note-picker label { color: var(--muted); }
.np-select { position: relative; min-width: 0; flex: 0 1 auto; }
.np-select::after {
  content: "▾";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.note-picker select {
  appearance: none;
  -webkit-appearance: none;
  max-width: 100%;
  padding: 6px 28px 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  text-overflow: ellipsis;
  cursor: pointer;
}
.note-picker select:hover { border-color: var(--muted); }
.note-picker select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.note-panel[hidden] { display: none; }
.note-panel .info-list { margin: 0 0 4px; }
.summary[hidden] { display: none; }
