/* ==========================================================================
   Litocubo · Configurador
   Paleta caligráfica: tinta #3b2a1e sobre papel #f3ead8
   Diseño fluido: nada usa anchos mínimos fijos, para que quepa en móvil.
   ========================================================================== */

#wlc-configurator-container {
    --wlc-ink: #3b2a1e;
    --wlc-paper: #f3ead8;
    --wlc-accent: #3b82f6;
    --wlc-border: #e2e8f0;
    /* Grosor extra del trazo caligráfico (negrilla). Igual que BOLD_RATIO en el JS. */
    --wlc-bold: 0.035em;

    margin: 30px 0;
    padding: clamp(14px, 4vw, 28px);
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    border: 1px solid #eaeaea;

    /* Evita que el configurador empuje la página a lo ancho. */
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: break-word;
}

/* El tema puede no usar border-box; lo forzamos dentro del configurador. */
#wlc-configurator-container,
#wlc-configurator-container *,
#wlc-configurator-container *::before,
#wlc-configurator-container *::after {
    box-sizing: border-box;
}

#wlc-configurator-container h3 {
    margin: 0 0 6px;
    color: #1f2937;
    font-size: clamp(1.3rem, 5vw, 1.65rem);
    font-weight: 700;
    letter-spacing: -0.01em;
}

#wlc-configurator-container p.wlc-intro {
    color: #6b7280;
    font-size: clamp(0.85rem, 3.4vw, 0.95rem);
    margin: 0 0 clamp(16px, 4vw, 24px);
    max-width: 46ch;
}

.wlc-layout {
    display: flex;
    flex-wrap: wrap;
    gap: clamp(18px, 4vw, 32px);
    align-items: flex-start;
}

/* --------------------------------------------------------------------------
   Columna de controles
   -------------------------------------------------------------------------- */

.wlc-controls {
    flex: 1 1 330px;
    /* min-width:0 es lo que permite al elemento flex encogerse por debajo
       del ancho de su contenido en pantallas estrechas. */
    min-width: 0;
}

.wlc-photo-grid {
    display: grid;
    /* Escritorio: filas de 3 (Frontal · Derecha · Izquierda / Trasera · Superior).
       En móvil pasa a lista vertical (ver media query al final). */
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: clamp(10px, 3vw, 16px);
}

/* Tarjeta de cada cara lateral: etiqueta, selector Foto/Texto, recuadro y campo */
.wlc-face-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    min-width: 0;
}

.wlc-drop-zone {
    position: relative;
    min-width: 0;
    cursor: pointer;
}

.wlc-thumb-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border: 2px dashed #cbd5e1;
    border-radius: 10px;
    background: #fbfcfd;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* Permite dimensionar el texto del recuadro en proporción a su ancho (cqi). */
    container-type: inline-size;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.wlc-face-card[data-mode="photo"] .wlc-drop-zone:hover .wlc-thumb-wrap,
.wlc-drop-zone.dragover .wlc-thumb-wrap {
    border-color: var(--wlc-accent);
    background: #eff6ff;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.12);
}

.wlc-plus {
    font-size: clamp(1.5rem, 6vw, 1.9rem);
    font-weight: 300;
    color: #b6c2d1;
    line-height: 1;
    pointer-events: none;
}

.wlc-preview-thumb {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.wlc-drop-zone.has-image .wlc-preview-thumb {
    opacity: 1;
}

.wlc-drop-zone.has-image .wlc-thumb-wrap {
    border-style: solid;
    border-color: #cbd5e1;
}

.wlc-drop-zone.has-image .wlc-plus {
    display: none;
}

.wlc-drop-label {
    font-size: clamp(0.75rem, 3vw, 0.85rem);
    font-weight: 600;
    color: #475569;
    text-align: center;
    pointer-events: none;
}

.wlc-file-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

/* --------------------------------------------------------------------------
   Selector Foto / Texto
   Selectores con #id: los temas de WooCommerce estilizan <button> con fuerza.
   -------------------------------------------------------------------------- */

#wlc-configurator-container .wlc-mode-toggle {
    display: flex;
    gap: 2px;
    padding: 3px;
    background: #f1f5f9;
    border-radius: 999px;
}

