/*
 * index.css - 当发网主页样式表
 * 版本：4.0
 * 描述：Web开发技术分享平台主页样式。纯 CSS Grid 响应式布局、无障碍优化（键盘焦点、
 *       深色模式、高对比度、减少动画）与打印样式
 * 作者：当发网
 * 版权所有：Dangfa.com
 */

/* ============================================ */
/* 现代化重置
/* ============================================ */

/* 全局盒模型重置 */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* 元素级重置：清除浏览器默认 margin/padding/border 与字号差异。
   现代浏览器中 header/nav/main/section/footer 原生即为块级元素，无需再声明 display:block。 */
html,
body,
div,
span,
h1,
h2,
h3,
h4,
h5,
h6,
p,
a,
img,
ul,
li,
header,
nav,
main,
section,
footer {
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  vertical-align: baseline;
}

/* ============================================ */
/* CSS 变量定义
/* ============================================ */

:root {
  /* 声明亮/暗配色，使原生控件（滚动条、复选框等）跟随系统深色模式 */
  color-scheme: light dark;

  /* 颜色系统 - 语义化命名 */
  --color-primary: #82255e;
  --color-primary-dark: #5a1840;
  --color-secondary: #b83b6a;
  --color-accent: #e8d8b0;
  --color-dark: #2a101b;
  --color-light: #f0e6dc;
  --color-white: #ffffff;

  /* 中性色调 */
  --color-gray-light: #f5f5f5;
  --color-gray-medium: #e0e0e0;

  /* 文本颜色系统 */
  --color-text-primary: #333333;
  --color-text-secondary: #595959;
  --color-text-on-primary: var(--color-white);
  --color-text-on-dark: var(--color-light);
  --color-link: var(--color-light);
  --color-link-hover: var(--color-primary-dark);

  /* 卡片专用颜色（浅色模式） */
  --color-card-bg: var(--color-accent);
  --color-card-text: var(--color-text-primary);
  --color-card-title: var(--color-primary);
  --color-card-border: rgba(130, 37, 94, 0.1);

  /* 排版系统 */
  --font-family:
    "微软雅黑", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --border-radius: 10px;

  /* 交互过渡：仅过渡会变化的属性，避免 transition: all 触发无关重绘 */
  --transition-default: color 0.3s ease, background-color 0.3s ease,
    border-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease,
    top 0.3s ease;
  --shadow-default: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-hover: 0 8px 15px rgba(0, 0, 0, 0.15);
  --focus-outline: 3px solid var(--color-accent);
  --focus-outline-offset: 2px;

  /* 卡片网格间距 */
  --card-gap: 1rem;
}

/* 深色模式变量 */
@media (prefers-color-scheme: dark) {
  :root {
    --color-primary: #6a1e4c;
    --color-primary-dark: #4d1838;
    --color-secondary: #8f2d5b;
    --color-accent: #e6d9b8;
    --color-dark: #1a0d13;
    --color-light: #f0e6d8;
    --color-gray-light: #2d2d2d;
    --color-gray-medium: #404040;

    /* 深色模式文本调整 */
    --color-text-primary: #f0f0f0;
    --color-text-secondary: #b3b3b3;
    --color-text-on-dark: var(--color-light);
    --color-link: var(--color-accent);
    --color-link-hover: var(--color-light);

    /* 深色模式卡片专用颜色 */
    --color-card-bg: #2a1a25;
    --color-card-text: #f0e6dc;
    --color-card-title: #e6d9b8;
    --color-card-border: rgba(230, 217, 184, 0.2);

    --shadow-default: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 8px 15px rgba(0, 0, 0, 0.5);
  }
}

/* 高对比度模式变量 */
@media (prefers-contrast: more) {
  :root {
    --color-primary: #5a1840;
    --color-primary-dark: #000000;
    --color-secondary: #333333;
    --color-accent: #000000;
    --color-dark: #000000;
    --color-light: #ffffff;
    --color-gray-light: #ffffff;
    --color-gray-medium: #cccccc;

    /* 高对比度文本 */
    --color-text-primary: #000000;
    --color-text-secondary: #333333;
    --color-text-on-primary: #ffffff;
    --color-text-on-dark: #ffffff;

    /* 高对比度卡片专用颜色 */
    --color-card-bg: #ffffff;
    --color-card-text: #000000;
    --color-card-title: #000000;
    --color-card-border: #000000;

    /* 高对比度专用强调色（普通模式下不使用） */
    --color-high-contrast-yellow: #ffff00;
    --focus-outline: 3px solid var(--color-high-contrast-yellow);
  }
}

