/* Shared academic design system. */
:root {
  --primary-color: #0066cc;
  --primary-hover: #004f9e;
  --background-color: #fafbfc;
  --surface-color: #fff;
  --text-color: #000;
  --heading-color: #000;
  --secondary-color: #6b7280;
  --metadata-color: #4b5563;
  --border-color: #e5e7eb;
  --border-hover: #cbd5e1;
  --soft-blue: #f3f7fc;
  --active-background: #eaf2fc;
  --card-radius: 8px;
  --entry-padding: 24px;
  --entry-text-inset: calc(var(--entry-padding) + 1px);
  --content-width: 1120px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  background: var(--background-color);
  color: var(--text-color);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

h1, h2, h3 {
  color: var(--heading-color);
  font-weight: 700;
  line-height: 1.4;
}

h1 {
  font-size: 2rem;
}

h2 {
  margin: 0 0 20px;
  font-size: 1.5rem;
}

h3 {
  margin: 0;
  font-size: 1.25rem;
}

p {
  margin: 0 0 12px;
}

p:last-child {
  margin-bottom: 0;
}

a {
  color: var(--primary-color);
  text-decoration: none;
  text-underline-offset: 3px;
  transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
}

a:hover, a:focus-visible {
  color: var(--primary-hover);
  text-decoration: underline;
}

a:focus-visible, button:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 3px;
}

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

/* Quiet, shared navigation. */
.navbar {
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 1000;
  width: 100%;
  background: var(--surface-color);
  border-bottom: 1px solid var(--border-color);
}

.navbar-brand {
  display: none;
  flex-shrink: 0;
  padding: 0 24px;
  color: var(--heading-color);
  font-weight: 600;
  white-space: nowrap;
}

.navbar-container {
  display: flex;
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
  gap: 0;
  width: 100%;
  padding: 0;
}

.navbar a {
  display: block;
  padding: 15px 16px 13px;
  border-bottom: 2px solid transparent;
  color: var(--text-color);
  font-size: 1rem;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
}

.navbar a:hover, .navbar a:focus-visible {
  color: var(--primary-hover);
  background: var(--soft-blue);
  text-decoration: none;
}

.navbar a.active {
  background: var(--active-background);
  border-bottom-color: var(--primary-color);
  color: var(--primary-color);
}

.navbar .icon {
  display: none;
}

/* Framed page headings and outer panels contain the individual entry cards. */
.container {
  flex: 1;
  width: 100%;
  max-width: calc(var(--content-width) + 48px);
  margin: 0 auto;
  padding: 40px 24px 56px;
}

.name-box {
  width: 100%;
  max-width: 560px;
  margin: 0 auto 24px;
  padding: 24px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  text-align: center;
}

.name-box h1 {
  margin: 0 0 8px;
  letter-spacing: -0.025em;
}

.name-box p {
  color: var(--text-color);
}

.content {
  width: 100%;
  min-width: 0;
  padding: 28px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
}

.content > section + section {
  margin-top: 36px;
}

.section-heading {
  margin-bottom: 16px;
}

/* Section labels align with the text inside the entry cards. */
.entry-heading {
  padding-inline-start: var(--entry-text-inset);
}

/* Shared cards for experience, education, awards, publications, projects and blog posts. */
.experience, .education-item, .award-item, .project-item, .post {
  min-width: 0;
  margin-bottom: 18px;
  padding: var(--entry-padding);
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.experience:last-child, .education-item:last-child,
.award-item:last-child, .project-item:last-child {
  margin-bottom: 0;
}

.experience:hover, .education-item:hover,
.award-item:hover, .project-item:hover, .post:hover {
  border-color: var(--border-hover);
  box-shadow: 0 2px 8px rgb(17 24 39 / 3%);
}

.title-date {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 10px;
}

.title-date h3 {
  min-width: 0;
  font-size: 1.25rem;
}

.date, .experience-date, .experience-location {
  color: var(--metadata-color);
  font-size: 1rem;
  font-style: normal;
}

.date {
  flex-shrink: 0;
}

.entry-details {
  margin: 14px 0 0;
  padding-left: 19px;
}

.entry-details li + li {
  margin-top: 4px;
}

.project-item p {
  margin-top: 12px;
}

.publication-status {
  color: var(--secondary-color);
}

/* Resource links are compact outline buttons. */
.resource-links, .publication-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.outline-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 4px 12px;
  background: var(--surface-color);
  border: 1px solid #d5deeb;
  border-radius: 5px;
  color: var(--primary-color);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.5;
  text-decoration: none;
}

