/* 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(560px, calc(100vw - 24px));
  max-height: min(92vh, 860px);
  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; }

/* Vista previa: la foto del estuche con el grabado encima, centrado como en el producto real. */
.f9eng__preview { position: relative; margin: 0; border-radius: 18px; overflow: hidden; background: #f2f3f5; }
.f9eng__preview img { display: block; width: 100%; height: auto; }
.f9eng__stage {
  position: absolute;
  left: 50%;
  bottom: 21%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: 1px;
  width: 46%;
  min-height: 1.4em;
  color: #6b7280;
  font-family: "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(11px, 2.6vw, 17px);
  letter-spacing: .02em;
  white-space: pre;
  text-align: center;
}
.f9eng__stage[data-length="0"]::after { content: ''; }
.f9eng__stage .f9eng__emoji { width: 1.25em; height: 1.25em; }

/* 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; }

.f9eng__emojis { display: grid; gap: 8px; }
.f9eng__emojis-title { margin: 0; font-size: .78rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.f9eng__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 4px;
  max-height: 188px;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 6px;
  border: 1px solid rgba(11, 13, 18, .12);
  border-radius: 14px;
  background: #f7f8fa;
}
.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__actions { flex-direction: column-reverse; }
  .f9eng__btn { width: 100%; }
}

/* 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; }
