/* ═══════════════════════════════════════════════
   Vinyls — estilos
   La escena 3D vive en <canvas id="stage">; todo lo demás es HTML encima.
════════════════════════════════════════════════ */

:root {
  --font: 'Space Grotesk', ui-sans-serif, system-ui, sans-serif;
  --white: #fff;
  --muted: rgba(255, 255, 255, .7);
  --faint: rgba(255, 255, 255, .1);
  --ease: cubic-bezier(.65, 0, .35, 1);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --t-detail: .82s;

  /* Las escribe stage.js según el tamaño de pantalla */
  --S: 288px;   /* lado del disco central */
  --cx: 50vw;   /* centro del carrusel */
  --cy: 43vh;

  /* Alto de la app: lo calcula un script en <head> (corrige el modo app de iOS) */
  --app-h: 100vh;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);

  color-scheme: dark;
}

@media (prefers-reduced-motion: reduce) {
  :root { --t-detail: .26s; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: var(--app-h);
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
  color: var(--white);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, input:focus-visible { outline: 2px solid rgba(255, 255, 255, .8); outline-offset: 3px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Fondo ─────────────────────────────────────── */

#bg, #stage, #ui { position: fixed; top: 0; left: 0; width: 100%; height: var(--app-h); }

#bg { background: #000; overflow: hidden; }

.bg-art {
  position: absolute;
  inset: 0;
  -webkit-mask-image: linear-gradient(to bottom, #000 57%, transparent 100%);
          mask-image: linear-gradient(to bottom, #000 57%, transparent 100%);
}

.bg-img {
  position: absolute;
  left: 50%;
  top: -7.7%;
  width: max(250vw, 118vh);
  aspect-ratio: 1;
  translate: -50% 0;
  object-fit: cover;
  filter: blur(clamp(40px, 12vw, 90px)) saturate(1.15);
  opacity: 0;
  transition: opacity .7s ease;
  will-change: opacity;
}
.bg-img.is-on { opacity: 1; }

.bg-shade { position: absolute; inset: 0; background: rgba(0, 0, 0, .4); }

/* Horizontal: el mismo fondo girado; se oscurece hacia la izquierda */
body.is-landscape .bg-art {
  -webkit-mask-image: linear-gradient(to left, #000 57%, transparent 100%);
          mask-image: linear-gradient(to left, #000 57%, transparent 100%);
}
body.is-landscape .bg-img {
  left: auto;
  right: -7.7%;
  top: 50%;
  width: max(250vh, 118vw);
  translate: 0 -50%;
}

/* ── Escena ────────────────────────────────────── */

#stage {
  display: block;
  touch-action: none;
  outline: none;
  opacity: 0;
  transition: opacity .6s ease;
}
body.is-ready #stage { opacity: 1; }

#ui { pointer-events: none; }
#ui > * { pointer-events: auto; }

/* ── Vidrio (aprox. del efecto Glass de Figma) ── */

.glass {
  -webkit-backdrop-filter: blur(10px) saturate(170%);
          backdrop-filter: blur(10px) saturate(170%);
  box-shadow:
    inset 1.2px 1.2px 1px -.6px rgba(255, 255, 255, .62),
    inset -1px -1px 1px -.6px rgba(255, 255, 255, .26),
    inset 0 0 0 .5px rgba(255, 255, 255, .1),
    inset 0 0 18px rgba(255, 255, 255, .05);
}
.glass--light { background: rgba(0, 0, 0, .11); }
.glass--dark  { background: rgba(0, 0, 0, .71); }

/* ── Burbuja de cantidad ───────────────────────── */

#count {
  position: absolute;
  left: calc(var(--cx) + var(--S) / 2 - 15px);
  top: calc(var(--cy) - 29px);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  font-size: 28px;
  font-weight: 500;
  line-height: 1;
  pointer-events: none;
  transition: transform var(--t-detail) var(--ease), opacity .3s ease;
}
#count span { display: block; font-variant-numeric: tabular-nums; }
#count span.roll-up   { animation: roll-up .32s var(--ease-out); }
#count span.roll-down { animation: roll-down .32s var(--ease-out); }
@keyframes roll-up   { from { transform: translateY(70%); opacity: 0; } }
@keyframes roll-down { from { transform: translateY(-70%); opacity: 0; } }
body.is-empty #count { opacity: 0; }

/* Horizontal: la burbuja queda bajo el disco */
body.is-landscape #count {
  left: calc(var(--cx) - 29px);
  top: calc(var(--cy) + var(--S) / 2 - 16px);
}

/* ── Buscador + filtro ─────────────────────────── */

#dock {
  position: absolute;
  left: 0;
  right: 0;
  /* 23 px del borde como en el diseño; ya libra la barra de inicio del iPhone */
  bottom: max(23px, calc(var(--safe-b) - 10px));
  margin: 0 auto;
  max-width: 452px;
  padding: 0 20px;
  display: flex;
  gap: 16px;
  transition: transform var(--t-detail) var(--ease), opacity .3s ease;
}

.search {
  flex: 1;
  height: 58px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  padding: 0 10px 0 23px;
  cursor: text;
}
.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 16px;
  font-weight: 400;
  -webkit-appearance: none;
          appearance: none;
}
.search input::placeholder { color: var(--white); opacity: 1; }
.search input::-webkit-search-cancel-button { display: none; }
.search:focus-within { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .35); }

.search-clear {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.search-clear svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; opacity: .75; }

.round {
  position: relative;
  flex: none;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}
.round svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.round .dot {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .7);
}