.outline-button:hover, .outline-button:focus-visible {
  background: var(--soft-blue);
  border-color: var(--primary-color);
  color: var(--primary-hover);
  text-decoration: none;
}

/* Dates remain in the layout instead of overlapping long titles. */
.experience, .education-item, .award-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 24px;
  align-items: start;
}

.experience-title {
  grid-column: 1;
  margin: 0;
  font-size: 1.25rem;
}

.experience-company {
  grid-column: 1;
  margin-top: 4px;
}

.experience .experience-company,
.education-item .experience-title {
  font-size: 1.125rem;
}

.experience-meta-container {
  display: flex;
  flex-direction: column;
  grid-column: 2;
  grid-row: 1 / span 2;
  gap: 4px;
  padding-top: 2px;
  text-align: right;
}

.experience > p, .experience > .entry-details {
  grid-column: 1 / -1;
  margin-top: 14px;
}

.experience a {
  color: var(--primary-color);
}

.experience a:hover, .experience a:focus-visible {
  color: var(--primary-hover);
  text-decoration: underline;
}

/* Blog cards reuse the shared entry styling. */
.post:last-of-type {
  margin-bottom: 0;
}

.post .title-date {
  margin-bottom: 6px;
}

.post .title-date h3 a {
  color: var(--primary-color);
}

.post .title-date h3 a:hover, .post .title-date h3 a:focus-visible {
  color: var(--primary-hover);
  text-decoration: underline;
}

.blog-categories {
  --filter-inline-padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
  /* Match card text while allowing for each tag's own inner padding. */
  padding: 6px calc(var(--entry-text-inset) - var(--filter-inline-padding));
  font-size: 0.875rem;
}

.category-filter {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 34px;
  padding: 6px var(--filter-inline-padding, 10px);
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--primary-color);
  font: inherit;
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: color 150ms ease, background-color 150ms ease;
}

.category-filter:focus-visible {
  background: var(--soft-blue);
  color: var(--primary-hover);
  text-decoration: none;
}

/* Touchscreens must not keep a hover highlight after a category is deselected. */
@media (hover: hover) and (pointer: fine) {
  .category-filter:hover {
    background: var(--soft-blue);
    color: var(--primary-hover);
    text-decoration: none;
  }
}

.category-filter.active-filter {
  background: var(--active-background);
  color: var(--primary-hover);
}

.blog-empty {
  padding: 20px var(--entry-text-inset);
  color: var(--metadata-color);
}

/* Home keeps the same typography and restrained link treatment. */
.home-page .container {
  max-width: 1048px;
  padding-top: 64px;
}

.home-page .name-box {
  margin-bottom: 24px;
}

.name-box .legal-name,
.name-box .english-name,
.name-box .chinese-name {
  font-size: 2.25rem;
  font-weight: 700;
}

.name-box .english-name, .name-box .chinese-name {
  display: block;
  margin: 0 0 8px;
  line-height: 1.4;
}

.social-icons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.social-icons a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 5px;
  color: var(--text-color);
  font-size: 17px;
  text-decoration: none;
}

.social-icons a:hover, .social-icons a:focus-visible {
  background: var(--soft-blue);
  border-color: var(--primary-color);
  color: var(--primary-hover);
  text-decoration: none;
}

