/* ==========================================================================
   VirtualFit: Spatial Try-On — High-Performance Optimized Stylesheet
   Hardware-accelerated, zero-layout-thrashing visionOS glassmorphism
   ========================================================================== */

:root {
  --ease: cubic-bezier(.2, .8, .2, 1);
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --MH: min(78vh, 62vw);
  --CW: min(14.8vw, 33vh);
  --room: url('assets/room.webp');
  --model: url('assets/model.webp');
  --garm: url('assets/garm.webp');
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html, body {
  height: 100%;
  width: 100%;
  background: #e9e4dc;
  color: #fff;
  font-family: var(--sans);
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  text-rendering: optimizeLegibility;
}

/* Lock overflow only on the 3D fitting room (non-.page-wrapper bodies) */
body:not(.page-wrapper) {
  overflow: hidden;
}

/* Allow scrolling on all other pages */
body.page-wrapper {
  overflow-x: hidden;
  overflow-y: auto;
}

/* Standard native pointers with zero input latency */
button, .tab-item, .tab-btn, .chip, .color-dot, .rail-btn, .arrow, .arrow-btn, .card {
  cursor: pointer;
}

/* ==========================================================================
   visionOS Glass Recipe — Optimized Layer Compositing
   (Used on stationary elements: .buy, .tabs-bar, .rail, .arrow)
   ========================================================================== */
.glass {
  background: linear-gradient(155deg, rgba(250, 248, 245, .30), rgba(150, 144, 136, .20) 48%, rgba(205, 200, 192, .24));
  backdrop-filter: blur(22px) saturate(1.5);
  -webkit-backdrop-filter: blur(22px) saturate(1.5);
  border: 1px solid rgba(255, 255, 255, .5);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .7),
    inset 0 -1px 0 rgba(255, 255, 255, .12),
    0 20px 50px -24px rgba(40, 30, 20, .45);
}

/* ==========================================================================
   Room Background Layer & Vignette (Pre-blurred & zero runtime filter)
   ========================================================================== */
.room {
  position: fixed;
  inset: -3%;
  z-index: 1;
  pointer-events: none;
  background: var(--room) center / cover no-repeat;
  filter: none;
  -webkit-filter: none;
  transform: scale(1.08) translateZ(0);
  will-change: transform;
  contain: strict;
  backface-visibility: hidden;
}

.room::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(70% 60% at 50% 45%, rgba(255, 252, 246, .10), rgba(40, 30, 20, .16));
  pointer-events: none;
}

/* ==========================================================================
   Ghost FIT Layer
   ========================================================================== */
.ghost {
  position: fixed;
  z-index: 2;
  pointer-events: none;
  top: calc(50% - var(--MH) * .42);
  left: 50%;
  transform: translate(-50%, 0) translateZ(0);
  display: flex;
  justify-content: center;
  font-family: var(--sans);
  font-weight: 900;
  font-size: calc(var(--MH) * .42);
  line-height: .8;
  letter-spacing: -.04em;
  color: rgba(255, 255, 255, .3);
  -webkit-text-stroke: 1px rgba(255, 255, 255, .35);
  text-stroke: 1px rgba(255, 255, 255, .35);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .35);
  will-change: transform;
  contain: layout style;
  backface-visibility: hidden;
}

.ghost span {
  display: inline-block;
  will-change: transform, opacity;
  backface-visibility: hidden;
}

/* ==========================================================================
   Stage for 3D Spatial Arc
   ========================================================================== */
.stage {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: auto;
  contain: layout size;
}

/* ==========================================================================
   Garment Card — Ultra High Performance 3D Spatial Presentation
   ========================================================================== */
.card {
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: calc(var(--CW) * -0.71);
  margin-left: calc(var(--CW) * -0.5);
  width: var(--CW);
  height: calc(var(--CW) * 1.42);
  border-radius: 22px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 16px 12px;
  will-change: transform, opacity;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  contain: layout style;
  backface-visibility: hidden;
  transform-style: flat;
}

/* Dedicated high-performance visionOS glass recipe for moving 3D cards */
.card.glass {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.42), rgba(190, 185, 178, 0.22) 48%, rgba(230, 225, 218, 0.32));
  border: 1px solid rgba(255, 255, 255, .55);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .75),
    inset 0 -1px 0 rgba(255, 255, 255, .15),
    0 16px 36px -16px rgba(40, 30, 20, .35);
}

.card-sheen {
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, .5) 50%, transparent 60%);
  transform: translateX(-100%);
  pointer-events: none;
  z-index: 5;
  will-change: transform;
}

.card:hover .card-sheen,
.card.sheen-active .card-sheen {
  animation: sheenSweep 0.9s var(--ease) 1;
}

@keyframes sheenSweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.card-thumb {
  width: 82%;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  background-image: var(--garm);
  background-size: 320% 212.5%;
  background-repeat: no-repeat;
  pointer-events: none;
  image-rendering: auto;
  transform: translateZ(0);
}

.card-label {
  text-align: center;
  pointer-events: none;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, .95);
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-price {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, .7);
}

