:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1f2630;
  --fg: #e6edf3;
  --dim: #8b949e;
  --accent: #ffb454;
  --accent2: #4ade80;
  --danger: #f85149;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 15px; touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}
.hidden { display: none !important; }
.dim { color: var(--dim); font-size: 13px; }
.center { text-align: center; padding: 40px 20px; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: var(--fg); }

#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.page { display: none; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page.active { display: flex; flex-direction: column; }
#page-camera { overflow: hidden; }

/* ---------- 拍摄页 ---------- */
#page-camera { position: relative; background: #000; }
#stage {
  position: absolute; inset: 0; background: #000; overflow: hidden;
  touch-action: none;
}
#stage::after {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 96px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent);
  pointer-events: none; z-index: 5;
}
#frame {
  position: absolute; left: 0; top: 0;
  overflow: hidden; background: #000;
}
#video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; transform-origin: center;
}
#video.mirror { transform: scaleX(-1); }
#video.mirror.zoomed { transform: scaleX(-1) scale(var(--zoom)); }
#video.zoomed { transform: scale(var(--zoom)); }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; }
#stage-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; z-index: 5;
  text-align: center; padding: 0 34px; background: #05070a;
}
#stage-empty p:first-child { font-size: 20px; font-weight: 700; }
#stage-empty-reason { color: #a8b3bf; font-size: 14px; line-height: 1.6; max-width: 340px; }
.btn-primary {
  background: var(--accent); color: #14100a; font-weight: 700;
  padding: 12px 28px; border-radius: 24px; font-size: 16px;
}
#top-hud {
  position: absolute; top: calc(8px + var(--safe-top)); left: 0; right: 0;
  display: flex; justify-content: center; gap: 8px; z-index: 6; padding: 0 10px;
}
.hud-btn {
  background: rgba(10, 12, 16, 0.45); border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px; padding: 7px 12px; font-size: 12px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); min-width: 42px;
}
.hud-btn.on { background: var(--accent); color: #14100a; font-weight: 700; border-color: transparent; }

#align-hud {
  position: absolute; top: calc(56px + var(--safe-top)); right: 10px; z-index: 6;
  display: flex; align-items: center; gap: 8px;
  background: rgba(10, 12, 16, 0.55); border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 22px; padding: 5px 13px 5px 5px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#align-score-wrap { position: relative; width: 40px; height: 40px; }
#align-ring { width: 40px; height: 40px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255,255,255,0.15); stroke-width: 4; }
.ring-fg {
  fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round;
  stroke-dasharray: 119.4; stroke-dashoffset: 119.4; transition: stroke-dashoffset 0.25s, stroke 0.25s;
}
#align-hud.ok .ring-fg { stroke: var(--accent2); }
#align-score { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
#align-tip { font-size: 12px; max-width: 42vw; line-height: 1.35; }

#countdown {
  position: absolute; inset: 0; z-index: 8; display: flex;
  align-items: center; justify-content: center;
  font-size: 110px; font-weight: 800; color: var(--accent);
  text-shadow: 0 4px 30px rgba(0,0,0,0.6);
}
#toast {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(10, 12, 16, 0.8); border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 9px 18px; border-radius: 999px;
  font-size: 13px; z-index: 9; white-space: nowrap; max-width: 92%;
  overflow: hidden; text-overflow: ellipsis;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}

/* 底部悬浮控制层 */
#cam-ui {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; flex-direction: column; padding-top: 26px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.97) 0%, rgba(0, 0, 0, 0.92) 55%, rgba(0, 0, 0, 0.5) 82%, transparent 100%);
}

