/**
 * 「时间碎片」Time Fragments - 样式表
 * 获奖级网页设计 · 完整实现
 */

/* ================================
   一、CSS 变量系统
   ================================ */
:root {
  /* 色彩系统 */
  --ink: #1A2332;
  --dawn: #FF6B35;
  --gold: #FFB800;
  --midnight: #0D1B2A;
  --mist: rgba(26, 35, 50, 0.03);
  --light: #FFFFFF;
  --paper: #FAFAFA;

  /* 色彩变体 */
  --ink-light: rgba(26, 35, 50, 0.7);
  --ink-lighter: rgba(26, 35, 50, 0.5);
  --dawn-light: rgba(255, 107, 53, 0.2);
  --gold-light: rgba(255, 184, 0, 0.2);

  /* 字体系统 */
  --font-heading: 'Noto Sans SC', 'Space Grotesk', sans-serif;
  --font-body: 'Noto Serif SC', serif;
  --font-ui: 'Space Grotesk', sans-serif;

  /* 字号系统 */
  --text-xs: 10px;
  --text-sm: 12px;
  --text-base: 16px;
  --text-lg: 24px;
  --text-xl: 48px;
  --text-2xl: 72px;
  --text-hero: clamp(60px, 8vw, 120px);

  /* 间距系统 */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 32px;
  --space-xl: 64px;
  --space-2xl: 128px;

  /* 动画时长 */
  --duration-fast: 150ms;
  --duration-normal: 300ms;
  --duration-slow: 500ms;
  --duration-slower: 1000ms;

  /* 缓动函数 */
  --ease-out: cubic-bezier(0.33, 1, 0.68, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-elastic: cubic-bezier(0.68, -0.55, 0.265, 1.55);

  /* 圆角 */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;

  /* 阴影 */
  --shadow-sm: 0 2px 8px rgba(26, 35, 50, 0.08);
  --shadow-md: 0 4px 24px rgba(26, 35, 50, 0.12);
  --shadow-lg: 0 8px 48px rgba(26, 35, 50, 0.16);
  --shadow-glow: 0 0 40px rgba(255, 107, 53, 0.3);

  /* 模糊 */
  --blur-sm: blur(4px);
  --blur-md: blur(12px);
  --blur-lg: blur(24px);

  /* 层级 */
  --z-background: -1;
  --z-fragments: 10;
  --z-content: 20;
  --z-overlay: 100;
  --z-modal: 200;
}

/* ================================
   二、基础重置与全局样式
   ================================ */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--light);
  overflow-x: hidden;
  min-height: 100vh;
}

/* 选择文本样式 */
::selection {
  background-color: var(--dawn-light);
  color: var(--ink);
}

/* 隐藏屏幕阅读器可访问的内容 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ================================
   三、背景层系统
   ================================ */
.background-layer {
  position: fixed;
  inset: 0;
  z-index: var(--z-background);
  pointer-events: none;
}

/* 底层：细微灰色网格 */
.grid-pattern {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(26, 35, 50, 0.02) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(26, 35, 50, 0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0;
  animation: fadeInGrid 2s ease-out forwards;
  animation-delay: 1s;
}

/* 中层：径向渐变 */
.radial-gradient {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse 80% 60% at 50% 40%,
    rgba(255, 255, 255, 1) 0%,
    rgba(250, 250, 250, 0.8) 40%,
    rgba(245, 245, 245, 0.6) 70%,
    rgba(240, 240, 240, 0.4) 100%
  );
}

/* 顶层：时间流动线条 */
.time-lines {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.time-line {
  position: absolute;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(26, 35, 50, 0.03) 20%,
    rgba(26, 35, 50, 0.06) 50%,
    rgba(26, 35, 50, 0.03) 80%,
    transparent 100%
  );
  animation: flowLine 60s linear infinite;
}

.time-line:nth-child(1) {
  top: 20%;
  width: 100%;
  left: -100%;
  animation-delay: 0s;
}

.time-line:nth-child(2) {
  top: 45%;
  width: 80%;
  left: -80%;
  animation-delay: -20s;
}

.time-line:nth-child(3) {
  top: 70%;
  width: 120%;
  left: -120%;
  animation-delay: -40s;
}

/* ================================
   四、第一幕：觉醒
   ================================ */
