/* Explore — Instagram-style uniform square grid */
:root {
  --ex-bg: #f7f5f2;
  --ex-surface: #ffffff;
  --ex-ink: #141414;
  --ex-muted: #6b7280;
  --ex-gap: 2px;
  --ex-header-h: 58px;
  --ex-nav-h: 40px;
  --ex-cols: 3;
  --ex-accent: #0f766e;
  --ex-shadow: 0 10px 30px rgba(20, 20, 20, 0.08);
  --ex-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ex-bg: #0c0c0c;
    --ex-surface: #161616;
    --ex-ink: #f3f3f3;
    --ex-muted: #9ca3af;
    --ex-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}

[data-theme="dark"] {
  --ex-bg: #0c0c0c;
  --ex-surface: #161616;
  --ex-ink: #f3f3f3;
  --ex-muted: #9ca3af;
  --ex-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html.ex-root,
body.ex-page {
  margin: 0;
  min-height: 100%;
  background: var(--ex-bg);
  color: var(--ex-ink);
  font-family: "Vazirmatn", "Tahoma", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.ex-page {
  padding:
    calc(var(--ex-header-h) + env(safe-area-inset-top, 0px))
    0
    calc(var(--ex-nav-h) + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
  overscroll-behavior-y: contain;
}

@media (min-width: 992px) {
  body.ex-page {
    --ex-nav-h: 60px;
  }
}

.ex-header {
  position: fixed;
  inset-inline: 0;
  top: 0;
  z-index: 40;
  padding-top: env(safe-area-inset-top, 0px);
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 8px;
  padding-inline: 10px;
  background: color-mix(in srgb, var(--ex-surface) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--ex-ink) 8%, transparent);
}

.ex-search {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}

.ex-search__label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ex-search__icon {
  position: absolute;
  inset-inline-start: 12px;
  color: var(--ex-muted);
  font-size: 0.85rem;
  pointer-events: none;
}

.ex-search__input {
  width: 100%;
  height: 40px;
  border: 1px solid color-mix(in srgb, var(--ex-ink) 12%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--ex-bg) 70%, var(--ex-surface));
  color: var(--ex-ink);
  font: inherit;
  font-size: 0.92rem;
  padding-inline: 36px 36px;
  outline: none;
  transition: border-color 160ms var(--ex-ease), box-shadow 160ms var(--ex-ease);
}

.ex-search__input::placeholder {
  color: var(--ex-muted);
}

.ex-search__input:focus {
  border-color: color-mix(in srgb, var(--ex-accent) 55%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ex-accent) 18%, transparent);
}

.ex-search__clear {
  position: absolute;
  inset-inline-end: 6px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ex-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ex-search__clear:hover {
  color: var(--ex-ink);
  background: color-mix(in srgb, var(--ex-ink) 8%, transparent);
}

.ex-header__title {
  margin: 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.ex-header__back,
.ex-header__shop {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ex-ink);
  text-decoration: none;
  border-radius: 12px;
  transition: background 180ms var(--ex-ease), transform 180ms var(--ex-ease);
}

.ex-header__back:active,
.ex-header__shop:active {
  transform: scale(0.94);
  background: color-mix(in srgb, var(--ex-ink) 8%, transparent);
}

.ex-main {
  width: min(1200px, 100%);
  margin: 0 auto;
  min-height: 50vh;
}

.ex-grid {
  display: grid;
  grid-template-columns: repeat(var(--ex-cols), minmax(0, 1fr));
  gap: var(--ex-gap);
  background: color-mix(in srgb, var(--ex-ink) 6%, transparent);
}

@media (min-width: 640px) {
  :root { --ex-cols: 4; }
}

@media (min-width: 900px) {
  :root { --ex-cols: 5; }
}

@media (min-width: 1200px) {
  :root { --ex-cols: 6; }
}

.ex-cell {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--ex-surface);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  border: 0;
  padding: 0;
  display: block;
  width: 100%;
  text-decoration: none;
  color: inherit;
  animation: ex-cell-in 420ms var(--ex-ease) both;
}

.ex-cell:focus-visible {
  outline: 2px solid var(--ex-accent);
  outline-offset: -2px;
  z-index: 1;
}

.ex-cell__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  background: var(--ex-surface);
  opacity: 0;
  transform: none;
  transition: opacity 220ms var(--ex-ease);
}

