/* Tienda en 3D: plaza con cinco puestos (Taller, Boutique, Tienda oficial,
   Mercadillo y Mostrador). El marcado lo genera marketView() en app.js y las
   etiquetas flotantes las crea shop/world.js. Se carga antes de glass.css, así
   que todo cuelga de #market para ganar en especificidad a las reglas de
   economy.css, cosmetics.css y del propio glass.css.

   Dos modos:
   - Inmersivo (por defecto): el escenario ocupa el alto visible, el panel de
     cada puesto se abre a la derecha (escritorio) o como hoja inferior (≤860px).
   - Sin 3D (data-status="failed"): cabecera normal, puestos como tarjetas y el
     panel como bloque debajo. */

/* ---------- Colores del escenario ---------- */

#market {
  --shop-chrome: 98px;                               /* barra superior flotante + aire de la página */
  --shop-foot: 14px;
  --shop-sky: linear-gradient(180deg, #bcdcff 0%, #e6f2ff 58%, #f5faff 100%);
  --shop-glass: rgba(255, 255, 255, .84);
  --shop-edge: rgba(255, 255, 255, .85);
  --shop-line: rgba(15, 23, 42, .09);
  --shop-chip: rgba(15, 23, 42, .06);
  --shop-shadow: 0 12px 32px rgba(15, 23, 42, .2), 0 2px 6px rgba(15, 23, 42, .08);
  --shop-stage-shadow: 0 18px 44px rgba(49, 46, 129, .14), 0 2px 6px rgba(15, 23, 42, .05);
  --shop-panel: rgba(244, 247, 252, .97);
  --shop-panel-edge: rgba(15, 23, 42, .1);
  --shop-card: #fff;
  --shop-card-edge: #e1e8f2;
  --shop-art: #edf2fa;
  --shop-plate: rgba(255, 255, 255, .97);
  --shop-plate-ink: #0f172a;
  --shop-plate-sub: #475569;
  --shop-ring: #fff;
  --shop-focus-a: #0b1220;
  --shop-focus-b: #fff;
  --shop-badge: #be123c;
}

html.theme-dark #market {
  --shop-sky: linear-gradient(180deg, #0a1226 0%, #14213f 62%, #1b2b4d 100%);
  --shop-glass: rgba(12, 19, 38, .72);
  --shop-edge: rgba(255, 255, 255, .13);
  --shop-line: rgba(255, 255, 255, .09);
  --shop-chip: rgba(255, 255, 255, .08);
  --shop-shadow: 0 12px 32px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .3);
  --shop-stage-shadow: 0 18px 46px rgba(0, 0, 0, .45);
  --shop-panel: rgba(19, 28, 46, .97);
  --shop-panel-edge: rgba(255, 255, 255, .11);
  --shop-card: #182338;
  --shop-card-edge: #2a3a56;
  --shop-art: #111a2c;
  --shop-plate: rgba(15, 23, 42, .94);
  --shop-plate-ink: #f1f5fb;
  --shop-plate-sub: #b6c2d9;
  --shop-ring: #0f172a;
  --shop-focus-a: #fff;
  --shop-focus-b: #0b1220;
  --shop-badge: #e11d48;
}

/* ---------- Escenario ---------- */

#market .shop-stage {
  --shop-panel-w: min(620px, max(46%, 360px));
  --shop-reserve: 0px;                               /* ancho que tapa el panel; centra los puestos en el resto */
  position: relative;
}

#market .shop-stage.has-panel {
  --shop-reserve: calc(var(--shop-panel-w) + 12px);
}

#market .shop-stage:not([data-status="failed"]) {
  height: calc(100vh - var(--shop-chrome) - var(--shop-foot));
  height: calc(100dvh - var(--shop-chrome) - var(--shop-foot));
  min-height: 520px;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid var(--shop-edge);
  border-radius: 24px;
  background: var(--shop-sky);
  box-shadow: var(--shop-stage-shadow);
}

/* La página no debe crecer más que la pantalla mientras se ve la plaza */
.app-shell .content:has(> #market.active) {
  padding-bottom: 14px;
}

/* Sin z-index propio a propósito: así la capa de etiquetas (z-index 1) compite en el
   mismo contexto que el título (0) y las etiquetas quedan siempre por encima de él. */
