/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #0a0e1a;
  --card:    #141929;
  --card2:   #1a2035;
  --border:  #1e2d45;
  --cyan:    #00d4ff;
  --purple:  #7c3aed;
  --green:   #10b981;
  --amber:   #f59e0b;
  --red:     #ef4444;
  --text:    #e2e8f0;
  --muted:   #64748b;
  --radius:  12px;
}

html, body { height: 100%; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ─── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Layout ───────────────────────────────────────────────────────────────── */
.app-wrapper {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

/* ─── Header ───────────────────────────────────────────────────────────────── */
.app-header {
  text-align: center;
  padding: 28px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}
.app-title {
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}
.app-subtitle {
  color: var(--muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

/* ─── Step Indicator ───────────────────────────────────────────────────────── */
.step-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 32px;
}
.step-dot {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--card2);
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  transition: all 0.3s;
  flex-shrink: 0;
}
.step-dot.active {
  background: var(--cyan);
  border-color: var(--cyan);
  color: #000;
  box-shadow: 0 0 12px #00d4ff55;
}
.step-dot.done {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.step-connector {
  height: 2px;
  width: 48px;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.3s;
}
.step-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-align: center;
  margin-top: 4px;
}

/* ─── Step Panels ──────────────────────────────────────────────────────────── */
.step-panel {
  display: none;
  animation: fadeIn 0.3s ease;
}
.step-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ─── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--cyan);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .icon { font-size: 1.1rem; }

/* ─── Form ─────────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}
input, select, textarea {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.9rem;
  width: 100%;
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px #00d4ff22;
}
textarea { resize: vertical; min-height: 70px; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 22px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--cyan), #0099bb);
  color: #000;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.15); transform: translateY(-1px); }
.btn-secondary {
  background: var(--card2);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--cyan); color: var(--cyan); }
.btn-danger {
  background: #2d0a0a;
  border: 1px solid var(--red);
  color: var(--red);
}
.btn-danger:hover:not(:disabled) { background: #3d1010; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--purple);
  color: var(--purple);
}
.btn-outline:hover:not(:disabled) { background: rgba(168,85,247,0.1); }
.btn-green {
  background: linear-gradient(135deg, var(--green), #0d9068);
  color: #fff;
}
.btn-green:hover:not(:disabled) { filter: brightness(1.1); }
.btn-purple {
  background: linear-gradient(135deg, var(--purple), #5b21b6);
  color: #fff;
}
.btn-purple:hover:not(:disabled) { filter: brightness(1.1); }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

/* ─── Camera Area ──────────────────────────────────────────────────────────── */
.camera-container {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4/3;
  max-height: 400px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror for front camera */
}
#canvas   { display: none; }
#overlayCanvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  transform: scaleX(-1);
}

/* Signal mini-canvas in recording view */
#signalCanvas {
  width: 100%;
  height: 80px;
  display: block;
  border-radius: 8px;
  background: #0a0e1a;
}

/* ─── Lighting Status ──────────────────────────────────────────────────────── */
.lighting-bar-wrap {
  background: var(--card2);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
  margin-top: 6px;
}
#lightingBar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s, background 0.3s;
  width: 50%;
  background: var(--green);
}
.lighting-status {
  font-size: 0.85rem;
  margin-top: 6px;
}
.lighting-status.good  { color: var(--green); }
.lighting-status.warn  { color: var(--amber); }
.lighting-status.bad   { color: var(--red); }

/* ─── Recording Panel ──────────────────────────────────────────────────────── */
.rec-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.rec-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.2} }
.rec-countdown {
  font-size: 2rem;
  font-weight: 700;
  font-family: monospace;
  color: var(--cyan);
}
.progress-bar-wrap {
  background: var(--card2);
  border-radius: 6px;
  height: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-bar {
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--cyan), var(--purple));
  width: 0%;
  transition: width 0.2s;
}
.live-beat {
  color: var(--amber);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 8px;
}