/* ============================================ */
/* 基础元素样式
/* ============================================ */

html {
  font-size: 16px;
  scroll-behavior: smooth;
  scroll-padding-top: 80px;
}

body {
  font-family: var(--font-family);
  line-height: 1.6;
  color: var(--color-text-primary);
  background-color: var(--color-gray-light);
}

/* 容器：纵向弹性布局实现粘性页脚（内容不足时页脚也贴底） */
.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  margin: 0 auto;
  padding: 0 15px;
}

/* 全局文本颜色 */
p,
h1,
h2,
h3,
h4,
h5,
h6,
li {
  color: var(--color-text-primary);
}

/* 链接基础样式 */
a {
  color: var(--color-link);
  text-decoration: none;
  transition: var(--transition-default);
}

/* 文本选择样式 */
::selection {
  background-color: var(--color-primary);
  color: var(--color-white);
}

/* ============================================ */
/* 无障碍组件
/* ============================================ */

/* 跳过链接：键盘聚焦时从屏幕外滑入 */
.skip-link {
  position: absolute;
  top: -44px;
  left: 6px;
  background: var(--color-primary);
  color: var(--color-white);
  padding: 8px 12px;
  border-radius: var(--border-radius);
  text-decoration: none;
  z-index: 1000;
  transition: var(--transition-default);
  font-weight: bold;
}

.skip-link:focus {
  top: 6px;
  outline: var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
}

/* 屏幕阅读器专用类（现代写法，兼容不支持 clip-path 的浏览器） */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ============================================ */
/* 页眉与导航
/* ============================================ */

header {
  background-color: var(--color-primary);
  color: var(--color-accent);
  text-align: center;
  padding: 1.5rem 1rem 0;
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-default);
}

header h1 {
  position: relative;
  z-index: 1;
  margin-top: 1.5rem;
  color: var(--color-text-on-primary);
  line-height: 3rem;
  background-color: var(--color-dark);
}

.logo-container {
  position: relative;
  display: inline-block;
}

.logo {
  max-width: 260px;
  height: auto;
  display: block;
  margin: 0 auto;
}

/* 主导航 */
.main-nav {
  background-color: var(--color-primary-dark);
}

.nav-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  list-style: none;
  padding: 0.75rem 0;
}

.nav-item {
  margin: 0.25rem;
}

.nav-link {
  display: block;
  padding: 0.5rem 1rem;
  color: var(--color-text-on-dark);
  text-decoration: none;
  border-radius: 20px;
  transition: var(--transition-default);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
}

.nav-link:hover {
  background-color: var(--color-accent);
  color: var(--color-primary-dark);
}

/* 键盘与鼠标聚焦均显示焦点环（旧浏览器兜底，hover 不再清除焦点样式） */
.nav-link:focus {
  outline: var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
}

/* 支持 :focus-visible 时：仅键盘导航显示焦点环，鼠标点击不显示 */
@supports selector(:focus-visible) {
  .nav-link:focus {
    outline: none;
  }

  .nav-link:focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--focus-outline-offset);
  }
}

/* 高对比度模式下导航链接描边 */
@media (prefers-contrast: more) {
  .nav-link {
    border: 1px solid var(--color-light);
  }
}

/* ============================================ */
/* 主要内容区域
/* ============================================ */

main {
  background-color: var(--color-secondary);
  padding: 1.5rem 1rem;
  flex-grow: 1;
}

/* ============================================ */
/* 技术卡片组件 - 纯 CSS Grid
/* ============================================ */

.tech-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--card-gap);
  align-items: stretch;
}

.tech-card {
  display: flex;
  flex-direction: column;
  min-width: 0; /* 防止长内容撑破网格轨道 */
  background-color: var(--color-card-bg);
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--shadow-default);
  border: 1px solid var(--color-card-border);
  position: relative;
  transition: var(--transition-default);
}

/* 卡片顶部装饰条 */
.tech-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: var(--color-primary);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
}

.tech-card a {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  padding: 1.25rem;
  color: var(--color-card-text);
  text-decoration: none;
}

/* 卡片标题 */
.tech-card h4 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: inline-block;
  font-style: italic;
  border-bottom: 2px solid var(--color-card-title);
  text-align: center;
  width: 100%;
  padding-bottom: 0.5rem;
  color: var(--color-card-title);
}

.tech-card p {
  margin-bottom: 1rem;
  text-align: justify;
  line-height: 1.7;
  font-size: 0.95rem;
  color: var(--color-card-text);
}