#market .shop-world-slot {
  position: absolute;
  inset: 0;
}

#market .shop-world {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#market .shop-world canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: pan-y;                               /* un dedo en vertical sigue desplazando la página */
  outline: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#market .shop-stage[data-status="failed"] .shop-world-slot {
  display: none;
}

/* ---------- Etiquetas flotantes sobre cada puesto ---------- */
/* shop/world.js coloca cada botón con su propio transform: aquí no se toca
   transform (ni se hace transición de él); el movimiento va con translate. */

#market .shop-labels {
  position: absolute;
  z-index: 1;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  transition: opacity .3s ease, visibility 0s linear 0s;
}

#market .shop-labels.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .3s ease, visibility 0s linear .3s;
}

#market .shop-labels.is-hidden .shop-label {
  pointer-events: none;
}

#market .shop-label {
  --c: var(--primary);
  position: absolute;
  top: 0;
  left: 0;
  width: max-content;
  max-width: 230px;
  min-height: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  margin: 0;
  padding: 7px 15px 10px;
  border: 2px solid var(--c);
  border-radius: 14px;
  background: var(--shop-plate);
  color: var(--shop-plate-ink);
  box-shadow: 0 8px 20px rgba(15, 23, 42, .3), 0 1px 3px rgba(15, 23, 42, .2);
  text-align: center;
  cursor: pointer;
  pointer-events: auto;
  will-change: transform;
  transition: opacity .2s ease, visibility 0s linear 0s, translate .18s ease, box-shadow .18s ease;
}

/* Flechita hacia el puesto; su relleno tapa el borde y se funde con la etiqueta */
#market .shop-label::after {
  position: absolute;
  bottom: -7px;
  left: 50%;
  width: 11px;
  height: 11px;
  border-right: 2px solid var(--c);
  border-bottom: 2px solid var(--c);
  border-bottom-right-radius: 3px;
  background: var(--shop-plate);
  content: '';
  transform: translateX(-50%) rotate(45deg);
  pointer-events: none;
}

#market .shop-label b {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: 'Manrope', sans-serif;
  font-size: 13.5px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -.01em;
  white-space: nowrap;
}

/* Punto con el color del puesto */
#market .shop-label b::before {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 3px rgba(128, 128, 128, .2);
  content: '';
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
  #market .shop-label b::before {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 30%, transparent);
  }
}

#market .shop-label small {
  max-width: 100%;
  overflow: hidden;
  color: var(--shop-plate-sub);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Contador de pendientes */
#market .shop-label i {
  position: absolute;
  top: -10px;
  right: -10px;
  min-width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 2px solid var(--shop-ring);
  border-radius: 99px;
  background: var(--shop-badge);
  color: #fff;
  padding: 0 5px;
  font-family: 'Manrope', sans-serif;
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
  line-height: 1;
}

#market .shop-label [hidden] {
  display: none !important;
}

#market .shop-label.is-hover {
  translate: 0 -3px;
  box-shadow: 0 12px 26px rgba(15, 23, 42, .36), 0 0 0 4px rgba(128, 128, 128, .22);
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
  #market .shop-label.is-hover {
    box-shadow: 0 12px 26px rgba(15, 23, 42, .36), 0 0 0 4px color-mix(in srgb, var(--c) 32%, transparent);
  }
}

/* Fuera de pantalla: se desvanece y deja de recibir clics */
#market .shop-label.is-off {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .2s ease, visibility 0s linear .2s;
}

#market .shop-label:focus-visible {
  outline: 3px solid var(--shop-focus-a);
  outline-offset: 3px;
}

/* ---------- Montando la plaza ---------- */

#market .shop-loading {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  display: none;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 10px 18px 10px 14px;
  border: 1px solid var(--shop-edge);
  border-radius: 99px;
  background: var(--shop-glass);
  color: var(--ink);
  box-shadow: var(--shop-shadow);
  font-size: 13px;
  font-weight: 700;
  translate: -50% -50%;
  pointer-events: none;
}

#market .shop-stage[data-status="loading"] .shop-loading {
  display: inline-flex;
}

