:root {
  --bg: #07070d;
  --bg2: #10101c;
  --line: rgba(150, 180, 255, 0.16);
  --fg: #e8edff;
  --dim: #9aa6c8;
  --accent: #7fd7ff;
  --accent2: #b98cff;
  --danger: #ff6b81;
  --panel: rgba(18, 20, 34, 0.82);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 700px at 15% -10%, #1b2440 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 0%, #2a1a3d 0%, transparent 55%),
    linear-gradient(180deg, var(--bg2), var(--bg) 70%);
  color: var(--fg);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  min-height: 100%;
}

.fog {
  position: fixed;
  inset: -20%;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(closest-side, rgba(120, 160, 255, 0.10), transparent 70%) 20% 30% / 60% 60% no-repeat,
    radial-gradient(closest-side, rgba(180, 120, 255, 0.09), transparent 70%) 80% 70% / 55% 55% no-repeat;
  animation: drift 26s ease-in-out infinite alternate;
  filter: blur(10px);
}
@keyframes drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to   { transform: translate3d(2%, 2%, 0) scale(1.08); }
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  background: linear-gradient(180deg, rgba(10, 12, 22, 0.75), rgba(10, 12, 22, 0.2));
}
.brand { display: flex; align-items: center; gap: 14px; }
.skull { font-size: 30px; filter: drop-shadow(0 0 12px rgba(140, 190, 255, 0.55)); }
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: 1px; }
.topbar p { margin: 4px 0 0; font-size: 12.5px; color: var(--dim); }

