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

:root {
  --teal: #007a6e;
  --teal-bright: #14b8a6;
  --teal-deep: #0a4f48;
  --ink: #0b1c1a;
  --fog: #e7f3f1;
  --paper: #f4faf9;
  --line: rgba(10, 79, 72, 0.14);
  --warn: #e0892a;
  --ok: #2db87a;
  --danger: #d64545;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "Outfit", sans-serif;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(20, 184, 166, 0.22), transparent 55%),
    radial-gradient(900px 600px at 100% 0%, rgba(0, 122, 110, 0.16), transparent 50%),
    linear-gradient(165deg, #f7fcfb 0%, #eef7f5 42%, #e4f0ee 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(0, 122, 110, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 122, 110, 0.04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 80%);
  z-index: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: calc(14px + var(--safe-top)) 22px 14px;
  background: rgba(244, 250, 249, 0.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 0 auto;
}

.brand img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0, 122, 110, 0.18));
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-name {
  font-size: clamp(1.35rem, 2.4vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--teal);
  line-height: 1.05;
}

.brand-sub {
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(11, 28, 26, 0.55);
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1280px, calc(100% - 28px));
  margin: 18px auto 28px;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.9fr);
  gap: 18px;
  padding-bottom: var(--safe-bottom);
}

.hero-panel,
.side-panel {
  border-radius: calc(var(--radius) + 4px);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 10px 30px rgba(10, 79, 72, 0.06);
  overflow: hidden;
}

.hero-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(244, 250, 249, 0.75));
}

.toolbar-left,
.toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(11, 28, 26, 0.5);
}

.field select {
  appearance: none;
  min-width: 140px;
  padding: 10px 36px 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(0, 122, 110, 0.22);
  background:
    linear-gradient(45deg, transparent 50%, var(--teal) 50%) calc(100% - 18px) calc(50% - 3px) / 6px 6px no-repeat,
    linear-gradient(135deg, var(--teal) 50%, transparent 50%) calc(100% - 12px) calc(50% - 3px) / 6px 6px no-repeat,
    #fff;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn,
.secondary-btn {
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  font-family: var(--sans);
  font-weight: 650;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.2s ease;
}

.primary-btn {
  background: linear-gradient(135deg, var(--teal-bright), var(--teal));
  color: #fff;
  box-shadow: 0 8px 18px rgba(0, 122, 110, 0.28);
}

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.primary-btn:not(:disabled):hover,
.secondary-btn:hover {
  transform: translateY(-1px);
}

.secondary-btn {
  background: rgba(0, 122, 110, 0.08);
  color: var(--teal-deep);
  border: 1px solid rgba(0, 122, 110, 0.16);
}

.privacy-chip {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--teal-deep);
  background: rgba(20, 184, 166, 0.12);
  border: 1px solid rgba(0, 122, 110, 0.16);
  border-radius: 999px;
  padding: 6px 10px;
}

#video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background:
    radial-gradient(circle at 50% 40%, rgba(20, 184, 166, 0.18), transparent 45%),
    #071614;
  overflow: hidden;
}

#video-frame.running {
  animation: softPulse 2.4s ease-in-out infinite;
}

canvas.display-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#largeStartBtn {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 168px;
  padding: 14px 28px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--teal-bright), var(--teal));
  color: #fff;
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: 0 14px 34px rgba(0, 122, 110, 0.35);
  transition: transform 0.18s ease, opacity 0.18s ease;
}

#largeStartBtn:hover:not(:disabled) {
  transform: translate(-50%, calc(-50% - 2px));
}

#largeStartBtn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.roi-badge {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 4;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #dffaf5;
  background: rgba(0, 122, 110, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 6px 10px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
  background: linear-gradient(135deg, var(--teal-deep), var(--teal));
}

.metrics.metrics-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  text-align: center;
}

.metric span {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.78);
  font-weight: 600;
}

.metric strong {
  width: 100%;
  min-height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--teal);
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 600;
  transition: color 0.25s ease, transform 0.25s ease;
}

.metric strong.active {
  color: var(--ok);
  transform: scale(1.02);
}