#market .shop-loading::before {
  width: 17px;
  height: 17px;
  flex: none;
  border: 2.5px solid rgba(128, 128, 128, .3);
  border-top-color: var(--primary);
  border-radius: 50%;
  content: '';
  animation: shop-spin .8s linear infinite;
}

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

/* ---------- Título sobre el cielo ---------- */

#market .shop-eyebrow {
  display: block;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .12em;
  line-height: 1.3;
  text-transform: uppercase;
}

#market .shop-title h2 {
  margin: 2px 0 0;
  color: var(--ink);
  font-family: 'Manrope', sans-serif;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.15;
}

#market .shop-title p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.4;
}

#market .shop-stage:not([data-status="failed"]) .shop-title {
  position: absolute;
  z-index: 0;
  top: 14px;
  left: 14px;
  max-width: min(360px, calc(100% - var(--shop-reserve) - 28px));
  padding: 9px 14px 10px;
  border: 1px solid var(--shop-edge);
  border-radius: 18px;
  background: var(--shop-glass);
  box-shadow: var(--shop-shadow);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  backdrop-filter: blur(14px) saturate(160%);
  pointer-events: none;
}

#market .shop-stage:not([data-status="failed"]) .shop-title .shop-eyebrow {
  color: var(--primary);
}

/* ---------- Puestos (pestañas) ---------- */

#market .shop-tab {
  --c: var(--primary);
  position: relative;
  margin: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .18s ease, color .18s ease, box-shadow .18s ease;
}

#market .shop-tab-icon {
  display: grid;
  place-items: center;
  flex: none;
  background: rgba(128, 128, 128, .16);
  color: var(--ink);
  transition: background-color .18s ease, color .18s ease;
}

#market .shop-tab-icon svg {
  width: 20px;
  height: 20px;
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
  #market .shop-tab-icon {
    background: color-mix(in srgb, var(--c) 20%, transparent);
    color: color-mix(in srgb, var(--c) 70%, #0b1220);
  }

  html.theme-dark #market .shop-tab-icon {
    color: color-mix(in srgb, var(--c) 68%, #fff);
  }
}

#market .shop-tab-text {
  display: grid;
  min-width: 0;
  gap: 1px;
}

#market .shop-tab-text b {
  font-family: 'Manrope', sans-serif;
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: -.01em;
  line-height: 1.2;
  white-space: nowrap;
}

#market .shop-tab-text small {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
}

#market .shop-tab-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  border: 2px solid var(--shop-ring);
  border-radius: 99px;
  background: var(--shop-badge);
  color: #fff;
  padding: 0 5px;
  font-family: 'Manrope', sans-serif;
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
  line-height: 1;
}

#market .shop-tab:focus-visible {
  outline: 3px solid var(--shop-focus-a);
  outline-offset: -3px;
  box-shadow: inset 0 0 0 5px var(--shop-focus-b);
}

/* Barra flotante (modo inmersivo): centrada en la zona que deja libre el panel */
#market .shop-stage:not([data-status="failed"]) .shop-tabs {
  position: absolute;
  z-index: 3;
  bottom: 16px;
  left: calc((100% - var(--shop-reserve)) / 2);
  max-width: calc(100% - var(--shop-reserve) - 24px);
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 6px;
  border: 1px solid var(--shop-edge);
  border-radius: 22px;
  background: var(--shop-glass);
  box-shadow: var(--shop-shadow);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  translate: -50% 0;
}

#market .shop-stage:not([data-status="failed"]) .shop-tabs::-webkit-scrollbar {
  display: none;
}

#market .shop-stage:not([data-status="failed"]) .shop-tab {
  flex: none;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 16px;
  padding: 7px 16px 7px 8px;
  scroll-snap-align: center;
}

#market .shop-stage:not([data-status="failed"]) .shop-tab-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
}

#market .shop-stage:not([data-status="failed"]) .shop-tab.is-active {
  background: var(--c);
  color: #0b1220;                                    /* el texto oscuro cumple AA sobre los cinco colores */
  box-shadow: 0 4px 14px rgba(15, 23, 42, .26);
}

#market .shop-stage:not([data-status="failed"]) .shop-tab.is-active .shop-tab-icon {
  background: rgba(255, 255, 255, .42);
  color: #0b1220;
}

#market .shop-stage:not([data-status="failed"]) .shop-tab.is-active .shop-tab-text small {
  color: #0b1220;
}

