*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #1a0a00;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* === WRAPPER: centered 1:1 viewport === */
#app-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
}

#mirror-view {
    position: relative;
    width: min(100vw, 100vh);
    height: min(100vw, 100vh);
    overflow: hidden;
}

/* === MindAR container (video + 3D canvas) === */
#container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    overflow: hidden;
}

/* === Penteadeira overlay === */
#penteadeira {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    object-fit: contain;
}

/* === CANVAS DE DEBUG DOTS (separado, não polui a textura) === */
#debug-dots {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    opacity: 0.6;
}

/* === DEBUG TOGGLE (oculto por padrão, ativado via makeup.debug()) === */
#debug-toggle {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 5;
    display: none;
    align-items: center;
    gap: 4px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    user-select: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    pointer-events: auto;
}
#debug-toggle input {
    accent-color: #4caf50;
}

/* === UI OVERLAY === */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
}

#ui-overlay > * {
    pointer-events: auto;
}

/* === BARRA DE FERRAMENTAS === */
#toolbar {
    position: absolute;
    bottom: min(20vh, 20vw);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: flex-end;
    gap: min(10vh, 10vw);
    z-index: 1;
}

.tool-btn {
    display: block;
    border: none;
    background-repeat: no-repeat;
    background-position: 0 0;
    background-size: 200% 100%;
    background-color: transparent;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
}

.tool-btn:hover{
    transform: scale(1.1);
}

.tool-btn:not(.active) {
    background-position: 100% 0;
}

#btn-batom {
    width: min(50px, 5vw);
    height: min(100px, 10vw);
    background-image: url('../assets/img/sprite_batom.png');
}

#btn-sombra {
    width: min(100px, 10vw);
    height: min(100px, 10vw);
    background-image: url('../assets/img/sprite_sombra.png');
}

#btn-clear {
    width: min(150px, 15vw);
    height: min(150px, 15vw);
    background-image: url('../assets/img/pano_limpar.png');
    background-size: 100% 100%;
    background-position: 0 0;
    margin-bottom: max(-3vh, -3vw);
}

/* === PINCEL (agora escondido por padrão) === */
#palette {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 10px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    max-width: 310px;
    z-index: 2;
}
#palette.hidden { display: none; }

.color-swatch {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
    outline: none;
}
.color-swatch:hover {
    transform: scale(1.15);
}
.color-swatch.selected {
    border-color: #fff;
    transform: scale(1.15);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

/* === PAINEL DE DEBUG (oculto por padrão) === */
#debug-panel {
    position: fixed;
    bottom: 100px;
    left: 8px;
    z-index: 100;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 8px;
    border-radius: 8px;
    display: none;
    gap: 8px;
    align-items: flex-start;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    line-height: 1.5;
    color: #0f0;
    border: 1px solid rgba(0, 255, 0, 0.2);
    pointer-events: none;
    max-width: 200px;
}

#debug-tex {
    width: 64px;
    height: 64px;
    border: 1px solid rgba(0, 255, 0, 0.3);
    border-radius: 4px;
    image-rendering: pixelated;
    flex-shrink: 0;
}

#debug-info .dv { color: #fff; }

/* === BOTÃO DOAR === */
#btn-doar {
    position: fixed;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0px;
    border: 3px outset;
    background: #FFF;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #000;
    font-size: 1.5rem;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    pointer-events: auto;
    white-space: nowrap;
    font-family: inherit;
    transition: background 0.2s;
}
#btn-doar img {
    width: 50%;
    margin: -50px auto;
    flex-shrink: 0;
}
#btn-doar span {
    color: rgba(0, 0, 0, 0.9);
}
#btn-doar:active {
    background: rgba(255, 255, 255, 0.1);
}

@media (orientation: portrait) {
    #btn-doar { bottom: 8px; left: 50%; transform: translateX(-50%); }
}
@media (orientation: landscape) {
    #btn-doar { top: 8px; right: 8px; }
}

/* === RESPONSIVO === */
@media (max-width: 480px) {
    #palette {
        bottom: 80px;
        gap: 4px;
        padding: 8px;
        max-width: 250px;
    }
    .color-swatch {
        width: 24px;
        height: 24px;
    }
}
