:root {
  --primary-color: #2563eb;
  --primary-bg: #3b82f6;
  --primary-light: #60a5fa;
  --danger-color: #ef4444;
  --success-color: #10b981;
  --warn-color: #f59e0b;
  --bg-color: #f5f5f5;
  --page-gradient: linear-gradient(165deg, #ffffff 0%, #f7f8fa 50%, #f0f1f3 100%);
  --text-color: #1e293b;
  --text-secondary: #64748b;
  --text-faint: #94a3b8;
  --border-color: #e2e8f0;
  --radius: 14px;
  --switch-on: #2563eb;
  --btn-width: 80%;
  --btn-max: 360px;
  --btn-height: 50px;
  --shadow-brand: 0 8px 32px rgba(37, 99, 235, .12);
}

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

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg-color);
  color: var(--text-color);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

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

/* === 通用按钮 === */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  width: 200px; height: 44px; border: none; border-radius: 22px;
  background: var(--primary-color); color: #fff; font-size: 16px;
  cursor: pointer; transition: opacity .2s;
}
.btn-primary:active { opacity: .85; }
.btn-primary:disabled { background: #c8c9cc; cursor: not-allowed; }

.btn-outline {
  padding: 8px 24px; border: 1px solid var(--border-color);
  background: #fff; border-radius: 20px; color: var(--text-color);
  font-size: 14px; cursor: pointer;
}

/* === 通用按钮（facelive 用） === */
.fl-btn {
  width: var(--btn-width); max-width: var(--btn-max); height: var(--btn-height);
  border: none; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary-light), var(--primary-color));
  color: #fff; font-size: 16px; font-weight: 500; cursor: pointer;
  transition: opacity .2s, transform .15s; letter-spacing: 1px;
}
.fl-btn:active { opacity: .88; transform: scale(.98); }
.fl-btn:disabled { background: #cbd5e1; color: #64748b; cursor: not-allowed; }
.fl-btn-outline {
  width: var(--btn-width); max-width: var(--btn-max); height: var(--btn-height);
  border: 1.5px solid var(--primary-color); border-radius: var(--radius);
  background: #fff; color: var(--primary-color); font-size: 16px; font-weight: 500;
  cursor: pointer; transition: opacity .2s, transform .15s; letter-spacing: 1px;
}
.fl-btn-outline:active { opacity: .88; transform: scale(.98); }
.fl-btn-ghost {
  width: var(--btn-width); max-width: var(--btn-max); height: var(--btn-height);
  border: 1.5px solid #e2e8f0; border-radius: var(--radius);
  background: #f1f5f9; color: #64748b; font-size: 16px; font-weight: 500;
  cursor: pointer; transition: opacity .2s, transform .15s; letter-spacing: 1px;
}
.fl-btn-ghost:active { opacity: .88; transform: scale(.98); }
.fl-btn-ghost.disabled { opacity: .7; cursor: not-allowed; transform: none; }

/* === 首页（初始化页） === */
.init-container {
  width: 100vw; height: 100vh; margin: 0 auto;
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  background: var(--page-gradient);
  padding: 0 24px;
  gap: 48px;
}
.init-container .init-top {
  display: flex; flex-direction: column; align-items: center; width: 100%;
}
.init-container .init-logo {
  width: 42%; margin-bottom: 28px; opacity: .9; object-fit: contain;
}
.init-container .message { text-align: center; line-height: 1.6; }
.init-container .message #initTitle { font-size: 22px; font-weight: 600; color: var(--text-color); }
.init-container .message #initScene { font-size: 14px; color: var(--text-secondary); margin-top: 8px; }
.init-container .document { width: var(--btn-width); max-width: var(--btn-max); font-size: 13px; color: var(--text-secondary); padding: 0 5px; }
.init-container .init-bottom {
  display: flex; flex-direction: column; align-items: center; width: 100%;
  gap: 16px;
}

/* 自定义圆形勾选框 */
.proto-check { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.proto-check input { display: none; }
.proto-check .check-box {
  display: block; width: 20px; height: 20px; border-radius: 50%;
  border: 1.5px solid var(--primary-color); background: #fff;
  flex-shrink: 0; position: relative; transition: all .2s;
}
.proto-check input:checked + .check-box { background: var(--primary-color); }
.proto-check input:checked + .check-box::after {
  content: ''; position: absolute; left: 6px; top: 3px;
  width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.proto-check a { color: var(--primary-color); }

/* 错误提示胶囊 */
.init-container .message-area {
  width: var(--btn-width); max-width: var(--btn-max);
  background: #eff6ff; color: var(--primary-color); font-size: 13px;
  border-radius: var(--radius); padding: 10px 14px; text-align: center;
  margin-bottom: 16px;
}

/* === 检测页 === */
.aix-container {
  width: 100vw; height: 100vh; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  overflow-y: auto; background: var(--page-gradient);
  padding: 24px 24px 20vh;
  gap: 24px;
}

/* 顶部状态标签 */
.status-tag {
  display: inline-flex; align-items: center; gap: 8px;
  background: #eff6ff; color: var(--primary-color); font-size: 14px; font-weight: 500;
  padding: 8px 18px; border-radius: 999px;
}
.status-tag .dots { display: inline-flex; gap: 4px; }
.status-tag .dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--primary-color); opacity: .4;
  animation: dot-pulse 1.2s infinite;
}
.status-tag .dots span:nth-child(2) { animation-delay: .2s; }
.status-tag .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dot-pulse { 0%, 80%, 100% { opacity: .4; } 40% { opacity: 1; } }

/* 视频框 + 光晕环 + 进度环 */
.video-stage { position: relative; display: flex; align-items: center; justify-content: center; }
.video-ring {
  position: absolute; inset: -10px; border-radius: 50%;
  border: 4px solid rgba(37, 99, 235, .25);
  box-shadow: 0 0 24px rgba(37, 99, 235, .3);
  transition: border-color .3s ease, box-shadow .3s ease;
  pointer-events: none;
}
#aix-video {
  width: 70vw; height: 70vw; max-width: 320px; max-height: 320px;
  flex-shrink: 0; object-fit: cover; z-index: 10;
  background-color: #1e293b; transform: scaleX(-1); border-radius: 50%;
  position: relative;
}
/* 进度环 SVG 覆盖在光晕环上 */
.progress-ring { position: absolute; inset: -10px; pointer-events: none; z-index: 11; }
.progress-ring circle { fill: none; stroke-width: 4; }
.progress-ring .track { stroke: rgba(37, 99, 235, .12); }
.progress-ring .bar { stroke: var(--primary-color); stroke-linecap: round; transition: stroke-dashoffset .1s linear; }

