/* ===== 基本设置（亮暗通用） ===== */
html {
  color-scheme: light dark;
  background-color: #ffffff; /* 亮色模式背景 */
  color: #000000; /* 亮色模式文本 */
}

/* 暗色模式 */
html[color-scheme="dark"] {
  background-color: #1b1f23; /* 暗色模式页面背景 */
  color: #e4e4e4; /* 暗色模式文本 */
}

/* 媒体查询后备，确保自动模式下暗色模式生效 */
@media (prefers-color-scheme: dark) {
  html:not([color-scheme="light"]) { /* 避免覆盖手动选择light模式 */
    background-color: #1b1f23;
    color: #e4e4e4;
  }
}

/* ===== 通用设置 ===== */
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
  max-width: 120ch;
  margin-inline: auto;
  padding: 2em 1em;
}

input, textarea, button, select {
  font: inherit;
}

/* ===== 通用标题样式 ===== */
h1, h2, h3, h4, h5, h6 {
  line-height: 1.2;
  text-wrap: balance;
  margin-block: 0.5em 0.2em;
}

h1 {
  font-size: 3em;
  border-bottom: 2px solid #ccc;
  padding-bottom: 0.3em;
  margin-top: 0;
}

h2 {
  font-size: 2em;
  color: #333;
  border-left: 4px solid #6c63ff; /* 亮色模式，紫色 */
  padding-left: 0.5em;
  margin-top: 1.2em;
}

h3, h4 {
  font-size: 1.25em;
  margin-top: 1em;
  font-weight: normal;
}

/* ===== 导航栏样式 ===== */
nav {
  display: flex;
  --border-color: oklch(50% 10% 200 / 40%);
  border-bottom: 1px solid var(--border-color);
  background-color: #ffffff; /* 亮色模式背景 */
}


nav ul,
nav li {
  display: contents;
}

nav a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  padding: 16px 0;
  color: black;
  position: relative;
  font-weight: bold;
  transition: all 0.3s ease-in-out;
  border-right: 1.2px solid rgba(0, 0, 0, 0.15);
}

nav a:last-child {
  border-right: none;
}

nav a::after {
  content: '';
  position: absolute;
  bottom: 8px;
  left: 20%;
  width: 60%;
  height: 4px;
  background-color: transparent;
  transition: background-color 0.3s ease-in-out;
}

nav a.current::after {
  background-color: #adb7bb;
}

nav a:hover {
  background-color: #fceef5;
  color: black;
}

nav a:hover::after {
  background-color: #ce2b7b;
}

/* ===== 表单样式（Contact 页面）===== */
.contact-form {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1em;
  max-width: 600px;
  margin: 2em auto;
}

.contact-form label {
  display: contents;
}

.contact-form input,
.contact-form textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5em;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.contact-form button {
  grid-column: 1 / -1;
  padding: 0.75em;
  background-color: #007acc; /* 亮色模式 */
  color: white;
  border: none;
  border-radius: 4px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.contact-form button:hover {
  background-color: #005fa3;
}

/* ===== Projects 页面布局 ===== */
.projects {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15em, 1fr)); /* 三列排版，最小280px */
  gap: 1.5em; /* 卡片之间的空隙 */
  padding: 1em ;
}

.projects article {
  background: #fff;
  padding: 1rem;
  border-radius: 0.75rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.projects article:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.projects img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}

.projects h2 {
  font-size: 1.2rem;
  font-weight: bold;
  margin: 0.5rem 0;
  text-align: center;
}

.projects p {
  font-size: 0.95rem;
  text-align: center;
  color: #555;
}

.project-card {
  width: 90%; /* 每张卡片不要太宽 */
  max-width: 300px; /* 控制最大宽度，避免太胖 */
}

.project-info {
  margin-top: 0.5em;
}

.project-year {
  color: gray;
  font-family: Baskerville, serif;
  font-variant-numeric: oldstyle-nums;
  font-style: italic;
  font-size: 0.9em;
  margin-top: 0.4em;
  text-align: left; /* 明确左对齐，尽管默认是这样 */
}

.container {
  display: flex;
  align-items: center;   /* 或 center */
  gap: 2em;                  /* 控制图和图例间距 */
  flex-wrap: wrap;           /* 小屏幕自动换行，响应式 */
  margin-top: 2em;
}

#projects-plot {
  flex-shrink: 0;            /* 图不要被压缩 */
  max-width: 20em;
  height: auto;
}

#projects-plot:has(path:hover) path:not(:hover) {
  opacity: 0.5;
}

path {
  transition: 300ms;
  cursor: pointer;
}