#wlc-configurator-container .wlc-mode-btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 7px 4px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    background-image: none;
    box-shadow: none;
    color: #64748b;
    font-family: inherit;
    font-size: clamp(0.72rem, 3vw, 0.8rem);
    font-weight: 600;
    line-height: 1.2;
    text-transform: none;
    letter-spacing: normal;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

#wlc-configurator-container .wlc-mode-btn:hover {
    background: transparent;
    color: #1f2937;
}

#wlc-configurator-container .wlc-mode-btn.is-active {
    background: #ffffff;
    color: #1f2937;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.14);
}

#wlc-configurator-container .wlc-mode-btn:focus-visible {
    outline: 2px solid var(--wlc-accent);
    outline-offset: 1px;
}

/* --------------------------------------------------------------------------
   Cara lateral en modo Texto
   El data-mode de la tarjeta decide qué se ve; el JS solo cambia ese atributo.
   -------------------------------------------------------------------------- */

/* Negrilla caligráfica. Great Vibes solo tiene un grosor, así que se engruesa
   el trazo con el mismo factor que usa el canvas al generar el PNG. Se anula la
   negrita sintética del navegador para que la vista previa sea la pieza grabada. */
.wlc-tile-text,
.wlc-face-text {
    font-weight: 400;
    font-synthesis: none;
    -webkit-text-stroke: var(--wlc-bold) var(--wlc-ink);
    paint-order: stroke fill;
}

.wlc-tile-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8%;
    text-align: center;
    font-family: "Great Vibes", "Segoe Script", cursive;
    color: var(--wlc-ink);
    font-size: 1.35rem;
    font-size: 16cqi; /* Proporcional al recuadro donde se soporte */
    line-height: 1.15;
    word-break: break-word;
    overflow: hidden;
    pointer-events: none;
}

.wlc-tile-text:empty::before {
    content: "Tu texto";
    opacity: 0.35;
}

.wlc-face-card[data-mode="photo"] .wlc-tile-text,
.wlc-face-card[data-mode="photo"] .wlc-card-input {
    display: none;
}

.wlc-face-card[data-mode="text"] .wlc-plus,
.wlc-face-card[data-mode="text"] .wlc-preview-thumb,
.wlc-face-card[data-mode="text"] .wlc-file-input {
    display: none;
}

.wlc-face-card[data-mode="text"] .wlc-drop-zone {
    cursor: text;
}

.wlc-face-card[data-mode="text"] .wlc-thumb-wrap {
    background: var(--wlc-paper);
    border: 2px solid #e6dcc6;
}

/* Campo más compacto en la tarjeta; 1rem se mantiene para evitar el zoom de iOS */
.wlc-text-input.wlc-card-input {
    padding: 8px 10px;
}

/* --------------------------------------------------------------------------
   Campo de texto de cada tarjeta
   -------------------------------------------------------------------------- */

