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

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #333;
  overflow-x: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* 工具栏样式 */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  flex-wrap: wrap;
  gap: 15px;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.8);
  padding: 8px 12px;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.tool-btn {
  background: linear-gradient(135deg, #4caf50, #45a049);
  color: white;
  border: none;
  padding: 10px 15px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.tool-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.tool-btn.active {
  background: linear-gradient(135deg, #2196f3, #1976d2);
  transform: translateY(-1px);
}

.tool-btn[data-tool="eraser"] {
  background: linear-gradient(135deg, #ff5722, #e64a19);
}

.tool-btn[data-tool="eraser"].active {
  background: linear-gradient(135deg, #f44336, #d32f2f);
}

/* 颜色选择器 */
.color-palette {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-option {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.color-option:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.color-option.active {
  border-color: #2196f3;
  transform: scale(1.15);
  box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.3);
}

/* 画笔大小控制 */
#brushSize {
  width: 120px;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, #ddd, #4caf50);
  outline: none;
  cursor: pointer;
}

#brushSize::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #4caf50;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

#brushSizeValue {
  background: #4caf50;
  color: white;
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: bold;
  min-width: 30px;
  text-align: center;
}

/* 主要内容区域 */
.main-content {
  display: flex;
  flex: 1;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

/* 摄像头绘画容器 */
.camera-drawing-container {
  position: relative;
  width: 90vw;
  height: 70vh;
  max-width: 1200px;
  max-height: 800px;
  background: transparent; /* 修复：移除白色背景，让视频可见 */
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
}

#videoElement {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* 镜像翻转 */
  z-index: 1;
}

#videoCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transform: scaleX(-1); /* 镜像翻转 */
  z-index: 2;
}

#drawingCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  z-index: 3;
  /* 绘画层不需要镜像，让用户正常绘制 */
  /* 移除背景，完全透明以避免白屏 */
  background: transparent;
}

.status-indicator {
  position: absolute;
  top: 15px;
  left: 15px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 14px;
  backdrop-filter: blur(10px);
  z-index: 4;
}

.drawing-info {
  position: absolute;
  bottom: 15px;
  right: 15px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 10px 15px;
  border-radius: 10px;
  font-size: 14px;
  backdrop-filter: blur(10px);
  z-index: 4;
}

#currentColor {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  vertical-align: middle;
  margin-left: 5px;
  border: 2px solid white;
}

.hand-status,
.gesture-status,
.performance-status {
  margin: 2px 0;
}

.performance-status {
  color: #4caf50;
  font-weight: bold;
}

/* 调试面板样式 */
.debug-panel {
  position: absolute;
  top: 15px;
  right: 15px;
  background: rgba(255, 87, 34, 0.9);
  color: white;
  padding: 15px;
  border-radius: 10px;
  font-size: 12px;
  backdrop-filter: blur(10px);
  z-index: 5;
  min-width: 200px;
}

.debug-panel h4 {
  margin: 0 0 10px 0;
  font-size: 14px;
  text-align: center;
}

.debug-panel #debugInfo div {
  margin: 5px 0;
  display: flex;
  justify-content: space-between;
}

.debug-panel #debugInfo span {
  font-weight: bold;
  color: #ffe0b2;
}

.debug-panel .tool-btn {
  margin-top: 10px;
  width: 100%;
  font-size: 12px;
  padding: 8px;
}

/* 手势指南 */
.gesture-guide {
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.95);
  padding: 20px;
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px);
  max-width: 250px;
  z-index: 1000;
}

.gesture-guide h3 {
  margin-bottom: 15px;
  color: #333;
  text-align: center;
  font-size: 18px;
}

.gesture-item {
  display: flex;
  align-items: center;
  margin: 10px 0;
  padding: 8px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  transition: all 0.3s ease;
}

.gesture-item:hover {
  background: rgba(33, 150, 243, 0.1);
  transform: translateX(5px);
}

.gesture-icon {
  font-size: 24px;
  margin-right: 10px;
  width: 35px;
  text-align: center;
}

.gesture-desc {
  font-size: 14px;
  color: #555;
  flex: 1;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .gesture-guide {
    position: static;
    transform: none;
    margin: 20px;
    order: -1;
  }

  .main-content {
    flex-direction: column;
    padding: 10px;
  }

  .camera-drawing-container {
    width: 95vw;
    height: 60vh;
  }
}

@media (max-width: 768px) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .tool-group {
    justify-content: center;
    flex-wrap: wrap;
  }

  .main-content {
    padding: 10px;
  }

  .camera-drawing-container {
    width: 95vw;
    height: 50vh;
    min-height: 300px;
  }

  .status-indicator {
    top: 10px;
    left: 10px;
    padding: 8px 12px;
    font-size: 12px;
  }

  .drawing-info {
    bottom: 10px;
    right: 10px;
    padding: 8px 12px;
    font-size: 12px;
  }
}

/* 加载动画 */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 5px solid #f3f3f3;
  border-top: 5px solid #3498db;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* 特殊效果 */
.drawing-cursor {
  position: fixed;
  width: 20px;
  height: 20px;
  border: 2px solid #2196f3;
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  transition: all 0.1s ease;
  background: rgba(33, 150, 243, 0.3);
}

.drawing-cursor.drawing {
  background: rgba(76, 175, 80, 0.5);
  border-color: #4caf50;
  box-shadow: 0 0 20px rgba(76, 175, 80, 0.8);
}

.drawing-cursor.erasing {
  background: rgba(244, 67, 54, 0.5);
  border-color: #f44336;
  box-shadow: 0 0 20px rgba(244, 67, 54, 0.8);
}

