@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Outfit:wght@400;500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #0a0a12;
  --surface: #121220;
  --card: rgba(26, 26, 40, 0.85);
  --red: #ff2d55;
  --red-bright: #ff5277;
  --red-dim: rgba(255, 45, 85, 0.15);
  --red-glow: rgba(255, 45, 85, 0.4);
  --green: #00ff88;
  --green-dim: rgba(0, 255, 136, 0.1);
  --text: #f0f0f8;
  --muted: #8a8aa8;
  --border: rgba(255, 255, 255, 0.08);
  --glass: rgba(255, 255, 255, 0.03);
  --glass-border: rgba(255, 255, 255, 0.08);
  --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --blue: #4da6ff;
  --blue-dim: rgba(77, 166, 255, 0.1);
  --blue-glow: rgba(77, 166, 255, 0.4);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg);
  background-image:
    radial-gradient(circle at 50% 0%, rgba(255, 45, 85, 0.08) 0%, transparent 50%),
    radial-gradient(circle at 0% 100%, rgba(0, 255, 136, 0.05) 0%, transparent 40%);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding-bottom: 60px;
  line-height: 1.6;
}

.header {
  width: 100%;
  padding: 32px 24px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.logo {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  text-transform: none;
  font-family: 'Outfit', sans-serif;
  background: linear-gradient(135deg, #fff 60%, var(--red) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 5px rgba(255, 45, 85, 0.3));
}

.logo span {
  color: var(--red)
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transition: background .3s, box-shadow .3s
}

.status-dot.active {
  background: var(--green);
  box-shadow: 0 0 12px var(--green);
  animation: pulse-dot 1s ease-in-out infinite
}

@keyframes pulse-dot {

  0%,
  100% {
    opacity: 1
  }

  50% {
    opacity: .4
  }
}

.bpm-section {
  width: 100%;
  max-width: 400px;
  padding: 10px 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center
}

.bpm-ring {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 10px 0
}

.bpm-ring svg {
  position: absolute;
  top: 0;
  left: 0;
  transform: rotate(-90deg)
}

.ring-bg {
  fill: none;
  stroke: var(--card);
  stroke-width: 6
}

.ring-fill {
  fill: none;
  stroke: var(--red);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 565;
  stroke-dashoffset: 565;
  transition: stroke-dashoffset .5s ease, stroke .5s;
  filter: drop-shadow(0 0 8px var(--red-glow))
}

.bpm-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center
}

.bpm-value {
  font-family: 'Space Mono', monospace;
  font-size: 64px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  transition: color .3s
}

.bpm-unit {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--muted);
  text-transform: uppercase;
  margin-top: 4px
}

.heartbeat-icon {
  font-size: 28px;
  color: var(--red);
  opacity: .6
}

.heartbeat-icon.beat {
  animation: heartbeat .3s ease-out;
  opacity: 1
}

@keyframes heartbeat {
  0% {
    transform: scale(1)
  }

  30% {
    transform: scale(1.4)
  }

  60% {
    transform: scale(.95)
  }

  100% {
    transform: scale(1)
  }
}

.zone-badge {
  margin-top: 6px;
  padding: 5px 16px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  background: var(--card);
  color: var(--muted);
  border: 1px solid var(--border);
  transition: all .4s
}

.wave-card {
  width: calc(100% - 40px);
  max-width: 400px;
  margin: 14px 0 0;
  background: var(--card);
  border-radius: 16px;
  border: 1px solid var(--border);
  overflow: hidden;
  padding: 14px
}

.wave-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 10px
}

canvas#waveCanvas {
  width: 100%;
  height: 80px;
  display: block;
  border-radius: 8px
}

.stats-row {
  width: calc(100% - 40px);
  max-width: 400px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px
}

.stat-card {
  background: var(--card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  transition: transform 0.3s ease, border-color 0.3s ease;
}

.stat-card:active {
  transform: scale(0.98);
}

.stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 6px
}

.stat-value {
  font-family: 'Space Mono', monospace;
  font-size: 26px;
  font-weight: 700;
  color: var(--text)
}

.stat-value small {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400
}

/* Confidence bar */
.conf-bar-wrap {
  margin-top: 6px;
  height: 3px;
  background: rgba(255, 255, 255, .07);
  border-radius: 2px;
  overflow: hidden
}

.conf-bar {
  height: 100%;
  border-radius: 2px;
  transition: width .5s, background .5s;
  width: 0%
}

#videoEl {
  position: fixed;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px
}

canvas#captureCanvas {
  display: none
}

.btn-wrap {
  width: calc(100% - 40px);
  max-width: 400px;
  margin-top: 16px
}

.btn-main {
  width: 100%;
  padding: 18px;
  border-radius: 20px;
  border: none;
  font-family: 'Outfit', sans-serif;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.5px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--red) 0%, #ff4d79 100%);
  color: #fff;
  box-shadow: 0 4px 15px rgba(255, 45, 85, 0.3);
  text-transform: none;
  transition: all .3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.btn-main:active {
  transform: scale(0.96);
  box-shadow: 0 2px 8px rgba(255, 45, 85, 0.2);
}

.btn-main.stop {
  background: #1a1a28;
  border: 1px solid var(--red);
  color: var(--red);
  box-shadow: none;
}