.ex-cell__img.is-loaded {
  opacity: 1;
}

.ex-cell__veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(255, 255, 255, 0.92) 0%, rgba(255, 255, 255, 0.55) 28%, transparent 52%);
  opacity: 0;
  transition: opacity 200ms var(--ex-ease);
  pointer-events: none;
}

.ex-cell__price {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  margin: 0;
  padding: 10px 8px 9px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #6e00ff;
  text-align: center;
  line-height: 1.2;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 200ms var(--ex-ease), transform 200ms var(--ex-ease);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.ex-cell__price-unit {
  margin-inline-start: 3px;
  font-size: 0.62em;
  font-weight: 600;
  opacity: 0.72;
}

.ex-cell__stock {
  display: block;
  width: fit-content;
  max-width: calc(100% - 8px);
  margin: 0 auto 4px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.35;
  color: #9f1239;
  background: rgba(255, 228, 230, 0.94);
}

@media (hover: hover) {
  .ex-cell:hover .ex-cell__veil,
  .ex-cell:hover .ex-cell__price {
    opacity: 1;
  }
  .ex-cell:hover .ex-cell__price {
    transform: translateY(0);
  }
}

.ex-cell.is-pressed {
  transform: scale(0.985);
}

/* لمس موبایل: قیمت تا ۲ثانیه بعد از برداشتن دست می‌ماند */
.ex-cell.is-price-on .ex-cell__veil,
.ex-cell.is-price-on .ex-cell__price {
  opacity: 1;
}

.ex-cell.is-price-on .ex-cell__price {
  transform: translateY(0);
}

/* پیش‌نمایش بزرگ — tap / کلیک چپ */
.ex-zoom {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: block;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: y mandatory;
  overscroll-behavior-y: contain;
  background: rgba(8, 8, 8, 0.88);
  touch-action: pan-y;
  cursor: zoom-out;
  opacity: 0;
  transition: opacity 280ms var(--ex-ease);
}

.ex-zoom[hidden] {
  display: none !important;
}

.ex-zoom.is-on {
  opacity: 1;
}

.ex-zoom__viewport {
  display: block;
  overflow: visible;
  touch-action: pan-y;
}

.ex-zoom__slide,
.ex-zoom__stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 100dvh;
  min-height: 100svh;
  flex-shrink: 0;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  box-sizing: border-box;
  scroll-snap-align: start;
}

.ex-zoom__stage {
  max-width: none;
  pointer-events: none;
}

.ex-zoom__img {
  max-width: 100%;
  max-height: min(62dvh, 68vh);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 10px;
  background: #111;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  user-select: none;
  -webkit-user-select: none;
  opacity: 0;
  transform: scale(1) translateY(0);
  transition: opacity 300ms var(--ex-ease);
  will-change: opacity;
}

.ex-zoom__img.is-ready {
  opacity: 1;
}

.ex-zoom.is-on .ex-zoom__stage > .ex-zoom__img.is-ready {
  animation: ex-zoom-fade 300ms var(--ex-ease) both;
}

.ex-zoom.is-live .ex-zoom__stage > .ex-zoom__img,
.ex-zoom.is-live .ex-zoom__stage .ex-zoom__name:not(:empty),
.ex-zoom.is-live .ex-zoom__stage > .ex-zoom__buy:not([hidden]),
.ex-zoom.is-live .ex-zoom__close {
  animation: none;
}

.ex-zoom__meta {
  text-align: center;
  padding: 0 10px 2px;
  max-width: 100%;
}

.ex-zoom__name {
  margin: 0;
  color: rgba(255, 255, 255, 0.94);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(8px);
}

.ex-zoom.is-on .ex-zoom__name:not(:empty) {
  opacity: 1;
  transform: none;
}

.ex-zoom.is-on .ex-zoom__stage .ex-zoom__name:not(:empty) {
  animation: ex-zoom-rise 300ms var(--ex-ease) 70ms both;
}

.ex-zoom__name:empty {
  display: none;
}

.ex-zoom__buy {
  pointer-events: auto;
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 4px 2px;
  opacity: 0;
  transform: translateY(10px);
}

.ex-zoom.is-on .ex-zoom__buy:not([hidden]) {
  opacity: 1;
  transform: none;
}

.ex-zoom.is-on .ex-zoom__stage > .ex-zoom__buy:not([hidden]) {
  animation: ex-zoom-rise 320ms var(--ex-ease) 90ms both;
}

