/* ============= 基础变量 ============= */
:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #94a3b8;
  --primary-hover: #cbd5e1;
  --danger: #ef4444;
  --success: #10b981;
  --warn: #f59e0b;
  --info: #06b6d4;
  --tag-a: #64748b;

  /* 主题色补充：视频/Topbar/Footer/Log/Lightbox 等 */
  --video-bg: #000;
  --topbar-bg: #1e293b;
  --topbar-border: #334155;
  --footer-bg: transparent;
  --log-bg: rgba(0, 0, 0, 0.3);
  --lightbox-backdrop: rgba(0, 0, 0, 0.92);
  --lightbox-text: #e2e8f0;
  --lightbox-meta-bg: rgba(0, 0, 0, 0.6);
  --lightbox-border: rgba(255, 255, 255, 0.2);
  --lightbox-btn-bg: rgba(255, 255, 255, 0.08);
  --lightbox-btn-bg-hover: rgba(255, 255, 255, 0.18);
  --lightbox-btn-color: #fff;
  --btn-hover: #334155;
  --debug-row-alt: rgba(255, 255, 255, 0.02);
  --debug-row-pulse: rgba(148, 163, 184, 0.18);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --code-bg: rgba(255, 255, 255, 0.06);
  --overlay-bg: rgba(0, 0, 0, 0.55);
  --badge-ok-bg: rgba(16, 185, 129, 0.18);
  --badge-err-bg: rgba(239, 68, 68, 0.18);
  --badge-warn-bg: rgba(245, 158, 11, 0.18);
  --badge-info-bg: rgba(6, 182, 212, 0.18);
  --badge-text: #e2e8f0;

  /* iOS PWA 安全区：避免被状态栏/底部 home indicator 遮挡 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* 浅色主题覆盖 */
:root.light {
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #64748b;
  --primary-hover: #475569;
  --danger: #dc2626;
  --success: #059669;
  --warn: #d97706;
  --info: #0891b2;
  --tag-a: #64748b;

  --video-bg: #000;          /* 视频画面始终黑底（更聚焦内容） */
  --topbar-bg: #ffffff;
  --topbar-border: #e2e8f0;
  --footer-bg: #f1f5f9;
  --log-bg: #f8fafc;
  --lightbox-backdrop: rgba(255, 255, 255, 0.96);
  --lightbox-text: #0f172a;
  --lightbox-meta-bg: rgba(255, 255, 255, 0.85);
  --lightbox-border: rgba(0, 0, 0, 0.2);
  --lightbox-btn-bg: rgba(0, 0, 0, 0.08);
  --lightbox-btn-bg-hover: rgba(0, 0, 0, 0.18);
  --lightbox-btn-color: #0f172a;
  --btn-hover: #e2e8f0;
  --debug-row-alt: rgba(0, 0, 0, 0.025);
  --debug-row-pulse: rgba(37, 99, 235, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --code-bg: rgba(0, 0, 0, 0.05);
  --overlay-bg: rgba(255, 255, 255, 0.7);
  --badge-ok-bg: rgba(16, 185, 129, 0.15);
  --badge-err-bg: rgba(239, 68, 68, 0.15);
  --badge-warn-bg: rgba(245, 158, 11, 0.15);
  --badge-info-bg: rgba(6, 182, 212, 0.15);
  --badge-text: #0f172a;
}

* { box-sizing: border-box; }

/* ============= SVG 图标基础规范（项目级，所有页面共享） ============= */
.icon {
  width: 24px;
  height: 24px;
  display: block;
  flex-shrink: 0;
  color: inherit;
  pointer-events: none;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 15px; color: var(--text); }
h3 { font-size: 13px; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ============= 顶部栏 ============= */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  padding-top: calc(12px + var(--safe-top));
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
  gap: 8px;
}
.topbar-meta { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.badge-ok { background: var(--badge-ok-bg); color: var(--success); }
.badge-warn { background: var(--badge-warn-bg); color: var(--warn); }
.badge-err { background: var(--badge-err-bg); color: var(--danger); }
.badge-info { background: var(--badge-info-bg); color: var(--info); }

/* ============= 布局 ============= */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  min-width: 0;
}

/* ============= 视频预览（单摄）============= */
.video-grid {
  display: block;
  margin-bottom: 12px;
}
.video-slot {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.slot-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.slot-info {
  color: var(--text);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot-tag {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  text-align: center;
  line-height: 22px;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  background: var(--tag-a);
}

.slot-fps {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 3px;
}

/* 左右布局容器：预览画面（左）+ 操作按钮（右） */
.camera-layout {
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-items: flex-start;
}

.video-wrap {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-width: 0;
  height: 200px;
}
.video-wrap video {
  width: 100%;
  height: 200px;
  object-fit: contain;
  display: block;
}
.video-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--overlay-bg);
  color: #fff; text-align: center;
  transition: opacity 0.2s;
  height: 200px;
}
.video-overlay.hidden { opacity: 0; pointer-events: none; }
.overlay-inner p { margin: 4px 0; }

.rec-indicator {
  position: absolute;
  top: 8px; left: 8px;
  background: var(--danger);
  color: #fff;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  display: flex; align-items: center; gap: 6px;
  opacity: 0.95;
}
.rec-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #fff;
  animation: rec-blink 1s infinite;
}
@keyframes rec-blink { 50% { opacity: 0.3; } }

