/* ==========================================
   NogginFit — Brand Theme
   ========================================== */

:root {
  --bg-deep: #ffffff;
  --bg-card: #f8f8f8;
  --bg-elevated: #f2f2f2;
  --bg-input: #ffffff;
  --teal: #0D9488;
  --teal-dim: rgba(13, 148, 136, 0.12);
  --teal-glow: rgba(13, 148, 136, 0.3);
  --teal-bright: #14B8A6;
  --white: #000000;
  --white-dim: #4A4A4A;
  --white-muted: #888888;
  --danger: #e53e3e;
  --warning: #d97706;
  --success: #10B981;
  --font-ui: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-heading: 'Oswald', 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--white);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

/* ============ SCREENS ============ */
.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ============ WELCOME ============ */
.welcome-container {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 24px 24px 16px; overflow-y: auto; gap: 24px;
  background: #ffffff;
}

.logo-area { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }

.brand-logo {
  height: 52px;
  width: auto;
  margin-bottom: 8px;
}

.app-title {
  font-family: var(--font-heading);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #000000;
}
.app-subtitle {
  font-family: var(--font-heading);
  font-size: 13px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 500;
}

.welcome-description { max-width: 340px; text-align: center; }
.welcome-description p { font-size: 15px; line-height: 1.6; color: var(--white-dim); }