.wlc-text-input {
    width: 100%;
    max-width: 100%;
    padding: 11px 14px;
    font-size: 1rem; /* 1rem evita el zoom automático de iOS al enfocar */
    border: 2px solid #cbd5e1;
    border-radius: 10px;
    background: #fbfcfd;
    color: #1f2937;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.wlc-text-input:focus {
    outline: none;
    border-color: var(--wlc-accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.wlc-text-hint {
    display: block;
    margin-top: clamp(12px, 3vw, 16px);
    font-size: 0.8rem;
    color: #94a3b8;
}

/* --------------------------------------------------------------------------
   Vista 3D
   -------------------------------------------------------------------------- */

#wlc-3d-preview {
    flex: 1 1 340px;
    min-width: 0;
    width: 100%;
    min-height: clamp(300px, 88vw, 460px);
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background: radial-gradient(circle at 50% 40%, #ffffff 0%, #eef2f7 100%);
    border: 1px solid var(--wlc-border);
    border-radius: 12px;
}

.wlc-scene {
    /* El cubo se adapta al ancho disponible. Las caras usan la mitad de este
       valor en translateZ, así que todo escala junto. */
    --wlc-cube-size: min(230px, 46vw);

    width: var(--wlc-cube-size);
    height: var(--wlc-cube-size);
    perspective: 1000px;

    /* Al girar, la esquina del cubo sobresale hasta (√3/2 − 1/2) ≈ 0,37 veces
       su lado por cada borde. Reservamos 0,42 para que nunca se recorte ni
       pise el texto de ayuda, en cualquier tamaño de pantalla. */
    margin: calc(var(--wlc-cube-size) * 0.42) auto;

    /* Solo el cubo captura el gesto táctil; el resto del panel deja
       que la página siga haciendo scroll con el dedo. */
    touch-action: none;
}

.wlc-cube {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-20deg) rotateY(-30deg);
    cursor: grab;
}

.wlc-cube:active {
    cursor: grabbing;
}

.wlc-cube-face {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fafafa;
    border: 1px solid #d8dde3;
    background-size: cover;
    background-position: center;
    /* Efecto litofanía aproximado */
    filter: grayscale(100%) contrast(1.15) brightness(1.08);
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.5);
    transition: background-image 0.2s ease-in;
}

.wlc-face-ph {
    font-size: calc(var(--wlc-cube-size) * 0.28);
    font-weight: 300;
    color: #d3d9e0;
    pointer-events: none;
    user-select: none;
}

.wlc-cube-face.has-image .wlc-face-ph,
.wlc-cube-face.is-text .wlc-face-ph {
    display: none;
}

.wlc-face-front  { transform: rotateY(0deg)    translateZ(calc(var(--wlc-cube-size) / 2)); }
.wlc-face-right  { transform: rotateY(90deg)   translateZ(calc(var(--wlc-cube-size) / 2)); }
.wlc-face-back   { transform: rotateY(180deg)  translateZ(calc(var(--wlc-cube-size) / 2)); }
.wlc-face-left   { transform: rotateY(-90deg)  translateZ(calc(var(--wlc-cube-size) / 2)); }
.wlc-face-top    { transform: rotateX(90deg)   translateZ(calc(var(--wlc-cube-size) / 2)); }
.wlc-face-bottom {
    transform: rotateX(-90deg) translateZ(calc(var(--wlc-cube-size) / 2));
    background-color: #222;
    filter: none;
}

/* Caras con texto: papel y tinta reales, sin el filtro gris de las fotos */
.wlc-cube-face.is-text {
    background-color: var(--wlc-paper);
    background-image: none;
    filter: none;
    padding: 8px;
}

.wlc-cube-face:not(.is-text) .wlc-face-text {
    display: none;
}

.wlc-face-text:empty::before {
    content: "Tu texto";
    opacity: 0.35;
}

.wlc-face-text {
    font-family: "Great Vibes", "Segoe Script", cursive;
    color: var(--wlc-ink);
    font-size: calc(var(--wlc-cube-size) * 0.17);
    line-height: 1.15;
    text-align: center;
    word-break: break-word;
    overflow: hidden;
    max-height: 100%;
}

.wlc-drag-indicator {
    text-align: center;
    color: #94a3b8 !important;
    font-size: clamp(0.75rem, 3vw, 0.85rem);
    margin: 6px 0 0 !important;
    font-style: italic;
}

/* Overlay de carga */
#wlc-loading-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    z-index: 10;
    flex-direction: column;
    gap: 14px;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    color: #475569;
    text-align: center;
    padding: 16px;
}

.wlc-spinner {
    width: 34px;
    height: 34px;
    border: 3px solid #dbe3ec;
    border-top-color: var(--wlc-accent);
    border-radius: 50%;
    animation: wlc-spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

/* --------------------------------------------------------------------------
   Acción (añadir al carrito)
   -------------------------------------------------------------------------- */

.wlc-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    margin-top: clamp(18px, 4vw, 26px);
    padding-top: clamp(16px, 4vw, 22px);
    border-top: 1px solid var(--wlc-border);
}