@media (hover: hover) {
  #market .shop-stage:not([data-status="failed"]) .shop-tab:not(.is-active):hover {
    background: var(--shop-chip);
  }
}

/* Con el panel abierto sobra poco sitio: solo el puesto activo enseña su nombre */
#market .shop-stage.has-panel:not([data-status="failed"]) .shop-tab {
  padding-right: 8px;
}

#market .shop-stage.has-panel:not([data-status="failed"]) .shop-tab.is-active {
  padding-right: 16px;
}

#market .shop-stage.has-panel:not([data-status="failed"]) .shop-tab-text small,
#market .shop-stage.has-panel:not([data-status="failed"]) .shop-tab:not(.is-active) .shop-tab-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  margin: -1px;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Pantallas medianas: sin subtítulos para que quepan los cinco */
@media (max-width: 1180px) {
  #market .shop-stage:not([data-status="failed"]) .shop-tab-text small {
    display: none;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-tab {
    min-height: 48px;
    padding-right: 13px;
  }
}

/* ---------- Panel de cada puesto ---------- */

#market .shop-panel {
  --c: var(--primary);
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--shop-panel-edge);
  border-radius: 22px;
  background: var(--shop-panel);
  color: var(--ink);
  box-shadow: 0 20px 48px rgba(15, 23, 42, .26), 0 2px 8px rgba(15, 23, 42, .1);
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
  #market .shop-panel {
    background: linear-gradient(180deg, color-mix(in srgb, var(--c) 11%, transparent) 0, transparent 170px), var(--shop-panel);
  }
}

/* Acento con el color del puesto en el borde superior */
#market .shop-panel::before {
  position: absolute;
  z-index: 2;
  top: 0;
  right: 0;
  left: 0;
  height: 4px;
  background: var(--c);
  content: '';
  pointer-events: none;
}

#market .shop-stage:not([data-status="failed"]) .shop-panel {
  position: absolute;
  z-index: 4;
  top: 12px;
  right: max(12px, env(safe-area-inset-right, 0px));
  bottom: 12px;
  width: var(--shop-panel-w);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
}

/* Solo al abrir el puesto: en los renderizados siguientes no se anima nada.
   Se anima transform/opacity, que no cambian offsetWidth/offsetHeight (los mide el JS). */
#market .shop-stage:not([data-status="failed"]) .shop-panel.is-fresh {
  animation: shop-panel-in-x .42s cubic-bezier(.2, .8, .2, 1) both;
}

@keyframes shop-panel-in-x {
  from { opacity: 0; transform: translateX(34px); }
  to { opacity: 1; transform: none; }
}

@keyframes shop-panel-in-y {
  from { opacity: 0; transform: translateY(44px); }
  to { opacity: 1; transform: none; }
}

#market .shop-panel-head {
  position: relative;
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 18px 14px 12px 10px;
  border-bottom: 1px solid var(--shop-line);
}

#market .shop-back {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 0;
  border: 0;
  border-radius: 12px;
  background: var(--shop-chip);
  color: var(--ink);
  padding: 0 14px 0 8px;
  font-size: 13px;
  font-weight: 700;
  transition: background-color .18s ease;
}

#market .shop-back svg {
  width: 18px;
  height: 18px;
  flex: none;
}

@media (hover: hover) {
  #market .shop-back:hover {
    background: rgba(128, 128, 128, .22);
  }
}

#market .shop-back:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

#market .shop-panel-title {
  min-width: 0;
  flex: 1 1 110px;
}

#market .shop-panel-title .shop-eyebrow {
  overflow-wrap: anywhere;
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
  #market .shop-panel-title .shop-eyebrow {
    color: color-mix(in srgb, var(--c) 62%, var(--ink));
  }

  html.theme-dark #market .shop-panel-title .shop-eyebrow {
    color: color-mix(in srgb, var(--c) 70%, #fff);
  }
}

#market .shop-panel-title h3 {
  margin: 2px 0 0;
  color: var(--ink);
  font-family: 'Manrope', sans-serif;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

#market .shop-panel-head > .primary {
  flex: none;
  margin-left: auto;
  white-space: nowrap;
}

