/* home.css — 首页：Bento 卡片系统、英雄/社交/项目/技能/时间线/友链卡片、3D 翻转卡、Email 卡、首页博客卡片。 */

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 20px;
}

.card {
  background-color: var(--card-bg);
  border-radius: 28px;
  padding: 30px;
  display: flex;
  flex-direction: column;
  /* 卡片本身可能是 <a>（#my-projects 就是这样）。不显式写 none 的话，
     浏览器默认的链接下划线会画在卡片文字下面，看起来像一条多余的分隔线。 */
  text-decoration: none;
  transition:
    transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
    background-color 220ms ease,
    border-color 220ms ease,
    box-shadow 220ms ease;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border-color);

  -webkit-mask-image: -webkit-radial-gradient(white, black);
  mask-image: radial-gradient(white, black);
}

.card-project,
.card-map {
  border: none;
  background-size: cover;
  background-position: center;
}

.card:active {
  transform: scale(0.96) translateY(2px);
  transition: 0.1s;
}

.card:hover {
  transform: translateY(-4px);
  background-color: var(--card-hover);
}

.card-motion-web {
  grid-column: span 6;
  min-height: 280px;
  justify-content: space-between;
  overflow: hidden;
  color: #f6f1e7;
  text-decoration: none;
  background:
    radial-gradient(ellipse at 84% 18%, rgba(215, 104, 47, 0.62), transparent 34%),
    linear-gradient(135deg, #1b211e 0%, #101411 58%, #25241e 100%);
  border-color: rgba(236, 204, 163, 0.2);
}

.card-motion-web::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(245, 229, 199, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(245, 229, 199, 0.08) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: linear-gradient(110deg, #000 0%, transparent 88%);
  pointer-events: none;
}

.motion-web-title,
.motion-web-description {
  position: relative;
  z-index: 1;
}

.motion-web-title {
  font-size: clamp(2rem, 3.2vw, 3.1rem);
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: -0.01em;
}

.motion-web-description {
  margin-top: 12px;
  color: rgba(246, 241, 231, 0.76);
  font-size: 0.92rem;
}

.card-motion-web:focus-visible {
  outline: 3px solid var(--accent-color);
  outline-offset: 4px;
}

/* --- 5. 英雄卡片 --- */
.card-hero {
  grid-column: span 12;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 50px;
}

.hero-text h1 {
  font-size: clamp(3rem, 5vw, 4.6rem);
  font-weight: 700;
  line-height: 1.08;
  margin: 0;
  letter-spacing: -0.035em;
  color: var(--text-primary);
  text-wrap: balance;
}

.avatar {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid rgba(255, 255, 255, 0.2);
}

/* --- 6. 社交卡片 --- */
.card-social {
  grid-column: span 1;
  aspect-ratio: 1/1;
  justify-content: center;
  align-items: center;
  text-decoration: none;
}

.card-social i {
  font-size: 3.5rem;
  color: var(--text-primary);
}

/* --- 7. 项目卡片 --- */
.card-project {
  grid-column: span 6;
  min-height: 280px;
  justify-content: flex-end;
  background-size: cover;
  background-position: center;
  border: none;
}

.card-project::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.9) 0%,
    rgba(0, 0, 0, 0.4) 60%,
    transparent 100%
  );
  z-index: 1;
  pointer-events: none;
}

.project-info {
  z-index: 2;
  color: #ffffff;
  text-shadow: 0 2px 15px rgba(0, 0, 0, 1);
}

.project-title {
  font-size: 1.3rem;
  font-weight: 700;
}

.project-desc {
  font-size: 0.95rem;
  opacity: 0.9;
}

/* 背景图类 */
.bg-project-1 {
  background-image: url("/img/project-1.jpg");
  background-size: cover;
  background-position: center;
}

.bg-project-3 {
  background-image: url("/img/project-3.jpg");
  background-size: cover;
  background-position: center;
}

/* Email 卡片专用样式 */
.card-email {
  background-color: #2997ff;
  color: white;
}

