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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: #000;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
}

#cam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
}

/* ---------- Start screen ---------- */
#start-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #0a0a0a, #1a1a1a);
  z-index: 100;
  padding: 24px;
}

#start-screen.hidden { display: none; }

.card {
  background: #111;
  border: 1px solid #2a2a2a;
  border-radius: 16px;
  padding: 28px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
}

.card h1 {
  margin: 0 0 8px;
  font-size: 24px;
  letter-spacing: 0.3px;
}

.card p {
  margin: 6px 0 18px;
  color: #bbb;
  font-size: 14px;
  line-height: 1.5;
}

.card .hint {
  margin-top: 16px;
  font-size: 12px;
  color: #888;
}

.btn {
  display: inline-block;
  width: 100%;
  padding: 14px 18px;
  border-radius: 10px;
  border: 1px solid #333;
  background: #1c1c1c;
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 8px;
  text-align: center;
  user-select: none;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: #2563eb; border-color: #2563eb; }
.btn.primary:active { background: #1e4fbf; }

/* ---------- Toolbar ---------- */
#toolbar {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  z-index: 50;
}

.tool {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool:active { background: rgba(255,255,255,0.15); }
.tool.active { background: #2563eb; }

.color-tool {
  position: relative;
  overflow: hidden;
}

.color-tool input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* ---------- Sliders ---------- */
#sliders {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#sliders label {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: #ddd;
}

#sliders label span {
  width: 56px;
  flex-shrink: 0;
  font-weight: 500;
}

#sliders input[type="range"] {
  flex: 1;
  accent-color: #2563eb;
  height: 28px;
}

/* ---------- Gallery ---------- */
.gallery {
  margin: 12px 0 20px;
  background: rgba(255,255,255,0.03);
  border-radius: 12px;
  padding: 10px;
}

.gallery-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.gallery-scroll::-webkit-scrollbar { display: none; }

.gallery-item {
  width: 70px;
  height: 70px;
  flex-shrink: 0;
  border-radius: 8px;
  background: #222;
  border: 1px solid #333;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.gallery-item:active { transform: scale(0.92); }
.gallery-item.active { border-color: #2563eb; background: #000; box-shadow: 0 0 10px rgba(37,99,235,0.3); }

.gallery-item img {
  max-width: 80%;
  max-height: 80%;
  object-fit: contain;
  filter: invert(1); /* Assume black on white stencils, invert for dark UI */
}

#gallery-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#gallery-overlay.hidden { display: none; }

/* ---------- UI Toggle ---------- */
#tool-toggle-ui {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease, background 0.2s;
  display: none; /* Hidden until camera starts */
}

#tool-toggle-ui:active { background: rgba(255,255,255,0.2); }

body.ui-minimized #toolbar {
  transform: translate(-50%, -120%);
  opacity: 0;
  pointer-events: none;
}

body.ui-minimized #sliders {
  transform: translateY(120%);
  opacity: 0;
  pointer-events: none;
}

body.ui-minimized #tool-toggle-ui {
  transform: rotate(180deg);
  background: rgba(37, 99, 235, 0.8);
}

#toolbar, #sliders {
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* ---------- Lock banner ---------- */
#lock-banner {
  position: fixed;
  top: max(70px, calc(env(safe-area-inset-top) + 60px));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(220, 38, 38, 0.9);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  z-index: 60;
  pointer-events: none;
}