/* 键盘快捷键说明 */
.keyboard-shortcuts {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.keyboard-shortcuts h4 {
  margin-bottom: 10px;
  color: #333;
  font-size: 14px;
  text-align: center;
}

.shortcut-item {
  padding: 5px 8px;
  margin: 5px 0;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 6px;
  font-size: 12px;
  color: #555;
  text-align: center;
  font-family: monospace;
}

/* 性能提示样式 */
.performance-tip {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.performance-tip h4 {
  margin-bottom: 10px;
  color: #ff9800;
  font-size: 14px;
  text-align: center;
}

.tip-item {
  padding: 5px 8px;
  margin: 5px 0;
  background: rgba(255, 152, 0, 0.1);
  border-radius: 6px;
  font-size: 12px;
  color: #e65100;
  text-align: center;
  border-left: 3px solid #ff9800;
}

/* 错误弹窗样式 */
.modal {
  position: fixed;
  z-index: 10000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(5px);
}

.modal-content {
  background-color: white;
  margin: 15% auto;
  padding: 30px;
  border-radius: 15px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: translateY(-50px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.3s ease;
}

.close:hover,
.close:focus {
  color: #333;
}

.modal h3 {
  margin-bottom: 15px;
  color: #333;
}

.modal p {
  margin-bottom: 20px;
  color: #666;
  line-height: 1.5;
}

#retryButton {
  margin-top: 10px;
}

/* 权限指导样式 */
.permission-guide {
  margin: 20px 0;
  padding: 15px;
  background: rgba(33, 150, 243, 0.1);
  border-radius: 8px;
  border-left: 4px solid #2196f3;
  text-align: left;
}

.permission-guide h4 {
  margin-bottom: 10px;
  color: #1976d2;
  font-size: 16px;
}

.permission-guide ol {
  margin: 10px 0;
  padding-left: 20px;
}

.permission-guide li {
  margin: 5px 0;
  line-height: 1.5;
}

.local-server-guide {
  margin: 20px 0;
  padding: 15px;
  background: rgba(76, 175, 80, 0.1);
  border-radius: 8px;
  border-left: 4px solid #4caf50;
  text-align: left;
}

.local-server-guide h4 {
  margin-bottom: 15px;
  color: #388e3c;
  font-size: 16px;
}

.server-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.server-option {
  padding: 10px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 6px;
  border: 1px solid rgba(76, 175, 80, 0.3);
}

.server-option strong {
  display: block;
  color: #388e3c;
  margin-bottom: 5px;
}

.server-option code {
  display: block;
  background: #f5f5f5;
  padding: 8px 12px;
  border-radius: 4px;
  font-family: "Courier New", monospace;
  font-size: 14px;
  margin: 5px 0;
  color: #333;
  border: 1px solid #ddd;
}

.server-option small {
  display: block;
  color: #666;
  font-style: italic;
  margin-top: 5px;
}

.button-group {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

.button-group .tool-btn {
  flex: 1;
  min-width: 120px;
  margin: 0;
}

.error-message {
  white-space: pre-line;
  line-height: 1.6;
}

/* 权限状态指示器 */
.permission-status {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 10px 15px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 9998;
  backdrop-filter: blur(10px);
  display: none;
}

.permission-status.show {
  display: block;
  animation: slideInRight 0.3s ease;
}

.permission-status.granted {
  background: rgba(76, 175, 80, 0.9);
}

.permission-status.denied {
  background: rgba(244, 67, 54, 0.9);
}

.permission-status.prompt {
  background: rgba(255, 193, 7, 0.9);
  color: #333;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* 响应式调整 */
@media (max-width: 768px) {
  .modal-content {
    margin: 10% auto;
    padding: 20px;
    width: 95%;
  }

  .server-options {
    flex-direction: column;
  }

  .button-group {
    flex-direction: column;
  }

  .button-group .tool-btn {
    width: 100%;
  }
}

/* 性能模式按钮样式 */
#performanceMode {
  background: linear-gradient(135deg, #ff9800, #f57c00);
  transition: all 0.3s ease;
}

#performanceMode:hover {
  background: linear-gradient(135deg, #f57c00, #e65100);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(255, 152, 0, 0.4);
}

#performanceMode.active {
  background: linear-gradient(135deg, #4caf50, #45a049);
  animation: pulse 2s infinite;
}

#performanceMode.active:hover {
  background: linear-gradient(135deg, #45a049, #388e3c);
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
  }
}

/* 调试按钮样式 */
#toggleDebug {
  background: linear-gradient(135deg, #9c27b0, #7b1fa2);
}

#toggleDebug:hover {
  background: linear-gradient(135deg, #7b1fa2, #6a1b9a);
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(156, 39, 176, 0.4);
}

/* 固定位置的性能状态显示 */
.performance-status-fixed {
  position: fixed;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  font-family: "Courier New", monospace;
  font-size: 14px;
  font-weight: bold;
  z-index: 1000;
}

/* 调试面板优化样式 */
.debug-panel {
  position: fixed;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 15px;
  border-radius: 8px;
  font-family: "Courier New", monospace;
  font-size: 12px;
  z-index: 1000;
  min-width: 250px;
  display: none;
}

.debug-panel h4 {
  margin: 0 0 10px 0;
  color: #4caf50;
  font-size: 14px;
}

.debug-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.debug-metric {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.debug-metric:last-child {
  border-bottom: none;
}

.debug-label {
  color: #ccc;
}

.debug-value {
  color: #4caf50;
  font-weight: bold;
}
