:root {
  --primary: #007AFF;
  --text: #1C1C1E;
  --muted: #8E8E93;
  --card: #FFFFFF;
  --bg: #F2F2F7;
  --border: #E5E5EA;
  --red: #FF3B30;
  --green: #34C759;
  --yellow: #FFCC00;
  --icon-gray: #D1D1D6;
  --destructive-bg: #E9E9EB;
}

* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.02em;
}

body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  margin: 0;
  display: flex;
  justify-content: center;
  background-color: var(--bg);
  color: var(--text);
  width: 100vw;
  overflow-x: hidden;
}

.app-container {
  width: 100%;
  max-width: 440px;
  padding: 20px;
}

.hidden {
  display: none !important;
}

/* App UI Components */
.card {
  background: var(--card);
  border-radius: 28px;
  padding: 32px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  margin-bottom: 20px;
}

.primary-btn,
.upload-trigger {
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 18px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  background: var(--primary);
  color: white;
  display: block;
  text-decoration: none;
}

.upload-trigger.retake {
  background: var(--destructive-bg) !important;
  color: var(--primary) !important;
}

.button-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.secondary-btn-danger {
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 18px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  background: var(--destructive-bg);
  color: var(--red);
  margin-top: 12px;
  margin-bottom: 32px;
  transition: all 0.2s;
}

.secondary-btn-danger:active {
  transform: scale(0.98);
  opacity: 0.9;
}

/* Header & Steps */
.logo-small {
  font-size: 20px;
  font-weight: 900;
  color: var(--primary);
  margin-bottom: 24px;
  text-align: center;
}

h2 {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 12px;
  text-align: center;
}

.left-align {
  text-align: left !important;
}

.stepper-instructions {
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step {
  font-size: 14px;
  color: var(--muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
}

.step span {
  background: #E9E9EB;
  color: var(--muted);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
}

/* Results & History */
.hero-status {
  text-align: center;
  padding-bottom: 24px;
}

.hero-status h1 {
  font-size: 52px;
  font-weight: 900;
  margin: 4px 0 16px;
  letter-spacing: -0.04em;
}

.hero-status label {
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--muted);
  opacity: 0.8;
}

.score-pill-hero {
  display: inline-block;
  padding: 8px 20px;
  background: var(--bg);
  border-radius: 100px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}

.meter-bar {
  width: 100%;
  height: 10px;
  background: #E9E9EB;
  border-radius: 5px;
  margin-bottom: 32px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  transition: width 1s ease-out;
}

.status-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
  min-width: 80px;
}

.badge-ready {
  background: rgba(52, 199, 89, 0.12);
  color: #1E6B30;
}

.badge-not-ready {
  background: rgba(255, 59, 48, 0.12);
  color: #721C24;
}

.badge-yellow {
  background: rgba(255, 204, 0, 0.15);
  color: #856404;
}

.history-card {
  padding: 8px 0;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
}

.history-item:last-child {
  border-bottom: none;
}

.hist-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hist-date {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.score-pill-small {
  background: #E9E9EB;
  color: var(--text);
  padding: 6px 12px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 700;
}

.hist-status-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}


/* Preview Box */
.preview-box {
  width: 100%;
  aspect-ratio: 1/1;
  background: #E9E9EB;
  border-radius: 20px;
  overflow: hidden;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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



/* ---- CAMERA MODAL: THE ULTIMATE iPHONE FIX ---- */
.camera-modal {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  /* Fill entire visible area */
  background: black;
  z-index: 3000;
  overflow: hidden;
}

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

/* Layers: Overlay and UI on top of video */
.camera-ui-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  /* Let clicks pass through to video/shutter */
}

/* Toilet Oval Stencil: Centered absolutely */
.guide-oval-container {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.guide-oval {
  width: 90%;
  height: 70%;
  max-width: 360px;
  max-height: 520px;
  border: 4px dashed rgba(255, 255, 255, 0.8);
  border-radius: 45% 45% 50% 50% / 40% 40% 60% 60%;
  opacity: 0.8;
  /* This creates a dark background everywhere BUT inside the oval */
  box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.6);
  z-index: 10;
}



