/* FASE NUEVE · Grabado personalizado (v01): editor con vista previa sobre la foto real del producto.
   Funciona igual en claro y oscuro y desde 320 px. */

.f9eng-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99990;
  background: rgba(2, 6, 12, .72);
  backdrop-filter: blur(3px);
}

html.f9eng-open { overflow: hidden; }

.f9eng {
  position: fixed;
  z-index: 99991;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(600px, calc(100vw - 24px));
  max-height: min(92vh, 900px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: clamp(18px, 4vw, 26px);
  border-radius: 22px;
  background: #fff;
  color: #0b0d12;
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .65);
  /* Columna flexible: con el modal desplazable cada bloque conserva su alto real (la vista previa no se aplasta). */
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.f9eng > * { flex: 0 0 auto; }

.f9eng__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.f9eng__kicker { display: block; font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: #0b7d4b; }
.f9eng h2 { margin: 4px 0 0; font-size: clamp(1.05rem, 3.4vw, 1.3rem); letter-spacing: .01em; }
.f9eng__close { appearance: none; border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; font-size: 26px; line-height: 1; cursor: pointer; color: inherit; }
.f9eng__close:hover { background: rgba(11, 13, 18, .07); }
.f9eng__help, .f9eng__warning { margin: 0; font-size: .82rem; line-height: 1.5; opacity: .78; }
.f9eng__warning { font-size: .76rem; opacity: .68; }
.f9eng .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; }

/* Vista previa: la foto del estuche con el grabado encima, en el mismo sitio donde lo hace Apple.
   La posición y el tamaño llegan del producto (preview_box) como variables; aquí están los valores por defecto. */
.f9eng__preview {
  position: relative;
  margin: 0;
  border-radius: 18px;
  overflow: hidden;
  background: #f2f3f5;
  container-type: inline-size;
}
.f9eng__preview img { display: block; width: 100%; height: auto; }
.f9eng__stage {
  position: absolute;
  left: var(--f9eng-x, 50%);
  top: var(--f9eng-y, 57.5%);
  transform: translate(-50%, -50%);
  width: var(--f9eng-w, 42%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: .04em;
  min-height: 1.2em;
  /* Tipografía y tinta del grabado láser: gris suave sobre el blanco del estuche. */
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  font-size: calc(var(--f9eng-size, 3.15) * 1cqw);
  font-weight: 400;
  letter-spacing: .05em;
  line-height: 1.05;
  color: #9aa0a6;
  text-shadow: 0 .04em 0 rgba(255, 255, 255, .92);
  white-space: pre;
  text-align: center;
  overflow: hidden;
  pointer-events: none;
}
@supports not (container-type: inline-size) {
  .f9eng__stage { font-size: clamp(9px, 2.1vw, 18px); }
}
.f9eng__stage[data-length="0"]::after { content: ''; }
.f9eng__stage .f9eng__emoji { width: 1.12em; height: 1.12em; opacity: .46; }

/* En línea con el texto aunque la tienda ponga las imágenes en bloque. */
.f9eng__emoji { display: inline-block !important; width: 1.15em; height: 1.15em; vertical-align: -.2em; object-fit: contain; }

.f9eng__label { font-size: .78rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.f9eng__field { display: grid; gap: 6px; }
.f9eng__input {
  min-height: 52px;
  padding: 13px 14px;
  border: 1px solid rgba(11, 13, 18, .3);
  border-radius: 14px;
  background: #fff;
  font-size: 1.05rem;
  line-height: 1.4;
  letter-spacing: .04em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.f9eng__input:focus-visible { outline: 2px solid rgb(var(--f9-accent-rgb, 255, 90, 31)); outline-offset: 1px; }
.f9eng__counter { margin: 0; justify-self: end; font-size: .76rem; font-variant-numeric: tabular-nums; opacity: .7; }
.f9eng__counter.is-full { color: #b3261e; opacity: 1; }
.f9eng__error { margin: 0; font-size: .8rem; color: #b3261e; }

/* Selector de iconos: categorías, buscador y rejilla. */
.f9eng__picker { display: grid; gap: 10px; }
.f9eng__picker-head { display: grid; gap: 8px; }
.f9eng__tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.f9eng__tab {
  appearance: none;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(11, 13, 18, .16);
  border-radius: 999px;
  background: #fff;
  color: inherit;
  font: inherit;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
}
.f9eng__tab:hover { background: rgba(11, 13, 18, .05); }
.f9eng__tab[aria-selected="true"] { border-color: transparent; background: #0b0d12; color: #fff; }
.f9eng__tab:focus-visible { outline: 2px solid rgb(var(--f9-accent-rgb, 255, 90, 31)); outline-offset: 1px; }
.f9eng__search input {
  width: 100%;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(11, 13, 18, .18);
  border-radius: 12px;
  background: #f7f8fa;
  font: inherit;
  font-size: .88rem;
}
.f9eng__search input:focus-visible { outline: 2px solid rgb(var(--f9-accent-rgb, 255, 90, 31)); outline-offset: 1px; }
.f9eng__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 4px;
  max-height: 208px;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 6px;
  border: 1px solid rgba(11, 13, 18, .12);
  border-radius: 14px;
  background: #f7f8fa;
}
.f9eng__empty { margin: 0; font-size: .82rem; opacity: .7; }
.f9eng__emoji-btn { appearance: none; border: 0; background: transparent; border-radius: 10px; min-height: 44px; display: grid; place-items: center; cursor: pointer; }
.f9eng__emoji-btn img { width: 26px; height: 26px; object-fit: contain; }
.f9eng__emoji-btn:hover { background: rgba(11, 13, 18, .07); }
.f9eng__emoji-btn:focus-visible { outline: 2px solid rgb(var(--f9-accent-rgb, 255, 90, 31)); outline-offset: 1px; }

.f9eng__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.f9eng__btn {
  appearance: none;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid rgba(11, 13, 18, .25);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .12em;
  cursor: pointer;
}
.f9eng__btn:hover { background: rgba(11, 13, 18, .06); }
.f9eng__btn--primary { border-color: transparent; background: #0b0d12; color: #fff; }
.f9eng__btn--primary:hover { background: #22262f; }

@media (max-width: 480px) {
  .f9eng { width: 100%; max-width: 100%; left: 0; bottom: 0; top: auto; transform: none; border-radius: 22px 22px 0 0; max-height: 94vh; }
  .f9eng__grid { max-height: 168px; }
  .f9eng__actions { flex-direction: column-reverse; }
  .f9eng__btn { width: 100%; }
}

/* Vista previa pequeña dentro de la ficha del producto, junto al botón de grabado. */
.cx-engraving__preview {
  width: min(240px, 100%);
  margin: 12px 0 0;
  border-radius: 16px;
  border: 1px solid rgba(127, 127, 127, .18);
}

/* Resumen del grabado donde ya se eligió (ficha, carrito, checkout, Cuenta F9). */
.f9eng-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .82rem; }
.f9eng-line span { font-size: 10px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; opacity: .7; }
.f9eng-line b { font-weight: 700; letter-spacing: .06em; display: inline-flex; align-items: center; gap: 1px; }
