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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111;
}

#status-bar {
  position: absolute;
  top: env(safe-area-inset-top, 12px);
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 20px;
  backdrop-filter: blur(8px);
  font-size: 14px;
  z-index: 10;
}

#status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-idle { background: #4ade80; }
.dot-recording { background: #ef4444; animation: pulse 1s infinite; }
.dot-stopping { background: #fbbf24; }
.dot-setup { background: #60a5fa; }
.dot-error { background: #9ca3af; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

#motion-score {
  margin-left: auto;
  font-size: 12px;
  color: #a3a3a3;
  font-variant-numeric: tabular-nums;
}

#record-indicator {
  position: absolute;
  top: calc(env(safe-area-inset-top, 12px) + 52px);
  left: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(239, 68, 68, 0.85);
  border-radius: 16px;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  z-index: 10;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1s infinite;
}

#controls {
  position: absolute;
  bottom: env(safe-area-inset-bottom, 16px);
  left: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  z-index: 10;
}

.btn {
  flex: 1;
  padding: 12px 8px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  backdrop-filter: blur(8px);
  transition: background 0.15s;
}

.btn:active { background: rgba(255, 255, 255, 0.25); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: #2563eb; }
.btn.primary:active { background: #1d4ed8; }
.btn.large { padding: 16px 32px; font-size: 16px; flex: none; }

/* ROI overlay */
#roi-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

#roi-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#roi-box {
  position: absolute;
  border: 2px solid #4ade80;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
  cursor: move;
  touch-action: none;
}

#roi-box::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px dashed rgba(255, 255, 255, 0.4);
}

.roi-handle {
  position: absolute;
  width: 24px;
  height: 24px;
  background: #4ade80;
  border: 2px solid #fff;
  border-radius: 50%;
  touch-action: none;
}

.roi-handle.nw { top: -12px; left: -12px; cursor: nw-resize; }
.roi-handle.ne { top: -12px; right: -12px; cursor: ne-resize; }
.roi-handle.sw { bottom: -12px; left: -12px; cursor: sw-resize; }
.roi-handle.se { bottom: -12px; right: -12px; cursor: se-resize; }

.roi-hint {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 8px;
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
}

#btn-roi.roi-active {
  background: #16a34a;
  flex: 1.2;
}

/* Panels */
.panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 16px calc(env(safe-area-inset-bottom, 16px) + 16px);
  background: rgba(20, 20, 20, 0.95);
  border-radius: 20px 20px 0 0;
  z-index: 30;
  max-height: 80vh;
  overflow-y: auto;
}

.panel h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

.panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 14px;
}

.panel input[type="range"] {
  flex: 1;
  accent-color: #2563eb;
}

.panel label span {
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #a3a3a3;
}

.checkbox-label {
  gap: 10px;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #2563eb;
}

#result-video {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 12px;
  background: #000;
}

.result-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.result-actions .btn {
  flex: 1;
  min-width: 0;
}

#history-list {
  list-style: none;
  margin-bottom: 12px;
}

#history-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 14px;
}

#history-list button {
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

/* Start screen */
#start-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 100%);
  z-index: 50;
  text-align: center;
}

#start-screen h1 {
  font-size: 28px;
  margin-bottom: 12px;
}

#start-screen p {
  font-size: 15px;
  color: #94a3b8;
  margin-bottom: 32px;
  line-height: 1.5;
  max-width: 320px;
}

#start-screen .note {
  margin-top: 24px;
  font-size: 12px;
  color: #64748b;
}

/* Error toast */
#error-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 16px 24px;
  background: rgba(239, 68, 68, 0.9);
  border-radius: 12px;
  font-size: 14px;
  z-index: 100;
  max-width: 80%;
  text-align: center;
}

.hidden { display: none !important; }

/* Landscape preference */
@media (orientation: portrait) {
  #start-screen::after {
    content: "如果太灵敏可以尝试在设置减小灵敏度";
    position: absolute;
    bottom: 40px;
    font-size: 13px;
    color: #fbbf24;
  }
}