.wlc-cart-slot {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    min-width: 0;
}

.wlc-cart-slot .quantity input {
    height: 100%;
}

#wlc-status-message {
    font-size: 0.9rem;
    font-weight: 600;
    margin-top: 14px;
}

#wlc-status-message.success { color: #16a34a; }
#wlc-status-message.error   { color: #dc2626; }

/* Botón de WooCommerce deshabilitado hasta completar el cubo */
button.single_add_to_cart_button:disabled {
    background-color: #e5e7eb !important;
    color: #9ca3af !important;
    cursor: not-allowed;
    opacity: 1 !important;
}

/* --------------------------------------------------------------------------
   Móvil
   -------------------------------------------------------------------------- */

@media (max-width: 640px) {
    #wlc-configurator-container {
        margin: 20px 0;
        border-radius: 10px;
    }

    /* Caras en lista vertical: miniatura a la izquierda y controles a la derecha.
       Evita recuadros enormes a una columna y deja todo al alcance del pulgar. */
    .wlc-photo-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
    }

    .wlc-face-card {
        display: grid;
        grid-template-columns: clamp(76px, 24vw, 96px) minmax(0, 1fr);
        /* Las filas 1fr de los extremos absorben la altura de la miniatura y
           centran verticalmente la etiqueta, el selector y el campo. */
        grid-template-rows: 1fr auto auto auto 1fr;
        grid-template-areas:
            "tile ."
            "tile label"
            "tile toggle"
            "tile input"
            "tile .";
        column-gap: 12px;
        row-gap: 6px;
        padding: 10px;
        border: 1px solid var(--wlc-border);
        border-radius: 12px;
        background: #ffffff;
    }

    .wlc-face-card .wlc-drop-label  { grid-area: label; text-align: left; }
    .wlc-face-card .wlc-mode-toggle { grid-area: toggle; }
    .wlc-face-card .wlc-drop-zone   { grid-area: tile; align-self: center; }
    .wlc-face-card .wlc-card-input  { grid-area: input; }

    .wlc-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .wlc-cart-slot {
        width: 100%;
    }

    /* Botón a todo el ancho: objetivo táctil cómodo. */
    .wlc-cart-slot button.single_add_to_cart_button {
        flex: 1 1 auto;
        width: 100%;
    }
}

/* --------------------------------------------------------------------------
   Aviso de "inicia sesión" para invitados
   -------------------------------------------------------------------------- */

.wlc-login-required .wlc-login-notice {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: clamp(16px, 4vw, 24px);
    background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 100%);
    border: 1px solid #dbeafe;
    border-radius: 10px;
}

.wlc-login-notice-icon {
    font-size: 2.4rem;
    line-height: 1;
    flex-shrink: 0;
}

.wlc-login-notice-title {
    margin: 0 0 6px !important;
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e3a8a !important;
}

.wlc-login-notice-text {
    margin: 0 0 14px !important;
    color: #475569 !important;
}

.wlc-login-btn {
    display: inline-block;
    padding: 11px 22px;
    background: #3b82f6;
    color: #fff !important;
    font-weight: 600;
    text-decoration: none;
    border-radius: 8px;
    transition: background 0.2s ease, transform 0.1s ease;
}

.wlc-login-btn:hover {
    background: #2563eb;
    transform: translateY(-1px);
    color: #fff !important;
}

@media (max-width: 480px) {
    .wlc-login-required .wlc-login-notice {
        flex-direction: column;
        text-align: center;
    }
}

/* Verificación anti-bots (Turnstile). Invisible salvo que Cloudflare pida un reto. */
#wlc-configurator-container .wlc-turnstile {
    margin-top: 10px;
}

#wlc-configurator-container .wlc-turnstile:empty {
    display: none;
}
