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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f0f2f5;
  color: #333;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  overflow-x: hidden;
}

header {
  text-align: center;
  padding: 24px 16px 12px;
}

header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 4px;
}

.subtitle {
  color: #666;
  font-size: 0.85rem;
}

main {
  flex: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 8px 12px;
  width: 100%;
}

.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  padding: 16px;
  margin-bottom: 12px;
}

/* Upload Buttons */
.upload-buttons {
  display: flex;
  gap: 12px;
}

.upload-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px 12px;
  border: 2px dashed #d0d5dd;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.9rem;
  color: #555;
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
}

.upload-btn:active {
  transform: scale(0.97);
}

.camera-btn {
  border-color: #4a7dff;
  color: #4a7dff;
  background: #f8faff;
}

.camera-btn svg {
  color: #4a7dff;
}

.gallery-btn svg {
  color: #9ca3af;
}

.upload-btn:hover,
.upload-btn:focus {
  border-color: #4a7dff;
  background: #f8faff;
  outline: none;
}

/* Loading */
.loading {
  text-align: center;
  padding: 32px;
  color: #666;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e5e7eb;
  border-top-color: #4a7dff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Result */
.result-card {
  text-align: center;
  padding: 20px 16px;
}

.result-number {
  font-size: 3.5rem;
  font-weight: 800;
  color: #4a7dff;
  line-height: 1;
  margin-bottom: 4px;
}

.result-label {
  font-size: 0.9rem;
  color: #666;
}

/* Params */
.params-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: #333;
}

.param-group {
  margin-bottom: 12px;
}

.param-group label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: #555;
  margin-bottom: 4px;
}

.param-value {
  font-weight: 600;
  color: #4a7dff;
  min-width: 50px;
  text-align: right;
}

.param-group input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #e5e7eb;
  border-radius: 3px;
  outline: none;
  /* Larger touch target */
  padding: 10px 0;
  margin: -10px 0;
  background-clip: content-box;
}

.param-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #4a7dff;
  cursor: pointer;
  box-shadow: 0 1px 6px rgba(74, 125, 255, 0.4);
}

.param-group input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #4a7dff;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 6px rgba(74, 125, 255, 0.4);
}

.checkbox-group label {
  justify-content: flex-start;
  gap: 8px;
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: #4a7dff;
}

/* Images Grid - single column on mobile */
.images-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.image-card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: #333;
}

.image-card canvas {
  width: 100%;
  border-radius: 8px;
  background: #fafafa;
  display: block;
}

.debug-card {
  margin-top: 0;
}

.debug-card canvas {
  max-width: 100%;
}

/* Footer */
footer {
  text-align: center;
  padding: 16px;
  color: #999;
  font-size: 0.8rem;
}

/* Utilities */
.hidden {
  display: none !important;
}

/* Larger screens */
@media (min-width: 700px) {
  header {
    padding: 40px 20px 20px;
  }

  header h1 {
    font-size: 2rem;
  }

  main {
    padding: 20px;
  }

  .card {
    padding: 24px;
    margin-bottom: 20px;
  }

  .result-number {
    font-size: 4rem;
  }

  .images-grid {
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }

  .debug-card canvas {
    max-width: 50%;
  }

  .upload-btn {
    padding: 36px 12px;
  }
}