.card-label {
  font-size: 0.9rem;
  margin-top: 5px;
  display: block;
}

.project-title--mb {
  margin-bottom: 5px;
}

/* --- 3D 翻转卡片 --- */

/* 舞台容器 */
.card-social-container {
  grid-column: span 3;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  perspective: 1000px;
  aspect-ratio: 1/1;
}

.card-social-container:hover,
.card-social-container:focus-within {
  background-color: transparent;
  box-shadow: none;
  transform: none;
}

/* 翻转主体 */
.card-social-flip {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 480ms cubic-bezier(0.2, 0.8, 0.2, 1);
  cursor: pointer;
  text-decoration: none;
  border-radius: 28px;
}

.card-social-container:hover .card-social-flip,
.card-social-container:focus-within .card-social-flip {
  transform: rotateY(180deg);
}

/* 正面与背面 */
.flip-front,
.flip-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;
  border-radius: 28px;
  overflow: hidden;
  -webkit-mask-image: -webkit-radial-gradient(white, black);
  mask-image: radial-gradient(white, black);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 0.9rem;
  font-weight: 500;
  background-color: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid transparent;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.flip-front i {
  font-size: 3.5rem;
  margin-bottom: 8px;
}

.flip-back {
  transform: rotateY(180deg);
  background-color: var(--card-hover);
}

.mini-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  margin-bottom: 8px;
  border: 3px solid rgba(255, 255, 255, 0.2);
}

/* Email 卡片配色 */
.email-card .flip-front {
  background-color: #2997ff;
  color: white;
  border: none;
}

.email-card .flip-back {
  background-color: #0071e3;
  color: white;
  border: none;
  padding: 10px;
  text-align: center;
}

.avatar {
  animation: avatar-breathe 4s infinite ease-in-out;
  border: 4px solid rgba(255, 255, 255, 0.2);
}

/* --- 卡片悬停逻辑：动静分离 --- */

.card {
  transition:
    transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1),
    background-color 220ms ease,
    border-color 220ms ease,
    box-shadow 220ms ease;
}

.card:not(.card-social-container):hover {
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.3);
  border-color: color-mix(in srgb, var(--accent-color), var(--border-color) 58%);
  z-index: 10;
}

[data-theme="light"] .card:not(.card-social-container):hover {
  box-shadow: 0 18px 36px rgba(24, 48, 58, 0.13);
  border-color: color-mix(in srgb, var(--accent-color), var(--border-color) 66%);
}

/* 浅色模式下卡片默认就要有边界感。底色是淡蓝、卡片是白，明度差本来就够，
   再补一道很淡的投影，卡片才是"浮在页面上"而不是"印在页面上"。
   深色模式不需要——那里的明度差比这里大得多。 */
[data-theme="light"] .card:not(.card-social-container) {
  box-shadow: 0 1px 2px rgba(20, 45, 70, 0.05), 0 10px 28px rgba(20, 45, 70, 0.07);
}

/* 翻转卡（GitHub / Email）的可见面不是 .card，而是 .flip-front / .flip-back，
   它们的 border 默认是 transparent，浅色下等于没有边，一并补上。 */
[data-theme="light"] .flip-front,
[data-theme="light"] .flip-back {
  border-color: var(--border-color);
  box-shadow: 0 1px 2px rgba(20, 45, 70, 0.05), 0 10px 28px rgba(20, 45, 70, 0.07);
}

.card-social-container:hover {
  transform: none;
  box-shadow: none;
  background: transparent;
}

/* --- 页面专用样式 --- */
body.index-page .grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 20px;
}

