:root {
  /* Morandi Light Theme */
  --md-sys-color-primary: #7A8B99;
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: #DCE3E9;
  --md-sys-color-on-primary-container: #2A353F;
  
  --md-sys-color-secondary: #A89B9D;
  --md-sys-color-on-secondary: #FFFFFF;
  --md-sys-color-secondary-container: #EBE3E4;
  --md-sys-color-on-secondary-container: #3F3537;

  --md-sys-color-tertiary: #99A89E;
  --md-sys-color-on-tertiary: #FFFFFF;
  
  --md-sys-color-error: #BA1A1A;
  --md-sys-color-on-error: #FFFFFF;
  
  --md-sys-color-background: #F5F5F0;
  --md-sys-color-on-background: #1C1B1F;
  
  --md-sys-color-surface: #FFFFFF;
  --md-sys-color-on-surface: #1C1B1F;
  --md-sys-color-surface-variant: #E7E0EC;
  --md-sys-color-on-surface-variant: #49454F;
  
  --md-sys-color-outline: #79747E;
  --md-sys-color-outline-variant: #CAC4D0;

  --md-sys-elevation-1: 0px 1px 3px 1px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.3);
  --md-sys-elevation-2: 0px 2px 6px 2px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.3);
  
  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-large: 16px;
  --md-sys-shape-corner-full: 9999px;

  /* Legacy variables mapping for compatibility */
  --primary-color: var(--md-sys-color-primary);
  --secondary-color: var(--md-sys-color-secondary);
  --bg-color: var(--md-sys-color-background);
  --panel-bg: var(--md-sys-color-surface);
  --text-color: var(--md-sys-color-on-surface);
  --text-secondary: var(--md-sys-color-on-surface-variant);
  --border-color: var(--md-sys-color-outline-variant);
  --shadow: var(--md-sys-elevation-1);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Morandi Dark Theme */
    --md-sys-color-primary: #AABBC9;
    --md-sys-color-on-primary: #131F28;
    --md-sys-color-primary-container: #2A353F;
    --md-sys-color-on-primary-container: #DCE3E9;
    
    --md-sys-color-secondary: #C8BCC0;
    --md-sys-color-on-secondary: #281F21;
    --md-sys-color-secondary-container: #3F3537;
    --md-sys-color-on-secondary-container: #EBE3E4;

    --md-sys-color-tertiary: #BCC8C0;
    --md-sys-color-on-tertiary: #1F2822;
    
    --md-sys-color-error: #FFB4AB;
    --md-sys-color-on-error: #690005;
    
    --md-sys-color-background: #1C1C1E;
    --md-sys-color-on-background: #E6E1E5;
    
    --md-sys-color-surface: #252529;
    --md-sys-color-on-surface: #E6E1E5;
    --md-sys-color-surface-variant: #49454F;
    --md-sys-color-on-surface-variant: #CAC4D0;
    
    --md-sys-color-outline: #938F99;
    --md-sys-color-outline-variant: #49454F;

    --md-sys-elevation-1: 0px 1px 3px 1px rgba(0, 0, 0, 0.3), 0px 1px 2px 0px rgba(0, 0, 0, 0.6);
    --md-sys-elevation-2: 0px 2px 6px 2px rgba(0, 0, 0, 0.3), 0px 1px 2px 0px rgba(0, 0, 0, 0.6);
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  min-height: 100vh;
  padding: 20px;
  transition: background-color 0.3s ease, color 0.3s ease;
  line-height: 1.5;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding-bottom: 40px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 40px;
  padding: 40px 20px;
  background: var(--md-sys-color-surface);
  border-radius: var(--md-sys-shape-corner-large);
  box-shadow: var(--md-sys-elevation-1);
  transition: background-color 0.3s ease;
}

header h1 {
  font-size: 2.5rem;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 10px;
  font-weight: 400;
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 1.1rem;
  font-weight: 300;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--md-sys-color-surface-container);
  padding: 8px;
  border-radius: var(--md-sys-shape-corner-full);
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}

.tab-btn {
  flex: 1;
  min-width: 120px;
  padding: 12px 24px;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  background-color: rgba(122, 139, 153, 0.08); /* Using primary color with low opacity */
}

.tab-btn.active {
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  box-shadow: var(--md-sys-elevation-1);
}

/* Content Panels */
.tab-content {
  display: none;
  animation: fadeIn 0.4s cubic-bezier(0.2, 0.0, 0, 1.0);
}