/* Horizontal: buscador y filtro abajo a la izquierda */
body.is-landscape #dock {
  left: calc(20px + var(--safe-l));
  right: auto;
  bottom: max(14px, calc(var(--safe-b) - 10px));
  width: 364px;
  max-width: none;
  margin: 0;
  padding: 0;
  gap: 18px;
}

/* ── Estado vacío ──────────────────────────────── */

#empty {
  position: absolute;
  left: var(--cx);
  top: var(--cy);
  translate: -50% -50%;
  width: min(320px, 86vw);
  text-align: center;
}
#empty[hidden] { display: none; }
.empty-title { margin: 0 0 6px; font-size: 26px; font-weight: 500; }
.empty-text  { margin: 0 0 22px; font-size: 16px; color: var(--muted); line-height: 1.4; }
#empty .btn  { height: 52px; padding: 0 28px; font-size: 16px; }

/* ── Botones ───────────────────────────────────── */

.btn {
  height: 63px;
  border-radius: 80px;
  font-size: 18px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease, opacity .2s ease, background-color .2s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: default; transform: none; }
.btn--ghost { border: 1px solid var(--white); color: var(--white); }
.btn--solid { background: var(--white); color: #000; }

/* ── Detalle ───────────────────────────────────── */

#detail {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -29px;
  margin: 0 auto;
  max-width: 420px;
  border-radius: 24px;
  padding: 36px 0 77px;
  text-align: center;
  touch-action: none;  /* se arrastra hacia abajo para cerrar */
  transform: translateY(calc(100% + 40px));
  transition: transform var(--t-detail) var(--ease);
}
body.is-detail #detail { transform: none; transition-delay: .06s; }
#detail.is-dragging { transition: none; transition-delay: 0s; }
body.is-detail #count { transform: translateX(calc(50vw + 40px)); }
body.is-detail #dock { transform: translateY(calc(100% + 80px)); }

.detail-grip {
  position: absolute;
  top: 8px;
  left: 50%;
  width: 40px;
  height: 5px;
  margin-left: -20px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .4);
}

.detail-head { padding: 0 32px; }
#d-song {
  margin: 0 0 12px;
  font-size: 31px;
  font-weight: 500;
  line-height: 1.25;
  text-wrap: balance;
}
#d-artist, #d-album {
  margin: 0;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--muted);
  text-wrap: balance;
}
#d-album { margin-top: 3px; }

