:root {
  --bg: #ffffff;
  --surface: #f5f5f7;
  --surface-2: #ebebef;
  --label: #1d1d1f;
  --label-2: #6e6e73;
  --label-3: #86868b;
  --separator: rgba(0, 0, 0, 0.08);
  --accent: #0071e3;
  --co-yellow: #fcd116;
  --co-blue: #2b46c9;
  --co-red: #ce1126;
  --tag: #b64400;
  --radius: 22px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
body.no-scroll { overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 8px max(16px, env(safe-area-inset-left)) 8px max(16px, env(safe-area-inset-right));
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
}
.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--label);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.topbar__brand img { width: 30px; height: auto; }
.topbar__brand b { font-weight: 400; color: var(--label-2); }

/* ---------- Hero ---------- */

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 16px 8px;
}
.hero__logo {
  width: min(260px, 64vw);
  height: auto;
  animation: rise 0.9s var(--ease) both;
}
.hero__lead {
  margin: 24px 0 0;
  max-width: 28ch;
  color: var(--label-2);
  font-size: 1.1875rem;
  animation: rise 0.9s 0.1s var(--ease) both;
}

/* ---------- Tabs & chips ---------- */

.tabs {
  display: flex;
  gap: 4px;
  width: fit-content;
  margin: 36px auto 0;
  padding: 4px;
  background: var(--surface);
  border-radius: 999px;
}
.tabs__btn {
  min-height: 40px;
  min-width: 110px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--label-2);
  font-weight: 600;
  transition: background 0.25s var(--ease), color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.tabs__btn.is-active {
  background: #fff;
  color: var(--label);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 4px 12px rgba(0, 0, 0, 0.06);
}

.panel { max-width: 1200px; margin: 0 auto; padding: 0 16px 72px; }

.filters {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 24px 0 32px;
}
.chip {
  min-height: 36px;
  padding: 0 16px;
  border: 1px solid var(--separator);
  border-radius: 999px;
  background: #fff;
  color: var(--label-2);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: all 0.2s var(--ease);
}
.chip:hover { color: var(--label); border-color: rgba(0, 0, 0, 0.2); }
.chip.is-active { color: #fff; background: var(--label); border-color: var(--label); }
@media (max-width: 420px) {
  /* Una sola fila deslizable en pantallas pequeñas */
  .filters {
    flex-wrap: nowrap;
    justify-content: flex-start;
    gap: 6px;
    margin-left: -16px;
    margin-right: -16px;
    padding: 2px 16px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .filters::-webkit-scrollbar { display: none; }
  .chip { flex: none; padding: 0 12px; font-size: 0.875rem; }
  /* Centra si caben; si no, se deslizan sin cortar el primero */
  .chip:first-child { margin-left: auto; }
  .chip:last-child { margin-right: auto; }
}

/* ---------- Grid & cards ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}
@media (max-width: 599px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  overflow: hidden;
  animation: rise 0.6s calc(var(--i) * 60ms) var(--ease) both;
  transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease), background 0.35s var(--ease);
}
.card:hover {
  transform: translateY(-4px);
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04), 0 20px 50px -12px rgba(0, 0, 0, 0.16);
}
.card:active { transform: scale(0.98); }
.card__tag {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 1;
  color: var(--tag);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.card__media { aspect-ratio: 1; padding: 32px 20px 0; }
.card__media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.5s var(--ease);
}
.card:hover .card__media img { transform: scale(1.05); }
.card__body { display: flex; flex: 1; flex-direction: column; padding: 8px 20px 22px; }
.card h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.card__storage { margin: 2px 0 10px; color: var(--label-2); font-size: 0.875rem; }
.card__price {
  margin: auto 0 0;
  padding-top: 12px;
  font-size: 1.125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.card__price small {
  display: block;
  color: var(--label-3);
  font-size: 0.75rem;
  font-weight: 500;
}
@media (max-width: 599px) {
  .card__media { padding: 28px 12px 0; }
  .card__body { padding: 6px 14px 16px; }
  .card h3 { font-size: 1rem; }
  .card__price { font-size: 1rem; }
  .card__tag { top: 10px; left: 12px; font-size: 0.625rem; }
}

.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}

/* ---------- Empty ---------- */

.empty {
  max-width: 440px;
  margin: 48px auto 0;
  padding: 40px 24px;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  color: var(--label-2);
}
.empty__title { margin: 0 0 8px; color: var(--label); font-size: 1.5rem; font-weight: 700; }

/* ---------- Footer ---------- */

.footer {
  padding: 32px 16px calc(32px + env(safe-area-inset-bottom));
  background: var(--surface);
  text-align: center;
  color: var(--label-3);
  font-size: 0.8125rem;
}
.flag { display: flex; width: 120px; height: 3px; margin: 0 auto 16px; border-radius: 3px; overflow: hidden; }
.flag i:nth-child(1) { flex: 2; background: var(--co-yellow); }
.flag i:nth-child(2) { flex: 1; background: var(--co-blue); }
.flag i:nth-child(3) { flex: 1; background: var(--co-red); }

/* ---------- Detail sheet ---------- */

.sheet {
  --glow: #ccc;
  width: min(1000px, calc(100% - 48px));
  max-width: none;
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 0;
  border-radius: 28px;
  background: #fff;
  color: var(--label);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.35);
  overflow: auto;
}
.sheet::backdrop {
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.sheet[open] { animation: pop 0.4s var(--ease) both; }
.sheet[open]::backdrop { animation: fade 0.3s ease both; }
.sheet.is-closing { animation: pop-out 0.22s ease both; }
.sheet.is-closing::backdrop { animation: fade 0.22s ease reverse both; }

.sheet__inner { position: relative; display: grid; grid-template-columns: 1.1fr 1fr; }
.sheet__close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  color: var(--label-2);
  font-size: 1.75rem;
  line-height: 1;
  transition: background 0.2s;
}
.sheet__close:hover { background: rgba(0, 0, 0, 0.1); }

.sheet__media {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 32px 24px;
  background: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--glow) 22%, #fff) 0%, var(--surface) 70%);
  transition: background 0.5s var(--ease);
  overflow: hidden;
}