.tab-content.active {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 24px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel {
  background: var(--md-sys-color-surface);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 32px;
  box-shadow: var(--md-sys-elevation-1);
  transition: background-color 0.3s ease;
  border: 1px solid var(--md-sys-color-outline-variant);
}

.panel.full-width {
  grid-column: 1 / -1;
}

.panel h2 {
  margin-bottom: 24px;
  color: var(--md-sys-color-on-surface);
  font-size: 1.5rem;
  font-weight: 400;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  padding-bottom: 16px;
}

/* Form Elements */
.form-group {
  margin-bottom: 24px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.9rem;
  font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="number"] {
  width: 100%;
  padding: 14px 16px;
  background: var(--md-sys-color-surface-container);
  border: 1px solid transparent;
  border-radius: var(--md-sys-shape-corner-small);
  color: var(--md-sys-color-on-surface);
  font-size: 1rem;
  transition: all 0.2s ease;
}

.form-group input[type="text"]:focus,
.form-group input[type="number"]:focus {
  outline: none;
  background: var(--md-sys-color-surface);
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 2px var(--md-sys-color-primary-container);
}

/* Range Slider */
.form-group input[type="range"] {
  width: calc(100% - 60px);
  margin-right: 10px;
  height: 6px;
  background: var(--md-sys-color-surface-variant);
  border-radius: 3px;
  appearance: none;
  outline: none;
}

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

.form-group input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.value-display {
  display: inline-block;
  min-width: 48px;
  padding: 4px 8px;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-radius: var(--md-sys-shape-corner-small);
  text-align: center;
  font-size: 0.9rem;
  font-weight: 500;
}

/* Checkbox */
.form-group input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-right: 10px;
  accent-color: var(--md-sys-color-primary);
  cursor: pointer;
  vertical-align: middle;
}

/* File Input */
.form-group input[type="file"] {
  padding: 10px;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-small);
  color: var(--md-sys-color-on-surface);
  width: 100%;
  font-size: 0.9rem;
}

/* Buttons */
.button-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 32px;
}

.btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-sys-elevation-1);
}

.btn-primary:hover {
  box-shadow: var(--md-sys-elevation-2);
  filter: brightness(1.05);
}

.btn-secondary {
  background-color: transparent;
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline);
}

.btn-secondary:hover {
  background-color: var(--md-sys-color-primary-container);
  border-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary-container);
}

.btn-info {
  background-color: var(--md-sys-color-tertiary);
  color: var(--md-sys-color-on-tertiary);
}

.btn-success {
  background-color: #4A6E58; /* Muted Green */
  color: white;
}

.btn-danger {
  background-color: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
}

.btn-recording {
  background-color: var(--md-sys-color-error);
  color: var(--md-sys-color-on-error);
  animation: pulse 2s infinite;
}

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

/* Preview Areas */
.preview-box {
  margin-top: 12px;
  min-height: 140px;
  background: var(--md-sys-color-surface-container);
  border: 2px dashed var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-medium);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.preview-box:empty:before {
  content: '预览区域';
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.9rem;
}

.preview-box img {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  display: block;
}

.preview-container {
  background: #333; /* Dark background to make white watermark visible */
  background-image: linear-gradient(45deg, #333 25%, #444 25%, #444 50%, #333 50%, #333 75%, #444 75%, #444 100%);
  background-size: 20px 20px;
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 24px;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.watermark-preview {
  position: relative;
  max-width: 100%;
}

.watermark-preview img {
  max-width: 100%;
  height: auto;
  display: block;
}

.preview-text {
  position: absolute;
  bottom: 10px;
  left: 20px;
  color: white;
  font-size: 1rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

/* Upload Area */
.upload-area {
  border: 2px dashed var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-large);
  padding: 60px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background: var(--md-sys-color-surface);
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.upload-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  color: var(--md-sys-color-primary);
}

.upload-hint {
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.9rem;
  margin-top: 10px;
}

/* File Info */
.file-info {
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 20px;
  margin-top: 20px;
}

.file-info h3 {
  margin-bottom: 15px;
  color: var(--md-sys-color-primary);
}

#fileDetails {
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.8;
}

/* Canvas and Video */
#previewCanvas,
#previewVideo {
  max-width: 100%;
  border-radius: var(--md-sys-shape-corner-small);
}

