/* 防止闪白的初始样式 */
html, body {
  background-color: #f8f9fa;
  color: #333333;
  margin: 0;
  padding: 0;
  height: 100%;
  min-height: 100vh;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

:root {
  /* 浅色主题变量 */
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f3f4;
  --bg-canvas: #ffffff;
  --text-primary: #202124;
  --text-secondary: #5f6368;
  --text-muted: #80868b;
  --border-color: #dadce0;
  --shadow-color: rgba(0, 0, 0, 0.12);
  --shadow-color-hover: rgba(0, 0, 0, 0.18);
  --accent-color: #5e35b1;
  --accent-hover: #502c9e;
  --accent-light: #eae5f9;
  --input-bg: #ffffff;
  --input-border: #dadce0;
  --gradient-start: #5e35b1;
  --gradient-end: #3949ab;
  --success-color: #0f9d58;
  --warning-color: #f4b400;
  --danger-color: #db4437;
  --footer-bg: rgba(0, 0, 0, 0.05);
  --theme-toggle-bg: #ffffff;
  --theme-toggle-border: #dadce0;
  --theme-toggle-shadow: rgba(0, 0, 0, 0.12);
  --theme-button-hover: #f1f3f4;
  --theme-button-active: #5e35b1;
  --theme-button-active-text: #ffffff;
  --highlight-text: #ff5722;
  --footer-link-color: #5e35b1;
  --footer-link-hover: #502c9e;
}

[data-theme="dark"] {
  /* 深色主题变量 */
  --bg-primary: #121212;
  --bg-secondary: #1e1e1e;
  --bg-tertiary: #2d2d2d;
  --bg-canvas: #252525;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0a6;
  --text-muted: #80868b;
  --border-color: #5f6368;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --shadow-color-hover: rgba(0, 0, 0, 0.5);
  --accent-color: #9a7dff;
  --accent-hover: #b09eff;
  --accent-light: #30284d;
  --input-bg: #2d2d2d;
  --input-border: #5f6368;
  --gradient-start: #7e57c2;
  --gradient-end: #5c6bc0;
  --success-color: #34a853;
  --warning-color: #fbbc04;
  --danger-color: #ea4335;
  --footer-bg: rgba(255, 255, 255, 0.05);
  --theme-toggle-bg: #2d2d2d;
  --theme-toggle-border: #5f6368;
  --theme-toggle-shadow: rgba(0, 0, 0, 0.3);
  --theme-button-hover: #3d3d3d;
  --theme-button-active: #9a7dff;
  --theme-button-active-text: #ffffff;
  --highlight-text: #ff9800;
  --footer-link-color: #9a7dff;
  --footer-link-hover: #b09eff;
}

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

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: clamp(12px, 2vw, 24px);
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
  touch-action: manipulation; /* Prevent double-tap zoom on sliders */
}

.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  background: var(--theme-toggle-bg);
  border: 1px solid var(--theme-toggle-border);
  border-radius: 24px;
  padding: 4px;
  display: flex;
  align-items: center;
  gap: 2px;
  box-shadow: 0 2px 10px var(--theme-toggle-shadow);
  transition: all 0.3s ease;
}

.theme-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px var(--theme-toggle-shadow);
}

.theme-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: all 0.3s ease;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  position: relative;
}

.theme-btn:hover {
  background: var(--theme-button-hover);
  color: var(--text-primary);
  transform: scale(1.1);
}

.theme-btn.active {
  background: var(--theme-button-active);
  color: var(--theme-button-active-text);
}

.theme-btn.active::after {
  content: "";
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 6px;
  height: 6px;
  background-color: var(--theme-button-active-text);
  border-radius: 50%;
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  transition: all 0.3s ease;
}

.container {
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg-secondary);
  border-radius: 16px;
  box-shadow: 0 4px 20px var(--shadow-color);
  overflow: hidden;
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
  flex: 1;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - clamp(24px, 4vw, 48px));
}