.act-awakening {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: var(--space-xl);
  /* 纯白背景 */
  background: var(--light);
}

.awakening-text {
  font-family: var(--font-body);
  /* 极小文字：10px */
  font-size: var(--text-xs);
  font-weight: 300;
  letter-spacing: 0.15em;
  color: var(--ink-light);
  text-align: center;
  /* 居中 */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  /* 淡入动画 */
  animation: fadeInAwakening 1.5s var(--ease-out) forwards;
  animation-delay: 300ms;
}

/* 标题停留2秒后碎裂 */
.awakening-text.shattered {
  animation: shatterText 1s var(--ease-out) forwards;
}

/* 滚动提示 */
.scroll-hint {
  position: absolute;
  bottom: var(--space-xl);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  opacity: 0;
  /* 5秒后显示（标题碎裂后） */
  animation: fadeInText 1s var(--ease-out) forwards;
  animation-delay: 5s;
}

.scroll-hint-text {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  letter-spacing: 0.2em;
  color: var(--ink-lighter);
  text-transform: uppercase;
}

.scroll-hint-icon {
  width: 24px;
  height: 24px;
  color: var(--ink-lighter);
  animation: bounceDown 2s ease-in-out infinite;
}

/* ================================
   五、第二幕：收集
   ================================ */
.act-collection {
  min-height: 200vh;
  position: relative;
  padding: var(--space-2xl) var(--space-lg);
}

/* 时间线 */
.timeline-hint {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 1px;
  height: 60vh;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(26, 35, 50, 0.08) 20%,
    rgba(26, 35, 50, 0.08) 80%,
    transparent 100%
  );
  opacity: 0.3;
  pointer-events: none;
  z-index: 5;
}

/* 碎片容器 */
.fragments-container {
  position: fixed;
  inset: 0;
  z-index: var(--z-fragments);
  pointer-events: none;
}

/* 时间碎片 */
.time-fragment {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  opacity: 0;
  will-change: transform, opacity;
  transform: translateZ(0);
  transition:
    box-shadow var(--duration-normal) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

/* 碎片玻璃质感 */
.fragment-inner {
  position: relative;
  width: 100%;
  height: 100%;
  /* 玻璃质感：半透明背景 + backdrop-filter blur */
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.9) 0%,
    rgba(255, 255, 255, 0.75) 50%,
    rgba(245, 245, 245, 0.85) 100%
  );
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  /* 边缘高光 */
  border: 1px solid rgba(255, 255, 255, 0.4);
  /* 三层阴影：近距离 + 中距离 + 漫射光晕 */
  box-shadow:
    0 2px 8px rgba(26, 35, 50, 0.06),      /* 近距离阴影 */
    0 8px 32px rgba(26, 35, 50, 0.08),      /* 中距离阴影 */
    0 16px 48px rgba(26, 35, 50, 0.04);     /* 漫射光晕 */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: var(--space-md);
  text-align: center;
}

/* 碎片内容 */
.fragment-icon {
  width: 32px;
  height: 32px;
  margin-bottom: var(--space-sm);
  color: var(--dawn);
  opacity: 0.8;
}

.fragment-text {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 300;
  color: var(--ink);
  line-height: 1.4;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fragment-timestamp {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-lighter);
  letter-spacing: 0.1em;
  margin-top: var(--space-xs);
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-out);
}

/* 悬停状态 */
.time-fragment:hover {
  z-index: 15;
}

.time-fragment:hover .fragment-inner {
  box-shadow:
    0 8px 32px rgba(26, 35, 50, 0.15),
    0 16px 64px rgba(26, 35, 50, 0.08),
    var(--shadow-glow);
}

.time-fragment:hover .fragment-timestamp {
  opacity: 1;
}

.time-fragment:focus-visible {
  outline: 2px solid var(--dawn);
  outline-offset: 4px;
  z-index: 15;
}

/* 聚焦状态 */
.time-fragment:focus-visible .fragment-inner {
  box-shadow:
    0 8px 32px rgba(26, 35, 50, 0.15),
    0 16px 64px rgba(26, 35, 50, 0.08),
    var(--shadow-glow);
}

/* 激活状态（拖拽时） */
.time-fragment.dragging {
  z-index: 50;
  cursor: grabbing;
  transition: none;
}