.metric strong.rr {
  color: var(--warn);
}

.metric strong.apnea {
  font-size: 0.78rem;
  color: #667;
}

.submetrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px 12px;
}

.submetric {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}

.submetric span {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(11, 28, 26, 0.48);
  font-weight: 650;
}

.submetric strong {
  width: 100%;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 7px 4px;
  border-radius: 10px;
  background: rgba(0, 122, 110, 0.06);
  border: 1px solid rgba(0, 122, 110, 0.1);
  color: var(--teal-deep);
}

.wave-stack {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}

.wave-row {
  position: relative;
  height: 72px;
  border-top: 1px solid rgba(0, 122, 110, 0.08);
  background: #fff;
}

.wave-row:first-child {
  border-top: none;
}

.wave-row label {
  position: absolute;
  z-index: 2;
  left: 10px;
  top: 8px;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.wave-row.bvp label {
  color: #2b7de9;
}

.wave-row.rsp label {
  color: #2f9e5f;
}

.wave-row canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.7);
}

.panel-title {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(11, 28, 26, 0.5);
}

.layer-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.layer-btn {
  border: 1px solid rgba(0, 122, 110, 0.16);
  background: rgba(244, 250, 249, 0.9);
  border-radius: 10px;
  padding: 8px 0;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.layer-btn.active,
.layer-btn:hover {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.nn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-height: 280px;
}

.grid-cell {
  position: relative;
  min-height: 120px;
  border-radius: 14px;
  overflow: hidden;
  background: #0b1c1a;
  border: 1px solid rgba(0, 122, 110, 0.25);
}

.grid-cell.full {
  grid-column: 1 / -1;
  min-height: 160px;
}

.cell-label {
  position: absolute;
  z-index: 2;
  left: 8px;
  top: 8px;
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--teal);
  border-radius: 6px;
  padding: 3px 7px;
}

.grid-cell canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#psd-frame {
  height: 132px;
  border-radius: 14px;
  overflow: hidden;
  background: #0b1c1a;
  border: 1px solid rgba(0, 122, 110, 0.25);
}

#psd-frame canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.trend-block {
  display: grid;
  grid-template-columns: 34px 1fr 88px;
  gap: 8px;
  align-items: stretch;
  min-height: 120px;
}

.trend-y {
  position: relative;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: rgba(11, 28, 26, 0.45);
}

.trend-y span {
  position: absolute;
  right: 0;
}

.trend-plot {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #0b1c1a;
  border: 1px solid rgba(0, 122, 110, 0.25);
}

.trend-plot strong {
  position: absolute;
  z-index: 2;
  left: 10px;
  top: 8px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: var(--teal-bright);
}

.trend-plot canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#saveBtn {
  width: 100%;
  height: 100%;
  min-height: 120px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(160deg, var(--teal-bright), var(--teal-deep));
  color: #fff;
  font-family: var(--sans);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  box-shadow: 0 10px 24px rgba(0, 122, 110, 0.25);
}

#saveBtn small {
  font-weight: 500;
  opacity: 0.85;
}

.footer-note {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 0.78rem;
  color: rgba(11, 28, 26, 0.48);
  padding: 4px 8px 10px;
}

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

@keyframes softPulse {
  0%,
  100% {
    box-shadow: inset 0 0 0 0 rgba(20, 184, 166, 0);
  }
  50% {
    box-shadow: inset 0 0 0 2px rgba(20, 184, 166, 0.28);
  }
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .brand img {
    width: 52px;
    height: 52px;
  }

  .metrics,
  .metrics.metrics-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .submetrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .trend-block {
    grid-template-columns: 28px 1fr;
  }

  #saveBtn {
    grid-column: 1 / -1;
    min-height: 56px;
    flex-direction: row;
    gap: 8px;
  }
}

@media (max-width: 640px) {
  .site-header {
    padding-left: 14px;
    padding-right: 14px;
  }

  .shell {
    width: calc(100% - 16px);
    margin-top: 12px;
  }

  #video-frame {
    aspect-ratio: 1 / 1;
  }
}