/* Paneles estrechos (≈360-420px): «Plaza» se queda en la flecha para que el botón de
   acción quepa en la misma fila. El nombre accesible sigue siendo «Volver a la plaza». */
@media (max-width: 1240px) {
  #market .shop-back {
    min-width: 40px;
    justify-content: center;
    padding: 0 8px;
  }

  #market .shop-back span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    margin: -1px;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

#market .shop-panel-body {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  align-content: start;
  gap: 14px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px max(20px, env(safe-area-inset-bottom, 0px));
}

#market .shop-panel-body > * {
  min-width: 0;
}

/* ---------- Contenido del panel (componentes de economy.css y cosmetics.css) ---------- */

#market .shop-intro {
  margin: 0;
  border-left: 3px solid var(--c);
  padding: 2px 0 2px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

#market .shop-panel .card {
  margin: 0;
  padding: 16px;
  border: 1px solid var(--shop-card-edge);
  border-radius: 16px;
  background: var(--shop-card);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

#market .shop-panel .card:hover {
  border-color: var(--shop-card-edge);
  background: var(--shop-card);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
}

#market .shop-panel .card-head {
  margin-bottom: 12px;
  gap: 10px;
}

#market .shop-panel .card h3 {
  font-size: 15px;
}

/* Rejillas pensadas para una página entera: aquí una columna y sin scroll propio */
#market .shop-panel .eco-offer-grid {
  grid-template-columns: 1fr;
  gap: 12px;
  max-height: none;
  margin: 0;
  overflow: visible;
}

#market .shop-panel .eco-offer {
  gap: 10px;
}

#market .shop-panel .eco-offer p {
  font-size: 13px;
}

#market .shop-panel .eco-offer.is-featured,
#market .shop-panel .eco-offer.is-featured:hover {
  border-color: var(--eco-gold);
  box-shadow: 0 0 0 1px var(--eco-gold) inset;
}

#market .shop-panel .eco-offer-foot {
  flex-wrap: wrap;
}

#market .shop-panel .eco-offer-actions {
  align-items: center;
}

/* Botones con icono: el svg de los iconos sueltos no trae tamaño propio */
#market .shop-panel .compact-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

#market .shop-panel .compact-btn svg {
  width: 15px;
  height: 15px;
  flex: none;
}

#market .shop-panel .eco-market-side {
  grid-template-columns: 1fr;
}

#market .shop-panel .eco-stats {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
}

#market .shop-panel .eco-stat {
  border-color: var(--shop-card-edge);
  background: var(--shop-card);
}

#market .shop-panel .eco-disputes {
  margin: 0;
}

#market .shop-panel .eco-orders,
#market .shop-panel .eco-tx-list {
  max-height: none;
  overflow: visible;
}

#market .shop-panel .subject-chips {
  margin: 0;
}

#market .shop-panel .eco-note {
  margin: 12px 0 0;
}

#market .shop-panel .eco-shop li {
  gap: 12px;
}

/* Boutique: la tarjeta grande de Apariencias se funde con el panel */
#market .shop-panel .cosmetics-market,
#market .shop-panel .cosmetics-market:hover {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

#market .shop-panel .cosmetics-market .card-head {
  align-items: center;
  gap: 12px;
  margin: 0;
  padding-bottom: 14px;
}

#market .shop-panel .cosmetics-market .card-head h3 {
  margin: 4px 0;
  font-size: 19px;
}

#market .shop-panel .cosmetics-market .card-head p {
  max-width: none;
  font-size: 12.5px;
  line-height: 1.55;
}

#market .shop-panel .cosmetic-kind {
  margin-top: 18px;
}

#market .shop-panel .cosmetic-kind h4 {
  margin-bottom: 14px;
  font-size: 17px;
}

#market .shop-panel .cosmetic-tier {
  margin: 14px 0 22px;
}

#market .shop-panel .cosmetic-grid {
  grid-template-columns: repeat(auto-fill, minmax(164px, 1fr));
  gap: 12px;
}

/* VIP y administración: sin el ancho fijo de 580px ni la tarjeta en dos columnas */
#market .shop-panel .cosmetic-tier-vip .cosmetic-grid,
#market .shop-panel .cosmetic-tier-admin .cosmetic-grid {
  grid-template-columns: repeat(auto-fill, minmax(236px, 1fr));
}