/* ==========================================================================
   Human Model Container & Try-On Scanner
   ========================================================================== */
.model {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateZ(0);
  height: var(--MH);
  aspect-ratio: 524 / 1360;
  width: calc(var(--MH) * 524 / 1360);
  z-index: 50;
  pointer-events: none;
  contain: layout paint;
  backface-visibility: hidden;
}

#mCur, #mNext {
  position: absolute;
  inset: 0;
  background-image: var(--model);
  background-size: 513% 111.76%;
  background-position-y: 100%;
  background-repeat: no-repeat;
  will-change: clip-path, transform, opacity;
  backface-visibility: hidden;
  transform: translateZ(0);
}

#mCur {
  opacity: 0;
}

#mNext {
  clip-path: inset(0 0 100% 0);
}

.grid, #mGrid, #scanGrid {
  position: absolute;
  inset: 0;
  clip-path: inset(0 0 100% 0);
  background-image:
    linear-gradient(rgba(180, 220, 255, .25) 1px, transparent 1px),
    linear-gradient(90deg, rgba(180, 220, 255, .25) 1px, transparent 1px);
  background-size: 16px 16px;
  pointer-events: none;
  will-change: clip-path;
  backface-visibility: hidden;
}

.scan, #mScan, #scanBeam {
  position: absolute;
  left: -14%;
  width: 128%;
  height: 2px;
  background: #fff;
  box-shadow: 0 0 10px 2px rgba(255, 255, 255, .9), 0 0 20px 5px rgba(180, 220, 255, .65);
  opacity: 0;
  transform: scaleX(.2) translateZ(0);
  pointer-events: none;
  will-change: top, transform, opacity;
  backface-visibility: hidden;
}

.scan::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: calc(var(--MH) * .12);
  background: linear-gradient(to top, rgba(180, 220, 255, .35), transparent);
  pointer-events: none;
}

/* ==========================================================================
   Top Pill Tab Bar
   ========================================================================== */
.tabs-bar {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translateX(-50%) translateZ(0);
  z-index: 70;
  border-radius: 999px;
  padding: 4px;
  display: flex;
  align-items: center;
  gap: 2px;
  contain: layout style;
  backface-visibility: hidden;
}

.tab-indicator, #tabsPill {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
  transition: transform .5s var(--ease), width .5s var(--ease);
  z-index: 1;
  pointer-events: none;
  will-change: transform, width;
}

.tab-btn, .tab-item {
  position: relative;
  z-index: 2;
  background: none;
  border: none;
  padding: 8px 18px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, .75);
  border-radius: 999px;
  cursor: pointer;
  transition: color .25s ease;
  white-space: nowrap;
}

.tab-btn.active, .tab-item.active {
  color: #111;
}

/* ==========================================================================
   Left Tool Rail
   ========================================================================== */
.rail {
  position: fixed;
  left: 28px;
  top: 50%;
  transform: translateY(-50%) translateZ(0);
  z-index: 70;
  border-radius: 999px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  contain: layout style;
  backface-visibility: hidden;
}

.rail-btn, .tool-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
  transition: background .2s, transform .2s;
  will-change: transform, background;
}

.rail-btn:hover, .tool-btn:hover {
  background: rgba(255, 255, 255, .2);
  transform: scale(1.05);
}

.rail-btn:active, .tool-btn:active {
  transform: scale(0.92);
}

/* ==========================================================================
   Chevron Navigation Arrows
   ========================================================================== */
.arrow, .arrow-btn {
  position: fixed;
  top: calc(50% + 20px);
  transform: translateY(-50%) translateZ(0);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .5);
  cursor: pointer;
  transition: transform .2s, background .2s;
  will-change: transform;
  contain: layout style;
  backface-visibility: hidden;
}

.arrow:hover, .arrow-btn:hover {
  background: rgba(255, 255, 255, .25);
  transform: translateY(-50%) scale(1.08) translateZ(0);
}

.arrow:active, .arrow-btn:active {
  transform: translateY(-50%) scale(0.95) translateZ(0);
}

.arrow.prev, #prevBtn, #arrowLeft { left: 28px; }
.arrow.next, #nextBtn, #arrowRight { right: 28px; }

/* ==========================================================================
   Floating Glass Buy Card
   ========================================================================== */
.buy {
  position: fixed;
  bottom: 4.6vh;
  left: 50%;
  transform: translateX(-50%) translateZ(0);
  z-index: 60;
  width: min(660px, calc(100vw - 32px));
  padding: 12px 20px 12px 14px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  contain: layout style;
  backface-visibility: hidden;
}

.buy-thumb-wrap {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .15);
  overflow: hidden;
  flex-shrink: 0;
  transform: translateZ(0);
}

.buy-thumb {
  width: 100%;
  height: 100%;
  background-image: var(--garm);
  background-size: 320% 212.5%;
  background-repeat: no-repeat;
  will-change: transform;
  backface-visibility: hidden;
}

.buy-meta {
  flex: 1;
  min-width: 0;
}

.ln {
  overflow: hidden;
  position: relative;
  height: 1.25em;
  line-height: 1.25em;
}