#zoom-bar {
  display: flex; align-items: center; gap: 8px; padding: 0 16px 6px;
}
.zoom-btn {
  width: 36px; height: 36px; border-radius: 50%; background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11.5px; flex-shrink: 0; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.zoom-btn.active { background: var(--accent); color: #14100a; font-weight: 700; border-color: transparent; }
#zoom-slider { flex: 1; }

#exposure-wrap {
  display: flex; align-items: center; gap: 8px; padding: 0 20px 6px;
  font-size: 16px;
}
#exposure-wrap input { flex: 1; }

#template-strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 6px 14px;
  scrollbar-width: none;
}
#template-strip::-webkit-scrollbar { display: none; }
.tpl-chip {
  flex-shrink: 0; background: rgba(255, 255, 255, 0.08);
  border: 1.5px solid rgba(255, 255, 255, 0.06);
  border-radius: 999px; padding: 7px 14px; font-size: 12.5px; text-align: center;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.tpl-chip small { display: block; color: var(--dim); font-size: 9.5px; margin-top: 1px; }
.tpl-chip.none { color: var(--dim); }
.tpl-chip.active { border-color: var(--accent); background: rgba(255, 180, 84, 0.16); }

#bottom-bar {
  display: flex; align-items: center; justify-content: space-around;
  padding: 8px 34px calc(10px + var(--safe-bottom));
}
#btn-shutter {
  width: 68px; height: 68px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.9);
  display: flex; align-items: center; justify-content: center;
}
#btn-shutter span { width: 54px; height: 54px; border-radius: 50%; background: #fff; transition: transform 0.1s; }
#btn-shutter:active span { transform: scale(0.85); background: var(--accent); }
#btn-gallery-thumb, #btn-filter-toggle {
  font-size: 22px; width: 48px; height: 48px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
#btn-filter-toggle.on { border-color: var(--accent); color: var(--accent); }

#filter-bar { padding: 2px 14px 8px; }
#filter-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
#filter-chips::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0; padding: 6px 14px; border-radius: 999px; font-size: 12.5px;
  background: rgba(255, 255, 255, 0.08); border: 1.5px solid rgba(255, 255, 255, 0.06);
}
.filter-chip.active { border-color: var(--accent); color: var(--accent); background: rgba(255, 180, 84, 0.14); }
#filter-strength-wrap { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--dim); }
#filter-strength-wrap input { flex: 1; }

/* 姿势模板面板：默认收成一条，点「调整」展开，不再挤压取景画面 */
#template-panel {
  margin: 2px 12px 6px; padding: 10px 14px;
  background: rgba(26, 30, 38, 0.92); border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
#tpl-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#template-info { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#template-info b { font-size: 14px; }
#tpl-tags { color: var(--accent); font-size: 11px; margin-left: 8px; }
#tpl-head-btns { display: flex; gap: 8px; flex-shrink: 0; }
#tpl-body { display: none; margin-top: 2px; max-height: 34dvh; overflow-y: auto; }
#template-panel.expanded #tpl-body { display: block; }
#tpl-tips { color: var(--dim); font-size: 12px; line-height: 1.55; margin: 8px 0 10px; }
.panel-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; }
.panel-row label { color: var(--dim); flex-shrink: 0; width: 52px; }
.panel-row input[type=range] { flex: 1; }
.panel-row.buttons { justify-content: flex-end; }
.switch-label { width: auto !important; color: var(--fg) !important; display: flex; align-items: center; gap: 5px; font-size: 12.5px; }
.mini-btn {
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px; padding: 6px 12px;
  font-size: 12px; flex-shrink: 0;
}
.mini-btn.active { background: rgba(255, 180, 84, 0.25); border-color: var(--accent); color: var(--accent); }