.header {
  background: linear-gradient(135deg, var(--gradient-start) 0%, var(--gradient-end) 100%);
  color: white;
  padding: clamp(10px, 2vw, 20px) clamp(15px, 3vw, 30px);
  text-align: center;
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.header::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 70%);
  transform: rotate(30deg);
}

.header h1 {
  font-size: clamp(1.25rem, 3vw, 1.5rem);
  margin-bottom: 6px;
  font-weight: 600;
  position: relative;
  letter-spacing: 0.5px;
}

.header p {
  opacity: 0.9;
  font-size: clamp(0.875rem, 2vw, 1rem);
  max-width: 600px;
  margin: 0 auto;
  position: relative;
  font-weight: 300;
}

.header-description {
  font-size: clamp(0.75rem, 1.5vw, 0.875rem) !important;
  line-height: 1.5;
  opacity: 0.95;
  max-width: 800px !important;
  margin: 8px auto 0 !important;
  font-weight: 300;
}

.highlight-text {
  color: var(--highlight-text);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
  margin: 2px 0;
}

.main-content {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  width: clamp(250px, 25vw, 320px);
  background: var(--bg-tertiary);
  padding: clamp(20px, 3vw, 32px);
  border-right: 1px solid var(--border-color);
  transition: background-color 0.3s ease, border-color 0.3s ease;
  overflow-y: auto;
  flex-shrink: 0;
}

.form-group {
  margin-bottom: 28px;
}

.form-group label {
  display: block;
  margin-bottom: 10px;
  font-weight: 500;
  color: var(--text-primary);
  font-size: 15px;
  display: flex;
  align-items: center;
}

.form-group label svg {
  margin-right: 8px;
  width: 18px;
  height: 18px;
  color: var(--accent-color);
}

.form-group input[type="text"],
.form-group input[type="color"],
.form-group input[type="range"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--input-border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--input-bg);
  color: var(--text-primary);
  transition: all 0.3s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.form-group input[type="text"]:focus,
.form-group input[type="color"]:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-group input[type="color"] {
  height: 46px;
  cursor: pointer;
  border-radius: 10px;
  padding: 4px;
}

.form-group input[type="range"] {
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
  height: 44px; /* Increased touch area */
  background: transparent;
  border-radius: 3px;
  outline: none;
  margin: 8px 0; /* Added margin for better touch area */
}

.form-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--accent-color);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 2px solid white;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.form-group input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 0 4px var(--accent-light), 0 2px 6px rgba(0, 0, 0, 0.3);
}

.form-group input[type="range"]::-moz-range-thumb {
  width: 28px; /* Increased size for better touch */
  height: 28px;
  background: var(--accent-color);
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid white;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.form-group input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 0 4px var(--accent-light), 0 2px 6px rgba(0, 0, 0, 0.3);
}

.range-value {
  display: inline-block;
  margin-left: 12px;
  font-size: 14px;
  color: var(--text-secondary);
  min-width: 36px;
  font-weight: 500;
  transition: color 0.3s ease;
  background: var(--accent-light);
  padding: 2px 8px;
  border-radius: 10px;
}

.file-input-wrapper {
  position: relative;
  overflow: hidden;
  display: inline-block;
  width: 100%;
}

.file-input-wrapper input[type=file] {
  position: absolute;
  left: -9999px;
}

.file-input-label {
  display: block;
  padding: 14px 22px;
  background: var(--accent-color);
  color: white;
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  transition: all 0.3s;
  font-weight: 500;
  font-size: 16px;
  box-shadow: 0 2px 6px rgba(94, 53, 177, 0.3);
}

.file-input-label:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(94, 53, 177, 0.4);
  transform: translateY(-2px);
}

.checkbox-wrapper {
  display: flex;
  align-items: center;
  margin-bottom: 18px;
  padding: 14px;
  background: var(--bg-tertiary);
  border-radius: 10px;
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;
}

.checkbox-wrapper:hover {
  border-color: var(--accent-color);
  background: var(--accent-light);
}

