:root {
  --bg: #0d2b2b;
  --accent: #14b8a8;
  --ink: #f3f5f4;
  --panel: rgba(10, 20, 20, .55);
  --panel-solid: rgba(8, 16, 16, .82);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #000; color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior: none; touch-action: none;
}

/* Camera fills the screen */
#cam {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  background: #000;
}

/* Grid overlay */
#grid { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* Reference image overlay */
#overlay {
  position: fixed; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 4; will-change: transform;
  touch-action: none;
}
#overlay.locked { pointer-events: none; }
#refimg {
  display: block; max-width: 80vw; max-height: 70vh;
  opacity: .5; pointer-events: none;
  -webkit-user-drag: none;
}

/* Start gate */
#gate {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 24px;
  background: linear-gradient(180deg, #0d2b2b, #04100f);
}
.gate-card { text-align: center; max-width: 340px; }
.gate-icon { border-radius: 18px; margin-bottom: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.gate-card h1 { margin: 6px 0; font-size: 30px; letter-spacing: .5px; }
.gate-card p { color: #b9c7c5; line-height: 1.5; margin: 10px 0 22px; font-size: 15px; }
.err { color: #ff8d8d; font-size: 14px; }

button { font: inherit; color: inherit; cursor: pointer; border: none; }
.primary {
  background: var(--accent); color: #022; font-weight: 700;
  padding: 14px 28px; border-radius: 999px; font-size: 16px;
  box-shadow: 0 8px 24px rgba(20,184,168,.35);
}
.primary:active { transform: scale(.97); }

/* Top toggles */
.topbar {
  position: fixed; top: calc(env(safe-area-inset-top) + 12px); right: 12px;
  display: flex; flex-direction: column; gap: 10px; z-index: 20;
}
.round {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--panel); backdrop-filter: blur(8px);
  display: grid; place-items: center;
  border: 1px solid rgba(255,255,255,.12);
}
.round svg { width: 24px; height: 24px; fill: currentColor; }
.round.active { background: var(--accent); color: #022; border-color: var(--accent); }
.round.off { opacity: .35; }
.round:active { transform: scale(.92); }

/* Bottom controls */
.controls {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 14px);
  background: linear-gradient(0deg, var(--panel-solid), transparent);
  display: flex; flex-direction: column; gap: 12px;
}
.opacity-row { display: flex; align-items: center; gap: 12px; }
.op-ico { width: 22px; height: 22px; opacity: .9; flex: 0 0 auto; }
.op-val { width: 46px; text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; color: #cfdedb; }
input[type=range] {
  -webkit-appearance: none; appearance: none; flex: 1;
  height: 6px; border-radius: 99px;
  background: rgba(255,255,255,.25);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.4); border: 2px solid #fff;
}
.btn-row { display: flex; gap: 12px; }
.pill {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px; border-radius: 14px; font-weight: 600; font-size: 15px;
  background: var(--panel); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.12);
}
.pill svg { width: 20px; height: 20px; }
.pill:active { transform: scale(.98); }
.pill:disabled { opacity: .4; }
.pill.active { background: var(--accent); color: #022; border-color: var(--accent); }

/* Unlock floating button */
.unlock {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px; border-radius: 999px; font-weight: 600;
  background: var(--panel-solid); border: 1px solid rgba(255,255,255,.18);
}
.unlock svg { width: 20px; height: 20px; }
.unlock:active { transform: translateX(-50%) scale(.97); }

/* Hint */
.hint {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  z-index: 6; background: var(--panel-solid); padding: 12px 18px; border-radius: 12px;
  font-size: 15px; color: #d7e4e2; pointer-events: none;
  border: 1px solid rgba(255,255,255,.12);
}
.hint b { color: #fff; }
