/* ============================================================
   AR Try-On — standalone camera app (mobile-first, dark)
============================================================ */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: #fff;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Almarai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  position: fixed;
  inset: 0;
  overflow: hidden;
}

[dir="ltr"] body {
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

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

/* ============ shared bits ============ */

.tg-iconbtn {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: transform 0.15s ease, background 0.2s ease;
}

.tg-iconbtn:active { transform: scale(0.92); }

.tg-iconbtn svg {
  width: 21px;
  height: 21px;
}

.tg-iconbtn--lg {
  width: 52px;
  height: 52px;
}

.tg-iconbtn--lg svg {
  width: 24px;
  height: 24px;
}

.tg-iconbtn.is-on {
  background: rgba(255, 59, 92, 0.9);
}

.tg-iconbtn.is-on svg {
  fill: #fff;
  stroke: #fff;
}

.tg-badge {
  position: absolute;
  top: -2px;
  inset-inline-end: -2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ff3b5c;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* shutter button */
.tg-shutter {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #000;
  transition: transform 0.12s ease;
  flex-shrink: 0;
}

.tg-shutter:active { transform: scale(0.9); }

.tg-shutter__ring {
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  pointer-events: none;
}

.tg-shutter svg {
  width: 30px;
  height: 30px;
}

/* ============ start screen ============ */

.tg-start {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 2rem 1.5rem;
  padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0px));
  text-align: center;
  background:
    radial-gradient(ellipse 110% 60% at 50% -10%, rgba(45, 212, 191, 0.16), transparent 60%),
    radial-gradient(ellipse 80% 50% at 50% 115%, rgba(56, 88, 233, 0.18), transparent 60%),
    #050507;
}

.tg-start__art {
  width: 132px;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 0.4rem;
  animation: tg-float 5s ease-in-out infinite;
}

@keyframes tg-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@media (prefers-reduced-motion: reduce) {
  .tg-start__art { animation: none; }
}

.tg-start__title {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.tg-start__sub {
  font-size: 0.92rem;
  color: rgba(255, 255, 255, 0.55);
  margin: 0 0 1.6rem;
  max-width: 280px;
  line-height: 1.6;
}

.tg-shutter--start {
  width: 84px;
  height: 84px;
  background: linear-gradient(145deg, #2dd4bf, #0d9488);
  color: #fff;
  box-shadow: 0 10px 40px rgba(13, 148, 136, 0.45);
}

.tg-shutter--start .tg-shutter__ring {
  border-color: rgba(45, 212, 191, 0.4);
  animation: tg-pulse 2.2s ease-out infinite;
}

@keyframes tg-pulse {
  0% { transform: scale(1); opacity: 1; }
  70% { transform: scale(1.25); opacity: 0; }
  100% { transform: scale(1.25); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .tg-shutter--start .tg-shutter__ring { animation: none; }
}

.tg-start__hint {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.45);
}

.tg-start__favs {
  position: absolute;
  top: calc(1rem + env(safe-area-inset-top, 0px));
  inset-inline-end: 1rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.85);
}

.tg-start__favs svg {
  width: 16px;
  height: 16px;
}

.tg-start__favs .tg-badge {
  position: static;
}

/* ============ camera view ============ */

.tg-cam {
  position: absolute;
  inset: 0;
}

.tg-cam[hidden] { display: none; }

.tg-cam__video,
.tg-cam__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.tg-cam__canvas { pointer-events: none; }

.tg-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: calc(0.8rem + env(safe-area-inset-top, 0px)) 0.9rem 1.4rem;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent);
}

.tg-hint {
  flex: 1;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 500;
  color: #fff;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-hint.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* loading state */
.tg-status {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  text-align: center;
  padding: 1.5rem;
}

.tg-status[hidden] { display: none; }

.tg-status p {
  margin: 0;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
  max-width: 280px;
  line-height: 1.6;
}

.tg-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #2dd4bf;
  border-radius: 50%;
  animation: tg-spin 0.8s linear infinite;
}

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

/* ============ bottom stack ============ */

.tg-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
  padding-bottom: calc(0.9rem + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.65) 40%, transparent);
  padding-top: 2.5rem;
}

/* selected product chip */
.tg-chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  max-width: calc(100% - 2rem);
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  background: rgba(20, 20, 24, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transition: transform 0.15s ease;
}

.tg-chip:active { transform: scale(0.97); }
.tg-chip[hidden] { display: none; }

.tg-chip__fit {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: #16a34a;
  color: #fff;
  flex-shrink: 0;
}

