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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
    "Helvetica", "Arial", sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 10px;
  color: #333;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  background: white;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

@media (max-width: 768px) {
  body {
    padding: 0;
  }

  .container {
    border-radius: 0;
    min-height: 100vh;
  }
}

header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 30px 20px;
  text-align: center;
}

header h1 {
  font-size: 2.5em;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
  font-size: 1.2em;
  opacity: 0.95;
}

.main-content {
  padding: 30px 20px;
}

@media (max-width: 768px) {
  header {
    padding: 25px 15px;
  }

  header h1 {
    font-size: 2em;
    margin-bottom: 8px;
  }

  .subtitle {
    font-size: 1em;
  }

  .main-content {
    padding: 20px 15px;
  }
}

/* Input Section */
.input-section {
  margin-bottom: 40px;
}

.input-options {
  display: flex;
  gap: 15px;
  justify-content: center;
  align-items: center;
  margin-bottom: 25px;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .input-options {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
  }
}

.btn {
  padding: 16px 32px;
  border: none;
  border-radius: 12px;
  font-size: 1.1em;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 600;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: 48px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

.btn:active {
  transform: translateY(0);
  opacity: 0.9;
}

@media (max-width: 768px) {
  .btn {
    padding: 18px 24px;
    font-size: 1em;
    min-height: 52px;
    width: 100%;
  }
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-secondary {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
}

.btn-capture {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  color: white;
  margin-top: 20px;
}

.btn-analyze {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  color: white;
  width: 100%;
  max-width: 400px;
  margin: 20px auto;
  display: block;
  padding: 20px;
  font-size: 1.3em;
}

@media (max-width: 768px) {
  .btn-analyze {
    max-width: 100%;
    font-size: 1.1em;
    padding: 18px;
    margin: 15px auto;
  }
}

.btn-reset {
  background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
  color: white;
  width: 100%;
  max-width: 400px;
  margin: 30px auto 0;
  display: block;
}

/* Webcam Section */
.webcam-section {
  text-align: center;
  margin: 30px 0;
}

#webcam {
  width: 100%;
  max-width: 640px;
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  transform: scaleX(-1);
}

/* Image Preview */
.image-preview {
  text-align: center;
  margin: 30px 0;
}

#imageCanvas {
  max-width: 100%;
  height: auto;
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

@media (max-width: 768px) {
  .webcam-section {
    margin: 20px 0;
  }

  #webcam {
    border-radius: 10px;
  }

  .image-preview {
    margin: 20px 0;
  }

  #imageCanvas {
    border-radius: 10px;
  }
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
}

.spinner {
  width: 60px;
  height: 60px;
  margin: 0 auto 20px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Results Section */
.results-section {
  animation: fadeIn 0.5s ease-in;
}

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

.results-section h2 {
  text-align: center;
  font-size: 2em;
  margin-bottom: 30px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

@media (max-width: 768px) {
  .results-section h2 {
    font-size: 1.6em;
    margin-bottom: 20px;
  }
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.metric-card {
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  border-radius: 15px;
  padding: 25px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.metric-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
}

.overall-card {
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
  grid-column: span 2;
}

@media (max-width: 768px) {
  .metrics-grid {
    grid-template-columns: 1fr;
    gap: 15px;
    margin-bottom: 20px;
  }

  .metric-card {
    border-radius: 12px;
    padding: 20px;
  }

  .metric-card:hover {
    transform: none;
  }

  .overall-card {
    grid-column: span 1;
  }
}

.metric-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.metric-icon {
  font-size: 2em;
  flex-shrink: 0;
}

.metric-header h3 {
  font-size: 1.3em;
  color: #333;
  line-height: 1.3;
}

@media (max-width: 768px) {
  .metric-header {
    gap: 10px;
    margin-bottom: 15px;
  }

  .metric-icon {
    font-size: 1.8em;
  }

  .metric-header h3 {
    font-size: 1.1em;
  }
}

.metric-score {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.score-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  position: relative;
}

.score-circle.large {
  width: 120px;
  height: 120px;
}

.score-value {
  font-size: 2.5em;
  font-weight: bold;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.score-circle.large .score-value {
  font-size: 3em;
}

@media (max-width: 768px) {
  .score-circle {
    width: 90px;
    height: 90px;
  }

  .score-circle.large {
    width: 110px;
    height: 110px;
  }

  .score-value {
    font-size: 2.2em;
  }

  .score-circle.large .score-value {
    font-size: 2.8em;
  }
}

.metric-bar {
  width: 100%;
  height: 12px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff6b6b 0%, #ee5a6f 100%);
  border-radius: 10px;
  transition: width 1s ease-out;
}

.bar-positive {
  background: linear-gradient(90deg, #51cf66 0%, #38d9a9 100%);
}

.metric-description {
  text-align: center;
  color: #666;
  font-size: 0.9em;
}

.metric-rating {
  text-align: center;
  font-size: 1.5em;
  font-weight: bold;
  color: #333;
  margin-top: 10px;
}

@media (max-width: 768px) {
  .metric-rating {
    font-size: 1.3em;
    margin-top: 8px;
  }
}

/* Footer */
footer {
  text-align: center;
  padding: 20px;
  background: #f8f9fa;
  color: #666;
  font-size: 0.9em;
}

@media (max-width: 768px) {
  footer {
    padding: 15px;
    font-size: 0.85em;
  }
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
  .btn:hover {
    transform: none;
  }

  .metric-card:hover {
    transform: none;
  }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
  .container {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }

  header {
    padding-top: max(30px, env(safe-area-inset-top));
  }

  footer {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
}