.selected {
  --color: oklch(60% 45% 0) !important;
  fill: var(--color);
}

.legend {
  flex: 1;                   /* 占据剩余空间 */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8em, 1fr));
  gap: 0.4em 0.8em;
  font-size: 0.85em;
  list-style: none;
  padding: 1em;
  border: 1px solid #ccc;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4em;
}

.legend-item.selected {
  --color: oklch(60% 45% 0) !important;
}

.swatch {
  width: 1em;
  height: 1em;
  background: var(--color);
  display: inline-block;
  border-radius: 0.2em;
  margin-right: 0.5em;
}

.searchBar {
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  border-radius: 0.5rem;
  border: 1.5px solid #3073cc;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
  margin-top: 2rem; 
  margin-inline: auto;
}



/* ===== CV 页面布局 ===== */
.cv-page .cv-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 2em;
  margin-top: 2em;
}

.cv-page aside {
  background-color: #f8f8f8; /* 亮色模式侧边栏背景 */
  padding: 1.5em;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  text-align: center;
  height: fit-content;
}

.cv-page aside img {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 1em;
}

.cv-page main {
  display: flex;
  flex-direction: column;
  gap: 1.2em;
}

.cv-page main section article {
  background-color: #f9f9f9; /* 亮色模式卡片背景 */
  padding: 1em;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* ===== 下载按钮 ===== */
a[href$=".pdf"] {
  display: inline-block;
  background-color: #007acc;
  color: white;
  padding: 0.75em 1.5em;
  border-radius: 4px;
  text-decoration: none;
  font-weight: bold;
  margin-top: 1em;
  transition: background-color 0.3s ease;
}

a[href$=".pdf"]:hover {
  background-color: #005fa3;
}

/* ===== 其他细节 ===== */
section article {
  background-color: #f9f9f9; /* 亮色模式通用卡片背景 */
  padding: 1em;
  border-radius: 8px;
  margin-top: 1em;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

ul {
  padding-left: 1.25em;
  margin-top: 0.5em;
}

li {
  margin-block: 0.25em;
}

time {
  color: #666;
  font-size: 0.9em;
}

.github-stats-card {
  max-width: 800px;
  margin: 2em auto;
  padding: 1em 2em;
  border-left: 4px solid #7a6ff0;
  background: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,0.05);
  border-radius: 8px;
}

.github-title {
  font-size: 1.8em;
  font-weight: bold;
  margin-bottom: 1em;
}

.github-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1em;
  text-align: center;
}

.github-grid .label {
  font-size: 0.85em;
  color: #777;
  letter-spacing: 0.5px;
}

.github-grid .value {
  font-size: 2em;
  font-weight: bold;
  margin-top: 0.2em;
}

/* ===== Summary Stats 卡片横向布局 ===== */
.summary-panel {
  padding: 2em 0;
}

.summary-panel h2 {
  font-size: 2em;
  font-weight: bold;
  margin-bottom: 1.2em;
}

.stat-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3em 2em;
  justify-content: flex-start;
  align-items: flex-start;
  flex-direction: row; /* 强制横向排列 */
}

.stat-card {
  flex: 0 0 auto;  /* 不拉伸 */
  text-align: left;
  min-width: 100px;
}

.stat-label {
  font-size: 0.75em;
  color: #6c757d;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-bottom: 0.25em;
}

.stat-value {
  font-size: 2.2em;
  font-weight: 600;
  color: #111;
}

.gridlines line {
  stroke: #ccc;
  stroke-opacity: 0.3;
  shape-rendering: crispEdges;
}

.gridlines path {
  display: none;
}

dl.info {
  position: fixed;
  top: 1em;
  left: 1em;
  background-color: rgba(255, 255, 255, 0.9);
  color: #000;
  padding: 1em;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(4px);
  display: grid;
  grid-template-columns: max-content auto;
  gap: 0.3em 0.8em;
  font-size: 0.9em;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 999;
}

dl.info[hidden]:not(:hover, :focus-within) {
  opacity: 0;
  visibility: hidden;
}

dl.info dt {
  font-weight: bold;
  color: #666;
  margin: 0;
}

dl.info dd {
  margin: 0;
}

.tooltip {
  pointer-events: none;
}

/* 现有点的样式，不应用过渡 */
circle {
  transition: all 200ms, r calc(var(--r) * 100ms);
}
@starting-style {
  circle {
    r: 0;
  }
}

circle:hover {
  transform: scale(1.5);
}

circle.selected {
  fill: #ff6b6b;
}