@media (max-width: 768px) {

  body.index-page .grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 0 20px;
  }
  body.index-page .card-hero {
    display: flex;
    flex-direction: column-reverse;
    text-align: center;
    padding: 40px 20px;
    height: auto;
  }
  body.index-page .card-hero .avatar {
    margin-bottom: 25px;
  }
  body.index-page .hero-text h1 {
    font-size: 2.2rem;
    margin-top: 10px;
  }
  body.index-page .card,
  body.index-page .card-project,
  body.index-page .card-social-container {
    width: 100%;
    grid-column: auto;
  }
  body.index-page .card-project {

    min-height: 240px;
    background-attachment: scroll;
  }
  body.index-page {
    overflow-x: hidden;
    width: 100%;
    position: relative;
  }
}

/* 统一边框厚度 */
.email-card .flip-front,
.email-card .flip-back {
  border: 1px solid rgba(255, 255, 255, 0.01);
  background-clip: padding-box;
}

/* --- 首页新页面入口小卡（标签 / 统计 / 壁纸） ---
   一排三张：12 列 grid 每张 span 4。全局 .card 的 3D 倾斜对它们同样生效，
   不用另写 hover。 */
.card-mini {
  grid-column: span 4;
  min-height: 160px;
  justify-content: space-between;
  text-decoration: none;
  color: var(--text-primary);
}

.card-mini-icon {
  color: var(--accent-color);
  margin-right: 8px;
  vertical-align: -2px;
}

/* 宽卡（归档/留言板）：一行放两张，与上面三张小卡补满页脚入口。 */
.card-mini--wide {
  grid-column: span 6;
}

/* 壁纸卡的轮换照片：两层 img 交替淡入淡出（main.js 驱动）。
   遮罩沿用博客卡的配方——左深右浅的渐变，保证白字在任何照片上都可读；
   照片模式下文字必须强制白色：主题变量的深色文字在照片上看不清。 */
.card-mini--photo {
  position: relative;
  overflow: hidden;
}

.card-mini-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .8s ease;
  z-index: 0;
}

.card-mini-photo.is-showing {
  opacity: 1;
}

.card-mini--photo::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    rgba(12, 14, 18, 0.82) 0%,
    rgba(12, 14, 18, 0.45) 55%,
    rgba(12, 14, 18, 0.2) 100%
  );
  z-index: 1;
}

.card-mini--photo .project-info {
  position: relative;
  z-index: 2;
}

.card-mini--photo .project-title,
.card-mini--photo .project-desc {
  color: #fff;
}

.card-mini--photo .project-title {
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.card-mini--photo .project-desc {
  color: rgba(255, 255, 255, 0.9);
}

.card-mini--photo .card-mini-icon {
  color: #fff;
}

[data-theme="light"] .card-mini {
  box-shadow: 0 1px 2px rgba(20, 45, 70, .05), 0 10px 28px rgba(20, 45, 70, .07);
}

/* --- 首页博客卡片 --- */

.card-blog {
  grid-column: span 6;
  background-image: url("/img/map.jpg");
  background-size: cover;
  background-position: center;
  border: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 25px;
  position: relative;
  text-decoration: none;
  overflow: hidden;
}

.card-blog::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.85) 0%,
    rgba(0, 0, 0, 0.2) 60%,
    transparent 100%
  );
  z-index: 1;
  pointer-events: none;
}

.card-blog .project-info {
  z-index: 2;
  position: relative;
}

.card-blog .project-title {
  color: #fff;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.card-blog .project-desc {
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.95rem;
}

/* 时间线 */
/* 说明：.card-timeline / .timeline-* 原为首页「学习之路」卡，现首页已下线该卡；
   site.html 的更新记录仍在用这套 timeline-* 类，所以只删了 .card-timeline 这一层外壳。 */
.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 6px;
}

.timeline-item {
  display: flex;
  gap: 14px;
  align-items: baseline;
  padding-left: 16px;
  border-left: 2px solid var(--accent-color);
  position: relative;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-color);
}

.timeline-date {
  color: var(--accent-color);
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 65px;
}

.timeline-text {
  color: var(--text-primary);
  font-size: 0.92rem;
}

.home-blog-badge-wrap {
  margin-top: 12px;
}

