/* Reset y configuración base PWA */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    width: 100vw;
    min-height: 100dvh; /* Dynamic Viewport Height para móviles (soluciona barra de navegación) */
    overflow-x: hidden;
    overflow-y: auto;
    background-color: #e0f7fa; 
    font-family: 'Comic Sans MS', 'Chalkboard SE', sans-serif;
    overscroll-behavior: none; /* BLOQUEO DE PULL-TO-REFRESH SIN BLOQUEAR SCROLL LOCAL */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
}

#app-container {
    width: 100%;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 15px;
}

/* Lienzo compuesto en capas */
#workspace {
    flex-grow: 1;
    min-height: 45vh; /* Asegurar que la pizarra tenga un minimo de alto utilizable en móviles apaisados */
    position: relative;
    border: 8px solid #FF9500;
    border-radius: 20px;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
    background-color: #FFFFFF;
    overflow: hidden; /* Asegurar que ningún sticker desborde la pizarra visualmente */
}

#drawingBoard {
    width: 100%;
    height: 100%;
    display: block; /* remueve el pixel extra de alineamiento inline */
    cursor: crosshair;
    touch-action: none; /* Canvas mantiene su propio touch-action: none */
}

#stickers-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* La pizarra captura eventos normales */
}

/* Modos del espacio de trabajo guiando cursores y eventos */
.hand-mode-active #stickers-container {
    pointer-events: auto; /* Activamos la interacción frontal */
}
.hand-mode-active #drawingBoard {
    cursor: default; /* desactivamos cursor de dibujo manual */
}

/* Estilos individuales del DOM Sticker */
.sticker {
    position: absolute;
    user-select: none;
    touch-action: none;
    transform-origin: center;
    /* el arrastre sin 'transition' lo hace más directo a 60fps */
}
.hand-mode-active .sticker {
    cursor: grab;
    filter: drop-shadow(0 4px 5px rgba(0,0,0,0.3)); /* resaltar agarrable */
}
.hand-mode-active .sticker:active {
    cursor: grabbing;
    filter: drop-shadow(0 8px 12px rgba(0,0,0,0.4)); /* efecto elevar */
}

/* Contenedor principal de pegatinas flotante */
#sticker-picker-container {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(255,255,255,0.9);
    padding: 5px;
    border-radius: 25px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 5px;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: auto;
    max-width: calc(100% - 20px);
}
#sticker-picker-container.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

#sticker-picker {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 5px;
    scroll-behavior: smooth;
    max-width: 60vw;
}
#sticker-picker::-webkit-scrollbar {
    display: none;
}

.sticker-scroll-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: #FF9500;
    cursor: pointer;
    padding: 0 5px;
    user-select: none;
    touch-action: manipulation;
}
.sticker-scroll-btn:active {
    transform: scale(0.8);
}
.sticker-option {
    font-size: 35px;
    cursor: pointer;
    transition: transform 0.1s;
    filter: grayscale(0.5);
}
.sticker-option.selected {
    transform: scale(1.3);
    filter: grayscale(0);
}

/* Barras de herramientas */
#controls-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
}
.toolbar {
    min-height: 85px;
    height: auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    background-color: #FFFFFF;
    border-radius: 25px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    padding: 10px;
    gap: 12px;
}

button {
    border: none;
    outline: none;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease, border 0.1s ease;
    flex-shrink: 0;
}

.thickness-tools {
    display: flex;
    gap: 5px;
    background: #f0f0f0;
    padding: 5px 10px;
    border-radius: 35px;
    align-items: center;
    height: 70px;
}
.thickness-btn {
    width: 55px;
    height: 55px;
    border-radius: 50%;
    background-color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 3px 0px rgba(0,0,0,0.1);
}
.thickness-btn.active {
    background-color: #e0e0e0;
    box-shadow: inset 0 3px 5px rgba(0,0,0,0.1);
    transform: translateY(2px);
}
.thickness-btn .dot {
    background-color: #333;
    border-radius: 50%;
}

.color-btn {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    box-shadow: 0 5px 0px rgba(0,0,0,0.15), 0 8px 8px rgba(0,0,0,0.1);
    border: 4px solid white;
    position: relative;
}
.color-btn.active {
    transform: translateY(4px) scale(1.1);
    box-shadow: 0 2px 0px rgba(0,0,0,0.15), 0 4px 4px rgba(0,0,0,0.1);
    border: 4px solid #333; 
}
.color-btn:active {
    transform: translateY(5px);
    box-shadow: none;
}
.custom-color-btn {
    background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
    overflow: hidden;
}

.tool-btn {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background-color: white;
    font-size: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 5px 0px rgba(0,0,0,0.1), 0 8px 8px rgba(0,0,0,0.1);
    border: 4px solid white;
}
.tool-btn.active {
    border-color: #333;
    transform: translateY(4px) scale(1.1);
    box-shadow: 0 2px 0px rgba(0,0,0,0.15);
}
.tool-btn:active {
    transform: translateY(5px);
    box-shadow: none;
}

.action-btn {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: radial-gradient(circle, #ff4e50, #f9d423); 
    font-size: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 5px 0px #b71c1c, 0 8px 8px rgba(0,0,0,0.15);
}
.action-btn:active {
    transform: translateY(5px);
    box-shadow: none;
}

@media (min-width: 768px) {
    #app-container {
        padding: 20px;
        gap: 20px;
        max-width: 1024px;
        margin: auto;
    }
    
    .toolbar {
        height: 100px;
        border-radius: 50px;
        padding: 0 25px;
        gap: 15px;
        justify-content: center;
    }

    .thickness-tools {
        padding: 5px 15px;
        height: 80px;
    }

    .thickness-btn {
        width: 70px;
        height: 70px;
    }
    
    .color-btn, .tool-btn, .action-btn {
        width: 80px;
        height: 80px;
        border-width: 5px;
        font-size: 40px;
    }
    
    .sticker-option {
        font-size: 45px;
    }
}

/* --- Banner de Actualización --- */
#update-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #FF9500, #FFCC00);
    padding: 3px;
    border-radius: 24px;
    box-shadow: 0 10px 25px rgba(255, 149, 0, 0.4);
    z-index: 1000;
    transition: opacity 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    width: 90%;
    max-width: 400px;
}

#update-notification.hidden {
    opacity: 0;
    transform: translate(-50%, 150%);
    pointer-events: none;
}

.update-content {
    background: #FFFFFF;
    border-radius: 21px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 10px;
}

.update-icon {
    font-size: 40px;
    margin-bottom: -5px;
}

.update-text h3 {
    color: #FF9500;
    margin-bottom: 5px;
    font-size: 22px;
}

.update-text p {
    color: #666;
    font-size: 14px;
    line-height: 1.4;
}

.update-actions {
    display: flex;
    gap: 10px;
    width: 100%;
    margin-top: 5px;
}

.update-actions button {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: bold;
    font-family: inherit;
    box-shadow: 0 4px 0 rgba(0,0,0,0.1);
}

.update-btn-yes {
    background-color: #34C759;
    color: white;
}

.update-btn-yes:active {
    background-color: #2eb350;
    transform: translateY(4px);
    box-shadow: 0 0px 0 rgba(0,0,0,0.1);
}

.update-btn-no {
    background-color: #f0f0f0;
    color: #555;
}

.update-btn-no:active {
    background-color: #e0e0e0;
    transform: translateY(4px);
    box-shadow: 0 0px 0 rgba(0,0,0,0.1);
}