.time-fragment.dragging .fragment-inner {
  box-shadow:
    0 16px 48px rgba(26, 35, 50, 0.25),
    0 32px 96px rgba(26, 35, 50, 0.15);
}

/* 风效果 */
.time-fragment.wind-effect {
  transition: transform 0.3s var(--ease-out);
}

/* 暂停状态 */
.time-fragment.paused {
  animation-play-state: paused !important;
}

/* 彩虹效果（彩蛋） */
.time-fragment.rainbow .fragment-inner {
  background: linear-gradient(
    135deg,
    rgba(255, 107, 107, 0.9) 0%,
    rgba(255, 184, 0, 0.9) 20%,
    rgba(247, 223, 30, 0.9) 40%,
    rgba(72, 219, 147, 0.9) 60%,
    rgba(52, 152, 219, 0.9) 80%,
    rgba(155, 89, 182, 0.9) 100%
  );
  border-color: rgba(255, 255, 255, 0.6);
}

/* ================================
   六、碎片展开卡片
   ================================ */
.fragment-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: var(--blur-lg);
  -webkit-backdrop-filter: var(--blur-lg);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--duration-normal) var(--ease-out),
    visibility var(--duration-normal);
}

.fragment-overlay.active {
  opacity: 1;
  visibility: visible;
}

.fragment-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  z-index: var(--z-modal);
  width: min(90vw, 480px);
  max-height: 80vh;
  background: var(--light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--duration-normal) var(--ease-out),
    visibility var(--duration-normal),
    transform var(--duration-slow) var(--ease-bounce);
  overflow: hidden;
}

.fragment-card.active {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.fragment-card-header {
  padding: var(--space-lg);
  background: linear-gradient(135deg, var(--dawn-light), var(--gold-light));
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.fragment-card-icon {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  background: var(--light);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.fragment-card-icon svg {
  width: 40px;
  height: 40px;
  color: var(--dawn);
}

.fragment-card-meta {
  flex: 1;
}

.fragment-card-timestamp {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--ink-lighter);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.fragment-card-title {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--ink);
  margin-top: var(--space-xs);
  letter-spacing: -0.01em;
}

.fragment-card-body {
  padding: var(--space-lg);
}

.fragment-card-description {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.8;
  color: var(--ink-light);
}

.fragment-card-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  transition:
    background var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.fragment-card-close:hover {
  background: var(--light);
  transform: scale(1.1);
}

.fragment-card-close:focus-visible {
  outline: 2px solid var(--dawn);
  outline-offset: 2px;
}

/* ================================
   七、第三幕：重组
   ================================ */
.act-reassembly {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: var(--space-2xl) var(--space-lg);
}

.reassembly-hint {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--ink-light);
  text-align: center;
  opacity: 0;
  animation: fadeInText 1s var(--ease-out) forwards;
}

.timeline-container {
  width: 100%;
  max-width: 800px;
  min-height: 200px;
  margin-top: var(--space-xl);
  padding: var(--space-lg);
  border: 2px dashed rgba(26, 35, 50, 0.15);
  border-radius: var(--radius-lg);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  justify-content: center;
  align-items: center;
}

.timeline-placeholder {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--ink-lighter);
  letter-spacing: 0.1em;
}

/* 总结显示 */
.summary-container {
  position: fixed;
  bottom: var(--space-xl);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-content);
  text-align: center;
  opacity: 0;
  transition: opacity var(--duration-slow) var(--ease-out);
}

.summary-container.visible {
  opacity: 1;
}

.summary-text {
  font-family: var(--font-body);
  font-size: var(--text-lg);
  font-weight: 300;
  color: var(--ink);
  letter-spacing: 0.05em;
  max-width: 600px;
  line-height: 1.8;
}

/* ================================
   八、终幕：消逝
   ================================ */
.act-ending {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  padding: var(--space-2xl) var(--space-lg);
  opacity: 0;
  transition: opacity var(--duration-slower) var(--ease-out);
}

.act-ending.visible {
  opacity: 1;
}

.ending-text {
  font-family: var(--font-body);
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 300;
  color: var(--ink);
  text-align: center;
  letter-spacing: 0.1em;
  line-height: 2;
  max-width: 600px;
}