/* ---------- 通用页头/芯片 ---------- */
.page-head { padding: calc(18px + var(--safe-top)) 20px 10px; }
.page-head h2 { font-size: 21px; margin-bottom: 4px; }
.page-head p { color: var(--dim); font-size: 13px; }
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 12px; scrollbar-width: none; flex-shrink: 0; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 7px 15px; border-radius: 18px; font-size: 13px;
  background: var(--panel); border: 1.5px solid transparent;
}
.chip.active { border-color: var(--accent); color: var(--accent); background: #2a2417; }

/* ---------- 模板库 ---------- */
#template-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  padding: 0 16px 90px;
}
.tpl-card {
  background: var(--panel); border-radius: 16px; padding: 14px; text-align: left;
  border: 1.5px solid transparent;
}
.tpl-card.active { border-color: var(--accent); }
.tpl-card canvas { width: 100%; aspect-ratio: 3/4; background: #0a0e13; border-radius: 10px; }
.tpl-card .name { font-weight: 700; margin-top: 8px; font-size: 14px; }
.tpl-card .tags { color: var(--accent); font-size: 11px; margin-top: 2px; }
.tpl-card .tip { color: var(--dim); font-size: 11.5px; margin-top: 5px; line-height: 1.45; }
.tpl-card .use { color: var(--accent); font-size: 12px; margin-top: 8px; font-weight: 700; }

/* ---------- 图库 ---------- */
#gallery-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px;
  padding: 0 3px 90px;
}
#gallery-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }

/* ---------- 学习 ---------- */
#learn-list { padding: 0 16px 90px; display: flex; flex-direction: column; gap: 12px; }
.learn-card { background: var(--panel); border-radius: 16px; padding: 16px; }
.learn-card h3 { font-size: 15.5px; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.learn-card ul { list-style: none; }
.learn-card li {
  font-size: 13.5px; line-height: 1.6; color: #c9d1d9; padding: 5px 0 5px 18px;
  position: relative; border-bottom: 1px dashed #21262d;
}
.learn-card li:last-child { border-bottom: none; }
.learn-card li::before { content: "▸"; position: absolute; left: 2px; color: var(--accent); }
.learn-card .bad { color: var(--danger); }
.learn-card .good { color: var(--accent2); }

/* ---------- 页签 ---------- */
#tabbar {
  display: flex; background: rgba(10, 12, 16, 0.94); border-top: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding-bottom: var(--safe-bottom); flex-shrink: 0; position: relative; z-index: 20;
}
.tab {
  flex: 1; padding: 8px 0 7px; font-size: 20px; color: var(--dim);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.tab span { font-size: 11px; }
.tab.active { color: var(--accent); }

/* ---------- 查看器 ---------- */
#viewer {
  position: fixed; inset: 0; z-index: 50; background: #000;
  display: flex; flex-direction: column;
}
#viewer-top {
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + var(--safe-top)) 14px 10px;
}
#viewer-top button { font-size: 20px; width: 44px; height: 44px; }
#viewer-stage { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; }
#viewer-menu {
  position: absolute; right: 12px; top: calc(60px + var(--safe-top));
  background: var(--panel2); border-radius: 14px; overflow: hidden; z-index: 5;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
#viewer-menu button { display: block; width: 100%; padding: 13px 20px; font-size: 14px; text-align: left; }
#viewer-menu button:active { background: var(--panel); }
#act-delete { color: var(--danger); }

#editor { position: absolute; inset: 0; background: #000; display: flex; flex-direction: column; z-index: 6; }
#editor-preview-wrap { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#editor-canvas { max-width: 100%; max-height: 100%; }
#editor-controls { background: var(--panel); padding: 10px 14px calc(12px + var(--safe-bottom)); max-height: 46dvh; overflow-y: auto; }
#editor-controls .panel-row label { width: 56px; }

/* ---------- 通用控件 ---------- */
input[type=range] {
  -webkit-appearance: none; appearance: none; height: 26px; background: transparent;
}
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: #30363d; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); margin-top: -8px;
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: #30363d; }
input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); border: none; }
input[type=checkbox] { accent-color: var(--accent); width: 17px; height: 17px; }
#video.flash-anim { animation: flashAnim 0.35s; }
@keyframes flashAnim { 0% { filter: brightness(2.5); } 100% { filter: brightness(1); } }