.home-blog-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.25);
  padding: 4px 12px;
  border-radius: 20px;
  color: white;
  font-size: 0.75rem;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.email-back-icon {
  font-size: 2rem;
  margin-bottom: 5px;
}

.email-back-address {
  font-size: 0.8rem;
  word-break: break-all;
  font-weight: 600;
}

/* =========================================
   手机端强制适配
   ========================================= */
@media (max-width: 768px) {

  .grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .card-hero {
    display: flex;
    flex-direction: column-reverse;
    text-align: center;
    padding: 30px 20px;
    height: auto;
  }

  .hero-text h1 {
    font-size: 2.2rem;
    margin-top: 15px;
  }

  .card-project,
  .card-social-container,
  .card-motion-web,
  .card-blog,
  .card-mini,
  #my-skills {
    grid-column: span 1;
    width: 100%;
  }

  .card-project,
  .card-blog {
    min-height: 220px;
    background-attachment: scroll;
  }
}

/* --- 3D 卡片高光扫光 --- */
.card {
  transform-style: preserve-3d;
}

@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {

  .card.is-tilting {
    transform: perspective(1000px) rotateX(var(--tilt-x, 0deg))
      rotateY(var(--tilt-y, 0deg)) scale3d(1.02, 1.02, 1.02);
    transition: none;
  }

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

.logo-icon:focus-visible,
.nav-theme-toggle:focus-visible,
.back-to-top:focus-visible,
.card-social-flip:focus-visible {
  outline: 3px solid var(--accent-color);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {

  .avatar {
    animation: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {

  .card:not(.card-social-container):hover,
  .card.is-tilting,
  .card-social-container:hover .card-social-flip,
  .card-social-container:focus-within .card-social-flip {
    transform: none;
  }
}

.card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 28px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.15) 0%,
    transparent 40%,
    transparent 100%
  );
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

/* --- Hero 指针交互：分层视差 + 光标聚光 ---
   main.js 把归一化到 -1..1 的指针坐标写进 --hero-x / --hero-y，这里消费。
   两点取舍：
   · 视差加在子元素上，不动卡片本身——卡片的 transform 已经被通用 3D 倾斜占用了。
   · ::before 被 .card::after 之外的第三条规则用掉了？没有，.card::before 是空的，
     所以聚光用 ::before，和已有的高光 ::after 互不干扰。 */
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {

  .card-hero .hero-text,
  .card-hero .avatar {
    transition: transform 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
  }

  /* 文字位移小、头像位移大 = 文字近、头像远，形成层次 */
  .card-hero .hero-text {
    transform: translate3d(calc(var(--hero-x, 0) * -5px), calc(var(--hero-y, 0) * -4px), 0);
  }

  .card-hero .avatar {
    transform: translate3d(calc(var(--hero-x, 0) * 11px), calc(var(--hero-y, 0) * 9px), 0);
  }

  .card-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 28px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 320ms ease;
    background: radial-gradient(
      300px circle at calc(50% + var(--hero-x, 0) * 190px) calc(50% + var(--hero-y, 0) * 150px),
      color-mix(in srgb, var(--accent-color), transparent 87%),
      transparent 70%
    );
  }

  .card-hero:hover::before,
  .card-hero:focus-within::before {
    opacity: 1;
  }
}

.card:hover::after {
  opacity: 1;
}

/* --- 翻转卡片最终保障 --- */
.card-social-container,
.card-social-container:hover,
.card-social-container:focus-within,
.card-social-container:active {
  background: transparent;
  background-color: transparent;
  box-shadow: none;
  border: none;
  outline: none;
  transform: none;
}

.flip-front,
.flip-back {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  overflow: hidden;
}

.card-social-flip {
  transform-style: preserve-3d;
  backface-visibility: visible;
}

.flip-back {
  transform: rotateY(180deg);
}

/* 清除翻转卡片的 ::after 残留光泽 */
.card-social-container::after {
  display: none !important;
  content: none !important;
  opacity: 0 !important;
}