.tg-chip__fit--mid { background: #ea580c; }
.tg-chip__fit--low { background: #64748b; }

.tg-chip__name {
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-chip__price {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
  flex-shrink: 0;
}

.tg-chip__arrow {
  width: 15px;
  height: 15px;
  opacity: 0.6;
  flex-shrink: 0;
}

/* glasses slider — filter style */
.tg-slider {
  display: flex;
  gap: 0.6rem;
  width: 100%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 0.35rem 50vw 0.35rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tg-slider::-webkit-scrollbar { display: none; }

.tg-slide {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  scroll-snap-align: center;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.25);
  padding: 9px;
  transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.tg-slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.tg-slide.is-active {
  border-color: #2dd4bf;
  background: rgba(45, 212, 191, 0.18);
  transform: scale(1.12);
}

.tg-slide__fit {
  position: absolute;
  top: -7px;
  inset-inline-end: -7px;
  font-size: 0.6rem;
  font-weight: 800;
  padding: 0.14rem 0.4rem;
  border-radius: 999px;
  background: #16a34a;
  color: #fff;
  line-height: 1.25;
  border: 1.5px solid #000;
}

.tg-slide__fit--mid { background: #ea580c; }
.tg-slide__fit--low { background: #64748b; }

/* controls row */
.tg-controls {
  display: flex;
  align-items: center;
  gap: 2.2rem;
  margin-top: 0.15rem;
}

.tg-controls .tg-shutter {
  width: 62px;
  height: 62px;
}

/* flash on capture */
.tg-flash {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.tg-flash.is-on {
  animation: tg-flash 0.35s ease-out;
}

@keyframes tg-flash {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* ============ scrim + sheets ============ */

.tg-scrim {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.tg-scrim.is-on { opacity: 1; }
.tg-scrim[hidden] { display: none; }

.tg-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: #141418;
  border-radius: 22px 22px 0 0;
  padding: 0.7rem 1.25rem calc(1.4rem + env(safe-area-inset-bottom, 0px));
  transform: translateY(110%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.tg-sheet.is-open { transform: translateY(0); }
.tg-sheet[hidden] { display: none; }

.tg-sheet__handle {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.25);
  margin: 0 auto 1.1rem;
}

.tg-sheet__row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.1rem;
}

.tg-sheet__img {
  width: 92px;
  height: 52px;
  object-fit: contain;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  padding: 6px;
}

.tg-sheet__info h2 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.tg-sheet__info p {
  margin: 0;
  font-size: 0.92rem;
  color: #2dd4bf;
  font-weight: 600;
}

.tg-sheet__fit {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  background: rgba(22, 163, 74, 0.18);
  color: #4ade80;
}

.tg-coupon {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 0.95rem;
  border-radius: 13px;
  background: rgba(45, 212, 191, 0.08);
  border: 1px dashed rgba(45, 212, 191, 0.45);
  margin-bottom: 1rem;
  text-align: start;
}

.tg-coupon__label {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.65);
  flex: 1;
}

.tg-coupon__code {
  font-family: ui-monospace, monospace;
  font-size: 1rem;
  font-weight: 800;
  color: #2dd4bf;
  letter-spacing: 0.06em;
}

.tg-coupon__action {
  font-size: 0.76rem;
  font-weight: 700;
  color: #2dd4bf;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(45, 212, 191, 0.5);
}

.tg-sheet__actions {
  display: flex;
  gap: 0.65rem;
}

.tg-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.85rem 1rem;
  border-radius: 13px;
  font-size: 0.92rem;
  font-weight: 700;
  transition: transform 0.12s ease, opacity 0.15s ease;
}

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

.tg-btn--primary {
  background: linear-gradient(135deg, #2dd4bf, #0d9488);
  color: #fff;
}

.tg-btn--ghost {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.tg-btn--ghost.is-on {
  background: rgba(255, 59, 92, 0.18);
  color: #ff6b85;
}

/* ============ favorites drawer ============ */

.tg-favs {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: #0c0c10;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}

.tg-favs.is-open { transform: translateY(0); }
.tg-favs[hidden] { display: none; }

.tg-favs__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(1rem + env(safe-area-inset-top, 0px)) 1.25rem 0.8rem;
}

.tg-favs__head h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
}

.tg-favs__list {
  flex: 1;
  overflow-y: auto;
  padding: 0.3rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.tg-favs__empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  text-align: center;
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.9rem;
  line-height: 1.7;
  margin: 0;
}

.tg-favs__empty[hidden] { display: none; }

.tg-fav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.8rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.tg-fav-item__img {
  width: 76px;
  height: 44px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 5px;
  flex-shrink: 0;
}

.tg-fav-item__body {
  flex: 1;
  min-width: 0;
}

.tg-fav-item__name {
  font-size: 0.88rem;
  font-weight: 700;
  margin: 0 0 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-fav-item__meta {
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.55);
  margin: 0;
}

.tg-fav-item__meta b { color: #2dd4bf; }

.tg-fav-item__actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.tg-fav-item__btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.09);
}

.tg-fav-item__btn svg {
  width: 17px;
  height: 17px;
}

.tg-fav-item__btn--store { background: rgba(45, 212, 191, 0.16); color: #2dd4bf; }
.tg-fav-item__btn--del { color: rgba(255, 255, 255, 0.55); }

/* ============ toast ============ */

.tg-toast {
  position: absolute;
  bottom: calc(7.5rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  z-index: 70;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  background: rgba(20, 20, 24, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.tg-toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.tg-toast[hidden] { display: none; }
