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

/* !important here because the ppg-monitor.min.js bundle injects its own
   `body { background:#f3f3f3 }` stylesheet at runtime (it bundles the
   library's built-in-UI CSS even in headless mode) - that <style> lands
   after this <link> in the DOM and wins the cascade at equal specificity
   otherwise. See README.md gotcha list. */
html, body {
  height: 100%;
  background: #0b0d12 !important;
  color: #f2f4f7 !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px);
  gap: 24px;
}

/* `.screen{display:flex}` and the UA `[hidden]{display:none}` rule have equal
   specificity (0,1,0); this author rule comes later in the cascade and would
   otherwise win, defeating `hidden` and stacking every screen on top of each
   other. */
.screen[hidden] {
  display: none;
}

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
}

h1 {
  font-size: 34px;
  font-weight: 700;
}

h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.lead {
  font-size: 17px;
  color: #c3c9d4;
  max-width: 32em;
}

.disclaimer {
  font-size: 13px;
  color: #8a90a0;
  max-width: 30em;
}

.btn-primary, .btn-secondary {
  display: block;
  width: 100%;
  min-height: 52px;
  border: none;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: #4fd1c5;
  color: #06231f;
}

.btn-secondary {
  background: #1c2028;
  color: #f2f4f7;
  border: 1px solid #2c313c;
}

.btn-bordered {
  border: 1px solid #5a6272;
}

/* Placement screen */
.finger-illustration { opacity: 0.95; }

#settle-ring {
  transition: stroke-dashoffset 0.3s linear;
}

.coach-line {
  font-size: 19px;
  font-weight: 600;
  min-height: 2.6em;
}

.countdown {
  font-size: 15px;
  color: #a7adba; /* >=4.5:1 vs #0b0d12 background */
  font-variant-numeric: tabular-nums;
}

.torch-note {
  font-size: 14px;
  color: #f5c76e;
  max-width: 30em;
  line-height: 1.4;
}

/* Measuring screen */
.measuring-content { gap: 12px; }

.hr-hero {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.hr-value {
  font-size: 96px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.hr-unit {
  font-size: 20px;
  color: #8a90a0;
}

.quality-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  background: #1c2028;
  font-size: 14px;
  min-height: 32px;
}

.quality-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #6b7280;
  flex-shrink: 0;
}