.checkbox-wrapper input[type="checkbox"] {
  margin-right: 12px;
  width: 20px;
  height: 20px;
  cursor: pointer;
  accent-color: var(--accent-color);
}

.checkbox-wrapper label {
  color: var(--text-primary);
  cursor: pointer;
  transition: color 0.3s ease;
  font-weight: 500;
}

.btn {
  width: 100%;
  padding: 14px;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.3s;
  box-shadow: 0 2px 6px rgba(94, 53, 177, 0.3);
}

.btn:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 4px 12px rgba(94, 53, 177, 0.4);
  transform: translateY(-2px);
}

.btn:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
  box-shadow: none;
}

#download-all {
  background: #4CAF50 !important;
}

#download-all:hover:not(:disabled) {
  background: #45a049 !important;
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
  transform: translateY(-2px);
}

.canvas-container {
  flex: 1;
  padding: clamp(20px, 3vw, 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-canvas);
  transition: background-color 0.3s ease;
  position: relative;
  overflow: hidden;
}

.canvas-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    linear-gradient(90deg, var(--border-color) 1px, transparent 1px),
    linear-gradient(var(--border-color) 1px, transparent 1px);
  background-size: 20px 20px;
  opacity: 0.1;
  z-index: 0;
}

#graph {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  max-height: 60vh;
  overflow-y: auto;
}

#graph canvas {
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 4px 20px var(--shadow-color);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  object-fit: contain;
}

#graph canvas:hover {
  box-shadow: 0 6px 24px var(--shadow-color-hover);
  transform: translateY(-2px);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  transition: color 0.3s ease;
  padding: 20px;
  max-width: min(90vw, 500px);
}

.drag-over {
  background-color: var(--accent-light) !important;
  border: 2px dashed var(--accent-color) !important;
  border-radius: 10px;
}

.empty-state svg {
  width: clamp(80px, 20vw, 120px);
  height: clamp(80px, 20vw, 120px);
  margin-bottom: 24px;
  opacity: 0.6;
  transition: opacity 0.3s ease;
  color: var(--accent-color);
}

.empty-state p {
  margin-bottom: 20px;
  line-height: 1.6;
}

/* 多图片预览样式 */
.image-preview-container {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  justify-content: center;
  width: 100%;
  padding: 24px;
  overflow-y: auto;
  max-height: 80vh;
}

.image-preview {
  position: relative;
  max-width: min(250px, 35vw);
  max-height: min(250px, 35vw);
  overflow: hidden;
  border-radius: 12px;
  box-shadow: 0 4px 12px var(--shadow-color);
  transition: all 0.3s ease;
  /* 移除固定宽高比，让容器根据图片比例自动调整 */
}

.image-preview:hover {
  box-shadow: 0 6px 16px var(--shadow-color-hover);
  transform: translateY(-4px);
}

.image-preview canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  /* 使用CSS自定义属性来保持图片比例 */
  aspect-ratio: attr(data-width) / attr(data-height);
}

.image-preview .preview-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.75);
  color: white;
  padding: 8px;
  font-size: clamp(0.6rem, 2vw, 0.75rem);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}

/* 网站底部样式 */
.site-footer {
  background: var(--footer-bg);
  padding: 20px;
  text-align: center;
  border-top: 1px solid var(--border-color);
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.footer-content p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  transition: color 0.3s ease;
}

.footer-content a {
  color: var(--footer-link-color);
  text-decoration: none;
  transition: color 0.3s ease;
}

.footer-content a:hover {
  color: var(--footer-link-hover);
  text-decoration: underline;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .main-content {
    flex-wrap: wrap;
  }
  
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    max-height: 40vh;
    overscroll-behavior: contain; /* Prevent scroll chaining */
  }
  
  .canvas-container {
    min-height: 400px;
  }
  
  #graph {
    max-height: 60vh;
  }
  
  .image-preview-container {
    max-height: 50vh;
  }
  
  .image-preview {
    max-width: min(200px, 30vw);
    max-height: min(200px, 30vw);
  }
  
  .site-footer {
    padding: 15px;
  }
  
  .footer-content p {
    font-size: 0.85rem;
  }
  
  .theme-toggle {
    top: 16px;
    right: 16px;
  }
  
  .header-description {
    font-size: clamp(0.7rem, 1.5vw, 0.8rem) !important;
  }
}