/* Camera */
.camera-container {
  position: relative;
  background: black;
  border-radius: var(--md-sys-shape-corner-large);
  overflow: hidden;
  width: auto;
  max-width: 100%;
  margin: 0 auto 24px auto;
  aspect-ratio: 16 / 9;
  box-shadow: var(--md-sys-elevation-2);
  max-height: 70vh;
}

#cameraPreview {
  width: 100%;
  height: 100%;
  display: block;
  background: black;
  object-fit: cover;
}

#cameraCanvas {
  display: none;
}

.camera-watermark {
  position: absolute;
  pointer-events: none;
  z-index: 10;
}

.camera-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-large);
}

.camera-controls .btn {
  flex: 0 1 auto;
  min-width: 100px;
  padding: 10px 16px;
  font-size: 0.9rem;
}

/* Captured Items */
.captured-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 24px;
  margin-top: 32px;
}

.captured-item {
  background: var(--md-sys-color-surface);
  border-radius: var(--md-sys-shape-corner-medium);
  overflow: hidden;
  box-shadow: var(--md-sys-elevation-1);
  transition: transform 0.2s;
}

.captured-item:hover {
  transform: translateY(-4px);
  box-shadow: var(--md-sys-elevation-2);
}

.captured-item img,
.captured-item video {
  width: 100%;
  display: block;
}

.captured-item-actions {
  padding: 12px;
  display: flex;
  gap: 8px;
  background: var(--md-sys-color-surface);
}

.captured-item-actions .btn {
  flex: 1;
  padding: 8px;
  font-size: 0.9rem;
  min-width: auto;
}

/* Status Messages */
.status-message {
  padding: 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  margin-top: 24px;
  text-align: center;
  font-weight: 500;
}

.status-message.success {
  background-color: #E6F4EA;
  color: #1E4620;
  border: 1px solid #C6E7CE;
}

.status-message.error {
  background-color: #FCE8E6;
  color: #8C1D18;
  border: 1px solid #F6C7C3;
}

.status-message.info {
  background-color: #E3F2FD;
  color: #0D47A1;
  border: 1px solid #BBDEFB;
}

/* Footer */
footer {
  text-align: center;
  margin-top: 60px;
  padding: 24px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.9rem;
}

footer a {
  color: var(--md-sys-color-primary);
  text-decoration: none;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .container {
    padding: 10px;
  }
  
  header {
    padding: 24px 16px;
    margin-bottom: 24px;
  }
  
  header h1 {
    font-size: 1.8rem;
  }
  
  .tabs {
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
    padding-bottom: 12px;
    /* Hide scrollbar */
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  
  .tabs::-webkit-scrollbar {
    display: none;
  }
  
  .tab-btn {
    flex: 0 0 auto;
    padding: 10px 20px;
  }
  
  .tab-content.active {
    grid-template-columns: 1fr;
  }
  
  .panel {
    padding: 20px;
  }
  
  .camera-controls .btn {
    flex: 1 1 calc(50% - 12px);
  }
}

/* Dark mode specific overrides for status messages if needed */
@media (prefers-color-scheme: dark) {
  .status-message.success {
    background-color: #0F291E;
    color: #A5D6A7;
    border-color: #1B5E20;
  }
  
  .status-message.error {
    background-color: #2C1515;
    color: #EF9A9A;
    border-color: #B71C1C;
  }
  
  .status-message.info {
    background-color: #0D1B2A;
    color: #90CAF9;
    border-color: #1565C0;
  }
}

/* File Input Group Utility */
.file-input-group {
  display: flex;
  gap: 10px;
  align-items: center;
}

.file-input-group input[type="file"] {
  flex: 1;
}

.file-input-group .btn {
  flex: 0 0 auto;
  padding: 10px 16px;
}

/* Preview Box Active State */
.preview-box.has-image {
  border-style: solid;
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
}

/* Camera Watermark Text */
.camera-watermark .watermark-text {
  position: absolute;
  color: white;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  line-height: 1.2;
  z-index: 2;
}

/* Progress Bar */
.progress-container {
  margin: 24px 0;
  padding: 20px;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-medium);
}

.progress-bar-wrapper {
  width: 100%;
  height: 8px;
  background: var(--md-sys-color-surface-variant);
  border-radius: var(--md-sys-shape-corner-full);
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--md-sys-color-primary), var(--md-sys-color-secondary));
  border-radius: var(--md-sys-shape-corner-full);
  transition: width 0.3s ease;
  width: 0%;
}

.progress-text {
  text-align: center;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.9rem;
  font-weight: 500;
  margin: 0;
}
