/* --- Base Styles --- */
body {
    margin: 0;
    overflow: hidden;
    background-color: #000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
#container {
    width: 100vw;
    height: 100vh;
}
#container.mirrored canvas {
    transform: scaleX(-1);
}
canvas {
    display: block;
    /* MODIFIED: Explicitly set width and height for object-fit */
    width: 100%;
    height: 100%;
    object-fit: cover;
}
#info {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 1.2em;
    text-shadow: 0 0 5px black;
}
.flash {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: white;
    opacity: 0.7;
    animation: fadeOut 0.3s forwards;
}
@keyframes fadeOut {
    from { opacity: 0.7; }
    to { opacity: 0; }
}

/* --- UI Container --- */
#ui-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px 20px calc(20px + env(safe-area-inset-bottom)) 20px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    z-index: 10;
}
#shader-buttons {
    display: flex;
    gap: 10px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 10px;
}
#shader-buttons button {
    padding: 8px 12px;
    border: 1px solid white;
    background: transparent;
    color: white;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}
#shader-buttons button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}
#shader-buttons button.active {
    background-color: #00aaff;
    border-color: #00aaff;
}
#shader-buttons button:active, #camera-controls button:active {
    transform: scale(0.95);
}

/* --- Camera Controls --- */
#camera-controls {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}
#snap-button {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: white;
    border: 4px solid black;
    box-shadow: 0 0 0 4px white;
    cursor: pointer;
    outline: none;
    transition: transform 0.1s;
}
#snap-button:active {
    background-color: #ccc;
}
#gallery-button {
    width: 44px;
    height: 44px;
    background-color: rgba(255, 255, 255, 0.2);
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white"><path d="M22 16V4c0-1.1-.9-2-2-2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2zm-11-4l2.03 2.71L16 11l4 5H8l3-4zM2 6v14c0 1.1.9 2 2 2h14v-2-H4V6H2z"/></svg>');
    background-size: 60%;
    background-position: center;
    background-repeat: no-repeat;
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    position: absolute;
    left: 0;
    right: auto;
    margin: 0 15%;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
    transition: transform 0.1s;
}
#switch-camera-button {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.2) url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24" fill="white"><path d="M440-200v-104L280-464l160-160v-104l-240 240 240 240Zm80 0-240-240 240-240v104l160 160-160 160v104Z"/></svg>') center/70% no-repeat;
    border: 1px solid white;
    border-radius: 50%;
    cursor: pointer;
    position: absolute;
    left: auto;
    right: 0;
    margin: 0 15%;
    transition: transform 0.1s;
}

/* Landscape Layout */
@media (orientation: landscape) {
    #ui-container {
        width: 120px;
        height: 100%;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        right: 0;
        left: auto;
        top: 0;
        bottom: auto;
        padding: env(safe-area-inset-top) calc(10px + env(safe-area-inset-right)) env(safe-area-inset-bottom) 10px;
    }
    #camera-controls {
        flex-direction: column-reverse;
        gap: 25px;
        width: auto;
    }
    #gallery-button, #switch-camera-button {
        position: static;
        margin: 0;
    }
    #shader-buttons {
        order: -1;
        flex-direction: column;
        flex-wrap: wrap;
        max-height: 40%;
        overflow-y: auto;
    }
}

/* --- Gallery & Modal --- */
.hidden { display: none !important; }
#gallery-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.95); color: white; overflow-y: auto; padding: 20px; box-sizing: border-box; }
#gallery-close-button { position: fixed; top: 20px; right: 20px; font-size: 2em; background: none; border: none; color: white; cursor: pointer; }
#gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; padding-top: 60px; }
#gallery-grid img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; border-radius: 5px; }
#preview-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); display: flex; justify-content: center; align-items: center; }
.modal-content { position: relative; max-width: 90vw; max-height: 90vh; }
#preview-image { max-width: 100%; max-height: 80vh; object-fit: contain; }
#preview-close-button { position: absolute; top: -10px; right: -10px; background: white; border-radius: 50%; width: 30px; height: 30px; border: none; font-size: 1.5em; cursor: pointer; }
.modal-actions { display: flex; justify-content: center; gap: 20px; margin-top: 15px; }
.modal-actions button { padding: 12px 20px; font-size: 1em; background-color: #00aaff; color: white; border: none; border-radius: 5px; cursor: pointer; }
#delete-button { background-color: #ff4d4d; }