/* ===== CSS 变量定义 ===== */
:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #1a2332;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: #2d3748;
  --accent-color: #06b6d4;
  --accent-glow: rgba(6, 182, 212, 0.3);
  
  /* 元素类别颜色 */
  --alkali-metal: #FF6B6B;
  --alkaline-earth: #FFA94D;
  --transition-metal: #FFD43B;
  --post-transition-metal: #A8E6CF;
  --metalloid: #74C0FC;
  --nonmetal: #69DB7C;
  --halogen: #748FFC;
  --noble-gas: #DA77F2;
  --lanthanide: #F783AC;
  --actinide: #C19A6B;
  --unknown: #868E96;
  
  /* 字体 */
  --font-mono: 'JetBrains Mono', monospace;
  --font-sans: 'Noto Sans SC', sans-serif;
  
  /* 间距 */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  
  /* 圆角 */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  
  /* 阴影 */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--accent-glow);
}

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

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* ===== 背景效果 ===== */
.bg-pattern {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    radial-gradient(circle at 25% 25%, rgba(6, 182, 212, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 75% 75%, rgba(218, 119, 242, 0.03) 0%, transparent 50%),
    linear-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 50px 50px, 50px 50px;
  pointer-events: none;
  z-index: 0;
}

.bg-glow {
  position: fixed;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
}

.bg-glow-1 {
  top: -200px;
  right: -200px;
  background: linear-gradient(135deg, var(--accent-color), var(--noble-gas));
}

.bg-glow-2 {
  bottom: -200px;
  left: -200px;
  background: linear-gradient(135deg, var(--lanthanide), var(--transition-metal));
}

/* ===== 头部导航 ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 14, 23, 0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
}

.header-content {
  max-width: 1600px;
  margin: 0 auto;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-lg);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.logo-icon {
  font-size: 2.5rem;
  animation: spin 20s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.logo-text {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.controls {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box input {
  width: 280px;
  padding: var(--space-sm) var(--space-md);
  padding-right: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: var(--font-sans);
  transition: all 0.3s ease;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: var(--shadow-glow);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-icon {
  position: absolute;
  right: 12px;
  font-size: 1rem;
  opacity: 0.6;
}

.view-toggle {
  display: flex;
  gap: var(--space-xs);
  background: var(--bg-card);
  padding: var(--space-xs);
  border-radius: var(--radius-md);
}

.view-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1.25rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.view-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.view-btn.active {
  background: var(--accent-color);
  box-shadow: var(--shadow-glow);
}

/* ===== 筛选栏 ===== */
.filter-bar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: var(--space-md) 0;
}

.filter-content {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-lg);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.filter-group label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.filter-btn {
  padding: var(--space-xs) var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  border-color: var(--accent-color);
  color: var(--text-primary);
}

.filter-btn.active {
  background: var(--accent-color);
  border-color: var(--accent-color);
  color: var(--bg-primary);
  font-weight: 600;
}