.selection {
  fill-opacity: 0.1;
  stroke: black;
  stroke-opacity: 0.7;
  stroke-dasharray: 5 3;
  animation: marching-ants 2s linear infinite;
}

#selection-count {
  font-size: 1.2em;
  font-weight: 600;
  text-align: center;
  margin: 2em 0 1em;
}

#language-breakdown.language-columns {
  display: flex;
  justify-content: center;
  gap: 5em;
  text-align: left;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  font-size: 1rem;
  font-weight: 400;
  margin-bottom: 3em;

  min-height: 5em; /* ✅ 给个固定初始高度，避免首次渲染时跳动 */
  transition: opacity 0.3s ease, transform 0.3s ease; /* 平滑动画 */
}

.lang-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2em;
  min-width: 6em;
}

.lang-name {
  font-weight: bold;
  font-size: 1.1em;
  text-transform: uppercase;
}

.lang-lines {
  font-size: 0.95em;
}

.lang-percent {
  font-size: 0.9em;
  color: #555;
}

@keyframes marching-ants {
  to {
    stroke-dashoffset: -8;
  }
}

/* ===== Summary Stats 暗色模式 ===== */
html[color-scheme="dark"] .stat-label {
  color: #c4c4c4;
}

html[color-scheme="dark"] .stat-value {
  color: #ffffff;
}
/* ===== 🌙 暗色模式样式 ===== */
html[color-scheme="dark"] nav {
  background-color: #2a2f33 !important; /* 强制覆盖导航栏背景 */
  --border-color: oklch(50% 10% 140 / 30%);
}

html[color-scheme="dark"] nav a {
  color: #e4e4e4;
  border-right: 1px solid #e4e4e4;
}

html[color-scheme="dark"] nav a.current::after {
  background-color: #6fd39e;
}

html[color-scheme="dark"] nav a:last-child {
  border-right: none !important; /* 暗色模式下移除最后一个链接的分割线 */
}

