:root {
  --bg: #0d0d12;
  --panel: #16161e;
  --panel-hover: #1e1e28;
  --text: #e8e8ef;
  --dim: #9a9ab0;
  --dim2: #6a6a80;
  --green: #4ade80;
  --yellow: #fbbf24;
  --red: #f87171;
  --accent: #60a5fa;
  --border: rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  height: 100dvh;
}

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.pill {
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--panel);
  font-size: 13px;
  font-weight: 500;
}
.pill.ok { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.pill.err { background: rgba(248, 113, 113, 0.15); color: var(--red); }

.stage {
  display: grid;
  grid-template-columns: 1fr 400px;
  height: 100dvh;
  gap: 0;
}

.video-wrap {
  position: relative;
  background: #000;
  overflow: hidden;
}

#cam {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

#overlay, #heart, #filter-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#filter-canvas {
  transform: scaleX(-1); /* mirror like the video */
  display: none; /* hidden until a filter is actively applied */
}

.filter-bar {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 6px;
  background: rgba(15, 15, 22, 0.72);
  backdrop-filter: blur(12px);
  border-radius: 999px;
  z-index: 5;
  max-width: 92%;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }

.filter-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--dim);
  font-size: 11px;
  font-weight: 500;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
  font-family: inherit;
}
.filter-chip:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}
.filter-chip .emoji {
  font-size: 18px;
  line-height: 1;
}
.filter-chip.active {
  background: rgba(96, 165, 250, 0.2);
  color: var(--accent);
  font-weight: 700;
}

.intensity-wrap {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: rgba(15, 15, 22, 0.72);
  backdrop-filter: blur(12px);
  padding: 10px 16px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--dim);
  z-index: 5;
}
.intensity-wrap label { font-weight: 500; }
#intensity-slider {
  width: 120px;
  accent-color: var(--accent);
}

@media (max-width: 900px) {
  .filter-bar { top: 58px; }
  .filter-chip { padding: 6px 10px; font-size: 10px; }
  .filter-chip .emoji { font-size: 16px; }
  .intensity-wrap { bottom: 14px; right: 14px; padding: 8px 12px; }
  #intensity-slider { width: 90px; }
}

.banner {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
  padding: 10px 22px;
  border-radius: 10px;
  font-size: 14px;
  max-width: 80%;
  text-align: center;
}
.banner.hidden { display: none; }

.panel {
  background: var(--panel);
  padding: 28px 22px 110px;
  overflow-y: auto;
  border-left: 1px solid var(--border);
}

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--dim2);
  margin: 22px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.section-title:first-of-type {
  margin-top: 10px;
}

.section-desc {
  display: block;
  font-size: 11px;
  color: var(--dim);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  margin-top: 4px;
  line-height: 1.4;
}

.metric {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.15s ease;
  cursor: help;
}

.metric:hover {
  background: rgba(255, 255, 255, 0.04);
}

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

.metric .label {
  font-size: 11px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}

.info {
  display: inline-flex;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  background: rgba(96, 165, 250, 0.15);
  color: var(--accent);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  user-select: none;
}

.value-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 2px 0 4px;
}

.metric .value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  color: var(--green);
  line-height: 1;
}

.metric .unit {
  font-size: 13px;
  color: var(--dim);
  font-weight: 400;
}

.metric .desc {
  font-size: 12px;
  color: var(--dim);
  line-height: 1.35;
  margin-top: 4px;
}

.metric.big {
  background: linear-gradient(135deg, rgba(74, 222, 128, 0.08), rgba(96, 165, 250, 0.05));
  border: 1px solid rgba(74, 222, 128, 0.25);
  padding: 18px 18px 14px;
  margin-bottom: 22px;
}

.metric.big .value {
  font-size: 56px;
  line-height: 1;
}

.metric.big .unit {
  font-size: 18px;
}

.metric.big .desc {
  font-size: 13px;
  margin-top: 8px;
}

.help-footer {
  margin-top: 24px;
  padding: 14px;
  background: rgba(96, 165, 250, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--dim);
}

.help-footer strong {
  color: var(--text);
  display: block;
  margin-bottom: 6px;
}

.help-footer ul {
  margin: 0;
  padding-left: 18px;
}

.help-footer li {
  margin-bottom: 3px;
}

.footer {
  position: fixed;
  bottom: 0; left: 0; right: 400px;
  padding: 14px 24px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--dim);
}
#calibration { display: flex; align-items: center; gap: 12px; }
#cal-bar { width: 180px; height: 8px; }

/* Floating tooltip */
.tooltip {
  position: fixed;
  max-width: 320px;
  padding: 10px 14px;
  background: #0a0a10;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 100;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.tooltip.hidden {
  opacity: 0;
  visibility: hidden;
}

@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; grid-template-rows: 50vh 1fr; }
  .panel { border-left: none; border-top: 1px solid var(--border); padding-bottom: 40px; }
  .footer { right: 0; }
  .metric.big .value { font-size: 44px; }
  .tooltip { max-width: 85vw; }
}