.top-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--dim);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; background: rgba(10, 14, 26, 0.6);
  white-space: nowrap;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #55607d; box-shadow: 0 0 0 rgba(0,0,0,0);
  transition: background 0.2s, box-shadow 0.2s;
}
.dot.on { background: #4ade80; box-shadow: 0 0 10px #4ade80aa; }
.dot.ghost { background: #9fd0ff; box-shadow: 0 0 14px #9fd0ff; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------------- 布局 ---------------- */
.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  padding: 18px 22px 30px;
  align-items: start;
  transition: all 0.3s ease;
}
@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

/* 全屏模式 - 摄像头启动后 */
body.fullscreen-mode .topbar,
body.fullscreen-mode .panel,
body.fullscreen-mode .stage-foot {
  display: none;
}
body.fullscreen-mode .layout {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0;
  gap: 0;
  grid-template-columns: 1fr;
}
body.fullscreen-mode .stage {
  width: 100vw;
  height: 100vh;
}
body.fullscreen-mode .stage-inner {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  aspect-ratio: auto;
}
body.fullscreen-mode {
  cursor: none;
  overflow: hidden;
}

.stage { min-width: 0; }
.stage-inner {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #04040a;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), inset 0 0 90px rgba(80, 120, 255, 0.06);
}
.stage-inner video,
.stage-inner canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.stage-inner canvas { z-index: 2; }
.stage-inner video { z-index: 1; }

.placeholder {
  position: absolute; inset: 0; z-index: 3;
  display: grid; place-items: center;
  background: radial-gradient(closest-side, rgba(20, 24, 44, 0.92), rgba(6, 8, 16, 0.97));
  text-align: center; padding: 20px;
}
.placeholder.hide { display: none; }
.ph-ghost { font-size: 54px; animation: float 3.2s ease-in-out infinite; filter: drop-shadow(0 0 18px rgba(150, 200, 255, 0.6)); }
@keyframes float { 50% { transform: translateY(-10px); } }
.ph-inner h2 { margin: 10px 0 8px; font-size: 18px; font-weight: 600; }
.ph-inner p { margin: 6px 0; color: var(--dim); font-size: 13px; max-width: 520px; line-height: 1.6; }
.ph-inner .tiny { font-size: 12px; opacity: 0.75; }
code {
  background: rgba(120, 160, 255, 0.14);
  border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 6px;
  font-family: Consolas, "Cascadia Mono", monospace; font-size: 0.92em; color: #cfe3ff;
}

.loading {
  position: absolute; inset: 0; z-index: 4;
  display: grid; place-items: center; align-content: center; gap: 14px;
  background: rgba(6, 8, 16, 0.86);
  font-size: 14px; color: var(--dim);
}
/* display:grid 会盖掉浏览器默认的 [hidden]{display:none}，必须显式还原 */
.loading[hidden], .errbox[hidden] { display: none; }
.loading i {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(140, 190, 255, 0.25); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.errbox {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 5;
  background: rgba(70, 14, 26, 0.92);
  border: 1px solid rgba(255, 107, 129, 0.45);
  color: #ffd7de; border-radius: 10px; padding: 10px 14px; font-size: 13px;
  line-height: 1.55; white-space: pre-wrap;
}

.stage-foot {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 12px;
}
.btn {
  appearance: none; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px;
  background: rgba(24, 28, 46, 0.9); color: var(--fg);
  padding: 10px 18px; font-size: 14px; font-family: inherit;
  transition: transform 0.12s, border-color 0.18s, background 0.18s;
}
.btn:hover:not(:disabled) { border-color: rgba(160, 200, 255, 0.5); transform: translateY(-1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, #2b4f9e, #6a3fb5);
  border-color: rgba(180, 210, 255, 0.35);
  box-shadow: 0 10px 26px rgba(70, 110, 220, 0.3);
  font-weight: 600;
}
.inline { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--dim); cursor: pointer; }
/* 当前风格用不到的选项：变暗且不可点 */
.inline.off, .field.off { opacity: 0.3; pointer-events: none; }
.face-card.off { display: none; }
.inline input { accent-color: #7fd7ff; width: 15px; height: 15px; }
.perf { margin-left: auto; font-size: 12px; color: var(--dim); font-family: Consolas, monospace; white-space: pre; }

/* ---------------- 侧栏 ---------------- */
.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}
.panel::-webkit-scrollbar { width: 6px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb { background: rgba(150, 180, 255, 0.2); border-radius: 3px; }
.panel::-webkit-scrollbar-thumb:hover { background: rgba(150, 180, 255, 0.35); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transition: box-shadow 0.2s;
}
.card:hover { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4); }
.card h3 {
  margin: 0 0 12px;
  font-size: 12px;
  letter-spacing: 1.5px;
  color: #a8b8d8;
  font-weight: 600;
  text-transform: uppercase;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(150, 180, 255, 0.1);
}
.card .field { display: block; margin: 8px 0; font-size: 12.5px; color: var(--dim); }
.card .field > span { display: flex; justify-content: space-between; margin-bottom: 5px; }
.card .field b { color: var(--fg); font-weight: 600; font-size: 12px; }
.card .inline { display: flex; margin: 6px 0; font-size: 12.5px; }
input[type="range"] { width: 100%; accent-color: #8fb8ff; }
select {
  width: 100%; margin-top: 2px;
  background: rgba(10, 14, 26, 0.9); color: var(--fg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  font-family: inherit; font-size: 13px;
}
.statecard .row { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--dim); margin: 6px 0; }
.statecard .row b { color: var(--fg); font-size: 14px; }
.statecard .row.tiny { font-size: 12px; }
.bar { height: 7px; border-radius: 999px; background: rgba(140, 180, 255, 0.14); overflow: hidden; margin: 10px 0 8px; }
.bar i { display: block; height: 100%; width: 0%; border-radius: 999px; background: linear-gradient(90deg, #4a7bff, #b98cff, #9ff0ff); transition: width 0.1s linear; }
.bar.active i { background: linear-gradient(90deg, #9fd0ff, #ffffff, #b98cff); box-shadow: 0 0 14px #9fd0ff; }

.tip {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.5;
  color: rgba(154, 166, 200, 0.85);
  border-left: 2px solid rgba(185, 140, 255, 0.4);
  padding-left: 8px;
  background: rgba(185, 140, 255, 0.03);
  padding: 6px 8px;
  border-radius: 6px;
}
.face-target-row { display: flex; align-items: center; gap: 12px; min-width: 0; }
.face-target-preview {
  width: 58px; height: 72px; flex: 0 0 58px; object-fit: cover;
  border: 1px solid rgba(159, 208, 255, 0.35); border-radius: 9px;
  background: rgba(7, 9, 18, 0.9); box-shadow: 0 8px 18px rgba(0, 0, 0, 0.26);
}
.face-target-copy { min-width: 0; display: grid; gap: 4px; }
.face-target-copy strong { font-size: 13px; color: var(--fg); font-weight: 600; }
.face-target-copy > span { color: var(--dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 210px; }
.face-target-actions { display: flex; gap: 6px; margin-top: 3px; flex-wrap: wrap; }
.btn.small { padding: 6px 9px; border-radius: 8px; font-size: 11px; }
.btn.subtle { color: var(--dim); background: rgba(10, 14, 26, 0.58); }
.face-stage { height: 6px; margin-top: 13px; border-radius: 99px; overflow: hidden; background: rgba(140, 180, 255, 0.14); }
.face-stage i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #8fb8ff 0 18%, #d7b2ff 58%, #f4fbff); box-shadow: 0 0 12px rgba(159, 208, 255, 0.7); transition: width 120ms linear; }
.face-stage-label { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; color: var(--dim); font-size: 11px; }
.face-stage-label b { color: var(--fg); font-variant-numeric: tabular-nums; }
.face-tip { margin: 10px 0 0; color: var(--dim); font-size: 11px; line-height: 1.55; }
.files {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  font-size: 11px;
  font-family: Consolas, monospace;
  max-height: 140px;
  overflow-y: auto;
}
.files::-webkit-scrollbar { width: 4px; }
.files::-webkit-scrollbar-track { background: transparent; }
.files::-webkit-scrollbar-thumb { background: rgba(150, 180, 255, 0.15); border-radius: 2px; }
.files li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; color: var(--dim); }
.files li b { color: #8ef0b0; font-weight: 500; }
.files li.bad b { color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .fog, .ph-ghost, .loading i, .dot.ghost { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  .face-stage i, .bar i { transition-duration: 0.01ms !important; }
}

/* 恐怖氛围增强 */
body.fullscreen-mode {
  background: #000;
}

body.fullscreen-mode .fog {
  opacity: 0.2;
  animation: fogDrift 25s ease-in-out infinite;
}

@keyframes fogDrift {
  0%, 100% { transform: translateX(0) translateY(0); }
  50% { transform: translateX(-30px) translateY(20px); }
}

.face-tip {
  font-size: 14px;
  line-height: 1.6;
  color: #8a98a8;
  margin: 10px 0 0 0;
  padding: 10px;
  background: rgba(20, 25, 35, 0.4);
  border-radius: 4px;
  border-left: 3px solid #5a6b7f;
}

/* 故障闪烁提示 */
.glitch-indicator {
  position: fixed;
  top: 10px;
  right: 10px;
  padding: 8px 14px;
  background: rgba(180, 10, 25, 0.9);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
  z-index: 10000;
  animation: glitchPulse 0.5s ease-in-out infinite;
  box-shadow: 0 0 20px rgba(180, 10, 25, 0.6);
}

@keyframes glitchPulse {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; }
}

/* 恐怖模式下的额外氛围 */
body.fullscreen-mode .stage {
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.9) inset;
}
