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

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --primary: #00d4ff;
  --primary-glow: rgba(0, 212, 255, 0.3);
  --accent: #ff6b6b;
  --text: #ffffff;
  --text-dim: #8888aa;
  --success: #4ecdc4;
  --radius: 12px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* Screens */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

/* Start Screen */
#start-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 100%);
}

.start-content {
  text-align: center;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
}

.logo {
  font-size: 4rem;
  margin-bottom: 0.5rem;
}

.start-content h1 {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--text-dim);
  margin: 0.5rem 0 2rem;
  font-size: 1rem;
}

.exercise-select h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}

.exercise-options {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.exercise-btn {
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 1rem 0.75rem;
  color: var(--text);
  cursor: pointer;
  flex: 1;
  max-width: 120px;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.exercise-btn.selected {
  border-color: var(--primary);
  background: rgba(0, 212, 255, 0.1);
  box-shadow: 0 0 20px var(--primary-glow);
}

.exercise-icon {
  font-size: 1.5rem;
}

.exercise-name {
  font-size: 0.8rem;
  font-weight: 600;
}

.camera-select {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.camera-select label {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.camera-select select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid #333;
  border-radius: 8px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

.primary-btn {
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  color: #000;
  border: none;
  border-radius: 50px;
  padding: 1rem 3rem;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  width: 100%;
  max-width: 300px;
}

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

/* Workout Screen */
#workout-screen {
  flex-direction: column;
  background: #000;
}

.video-container {
  position: relative;
  flex: 1;
  overflow: hidden;
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* HUD */
.hud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  padding: env(safe-area-inset-top, 12px) 12px env(safe-area-inset-bottom, 12px);
}

.hud > * {
  pointer-events: auto;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
}

.icon-btn {
  background: rgba(0, 0, 0, 0.5);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.exercise-label {
  background: rgba(0, 0, 0, 0.5);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  backdrop-filter: blur(10px);
}

.hud-center {
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.counter-display {
  text-align: center;
}

.counter-value {
  font-size: 7rem;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0 40px var(--primary-glow), 0 2px 10px rgba(0,0,0,0.8);
  color: var(--primary);
  transition: transform 0.15s;
}

.counter-value.bump {
  transform: scale(1.15);
}

.counter-label {
  font-size: 1.2rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.hud-bottom {
  display: flex;
  justify-content: space-around;
  padding: 8px;
}

.stat-box {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  padding: 8px 16px;
  text-align: center;
  min-width: 80px;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 26, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 10;
}

.loading-overlay.hidden {
  display: none;
}

.loading-overlay p {
  font-size: 1rem;
  font-weight: 600;
  max-width: 280px;
  text-align: center;
}

.loading-tips {
  font-size: 0.8rem;
  color: var(--text-dim);
  max-width: 260px;
  text-align: center;
  min-height: 1.2em;
}

/* No Body Detected Overlay */
.no-body-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  z-index: 8;
  pointer-events: none;
}

.no-body-overlay.hidden {
  display: none;
}

.no-body-icon {
  font-size: 3rem;
  opacity: 0.8;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.1); opacity: 1; }
}

.no-body-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: #ff6b6b;
  text-shadow: 0 1px 6px rgba(0,0,0,0.8);
  background: rgba(0, 0, 0, 0.5);
  padding: 6px 18px;
  border-radius: 20px;
  backdrop-filter: blur(10px);
}

.no-body-tip {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  background: rgba(0, 0, 0, 0.5);
  padding: 8px 18px;
  border-radius: 12px;
  backdrop-filter: blur(10px);
  max-width: 300px;
  text-align: center;
  transition: opacity 0.3s;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Feedback Toast */
.feedback {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 212, 255, 0.2);
  border: 2px solid var(--primary);
  color: var(--primary);
  padding: 12px 28px;
  border-radius: 50px;
  font-size: 1.3rem;
  font-weight: 700;
  backdrop-filter: blur(10px);
  z-index: 5;
  animation: feedbackPop 0.6s ease-out forwards;
}

.feedback.hidden {
  display: none;
}

@keyframes feedbackPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  30% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* Controls Bar */
.controls-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--surface);
}

.control-btn {
  flex: 1;
  padding: 12px;
  border: 1px solid #333;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.control-btn.primary {
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  color: #000;
  border: none;
}

/* Summary Screen */
#summary-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 100%);
}

.summary-content {
  text-align: center;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
}

.summary-content h1 {
  font-size: 1.8rem;
  margin-bottom: 2rem;
  background: linear-gradient(135deg, var(--success), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.summary-stats {
  margin-bottom: 2rem;
}

.summary-stat.main {
  margin-bottom: 1.5rem;
}

.summary-stat.main .summary-value {
  font-size: 5rem;
  font-weight: 900;
  color: var(--primary);
  line-height: 1;
}

.summary-row {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.summary-stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  flex: 1;
}

.summary-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.summary-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-top: 4px;
}

.summary-actions {
  margin-top: 2rem;
}

/* Secondary Button */
.secondary-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid #333;
  border-radius: 50px;
  padding: 0.75rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  max-width: 300px;
  margin-top: 0.75rem;
  transition: all 0.2s;
}

.secondary-btn:active {
  background: var(--surface);
}

/* History Screen */
#history-screen {
  flex-direction: column;
  background: var(--bg);
}

.history-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}

.history-header h1 {
  font-size: 1.3rem;
  font-weight: 700;
}

.clear-btn {
  font-size: 1rem;
}

/* Totals Grid */
.totals-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 0 16px 16px;
}

.total-item {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
}

.total-value {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.total-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-top: 2px;
}

/* History List */
.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 24px;
}

.history-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 3rem 1rem;
  font-size: 0.95rem;
}

.history-day {
  margin-bottom: 16px;
}

.history-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #222;
  margin-bottom: 8px;
}

.history-day-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

.history-day-total {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 6px;
}

.history-item-exercise {
  font-size: 0.95rem;
  font-weight: 600;
}

.history-item-time {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.history-item-reps {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
}

.reps-unit {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-dim);
  margin-left: 3px;
}