[data-rarity="common"]    { --rarity: #e9e9e9; }
[data-rarity="uncommon"]  { --rarity: #7be0a6; }
[data-rarity="rare"]      { --rarity: #8ab8ff; }
[data-rarity="exclusive"] { --rarity: #ffd36e; }

/* Obtenido / Repetidos, con − y + centrados en la línea entre ambos */
.detail-stock { position: relative; margin: 33px 30px 0; }
.detail-rows { margin: 0; }
.detail-rows > div {
  display: flex;
  justify-content: center;
  gap: .3em;
  border-top: 1px solid var(--faint);
  padding: 13px 0 12px;
  font-size: 20px;
  font-weight: 500;
  line-height: 26px;
  color: var(--muted);
}
.detail-rows > div:last-child { padding-bottom: 0; }
.detail-rows dt, .detail-rows dd { margin: 0; }
.detail-rows dd { font-variant-numeric: tabular-nums; }

.stepper {
  position: absolute;
  top: calc(52px - 29px);
  transition: transform .15s ease, opacity .2s ease;
}
.stepper:active { transform: scale(.94); }
.stepper:disabled { opacity: .35; cursor: default; transform: none; }
.stepper--minus { left: -14px; }
.stepper--plus  { right: -14px; }

.detail-actions { display: flex; justify-content: center; margin-top: 47px; }
.btn--close { height: 54px; padding: 0 56px; font-size: 18px; }

/* Horizontal: la tarjeta entra por la izquierda y se arrastra hacia la izquierda */
body.is-landscape #detail {
  left: -29px;
  right: auto;
  top: calc(8px + var(--safe-t));
  bottom: max(8px, calc(var(--safe-b) - 10px));
  width: calc(min(50.6vw, 470px) + 29px + var(--safe-l));
  max-width: none;
  margin: 0;
  padding: 22px 0 22px calc(29px + var(--safe-l));
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow-y: auto;
  touch-action: pan-y;
  transform: translateX(calc(-100% - 40px));
}
body.is-landscape.is-detail #detail { transform: none; }
body.is-landscape .detail-grip {
  top: 50%;
  left: auto;
  right: 8px;
  width: 5px;
  height: 40px;
  margin: -20px 0 0;
}
body.is-landscape .detail-stock { margin-top: 22px; }
body.is-landscape .detail-actions { margin-top: 24px; }
body.is-landscape.is-detail #count { transform: translateY(calc(50vh + 60px)); }

/* ── Hoja de filtros ───────────────────────────── */

#scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s ease;
}
body.is-sheet #scrim { opacity: 1; pointer-events: auto; }

#sheet {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(8px + var(--safe-b));
  margin: 0 auto;
  max-width: 440px;
  max-height: calc(100% - 24px - var(--safe-t) - var(--safe-b));
  display: flex;
  flex-direction: column;
  border-radius: 30px;
  padding: 10px 0 16px;
  transform: translateY(calc(100% + 40px));
  visibility: hidden;
  transition: transform .5s var(--ease-out), visibility 0s linear .5s;
}
body.is-sheet #sheet { transform: none; visibility: visible; transition: transform .5s var(--ease-out), visibility 0s; }

.sheet-grip { width: 38px; height: 5px; border-radius: 3px; margin: 0 auto 14px; background: rgba(255, 255, 255, .3); flex: none; }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px 4px;
  flex: none;
}
.sheet-kicker { margin: 0 0 4px; font-size: 13px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: rgba(255, 255, 255, .55); }
.sheet-stat { margin: 0; font-size: 18px; font-weight: 500; color: var(--muted); }
.sheet-stat b { color: var(--white); font-weight: 600; }

.ring {
  --p: 0;
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  background: conic-gradient(#fff calc(var(--p) * 1turn), rgba(255, 255, 255, .14) 0);
}
.ring::before { content: ''; position: absolute; inset: 4px; border-radius: 50%; background: #141414; }
.ring span { position: relative; }

.sheet-body { overflow-y: auto; padding: 0 22px; overscroll-behavior: contain; }

.field h3 { margin: 20px 0 9px; font-size: 13px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: rgba(255, 255, 255, .55); }

.seg {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 3px;
  border-radius: 15px;
  background: rgba(255, 255, 255, .08);
}
.seg button {
  height: 38px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  transition: background-color .2s ease, color .2s ease;
}
.seg button[aria-checked="true"] { background: #fff; color: #000; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  height: 36px;
  padding: 0 15px;
  border-radius: 99px;
  border: 1px solid rgba(255, 255, 255, .24);
  font-size: 14px;
  font-weight: 500;
  color: rgba(255, 255, 255, .85);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}
.chips[data-key="rarity"] button::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--rarity);
}
.chips button[aria-pressed="true"] { background: #fff; color: #000; border-color: #fff; }

.sheet-foot { display: flex; gap: 12px; padding: 22px 22px 0; flex: none; }
.sheet-foot .btn { flex: 1; height: 54px; font-size: 17px; }

.sync {
  margin: 14px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 12px;
  color: rgba(255, 255, 255, .5);
  flex: none;
}
.sync i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, .45); }
.sync.is-cloud i { background: #6ee7a0; box-shadow: 0 0 8px #6ee7a0; }
.sync.is-error i { background: #ff8a7a; }

/* ── Carga ─────────────────────────────────────── */

#boot {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--app-h);
  display: grid;
  place-items: center;
  background: #000;
  transition: opacity .6s ease, visibility 0s linear .6s;
}
body.is-ready #boot { opacity: 0; visibility: hidden; }
.boot-disc {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background:
    radial-gradient(circle, #eee 0 17%, transparent 18%),
    repeating-radial-gradient(circle, #111 0 2px, #1d1d1d 2px 4px);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .08);
  animation: spin 1.1s linear infinite;
}
.boot-disc::after { content: ''; display: block; width: 100%; height: 100%; border-radius: 50%; background: conic-gradient(from 20deg, transparent 0 30%, rgba(255,255,255,.18) 38%, transparent 46%); }
@keyframes spin { to { rotate: 1turn; } }
