/* ============================================================
   VIRTUAL TRY-ON SYSTEM — MORPHIC GLASSMORPHISM UI
   MMZ Digital Technology © 2025
   All class names use to-* prefix
   ============================================================ */

/* ── Reset & Base ─────────────────────────────────────────── */
.to-overlay *,
.to-overlay *::before,
.to-overlay *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Overlay (fullscreen backdrop) ───────────────────────── */
.to-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  animation: to-fade-in 0.28s ease forwards;
}

@keyframes to-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Main Container ───────────────────────────────────────── */
.to-container {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #0a0a0f;
  overflow: hidden;
  animation: to-slide-up 0.36s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@media (min-width: 480px) {
  .to-container {
    max-height: 860px;
    border-radius: 28px;
    box-shadow:
      0 0 0 1px rgba(255,255,255,0.07),
      0 40px 120px rgba(0,0,0,0.9),
      0 0 80px rgba(139,92,246,0.12);
  }
}

@keyframes to-slide-up {
  from { opacity: 0; transform: translateY(40px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}


/* ── Top Bar ──────────────────────────────────────────────── */
.to-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px;
  background: linear-gradient(to bottom,
    rgba(0,0,0,0.72) 0%,
    rgba(0,0,0,0.28) 70%,
    transparent 100%);
  pointer-events: none;
}

.to-topbar > * {
  pointer-events: auto;
}

/* ── Icon Buttons ─────────────────────────────────────────── */
.to-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(16px) saturate(1.6);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.14s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.to-btn:hover {
  background: rgba(255,255,255,0.16);
  border-color: rgba(255,255,255,0.28);
}

.to-btn:active {
  transform: scale(0.9);
}

/* Heart / Like button */
.to-heart {
  font-size: 17px;
  transition: color 0.2s, transform 0.2s;
}

.to-heart.liked {
  color: #f472b6;
  text-shadow: 0 0 12px rgba(244,114,182,0.6);
}

.to-heart.liked:active {
  transform: scale(1.3);
}

/* Adjust toggle button */
.to-adjust-btn {
  font-size: 15px;
}

.to-adjust-btn.active {
  background: rgba(255,255,255,0.92);
  color: #0a0a0f;
  border-color: transparent;
}

/* Product info in topbar */
.to-prod-info {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.to-prod-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  text-shadow: 0 1px 8px rgba(0,0,0,0.6);
}

.to-prod-price {
  font-size: 11px;
  font-weight: 500;
  color: rgba(255,255,255,0.55);
  margin-top: 1px;
}

/* ── Camera Stage ─────────────────────────────────────────── */
.to-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
  min-height: 0;
}

/* Vignette overlay */
.to-stage::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 5;
  background: radial-gradient(
    ellipse 90% 90% at 50% 50%,
    transparent 55%,
    rgba(0,0,0,0.55) 100%
  );
  pointer-events: none;
}

/* Video feed — mirrored */
.to-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  z-index: 1;
}

/* Canvas overlay — NOT mirrored (JS handles mirroring) */
.to-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: none;
  z-index: 2;
  pointer-events: none;
}

/* ── Loading State ────────────────────────────────────────── */
.to-loading {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(10,10,15,0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.to-loading[hidden] {
  display: none;
}

.to-spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.12);
  border-top-color: rgba(255,255,255,0.9);
  animation: to-spin 0.8s linear infinite;
}

@keyframes to-spin {
  to { transform: rotate(360deg); }
}

.to-loading p {
  font-size: 15px;
  font-weight: 500;
  color: rgba(255,255,255,0.85);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  letter-spacing: -0.01em;
}

/* ── Error State ──────────────────────────────────────────── */
.to-error-wrap {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px;
  background: rgba(10,10,15,0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  text-align: center;
}

.to-error-wrap[hidden] {
  display: none;
}

.to-error-icon {
  font-size: 40px;
  line-height: 1;
}

.to-error-text {
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  line-height: 1.5;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
}

.to-retry-btn {
  margin-top: 4px;
  padding: 10px 24px;
  border-radius: 50px;
  border: 1px solid rgba(139,92,246,0.5);
  background: rgba(139,92,246,0.15);
  color: #c4b5fd;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
}

.to-retry-btn:hover {
  background: rgba(139,92,246,0.28);
  border-color: rgba(139,92,246,0.8);
}

/* ── Hint Pill ────────────────────────────────────────────── */
.to-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 50px;
  background: rgba(0,0,0,0.52);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1);
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  white-space: nowrap;
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  transition: opacity 0.4s;
}

