/* ============ 基础变量 ============ */
:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --accent: #f59e0b;
  --accent-light: #fef3c7;
  --success: #10b981;
  --danger: #ef4444;
  --text: #1e293b;
  --text-sub: #64748b;
  --border: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 60px rgba(15, 23, 42, 0.25);
}

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

body {
  font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, #eef2ff 0%, #f1f5f9 50%, #fdf2f8 100%);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
svg { width: 20px; height: 20px; }
.hidden { display: none !important; }

.app { max-width: 1500px; margin: 0 auto; padding: 0 24px 40px; }

/* ============ 顶部栏 ============ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-icon {
  width: 52px; height: 52px; border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(79, 70, 229, .35);
}
.brand-icon svg { width: 30px; height: 30px; }
.brand-text h1 { font-size: 24px; font-weight: 800; letter-spacing: .5px; }
.brand-text p { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.badge {
  background: var(--primary-light); color: var(--primary);
  padding: 8px 14px; border-radius: 20px; font-size: 13px; font-weight: 700;
}
.icon-btn {
  width: 42px; height: 42px; border: 1px solid var(--border);
  background: #fff; border-radius: 12px; color: var(--text-sub);
  display: grid; place-items: center; transition: .2s;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ============ 步骤指示器 ============ */
.steps {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--card); border-radius: 16px; padding: 14px 24px;
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.step { display: flex; align-items: center; gap: 8px; opacity: .45; transition: .3s; }
.step.active { opacity: 1; }
.step.done { opacity: .8; }
.step-num {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--border); color: var(--text-sub);
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  transition: .3s;
}
.step.active .step-num { background: var(--primary); color: #fff; box-shadow: 0 3px 10px rgba(79,70,229,.4); }
.step.done .step-num { background: var(--success); color: #fff; }
.step-label { font-size: 13px; font-weight: 600; white-space: nowrap; }
.step.active .step-label { color: var(--primary); }
.step-line { flex: 0 0 40px; height: 2px; background: var(--border); border-radius: 2px; }

/* ============ 主体布局 ============ */
.main { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.stage-wrap {
  background: var(--card); border-radius: 20px; padding: 18px;
  box-shadow: var(--shadow);
}

/* ============ 舞台 ============ */
.stage {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #0f172a; border-radius: 14px; overflow: hidden;
}
.stage video, .stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover;
}
.stage video { transform: scaleX(-1); }  /* 镜像，自拍更自然 */
.stage canvas { display: none; }
.stage.photo-mode video { display: none; }
.stage.photo-mode canvas { display: block; }

.stage-mask {
  position: absolute; inset: 0; z-index: 10;
  background: rgba(15, 23, 42, .82); backdrop-filter: blur(4px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; text-align: center; padding: 20px;
}
.mask-icon {
  width: 72px; height: 72px; border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  display: grid; place-items: center; margin-bottom: 18px;
  box-shadow: 0 8px 24px rgba(79,70,229,.5);
}
.mask-icon svg { width: 38px; height: 38px; }
.stage-mask h2 { font-size: 22px; margin-bottom: 8px; }
.stage-mask p { color: #cbd5e1; font-size: 14px; margin-bottom: 22px; }
.mask-tip { font-size: 12px !important; color: #94a3b8 !important; margin-top: 16px !important; margin-bottom: 0 !important; }

.spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.2); border-top-color: #fff;
  animation: spin .8s linear infinite; margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.countdown {
  position: absolute; inset: 0; z-index: 12;
  display: grid; place-items: center;
  font-size: 140px; font-weight: 900; color: #fff;
  text-shadow: 0 8px 30px rgba(0,0,0,.5);
  background: rgba(15,23,42,.3);
  animation: pop .5s ease;
}
@keyframes pop { 0% { transform: scale(1.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

.drawing-bar {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 9;
  background: rgba(15,23,42,.85); color: #fff; padding: 10px 20px;
  border-radius: 30px; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 10px;
}
.drawing-dots { display: flex; gap: 4px; }
.drawing-dots i { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; animation: blink 1s infinite; }
.drawing-dots i:nth-child(2) { animation-delay: .2s; }
.drawing-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,100% { opacity: .3; } 50% { opacity: 1; } }

/* ============ 控制按钮 ============ */
.controls { display: flex; gap: 12px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 22px; border-radius: 12px; font-size: 14px; font-weight: 700;
  border: 2px solid transparent; transition: .2s; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(79,70,229,.3); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); transform: translateY(-1px); }
.btn-ghost { background: #fff; color: var(--text-sub); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn-lg { padding: 14px 32px; font-size: 16px; }
.btn-draw { background: linear-gradient(135deg, var(--accent), #f97316); box-shadow: 0 4px 16px rgba(245,158,11,.4); }
.btn-draw:hover:not(:disabled) { filter: brightness(1.05); transform: translateY(-1px); }
.stage-hint { text-align: center; font-size: 12px; color: var(--text-sub); margin-top: 14px; }

/* ============ 侧边栏 ============ */
.sidebar { display: flex; flex-direction: column; gap: 16px; }
.panel { background: var(--card); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); }
.panel-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; margin-bottom: 16px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.panel-title svg { width: 18px; height: 18px; color: var(--primary); }
.setting-item { margin-bottom: 18px; }
.setting-item:last-child { margin-bottom: 0; }
.setting-item label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.setting-value { float: right; color: var(--primary); }
.setting-desc { font-size: 11px; color: var(--text-sub); margin-top: 6px; line-height: 1.5; }
input[type=range] { width: 100%; accent-color: var(--primary); cursor: pointer; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.setting-row label { margin: 0; }
.switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 24px; transition: .3s; }
.slider:before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .3s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* 历史记录 */
.clear-btn { margin-left: auto; background: none; border: none; color: var(--text-sub); font-size: 12px; padding: 2px 6px; border-radius: 6px; }
.clear-btn:hover { color: var(--danger); background: #fef2f2; }
.history-list { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.history-empty { text-align: center; color: var(--text-sub); font-size: 13px; padding: 24px 0; }
.history-item {
  display: flex; align-items: center; gap: 10px; padding: 8px;
  background: var(--primary-light); border-radius: 10px; font-size: 13px;
}
.history-item img { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; }
.history-item .h-info { flex: 1; }
.history-item .h-info strong { display: block; font-size: 13px; }
.history-item .h-info span { font-size: 11px; color: var(--text-sub); }
.history-item .h-time { font-size: 11px; color: var(--text-sub); }

.tip-panel { display: flex; gap: 12px; background: linear-gradient(135deg, #fffbeb, #fef3c7); border: 1px solid #fde68a; }
.tip-icon { font-size: 22px; flex-shrink: 0; }
.tip-panel strong { font-size: 13px; color: #92400e; }
.tip-panel p { font-size: 11px; color: #b45309; line-height: 1.6; margin-top: 4px; }

/* ============ 抽选结果弹窗 ============ */
.result-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, .75); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 20px;
  animation: fadeIn .3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.result-card {
  position: relative; background: #fff; border-radius: 28px;
  padding: 40px 40px 32px; text-align: center;
  box-shadow: var(--shadow-lg); max-width: 420px; width: 100%;
  animation: cardPop .5s cubic-bezier(.2,1.3,.4,1);
}
@keyframes cardPop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.result-close {
  position: absolute; top: 16px; right: 20px;
  background: none; border: none; font-size: 28px; color: var(--text-sub); line-height: 1;
}
.result-close:hover { color: var(--danger); }
.result-label { font-size: 18px; font-weight: 700; color: var(--primary); margin-bottom: 24px; }
.result-avatar-wrap { position: relative; width: 220px; height: 220px; margin: 0 auto 20px; }
.result-avatar-ring {
  position: absolute; inset: -10px; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--primary), var(--accent), var(--primary));
  animation: rotate 3s linear infinite;
}
@keyframes rotate { to { transform: rotate(360deg); } }
#resultAvatar {
  position: relative; width: 220px; height: 220px; border-radius: 50%;
  border: 5px solid #fff; object-fit: cover; display: block;
}
.result-number {
  position: absolute; bottom: 0; right: 0; width: 48px; height: 48px;
  background: var(--accent); color: #fff; border: 4px solid #fff;
  border-radius: 50%; display: grid; place-items: center;
  font-size: 18px; font-weight: 800;
}
.result-name { font-size: 28px; font-weight: 800; margin-bottom: 24px; }
.result-actions { display: flex; gap: 12px; justify-content: center; }

/* 彩带 */
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 18px;
  opacity: 0; animation: confettiFall 2.5s ease-in forwards;
}
@keyframes confettiFall {
  0% { opacity: 1; transform: translateY(0) rotate(0); }
  100% { opacity: 0; transform: translateY(100vh) rotate(720deg); }
}

/* ============ 响应式 ============ */
@media (max-width: 1000px) {
  .main { grid-template-columns: 1fr; }
  .sidebar { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
@media (max-width: 640px) {
  .app { padding: 0 12px 30px; }
  .brand-text h1 { font-size: 18px; }
  .steps { padding: 12px; gap: 4px; }
  .step-label { display: none; }
  .step-line { flex-basis: 30px; }
  .controls .btn { flex: 1; padding: 10px 12px; font-size: 12px; }
  .stage-hint { font-size: 11px; }
}
