/* =========================================
   SafeW 全站共享样式
   ========================================= */

/* === Design Tokens & Variables === */
:root {
  /* 基础色板 */
  --color-dark: #141838;
  --color-paper: #FCFCFD;
  --color-paper-light: #F4F5F8;
  --color-body: #151723;
  --color-brand: #142CEB;
  --color-accent: #6EAFED;

  /* 结构性 Token */
  --radius-card: 8px;
  --radius-btn: 6px;
  --card-border: 0;
  --card-shadow: none;
  --section-y: clamp(5rem, 10vw, 9rem);
  --gap: clamp(1.5rem, 3vw, 2.5rem);
  --content-max: 1120px;

  /* 语义化变量（默认纸面） */
  --bg-section: var(--color-paper);
  --bg-section-alt: var(--color-paper-light);
  --text-primary: var(--color-body);
  --text-inverse: var(--color-paper);
  --hl-color: var(--color-brand);
  --btn-bg: var(--color-brand);
  --btn-text: var(--color-paper);
  --border-subtle: rgba(0, 0, 0, 0.06);
}

/* 深色面上下文覆盖 */
.bg-dark {
  --bg-section: var(--color-dark);
  --bg-section-alt: #1A1F45;
  --text-primary: #FCFCFD;
  --text-inverse: var(--color-dark);
  --hl-color: var(--color-accent);
  --btn-bg: var(--color-accent);
  --btn-text: var(--color-dark);
  --border-subtle: rgba(255, 255, 255, 0.08);
}

/* 浅色卡片在深色面上的取色回正 */
.card-light {
  --bg-section: var(--color-paper);
  --bg-section-alt: var(--color-paper-light);
  --text-primary: var(--color-body);
  --hl-color: var(--color-brand);
  --btn-bg: var(--color-brand);
  --btn-text: var(--color-paper);
  --border-subtle: rgba(0, 0, 0, 0.06);
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  font-size: 16px;
  line-height: 1.75;
  color: var(--text-primary);
  background: var(--bg-section);
  overflow-x: hidden;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--hl-color); text-decoration: none; transition: opacity 0.2s; }
a:hover { opacity: 0.85; }
ul, ol { list-style: none; }

/* === Typography === */
h1, h2, h3, h4 { font-weight: 500; line-height: 1.15; letter-spacing: -0.01em; color: var(--text-primary); }
h1 { font-size: clamp(2.6rem, 6.4vw, 5rem); text-wrap: balance; }
h2 { font-size: clamp(1.6rem, 3vw, 2.4rem); margin-bottom: 0.6em; }
h3 { font-size: clamp(1.2rem, 2vw, 1.5rem); margin-bottom: 0.5em; }
p { margin-bottom: 1em; max-width: 38em; }
small { font-size: 0.875rem; opacity: 0.8; }
.badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 0.5em;
  color: var(--hl-color);
  text-transform: uppercase;
}
.hl { color: var(--hl-color); font-weight: 600; }

/* === Layout Containers === */
.container {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: 1.5rem;
}
.section {
  padding-block: var(--section-y);
  background: var(--bg-section);
}
.section-alt {
  background: var(--bg-section-alt);
}

/* === Header & Nav === */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-subtle);
}
.bg-dark .site-header { background: rgba(20, 24, 56, 0.95); }
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 600; color: var(--text-primary); }
.brand img { width: 32px; height: 32px; object-fit: contain; }
.nav-list { display: flex; gap: 24px; }
.nav-link { color: var(--text-primary); font-weight: 500; padding: 8px 0; position: relative; }
.nav-link[aria-current="page"] { color: var(--hl-color); }
.nav-link[aria-current="page"]::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--hl-color);
  border-radius: 2px;
}
.header-cta { margin-left: 16px; }
@media (max-width: 768px) {
  .nav-list { display: none; }
}

/* === Footer === */
.site-footer {
  background: var(--color-dark);
  color: var(--color-paper);
  padding: var(--section-y) 0 calc(var(--section-y) - 32px);
}
.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--gap);
  margin-bottom: var(--gap);
}
.footer-col h4 { color: var(--color-paper); margin-bottom: 12px; font-size: 1rem; }
.footer-col a { color: rgba(255, 255, 255, 0.75); display: block; margin-bottom: 8px; }
.footer-col a:hover { color: var(--color-paper); }
.footer-bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 24px;
  text-align: center;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.5);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 52px;
  padding: 0 24px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, opacity 0.2s ease;
  border: none;
  text-decoration: none;
}
.btn:focus-visible { outline: 3px solid var(--hl-color); outline-offset: 2px; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--btn-bg); color: var(--btn-text); }
.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid currentColor;
}
.btn-secondary:hover { background: rgba(0,0,0,0.05); }
.bg-dark .btn-secondary { color: var(--text-inverse); }
.bg-dark .btn-secondary:hover { background: rgba(255,255,255,0.08); }
.icon-btn { width: 20px; height: 20px; flex-shrink: 0; }

