*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ========== 视频层 ========== */
#video {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}

/* ========== 画框叠加层 ========== */
#overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

/* ========== 顶部状态栏 ========== */
#status-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 44px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 100%);
  color: #fff;
  font-size: 13px;
}

.status-left, .status-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-center {
  font-size: 12px;
  opacity: 0.8;
}

#btn-switch-camera, #btn-toggle-lane {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(0,0,0,0.4);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

#btn-switch-camera:active, #btn-toggle-lane:active {
  background: rgba(255,255,255,0.2);
}

/* ========== 底部统计面板 ========== */
#stats-panel {
  position: fixed;
  bottom: 60px; left: 12px; right: 12px;
  z-index: 10;
  display: flex;
  gap: 8px;
  justify-content: center;
}

.stat-item {
  flex: 1;
  max-width: 90px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(12px);
  border-radius: 12px;
  padding: 8px 4px;
  text-align: center;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.1);
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.stat-item.roadside .stat-value { color: #ff4444; }
.stat-item.midroad .stat-value { color: #44ff44; }
.stat-item.plate .stat-value { color: #4488ff; }
.stat-item.total .stat-value { color: #ffffff; }

.stat-label {
  font-size: 10px;
  opacity: 0.7;
  margin-top: 2px;
}

/* ========== 底部提示条 ========== */
#hint-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 36px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: rgba(0,0,0,0.4);
  color: #fff;
  font-size: 11px;
  opacity: 0.7;
}

/* ========== 加载遮罩 ========== */
#loading-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 100;
  background: #0a0a0a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.5s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 48px; height: 48px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: #4488ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: #fff;
  font-size: 16px;
  font-weight: 500;
}

.loading-progress {
  width: 200px;
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}

.loading-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4488ff, #44ff88);
  border-radius: 2px;
  transition: width 0.5s ease;
}

.loading-tip {
  color: rgba(255,255,255,0.4);
  font-size: 12px;
}

/* ========== 错误提示 ========== */
#error-toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: rgba(255,68,68,0.92);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-line;
  max-width: 90vw;
  text-align: center;
  backdrop-filter: blur(12px);
  transition: opacity 0.3s ease;
}

#error-toast.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ========== 参数设置面板 ========== */
#settings-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 300;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: opacity 0.3s ease;
}

#settings-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#settings-panel {
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  background: #1a1a2e;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.35s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.settings-header h2 {
  font-size: 18px;
  color: #fff;
  font-weight: 600;
}

.btn-close {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.1);
  color: #aaa;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-close:active {
  background: rgba(255,255,255,0.2);
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
  -webkit-overflow-scrolling: touch;
}

/* 分组标题 */
.settings-group {
  margin-bottom: 16px;
}

.settings-group-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
  padding: 8px 0 6px 0;
  margin-bottom: 4px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* 参数行 */
.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  gap: 12px;
}

.setting-label {
  color: #ccc;
  font-size: 13px;
  white-space: nowrap;
  min-width: 70px;
}

.setting-control {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.setting-value {
  color: #66aaff;
  font-size: 12px;
  font-weight: 600;
  min-width: 42px;
  text-align: right;
}

/* 滑块 */
input[type="range"].setting-slider {
  -webkit-appearance: none;
  width: 100%;
  max-width: 140px;
  height: 6px;
  border-radius: 3px;
  background: rgba(255,255,255,0.12);
  outline: none;
}

input[type="range"].setting-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #4488ff;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.3);
  box-shadow: 0 2px 8px rgba(68,136,255,0.4);
}

/* 开关 */
.setting-toggle {
  -webkit-appearance: none;
  width: 48px; height: 28px;
  border-radius: 14px;
  background: rgba(255,255,255,0.15);
  position: relative;
  cursor: pointer;
  outline: none;
  transition: background 0.3s;
  flex-shrink: 0;
}

.setting-toggle::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.25s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.setting-toggle:checked {
  background: #44bb44;
}

.setting-toggle:checked::after {
  transform: translateX(20px);
}

/* 下拉 */
.setting-select {
  appearance: none;
  -webkit-appearance: none;
  background: rgba(255,255,255,0.08);
  color: #eee;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  cursor: pointer;
  max-width: 150px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%23aaa' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
}

/* 多选框 */
.setting-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.setting-checkbox-label {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  color: #ccc;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  transition: all 0.2s;
}

.setting-checkbox-label:has(input:checked) {
  background: rgba(68,136,255,0.2);
  border-color: rgba(68,136,255,0.4);
  color: #88bbff;
}

.setting-checkbox-label input {
  display: none;
}

/* 描述 */
.setting-desc {
  font-size: 10px;
  color: #555;
  padding: 2px 0 6px 0;
  margin-top: -6px;
}

/* 底部栏 */
.settings-footer {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.btn-sm {
  flex: 1;
  padding: 8px 0;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  color: #ccc;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  transition: background 0.2s;
}

.btn-sm:active {
  background: rgba(255,255,255,0.15);
}

.btn-danger {
  border-color: rgba(255,68,68,0.3);
  color: #ff6666;
}

/* 导入区域 */
.settings-import-area {
  padding: 0 20px 12px 20px;
  flex-shrink: 0;
}

.settings-import-area.hidden {
  display: none;
}

.settings-import-area textarea {
  width: 100%;
  height: 80px;
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: #ccc;
  font-size: 12px;
  padding: 8px;
  resize: vertical;
  font-family: monospace;
}

.settings-import-area textarea:focus {
  outline: none;
  border-color: rgba(68,136,255,0.5);
}

.import-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* 成功提示 */
.settings-toast {
  position: fixed;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  background: rgba(68, 255, 136, 0.9);
  color: #000;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
  animation: fadeInOut 2s ease forwards;
  white-space: nowrap;
}

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateX(-50%) translateY(10px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  75% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* ========== 响应式 ========== */
@media (max-width: 400px) {
  #stats-panel {
    left: 4px; right: 4px;
    bottom: 50px;
    gap: 4px;
  }
  .stat-item {
    padding: 6px 2px;
    border-radius: 8px;
  }
  .stat-value { font-size: 18px; }
  .stat-label { font-size: 9px; }
}

@media (min-width: 768px) {
  #stats-panel {
    bottom: 80px;
    max-width: 500px;
    margin: 0 auto;
    left: 0; right: 0;
  }
  .stat-item { max-width: 120px; }
}
