/* LEPEDJIAN AR – clean, Safari-compatible */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: #000;
  overflow: hidden;
  font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#arApp {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
}

#sceneMount {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1;
}

.hidden { display: none; }

.preview-gate {
  position: fixed;
  z-index: 11;
  inset: 0;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}

.preview-gate.hidden {
  display: none;
}

.start-preview-btn {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

/* ── Camera preview ── */
.preview-stage {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 2;
  background: #000;
}

#previewVideo {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  -o-object-fit: cover;
  object-fit: cover;
}

/* ── Color overlay frame ── */
#previewOverlay {
  position: absolute;
  left: 50%; top: 50%;
  width: 58%; height: 54%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255,255,255,0.65);
  border-radius: 6px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.12);
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
  z-index: 3;
  -webkit-transition: opacity 0.15s ease;
  transition: opacity 0.15s ease;
}
#previewOverlay.dragging { cursor: grabbing; }

#previewOverlay.compare-hidden {
  opacity: 0 !important;
}

#previewOverlay.tweak-mode {
  border-color: rgba(255, 255, 255, 0.95);
}

.corner-handle {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.95);
  background: rgba(0, 0, 0, 0.45);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  display: none;
  touch-action: none;
}

#previewOverlay.tweak-mode .corner-handle {
  display: block;
}

.corner-tl { top: -8px; left: -8px; }
.corner-tr { top: -8px; right: -8px; }
.corner-bl { bottom: -8px; left: -8px; }
.corner-br { bottom: -8px; right: -8px; }

.try-controls {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
  z-index: 9;
  pointer-events: auto;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  -webkit-justify-content: center;
  justify-content: center;
  width: min(92vw, 430px);
  gap: 8px;
}

.try-btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-block;
  min-height: 40px;
  min-width: 126px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.try-btn:active {
  -webkit-transform: scale(0.98);
  transform: scale(0.98);
}

.try-btn.active {
  border-color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.16);
}

/* ── Smart Paint mode ── */
#paintCanvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 4;
  pointer-events: none;
  display: none;
}

.paint-active #paintCanvas {
  display: block;
  pointer-events: auto;
}

.paint-active #previewOverlay {
  display: none !important;
}

.paint-active #btnPerspective {
  display: none;
}

.paint-only {
  display: none !important;
}

.paint-active .paint-only {
  display: inline-block !important;
}

.paint-hint {
  position: fixed;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  z-index: 12;
  padding: 12px 20px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  -webkit-transition: opacity 0.3s ease;
  transition: opacity 0.3s ease;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.paint-hint.visible {
  opacity: 1;
}

/* ── Back button ── */
.back-btn {
  position: fixed;
  left: 12px;
  top: 12px;
  top: calc(12px + constant(safe-area-inset-top));
  top: calc(12px + env(safe-area-inset-top, 0px));
  z-index: 10;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(0,0,0,0.52);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  border: 1px solid rgba(255,255,255,0.28);
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.back-btn-arrow {
  font-size: 16px;
}

.back-btn-label {
  font-size: 13px;
  letter-spacing: 0.2px;
}

/* ── Instagram-style swatch strip ── */
.swatch-strip {
  position: fixed;
  z-index: 8;
  bottom: 0; left: 0; right: 0;
  background: -webkit-linear-gradient(bottom, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.35) 75%, transparent 100%);
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.35) 75%, transparent 100%);
  padding: 12px 0;
  padding-bottom: calc(12px + constant(safe-area-inset-bottom));
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  pointer-events: auto;
}

.swatches {
  display: -webkit-flex; display: flex;
  gap: 16px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x mandatory;
  padding: 4px calc(50vw - 30px) 2px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.swatches::-webkit-scrollbar { display: none; }

.swatch-item {
  display: -webkit-flex; display: flex;
  -webkit-flex-direction: column; flex-direction: column;
  -webkit-align-items: center; align-items: center;
  gap: 5px;
  -webkit-flex-shrink: 0; flex-shrink: 0;
  scroll-snap-align: center;
  cursor: pointer;
}

.swatch {
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.22);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  -webkit-transition: transform 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
  transition: transform 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
  opacity: 0.5;
  cursor: pointer;
  -webkit-flex-shrink: 0; flex-shrink: 0;
  -webkit-appearance: none; appearance: none;
  padding: 0;
  background: none;
}

.swatch.texture {
  background-size: cover;
  background-position: center;
}

.swatch.active {
  border-color: #fff;
  border-width: 3px;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.9), 0 4px 14px rgba(0,0,0,0.4);
  -webkit-transform: scale(1.22);
  transform: scale(1.22);
  opacity: 1;
}

.swatch-label {
  font-size: 10px;
  color: rgba(255,255,255,0.45);
  text-align: center;
  max-width: 66px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
  -webkit-transition: color 0.2s ease;
  transition: color 0.2s ease;
}

.swatch-item.active .swatch-label {
  color: #fff;
  font-weight: 700;
  font-size: 11px;
}

/* ── Small screens ── */
@media (max-width: 520px) {
  .swatch { width: 48px; height: 48px; }
  .back-btn {
    left: 8px;
    min-height: 38px;
    padding: 0 10px;
    gap: 5px;
  }
  .back-btn-arrow { font-size: 14px; }
  .back-btn-label { font-size: 12px; }
  .start-preview-btn {
    min-height: 44px;
    font-size: 14px;
    padding: 0 16px;
  }

  .try-controls {
    bottom: calc(86px + env(safe-area-inset-bottom, 0px));
    width: min(94vw, 360px);
    gap: 6px;
  }

  .try-btn {
    min-height: 36px;
    font-size: 11px;
    padding: 0 12px;
    min-width: 110px;
  }

  .corner-handle {
    width: 14px;
    height: 14px;
  }
}
