:root {
  color-scheme: dark;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  --ink: #f8f8f6;
  --muted: rgba(248, 248, 246, 0.7);
  --panel: rgba(16, 16, 16, 0.48);
  --panel-strong: rgba(16, 16, 16, 0.72);
  --line: rgba(255, 255, 255, 0.24);
  --line-strong: rgba(255, 255, 255, 0.6);
  --accent: #52e0a2;
  --accent-2: #ffd369;
  --warn: #ff6f61;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #050505;
  color: var(--ink);
}

body { min-width: 320px; }

.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #050505;
}

.camera-video {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #111;
}

.glass-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(5, 5, 5, 0.28)),
    rgba(255, 255, 255, 0.055);
  backdrop-filter: blur(10px) saturate(1.08);
  -webkit-backdrop-filter: blur(10px) saturate(1.08);
}

.mocap-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.avatar-stage {
  position: absolute;
  left: min(68%, calc(100% - 280px));
  top: 50%;
  z-index: 4;
  width: min(34vw, 430px);
  min-width: 300px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  perspective: 900px;
  pointer-events: none;
}

#avatarSvg {
  width: 100%;
  height: 100%;
  --face-rotate-x: 0deg;
  --face-rotate-y: 0deg;
  --face-rotate-z: 0deg;
  --face-translate-x: 0px;
  transform:
    translateX(var(--face-translate-x))
    rotateX(var(--face-rotate-x))
    rotateY(var(--face-rotate-y))
    rotateZ(var(--face-rotate-z));
  transform-style: preserve-3d;
  transition: transform 70ms linear;
}

.status-panel {
  position: absolute;
  top: 24px;
  right: 24px;
  z-index: 6;
  max-width: min(420px, calc(100vw - 48px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.status-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.status-panel.is-warning p { color: var(--warn); }
.status-panel.is-ready p { color: var(--accent); }

.mocap-panel {
  position: absolute;
  left: 24px;
  top: 24px;
  z-index: 6;
  width: 280px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.mocap-panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.mocap-panel-row strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-transform: lowercase;
}

.mocap-panel-row strong[data-tone="ready"] { color: var(--accent); }
.mocap-panel-row strong[data-tone="warning"] { color: var(--warn); }

.metric-list {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.metric {
  display: grid;
  grid-template-columns: 64px 1fr 42px;
  align-items: center;
  gap: 8px;
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

.metric-label, .metric-value {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.metric-value {
  text-align: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.metric-track {
  position: relative;
  height: 6px;
  overflow: hidden;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.14);
}

.metric-track::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  background: rgba(255, 255, 255, 0.24);
}

.metric-fill {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: left 70ms linear, width 70ms linear;
}

.preview-window {
  position: absolute;
  left: 24px;
  bottom: 24px;
  z-index: 6;
  width: clamp(172px, 18vw, 240px);
  aspect-ratio: 16 / 10;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 5, 5, 0.7);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
}

.preview-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  background: #111;
}

.preview-meta {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: var(--ink);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass-layer, .status-panel, .mocap-panel {
    background: rgba(18, 18, 18, 0.78);
  }
}

@media (max-width: 920px) {
  .avatar-stage {
    left: 58%;
    width: min(48vw, 380px);
  }
  .mocap-panel { width: 250px; }
}

@media (max-width: 720px) {
  .status-panel {
    top: 16px;
    right: 16px;
    left: 16px;
    max-width: none;
  }
  .mocap-panel {
    left: 16px;
    top: 86px;
    width: min(280px, calc(100vw - 32px));
  }
  .avatar-stage {
    left: 50%;
    top: 55%;
    width: min(78vw, 340px);
    min-width: 250px;
  }
  .preview-window {
    left: 16px;
    bottom: 16px;
    width: 172px;
  }
}