/* ─── Live Vitals Panel (moving window during recording) ─────────────────── */
#liveVitalsPanel {
  background: rgba(0, 212, 255, 0.04);
  border: 1px solid rgba(0, 212, 255, 0.13);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0;
}
.live-panel-title {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.live-metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
@media (max-width: 500px) {
  .live-metrics-grid { grid-template-columns: repeat(3, 1fr); }
}
.live-metric-cell {
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  padding: 7px 4px;
  text-align: center;
}
.live-metric-val {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--cyan);
  font-family: 'SF Mono', 'Fira Code', monospace;
  min-height: 1.4em;
  transition: color 0.5s;
}
.live-metric-lbl {
  font-size: 0.62rem;
  color: var(--muted);
  margin-top: 2px;
}
.live-val-flash {
  color: #10b981 !important;
}

/* ─── Processing Panel ─────────────────────────────────────────────────────── */
.processing-wrap {
  text-align: center;
  padding: 40px 20px;
}
.processing-spinner {
  width: 60px; height: 60px;
  border: 3px solid var(--border);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.processing-status {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 12px;
}
.process-progress-wrap {
  width: 60%;
  margin: 16px auto 0;
  background: var(--card2);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
}
#processProgress {
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--purple));
  width: 0%;
  transition: width 0.3s;
  border-radius: 4px;
}

/* ─── Results ──────────────────────────────────────────────────────────────── */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}
.results-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--cyan);
}
.results-time {
  font-size: 0.8rem;
  color: var(--muted);
}

/* Metric grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric-card {
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.metric-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}
.metric-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: monospace;
}
.metric-value.good { color: var(--green); }
.metric-value.warn { color: var(--amber); }
.metric-interp {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Stress bar */
.stress-section { margin-bottom: 4px; }
.stress-bar-wrap {
  background: var(--card2);
  border-radius: 6px;
  height: 8px;
  overflow: hidden;
  margin: 8px 0;
}
#stressBar {
  height: 100%;
  border-radius: 6px;
  transition: width 0.5s;
}
.stress-score { font-size: 1.4rem; font-weight: 700; font-family: monospace; }
.stress-label { font-size: 0.85rem; color: var(--muted); }

/* Charts */
.chart-wrap {
  background: #0d1117;
  border-radius: 8px;
  overflow: hidden;
  margin-top: 12px;
}
.chart-wrap canvas {
  width: 100% !important;
  height: 120px !important;
  display: block;
}
.chart-title {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 8px 12px 4px;
}

/* Experimental section */
.exp-badge {
  font-size: 0.7rem;
  background: #3d1f7a33;
  color: var(--purple);
  border: 1px solid var(--purple);
  padding: 2px 7px;
  border-radius: 99px;
  margin-left: 8px;
}
.exp-note {
  font-size: 0.72rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 3px;
}

/* Alert box */
#alertBox {
  display: none;
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #2d1515;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 999;
  max-width: 80%;
  text-align: center;
}

/* ─── Dividers & Section headers ───────────────────────────────────────────── */
.section-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 20px 0 10px;
  padding-left: 2px;
}
hr.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

/* ─── Disclaimer banner ─────────────────────────────────────────────────────── */
.disclaimer {
  background: #1a1a00;
  border: 1px solid #555500;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.78rem;
  color: #aaa070;
  margin-top: 16px;
  line-height: 1.6;
}

/* ─── Range input ──────────────────────────────────────────────────────────── */
input[type=range] {
  -webkit-appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  padding: 0;
  border: none;
  background: linear-gradient(to right, var(--cyan), var(--border));
  cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--cyan);
  border: 2px solid #000;
  cursor: pointer;
}
.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}
.range-row label { width: 60px; flex-shrink: 0; }
.range-row input[type=range] { flex: 1; }
#recDurationVal { width: 36px; text-align: right; color: var(--cyan); font-weight: 600; }

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .app-title { font-size: 1.4rem; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .btn-row { flex-direction: column; }
  .btn { justify-content: center; }
  .step-connector { width: 24px; }
}

@media (max-width: 400px) {
  .form-grid { grid-template-columns: 1fr; }
  .step-connector { width: 12px; }
}

/* ─── Tag for face alignment tip ───────────────────────────────────────────── */
.align-tip {
  background: #001a2a;
  border: 1px solid #005577;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.82rem;
  color: #60a8c8;
  margin-top: 10px;
  line-height: 1.6;
}