/* === Cards & Panels === */
.card {
  background: var(--bg-section);
  border: var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: var(--card-shadow);
  padding: 24px;
  transition: transform 0.2s ease;
}
.card:hover { transform: translateY(-2px); }
.panel {
  background: var(--bg-section-alt);
  border-radius: 16px;
  padding: 24px;
  position: relative;
  overflow: hidden;
}
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
@media (max-width: 900px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* === Chessboard Layout === */
.chess-row { display: flex; flex-wrap: wrap; gap: var(--gap); align-items: center; }
.chess-row:nth-child(even) { flex-direction: row-reverse; }
.chess-text { flex: 1 1 0; min-width: 0; }
.chess-visual { flex: 1 1 0; min-width: 0; }
@media (max-width: 768px) {
  .chess-row, .chess-row:nth-child(even) { flex-direction: column; }
}

/* === Table === */
.spec-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  font-size: 0.95rem;
}
.spec-table th, .spec-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}
.spec-table th { font-weight: 600; width: 40%; }
.spec-table tr:last-child td { border-bottom: none; }

/* === FAQ === */
.faq-item { margin-bottom: 16px; border-bottom: 1px solid var(--border-subtle); }
.faq-item summary {
  padding: 16px 0;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+";
  font-size: 1.2rem;
  transition: transform 0.2s;
}
.faq-item[open] summary::after { transform: rotate(45deg); }
.faq-item .answer { padding-bottom: 16px; line-height: 1.7; color: var(--text-primary); }

/* === Magazine / TOC Layout === */
.magazine-layout { display: grid; grid-template-columns: 1fr 240px; gap: 40px; }
.toc-nav { position: sticky; top: 80px; align-self: start; }
.toc-nav ul { border-left: 2px solid var(--border-subtle); padding-left: 16px; }
.toc-nav li { margin-bottom: 12px; }
.toc-nav a { color: var(--text-primary); opacity: 0.7; font-size: 0.9rem; display: block; padding: 4px 0; }
.toc-nav a:hover, .toc-nav a.active { opacity: 1; color: var(--hl-color); }
@media (max-width: 900px) {
  .magazine-layout { grid-template-columns: 1fr; }
  .toc-nav { position: static; margin-bottom: 24px; }
}

/* === SVG Animations === */
.svg-responsive { width: 100%; height: auto; }
.orbit-ring {
  fill: none;
  stroke: var(--hl-color);
  stroke-width: 1.5;
  opacity: 0.6;
  transform-box: fill-box;
  transform-origin: center;
}
.orbit-ring.a { animation: orbit-breathe-a 6s ease-in-out infinite; }
.orbit-ring.b { animation: orbit-breathe-b 8s ease-in-out infinite; }
.orbit-ring.c { animation: orbit-breathe-c 10s ease-in-out infinite; }
@keyframes orbit-breathe-a {
  0%, 100% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.04); opacity: 0.8; }
}
@keyframes orbit-breathe-b {
  0%, 100% { transform: scale(1.02); opacity: 0.6; }
  50% { transform: scale(1.06); opacity: 0.9; }
}
@keyframes orbit-breathe-c {
  0%, 100% { transform: scale(0.98); opacity: 0.4; }
  50% { transform: scale(1.03); opacity: 0.7; }
}
.draw-path {
  pathLength: 1;
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}
.draw-path.animate {
  animation: dash-flow 4s ease-in-out infinite;
}
@keyframes dash-flow {
  0% { stroke-dashoffset: 1; }
  100% { stroke-dashoffset: 0; }
}
.float-slow { animation: float-up 5s ease-in-out infinite; }
.float-delay { animation: float-up 5s ease-in-out infinite 1.5s; }
@keyframes float-up {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.fade-in-panel { animation: fade-slide 6s ease-in-out infinite alternate; }
@keyframes fade-slide {
  0% { opacity: 0.85; transform: translateX(-4px); }
  100% { opacity: 1; transform: translateX(0); }
}
.breath-dot { animation: breath-pulse 3s ease-in-out infinite; }
@keyframes breath-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .draw-path.animate, .orbit-ring, .float-slow, .fade-in-panel, .breath-dot {
    animation: none;
  }
}

/* 兜底：裁掉横向溢出 */
body > * {
  overflow-x: clip;
}
