/* Reset muy ligero */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    /*font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;*/
    font-family: "Inter", system-ui, sans-serif;
    background-color: #f4f4f4;
    color: #222;
}

/* Opcional: limitar ancho en pantallas grandes */
body {
    display: flex;
    justify-content: center;
}

.app-root {
    width: 100%;
    max-width: 1200px;
}

/* Encabezado simple */
.app-header {
    padding: 0.75rem 1rem;
    text-align: center;
    background: #ffffff;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    z-index: 5;
}

.app-header h1 {
    margin: 0;
    font-size: 1.1rem;
}

/* ===========================
   GALERÍA (MOBILE FIRST)
   =========================== */

main {
    width: 100%;
}

/* Base: móviles pequeños → 2 columnas */
.gallery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    padding: 0.5rem;
}

.gallery-card {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.gallery-image {
    width: 100%;
    border-radius: 0.5rem;
    background: #f1f1f1;
}

.gallery-name {
    text-align: center;
    font-size: 0.9rem;
    color: #333;
    font-weight: 500;
    padding: 0.2rem 0.1rem 0.4rem;
    user-select: none;
}

/* Card básica */
.card {
    background: #ffffff;
    border-radius: 0.75rem;
    border: 1px solid #e0e0e0;
    cursor: pointer;
    touch-action: manipulation;

    /* NUEVO: caja vertical imagen + texto */
    display: flex;
    flex-direction: column;
    padding: 0.4rem 0.4rem 0.5rem;
    gap: 0.3rem;

    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.card img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-image-wrapper {
    border-radius: 0.55rem;
    overflow: hidden;
    background: #f2f2f2;
    /* por si la imagen tarda o no llena todo */
}

/* Imagen del modelo */
.card-image-wrapper img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: cover;
}

.card-name {
    text-align: center;
    font-size: 1rem;
    /* antes 0.9rem */
    font-weight: 700;
    /* negrita real */
    color: #1a1a1a;
    /* más oscuro para más contraste */
    padding-top: 0.3rem;
    letter-spacing: 0.3px;
    /* ligera claridad visual */
    line-height: 1.25;
    user-select: none;

    /* Si el nombre es largo, evitar que descuadre */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    /* máximo 2 líneas */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-name {
    background: #f7f7f7;
    border-radius: 0.4rem;
    padding: 0.4rem 0.6rem;
}

.card-name {
    /* color: #0050a8; */
    /* azul moderno */
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
}


/* Móviles un poco más grandes */
@media (min-width: 400px) {
    .gallery {
        gap: 0.75rem;
        padding: 0.75rem;
    }
}

/* Tablets en vertical (~ 600px) → 3 columnas */
@media (min-width: 600px) {
    .gallery {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Escritorio / tablets grandes → 4 columnas */
@media (min-width: 900px) {
    .gallery {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        max-width: 1000px;
        margin: 0 auto;
    }
}

/* ===========================
   MODAL
   =========================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: none;
    /* oculto por defecto */
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.modal-backdrop.is-visible {
    display: flex;
}

/* Base: móvil en vertical → ocupa casi toda la pantalla */
.modal {
    background: #ffffff;
    width: 100%;
    height: 100%;
    max-width: 600px;
    max-height: 100vh;
    border-radius: 0.75rem 0.75rem 0 0;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Botón cerrar grande */
.modal-close {
    position: absolute;
    top: 0.4rem;
    right: 0.6rem;
    border: none;
    background: transparent;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem;
    color: #444;
    z-index: 2;
}

.modal-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-top: 2.5rem;
    /* espacio para botón cerrar */
    overflow: hidden;
}

/* Visor 3D ocupa la mayor parte y se adapta a la altura de la pantalla */
.viewer-wrapper {
    flex: 1 1 auto;
    position: relative;
    background: #fafafa;

    /* Siempre algo de altura, y escalado según pantalla */
    min-height: 260px;
    height: clamp(260px, 60vh, 520px);
}

/* El canvas de Three.js se ajustará a este contenedor */
.viewer-wrapper canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.color-section {
    flex: 0 0 auto;
    border-top: 1px solid #e0e0e0;
    background: #ffffff;
    display: flex;
    flex-direction: column;
}


/* Nombre del color seleccionado */
.color-label {
    padding: 0.5rem 0.75rem 0.25rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #333;
}

/* Ajustamos el picker porque ahora está dentro de .color-section */
.color-picker {
    flex: 0 0 auto;
    padding: 0.5rem 0.75rem 0.75rem;
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    background: #ffffff;
    border-top: none;
    /* ya lo lleva .color-section */
}

/* Círculos grandes y fáciles de tocar */
.color-swatch {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 2px solid rgba(0, 0, 0, 0.35);
    /* borde suave visible en todos */
    flex-shrink: 0;
    cursor: pointer;
    outline: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.color-swatch.is-active {
    border-color: #000000;
    /* borde más fuerte */
    box-shadow:
        0 0 0 3px rgba(0, 0, 0, 0.20),
        /* anillo exterior suave */
        0 0 6px rgba(0, 0, 0, 0.25);
    /* glow ligero */
    transform: scale(1.07);
    /* un poquito más grande */
}

/* ===========================
   AJUSTES PARA MÓVILES BAJETES
   (ej. altura pequeña / en horizontal)
   =========================== */

/* Altura pequeña (móvil en horizontal) */
@media (max-height: 600px) {
    .app-header {
        padding: 0.5rem 0.75rem;
    }

    .modal {
        border-radius: 0.5rem;
        max-height: 95vh;
    }

    .modal-content {
        padding-top: 2rem;
    }

    .viewer-wrapper {
        min-height: 200px;
    }

    /* Bloque de colores más compacto */
    .color-section {
        padding-bottom: 0.25rem;
    }

    .color-label {
        padding: 0.4rem 0.6rem 0.15rem;
        font-size: 0.8rem;
    }

    .color-picker {
        padding: 0.4rem 0.6rem 0.6rem;
    }

    .color-swatch {
        width: 38px;
        height: 38px;
    }
}

/* Pantallas con notch (iPhone) */
@supports (padding: max(0px)) {
    .app-header {
        padding-top: max(0.75rem, env(safe-area-inset-top));
    }

    .modal {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ===========================
   MODAL EN PANTALLAS GRANDES
   (tablets horizontales y escritorio)
   =========================== */

@media (min-width: 768px) and (min-height: 600px) {
    .modal {
        width: 90%;
        height: 90%;
        max-width: 900px;
        max-height: 90vh;
        border-radius: 1rem;
    }

    .modal-content {
        flex-direction: row;
        padding-top: 0;
    }

    .viewer-wrapper {
        flex: 2 1 0;
        min-height: 0;
        /* que pueda ajustarse en altura */
    }

    /* Ahora la columna derecha es la sección completa (label + picker) */
    .color-section {
        flex: 0 0 260px;
        border-top: none;
        border-left: 1px solid #e0e0e0;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
    }

    .color-label {
        padding: 0.75rem 0.75rem 0.5rem;
        font-size: 0.9rem;
    }

    .color-picker {
        flex: 1 1 auto;
        padding: 0.5rem 0.75rem 0.75rem;
        flex-wrap: wrap;
        overflow-x: hidden;
        overflow-y: auto;
        border-top: none;
    }

    .color-swatch {
        width: 40px;
        height: 40px;
    }
}