:root {
  --bg0: #070a12;
  --bg1: #101527;
  --fg: #eef2ff;
  --muted: #93a0bd;
  --accent: #7c9cff;
  --accent2: #59e1c8;
  --glass: rgba(20, 26, 42, 0.62);
  --line: rgba(255, 255, 255, 0.1);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg0);
  color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  background:
    radial-gradient(120% 80% at 50% 0%, #1b2340 0%, transparent 60%),
    radial-gradient(90% 70% at 80% 100%, #102b33 0%, transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg0) 70%);
}

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; }

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
  pointer-events: none;
  z-index: 20;
}

.brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; letter-spacing: .02em;
  color: #dbe3ff;
  text-shadow: 0 1px 12px rgba(0, 0, 0, .6);
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4b5672;
  box-shadow: 0 0 0 0 rgba(89, 225, 200, .5);
  transition: background .2s;
}
.dot.live { background: var(--accent2); animation: pulse 2s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(89, 225, 200, .45); }
  70% { box-shadow: 0 0 0 9px rgba(89, 225, 200, 0); }
  100% { box-shadow: 0 0 0 0 rgba(89, 225, 200, 0); }
}

.stats { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.stats small { margin-left: 3px; opacity: .6; }

#cam-preview {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 46px);
  right: 14px;
  width: 84px; height: 112px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #000;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
  z-index: 15;
  opacity: .92;
  transition: opacity .25s, transform .25s;
}
#cam-preview.hidden { opacity: 0; transform: translateY(-6px) scale(.96); pointer-events: none; }
#cam-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
#cam-preview.no-mirror video { transform: none; }
#landmarks {
  position: absolute; inset: 0; width: 100%; height: 100%;
  transform: scaleX(-1);
  pointer-events: none;
}
#cam-preview.no-mirror #landmarks { transform: none; }

#hint {
  position: fixed;
  left: 50%; bottom: calc(var(--safe-b) + 96px);
  transform: translateX(-50%);
  max-width: 82vw;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(12, 16, 28, .55);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  z-index: 12;
  transition: opacity .35s, transform .35s;
  pointer-events: none;
}
#hint.gone { opacity: 0; transform: translateX(-50%) translateY(8px); }

#toolbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex; gap: 8px; align-items: center;
  padding: 10px 14px calc(var(--safe-b) + 12px);
  background: linear-gradient(180deg, transparent, rgba(5, 8, 15, .82) 40%);
  z-index: 30;
}

.btn {
  flex: 1 1 auto;
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(14px);
  color: var(--fg);
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: .02em;
  transition: transform .12s, background .2s, opacity .2s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; }
.btn.primary {
  flex: 1.6 1 auto;
  background: linear-gradient(135deg, #6f8dff, #4f6fe8);
  border-color: rgba(160, 180, 255, .55);
  box-shadow: 0 6px 24px rgba(79, 111, 232, .35);
}
.btn.primary.stop { background: linear-gradient(135deg, #ff7b8a, #e0526a); border-color: rgba(255, 160, 175, .5); box-shadow: 0 6px 24px rgba(224, 82, 106, .3); }
.btn.on { background: rgba(89, 225, 200, .16); border-color: rgba(89, 225, 200, .45); color: #b8fff1; }
.btn.ghost { flex: 0 0 64px; background: transparent; }

/* 手机端表情快捷面板 */
.expr-fab {
  position: fixed;
  right: 14px;
  bottom: calc(var(--safe-b) + 80px);
  z-index: 31;
  height: 44px;
  padding: 0 18px;
  border-radius: 22px;
  border: 1px solid rgba(160, 180, 255, .45);
  background: rgba(28, 38, 66, .88);
  backdrop-filter: blur(14px);
  color: #dce4ff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .04em;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .35);
  touch-action: manipulation;
}
.expr-fab:active { transform: scale(.96); }
.expr-pop {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(var(--safe-b) + 132px);
  z-index: 32;
  max-width: 420px;
  margin-left: auto;
  padding: 10px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(12, 18, 32, .95);
  backdrop-filter: blur(18px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .5);
}
.expr-pop.hidden { display: none; }
.expr-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 8px;
  font-size: 13px;
  color: rgba(220, 230, 255, .65);
}
.expr-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-height: 42vh;
  overflow: auto;
}
.expr-grid .chip {
  min-height: 38px;
  padding: 4px 6px;
  font-size: 12.5px;
  white-space: nowrap;
}

#sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  padding: 16px 18px calc(var(--safe-b) + 18px);
  background: rgba(12, 16, 27, .92);
  backdrop-filter: blur(22px);
  border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -20px 50px rgba(0, 0, 0, .5);
  transform: translateY(0);
  transition: transform .28s cubic-bezier(.2, .8, .2, 1);
  max-height: 72vh;
  overflow: auto;
}
#sheet.hidden { transform: translateY(110%); }

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head strong { font-size: 16px; }
.icon { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 6px; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .05);
  font-size: 14px;
  color: #ccd5ee;
}
.row > span:first-child { flex: 1 1 auto; }
.row input[type="range"] { flex: 1.2 1 auto; accent-color: var(--accent); height: 26px; }
.row output { width: 42px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.row.toggle input { width: 20px; height: 20px; accent-color: var(--accent2); }
.row select {
  flex: 1.2 1 auto;
  background: rgba(255, 255, 255, .06);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
}
.fine { margin: 14px 0 0; font-size: 11px; color: #6d7896; line-height: 1.5; }

[hidden] { display: none !important; }
.mini {
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 10px; }
.chip {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .06);
  color: #ccd5ee;
  font-size: 12.5px;
  transition: background .15s, border-color .15s;
}
.chip.on {
  background: rgba(124, 156, 255, .28);
  border-color: rgba(124, 156, 255, .65);
  color: #fff;
}

.welcome {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(5, 8, 15, .78);
  backdrop-filter: blur(10px);
}
.welcome-card {
  width: 100%; max-width: 360px;
  padding: 22px 22px 18px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #171d30, #101422);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}
.welcome-card h2 { margin: 0 0 12px; font-size: 19px; }
.welcome-card ol { margin: 0 0 12px; padding-left: 20px; color: #c6d0ea; font-size: 14px; line-height: 1.7; }
.welcome-note { margin: 0 0 16px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.welcome-card .btn { width: 100%; }

#loading {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: rgba(7, 10, 18, .92);
  z-index: 60;
  transition: opacity .4s;
}
#loading.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
#loading p { color: var(--muted); font-size: 13px; margin: 0; }
#progressBar {
  width: 200px; height: 4px; border-radius: 2px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
}
#progressBar.hidden { display: none; }
#progressFill {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, #6f8dff, #59e1c8);
  transition: width .15s linear;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .12);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#selftest {
  position: fixed; left: 8px; bottom: 8px; z-index: 99;
  max-width: 60vw; max-height: 40vh; overflow: auto;
  font-size: 10px; color: #9fe;
  background: rgba(0, 0, 0, .7);
  padding: 6px;
  display: none;
}
#selftest.show { display: block; }

@media (min-width: 620px) {
  #cam-preview { width: 120px; height: 158px; }
  #toolbar { left: 50%; right: auto; transform: translateX(-50%); width: 560px; border-radius: 20px 20px 0 0; }
}
