:root {
  --bg: #0a0a0a;
  --fg: #f5f5f5;
  --accent: #ff3b3b;
  --panel: rgba(20, 20, 20, 0.78);
  --panel-border: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, label { font: inherit; color: inherit; }

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

#camera {
  /* Hidden visually but still rendered/decoded by the browser. Some browsers
     (notably Safari) throttle frame delivery for tiny/invisible videos, so
     keep the element at a real size and just push it off-screen. */
  position: fixed;
  top: -200vh;
  left: 0;
  width: 320px;
  height: 240px;
  pointer-events: none;
}

#output {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  display: block;
  object-fit: contain;
}

#overlay-controls {
  position: absolute;
  top: max(env(safe-area-inset-top), 12px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 10;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100% - 24px);
}

#overlay-controls button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: background 120ms, transform 80ms;
}

#overlay-controls button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

#overlay-controls button:active:not(:disabled) {
  transform: scale(0.97);
}

#overlay-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#overlay-controls button.primary {
  background: var(--accent);
  border-color: var(--accent);
}

#overlay-controls button.recording {
  background: #ff3b3b;
  border-color: #ff3b3b;
  box-shadow: 0 0 0 0 rgba(255, 59, 59, 0.6);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 59, 59, 0.6); }
  70%  { box-shadow: 0 0 0 12px rgba(255, 59, 59, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 59, 59, 0); }
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  user-select: none;
  cursor: pointer;
  padding: 0 8px;
}

.toggle input { accent-color: var(--accent); }

.bg-control input[type="color"] {
  width: 28px;
  height: 22px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
}
.bg-control input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.bg-control input[type="color"]::-webkit-color-swatch { border: none; border-radius: 3px; }

#mask-strip {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom), 12px);
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 8px;
  z-index: 10;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#mask-thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
  padding: 2px;
}

.mask-hint {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  user-select: none;
}

.mask-thumb {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: #222;
  background-size: cover;
  background-position: center;
  cursor: pointer;
  position: relative;
  transition: border-color 120ms, transform 80ms;
}

.mask-thumb.selected {
  border-color: var(--accent);
}

.mask-thumb.placeholder {
  background: linear-gradient(135deg, #ffd1a8, #f5a36c);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #4b2a14;
  text-align: center;
  padding: 4px;
}

.mask-thumb .delete {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #000;
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  border: 1px solid #555;
  cursor: pointer;
  display: none;
}

.mask-thumb:hover .delete {
  display: block;
}

#upload-btn {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 10px;
  border: 2px dashed rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.04);
  color: #aaa;
  font-size: 28px;
  font-weight: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 120ms, color 120ms;
}

#upload-btn:hover { border-color: #fff; color: #fff; }

#status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.7);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 20;
  pointer-events: none;
  text-align: center;
  max-width: 80%;
}

#status.hidden { display: none; }

#loading {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 30;
  transition: opacity 300ms;
}

#loading.fade { opacity: 0; pointer-events: none; }

#loading-face {
  width: 128px;
  height: 128px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 18px 40px rgba(0, 0, 0, 0.4));
  animation: bob 1.6s ease-in-out infinite;
}

#loading-face svg {
  width: 100%;
  height: 100%;
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50%      { transform: translateY(-6px) rotate(3deg); }
}

#drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  border: 4px dashed var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  z-index: 40;
  pointer-events: none;
}

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

@media (max-width: 600px) {
  #overlay-controls { font-size: 13px; padding: 6px 10px; gap: 6px; }
  #overlay-controls button { padding: 6px 10px; font-size: 13px; }
  .mask-thumb, #upload-btn { width: 48px; height: 48px; }
}