.to-hint[hidden] {
  display: none;
}

.to-hint-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8b5cf6;
  box-shadow: 0 0 8px rgba(139,92,246,0.8);
  animation: to-pulse-dot 1.8s ease-in-out infinite;
  flex-shrink: 0;
}

/* ── Shutter Button ───────────────────────────────────────── */
.to-shutter {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.14s;
}

.to-shutter:active {
  transform: translateX(-50%) scale(0.92);
}

.to-shutter-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.85);
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.15),
    inset 0 0 0 1px rgba(255,255,255,0.08);
}

.to-shutter-inner {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  transition: background 0.14s, transform 0.14s;
}

.to-shutter:active .to-shutter-inner {
  background: rgba(255,255,255,0.7);
  transform: scale(0.94);
}

/* ── Adjust Panel ─────────────────────────────────────────── */
.to-adjust-panel {
  position: absolute;
  top: 64px;
  right: 14px;
  z-index: 18;
  width: 196px;
  border-radius: 18px;
  background: rgba(18,18,28,0.82);
  backdrop-filter: blur(24px) saturate(1.8);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow:
    0 8px 32px rgba(0,0,0,0.6),
    0 0 0 1px rgba(139,92,246,0.08);
  animation: to-panel-in 0.22s cubic-bezier(0.22,1,0.36,1) forwards;
}

.to-adjust-panel[hidden] {
  display: none;
}

@keyframes to-panel-in {
  from { opacity: 0; transform: scale(0.92) translateY(-8px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

.to-adjust-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.to-adjust-lbl {
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
}

/* Chips */
.to-chips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.to-chip {
  padding: 5px 10px;
  border-radius: 50px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: rgba(255,255,255,0.6);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, color 0.16s;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.to-chip:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.22);
}

.to-chip.active {
  background: linear-gradient(135deg, rgba(139,92,246,0.35), rgba(236,72,153,0.25));
  border-color: rgba(139,92,246,0.55);
  color: #e9d5ff;
}

/* Range Slider */
.to-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: rgba(255,255,255,0.12);
  outline: none;
  cursor: pointer;
}

.to-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  box-shadow: 0 2px 8px rgba(139,92,246,0.5);
  cursor: pointer;
  transition: transform 0.14s;
}

.to-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.to-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  box-shadow: 0 2px 8px rgba(139,92,246,0.5);
  cursor: pointer;
  border: none;
}

/* Reset button */
.to-reset-btn {
  width: 100%;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: rgba(255,255,255,0.5);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.16s, color 0.16s;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  letter-spacing: 0.04em;
}

.to-reset-btn:hover {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.8);
}