.instructions { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 340px; }
.instruction-step {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px;
  background: #ffffff; border: 1px solid #e8e8e8; border-radius: var(--radius-sm);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.step-num {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--teal);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-heading); font-size: 14px; font-weight: 600;
  color: var(--teal); flex-shrink: 0; background: var(--teal-dim);
}
.step-text { font-size: 14px; color: var(--white-dim); }
.step-text strong { color: #000000; }

/* Buttons */
.btn-primary {
  width: 100%; max-width: 340px; padding: 16px 24px; background: var(--teal);
  color: #ffffff; border: none; border-radius: var(--radius);
  font-family: var(--font-heading); font-size: 18px; font-weight: 600;
  letter-spacing: 1px; text-transform: uppercase; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: all 0.2s; min-height: 52px;
  box-shadow: 0 4px 16px rgba(13,148,136,0.3);
}
.btn-primary:hover { background: var(--teal-bright); transform: translateY(-1px); box-shadow: 0 6px 24px rgba(13,148,136,0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-icon svg { display: block; }

.btn-secondary {
  width: 100%; max-width: 340px; padding: 14px 24px; background: transparent;
  color: var(--teal); border: 2px solid var(--teal);
  border-radius: var(--radius); font-family: var(--font-heading); font-size: 15px;
  font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase;
  cursor: pointer; transition: all 0.2s; min-height: 48px;
}
.btn-secondary:hover { background: var(--teal); color: #ffffff; }

.welcome-footer {
  padding: 16px; text-align: center;
  background: #ffffff; border-top: 1px solid #f0f0f0;
}
.footer-note { font-size: 11px; color: var(--white-muted); letter-spacing: 0.5px; }

/* ============ CAMERA SCREEN ============ */
.camera-container { position: relative; width: 100%; height: 100%; background: #000; overflow: hidden; }
#camera-video { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
#camera-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

.hud-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  justify-content: space-between; pointer-events: none; z-index: 10;
}

.hud-top {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 16px; padding-top: max(16px, env(safe-area-inset-top, 16px)); pointer-events: auto;
}
.hud-top-left { display: flex; flex-direction: column; gap: 8px; }

.hud-status {
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 8px 14px; border-radius: 20px; border: 1px solid rgba(13,148,136,0.3);
  font-family: var(--font-ui); font-size: 12px; color: rgba(255,255,255,0.8);
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); transition: background 0.3s; }
.status-dot.detecting { background: var(--teal); animation: dot-pulse 1.5s infinite; }
.status-dot.stable { background: var(--success); }
.status-dot.error { background: var(--danger); }
@keyframes dot-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.btn-back {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.15); color: #ffffff;
  display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s;
}
.btn-back:hover { border-color: var(--danger); color: var(--danger); }

/* HUD Bottom */
.hud-bottom {
  padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  display: flex; flex-direction: column; gap: 10px; pointer-events: auto;
}

/* Angle Arc */
.angle-arc-container {
  display: flex; justify-content: center; align-items: center;
}
#angle-arc { width: 200px; height: 100px; }

/* Readouts */
.hud-readouts { display: flex; gap: 8px; justify-content: center; }
.readout {
  flex: 1; background: rgba(0,0,0,0.8); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(13,148,136,0.15); border-radius: var(--radius-sm);
  padding: 8px 6px; text-align: center; display: flex; flex-direction: column; gap: 3px;
}
.readout-primary { border-color: rgba(13,148,136,0.4); background: rgba(13,148,136,0.1); }
.readout-label { font-family: var(--font-ui); font-size: 9px; letter-spacing: 1px; color: rgba(255,255,255,0.5); text-transform: uppercase; }
.readout-value { font-family: var(--font-ui); font-size: 20px; font-weight: 700; color: var(--teal); line-height: 1; }
.readout-primary .readout-value { font-size: 24px; }
.readout-unit { font-family: var(--font-ui); font-size: 10px; color: rgba(255,255,255,0.4); }

/* Scan Progress */
.scan-progress-container {
  background: rgba(0,0,0,0.7); border-radius: var(--radius-sm);
  padding: 10px 12px; display: flex; flex-direction: column; gap: 6px;
}
.scan-progress-header { display: flex; justify-content: space-between; align-items: center; }
.scan-progress-title { font-family: var(--font-ui); font-size: 9px; letter-spacing: 1.5px; color: rgba(255,255,255,0.5); }
.scan-progress-pct { font-family: var(--font-ui); font-size: 12px; font-weight: 700; color: var(--teal); }

.scan-progress-bar { height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; overflow: hidden; }
.scan-progress-fill {
  height: 100%; width: 0%; border-radius: 2px; transition: width 0.3s ease;
  background: linear-gradient(90deg, var(--teal), var(--teal-bright));
  box-shadow: 0 0 8px var(--teal-glow);
}

.scan-angle-label { font-family: var(--font-ui); font-size: 10px; color: rgba(255,255,255,0.5); }

/* Voice Instructions */
.voice-instructions-area {
  background: rgba(0,0,0,0.85); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(13,148,136,0.25); border-radius: var(--radius-sm);
  padding: 10px 14px; text-align: center;
}
.voice-instructions-text {
  font-family: var(--font-ui); font-size: 13px; color: var(--teal); line-height: 1.5;
  margin-bottom: 4px; font-weight: 600;
}
.voice-instructions-hint {
  font-size: 10px; color: rgba(255,255,255,0.5); line-height: 1.4;
}

/* ============ EYE READING PHASE OVERLAY ============ */
.eye-phase-overlay {
  position: absolute; inset: 0; z-index: 15;
  display: flex; flex-direction: column; justify-content: space-between;
  background: linear-gradient(180deg, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.25) 40%, rgba(0,0,0,0.25) 60%, rgba(0,0,0,0.75) 100%);
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.eye-phase-overlay.hidden {
  opacity: 0; pointer-events: none;
}

.eye-phase-top {
  display: flex; justify-content: flex-end; align-items: flex-start;
  padding: 16px; padding-top: max(16px, env(safe-area-inset-top, 16px));
  pointer-events: auto;
}

.eye-phase-center {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 0 32px; text-align: center;
}
.eye-phase-icon {
  width: 80px; height: 50px;
  animation: eye-pulse 2s ease-in-out infinite;
}
.eye-phase-icon.locked {
  animation: none;
  filter: drop-shadow(0 0 12px rgba(13,148,136,0.8));
}
@keyframes eye-pulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}
.eye-phase-title {
  font-family: var(--font-heading); font-size: 22px; font-weight: 700;
  color: var(--teal); letter-spacing: 1px; text-transform: uppercase;
  text-shadow: 0 0 30px rgba(13,148,136,0.4);
}
.eye-phase-subtitle {
  font-size: 14px; color: rgba(255,255,255,0.8); line-height: 1.5;
  max-width: 280px;
}

.eye-phase-bottom {
  padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  display: flex; flex-direction: column; gap: 12px;
  pointer-events: auto;
}

/* Eye Progress Bar */
.eye-progress-container {
  background: rgba(0,0,0,0.8); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(13,148,136,0.2); border-radius: var(--radius-sm);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
}
.eye-progress-header { display: flex; justify-content: space-between; align-items: center; }
.eye-progress-label {
  font-family: var(--font-ui); font-size: 10px; letter-spacing: 1.5px;
  color: var(--teal); text-transform: uppercase; font-weight: 600;
}
.eye-progress-pct {
  font-family: var(--font-ui); font-size: 13px; font-weight: 700; color: var(--teal);
}
.eye-progress-bar {
  height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; overflow: hidden;
}
.eye-progress-fill {
  height: 100%; width: 0%; border-radius: 3px; transition: width 0.3s ease;
  background: linear-gradient(90deg, var(--teal), var(--teal-bright));
  box-shadow: 0 0 10px var(--teal-glow);
}
.eye-progress-hint {
  font-family: var(--font-ui); font-size: 11px; color: rgba(255,255,255,0.5);
}

/* Scan Buttons */
.scan-buttons { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.manual-scan-hint { font-size: 10px; color: rgba(255,255,255,0.4); text-align: center; line-height: 1.3; }

/* Distance Indicator */
.distance-indicator {
  font-family: var(--font-ui); font-size: 13px; text-align: center;
  padding: 8px 14px; border-radius: var(--radius-sm); min-height: 36px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.3s ease;
}
.distance-indicator:empty { display: none; }
.distance-indicator.too-far {
  background: rgba(217, 119, 6, 0.2); border: 1px solid rgba(217, 119, 6, 0.4);
  color: #fbbf24;
}
.distance-indicator.approaching {
  background: rgba(217, 119, 6, 0.15); border: 1px solid rgba(217, 119, 6, 0.25);
  color: #fbbf24;
}
.distance-indicator.good {
  background: rgba(13,148,136,0.15); border: 1px solid rgba(13,148,136,0.35);
  color: var(--teal);
}
.distance-indicator.too-close {
  background: rgba(229, 62, 62, 0.2); border: 1px solid rgba(229, 62, 62, 0.4);
  color: #fc8181;
}

.btn-capture {
  width: 100%; padding: 14px; background: var(--teal); border: none;
  border-radius: var(--radius); color: #ffffff; font-family: var(--font-heading);
  font-size: 16px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase;
  cursor: pointer; transition: all 0.2s; min-height: 48px;
}
.btn-capture:disabled { opacity: 0.35; cursor: not-allowed; background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.5); }
.btn-capture:not(:disabled):hover { background: var(--teal-bright); }

/* Message Overlay */
.message-overlay {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.85); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(13,148,136,0.3); border-radius: var(--radius);
  padding: 16px 24px; text-align: center; opacity: 0; transition: opacity 0.3s;
  pointer-events: none; z-index: 20;
}
.message-overlay.visible { opacity: 1; }
.message-overlay p { font-family: var(--font-ui); font-size: 13px; color: var(--teal); line-height: 1.5; font-weight: 600; }