/* 人脸引导线 */
.face-guide {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 50%; height: 60%; border: 1.5px dashed rgba(255, 255, 255, .25);
  border-radius: 50%; z-index: 12; pointer-events: none;
}

/* 下方提示区 */
.prompt-area { text-align: center; min-height: 28px; }
.prompt-area .prompt-row { display: inline-flex; align-items: center; gap: 8px; font-size: 16px; color: var(--text-color); }
.prompt-area .prompt-row .prompt-icon { width: 20px; height: 20px; flex-shrink: 0; }
.prompt-area .prompt-row.info .prompt-icon { color: var(--primary-color); }
.prompt-area .prompt-row.warn .prompt-icon { color: var(--warn-color); }
.prompt-area .prompt-row.ok .prompt-icon { color: var(--success-color); }

/* 静态拍摄指引 */
.tips-area { display: flex; flex-direction: column; gap: 8px; }
.tips-area .tip-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.tips-area .tip-row svg { width: 16px; height: 16px; color: var(--text-faint); flex-shrink: 0; }

/* === 结果页（全屏沉浸） === */
#resultArea {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 100%; flex: 1; padding: 40px 24px; text-align: center;
}
.result-icon-wrap { position: relative; width: 80px; height: 80px; margin-bottom: 24px; }
.result-icon {
  width: 80px; height: 80px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; position: relative; z-index: 2;
  animation: icon-pop .5s cubic-bezier(.18, .89, .32, 1.28);
}
.result-icon.pass { background: linear-gradient(135deg, var(--primary-light), var(--primary-color)); }
.result-icon.fail { background: var(--danger-color); animation: icon-pop .5s cubic-bezier(.18, .89, .32, 1.28), shake .4s .5s 2; }
.result-icon svg { width: 40px; height: 40px; color: #fff; }
/* 通过扩散光环 */
.result-icon-wrap.pass .ripple {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--primary-color); opacity: 0;
  animation: ripple-out 1.5s ease-out .3s 2;
}
@keyframes icon-pop { 0% { transform: scale(0); } 60% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes ripple-out { 0% { transform: scale(1); opacity: .5; } 100% { transform: scale(2.2); opacity: 0; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.result-pass { font-size: 28px; font-weight: 600; color: var(--text-color); margin-bottom: 12px; }
.result-prompt { font-size: 16px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 32px; max-width: 320px; }
#resultArea .result-btns { display: flex; flex-direction: column; gap: 12px; width: 100%; align-items: center; }

/* 上报异常（底部低调链接，检测页与结果页通用） */
#reportLink {
  position: static; color: var(--text-faint); font-size: 13px;
  text-decoration: none; display: block; text-align: center;
  margin-top: 24px; padding: 8px 0 16px;
}
#reportLink:active { color: var(--text-secondary); }

/* Toast 提示 */
.fl-toast {
  position: fixed; left: 50%; bottom: 20%; transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,.78); color: #fff; font-size: 14px; line-height: 1.5;
  padding: 10px 20px; border-radius: 8px; max-width: 80%; text-align: center;
  opacity: 0; transition: opacity .3s, transform .3s; z-index: 9999; pointer-events: none;
}
.fl-toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* === Demo 页 === */
.demo-page {
  display: flex; flex-direction: column; align-items: center;
  min-height: 100vh; background: #fff; padding: 0 16px;
}
.demo-page .demo-header {
  width: 100%; max-width: 600px; margin: 0 auto; padding-top: 40px;
}
.demo-page .demo-desc {
  font-size: 13px; color: var(--text-secondary); line-height: 1.7;
  background: #f7f8fa; border-radius: var(--radius); padding: 12px 16px;
  margin-bottom: 24px;
}
.demo-page .demo-body {
  width: 100%; max-width: 600px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center;
}
.demo-page .device-input {
  width: 100%; font-size: 15px; padding: 12px 16px;
  border: 1px solid var(--border-color); border-radius: var(--radius);
  margin-bottom: 20px; outline: none; transition: border-color .2s;
}
.demo-page .device-input:focus { border-color: var(--primary-color); }

.demo-page .result-icon:empty { display: none; }
.demo-page .result-icon {
  margin: 16px 0; font-size: 36px; font-weight: 600;
  width: auto; height: auto; border-radius: 0; background: none;
  animation: none;
}
.demo-page .result-icon.pass { color: #07c160; }
.demo-page .result-icon.fail { color: var(--danger-color); }

.demo-page .upload-btn { margin: 8px 0 32px; }

.demo-page .switch-group {
  width: 100%; display: flex; flex-direction: column; gap: 16px;
  margin-bottom: 32px;
}
.demo-page .switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; background: #f7f8fa; border-radius: var(--radius);
}
.demo-page .switch-row .switch-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 15px; color: var(--text-color);
}
.demo-page .switch-row .help-icon {
  width: 18px; height: 18px; border-radius: 50%;
  background: #c8c9cc; color: #fff; font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.demo-page .switch-row .help-icon:active { background: var(--primary-color); }

/* iOS 风格开关 */
.switch-toggle {
  position: relative; width: 44px; height: 26px; flex-shrink: 0;
}
.switch-toggle input { opacity: 0; width: 0; height: 0; }
.switch-toggle .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #c8c9cc; border-radius: 13px; transition: .3s;
}
.switch-toggle .slider::before {
  content: ''; position: absolute; width: 22px; height: 22px;
  left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .3s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch-toggle input:checked + .slider { background: var(--switch-on); }
.switch-toggle input:checked + .slider::before { transform: translateX(18px); }

.demo-page .result-display {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 12px 16px; background: #fff; border-top: 1px solid var(--border-color);
  font-size: 12px; color: var(--text-secondary); word-break: break-all;
  max-height: 120px; overflow-y: auto; z-index: 100;
}

/* === 裁剪弹窗 === */
.crop-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,.6); z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.crop-dialog {
  background: #fff; border-radius: var(--radius); padding: 20px;
  width: 90%; max-width: 500px;
}
.crop-dialog h3 { margin-bottom: 16px; font-size: 16px; text-align: center; }
.crop-dialog .crop-body { width: 100%; height: 50vh; overflow: hidden; }
.crop-dialog .crop-footer {
  display: flex; gap: 12px; margin-top: 16px; justify-content: flex-end;
}

.hidden { display: none !important; }

/* === 调试面板 === */
.debug-panel {
  position: fixed; z-index: 9999;
  background: rgba(30, 41, 59, .88); color: #e2e8f0;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 11px; line-height: 1.6; white-space: pre;
  padding: 8px 10px; border-radius: 8px; margin: 0;
  pointer-events: none; backdrop-filter: blur(4px);
}
.debug-stt { top: 8px; right: 8px; min-width: 120px; }
.debug-prf { bottom: 8px; left: 8px; max-width: 240px; max-height: 100px; overflow-y: auto; }
