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

/* Original reference layout; the ChatPPG skin below supplies its current
   colors and typography. The library itself does not inject UI styles. */
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); }

/* ChatPPG skin on the original four-screen HRV Spot Check reference flow. */
@font-face { font-family: "DM Sans"; src: url("fonts/dm-sans-latin.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
:root { --paper: #f7f9fc; --ink: #111827; --muted: #52627c; --line: #dce3ee; --accent: #2855ff; }
html, body { height: auto; background: var(--paper) !important; color: var(--ink) !important; font-family: "DM Sans", sans-serif; line-height: 1.5; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.screen { padding-top: calc(env(safe-area-inset-top) + 48px); gap: 24px; }
.content { min-width: 0; }
h1, .screen-title { width: 100%; margin: 0; font-size: clamp(32px, 7vw, 46px); line-height: 1.1; letter-spacing: -.045em; color: var(--ink); text-align: left; }
h2, h3, .report-content h3 { color: var(--ink); }
.lead { font-size: 17px; color: var(--muted); line-height: 1.55; }
.disclaimer, .state-line, .session-countdown, .rmssd-floor, .floor, .report-note, .report-footer, .ans-line, .bar-label, .psd-legend, .poincare-legend { color: var(--muted); font-size: 14px; line-height: 1.5; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-primary, .btn-secondary { min-height: 52px; padding: 12px 16px; border-radius: 12px; }
.btn-primary:hover:not(:disabled) { background: #1645ed; }
.btn-secondary:hover { background: #edf2ff; }
.btn-primary:disabled { opacity: 1; background: #dbe4f8; color: #52627c; }
#screen-ready .content { align-items: flex-start; justify-content: flex-start; text-align: left; gap: 22px; }
#screen-ready .ready-eyebrow { color: var(--accent); font-size: 14px; letter-spacing: .05em; }
#screen-ready .ready-step { border-color: var(--line); padding: 18px 0; }
#screen-ready .ready-step-num { color: var(--accent); background: #e7edff; font-size: 14px; }
#screen-ready .ready-step-text { color: var(--muted); font-size: 16px; }
#screen-ready .ready-step-text strong { color: var(--ink); font-size: 16px; }
#screen-ready .disclaimer { margin-top: auto; }
.torch-note { color: #8b5417; background: #fff5df; padding: 12px; border-radius: 8px; }
.camera-preview-wrap { flex-shrink: 0; }
.measuring-content { justify-content: flex-start; gap: 18px; }
.measuring-content .screen-title { margin-bottom: 14px; }
.hr-value { font-size: clamp(80px, 22vw, 112px); letter-spacing: -.06em; }
.hr-unit, .sm-label, .sm-unit { color: var(--muted); }
.sm-label, .sm-unit { font-size: 14px; }
.sm-value { font-size: 25px; }
.sm-value-small { font-size: 18px; }
.secondary-row { width: 100%; gap: 16px; justify-content: space-around; }
.secondary-metric { min-width: 0; }
.quality-pill { background: #edf2ff; font-size: 14px; max-width: 100%; }
.quality-pill.good .quality-dot { background: #12827a; }
.wave-canvas { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.tacho-canvas { background: #fff; border-radius: 8px; padding: 8px; }
.report-screen { height: auto; min-height: 100dvh; overflow: visible; padding: 56px 16px 24px; }
.report-content { width: 100%; max-width: 720px; padding-bottom: 0; }
.report-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-bottom: 16px; }
.report-title { font-size: clamp(28px, 5.8vw, 42px); padding-right: 18px; }
.report-content .report-title { margin: 0 0 20px; }
.report-header .meta-row { font-size: 14px; color: var(--muted); gap: 8px 16px; margin-top: 8px; }
.report-header .meta-row span b { color: var(--ink); }
.report-content h3 { font-size: 18px; }
.experimental { color: #8b5417; border-color: #d9ba8e; font-size: 12px; padding: 2px 6px; }
.bipolar-bar { background: #edf1f7; height: 34px; margin-top: 30px; }
.bipolar-bar .zero-line { background: #a8b4c8; }
.bipolar-bar .fill.pns { background: #278b86; }
.bipolar-bar .fill.sns { background: #bc7737; }
.bipolar-bar .bar-value-label.pns, .bipolar-bar .bar-value-label.sns { color: var(--ink); font-size: 14px; top: -4px; }
.bipolar-ticks { height: 24px; }
.bipolar-ticks span, .zero-mean-label { color: var(--muted); font-size: 14px; }
.bipolar-mean { height: 24px; }
.hrv-table { font-size: 15px; table-layout: fixed; }
.hrv-table td { padding: 10px 0; border-color: var(--line); vertical-align: top; }
.hrv-table td:first-child { color: var(--muted); width: 52%; padding-right: 12px; }
.hrv-table td:last-child { color: var(--ink); white-space: normal; overflow-wrap: anywhere; }
.floor { display: block; font-weight: 400; }
.report-canvas-wrap { width: 100%; min-width: 0; }
.report-canvas-wrap canvas { background: #fff; border-radius: 0; height: 248px; }
#poincare-canvas { max-width: 420px; margin-inline: auto; }
.psd-legend { gap: 8px 14px; }
.psd-legend .lf::before { background: #bc7737; }
.psd-legend .hf::before { background: #278b86; }
.insufficient { color: #80501f; background: #fff4e3; font-size: 15px; }
.ans-methods { margin-top: 12px; }
.ans-methods summary { cursor: pointer; color: var(--accent); min-height: 44px; padding: 10px 0; }
.summary-actions { max-width: 720px; margin: 20px auto 0; flex-direction: row; }
.summary-actions button { flex: 1; }
.debug-menu-trigger { width: 44px; height: 44px; background: #fff; border: 1px solid var(--line); color: var(--muted); }
.debug-sheet { background: #fff; max-height: calc(100dvh - 24px); overflow: auto; border: 1px solid var(--line); }
.debug-sheet-handle { background: #a8b4c8; }
.debug-toggle-row { color: var(--ink); font-size: 16px; min-height: 44px; }
.debug-toggle-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.debug-live-stats { max-width: calc(100vw - 24px); font-size: 14px; white-space: pre-wrap; }
.project-attribution { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 24px; padding: 12px 24px 24px; font-size: 14px; }
.project-attribution a { color: var(--muted); }
@media (min-width: 480px) { .screen:not(.report-screen) { max-width: 560px; } }
@media (max-width: 600px) {
  .screen { padding-bottom: calc(106px + env(safe-area-inset-bottom)); }
  .screen > .btn-primary, .screen > .btn-secondary, .summary-actions { position: fixed; z-index: 40; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); width: auto; margin: 0; }
  .summary-actions { background: rgba(255,255,255,.96); padding: 8px; gap: 8px; border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 6px 24px #172b4d14; }
  .summary-actions button { padding: 10px; font-size: 15px; }
  .report-card { padding: 16px; }
}
@media print {
  @page { margin: 12mm; }
  .project-attribution, .debug-menu-trigger, .debug-sheet { display: none !important; }
  .report-screen { padding: 0; width: 170mm; max-width: none; margin-inline: auto; }
  #poincare-canvas { width: 100mm; max-width: none; }
  .report-canvas-wrap { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .report-card { break-inside: avoid; padding: 20px; }
}
