/* Grid layout for cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 25px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 0;
  /* 优化渲染性能 */
  contain: layout style paint;
}

/* --- LIGHT MODE STYLES (DEFAULT) --- */

.card {
  /* Define light mode colors as CSS variables within the card scope */
  --card-bg-color: rgba(255, 255, 255, 0.6);
  --card-border-color: rgba(255, 255, 255, 0.8);
  --text-color-primary: #333;
  --text-color-secondary: #555;
  --shadow-color: rgba(0, 0, 0, 0.1);
  --wiki-btn-bg-color: #4f88c6;
  --wiki-btn-bg-hover-color: #357ab8;
  --wiki-btn-text-color: white;

  /* Common structural and aesthetic styles */
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  background-color: var(--card-bg-color);
  border: 1px solid var(--card-border-color);
  box-shadow: 0 8px 32px 0 var(--shadow-color);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
}

/* --- DARK MODE STYLES (ACTIVATED BY THEME'S .darkmode class) --- */

body.darkmode .card {
  /* Override the CSS variables for dark mode */
  --card-bg-color: rgba(40, 40, 40, 0.6);
  --card-border-color: rgba(255, 255, 255, 0.1);
  --text-color-primary: #f0f0f0;
  --text-color-secondary: #aaa;
  --shadow-color: rgba(0, 0, 0, 0.4);
  --wiki-btn-bg-color: #357ab8;
  --wiki-btn-bg-hover-color: #4f88c6;
}

/* Dark mode button styles */
body.darkmode .wiki-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-color-primary);
}

body.darkmode .wiki-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* --- COMMON CARD STYLES THAT USE THE VARIABLES --- */

.card:hover {
  transform: translateY(-5px) scale(1.02);
  box-shadow: 0 12px 40px 0 var(--shadow-color);
}

.card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-image: var(--bg);
  background-size: cover;
  background-position: center;
  filter: blur(15px) brightness(0.9);
  transform: scale(1.15);
  z-index: -1;
  opacity: 0.5;
}

.card-content {
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex-grow: 1;
}

.card img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--card-border-color);
  box-shadow: 0 0 10px var(--shadow-color);
  margin-bottom: 15px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover img {
  transform: scale(1.05);
  box-shadow: 0 0 20px var(--shadow-color);
}

.card .caption {
  display: none !important;
}

.card h2 {
  font-size: 1.25em;
  margin: 10px 0 2px;
  color: var(--text-color-primary);
  font-weight: 600;
}

.card .subname {
  font-size: 0.9em;
  color: var(--text-color-secondary);
  margin: 0 0 15px;
  font-style: italic;
}

.card .intro {
  font-size: 0.95em;
  color: var(--text-color-primary);
  line-height: 1.5;
  margin: 0 0 20px;
  flex-grow: 1;
}

.wiki-btn {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text-color-primary);
  text-decoration: none;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.9em;
  font-weight: 500;
  transition: all 0.3s ease;
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
}

.wiki-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  transition: left 0.5s ease;
}

.wiki-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.wiki-btn:hover::before {
  left: 100%;
}

/* 键盘导航支持 */
.wiki-btn:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 2px;
}

/* 图片懒加载优化 */
.card img {
  loading: lazy;
}

/* 减少重绘优化 */
.card {
  will-change: transform;
}

.card:hover {
  will-change: auto;
}