/* New responsive styles for max width 768px */
@media (max-width: 768px) {
  .header p {
    font-size: clamp(0.75rem, 2vw, 1rem);
  }
  
  .sidebar {
    max-height: 35vh;
  }
  
  #graph {
    max-height: 50vh;
  }
  
  .image-preview-container {
    max-height: 45vh;
    gap: 12px;
    padding: 12px;
  }
  
  .image-preview {
    width: calc(50% - 8px);
    min-width: 140px;
  }
  
  .site-footer {
    padding: 12px;
  }
  
  .theme-toggle {
    top: 12px;
    right: 12px;
  }
  
  .theme-btn {
    width: 28px;
    height: 28px;
    padding: 4px;
  }
  
  .theme-toggle svg {
    width: 16px;
    height: 16px;
  }
  
  .header-description {
    font-size: clamp(0.65rem, 1.5vw, 0.75rem) !important;
  }
}

@media (max-width: 576px) {
  .header {
    padding: clamp(16px, 4vw, 24px) clamp(12px, 3vw, 16px);
  }
  
  .header h1 {
    font-size: clamp(1.125rem, 5vw, 1.5rem);
  }
  
  .header p {
    font-size: clamp(0.75rem, 3vw, 0.875rem);
  }
  
  .sidebar {
    padding: clamp(16px, 3vw, 20px);
    max-height: 30vh;
  }
  
  .form-group {
    margin-bottom: clamp(16px, 3vw, 20px);
  }
  
  .canvas-container {
    padding: clamp(16px, 3vw, 20px);
  }
  
  #graph {
    max-height: 45vh;
  }
  
  .image-preview-container {
    gap: 10px;
    padding: 10px;
    max-height: 40vh;
  }
  
  .image-preview {
    width: 100%;
    min-width: unset;
  }
  
  .empty-state {
    font-size: clamp(0.75rem, 3vw, 1rem);
    padding: 16px;
  }
  
  .empty-state svg {
    width: clamp(50px, 15vw, 80px);
    height: clamp(50px, 15vw, 80px);
  }
  
  .site-footer {
    padding: 10px;
  }
  
  .footer-content p {
    font-size: 0.8rem;
  }
  
  .theme-toggle {
    top: 10px;
    right: 10px;
  }
  
  .theme-btn {
    width: 24px;
    height: 24px;
    padding: 3px;
  }
  
  .theme-toggle svg {
    width: 14px;
    height: 14px;
  }
  
  .header-description {
    font-size: clamp(0.6rem, 1.5vw, 0.7rem) !important;
  }
  
  .highlight-text {
    font-size: 0.65rem;
  }
}

/* 超大屏幕优化 */
@media (min-width: 1600px) {
  .container {
    max-width: 1600px;
  }
  
  .header {
    padding: 30px 40px;
  }
  
  .header h1 {
    font-size: 2rem;
  }
  
  .header p {
    font-size: 1.1rem;
  }
  
  .sidebar {
    width: 380px;
    padding: 40px;
  }
  
  .canvas-container {
    padding: 40px;
  }
  
  .image-preview {
    min-width: 250px;
    width: calc(25% - 15px);
  }
  
  .image-preview-container {
    max-height: 85vh;
    gap: 24px;
    padding: 24px;
  }
  
  .site-footer {
    padding: 25px;
  }
  
  .footer-content p {
    font-size: 1rem;
  }
  
  .theme-toggle {
    top: 32px;
    right: 32px;
  }
  
  .theme-btn {
    width: 36px;
    height: 36px;
  }
  
  .theme-toggle svg {
    width: 20px;
    height: 20px;
  }
  
  .header-description {
    font-size: 1rem !important;
  }
}

/* 平滑过渡动画 */
* {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}