:root {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #161f36;
  --line: #263045;
  --text: #e6ebf5;
  --muted: #93a1bd;
  --accent: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

header h1 {
  font-size: 1.25rem;
  margin: 0;
}

header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.video-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.video-wrap video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror, like a selfie camera */
}

.video-wrap canvas.overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: scaleX(-1);
  pointer-events: none;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 0.95rem;
}

.status-banner {
  position: absolute;
  left: 0; right: 0; top: 0;
  padding: 8px 12px;
  background: rgba(0,0,0,0.55);
  font-size: 0.85rem;
  color: #fff;
  text-align: center;
}
.status-banner[data-kind="warn"] { color: var(--warn); }
.status-banner[data-kind="danger"] { color: var(--danger); }
.status-banner.hidden { display: none; }

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.95rem;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 120px;
}
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: #06281d; border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.hidden { display: none; }

.vitals-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}

.tile .value {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tile .label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

.waveform {
  width: 100%;
  height: 70px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

footer {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

@media (max-width: 420px) {
  .vitals-grid { grid-template-columns: 1fr 1fr; }
  .vitals-grid .tile:last-child { grid-column: span 2; }
  header h1 { font-size: 1.1rem; }
}