.big-intro {
  font-size: 1.125rem;
  line-height: 1.8;
}

.big-intro p {
  margin-bottom: 16px;
}

/* Article typography follows the shared design system. */
.blog-post {
  max-width: 840px;
  margin: 0 auto;
}

.post-header {
  margin-bottom: 28px;
}

.post-header h1 {
  margin: 0 0 14px;
  font-size: 2rem;
  letter-spacing: -0.025em;
}

.post-meta {
  color: var(--metadata-color);
  font-size: 1rem;
}

.post-updated {
  display: block;
  margin-top: 4px;
}

.post-content {
  line-height: 1.8;
}

.post-content p {
  margin-bottom: 18px;
}

.post-content h2 {
  margin: 32px 0 14px;
}

.post-content h3 {
  margin: 24px 0 12px;
}

.post-content ul, .post-content ol {
  margin: 0 0 18px;
  padding-left: 24px;
}

.post-content li + li {
  margin-top: 6px;
}

.post-content figure {
  margin: 24px 0;
}

.post-content figcaption {
  margin-top: 8px;
  color: var(--secondary-color);
  font-size: 0.875rem;
}

.post-content pre {
  max-width: 100%;
  margin: 20px 0;
  padding: 18px;
  overflow-x: auto;
  background: #f3f4f6;
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
}

.post-content code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  font-size: 0.875em;
}

.post-content pre code {
  display: block;
  line-height: 1.6;
}

.post-navigation {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: start;
  gap: 16px;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
  font-size: 0.875rem;
}

.next-post {
  text-align: right;
}

.post-sources {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.post-sources a {
  overflow-wrap: anywhere;
}

/* Desktop name stays on the left; menu items can shrink on narrow screens. */
@media (min-width: 768px) {
  .navbar-brand {
    display: block;
  }

  .navbar a:not(.icon) {
    flex: 0 1 100px;
  }
}

/* Compact layouts preserve readable text and generous tap targets. */
@media (max-width: 767px) {
  :root {
    --entry-padding: 20px;
  }

  .navbar-container {
    position: relative;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 0;
    padding: 0;
  }

  .navbar a {
    display: flex;
    align-items: center;
    min-height: 56px;
    padding: 12px 29px;
  }

  .navbar a:first-child {
    display: flex;
    justify-content: center;
    min-width: 102px;
    text-align: center;
  }

  .navbar a:not(:first-child):not(.icon) {
    display: none;
  }

  .navbar a.icon {
    display: flex;
    justify-content: center;
    position: absolute;
    top: 0;
    right: 0;
    width: 102px;
    min-width: 102px;
    height: 56px;
    padding: 0;
    font-size: 20px;
  }

  .navbar.responsive a:not(:first-child):not(.icon) {
    display: flex;
    flex-basis: 100%;
    border-bottom: 0;
    text-align: left;
  }

  .navbar.responsive a.active:not(:first-child) {
    background: var(--active-background);
  }

  .container, .home-page .container {
    padding: 28px 12px 40px;
  }

  .name-box {
    padding: 20px;
  }

  .content {
    padding: 20px 12px;
  }

  .name-box h1, .post-header h1 {
    font-size: 1.75rem;
  }

  .name-box .legal-name,
  .name-box .english-name,
  .name-box .chinese-name {
    font-size: 2rem;
  }

  .content > section + section {
    margin-top: 30px;
  }

  .title-date {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .experience, .education-item, .award-item {
    grid-template-columns: minmax(0, 1fr);
  }

  .experience-meta-container {
    grid-column: 1;
    grid-row: auto;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 2px 16px;
    margin-top: 6px;
    padding-top: 0;
    text-align: left;
  }

  .outline-button {
    min-height: 36px;
  }

  .post-navigation {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .next-post {
    text-align: left;
  }

  .post-content pre {
    padding: 14px;
  }
}

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