.restart-button {
  margin-top: var(--space-xl);
  padding: var(--space-md) var(--space-lg);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--ink);
  background: transparent;
  border: 1px solid rgba(26, 35, 50, 0.2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    border-color var(--duration-normal) var(--ease-out),
    background var(--duration-normal) var(--ease-out);
}

.restart-button:hover {
  border-color: var(--dawn);
  background: var(--dawn-light);
}

.restart-button:focus-visible {
  outline: 2px solid var(--dawn);
  outline-offset: 4px;
}

/* ================================
   九、动画定义
   ================================ */
@keyframes fadeInText {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 觉醒标题淡入动画 */
@keyframes fadeInAwakening {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes fadeInGrid {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes shatterText {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
  50% {
    opacity: 0.5;
    transform: translateY(-10px) scale(1.02);
    filter: blur(2px);
  }
  100% {
    opacity: 0;
    transform: translateY(-30px) scale(0.95);
    filter: blur(8px);
  }
}

@keyframes flowLine {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(200vw);
  }
}

@keyframes bounceDown {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(8px);
  }
}

@keyframes fragmentEnter {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0) rotate(0deg);
  }
  60% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.1) rotate(10deg);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(var(--rotation, 0deg));
  }
}

@keyframes fragmentFadeOut {
  from {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8) translateY(-50px);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.3;
  }
  50% {
    opacity: 0.6;
  }
}

/* ================================
   十、响应式设计
   ================================ */
/* 平板 */
@media (max-width: 1199px) {
  :root {
    --text-hero: clamp(48px, 7vw, 96px);
    --text-xl: 36px;
    --text-2xl: 56px;
  }

  .act-awakening {
    padding: var(--space-lg);
  }

  .fragment-card {
    width: min(85vw, 420px);
  }
}

/* 手机 */
@media (max-width: 767px) {
  :root {
    --text-hero: clamp(36px, 10vw, 72px);
    --text-xl: 28px;
    --text-2xl: 40px;
    --space-xl: 48px;
    --space-2xl: 80px;
  }

  .act-awakening {
    padding: var(--space-md);
  }

  .awakening-text {
    font-size: var(--text-xs);
    letter-spacing: 0.2em;
  }

  .fragment-inner {
    padding: var(--space-sm);
  }

  .fragment-icon {
    width: 24px;
    height: 24px;
  }

  .fragment-text {
    font-size: var(--text-xs);
  }

  .fragment-card {
    width: 95vw;
    max-height: 85vh;
  }

  .fragment-card-header {
    padding: var(--space-md);
  }

  .fragment-card-icon {
    width: 48px;
    height: 48px;
  }

  .fragment-card-icon svg {
    width: 28px;
    height: 28px;
  }

  .fragment-card-title {
    font-size: var(--text-base);
  }

  .fragment-card-body {
    padding: var(--space-md);
  }

  .timeline-hint {
    display: none;
  }

  .scroll-hint {
    bottom: var(--space-lg);
  }

  .ending-text {
    font-size: clamp(16px, 4vw, 20px);
    padding: 0 var(--space-md);
  }
}

/* ================================
   十一、无障碍支持
   ================================ */
/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .time-fragment {
    opacity: 1 !important;
  }

  .time-line {
    animation: none;
  }

  .scroll-hint-icon {
    animation: none;
  }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
  :root {
    --ink: #000000;
    --dawn: #D63000;
    --gold: #B38F00;
  }

  .fragment-inner {
    border: 2px solid rgba(0, 0, 0, 0.5);
    background: rgba(255, 255, 255, 1);
  }

  .time-fragment:focus-visible {
    outline-width: 4px;
  }
}

/* 打印样式 */
@media print {
  .background-layer,
  .fragments-container,
  .fragment-overlay,
  .scroll-hint {
    display: none !important;
  }

  .act-awakening,
  .act-collection,
  .act-reassembly,
  .act-ending {
    min-height: auto;
    page-break-inside: avoid;
  }

  .awakening-text {
    opacity: 1;
    transform: none;
  }

  .ending-text {
    opacity: 1;
  }
}

/* ================================
   十二、工具类
   ================================ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.no-scroll {
  overflow: hidden;
}

.fade-in {
  animation: fadeInText var(--duration-normal) var(--ease-out) forwards;
}

.fade-out {
  animation: fadeInText var(--duration-normal) var(--ease-out) reverse forwards;
}