/* ============= 控件按钮 ============= */
.slot-controls {
  display: flex;
  flex-direction: row;
  gap: 6px;
  flex-shrink: 0;
}
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  /* 关键：inline-flex 让 emoji / SVG 与文字基线对齐
   * - align-items: center 让图标和文字在垂直方向居中
   * - gap 控制图标与文字之间的固定间距，不再依赖内联空格的宽度
   * - justify-content: center 统一水平居中（替代不存在的 text-align）
   */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
/* 按钮内的图标统一尺寸：emoji 与 SVG 视觉一致
 * - .btn-icon 直接子级 span 里的 emoji 默认继承 text font-size
 * - .btn-icon > svg 缩小到 14px（默认 .icon 是 24px，单独放按钮里会过大）
 */
.btn > .btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-size: 14px;  /* emoji 视觉尺寸：与 14px svg 接近 */
  flex-shrink: 0;
}
.btn > .btn-icon > svg,
.btn > .btn-icon > .icon {
  width: 14px;
  height: 14px;
  display: block;
  flex-shrink: 0;
}
/* 兼容旧结构：直接子级 svg（没有 .btn-icon 包裹） */
.btn > svg.icon,
.btn > svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
/* 纯文字按钮的标签居中（flex 容器内自动 justify-content 即可） */
.btn > .btn-label {
  display: inline-block;
  line-height: 1.2;
}
.btn:hover:not(:disabled) { background: var(--btn-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { filter: brightness(0.92); }
.btn-ghost { background: transparent; }
.btn-small { padding: 4px 10px; font-size: 12px; }

/* ============= 设置区 ============= */
.slot-source {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
@media (max-width: 800px) {
  .slot-source { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 500px) {
  .slot-source { grid-template-columns: 1fr; }
}
/* ① 带轮询按钮的 field：select + 按钮同行，select 占满剩余空间 */
.select-row {
  display: flex;
  gap: 4px;
  align-items: stretch;
}
.select-row select {
  flex: 1 1 auto;
  min-width: 0;  /* 防止 select 因内容过长挤压按钮 */
}
.btn-cycle {
  flex: 0 0 auto;
  padding: 4px 8px;
  font-size: 13px;
  line-height: 1.2;
  min-width: 32px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-cycle:hover:not(:disabled) {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-cycle:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
/* 轮询按钮点击瞬时反馈：颜色脉冲一次，让用户看到点击已生效 */
.btn-cycle.pulse-once {
  animation: cycle-pulse 0.4s ease-out;
}
@keyframes cycle-pulse {
  0%   { background: var(--primary); color: #fff; transform: scale(1.08); }
  60%  { background: var(--primary); color: #fff; transform: scale(1.0); }
  100% { background: var(--panel-2); color: var(--text); transform: scale(1.0); }
}
/* ② 自动找最大画质：跨整行全宽 */
.field-auto-quality {
  grid-column: 1 / -1;
}
.btn-auto-quality {
  width: 100%;
  background: linear-gradient(135deg, var(--info), var(--primary));
  color: #fff;
  border: 1px solid var(--info);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-auto-quality:hover:not(:disabled) {
  filter: brightness(1.1);
  transform: translateY(-1px);
}
.btn-auto-quality:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--panel-2);
  color: var(--muted);
  border-color: var(--border);
}
.btn-auto-quality.running {
  background: var(--warn);
  border-color: var(--warn);
  animation: pulse-btn 1.2s infinite;
}
@keyframes pulse-btn {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}
.slot-auto {
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  margin-top: 4px;
}
.panel-title {
  font-size: 15px;
  color: var(--text);
  margin: 0 0 8px;
  font-weight: 600;
}
.settings.global-actions {
  display: block;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.section-caption {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 8px;
  font-weight: 500;
}
.slot-settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
@media (max-width: 500px) {
  .slot-settings { grid-template-columns: 1fr; }
}
.settings.shared {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--muted); }
.field > .caption {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.field select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  color: var(--text);
}
.checkbox input { cursor: pointer; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 6px; }

/* ============= 作品集（可折叠） ============= */
/* 关键设计：
 *   1) 5 列固定网格，每列宽 15% 容器宽度（5×15% = 75%，剩 25% 给 gap）
 *      - 15% × 410px（侧栏）≈ 62px 缩略图，肉眼一眼能辨
 *      - 15% × 360px（手机整宽）≈ 54px，仍可辨认
 *   2) h2 标题作为可点击的折叠开关，展开/收起走 max-height + opacity
 *   3) 折叠状态用 localStorage 记忆（key = collapse-<targetId>）
 *   4) gallery-actions（清空 + 计数）跟随内容一起折叠，避免漏按钮
 */
/* 通用：可折叠 h2 头部 */
.collapsible-header {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px 0;
  padding: 4px 2px;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  /* 保留原 h2 的字体/字号（不强制覆盖，靠 h2 默认） */
  outline: none;
}
.collapsible-header:hover { color: var(--primary); }
.collapsible-header:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.collapsible-header .collapse-icon {
  display: inline-block;
  width: 12px;
  font-size: 9px;
  text-align: center;
  transition: transform 0.2s ease;
  flex-shrink: 0;
  color: var(--muted);
}
.collapsible-header.collapsed .collapse-icon {
  transform: rotate(-90deg);
}
/* storage-info 推到右侧（用 margin-left: auto 兼容 flex 容器） */
.collapsible-header .storage-info {
  margin-left: auto;
  font-weight: normal;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}
/* 折叠内容：用 max-height 动画，opacity 渐变 */
.collapsible-content {
  overflow: hidden;
  max-height: 1200px;
  opacity: 1;
  transition: max-height 0.3s ease, opacity 0.2s ease, margin 0.3s ease;
  /* 关键：min-width: 0 让内部 grid 能正确收缩 */
  min-width: 0;
}
.collapsible-content.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* 作品集主体
 * ===================================================================
 * 关键设计：
 *   - 5 列等宽布局（手机 / 桌面 / 大屏都生效）
 *   - 高度按内容自然增长，不限制 max-height
 *   - .gallery-item 强制 1 列宽，绝不撑大
 *   - min-width: 0 + 1fr 是防"图片撑大列宽"的黄金组合
 *
 * 历史问题与修复：
 *   v6: grid-template-columns: repeat(5, minmax(0, 15%)) + max-height
 *       - 旧版有 max-height: 240px / 320px（用户要求移除）
 *       - minmax(0, 15%) 在某些浏览器 / 嵌套 grid 场景下解释不一致
 *   v7: 改用 repeat(5, 1fr) + 强约束 .gallery-item 宽度
 *       - 1fr 自动等分剩余空间（5 列均分 100% - gap）
 *       - 配合 .gallery-item 的 flex + min-width: 0 永不撑大
 *       - 完全移除 max-height 与 overflow-y，按内容自然增长
 * =================================================================== */
.gallery {
  display: grid;
  /* 5 列等宽：1fr 自动分配剩余空间，配合 min-width: 0 永不撑大 */
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  background: var(--code-bg);
  border-radius: 6px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  /* 高度按内容自然增长，不限制 */
  height: auto;
  /* 移除所有 max-height / overflow-y（旧版遗留的滚动条干扰，已按用户要求移除） */
}
@media (min-width: 1024px) {
  .gallery {
    gap: 6px;
    padding: 6px;
  }
}
.gallery.empty {
  display: flex; align-items: center; justify-content: center;
  text-align: center;
}
.gallery-item {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  display: flex; flex-direction: column;
  /* 关键：min-width: 0 + width: 100% + box-sizing 强制 item 只能占 1 列宽，绝不撑大 */
  min-width: 0;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.gallery-item img, .gallery-item video {
  width: 100%;
  max-width: 100%;        /* 关键：硬上限，图片不会撑出 item */
  min-width: 0;            /* 关键：让图片可以被压缩 */
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--video-bg);
  cursor: pointer;
  flex-shrink: 1;
}
/* 视频缩略图播放图标：覆盖在视频帧上，提示"可点击打开播放" */
/* 关键：pointer-events: none 让点击穿透到下层 video，由 video.click → 触发 lightbox */
.gallery-play-icon {
  position: absolute;
  bottom: 28px;            /* 留出 item-actions 高度 */
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 11px;
  line-height: 22px;
  text-align: center;
  z-index: 2;
  pointer-events: none;    /* 关键：点击穿透，不拦截 lightbox 打开 */
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  user-select: none;
}
.gallery-meta {
  padding: 2px 4px;
  font-size: 9px;
  display: flex; flex-direction: column; gap: 1px;
  line-height: 1.2;
  background: var(--panel-2);
  min-width: 0;            /* 同理：meta 也不被内容撑 */
  overflow: hidden;
}
.gallery-meta .name {
  color: var(--text);
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.2;
  min-width: 0;
}
.gallery-meta .info {
  color: var(--muted);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 8px;
  opacity: 0.75;
  min-width: 0;
}
.gallery-actions {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 6px; gap: 8px;
  flex-wrap: wrap;
}
.gallery-item .item-actions {
  display: flex; gap: 2px;
  padding: 2px 3px;
  border-top: 1px solid var(--border);
}
.gallery-item .item-actions a, .gallery-item .item-actions button {
  flex: 1;
  text-align: center;
  font-size: 9px;
  padding: 2px 3px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  text-decoration: none;
  cursor: pointer;
}
.gallery-item .item-actions a:hover,
.gallery-item .item-actions button:hover {
  background: var(--panel-2);
}
.gallery-item .badges {
  position: absolute;
  top: 2px; left: 2px;
  display: flex; gap: 2px;
  z-index: 2;
}
.badge-mini {
  display: inline-block;
  padding: 1px 4px;
  border-radius: 6px;
  font-size: 8px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,0.5);
}
.badge-mini.slot-A { background: var(--tag-a); }
.badge-mini.auto { background: var(--info); }
.badge-mini.saved { background: var(--success); }
.badge-mini.unsaved { background: var(--warn); }

/* ============= 日志面板 ============= */
.log-panel {
  background: var(--log-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  height: 200px;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}
.log-line {
  display: grid;
  grid-template-columns: 78px 50px 1fr;
  gap: 8px;
  padding: 2px 4px;
  border-bottom: 1px dashed var(--debug-row-alt);
  word-break: break-word;
}
.log-time { color: var(--muted); }
.log-level { font-weight: 600; text-align: center; border-radius: 3px; }
.log-level.lvl-info { color: var(--info); }
.log-level.lvl-ok { color: var(--success); }
.log-level.lvl-warn { color: var(--warn); }
.log-level.lvl-err { color: var(--danger); }
.log-msg { color: var(--text); }

/* ============= 调试信息面板 ============= */
.debug-panel { margin: 0 16px 16px; }
.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.debug-actions { display: flex; align-items: center; gap: 10px; }
.debug-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 10px;
}
.debug-grid details {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
}
.debug-grid summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  user-select: none;
  padding: 4px 0;
  color: var(--text);
}
.debug-grid summary:hover { color: var(--primary); }
.debug-table {
  margin-top: 8px;
  max-height: 320px;
  overflow-y: auto;
}
.debug-table dl {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.debug-table dt { color: var(--muted); }
.debug-table dd {
  margin: 0;
  word-break: break-all;
  color: var(--text);
}
.debug-table dd .ua { font-size: 11px; color: var(--muted); }
.debug-table dd pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  margin: 2px 0 0;
  font-size: 11px;
  line-height: 1.4;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
}
.debug-table .val-ok { color: var(--success); }
.debug-table .val-no { color: var(--danger); }
.debug-table .val-warn { color: var(--warn); }
.debug-table .pulse { animation: pulse 0.6s ease-out; }
@keyframes pulse {
  0% { background: var(--debug-row-pulse); }
  100% { background: transparent; }
}

.footer {
  text-align: center;
  padding: 12px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ============= Lightbox：照片/视频大图预览 ============= */
body.no-scroll { overflow: hidden; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  animation: lb-fadein 0.15s ease-out;
}
@keyframes lb-fadein { from { opacity: 0; } to { opacity: 1; } }

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: var(--lightbox-backdrop);
}

.lightbox-figure {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 64px 80px;
}
.lightbox-media {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: var(--video-bg);
  border-radius: 4px;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  background: var(--lightbox-btn-bg);
  color: var(--lightbox-btn-color);
  border: 1px solid var(--lightbox-border);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: background 0.15s;
  user-select: none;
}
.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
  background: var(--lightbox-btn-bg-hover);
}
.lightbox-close {
  top: 16px;
  right: 20px;
  font-size: 28px;
}
.lightbox-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 16px; top: 50%; transform: translateY(-50%); }

.lightbox-meta {
  position: relative;
  z-index: 2;
  padding: 12px 24px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--lightbox-text);
  font-size: 13px;
  background: var(--lightbox-meta-bg);
  border-top: 1px solid var(--lightbox-border);
}
.lightbox-name { font-weight: 600; }
.lightbox-info { color: var(--muted); }
.lightbox-counter { margin-left: auto; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

@media (max-width: 600px) {
  .lightbox-figure { padding: 56px 8px; }
  .lightbox-close,
  .lightbox-prev,
  .lightbox-next { width: 44px; height: 44px; font-size: 22px; }
  .lightbox-close { right: 8px; top: 8px; }
  .lightbox-prev { left: 4px; }
  .lightbox-next { right: 4px; }
  .lightbox-meta { padding: 10px 12px; font-size: 13px; gap: 8px; }
}

/* =================================================================
 * 响应式 3 档适配
 *   桌面  ≥ 1024px  — 当前布局
 *   平板  600-1023  — 单列堆叠，紧凑
 *   手机  < 600px   — 单列堆叠，触摸目标 ≥ 44px
 * ================================================================= */

/* 平板：单列堆叠，紧凑 */
@media (max-width: 1023px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }
  .debug-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }
  .debug-panel { margin: 0 12px 12px; }
}

/* 手机：触摸目标 ≥ 44px（iOS HIG），字号提升 */
@media (max-width: 599px) {
  .layout {
    padding: 8px;
    gap: 10px;
  }
  .panel {
    padding: 12px;
    border-radius: 8px;
  }
  .topbar {
    padding: 10px 12px;
    gap: 6px;
  }
  .topbar h1 { font-size: 15px; }
  .topbar-meta { gap: 6px; }
  .service-info, .small.muted { font-size: 11px; }

  /* 触摸目标最小 44px */
  .btn {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 14px;
  }
  .btn-small {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 13px;
  }

  /* 四件套：手机端保持 2 列（不浪费空间） */
  .slot-source {
    grid-template-columns: repeat(2, 1fr);
  }
  .field > .caption { font-size: 12px; }
  .field select {
    font-size: 14px;
    padding: 8px 10px;
  }
  .slot-fps { font-size: 12px; padding: 3px 8px; }

  /* 视频卡：紧凑 */
  .video-slot { padding: 8px; }
  .camera-layout { gap: 6px; }
  .slot-controls .btn { width: 100%; justify-content: center; }

  /* 镜头启用列表：触摸友好 */
  .camera-item {
    padding: 10px 8px;
    min-height: 40px;
  }
  /* 小屏：镜头列表改回单列，避免每列过窄 */
  .camera-list {
    grid-template-columns: 1fr;
    max-height: 200px;
  }

  /* 作品集：手机端 5 列等宽，按内容自然增长 */
  .gallery {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 3px;
    padding: 3px;
  }
  .gallery-item img, .gallery-item video {
    aspect-ratio: 1 / 1;
  }
  .gallery-meta {
    padding: 2px 3px;
    font-size: 8px;
  }
  .gallery-meta .info { font-size: 7px; }
  .gallery-actions { margin-top: 4px; }

  /* 调试面板：单列堆叠 */
  .debug-grid {
    grid-template-columns: 1fr;
  }
  .debug-table dl {
    grid-template-columns: 100px 1fr;
    font-size: 11px;
  }
  .debug-panel { margin: 0 8px 8px; }
  .debug-actions { font-size: 12px; }

  /* 徽章：略小 */
  .badge { font-size: 11px; padding: 3px 8px; }

  /* 日志：紧凑 */
  .log-panel { height: 160px; font-size: 11px; }
  .log-line { grid-template-columns: 70px 45px 1fr; }

  /* Footer */
  .footer { padding: 10px; font-size: 11px; }
}

/* iPhone SE 等小屏（< 360px） */
@media (max-width: 359px) {
  .topbar h1 { font-size: 14px; }
  .topbar-meta { gap: 4px; }
  .btn { font-size: 13px; padding: 8px 10px; }
  .btn-small { font-size: 12px; padding: 4px 8px; }
  .debug-table dl { grid-template-columns: 80px 1fr; }
}

/* ============= 镜头启用列表 ============= */
.camera-list-wrap {
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  margin-top: 4px;
}
.camera-list-wrap .section-caption {
  margin: 0 0 6px;
}
.camera-list {
  /* 多列网格布局：自动填充列数，每列最小 220px（容纳 label + id hint + 角标） */
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  padding: 6px;
  background: var(--code-bg);
  border-radius: 6px;
}
.camera-list:empty { display: none; }

.camera-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  font-size: 12px;
  /* 防止单行内容过长导致卡片异常拉伸 */
  min-width: 0;
}
.camera-item:hover { background: var(--btn-hover); }
.camera-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary) inset;
}
.camera-item input[type="checkbox"] {
  cursor: pointer;
  flex-shrink: 0;
}
.camera-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.camera-id-hint {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  opacity: 0.55;
  flex-shrink: 0;
  padding: 0 4px;
  background: var(--code-bg);
  border-radius: 3px;
}
.camera-current {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  background: var(--badge-info-bg);
  color: var(--info);
  flex-shrink: 0;
}
.camera-pos {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ============= 持久化按钮三态 ============= */
.btn-persist[data-state="loading"] {
  color: var(--muted);
  cursor: wait;
  opacity: 0.8;
}
.btn-persist[data-state="granted"] {
  color: var(--success);
  border-color: var(--success);
  background: var(--badge-ok-bg);
}
.btn-persist[data-state="denied"] { color: var(--warn); }
.btn-persist[data-state="unsupported"] {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.6;
}
/* 持久化按钮内的图标 / 文字：保留旧 class 以兼容 app.js 的 setPersistButton
 * - 间距由 .btn 的 gap: 6px 控制，这里不再加 margin-right 避免叠加
 */
.btn-persist .persist-icon { line-height: 1; }
.btn-persist .persist-text { font-size: 12px; }

/* ============= 主题切换按钮 ============= */
.btn-theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  min-height: 32px;
  line-height: 1;
}
.btn-theme-toggle .theme-icon-dark,
.btn-theme-toggle .theme-icon-light {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-theme-toggle .theme-icon-dark .icon,
.btn-theme-toggle .theme-icon-light .icon {
  width: 16px;
  height: 16px;
}
/* 浅色主题下按钮需要更明显的边框/底色，否则与浅色 panel 融为一体 */
:root.light .btn-theme-toggle {
  background: var(--panel-2);
  border-color: var(--border);
}
:root.light .btn-theme-toggle:hover {
  background: var(--btn-hover);
}

/* ============= 触摸设备优化 ============= */
/* 触摸设备上 .btn 在 :active 时给个明显反馈 */
@media (hover: none) {
  .btn:active:not(:disabled) {
    transform: scale(0.97);
    transition: transform 0.05s;
  }
}

/* ============= 减少动画（系统级偏好）============= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