/* Hints: Pinned to top area */
.camera-hints-top {
  position: absolute;
  top: env(safe-area-inset-top, 10px);
  width: 100%;
  padding-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 20;
}

.hint-pill {
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 10px 22px;
  border-radius: 24px;
  font-weight: 600;
  font-size: 14px;
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--muted);
}

.status-dot.active {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.status-dot.error {
  background: var(--red);
  box-shadow: 0 0 8px var(--red);
}

/* Shutter Button: Pinned to bottom area */
.camera-actions-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 140px;
  /* Adjust height for natural thumb position */
  display: flex;
  justify-content: center;
  align-items: center;
  /* Extra padding to clear Safari's floating bottom bar - adjusted to move button down */
  padding-bottom: calc(env(safe-area-inset-bottom, 20px) + 5px);
  background: transparent;
  /* Transparent over video */
  z-index: 50;
  /* Above oval and video */
  pointer-events: auto;
  /* Capture clicks on the bar */
}

.shutter-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid white;
  background-color: white;
  background-clip: content-box;
  /* Creates the inner circle */
  padding: 4px;
  /* Creates the gap between ring and circle */
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.1s ease-out;
}

.shutter-btn:active {
  background-color: #e5e5e5;
  transform: scale(0.94);
  padding: 6px;
  /* Increases gap slightly on press for visual feedback */
}

.close-btn-round {
  position: absolute;
  top: env(safe-area-inset-top, 20px);
  right: 20px;
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  color: white;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  z-index: 4000;
}

/* Animations */
.animate-in {
  animation: slideUp 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Reassuring Minimalist UI Updates */
.placeholder-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  width: 100%;
  height: 100%;
}

.ghost-rim {
  width: 140px;
  height: 190px;
  border: 4px dashed #D1D1D6;
  border-radius: 45% 45% 50% 50% / 40% 40% 60% 60%;
  /* Organic oval shape */
  margin-bottom: 12px;
  opacity: 0.6;
}


.upload-trigger {
  font-size: 18px !important;
  /* Better visibility */
}

/* Loading Spinner */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
  vertical-align: middle;
}

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

/* Survey Styles */
.survey-container {
  background: #F8F8F9;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  margin: 8px 0 24px;
  text-align: left;
}

.survey-header h3 {
  font-size: 18px;
  font-weight: 800;
  margin: 0 0 4px 0;
  text-align: left;
}

.survey-header p {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 20px 0;
}

.survey-question {
  margin-bottom: 16px;
}

.survey-question label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.rating-stars {
  display: flex;
  gap: 8px;
  font-size: 28px;
  color: var(--icon-gray);
  cursor: pointer;
}

.rating-stars span {
  transition: color 0.1s;
}

.rating-stars span.active {
  color: var(--yellow);
}

.survey-question textarea {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  height: 80px;
}

.survey-submit {
  padding: 14px !important;
  font-size: 15px !important;
  margin-top: 8px;
}

.survey-thanks {
  text-align: center;
  font-weight: 700;
  color: var(--green);
  padding: 10px;
}

/* Waiver Modal Styles */
.waiver-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  padding: 20px;
}

.waiver-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.waiver-card {
  position: relative;
  background: white;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  border-radius: 32px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.waiver-header {
  padding: 32px 32px 16px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.waiver-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
}

.waiver-header p {
  color: var(--muted);
  font-size: 14px;
  margin: 8px 0 0;
  font-weight: 500;
}

.waiver-body {
  padding: 24px 32px;
  overflow-y: auto;
  flex: 1;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  -webkit-overflow-scrolling: touch;
}

.waiver-body h3 {
  font-size: 18px;
  font-weight: 800;
  margin-top: 0;
  margin-bottom: 16px;
}

.waiver-body p {
  margin-bottom: 16px;
}

.waiver-body strong {
  font-weight: 700;
}

.waiver-footer {
  padding: 24px 32px 32px;
  border-top: 1px solid var(--border);
  background: white;
}

.waiver-footer .primary-btn:disabled {
  background: #E9E9EB;
  color: var(--muted);
  cursor: not-allowed;
  opacity: 1;
}

.scroll-instruction {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 12px;
  font-weight: 600;
}

.scroll-instruction.hidden {
  display: none;
}