.ex-zoom__slide .ex-zoom__name {
  opacity: 1;
  transform: none;
  animation: none;
}

.ex-zoom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(32, 32, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  touch-action: pan-y;
  overscroll-behavior: none;
}

.ex-zoom-row__btn {
  flex: 0 0 auto;
  min-width: 108px;
  border: none;
  border-radius: 20px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  background: #6e00ff;
  cursor: pointer;
}

.ex-zoom-row__btn:disabled,
.ex-zoom-row__btn[aria-disabled="true"] {
  background: #828282;
  cursor: not-allowed;
}

.ex-zoom-row__btn.is-busy {
  opacity: 0.72;
  pointer-events: none;
}

.ex-zoom-row__side {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.ex-zoom-row__price {
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ex-zoom-row__price-unit {
  margin-inline-start: 3px;
  font-size: 0.68em;
  font-weight: 600;
  opacity: 0.78;
}

.ex-zoom-qty {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border-radius: 23px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(20, 20, 20, 0.08);
}

.ex-zoom-qty.is-locked {
  pointer-events: none;
}

.ex-zoom-qty__btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 16px;
  background: #0f766e;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ex-zoom-qty__btn:disabled {
  background: #828282;
  cursor: not-allowed;
}

.ex-zoom-qty__input {
  width: 52px;
  height: 30px;
  border: none;
  background: transparent;
  text-align: center;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: #141414;
}

.ex-zoom__close {
  pointer-events: auto;
  margin-top: 4px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
}

.ex-zoom.is-on .ex-zoom__close {
  opacity: 1;
  animation: ex-zoom-rise 260ms var(--ex-ease) 180ms both;
}

.ex-zoom-qty__btn,
.ex-zoom-row__btn {
  touch-action: manipulation;
}

.ex-zoom__toast {
  position: fixed;
  top: max(16px, env(safe-area-inset-top, 0px));
  left: 50%;
  bottom: auto;
  transform: translateX(-50%) translateY(-8px);
  pointer-events: none;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(20, 20, 20, 0.88);
  color: #fff;
  font-size: 0.82rem;
  z-index: 140;
  opacity: 0;
  transition: opacity 160ms var(--ex-ease), transform 160ms var(--ex-ease);
}

.ex-zoom__toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@keyframes ex-zoom-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes ex-zoom-rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ex-zoom,
  .ex-zoom.is-on .ex-zoom__img,
  .ex-zoom.is-on .ex-zoom__img.is-ready,
  .ex-zoom.is-on .ex-zoom__name:not(:empty),
  .ex-zoom.is-on .ex-zoom__buy:not([hidden]),
  .ex-zoom.is-on .ex-zoom__close,
  .ex-zoom__track.is-anim {
    animation: none;
    transition: none;
    opacity: 1;
    transform: none;
  }
}

body.ex-zooming {
  overflow: hidden;
}

body.ex-zooming .bottom-nav.hp-bottom-nav {
  visibility: hidden;
  pointer-events: none;
  transform: translateY(100%);
  opacity: 0;
}

.ex-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 22px 12px;
  color: var(--ex-muted);
  font-size: 0.9rem;
}

.ex-status[hidden] {
  display: none;
}

.ex-status.is-error {
  color: #b91c1c;
}

.ex-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid color-mix(in srgb, var(--ex-ink) 15%, transparent);
  border-top-color: var(--ex-accent);
  border-radius: 50%;
  animation: ex-spin 0.7s linear infinite;
}

.ex-sentinel {
  height: 1px;
  width: 100%;
  pointer-events: none;
}

.ex-empty {
  text-align: center;
  padding: 64px 20px;
  color: var(--ex-muted);
}

.ex-empty strong {
  display: block;
  color: var(--ex-ink);
  font-size: 1.1rem;
  margin-bottom: 8px;
}

@keyframes ex-spin {
  to { transform: rotate(360deg); }
}

@keyframes ex-cell-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ex-cell,
  .ex-cell__img,
  .ex-cell__veil,
  .ex-cell__price,
  .ex-cell__stock,
  .ex-zoom,
  .ex-zoom__img,
  .ex-spinner {
    animation: none !important;
    transition: none !important;
  }
  .ex-cell__img {
    opacity: 1;
    transform: none;
  }
}