.ln-text, .ln-item {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  will-change: transform;
}

.buy-title {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
}

.buy-price {
  font-size: 14px;
  font-weight: 500;
  color: rgba(255, 255, 255, .8);
}

.buy-sizes {
  display: flex;
  gap: 6px;
}

.size-chip, .chip {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .15);
  border: 1px solid rgba(255, 255, 255, .3);
  color: #fff;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .15s, background .2s, color .2s;
  will-change: transform;
}

.size-chip:active, .chip:active {
  transform: scale(.9);
}

.size-chip.active, .chip.active {
  background: #fff;
  color: #111;
  border-color: #fff;
}

.buy-colors-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.color-label {
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, .7);
}

.buy-colors, #colorDots {
  display: flex;
  gap: 6px;
}

.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background-color: var(--dot-col, #fff);
  transition: transform .15s, box-shadow .2s;
  outline: none;
  will-change: transform;
}

.color-dot.active {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .95), 0 0 0 4px rgba(0, 0, 0, .12);
  transform: scale(1.1);
}

/* Add to bag action button in buy card */
.buy-action-btn {
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  color: #111;
  border: none;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .2s, background .2s;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.buy-action-btn:hover {
  background: #f0ede6;
  transform: scale(1.03);
}

/* ==========================================================================
   Custom Cursor — Completely Removed per User Request
   (Kept in stylesheet as display:none for zero-layout interference)
   ========================================================================== */
.cur, #cursor {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  opacity: 0 !important;
}

#curLabel {
  display: none !important;
}

/* ==========================================================================
   Responsive Mobile Architecture (<= 767px)
   Engineered to resolve all truncation, overlapping & layout flaws
   ========================================================================== */
@media (max-width: 767px) {
  :root {
    --MH: min(62vh, 128vw);
    --CW: min(30vw, 170px);
  }

  /* Compact top tabs with horizontal swipe */
  .tabs-bar {
    top: 64px;
    height: 34px;
    padding: 2px 6px;
    max-width: calc(100vw - 20px);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    font-size: 12px;
    gap: 4px;
  }

  .tabs-bar::-webkit-scrollbar {
    display: none;
  }

  .tab-btn, .tab-item {
    padding: 4px 10px;
    font-size: 12px;
    flex-shrink: 0;
  }

  /* Ghost FIT repositioned behind the model nicely */
  .ghost {
    top: calc(50% - var(--MH) * .36);
    font-size: calc(var(--MH) * .32);
    opacity: 0.35;
  }

  /* Side cards styling for mobile: compact and framed */
  .card {
    border-radius: 18px;
    padding: 10px 8px;
  }

  .card-title {
    font-size: 11px;
    margin-bottom: 1px;
  }

  .card-price {
    font-size: 10px;
  }

  /* Tool rail cleanly docked above the buy card, clear of model torso */
  .rail {
    left: 10px;
    bottom: 112px;
    top: auto;
    transform: none;
    flex-direction: row;
    gap: 8px;
    padding: 4px 8px;
    height: 36px;
    z-index: 70;
  }

  .rail-btn, .tool-btn {
    width: 28px;
    height: 28px;
  }

  .rail-btn svg, .tool-btn svg {
    width: 15px;
    height: 15px;
  }

  .arrow, .arrow-btn, #prevBtn, #nextBtn, #arrowLeft, #arrowRight {
    display: none !important;
  }

  /* Bottom Buy Card — Polished, non-truncated layout with CSS Grid */
  .buy {
    width: calc(100vw - 20px);
    max-width: 440px;
    bottom: 10px;
    padding: 8px 12px;
    border-radius: 18px;
    display: grid;
    grid-template-areas:
      "thumb meta sizes"
      "colors colors action";
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 6px 10px;
    box-sizing: border-box;
  }

  .buy-thumb-wrap {
    grid-area: thumb;
    width: 42px;
    height: 42px;
    border-radius: 10px;
  }

  .buy-meta {
    grid-area: meta;
    min-width: 0;
  }

  .buy-title {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .buy-price {
    font-size: 12px;
    font-weight: 600;
  }

  .buy-sizes {
    grid-area: sizes;
    display: flex;
    gap: 4px;
  }

  .size-chip, .chip {
    width: 26px;
    height: 26px;
    font-size: 10px;
    border-radius: 6px;
  }

  .buy-colors-wrap {
    grid-area: colors;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding-top: 5px;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
  }

  .color-label {
    font-size: 11px;
    white-space: nowrap;
  }

  .buy-colors, #colorDots {
    display: flex;
    gap: 5px;
  }

  .color-dot {
    width: 15px;
    height: 15px;
  }

  .buy-action-btn {
    grid-area: action;
    justify-self: end;
    margin-top: 5px;
    padding: 6px 12px;
    font-size: 11px;
    white-space: nowrap;
  }
}

@media (pointer: coarse) {
  .cur {
    display: none !important;
  }
}

/* ==========================================================================
   Accessibility / Reduced Motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .card-sheen, .scan, #mScan, #scanBeam, .grid, #mGrid, #scanGrid {
    display: none !important;
  }
}