.tech-card .description {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.read-more-container {
  display: flex;
  justify-content: flex-end;
  margin-top: auto;
  padding-top: 1rem;
}

.tech-card .read-more {
  display: inline-flex;
  align-items: center;
  font-weight: bold;
  color: var(--color-dark);
  gap: 0.25rem;
  font-size: 0.9rem;
  transition: var(--transition-default);
}

.arrow {
  font-weight: bold;
  margin-left: 0.25rem;
}

/* 卡片交互状态 */
.tech-card:hover::before,
.tech-card:focus-within::before {
  transform: scaleX(1);
}

.tech-card:hover,
.tech-card:focus-within {
  transform: translateY(-5px);
  box-shadow: var(--shadow-hover);
}

/* 聚焦时绘制外圈，并提升层级避免被相邻卡片遮挡 */
.tech-card:focus-within {
  box-shadow: 0 0 0 3px var(--color-primary), var(--shadow-hover);
  z-index: 2;
}

.tech-card:hover .read-more,
.tech-card:focus-within .read-more {
  transform: translateX(5px);
  color: var(--color-primary-dark);
}

/* 深色模式下卡片文字交互色 */
@media (prefers-color-scheme: dark) {
  .tech-card .read-more {
    color: var(--color-card-title);
  }

  .tech-card:hover .read-more,
  .tech-card:focus-within .read-more {
    color: var(--color-light);
  }
}

/* 链接焦点：兜底方案（所有聚焦方式都显示焦点环） */
.tech-card a:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--border-radius);
}

/* 支持 :focus-visible 时：仅键盘导航显示焦点环 */
@supports selector(:focus-visible) {
  .tech-card a:focus {
    outline: none;
  }

  .tech-card a:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--border-radius);
  }
}

/* 高对比度模式下的卡片 */
@media (prefers-contrast: more) {
  .tech-card {
    border: 2px solid #000;
  }

  .tech-card h4 {
    border-bottom: 2px solid #000;
  }

  .tech-card .read-more {
    color: #000;
  }

  .tech-card a {
    color: #0000ee;
  }

  .tech-card:focus-within {
    box-shadow: 0 0 0 4px var(--color-high-contrast-yellow),
      0 4px 8px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--color-high-contrast-yellow);
  }
}

/* ============================================ */
/* 页脚样式
/* ============================================ */