#market .shop-panel .cosmetic-tier-vip .cosmetic-card,
#market .shop-panel .cosmetic-tier-admin .cosmetic-card {
  display: flex;
  padding-bottom: 15px;
}

#market .shop-panel .cosmetic-tier-vip .cosmetic-card-visual,
#market .shop-panel .cosmetic-tier-admin .cosmetic-card-visual {
  min-height: 170px;
}

#market .shop-panel .cosmetic-tier-vip .cosmetic-card-meta,
#market .shop-panel .cosmetic-tier-admin .cosmetic-card-meta {
  flex-direction: row;
  align-items: baseline;
  gap: 6px;
}

#market .shop-panel .cosmetic-tier-vip .cosmetic-card > button,
#market .shop-panel .cosmetic-tier-admin .cosmetic-card > button,
#market .shop-panel .cosmetic-tier-vip .cosmetic-card > .tag,
#market .shop-panel .cosmetic-tier-admin .cosmetic-card > .tag {
  align-self: start;
  margin-bottom: 0;
}

#market .shop-panel .cosmetic-card {
  border-radius: 18px;
}

#market .shop-panel .cosmetic-card:hover {
  border-color: #a9bdd9;
  box-shadow: 0 4px 10px #17284405;
  transform: none;
}

html.theme-dark #market .shop-panel .cosmetic-card:hover {
  border-color: #3f5170;
  box-shadow: none;
}

#market .shop-panel .cosmetic-card-visual {
  min-height: 150px;
  padding: 40px 16px 22px;
}

#market .shop-panel .cosmetic-card-meta strong {
  font-size: 13.5px;
}

#market .shop-panel .cosmetic-card-description {
  font-size: 12px;
}

#market .shop-panel .cosmetic-custom-offer {
  padding: 16px;
}

/* Taller: dos encargos a medida */
#market .shop-craft-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
  gap: 14px;
}

#market .shop-craft {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
}

#market .shop-craft-art {
  min-height: 132px;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 26px 16px;
  border: 1px solid var(--shop-card-edge);
  border-radius: 13px;
  background: var(--shop-art);
}

@supports (color: color-mix(in srgb, red 50%, blue)) {
  #market .shop-craft-art {
    background: radial-gradient(ellipse at 50% 0, color-mix(in srgb, var(--c) 20%, transparent), transparent 75%), var(--shop-art);
  }
}

#market .shop-craft-art .cosmetic-bubble-preview {
  max-width: 230px;
}

#market .shop-craft-text {
  display: grid;
  gap: 5px;
}

#market .shop-craft-text h4 {
  margin: 0;
  font-family: 'Manrope', sans-serif;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -.02em;
}

#market .shop-craft-text p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

#market .shop-craft-text strong {
  margin-top: 4px;
  font-family: 'Manrope', sans-serif;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -.03em;
}

#market .shop-craft > button {
  align-self: flex-start;
  margin-top: auto;
}

#market .shop-note {
  border-style: dashed;
  padding: 12px 14px;
}

#market .shop-note p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

#market .shop-note .link-btn {
  font-size: inherit;
}

/* ---------- Pantallas estrechas ---------- */

@media (max-width: 860px) {
  #market .shop-stage:not([data-status="failed"]) {
    border-radius: 20px;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-title {
    top: 10px;
    left: 10px;
    max-width: calc(100% - 20px);
    padding: 8px 12px 9px;
    border-radius: 15px;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-title h2 {
    font-size: 17px;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-title p {
    display: none;
  }

  #market .shop-panel-title h3 {
    font-size: 19px;
  }

  #market .shop-panel .cosmetic-grid {
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 10px;
  }
}

/* Hoja inferior: pantallas estrechas que NO son apaisadas bajas. Es la misma condición que usa app.js,
   escrita sin «and not (...)» (equivalente) para que la entiendan también los Safari antiguos:
   (max-width: 860px) and not ((orientation: landscape) and (max-height: 520px)) */