/* ============ RESULTS ============ */
.results-container {
  flex: 1; overflow-y: auto; padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top, 24px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 24px));
  display: flex; flex-direction: column; gap: 20px;
  background: #f5f5f5;
}

.results-header { display: flex; justify-content: space-between; align-items: center; }
.results-header h2 {
  font-family: var(--font-heading);
  font-size: 20px; font-weight: 700; color: #000000;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.results-confidence { display: flex; align-items: center; gap: 6px; font-family: var(--font-ui); font-size: 12px; color: #22c55e; font-weight: 600; }
.confidence-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }
.results-confidence.medium .confidence-dot { background: var(--warning); }
.results-confidence.medium { color: var(--warning); }
.results-confidence.low .confidence-dot { background: var(--danger); }
.results-confidence.low { color: var(--danger); }

/* Measurement size summary (cm / inches) */
.measurement-size-summary {
  text-align: center; padding: 12px 16px;
}
.size-summary-text {
  font-family: var(--font-ui); font-size: 16px; color: var(--white-muted); font-weight: 500;
}

.hat-size-section {
  background: #ffffff; border: 1px solid #e8e8e8; border-radius: var(--radius);
  padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.hat-size-section h3 {
  font-family: var(--font-heading); font-size: 12px; letter-spacing: 2px;
  text-transform: uppercase; color: var(--teal); margin-bottom: 12px; font-weight: 600;
}
.hat-size-display {
  font-family: var(--font-heading); font-size: 40px; font-weight: 700;
  text-align: center; margin-bottom: 16px; color: #000000; letter-spacing: 1px;
}
.hat-size-chart { display: flex; flex-direction: column; gap: 4px; }
.hat-row {
  display: flex; justify-content: space-between; padding: 10px 14px;
  border-radius: 8px; font-size: 14px; transition: all 0.2s;
  border: 1px solid transparent;
}
.hat-row.active {
  background: var(--teal-dim); border: 1px solid rgba(13,148,136,0.35);
}
.hat-label { font-family: var(--font-heading); font-weight: 600; color: #4A4A4A; font-size: 15px; }
.hat-row.active .hat-label { color: var(--teal); }
.hat-range { font-family: var(--font-ui); font-size: 13px; color: var(--white-muted); }



.how-it-works {
  background: #ffffff; border: 1px solid #e8e8e8; border-radius: var(--radius);
  overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.accordion-toggle {
  width: 100%; padding: 16px 20px; background: none; border: none;
  color: #4A4A4A; font-family: var(--font-ui); font-size: 14px; font-weight: 500;
  cursor: pointer; display: flex; justify-content: space-between; align-items: center; transition: color 0.2s;
}
.accordion-toggle:hover { color: var(--teal); }
.accordion-arrow { transition: transform 0.3s; color: var(--teal); }
.accordion-toggle.open .accordion-arrow { transform: rotate(180deg); }
.accordion-content { max-height: 0; overflow: hidden; transition: max-height 0.4s ease; }
.accordion-content p, .accordion-content ul { padding: 0 20px; font-size: 14px; line-height: 1.7; color: var(--white-dim); }
.accordion-content p { margin-bottom: 12px; }
.accordion-content ul { margin-bottom: 20px; padding-left: 36px; }
.accordion-content li { margin-bottom: 6px; }
.accordion-content strong { color: #000000; }

.results-actions { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
.results-actions .btn-primary, .results-actions .btn-secondary { max-width: 100%; }

/* ============ LOADING ============ */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(255,255,255,0.97);
  display: none; align-items: center; justify-content: center; z-index: 1000; flex-direction: column;
}
.loading-overlay.visible { display: flex; }
.loading-content { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.loading-spinner {
  width: 48px; height: 48px; border: 3px solid rgba(13,148,136,0.15);
  border-top-color: var(--teal); border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-family: var(--font-heading); font-size: 16px; color: var(--teal); font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }
.loading-subtext { font-size: 13px; color: var(--white-muted); }

/* ============ ANIMATIONS ============ */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.screen.active .welcome-container > * { animation: fadeIn 0.5s ease backwards; }
.screen.active .welcome-container > *:nth-child(1) { animation-delay: 0.05s; }
.screen.active .welcome-container > *:nth-child(2) { animation-delay: 0.15s; }
.screen.active .welcome-container > *:nth-child(3) { animation-delay: 0.25s; }
.screen.active .welcome-container > *:nth-child(4) { animation-delay: 0.35s; }
.screen.active .welcome-container > *:nth-child(5) { animation-delay: 0.45s; }

/* ============ RESPONSIVE ============ */
@media (max-width: 380px) {
  .readout-value { font-size: 16px; }
  .readout-primary .readout-value { font-size: 20px; }
  #angle-arc { width: 160px; height: 80px; }
}
@media (min-width: 768px) {
}

/* ============ DATA CAPTURE PANEL ============ */

.capture-panel {
  margin-top: 32px;
  background: #f8f8f8;
  border: 1px solid #e0e0e0;
  border-radius: 16px;
  padding: 20px;
}

.capture-header {
  margin-bottom: 16px;
}

.capture-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.capture-title-row h3 {
  font-family: var(--font-heading);
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--teal);
  margin: 0;
  font-weight: 600;
}

.capture-badge {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--teal);
  background: var(--teal-dim);
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 700;
}

.capture-summary {
  font-size: 12px;
  color: var(--white-dim);
  margin: 0;
  line-height: 1.5;
}

.capture-summary strong {
  color: var(--teal);
}

.capture-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -20px;
  padding: 0 20px;
}

.capture-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 11px;
}

.capture-table th {
  text-align: left;
  color: var(--white-muted);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 8px;
  border-bottom: 1px solid #e0e0e0;
  white-space: nowrap;
}

.capture-table td {
  padding: 7px 8px;
  color: var(--white-dim);
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
}

.capture-table td strong {
  color: var(--teal);
  font-weight: 700;
}

.capture-table tbody tr:last-child td {
  border-bottom: none;
}

.capture-table tbody tr:hover td {
  background: var(--teal-dim);
}

.capture-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn-capture-action {
  flex: 1;
  padding: 10px 16px;
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #ffffff;
  background: var(--teal);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-capture-action:hover {
  opacity: 0.85;
}

.btn-capture-clear {
  padding: 10px 16px;
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 600;
  color: var(--danger);
  background: rgba(229, 62, 62, 0.08);
  border: 1px solid rgba(229, 62, 62, 0.25);
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-capture-clear:hover {
  opacity: 0.85;
}

/* ============ SESSION INDICATOR ============ */

.session-indicator {
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--teal);
  background: rgba(13,148,136,0.15);
  border: 1px solid rgba(13,148,136,0.25);
  padding: 4px 10px;
  border-radius: 12px;
  display: inline-block;
  font-weight: 600;
}

.session-indicator:empty {
  display: none;
}


/* ============ BETWEEN-SIZES ADVISORY ============ */

.between-sizes-advisory {
  background: rgba(13,148,136,0.08);
  border: 1px solid rgba(13,148,136,0.3);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--teal);
}

.between-sizes-advisory strong {
  color: var(--teal);
}