footer {
  background-color: var(--color-dark);
  color: var(--color-light);
  text-align: center;
  padding: 1.25rem 1rem;
  border-radius: 0 0 var(--border-radius) var(--border-radius);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

footer p {
  margin: 0.5rem 0;
  font-size: 0.9rem;
  color: var(--color-text-on-dark);
}

footer a {
  color: var(--color-link);
  text-decoration: none;
  transition: var(--transition-default);
}

footer a:hover {
  text-decoration: underline;
  color: var(--color-accent);
}

/* ============================================ */
/* 响应式设计 - 移动设备 (< 400px)
/* ============================================ */

@media (max-width: 399.98px) {
  .container {
    padding: 0 10px;
  }

  header {
    padding: 1.25rem 0.5rem 0;
  }

  .logo {
    max-width: 220px;
  }

  /* 导航纵向堆叠，扩大触控点击区 */
  .nav-list {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .nav-item {
    margin: 0;
    width: 100%;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  .nav-item:first-child {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .nav-link {
    text-align: center;
    border-radius: var(--border-radius);
    padding: 0.75rem 1rem;
    min-height: 44px; /* 无障碍最小触控高度 */
  }

  .tech-card a {
    padding: 1rem;
  }

  .tech-card h4 {
    font-size: 1.3rem;
  }

  .tech-card:focus-within {
    transform: translateY(-3px);
    box-shadow: 0 0 0 2px var(--color-primary), var(--shadow-hover);
  }
}

/* ============================================ */
/* 响应式设计 - 小屏设备 (400px - 575px)
/* ============================================ */

@media (min-width: 400px) and (max-width: 575.98px) {
  .nav-list {
    max-width: 100%;
  }

  .nav-item {
    width: calc(50% - 0.5rem);
    margin: 0.25rem;
  }

  .nav-link {
    text-align: center;
    padding: 0.6rem 0.5rem;
    font-size: 0.9rem;
  }
}

/* ============================================ */
/* 响应式设计 - 小型设备 (576px - 767px)
/* ============================================ */

@media (min-width: 576px) and (max-width: 767.98px) {
  .container {
    max-width: 540px;
    padding: 0 15px;
  }

  header {
    padding: 1.75rem 1rem 0;
  }

  .logo {
    max-width: 280px;
  }

  main {
    padding: 1.75rem 1rem;
  }

  .tech-cards {
    --card-gap: 1.25rem;
  }

  .tech-card a {
    padding: 1.5rem;
  }

  .tech-card h4 {
    font-size: 1.5rem;
  }

  footer {
    padding: 1.5rem 1rem;
  }

  /* 导航：三列网格 */
  .nav-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    justify-items: center;
  }

  .nav-item {
    margin: 0;
    width: 100%;
    max-width: 160px;
  }

  .nav-link {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    text-align: center;
    border-radius: var(--border-radius);
    width: 100%;
  }
}

/* ============================================ */
/* 响应式设计 - 中等设备 (768px - 991px)
/* ============================================ */

@media (min-width: 768px) and (max-width: 991.98px) {
  .container {
    max-width: 720px;
  }

  header {
    padding: 2rem 1rem 0;
  }

  .logo {
    max-width: 300px;
  }

  main {
    padding: 2rem 1rem;
  }

  /* 卡片：两列 */
  .tech-cards {
    --card-gap: 1.5rem;
    grid-template-columns: repeat(2, 1fr);
  }

  .tech-card h4 {
    font-size: 1.5rem;
  }

  .tech-card p {
    font-size: 1rem;
  }

  /* 导航：三列两行 */
  .nav-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    justify-items: center;
  }

  .nav-item {
    margin: 0;
    width: 100%;
    max-width: 180px;
  }

  .nav-link {
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
    text-align: center;
    border-radius: var(--border-radius);
    width: 100%;
  }
}

/* ============================================ */
/* 响应式设计 - 大屏设备 (≥ 992px)
/* ============================================ */

@media (min-width: 992px) {
  .container {
    max-width: 960px;
    padding: 0 15px;
  }

  header {
    padding: 2.5rem 1rem 0;
  }

  .logo {
    max-width: 320px;
  }

  main {
    padding: 2.5rem 1rem;
  }

  /* 卡片：保持两列，1200px 起切换为三列 */
  .tech-cards {
    --card-gap: 1.75rem;
    grid-template-columns: repeat(2, 1fr);
  }

  .tech-card a {
    padding: 1.75rem;
  }

  /* 导航：单行不换行 */
  .nav-list {
    padding: 1.25rem 0;
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
  }

  .nav-item {
    margin: 0.25rem;
    width: auto;
    max-width: none;
  }

  .nav-link {
    padding: 0.6rem 1.5rem;
    font-size: 1rem;
  }
}

/* ============================================ */
/* 响应式设计 - 超大设备 (≥ 1200px)
/* ============================================ */

@media (min-width: 1200px) {
  .container {
    max-width: 1140px;
  }

  .logo {
    max-width: 340px;
  }

  /* 卡片：三列 */
  .tech-cards {
    --card-gap: 2rem;
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ============================================ */
/* 响应式设计 - 特大设备 (≥ 1400px)
/* ============================================ */

@media (min-width: 1400px) {
  .container {
    max-width: 1320px;
  }

  header {
    padding: 3rem 1rem 0;
  }

  .logo {
    max-width: 360px;
  }

  .tech-cards {
    --card-gap: 2.25rem;
  }
}

/* ============================================ */
/* 无障碍优化 - 减少动画
/* ============================================ */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .tech-card:hover,
  .tech-card:focus-within {
    transform: none;
  }

  .tech-card:focus-within {
    box-shadow: 0 0 0 4px var(--color-primary), 0 2px 4px rgba(0, 0, 0, 0.2);
  }

  .tech-card:hover .read-more,
  .tech-card:focus-within .read-more {
    transform: none;
  }
}

/* ============================================ */
/* 打印样式
/* ============================================ */

@media print {
  * {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  body {
    color: #000;
  }

  p,
  h1,
  h2,
  h3,
  h4,
  h5,
  h6,
  li {
    color: #000;
  }

  .tech-card {
    border: 1px solid #000;
    page-break-inside: avoid;
    break-inside: avoid;
    margin-bottom: 1rem;
    background-color: #ffffff !important;
  }

  .tech-card h4,
  .tech-card p {
    color: #000;
  }

  .tech-card h4 {
    border-bottom: 1px solid #000;
  }

  /* 打印时显示链接地址，排除页内锚点与 javascript: 伪链接 */
  a[href]:not([href^="#"]):not([href^="javascript"]):after {
    content: " (" attr(href) ")";
  }

  /* 隐藏非必要元素：导航、阅读更多按钮、跳过链接（纸质媒体无交互） */
  header,
  footer {
    background: #ffffff !important;
    color: black !important;
  }

  .read-more-container,
  .main-nav,
  .skip-link {
    display: none;
  }
}