@media (max-width: 860px) and (orientation: portrait), (max-width: 860px) and (min-height: 520.02px) {
  #market .shop-stage.has-panel {
    --shop-reserve: 0px;
  }

  #market .shop-stage.has-panel:not([data-status="failed"]) .shop-title {
    display: none;
  }

  /* Barra inferior desplazable: icono y título */
  #market .shop-stage:not([data-status="failed"]) .shop-tabs {
    bottom: 10px;
    max-width: calc(100% - 20px);
    padding: 5px;
    border-radius: 20px;
    scroll-snap-type: x mandatory;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-tab {
    min-width: 72px;
    min-height: 56px;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 6px 11px;
    border-radius: 15px;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-tab-icon {
    width: 30px;
    height: 30px;
    border-radius: 10px;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-tab-text {
    justify-items: center;
    text-align: center;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-tab-text b {
    font-size: 11.5px;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-tab-text small {
    display: none;
  }

  /* Con el panel abierto, la barra sube y se queda solo con los iconos */
  #market .shop-stage.has-panel:not([data-status="failed"]) .shop-tabs {
    top: 10px;
    bottom: auto;
  }

  #market .shop-stage.has-panel:not([data-status="failed"]) .shop-tab,
  #market .shop-stage.has-panel:not([data-status="failed"]) .shop-tab.is-active {
    min-width: 48px;
    min-height: 48px;
    padding: 6px;
  }

  #market .shop-stage.has-panel:not([data-status="failed"]) .shop-tab-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    margin: -1px;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* Hoja inferior: altura estable (el JS la mide para encuadrar la cámara) */
  #market .shop-stage:not([data-status="failed"]) .shop-panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    height: 58vh;
    height: min(58dvh, calc(100% - 76px));
    border-right: 0;
    border-bottom: 0;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -12px 36px rgba(15, 23, 42, .24);
  }

  #market .shop-stage:not([data-status="failed"]) .shop-panel.is-fresh {
    animation-name: shop-panel-in-y;
  }

  /* Agarre decorativo */
  #market .shop-panel-head {
    padding: 22px 12px 10px 8px;
  }

  #market .shop-panel-head::before {
    position: absolute;
    top: 9px;
    left: 50%;
    width: 40px;
    height: 4px;
    border-radius: 4px;
    background: rgba(128, 128, 128, .42);
    content: '';
    transform: translateX(-50%);
  }

  #market .shop-panel-body {
    padding: 14px 14px max(20px, env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 650px) {
  #market {
    --shop-chrome: 90px;
    --shop-foot: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .app-shell .content:has(> #market.active) {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  /* El botón de acción baja a su propia fila si no cabe junto al título */
  #market .shop-panel-head > .primary {
    padding: 10px 12px;
  }

  #market .shop-panel .eco-stats {
    gap: 8px;
  }

  #market .shop-panel .card {
    padding: 14px;
  }
}

/* Pantallas bajas (móvil apaisado): el escenario puede ser más corto que 520px */
@media (max-height: 560px) {
  #market .shop-stage:not([data-status="failed"]) {
    min-height: 340px;
  }
}

/* Móvil apaisado (y cualquier ventana baja y ancha): el escenario ocupa justo el alto visible,
   el título se oculta y el panel va a un lado con ancho estable (min(46vw, 400px)). */
@media (orientation: landscape) and (max-height: 520px) {
  #market {
    --shop-chrome: 82px;
    --shop-foot: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .app-shell .content:has(> #market.active) {
    padding-top: 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  #market .shop-stage {
    --shop-panel-w: min(46vw, 400px);
  }

  #market .shop-stage:not([data-status="failed"]) {
    min-height: 0;
    border-radius: 20px;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-title {
    display: none;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-tabs {
    bottom: 8px;
    padding: 4px;
    border-radius: 18px;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-tab {
    min-height: 46px;
    padding: 5px 12px 5px 6px;
    border-radius: 14px;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-tab-icon {
    width: 32px;
    height: 32px;
    border-radius: 11px;
  }

  #market .shop-stage.has-panel:not([data-status="failed"]) .shop-tab {
    padding-right: 6px;
  }

  #market .shop-stage.has-panel:not([data-status="failed"]) .shop-tab.is-active {
    padding-right: 12px;
  }

  #market .shop-stage:not([data-status="failed"]) .shop-panel {
    top: 8px;
    right: max(8px, env(safe-area-inset-right, 0px));
    bottom: 8px;
    border-radius: 18px;
  }

  #market .shop-panel-head {
    padding: 14px 12px 8px 8px;
  }

  #market .shop-panel-title h3 {
    font-size: 18px;
  }

  #market .shop-panel-body {
    padding: 12px 12px max(16px, env(safe-area-inset-bottom, 0px));
  }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 650px) {
  #market {
    --shop-chrome: 74px;
  }
}