.instructions {
  width: calc(100% - 40px);
  max-width: 400px;
  margin-top: 12px;
  padding: 14px;
  background: rgba(255, 45, 85, .05);
  border: 1px solid rgba(255, 45, 85, .15);
  border-radius: 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  display: none
}

.instructions.visible {
  display: block
}

.instructions strong {
  color: var(--text)
}

.progress-wrap {
  width: calc(100% - 40px);
  max-width: 400px;
  margin-top: 12px;
  display: none
}

.progress-wrap.visible {
  display: block
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 700;
  letter-spacing: 1px
}

.progress-bar {
  height: 4px;
  background: var(--card);
  border-radius: 2px;
  overflow: hidden
}

.progress-fill {
  height: 100%;
  background: var(--red);
  border-radius: 2px;
  width: 0%;
  transition: width .3s;
  box-shadow: 0 0 8px var(--red-glow)
}

.noise-warn {
  font-size: 11px;
  color: #ffb800;
  text-align: center;
  margin-top: 6px;
  display: none;
  letter-spacing: .5px
}

.noise-warn.visible {
  display: block
}

/* ── AI ANALYSIS PANEL ── */
.ai-panel {
  width: calc(100% - 40px);
  max-width: 400px;
  margin-top: 24px;
  background: linear-gradient(135deg, rgba(26, 26, 40, 0.9) 0%, rgba(20, 20, 30, 0.95) 100%);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 45, 85, 0.3);
  border-radius: 20px;
  overflow: hidden;
  display: none;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4), 0 0 20px rgba(255, 45, 85, 0.1);
  animation: panelAppear 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes panelAppear {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-panel.visible {
  display: block
}

.ai-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px
}

.ai-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--red);
  animation: pulse-dot 1.2s ease-in-out infinite
}

.ai-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--muted);
  text-transform: uppercase
}

.ai-body {
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
  min-height: 60px
}

.ai-body .ai-loading {
  color: var(--muted);
  font-style: italic
}

.ai-body p {
  margin-bottom: 8px
}

.ai-body p:last-child {
  margin-bottom: 0
}

.ai-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-right: 4px;
  margin-bottom: 4px
}

.ai-disclaimer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--muted);
  line-height: 1.5
}

/* History */
.history-section {
  width: calc(100% - 40px);
  max-width: 400px;
  margin-top: 24px
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px
}

.history-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2.5px;
  color: var(--muted);
  text-transform: uppercase;
  margin: 0
}

.btn-export {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  transition: all .2s;
  display: none
}

.btn-export:hover {
  color: var(--text);
  border-color: var(--muted)
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px
}

.history-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'Space Mono', monospace;
  font-size: 14px;
  animation: slideIn .3s ease
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px)
  }

  to {
    opacity: 1;
    transform: translateY(0)
  }
}

.history-item .h-bpm {
  font-weight: 700;
  color: var(--red);
}

.history-item .h-time {
  font-size: 11px;
  color: var(--muted);
}

.history-item .h-zone {
  font-size: 10px;
  color: var(--muted);
}

/* --- SIDE NAV (TOP RIGHT VERTICAL) --- */
.side-nav {
  position: fixed !important;
  top: 110px !important;
  right: 20px !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 12px;
  z-index: 9999 !important;
}

.nav-btn {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  border: 1px solid var(--glass-border);
  background: var(--card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--muted);
  cursor: pointer;
  transition: all .3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
}

.nav-btn.active {
  border-color: var(--red) !important;
  color: var(--red) !important;
  background: var(--red-dim) !important;
  box-shadow: 0 0 20px var(--red-glow) !important;
  transform: scale(1.1);
}

.nav-btn.active.blue {
  border-color: var(--blue) !important;
  color: var(--blue) !important;
  background: var(--blue-dim) !important;
  box-shadow: 0 0 20px var(--blue-glow) !important;
}

.nav-btn:active {
  transform: scale(0.9);
}

/* --- MODULES --- */
.view-module {
  width: 100%;
  padding-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadeIn .4s ease-out;
}

.view-module.hidden {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- METABOLIC SECTION --- */
.meta-card {
  width: calc(100% - 40px);
  max-width: 400px;
  margin: 16px 0;
  background: var(--card);
  border-radius: 20px;
  border: 1px solid var(--border);
  padding: 20px;
}

.meta-title {
  font-size: 18px;
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--blue);
  display: flex;
  align-items: center;
  gap: 8px;
}

.symptom-tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.symptom-tag {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 30px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: all .2s;
}

.symptom-tag.selected {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue);
  box-shadow: 0 0 10px var(--blue-glow);
}

.photo-upload-area {
  width: 100%;
  height: 120px;
  border: 2px dashed var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.01);
  transition: all .3s;
}

.photo-upload-area:hover {
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--blue);
}

.photo-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 14px;
  display: none;
}

.btn-blue {
  width: 100%;
  padding: 16px;
  border-radius: 16px;
  border: none;
  background: linear-gradient(135deg, var(--blue) 0%, #00d2ff 100%);
  color: #fff;
  font-family: 'Outfit', sans-serif;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 20px;
  box-shadow: 0 4px 15px rgba(77, 166, 255, 0.3);
}

.btn-blue:active {
  transform: scale(0.98);
}