:root {
  color-scheme: light dark;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --accent: #ff6f61;
  --bg: #10151a;
  --card: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.12);
  --shadow: rgba(16, 21, 26, 0.25);
}

body {
  margin: 0 auto;
  padding: 2.5rem 1.5rem 3rem;
  max-width: 1100px;
  color: #f7fafc;
  background: linear-gradient(160deg, #10151a, #1a2230 55%, #10151a 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

header {
  text-align: center;
}

h1 {
  margin: 0;
  font-size: clamp(2.5rem, 4vw, 3.5rem);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tagline {
  margin-top: 0.5rem;
  font-size: 1.05rem;
  color: rgba(255, 255, 255, 0.75);
}

main {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
  text-align: center;
}

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.unit-select {
  appearance: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.6rem;
  padding: 0.45rem 0.9rem;
  font-weight: 600;
}

.camera-select {
  appearance: none;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.6rem;
  padding: 0.45rem 0.9rem;
  width: 10rem;
  max-width: 10rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  font-weight: 600;
}

.primary {
  padding: 0.9rem 1.6rem;
  font-size: 1rem;
  font-weight: 600;
  color: #10151a;
  background: linear-gradient(120deg, #ff6f61, #ff9f50);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 15px 35px rgba(255, 111, 97, 0.3);
}

.secondary {
  padding: 0.9rem 1.6rem;
  font-size: 1rem;
  font-weight: 600;
  color: #10151a;
  background: linear-gradient(120deg, #4dd0e1, #80ffea);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 15px 35px rgba(77, 208, 225, 0.25);
}

.primary:disabled {
  cursor: wait;
  opacity: 0.6;
  box-shadow: none;
}

.secondary:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  box-shadow: none;
}

.primary:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 18px 40px rgba(255, 111, 97, 0.35);
}

.secondary:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 18px 40px rgba(77, 208, 225, 0.3);
}

#status {
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.8);
}


/* Focus styles */
button:focus-visible,
select:focus-visible,
input[type="checkbox"]:focus-visible {
  outline: 2px solid #80ffea;
  outline-offset: 2px;
}

.primary:focus-visible { outline-color: #ff9f50; }
.secondary:focus-visible { outline-color: #4dd0e1; }

.disclaimer {
  font-size: 0.85rem;
  max-width: 540px;
  color: rgba(255, 255, 255, 0.65);
}

.stage {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: flex-start;
}

.video-wrapper {
  position: relative;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 1.25rem;
  overflow: hidden;
  box-shadow: 0 25px 45px var(--shadow);
  /* Shorter, wider default ratio to avoid overly tall viewport */
  aspect-ratio: 4 / 3;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

canvas.overlay {
  position: absolute;
  left: 0;
  top: 0;
  /* Do not mirror the canvas; we mirror shapes in code so text stays LTR */
  transform: none;
}

.metrics {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 1.25rem;
  padding: 1.5rem;
  box-shadow: 0 20px 35px var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.metrics h2 {
  margin: 0;
  font-size: 1.35rem;
}

.leaderboard {
  margin-top: 0.5rem;
}

.leaderboard h2 {
  font-size: 1.15rem;
  margin: 0.25rem 0 0.5rem;
}

.leaderboard-list {
  margin: 0;
  padding-left: 1rem;
  display: grid;
  gap: 0.35rem;
}

.leaderboard-list li {
  color: rgba(255, 255, 255, 0.9);
}

.research-mode {
  background: rgba(255, 255, 255, 0.04);
  padding: 1.5rem;
  border-radius: 1.25rem;
  box-shadow: 0 20px 35px var(--shadow);
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.78);
}

footer {
  text-align: center;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.55);
}

@media (max-width: 960px) {
  body {
    padding: 2rem 1rem 3rem;
  }

  .stage {
    grid-template-columns: 1fr;
  }

  /* On smaller screens, use a taller portrait ratio to keep the face large */
  .video-wrapper {
    aspect-ratio: 3 / 4;
  }

  .metrics {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 1rem 2rem;
  }

}

@media (max-width: 600px) {
  header {
    text-align: left;
  }

  .tagline {
    font-size: 0.95rem;
  }

  .controls {
    align-items: flex-start;
    text-align: left;
  }
}
