/* --- 全局与重置 --- */
:root {
  --primary-color: #007bff;
  --primary-hover: #0056b3;
  --background-color: #121212;
  --surface-color: #1e1e1e;
  --text-color: #e0e0e0;
  --text-muted: #ffffff;
  --border-color: #333;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --radius: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--background-color);
  color: var(--text-color);
  line-height: 1.6;
  padding-bottom: 120px; /* 为底部栏和悬浮控制器留出空间 */
  scrollbar-width: none; /* Firefox */
}

body::-webkit-scrollbar {
  display: none; /* WebKit */
}

a {
  color: var(--primary-color);
  text-decoration: none;
}
a:hover {
  color: var(--primary-hover);
}

img, video, canvas {
  max-width: 100%;
  height: auto;
  display: block;
}

/* --- 背景 --- */
.background-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  overflow: hidden;
}
.background-media {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: translate(-50%, -50%);
  filter: blur(2px) brightness(0.5);
  transition: opacity 0.8s ease-in-out;
  opacity: 0;
}

/* --- 主导航 --- */
.main-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.5rem;
  background: rgba(30, 30, 30, 0.7);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1rem;
}
.nav-left, .nav-right, .nav-center {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.nav-logo {
  height: 32px;
  width: 32px;
}
.nav-title {
  font-size: 1.1rem;
  font-weight: 600;
  white-space: nowrap;
}
.nav-right .action-btn {
  width: 36px;
  height: 36px;
  background: transparent;
}
.nav-right .action-btn:hover {
  background: var(--border-color);
}
.nav-item {
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  transition: background-color 0.3s, color 0.3s;
  font-weight: 500;
  color: var(--text-muted);
}
.nav-item:hover {
  background-color: var(--border-color);
  color: var(--text-color);
}
.nav-item.active {
  background-color: var(--primary-color);
  color: white;
}

/* --- 主内容与卡片 --- */
main {
  padding: 2rem;
  transition: opacity 0.4s ease-out;
}
.masonry {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}
.card {
  background: var(--surface-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  break-inside: avoid;
  margin-bottom: 1.5rem;
  position: relative;
  border: 1px solid var(--border-color);
}

/* Canvas within a card will have its size managed by JS */
.card > canvas {
  width: 100%;
  height: auto;
}
.meta {
  padding: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}
.badge {
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: bold;
  color: white;
}
.badge.dynamic { background-color: #28a745; }
.badge.static { background-color: #17a2b8; }
.badge.legacy { background-color: #6c757d; }
.card-actions {
  display: flex;
  gap: 0.5rem;
}
.action-btn {
  background: rgba(40, 40, 40, 0.8);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.3s;
  border: none;
  color: var(--text-color);
}
.action-btn:hover {
  background: #444;
}
.action-btn svg {
  color: var(--text-color);
}

/* --- 悬浮控制器 --- */
.floating-controller {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 220px;
}
.controller-group, .controller-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.controller-toggles {
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center;
  gap: 1rem;
}
.controller-group label, .switch-label span {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.floating-controller input[type="number"] {
  width: 118px;
  padding: 0.3rem;
  background: var(--background-color);
  border: 1px solid var(--border-color);
  color: var(--text-color);
  border-radius: 4px;
}
.controller-actions button {
  flex: 1;
  padding: 0.5rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  transition: background-color 0.3s ease;
}
#scan-toggle-btn {
  background-color: var(--primary-color);
  color: white;
}
#scan-toggle-btn.scanning {
  background-color: #dc3545;
}
.controller-status {
  font-size: 0.8rem;
  text-align: center;
  color: var(--text-muted);
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
}

/* --- 其他 --- */
.status { text-align: center; padding: 2rem; font-size: 1.2rem; color: var(--text-muted); display: none; }
.footer { text-align: center; padding: 2rem; font-size: 0.9rem; color: var(--text-muted); border-top: 1px solid var(--border-color); margin-top: 2rem; }
.footer a { color: var(--text-muted); text-decoration: none; } /* 备案号样式 */
.footer a:hover { text-decoration: underline; }

/* --- 开关样式 --- */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #555; transition: .4s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(20px); }

/* --- 动画 --- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.fade-in { animation: fadeIn 0.5s ease-in-out forwards; }

/* --- 灯箱与弹窗 (暗黑主题) --- */
.lightbox, .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.9); display: none; align-items: center; justify-content: center; z-index: 1000; }
.lightbox-content { max-width: 90vw; max-height: 90vh; display: flex; align-items: center; justify-content: center; }
.lightbox-media { max-width: 100%; max-height: 100%; border-radius: var(--radius); object-fit: contain; }
.lightbox-close { position: absolute; top: 20px; right: 30px; font-size: 2.5rem; color: white; cursor: pointer; }

.modal-wrapper {
  position: relative;
  max-height: 80vh; /* 限制最大高度 */
  overflow-y: auto; /* 只显示垂直滚动条 */
  overflow-x: hidden; /* 隐藏水平滚动条 */
}
.modal-close {
  position: absolute;
  top: -8px;
  right: -6px;
  width: 32px;
  height: 32px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-color);
  font-size: 1.5rem;
  line-height: 24px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s;
}
.modal-close:hover {
  transform: scale(1.1);
}

.modal-content { background: var(--surface-color); padding: 2rem; border-radius: var(--radius); text-align: left; max-width: 500px; border: 1px solid var(--border-color); }
.modal-content h3, .modal-content > p {
  text-align: center;
}
.modal-content img { max-width: 150px; margin: 1rem auto; display: block; }

.api-docs {
  margin-top: 1.5rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--background-color);
  text-align: left;
}
.api-docs summary {
  padding: 0.75rem;
  font-weight: bold;
  cursor: pointer;
  outline: none;
}
.api-docs .api-content {
  padding: 0 1rem 1rem 1rem;
  border-top: 1px solid var(--border-color);
}
.api-docs h4, .api-docs h5 {
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}
.api-docs ul {
  list-style-position: inside;
  padding-left: 0.5rem;
}
.api-docs code {
  display: block;
  background: #111;
  padding: 0.5rem;
  border-radius: 4px;
  font-family: 'Courier New', Courier, monospace;
  margin-top: 0.5rem;
  word-break: break-all;
  font-size: 0.85rem;
}

/* --- 响应式 --- */
@media (max-width: 768px) {
  body {
    padding-bottom: 80px; /* 减少底部空间 */
  }

  /* 导航栏调整 */
  .main-nav {
    flex-direction: column;
    padding: 0.5rem;
    gap: 0.5rem;
  }
  .nav-left {
    order: 1; /* 标题 */
  }
  .nav-center {
    order: 2; /* 分类 */
    width: 100%;
    justify-content: center;
  }
  .nav-title {
    font-size: 1rem; /* 缩小标题 */
  }
  .nav-logo, .nav-right {
    display: none; /* 隐藏Logo和右侧帮助/Github按钮 */
  }
  .nav-item {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
  }

  /* 主内容和卡片网格 */
  main {
    padding: 0.75rem;
  }
  .masonry {
    /* 手机端一排显示2个 */
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }
  .card {
    margin-bottom: 0; /* gap会处理间距 */
  }
  .meta {
    padding: 0.5rem;
  }
  .id {
    display: none; /* 手机端隐藏ID显示，节省空间 */
  }

  /* 隐藏悬浮控制器，其功能应整合到菜单中 */
  .floating-controller {
    display: none;
  }

  /* 弹窗适应 */
  .modal-content {
    max-width: 90vw;
    padding: 1.5rem;
  }
}
