* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --accent: #ffc94d;
  --glass: rgba(16, 18, 24, 0.62);
  --hairline: rgba(255, 255, 255, 0.14);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  color: #fff;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#safeProbe { position: fixed; top: 0; height: var(--sat); width: 0; visibility: hidden; }

#video { position: fixed; inset: 0; width: 100vw; height: 100vh; object-fit: cover; }

/* desktop preview (?demo=1): sky stand-in for the camera feed */
body.demo #video { display: none; }
body.demo {
  background: linear-gradient(180deg, #3d6491 0%, #6f93b4 45%, #a8bcc7 62%, #8fa3a8 70%, #5c6e63 100%);
}
#canvas { position: fixed; inset: 0; touch-action: none; }

.hidden { display: none !important; }

/* ---------- Start screen ---------- */

#start {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 60% at 50% 108%, rgba(255, 201, 77, 0.13), transparent 60%),
    linear-gradient(180deg, #07090f 0%, #0b101c 55%, #101728 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 10;
  opacity: 1;
  transition: opacity 0.6s ease;
}
#start.fadeOut { opacity: 0; pointer-events: none; }

#start .ridge {
  position: absolute;
  inset: auto 0 0 0;
  height: 38vh;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,0.5));
  clip-path: polygon(0 78%, 9% 58%, 18% 70%, 30% 38%, 41% 60%, 52% 30%, 64% 56%, 75% 42%, 86% 64%, 100% 50%, 100% 100%, 0 100%);
}

.startInner { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 36px; z-index: 1; }

#start h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0.42em;
  margin-left: 0.42em; /* visually recenters letterspaced text */
}

#start .tagline { color: #8e98a8; font-size: 15px; line-height: 1.55; font-weight: 400; }

#startBtn {
  margin-top: 18px;
  font-size: 17px;
  font-weight: 600;
  padding: 15px 58px;
  border: none;
  border-radius: 100px;
  background: #fff;
  color: #0b101c;
  transition: transform 0.15s ease, opacity 0.2s;
}
#startBtn:active { transform: scale(0.96); }
#startBtn:disabled { opacity: 0.45; }

.note { color: #5d6675; font-size: 12px; line-height: 1.6; }

/* ---------- HUD ---------- */

.glassBtn {
  position: fixed;
  top: calc(var(--sat) + 12px);
  right: 14px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.92);
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
  border: 0.5px solid var(--hairline);
  border-radius: 50%;
  transition: transform 0.15s ease;
}
.glassBtn:active { transform: scale(0.92); }

.pill {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  font-size: 12.5px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.92);
  background: var(--glass);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
  border: 0.5px solid var(--hairline);
  padding: 8px 16px;
  border-radius: 100px;
  max-width: 82vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.pill.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#statusPill { bottom: calc(var(--sab) + 24px); }

#calPill {
  top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
#calPill.show { transform: translate(-50%, -50%) scale(1); }

/* ---------- Sheets ---------- */

#backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 19;
  opacity: 0;
  transition: opacity 0.3s ease;
}
#backdrop.show { opacity: 1; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--glass);
  -webkit-backdrop-filter: blur(28px) saturate(1.5);
  backdrop-filter: blur(28px) saturate(1.5);
  border-top: 0.5px solid var(--hairline);
  border-radius: 22px 22px 0 0;
  padding: 10px 22px calc(var(--sab) + 26px);
  transform: translateY(105%);
  transition: transform 0.42s cubic-bezier(0.32, 0.72, 0.27, 1);
}
.sheet.open { transform: translateY(0); }

.grabber {
  width: 36px;
  height: 4.5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.28);
  margin: 2px auto 16px;
}

.sheet h2 { font-size: 21px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 18px; }

.stats { display: flex; gap: 10px; margin-bottom: 20px; }
.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: rgba(255, 255, 255, 0.07);
  border: 0.5px solid var(--hairline);
  border-radius: 14px;
  padding: 13px 14px;
}
.statVal { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.statKey { font-size: 10.5px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: rgba(255, 255, 255, 0.5); }

.sheetBtn {
  display: block;
  text-align: center;
  text-decoration: none;
  color: #0b101c;
  background: #fff;
  font-size: 15.5px;
  font-weight: 600;
  padding: 14px;
  border-radius: 14px;
  transition: transform 0.15s ease;
}
.sheetBtn:active { transform: scale(0.98); }

/* ---------- Settings controls ---------- */

.slider { display: block; margin-bottom: 20px; }
.sliderHead { display: flex; justify-content: space-between; font-size: 14.5px; margin-bottom: 10px; }
.sliderVal { color: rgba(255, 255, 255, 0.55); font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.22);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  margin-top: -11.5px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14.5px;
  padding: 4px 0 16px;
}
.dim { color: rgba(255, 255, 255, 0.55); font-variant-numeric: tabular-nums; }

.miniBtn {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 0.5px solid var(--hairline);
  border-radius: 100px;
  padding: 7px 16px;
}
.miniBtn:active { background: rgba(255, 255, 255, 0.2); }

.sheet .note { margin-top: 4px; }

/* The guide leaves the camera interactive and yields to peak details/settings. */
.guide {
  position: fixed;
  z-index: 5;
  bottom: calc(var(--sab) + 16px);
  left: 50%;
  transform: translateX(-50%);
  width: min(400px, calc(100% - 28px));
  max-height: calc(100dvh - var(--sat) - var(--sab) - 120px);
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--hairline);
  border-radius: 20px;
  background: rgba(12, 16, 24, 0.94);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.guideEyebrow {
  display: flex;
  justify-content: space-between;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}
#guideProgress { color: #b5bdca; letter-spacing: normal; }
.guide h2 { font-size: 21px; margin-bottom: 8px; }
.guide p { font-size: 16px; line-height: 1.5; color: #ced4de; }
.guideActions { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }
.guideActions button { min-height: 44px; padding: 10px 18px; border: 0; border-radius: 100px; font-size: 15px; font-weight: 600; }
#guideSkip { background: transparent; color: #ced4de; padding-left: 0; }
#guideNext { background: var(--accent); color: #0b101c; min-width: 90px; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
body.guide-open #statusPill { bottom: auto; top: calc(var(--sat) + 78px); }
body.sheet-open .guide { display: none; }
#replayGuide { margin-top: 16px; min-height: 44px; }