/* Táctil: objetivos de al menos 44px */
@media (pointer: coarse) {
  #market .shop-label {
    min-height: 46px;
  }

  #market .shop-back {
    min-height: 44px;
  }

  #market .shop-panel .compact-btn,
  #market .shop-panel .chip {
    min-height: 44px;
  }

  #market .shop-panel .link-btn {
    min-height: 32px;
  }
}

/* ---------- Sin 3D: cabecera normal, tarjetas y panel debajo ---------- */

#market .shop-stage[data-status="failed"] {
  display: grid;
  gap: 18px;
}

#market .shop-stage[data-status="failed"] .shop-loading {
  display: none;
}

#market .shop-stage[data-status="failed"] .shop-title {
  padding: 2px 2px 0;
}

#market .shop-stage[data-status="failed"] .shop-title .shop-eyebrow {
  color: var(--primary);
}

#market .shop-stage[data-status="failed"] .shop-title h2 {
  font-size: 28px;
}

#market .shop-stage[data-status="failed"] .shop-title p {
  max-width: 560px;
  font-size: 14px;
}

#market .shop-stage[data-status="failed"] .shop-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

#market .shop-stage[data-status="failed"] .shop-tab {
  min-height: 150px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--shop-card-edge);
  border-radius: 18px;
  background: var(--shop-card);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 6px 16px rgba(15, 23, 42, .05);
  transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}

#market .shop-stage[data-status="failed"] .shop-tab-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
}

#market .shop-stage[data-status="failed"] .shop-tab-text {
  gap: 3px;
}

#market .shop-stage[data-status="failed"] .shop-tab-text b {
  font-size: 16px;
  white-space: normal;
}

#market .shop-stage[data-status="failed"] .shop-tab-text small {
  font-size: 12.5px;
  white-space: normal;
}

#market .shop-stage[data-status="failed"] .shop-tab-badge {
  top: 14px;
  right: 14px;
}

#market .shop-stage[data-status="failed"] .shop-tab.is-active {
  border-color: var(--c);
  box-shadow: inset 0 4px 0 var(--c), 0 6px 16px rgba(15, 23, 42, .08);
}

@media (hover: hover) {
  #market .shop-stage[data-status="failed"] .shop-tab:not(.is-active):hover {
    border-color: var(--c);
    box-shadow: 0 8px 22px rgba(15, 23, 42, .1);
  }
}

#market .shop-stage[data-status="failed"] .shop-panel {
  border-radius: 20px;
}

#market .shop-stage[data-status="failed"] .shop-panel-body {
  overflow: visible;
}

/* Sin hoja inferior no hay agarre */
#market .shop-stage[data-status="failed"] .shop-panel-head {
  padding: 18px 16px 12px 12px;
}

#market .shop-stage[data-status="failed"] .shop-panel-head::before {
  display: none;
}

@media (max-width: 650px) {
  #market .shop-stage[data-status="failed"] .shop-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  #market .shop-stage[data-status="failed"] .shop-tab {
    min-height: 132px;
    padding: 14px;
  }

  #market .shop-stage[data-status="failed"] .shop-title h2 {
    font-size: 23px;
  }
}

/* ---------- Preferencias del sistema ---------- */

@media (prefers-reduced-motion: reduce) {
  #market .shop-stage .shop-panel.is-fresh {
    animation: none !important;
  }

  #market .shop-loading::before {
    animation: none !important;
  }

  #market .shop-labels,
  #market .shop-labels.is-hidden,
  #market .shop-label,
  #market .shop-label.is-off,
  #market .shop-tab,
  #market .shop-tab-icon,
  #market .shop-back {
    transition: none;
  }

  #market .shop-label.is-hover {
    translate: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  #market .shop-title,
  #market .shop-tabs,
  #market .shop-panel {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  #market .shop-title,
  #market .shop-tabs,
  #market .shop-loading {
    background: var(--shop-panel);
  }
}