/* ── Bottom Panel ─────────────────────────────────────────── */
.to-bottom {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(to bottom, #0d0d18 0%, #0a0a12 100%);
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Frames header */
.to-frames-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 6px;
}

.to-frames-label {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
}

.to-frames-count {
  font-size: 11px;
  font-weight: 500;
  color: rgba(139,92,246,0.7);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
}

/* Frames scroll list */
.to-frames {
  display: flex;
  gap: 10px;
  padding: 4px 16px 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.to-frames::-webkit-scrollbar {
  display: none;
}

/* Empty state */
.to-frames-empty {
  width: 100%;
  padding: 20px 16px;
  text-align: center;
  font-size: 12px;
  color: rgba(255,255,255,0.3);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
}

/* Individual frame card */
.to-frame {
  flex-shrink: 0;
  width: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  scroll-snap-align: start;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.16s;
}

.to-frame:active {
  transform: scale(0.94);
}

.to-frame-img {
  width: 68px;
  height: 52px;
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  border: 2px solid rgba(255,255,255,0.08);
  transition: border-color 0.18s, box-shadow 0.18s;
  display: block;
  overflow: hidden;
  flex-shrink: 0;
}

.to-frame-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 0;
}

.to-frame.sel .to-frame-img {
  border-color: #8b5cf6;
  box-shadow:
    0 0 0 1px rgba(139,92,246,0.4),
    0 4px 16px rgba(139,92,246,0.3);
}

.to-frame-lbl {
  font-size: 10px;
  font-weight: 500;
  color: rgba(255,255,255,0.45);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 68px;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  transition: color 0.18s;
}

.to-frame.sel .to-frame-lbl {
  color: #c4b5fd;
}

/* Favorite heart on frame */
.to-frame-fav {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  transition: color 0.18s, transform 0.18s;
  line-height: 1;
}

.to-frame-fav.liked {
  color: #f472b6;
  text-shadow: 0 0 8px rgba(244,114,182,0.5);
}

/* Frame wrapper for positioning fav icon */
.to-frame {
  position: relative;
}

/* ── Add to Cart Button ───────────────────────────────────── */
.to-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 16px 14px;
  padding: 15px 24px;
  border-radius: 50px;
  border: none;
  background: #fff;
  color: #0a0a0f;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.22s, color 0.22s, transform 0.14s, box-shadow 0.22s;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  letter-spacing: 0.01em;
  box-shadow: 0 4px 20px rgba(255,255,255,0.15);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.to-add-btn:hover {
  background: #f0f0f0;
  box-shadow: 0 6px 28px rgba(255,255,255,0.22);
}

.to-add-btn:active {
  transform: scale(0.97);
}

.to-add-btn.added {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  box-shadow: 0 4px 20px rgba(34,197,94,0.35);
}

.to-add-check {
  font-size: 16px;
  line-height: 1;
}

.to-add-price {
  font-size: 13px;
  font-weight: 500;
  opacity: 0.65;
}

/* ── Capture / Photo Modal ────────────────────────────────── */
.to-capture-modal {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  animation: to-fade-in 0.22s ease forwards;
  padding: 24px;
}

.to-capture-modal[hidden] {
  display: none;
}

.to-capture-card {
  width: 100%;
  max-width: 320px;
  border-radius: 24px;
  overflow: hidden;
  background: rgba(18,18,28,0.9);
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 24px 80px rgba(0,0,0,0.8);
}

.to-capture-card img,
.to-capture-card canvas {
  width: 100%;
  display: block;
  border-radius: 0;
}

.to-capture-actions {
  display: flex;
  gap: 10px;
  padding: 14px;
}

/* ── Pill Buttons ─────────────────────────────────────────── */
.to-pill {
  flex: 1;
  padding: 12px 16px;
  border-radius: 50px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.14s;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.to-pill:hover {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.26);
}

.to-pill:active {
  transform: scale(0.96);
}

.to-pill-outline {
  background: transparent;
  border-color: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7);
}

.to-pill-outline:hover {
  background: rgba(255,255,255,0.06);
}

/* ── Flash animation for shutter ─────────────────────────── */
@keyframes to-flash {
  0%   { opacity: 0; }
  15%  { opacity: 0.85; }
  100% { opacity: 0; }
}

.to-flash {
  position: absolute;
  inset: 0;
  z-index: 25;
  background: #fff;
  pointer-events: none;
  animation: to-flash 0.45s ease forwards;
}

/* ── Scrollbar for frames on desktop ─────────────────────── */
@media (hover: hover) {
  .to-frames::-webkit-scrollbar {
    display: block;
    height: 3px;
  }
  .to-frames::-webkit-scrollbar-track {
    background: transparent;
  }
  .to-frames::-webkit-scrollbar-thumb {
    background: rgba(139,92,246,0.3);
    border-radius: 3px;
  }
}

/* ── Responsive: very small screens ──────────────────────── */
@media (max-height: 640px) {
  .to-brand-inner {
    padding: 7px 14px;
  }
  .to-brand-icon {
    width: 26px;
    height: 26px;
    font-size: 13px;
  }
  .to-brand-name {
    font-size: 12px;
  }
  .to-frames {
    padding-bottom: 8px;
  }
  .to-add-btn {
    padding: 12px 20px;
    font-size: 13px;
    margin-bottom: 10px;
  }
  .to-frame-img {
    width: 58px;
    height: 44px;
  }
  .to-frame {
    width: 62px;
  }
}

/* ── Accessibility ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .to-overlay,
  .to-container,
  .to-adjust-panel {
    animation: none;
  }
  .to-brand::before,
  .to-live-dot::before,
  .to-hint-dot,
  .to-spinner {
    animation: none;
  }
}