.clear-filters {
  padding: var(--space-xs) var(--space-md);
  background: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.clear-filters:hover {
  border-color: #ef4444;
  color: #ef4444;
}

/* ===== 主内容区 ===== */
.main-content {
  max-width: 1600px;
  margin: 0 auto;
  padding: var(--space-xl) var(--space-lg);
  position: relative;
  z-index: 1;
}

/* ===== 周期表视图 ===== */
.periodic-table-view {
  overflow-x: auto;
}

.periodic-table {
  display: grid;
  grid-template-columns: repeat(18, minmax(56px, 1fr));
  gap: 3px;
  margin-bottom: var(--space-lg);
  animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 元素格子 */
.element {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.element::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
  pointer-events: none;
}

.element:hover {
  transform: scale(1.15);
  z-index: 10;
  box-shadow: var(--shadow-lg), 0 0 30px currentColor;
}

.element.dimmed {
  opacity: 0.2;
}

.element.selected {
  transform: scale(1.1);
  box-shadow: 0 0 0 3px var(--accent-color), var(--shadow-lg);
}

.element-number {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  opacity: 0.8;
  position: absolute;
  top: 3px;
  left: 4px;
}

.element-symbol {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
}

.element-name {
  font-size: 0.55rem;
  opacity: 0.9;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 镧系锕系 */
.actinide-lanthanide {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-top: var(--space-lg);
  padding-left: calc(3 * (minmax(56px, 1fr) + 3px));
}

.series {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.series-label {
  min-width: 100px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.series-elements {
  display: flex;
  gap: 3px;
}

.series-elements .element {
  width: 56px;
  height: 56px;
}

/* 图例 */
.legend {
  margin-top: var(--space-xl);
  padding: var(--space-lg);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.legend-title {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
  display: block;
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: var(--radius-sm);
}

.legend-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ===== 时间线视图 ===== */
.timeline-view {
  animation: fadeIn 0.5s ease-out;
}

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

.timeline-container {
  max-width: 1000px;
  margin: 0 auto;
}

.timeline-header {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.timeline-header h2 {
  font-size: 2rem;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-sm);
}

.timeline-header p {
  color: var(--text-secondary);
}

.timeline {
  position: relative;
  padding-left: var(--space-xl);
}

.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: linear-gradient(to bottom, var(--accent-color), var(--noble-gas), var(--lanthanide));
}

.timeline-item {
  position: relative;
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.3s ease;
  animation: slideIn 0.5s ease-out backwards;
}

.timeline-item:nth-child(odd) {
  animation-delay: 0.1s;
}

.timeline-item:nth-child(even) {
  animation-delay: 0.2s;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.timeline-item:hover {
  border-color: var(--accent-color);
  transform: translateX(8px);
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: calc(-1 * var(--space-xl) + 4px);
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  background: var(--accent-color);
  border-radius: 50%;
  border: 2px solid var(--bg-primary);
}

.timeline-year {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--accent-color);
  margin-bottom: var(--space-xs);
}

.timeline-element {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.timeline-symbol {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.25rem;
}

.timeline-info h3 {
  font-size: 1.1rem;
  margin-bottom: var(--space-xs);
}

.timeline-info p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.timeline-discoverer {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

/* ===== 对比视图 ===== */
.compare-view {
  animation: fadeIn 0.5s ease-out;
}

.compare-container {
  max-width: 1200px;
  margin: 0 auto;
}

.compare-header {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.compare-header h2 {
  font-size: 2rem;
  margin-bottom: var(--space-sm);
}

.compare-header p {
  color: var(--text-secondary);
}

.compare-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.compare-slot {
  aspect-ratio: 2;
  background: var(--bg-card);
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.compare-slot:hover {
  border-color: var(--accent-color);
}

.compare-slot.filled {
  border-style: solid;
  border-color: var(--accent-color);
}

.compare-slot .slot-label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.slot-element {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}

.slot-symbol {
  font-family: var(--font-mono);
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: var(--space-sm);
}

.slot-name {
  font-size: 1.25rem;
  margin-bottom: var(--space-xs);
}

.slot-info {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.slot-remove {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  width: 24px;
  height: 24px;
  background: rgba(239, 68, 68, 0.8);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.slot-remove:hover {
  background: #ef4444;
  transform: scale(1.1);
}

.compare-slot {
  position: relative;
}

.compare-results {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
}

.compare-table th,
.compare-table td {
  padding: var(--space-md);
  text-align: center;
  border-bottom: 1px solid var(--border-color);
}

.compare-table th {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.compare-table td {
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.compare-table tr:last-child td {
  border-bottom: none;
}

.compare-table .property-name {
  text-align: left;
  font-family: var(--font-sans);
  color: var(--text-secondary);
}

.compare-hint {
  text-align: center;
  margin-top: var(--space-lg);
  color: var(--text-muted);
}

.compare-search {
  margin-top: var(--space-md);
}

.compare-search input {
  width: 300px;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.compare-search input:focus {
  outline: none;
  border-color: var(--accent-color);
}

/* ===== 弹窗 ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-lg);
  animation: fadeIn 0.3s ease-out;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalSlideIn 0.4s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 10;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
}

.modal-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-xl);
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.1), rgba(218, 119, 242, 0.1));
}

.modal-element-symbol {
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  font-family: var(--font-mono);
  font-size: 3.5rem;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
}

.modal-element-info {
  flex: 1;
}

.modal-element-info h2 {
  font-size: 2rem;
  margin-bottom: var(--space-xs);
}

.modal-english-name {
  display: block;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.modal-category-badge {
  display: inline-block;
  padding: var(--space-xs) var(--space-md);
  background: var(--accent-color);
  color: var(--bg-primary);
  border-radius: var(--radius-lg);
  font-size: 0.8rem;
  font-weight: 600;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.stat-item {
  background: var(--bg-secondary);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-color);
}

.modal-details {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.detail-section h3 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border-color);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.detail-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.detail-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.detail-text {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.hazard-text {
  color: #ef4444;
}

.modal-footer {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-lg);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
}

.modal-action-btn {
  flex: 1;
  padding: var(--space-md);
  background: var(--accent-color);
  border: none;
  border-radius: var(--radius-md);
  color: var(--bg-primary);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.modal-action-btn.secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.modal-action-btn.secondary:hover {
  background: var(--bg-primary);
}

/* ===== 底部 ===== */
.footer {
  text-align: center;
  padding: var(--space-lg);
  color: var(--text-muted);
  font-size: 0.875rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.footer span {
  color: var(--accent-color);
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ===== 工具类 ===== */
.hidden {
  display: none !important;
}

/* ===== 响应式设计 ===== */
@media (max-width: 1200px) {
  .periodic-table {
    grid-template-columns: repeat(18, minmax(48px, 1fr));
    gap: 2px;
  }
  
  .element-symbol {
    font-size: 1.2rem;
  }
  
  .element-name {
    display: none;
  }
  
  .series-elements .element {
    width: 48px;
    height: 48px;
  }
}

@media (max-width: 900px) {
  .header-content {
    flex-direction: column;
    gap: var(--space-md);
  }
  
  .controls {
    width: 100%;
    justify-content: space-between;
  }
  
  .search-box input {
    width: 100%;
  }
  
  .filter-content {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .modal-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .compare-slots {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .periodic-table {
    grid-template-columns: repeat(18, minmax(36px, 1fr));
  }
  
  .element-number {
    display: none;
  }
  
  .element-symbol {
    font-size: 1rem;
  }
  
  .logo-text {
    font-size: 1.25rem;
  }
  
  .logo-subtitle {
    display: none;
  }
  
  .view-btn {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }
  
  .modal-header {
    flex-direction: column;
    text-align: center;
  }
  
  .modal-element-symbol {
    width: 80px;
    height: 80px;
    font-size: 2.5rem;
  }
}

/* ===== 滚动条样式 ===== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