.quality-pill.good .quality-dot { background: #4fd1c5; }
.quality-pill.bad .quality-dot { background: #6b7280; }

.secondary-row {
  display: flex;
  gap: 32px;
  margin-top: 8px;
}

.secondary-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sm-label {
  font-size: 12px;
  color: #8a90a0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sm-value {
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.sm-unit {
  font-size: 11px;
  color: #8a90a0;
}

.wave-canvas, .tacho-canvas {
  width: 100%;
  max-width: 480px;
  height: auto;
  margin-top: 16px;
}

.tacho-canvas { margin-top: 4px; opacity: 0.8; }

/* Summary screen */
.summary-rows {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.summary-row {
  display: grid;
  grid-template-columns: 1fr repeat(3, auto);
  gap: 8px;
  align-items: baseline;
  padding: 12px 16px;
  background: #14171d;
  border-radius: 12px;
  font-variant-numeric: tabular-nums;
}

.summary-row .label {
  font-size: 14px;
  color: #c3c9d4;
  grid-column: 1 / -1;
  font-variant-numeric: initial;
  margin-bottom: 2px;
}

.summary-row .stat { font-size: 16px; text-align: right; white-space: nowrap; }
.summary-row .stat small { display: block; font-size: 10px; color: #a7adba; }

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.video-container { display: none; }

/* ------------------------------------------------------------- HRV report */
.report-screen {
  display: block;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  padding: calc(env(safe-area-inset-top) + 20px) 20px 0;
}

.report-content {
  display: block;
  text-align: left;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 24px;
}

@media (min-width: 900px) {
  .report-content { max-width: 720px; }
  .report-card { padding: 20px 24px; }
}

.report-content h2 { margin: 0 0 4px; }
.report-content h3 { font-size: 16px; margin: 28px 0 10px; color: #f2f4f7; }

.report-card {
  background: #14171d;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.report-header .meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 13px;
  color: #c3c9d4;
}

.report-header .meta-row span b { color: #f2f4f7; font-variant-numeric: tabular-nums; }

.ans-line {
  font-size: 13px;
  color: #c3c9d4;
  margin-top: 10px;
  line-height: 1.4;
}

.bipolar-bar {
  position: relative;
  height: 28px;
  background: #1c2028;
  border-radius: 6px;
  margin: 8px 0 2px;
}

.bipolar-bar .zero-line {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: #454b58;
}

.bipolar-mean {
  position: relative;
  height: 12px;
  margin-bottom: 4px;
}

.zero-mean-label {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 9px;
  color: #5a6272;
  white-space: nowrap;
}

.bipolar-bar .fill {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-radius: 4px;
}

.bipolar-bar .fill.pns { background: #4fd1c5; }
.bipolar-bar .fill.sns { background: #f5a06e; }

.bipolar-bar .bar-value-label {
  position: absolute;
  top: 50%;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.bipolar-bar .bar-value-label.pns { color: #4fd1c5; }
.bipolar-bar .bar-value-label.sns { color: #f5a06e; }

.bipolar-ticks {
  position: relative;
  height: 14px;
  margin-bottom: 2px;
}
.bipolar-ticks span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 10px;
  color: #a7adba;
  font-variant-numeric: tabular-nums;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #a7adba;
}

.hrv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.hrv-table td { padding: 6px 4px; border-bottom: 1px solid #1f232c; }
.hrv-table td:first-child { color: #c3c9d4; }
.hrv-table td:last-child { text-align: right; font-weight: 600; white-space: nowrap; }

.report-canvas-wrap { margin: 10px 0; }
.report-canvas-wrap canvas { width: 100%; height: auto; display: block; background: #0e1015; border-radius: 8px; }

.psd-legend, .poincare-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 11px;
  color: #a7adba;
  margin-top: 6px;
}
.psd-legend span::before, .poincare-legend span::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: middle;
}
.psd-legend .vlf::before { background: #6b7280; }
.psd-legend .lf::before { background: #f5a06e; }
.psd-legend .hf::before { background: #4fd1c5; }

.report-note {
  font-size: 12px;
  color: #a7adba;
  line-height: 1.5;
}

.report-footer {
  font-size: 11px;
  color: #8a90a0;
  line-height: 1.6;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid #1f232c;
}

.insufficient {
  font-size: 13px;
  color: #f5c76e;
  background: #1c1a12;
  border-radius: 8px;
  padding: 10px 12px;
}

@media print {
  .no-print { display: none !important; }
  html, body { background: #ffffff !important; color: #10131a !important; }
  .report-screen { height: auto; overflow: visible; padding: 0; }
  .report-card { background: #f4f5f7; }
  .report-canvas-wrap canvas { background: #ffffff; border: 1px solid #ddd; }
  .ans-line, .report-note, .report-footer, .hrv-table td:first-child,
  .bar-label, .psd-legend, .poincare-legend { color: #333 !important; }
}

@media (prefers-reduced-motion: reduce) {
  #settle-ring { transition: none; }
}

@media (min-width: 480px) {
  .screen:not(.report-screen) { max-width: 480px; margin: 0 auto; }
}

.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
#desktop-note { margin-top: 12px; }

.camera-preview-wrap { position: relative; width: 180px; height: 180px; margin: 0 auto 20px; }
#camera-preview { position: absolute; inset: 6px; border-radius: 50%; overflow: hidden; background: #0d0f14; }
#camera-preview video { width: 100%; height: 100%; object-fit: cover; display: block; }
.settle-ring-svg { position: absolute; inset: 0; width: 100%; height: 100%; }

/* Debug menu: '...' trigger on every screen + bottom sheet */
.debug-menu-trigger {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  right: 12px;
  z-index: 50;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.08);
  color: #a7adba;
  font-size: 20px;
  line-height: 1;
}
.debug-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 60;
}
.debug-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 61;
  background: #14161d;
  border-radius: 16px 16px 0 0;
  padding: 8px 20px calc(env(safe-area-inset-bottom) + 20px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.debug-sheet-handle {
  width: 36px; height: 4px;
  background: #3a3f4a;
  border-radius: 2px;
  margin: 8px auto 4px;
}
.debug-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #c3c9d4;
  padding: 6px 0;
}
.debug-live-stats {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 48px);
  right: 12px;
  z-index: 55;
  background: rgba(0,0,0,0.7);
  color: #4fd1c5;
  font-size: 10px;
  line-height: 1.4;
  padding: 6px 8px;
  border-radius: 6px;
  white-space: pre;
  max-width: 220px;
}
.state-line { font-size: 12px; color: #6b7280; margin-top: -8px; }
.wave-canvas-small { height: 40px; opacity: 0.8; }
.session-countdown { font-variant-numeric: tabular-nums; font-size: 15px; color: #a7adba; margin: -8px 0 4px; }


.debug-sheet[hidden], .debug-sheet-backdrop[hidden] { display: none; }

/* Ready screen (home) */
/* Scoped to #screen-ready only — uses existing app.css tokens (#4fd1c5 teal,
   #8a90a0/#c3c9d4 muted text, #2c313c hairline) so this pastes verbatim into
   index.html without touching app.css. */

#screen-ready .ready-eyebrow {
  font-size: 13px;
  font-weight: 600;
  color: #4fd1c5;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0;
}

#screen-ready .ready-steps {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  width: 100%;
  max-width: 32em;
  text-align: left;
}

#screen-ready .ready-step {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 0;
  border-top: 1px solid #2c313c;
}

#screen-ready .ready-step:first-child {
  border-top: none;
}

#screen-ready .ready-step-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #1c2028;
  color: #4fd1c5;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
}

#screen-ready .ready-step-text {
  font-size: 15px;
  line-height: 1.45;
  color: #c3c9d4;
}

#screen-ready .ready-step-text strong {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: #f2f4f7;
  margin-bottom: 2px;
}


/* --- added with the v0.3 report: measurement floor, breathing, experimental tag --- */
.rmssd-floor { margin: 2px 0 0; font-size: 12px; color: #a7adba; text-align: center; min-height: 1em; }
.sm-value-small { font-size: 0.8em; }
.floor { color: #a7adba; font-size: 0.85em; }
.experimental { display: inline-block; margin-left: 8px; padding: 1px 6px; border-radius: 3px; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; vertical-align: middle; color: #f5a06e; border: 1px solid rgba(245,160,110,.5); }