html[color-scheme="dark"] nav a:hover {
  background-color: color-mix(in oklch, #6fd39e, #2a2f33 85%); /* 修正悬停背景 */
  color: white;
}

html[color-scheme="dark"] nav a:hover::after {
  background-color: #7ee2a1;
}

html[color-scheme="dark"] .projects article,
html[color-scheme="dark"] .cv-page main section article,
html[color-scheme="dark"] section article {
  background-color: #2c3338 !important; /* 强制覆盖卡片背景 */
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  color: #e4e4e4;
}

html[color-scheme="dark"] .cv-page aside {
  background-color: #2c3338 !important; /* 强制覆盖侧边栏背景 */
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  color: #e4e4e4;
}

html[color-scheme="dark"] .cv-page aside h2,
html[color-scheme="dark"] .cv-page aside .name {
  color: #f0f0f0; /* 侧边栏标题和姓名颜色 */
}

html[color-scheme="dark"] .cv-page h2 {
  color: #f0f0f0; /* CV页面h2标题颜色 */
}

html[color-scheme="dark"] .projects article h2 {
  color: #f0f0f0; /* 项目卡片标题颜色 */
}

html[color-scheme="dark"] .contact-form input,
html[color-scheme="dark"] .contact-form textarea {
  background-color: #2e333a;
  color: #e4e4e4;
  border: 1px solid #444;
}

html[color-scheme="dark"] .contact-form button {
  background-color: #37996b !important; /* 强制覆盖按钮背景 */
}

html[color-scheme="dark"] .contact-form button:hover {
  background-color: #2c7a56 !important;
}

html[color-scheme="dark"] a[href$=".pdf"] {
  background-color: #37996b !important;
}

html[color-scheme="dark"] a[href$=".pdf"]:hover {
  background-color: #2c7a56 !important;
}

/* 暗色模式下，所有h2的边框颜色切换为绿色 */
html[color-scheme="dark"] h2 {
  border-left: 4px solid #2c7a56 !important; /* 覆盖所有h2边框颜色 */
}

/* 保持特定页面h2的文本颜色 */
html[color-scheme="dark"] .projects h2 {
  color: #aac5aa; /* 项目卡片标题颜色 */
}

html[color-scheme="dark"] .cv-page h2 {
  color: #f0f0f0; /* CV页面h2标题颜色 */
}

html[color-scheme="dark"] h2 {
  color: #f0f0f0 !important;
  border-left: 4px solid #2c7a56 !important;
}
/* ===== 媒体查询后备，确保自动模式下暗色模式样式生效 ===== */
@media (prefers-color-scheme: dark) {
  html:not([color-scheme="light"]) { /* 避免覆盖手动选择light模式 */
    nav {
      background-color: #2a2f33 !important;
      --border-color: oklch(50% 10% 140 / 30%);
    }

    nav a {
      color: #e4e4e4;
      border-right: 1px solid rgba(255, 255, 255, 0.1);
    }

    nav a.current::after {
      background-color: #6fd39e;
    }

    nav a:hover {
      background-color: color-mix(in oklch, #6fd39e, #2a2f33 85%);
      color: white;
    }

    nav a:hover::after {
      background-color: #7ee2a1;
    }

    .projects article,
    .cv-page main section article,
    section article {
      background-color: #2c3338 !important;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
      color: #e4e4e4;
    }

    .cv-page aside {
      background-color: #2c3338 !important;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
      color: #e4e4e4;
    }

    .cv-page aside h2,
    .cv-page aside .name {
      color: #f0f0f0;
    }

    .cv-page h2 {
      color: #f0f0f0;
    }

    .projects article h2 {
      color: #aac5aa;
    }

    .contact-form input,
    .contact-form textarea {
      background-color: #2e333a;
      color: #e4e4e4;
      border: 1px solid #444;
    }

    .contact-form button {
      background-color: #37996b !important;
    }

    .contact-form button:hover {
      background-color: #2c7a56 !important;
    }

    a[href$=".pdf"] {
      background-color: #37996b !important;
    }

    a[href$=".pdf"]:hover {
      background-color: #2c7a56 !important;
    }

    .color-scheme {
      background-color: rgba(30, 30, 30, 0.85) !important;
      color: white;
    }

    /* 自动模式下，所有h2的边框颜色切换为绿色 */
    h2 {
      border-left: 4px solid #2c7a56 !important;
    }

    /* 保持特定页面h2的文本颜色 */
    .projects h2 {
      color: #aac5aa;
    }

    .cv-page h2 {
      color: #f0f0f0;
    }
  }
}

/* ===== 主题切换器右上角样式 ===== */
.color-scheme {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 80%;
  font-family: inherit;
  background-color: rgba(255, 255, 255, 0.75);
  padding: 0.4em 0.8em;
  border-radius: 6px;
  z-index: 999;
  backdrop-filter: blur(6px);
  color: black;
}

html[color-scheme="dark"] .color-scheme {
  background-color: rgba(30, 30, 30, 0.85) !important;
  color: white;
}

input[type="range"] {
  width: 940px;
  max-width: 100%;
  margin-left: 1em;
  margin-right: 1em;
  /* 你可以根据实际情况再微调 */
}

/* Step 2.1：使用网格和子网格布局文件列表 */
.files > div {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
}

dt {
  grid-column: 1;
}

dd {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  align-content: start;
  gap: 0.15em;
  padding-top: 0.6em;
  margin-left: 0;
  justify-content: flex-end;
}

/* Step 2.2：单元可视化的点样式 */
.line {
  display: flex;
  width: 0.5em;
  aspect-ratio: 1;
  border-radius: 50%;
}

:global(body) {
  max-width: min(120ch, 80vw);
}

#scrollytelling {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
}

/* feel free to play with this to make your scrolly more seemless with your plot */
#scroll-container {
  grid-column: 1;
  position: relative;
  width: 95%;
  height: 350px;
  overflow-y: scroll;
  border: 1px solid #ccc;
  margin-bottom: 50px;
}

#chart {
  grid-column: 2;
}

#spacer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  background: none; /* transparent */
  pointer-events: none;
}

#items-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
}

.item {
  height: 100px; /* Updated from 30px to 100px */
  padding: 10px;
  box-sizing: border-box;
  border-bottom: 2px solid #eee;
}

#files {
  display: grid;
  grid-template-columns: 1fr 4fr;

  > div {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: subgrid;
  }

  dt {
    grid-column: 1;
  }

  dd {
    grid-column: 2;
    display: flex;
    flex-wrap: wrap;
    align-items: start;
    align-content: start;
    gap: 0.15em;
    padding-top: 0.6em;
    margin-left: 0;
  }
  }

  .loc {
    display: flex;
    width: 0.5em;
    aspect-ratio: 1;
    background: var(--color, steelblue); /* [Step 2.4] 使用 --color 变量 */
    border-radius: 50%;
  }

small {
  font-size: 0.8em;
  opacity: 0.7;
  display: block;
}

#scrolly-1 {
  width: 100%;
  margin: 0 auto;
  position: relative;
  display: flex;
  gap: 1rem;

  > * {
    flex: 1;
  }
}

#scatter-story {
  position: relative;
}

#scatter-plot {
  position: sticky;
  top: 0;
  left: 0;
  bottom: auto;
  height: 50vh;
}