/* Visor 3D */
.viewer {
  position: relative;
  width: 100%;
  max-width: 500px;
  perspective: 1100px;
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.viewer.is-dragging { cursor: grabbing; }
.viewer__stage {
  position: relative;
  transform-style: preserve-3d;
  will-change: transform;
}
.viewer__stage img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 18px 24px rgba(0, 0, 0, 0.14));
  animation: zoom-in 0.7s 0.05s var(--ease) both;
  transition: opacity 0.16s ease, transform 0.35s var(--ease);
}
.viewer__stage img.is-swapping { opacity: 0; transform: scale(0.96); }
/* Reflejo de luz que se desplaza al girar, recortado a la silueta del celular */
.viewer__shine {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.55) 50%, transparent 65%);
  background-size: 300% 100%;
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mix-blend-mode: soft-light;
}
.viewer__shadow {
  width: 60%;
  height: 18px;
  margin: -6px auto 0;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.18), transparent);
}
.viewer__hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 12px 0 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--label-2);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: opacity 0.4s var(--ease);
}
.viewer__hint.is-hidden { opacity: 0; }

.sheet__info { display: flex; flex-direction: column; padding: 48px 36px 36px; }
.sheet__tag {
  margin: 0;
  color: var(--tag);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.sheet h2 {
  margin: 4px 0 12px;
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
}
.specs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 24px; padding: 0; list-style: none; }
.specs li {
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--label-2);
  font-size: 0.8125rem;
}

.label { margin: 0 0 10px; color: var(--label-2); font-size: 0.875rem; }
.label span { color: var(--label); font-weight: 500; }

.swatches--lg { gap: 12px; margin-bottom: 24px; }
.swatches--lg button {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15), 0 0 0 2px #fff, 0 0 0 3px transparent;
  transition: box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}
.swatches--lg button:hover { transform: scale(1.08); }
.swatches--lg button.is-active {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15), 0 0 0 3px #fff, 0 0 0 5px var(--accent);
}

.storage { display: flex; gap: 10px; margin-bottom: 28px; }
.storage button {
  flex: 1;
  max-width: 160px;
  min-height: 52px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 14px;
  background: #fff;
  font-weight: 600;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.storage button.is-active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.sheet__buy { margin-top: auto; padding-top: 20px; border-top: 1px solid var(--separator); }
.price-label { margin: 0; color: var(--label-2); font-size: 0.875rem; }
.price {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

/* Pantallas bajas (celular acostado): el celular se ajusta a la altura */
@media (min-width: 768px) {
  .viewer { max-width: min(500px, calc(100dvh - 170px)); }
}
@media (min-width: 768px) and (max-height: 560px) {
  .sheet { max-height: calc(100dvh - 24px); }
  .sheet__media { padding: 20px 24px 12px; }
  .viewer { max-width: min(500px, calc(100dvh - 110px)); }
  .viewer__hint { margin-top: 4px; }
  .sheet__info { padding: 24px 28px 20px; }
  .specs { margin-bottom: 14px; }
  .swatches--lg { margin-bottom: 14px; }
  .storage { margin-bottom: 16px; }
  .storage button { min-height: 44px; }
  .sheet__buy {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin: 0 -28px -20px;
    padding: 12px 28px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
  .price { font-size: 1.5rem; }
}

/* Móvil: hoja inferior */
@media (max-width: 767px) {
  .sheet {
    width: 100%;
    max-height: 94dvh;
    margin: auto 0 0;
    border-radius: 28px 28px 0 0;
  }
  .sheet[open] { animation: slide-up 0.45s var(--ease) both; }
  .sheet.is-closing { animation: slide-down 0.22s ease both; }
  .sheet__inner { grid-template-columns: 1fr; }
  .sheet__media { padding: 36px 24px 16px; }
  .viewer { max-width: 340px; }
  .sheet__info { padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); }
  .sheet__buy {
    position: sticky;
    bottom: 0;
    margin: 0 -20px calc(-20px - env(safe-area-inset-bottom));
    padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
  }
  .price { font-size: 1.5rem; }
}

/* ---------- Animaciones ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(12px); } }
@keyframes pop-out { to { opacity: 0; transform: scale(0.96); } }
@keyframes slide-up { from { transform: translateY(100%); } }
@keyframes slide-down { to { transform: translateY(100%); } }
@keyframes zoom-in { from { opacity: 0; transform: scale(0.85); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
