:root {
  --bg: #08080c;
  --bg-2: #11121a;
  --fg: #f3f4f8;
  --muted: #8a8d9a;
  --accent: #ff3b6b;
  --accent-2: #ff7a9c;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #ef4444;
  --radius: 18px;
  --radius-lg: 28px;
  --shadow: 0 10px 40px rgba(255, 59, 107, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(120% 80% at 50% 0%, #1a0a16 0%, var(--bg) 60%);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  min-height: 100dvh;
}

body {
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  padding: max(env(safe-area-inset-top), 24px) 24px max(env(safe-area-inset-bottom), 24px);
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  gap: 18px;
  animation: fade 220ms ease;
}

.screen[data-active] { display: flex; }

@keyframes fade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

h1 {
  font-size: 40px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 26px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.muted { color: var(--muted); line-height: 1.5; margin: 0; }
.small { font-size: 13px; }

/* ============ LANDING ============ */
.screen--landing {
  justify-content: space-between;
  align-items: center;
  text-align: center;
  padding: 60px 0 20px;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
}

.tagline {
  color: var(--muted);
  margin: 0;
  font-size: 17px;
}

.pulse-orb {
  width: 160px;
  height: 160px;
  position: relative;
  display: grid;
  place-items: center;
}
.pulse-orb::before {
  content: "";
  position: absolute;
  inset: 30%;
  background: radial-gradient(circle, var(--accent) 0%, var(--accent-2) 60%, transparent 100%);
  border-radius: 50%;
  filter: blur(2px);
  box-shadow: var(--shadow);
  animation: heart 1.05s ease-in-out infinite;
}
.pulse-orb span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  opacity: 0;
  animation: ring 2.1s ease-out infinite;
}
.pulse-orb span:nth-child(2) { animation-delay: 0.7s; }
.pulse-orb span:nth-child(3) { animation-delay: 1.4s; }

@keyframes heart {
  0%, 100% { transform: scale(1);    opacity: 0.95; }
  20%      { transform: scale(1.18); opacity: 1;    }
  40%      { transform: scale(0.98); opacity: 0.9;  }
  60%      { transform: scale(1.08); opacity: 1;    }
}
@keyframes ring {
  0%   { transform: scale(0.7); opacity: 0.6; }
  100% { transform: scale(1.4); opacity: 0;   }
}

/* ============ BUTTONS ============ */
.cta {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 18px 28px;
  font-size: 17px;
  font-weight: 600;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: white;
  box-shadow: 0 10px 30px rgba(255, 59, 107, 0.4);
  cursor: pointer;
  width: 100%;
  letter-spacing: 0.01em;
  transition: transform .12s ease, opacity .2s;
}
.cta:active { transform: scale(0.98); }
.cta:disabled {
  background: #2a2b36;
  color: #6e7180;
  box-shadow: none;
  cursor: not-allowed;
}

.ghost {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  padding: 12px;
  cursor: pointer;
  font-weight: 500;
}
.ghost:active { color: var(--fg); }
.ghost.small { font-size: 13px; padding: 6px; }

.legal {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
}

/* ============ CHECK LIST ============ */
.check-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 16px;
}
.check {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
}
.check .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #3a3c4a;
  flex-shrink: 0;
}
.check[data-state="ok"]    .dot { background: var(--good); box-shadow: 0 0 8px var(--good); }
.check[data-state="warn"]  .dot { background: var(--warn); }
.check[data-state="bad"]   .dot { background: var(--bad);  }

/* ============ PLACEMENT ============ */
.placement-viz {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 260px;
}

.preview-wrap {
  position: relative;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid #25262f;
  background: #000;
}
#preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.55);
  color: var(--fg);
  font-size: 14px;
  text-align: center;
  padding: 0 16px;
  transition: opacity 0.3s;
}
.preview-overlay[data-hidden] {
  opacity: 0;
  pointer-events: none;
}

.finger-anim {
  position: absolute;
  width: 80px;
  height: 110px;
  border-radius: 40px 40px 28px 28px;
  background: linear-gradient(180deg, #ffd2bb 0%, #e7a98e 100%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.0;
  pointer-events: none;
  animation: finger-tap 2.4s ease-in-out infinite;
}
@keyframes finger-tap {
  0%, 100% { opacity: 0;   transform: translate(-50%, -10%); }
  50%      { opacity: 0.35; transform: translate(-50%, -50%); }
}

.ios-note {
  background: var(--bg-2);
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
  border: 1px solid #1f2029;
}
.ios-note b { color: var(--fg); }

/* ============ MEASURING ============ */
.bpm-live {
  text-align: center;
  padding: 20px 0 4px;
}
.bpm-number {
  font-size: 80px;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}
.bpm-number small {
  font-size: 18px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.05em;
}
.bpm-sub {
  color: var(--muted);
  font-size: 14px;
  margin-top: 8px;
}
.dot-sep {
  display: inline-block;
  margin: 0 8px;
  opacity: 0.5;
}

#waveform {
  width: 100%;
  height: 160px;
  background: var(--bg-2);
  border-radius: var(--radius);
  display: block;
}

.progress {
  height: 6px;
  background: #1d1e27;
  border-radius: 999px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width .3s linear;
}

/* ============ RESULT ============ */
.result-card {
  background: var(--bg-2);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  border: 1px solid #1f2029;
  margin: 12px 0 4px;
}
.result-label {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 59, 107, 0.15);
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.result-bpm {
  font-size: 96px;
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  font-variant-numeric: tabular-nums;
}
.result-bpm small {
  font-size: 22px;
  color: var(--muted);
  font-weight: 500;
}
.result-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 14px;
}

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

.history {
  background: var(--bg-2);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 14px;
  color: var(--muted);
}
.history summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--fg);
}
.history ul {
  list-style: none;
  padding: 0;
  margin: 12px 0 8px;
  max-height: 200px;
  overflow-y: auto;
}
.history li {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid #1d1e27;
}
.history li:last-child { border-bottom: 0; }
.history li b {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.history .empty {
  text-align: center;
  padding: 12px 0;
  border: 0;
  display: block;
}
