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

body {
    font-family: 'Arial', sans-serif;
    background-color: #000000;
    color: #ffffff;
    overflow: hidden;
    height: 100dvh;
    -webkit-tap-highlight-color: transparent; /* remove blue tap highlight (iOS/Safari/Chrome) */
}

/* Remove blue text selection highlight globally */
::selection { background: transparent; color: inherit; }
::-moz-selection { background: transparent; color: inherit; }

/* Suppress default focus outlines that can appear blue on some platforms */
:focus { outline: none; }

/* Screen Management */
.screen {
    display: none !important;
    width: 100dvw;
    height: 100dvh;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

.screen.active {
    display: block !important;
    z-index: 10;
}

/* Launch Screen Styles */
#launchScreen {
    background-color: #000000;
    min-height: 100dvh;
    position: relative;
}
.launch-content {
    width: 100dvw;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4vh;
    box-sizing: border-box;
}

.logo-container {
    margin-bottom: 6vh;
    margin-top: 6vh;
}

.logo {
    width: 30vh;
    height: 30vh;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(193, 159, 204, 0.22);
    border: 3px solid rgba(255, 255, 255, 0.1);
    margin: 0 auto;
}

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

.app-title {
    color: #bdff98;
    font-size: 4vh;
    font-weight: 300;
    margin-bottom: 5vh;
    text-align: center;
    letter-spacing: 1px;
    background: linear-gradient(90deg, #bdff98, #f4ff68, #ff6644, #ff75d2, #a670fc, #a3e6d0, #bdff98);
    background-size: 600% 100%;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientFlow 4s ease-in-out infinite;
}

@keyframes gradientFlow {
    0% {
        background-position: 100% 50%;
        color: #bdff98;
    }
    50% {
        background-position: 100% 50%;
        color: #bdff98;
    }
    50.01% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.main-navigation {
    display: flex;
    flex-wrap: nowrap;
    gap: 3vmin;
    margin-bottom: 3vmin;
    justify-content: center;
}

.start-button {
    background-color: #bdff98;
    color: #000000;
    border: none;
    border-radius: 2vmin;
    height: 5vh;
    font-size: 3.5vh;
    font-weight: 600;
    padding: 0 4vmin;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20vmin;
}

.start-button:hover {
    background-color: #00ff00;
    transform: translateY(-2px);
}

.start-button:active {
    transform: translateY(0);
    background-color: #00cc00;
}



/* Main Editor Styles */
#editorScreen {
    position: relative;
    background-color: #000000;
}

.editor-canvas {
    position: absolute;
    top: 0;
    left: 0;
    background-image: 
        linear-gradient(45deg, #333 25%, transparent 25%), 
        linear-gradient(-45deg, #333 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #333 75%), 
        linear-gradient(-45deg, transparent 75%, #333 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    cursor: crosshair;
}

.editor-sidebar {
    position: absolute;
    left: 60px;
    top: 80px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 200;
    transform: translateX(-50%);
}

/* iPhone-specific sidebar adjustments (keep position; just size/spacing) */
@media (max-width: 480px) and (orientation: landscape) {
    .editor-sidebar {
        gap: 4px; /* tighter spacing */
    }
    
    .sidebar-tool {
        width: 36px;  /* smaller buttons */
        height: 36px;
    }
    
    .sidebar-tool svg,
    .sidebar-tool img {
        width: 24px;  /* keep icon size */
        height: 24px;
    }
}

.sidebar-tool {
    width: 40px;
    height: 40px;
    background-color: transparent;
    border: none;
    outline: none;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.sidebar-tool:hover {
    background-color: rgba(255, 255, 255, 0.2); /* match .toolbar-button:hover */
}

.sidebar-tool.active {
    background-color: rgba(0, 255, 0, 0.3);
    border-color: #00ff00;
}

.sidebar-tool svg,
.sidebar-tool img {
    width: 24px;
    height: 24px;
    fill: #ffffff;
}

/* Layers Options Panel */
.layers-options-panel {
    position: absolute;
    left: 60px;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
    background-color: rgba(0, 0, 0, 0.9);
    border: 1px solid #666;
    border-radius: 8px;
    padding: 5px;
    z-index: 300;
}

.layers-option {
    width: 40px;
    height: 40px;
    background-color: transparent;
    border: 1px solid #666;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.layers-option:hover {
    background-color: rgba(100, 100, 100, 0.8);
    border-color: #999;
}

.layers-option svg,
.layers-option img {
    width: 20px;
    height: 20px;
    fill: #ffffff;
}

/* Effects Options Panel */
.effects-options-panel {
    position: absolute;
    left: 60px;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
    background-color: rgba(0, 0, 0, 0.9);
    border: 1px solid #666;
    border-radius: 8px;
    padding: 5px;
    z-index: 300;
}

.effects-option {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px; /* match toolbar button height */
    padding: 0;
    background-color: transparent;
    border: 1px solid #666;
    outline: none;
    border-radius: 4px; /* match toolbar button radius */
    cursor: pointer;
    transition: all 0.3s ease;
    color: #ffffff;
}

.effects-option:hover {
    background-color: rgba(100, 100, 100, 0.8);
    border-color: #999;
}

/* Remove Effects Option Styling */
.remove-effects-option {
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    margin-top: 5px;
    padding-top: 10px;
}

.remove-effects-option:hover {
    background-color: rgba(100, 100, 100, 0.8);
    border-color: #999;
}

.bottom-toolbar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    align-items: center;
    z-index: 100;
}

.toolbar-group {
    display: contents;
    gap: 0;
    padding: 0;
    background-color: transparent;
    border-radius: 0;
    border: none;
}

.toolbar-button {
    width: 40px;
    height: 40px;
    background-color: transparent;
    border: none;
    outline: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.toolbar-button.active {
    background-color: rgba(0, 255, 0, 0.3);
}

.toolbar-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.toolbar-button svg,
.toolbar-button img {
    width: 24px;
    height: 24px;
    fill: #ffffff;
}

/* Projector button (top-left) */
.projector-button {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 80px;
    height: 50px;
    background: rgba(0, 0, 0, 0.8);
    border: none;
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
    z-index: 100;
    /* Touch-friendly improvements */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* Fullscreen button (bottom-right) */
.fullscreen-button {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(0, 0, 0, 0.8);
    border: none;
    border-radius: 3px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s ease;
    z-index: 100;
    /* Touch-friendly improvements */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.projector-button:hover {
    opacity: 0.8;
}

.projector-button img {
    width: 48px;
    height: 48px;
}

.fullscreen-button:hover {
    opacity: 0.8;
}

.fullscreen-button img {
    width: 30px;
    height: 30px;
}

/* Add to Home Screen hint toast */
.a2hs-hint {
    position: fixed;
    right: 20px;
    bottom: 90px;
    background: rgba(0, 0, 0, 0.85);
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    max-width: 260px;
    line-height: 1.3;
    z-index: 10000;
    pointer-events: none;
}

@media (max-width: 768px) {
    .a2hs-hint {
        right: 16px;
        bottom: 80px;
        font-size: 13px;
        max-width: 240px;
    }
}

/* Media Selection Screen */
#mediaScreen {
    background-color: #000000;
}

#mediaScreen.active {
    display: flex !important;
    flex-direction: column;
}

.media-header {
    display: flex;
    align-items: center;
    padding: 2px 20px;
}

.back-button {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 36px;
    cursor: pointer;
    margin-right: 20px;
    padding: 10px;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.back-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.media-title {
    font-size: 24px;
    color: #ffffff;
}

.media-controls {
    display: flex;
    gap: 20px;
    padding: 20px;
    align-items: center;
}


.upload-buttons {
    display: flex;
    gap: 10px;
}

.upload-button {
    width: 80px;
    height: 50px;
    background-color: transparent;
    border: none;
    outline: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.upload-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.upload-button img {
    width: 48px;
    height: 48px;
}

.media-content {
    flex: 1;
    min-height: 0; /* allow child to scroll */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
}

.media-grid {
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, 150px);
    grid-auto-rows: 150px;
    gap: 15px;
    justify-content: start;
    align-content: start;
    box-sizing: border-box;
}

/* Mobile media grid adjustments - more specific targeting */
@media (max-width: 768px) {
    .media-title {
        font-size: 18px !important;
    }
    
    .media-controls {
        padding: 8px !important;
        gap: 8px !important;
        flex-wrap: wrap !important;
    }
    
    .upload-button {
        width: 70px !important;
        height: 45px !important;
    }
    
    .upload-button img {
        width: 40px !important;
        height: 40px !important;
    }
    
    .media-content {
        flex: 1 !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .media-grid {
        padding: 6px !important;
        grid-template-columns: repeat(auto-fill, 64px) !important;
        grid-auto-rows: 64px !important;
        gap: 4px !important;
        justify-content: start !important;
        align-content: start !important;
    }
    
    .media-item {
        border-width: 1px !important;
        width: 100% !important;
        aspect-ratio: 1 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-width: 0 !important;
        min-height: 0 !important;
    }
    
}

/* Even more aggressive mobile targeting for very small screens */
@media (max-width: 480px) {
    .media-grid {
        grid-template-columns: repeat(auto-fill, 56px) !important;
        grid-auto-rows: 56px !important;
        gap: 3px !important;
        padding: 4px !important;
        justify-content: start !important;
        align-content: start !important;
    }
    
    .media-item {
        width: 100% !important;
        aspect-ratio: 1 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-width: 0 !important;
        min-height: 0 !important;
    }
    
    .media-controls {
        padding: 6px !important;
    }
    
    .upload-button {
        padding: 4px 8px !important;
        font-size: 10px !important;
    }
}

.media-item {
    background-color: #333;
    border: 2px solid #666;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
}

.media-item:hover {
    border-color: #bdff98;
    transform: scale(1.05);
}

.media-item.selected {
    border-color: #00ff00;
}

.media-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.media-item video, .media-item canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}





/* Projection Mode */
.projection-mode .editor-sidebar,
.projection-mode .bottom-toolbar {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.projection-mode .projector-button {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 10001; /* Ensure it's above everything when shown */
}

.projection-mode .fullscreen-button {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.projection-mode .editor-canvas {
    background: #000000;
}

/* Hide shape selection indicators in projection mode */
.projection-mode .shape-corner,
.projection-mode .shape-edge,
.projection-mode .shape-outline {
    display: none !important;
}

/* Mobile projection mode enhancements */
@media (max-width: 768px) {
    .projection-mode .editor-canvas {
        width: 100vw !important;
        height: 100vh !important;
    }
    
    .projection-mode .projector-button {
        /* Make projector button larger and more touch-friendly when shown */
        width: 100px;
        height: 70px;
        top: 30px;
        left: 30px;
    }
    
    .projection-mode .projector-button img {
        width: 60px;
        height: 60px;
    }
}


/* Hidden file inputs */
input[type="file"] {
    position: fixed;
    top: -10000px;
    left: -10000px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Custom cursors - all white for consistency */
.lock-cursor {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><circle cx="12" cy="16" r="1"></circle><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>') 12 12, not-allowed !important;
}

.move-cursor {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="5,9 2,12 5,15"></polyline><polyline points="9,5 12,2 15,5"></polyline><polyline points="15,19 12,22 9,19"></polyline><polyline points="19,9 22,12 19,15"></polyline><line x1="2" y1="12" x2="22" y2="12"></line><line x1="12" y1="2" x2="12" y2="22"></line></svg>') 12 12, move !important;
}

.crosshair-cursor {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="2" x2="12" y2="22"></line><line x1="2" y1="12" x2="22" y2="12"></line></svg>') 12 12, crosshair !important;
}

.grab-cursor {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"></path><path d="M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v2"></path><path d="M10 9.5V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v6"></path><path d="M18 8a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2"></path></svg>') 12 12, grab !important;
}

/* Use white hand cursor on interactive buttons */
.toolbar-button,
.sidebar-tool,
.projector-button,
.fullscreen-button,
.upload-button,
.start-button {
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"></path><path d="M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v2"></path><path d="M10 9.5V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v6"></path><path d="M18 8a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2"></path></svg>') 12 12, grab !important;
}

/* Touch device styling for upload buttons */
@media (hover: none) and (pointer: coarse) {
    .upload-button {
        min-width: 44px;
        min-height: 44px;
    }
    
    .upload-button:active {
        background-color: rgba(255, 255, 255, 0.3);
        transform: scale(0.95);
    }
}



/* Responsive adjustments for editor toolbar sizing */
@media (max-width: 1024px) {
    .editor-sidebar {
        top: 75px;
        gap: 8px;
    }
    
    .sidebar-tool {
        width: 48px;
        height: 48px;
    }
    
    .sidebar-tool svg,
    .sidebar-tool img {
        width: 22px;
        height: 22px;
    }
    
    .bottom-toolbar {
        bottom: 15px;
        gap: 8px;
    }
    
    .toolbar-button {
        width: 48px;
        height: 48px;
    }
    
    .toolbar-button svg,
    .toolbar-button img {
        width: 22px;
        height: 22px;
    }
    
    .effects-option {
        height: 48px;
    }
}

@media (max-width: 768px) {
    .editor-sidebar {
        top: 70px;
        gap: 6px;
    }
    
    .sidebar-tool {
        width: 50px;
        height: 50px;
    }
    
    .sidebar-tool svg,
    .sidebar-tool img {
        width: 24px;
        height: 24px;
    }
    
    .bottom-toolbar {
        bottom: 10px;
        gap: 6px;
    }
    
    .toolbar-button {
        width: 50px;
        height: 50px;
    }
    
    .toolbar-button svg,
    .toolbar-button img {
        width: 24px;
        height: 24px;
    }
    
    .projector-button {
        width: 70px;
        height: 45px;
    }
    
    .projector-button img {
        width: 40px;
        height: 40px;
    }
    
    .fullscreen-button {
        width: 45px;
        height: 45px;
    }
    
    .fullscreen-button img {
        width: 40px;
        height: 40px;
    }
    
    .media-content {
        height: calc(100vh - 110px);
    }
    
    
    .upload-button {
        padding: 12px 18px;
        font-size: 15px;
    }
    
    .effects-option {
        height: 50px;
    }
}

@media (max-width: 480px) {
    .editor-sidebar {
        top: 60px;
        gap: 4px;
    }
    
    .sidebar-tool {
        width: 45px;
        height: 45px;
    }
    
    .sidebar-tool svg,
    .sidebar-tool img {
        width: 20px;
        height: 20px;
    }
    
    .bottom-toolbar {
        bottom: 8px;
        gap: 4px;
    }
    
    .toolbar-button {
        width: 45px;
        height: 45px;
    }
    
    .toolbar-button svg,
    .toolbar-button img {
        width: 20px;
        height: 20px;
    }
    
    
    .effects-option {
        height: 45px;
    }
}

/* Touch-friendly improvements for mobile devices */
@media (hover: none) and (pointer: coarse) {
    /* Touch devices - improve touch targets */
    .sidebar-tool {
        min-width: 44px;
        min-height: 44px;
    }
    
    .toolbar-button {
        min-width: 44px;
        min-height: 44px;
    }
    
    
    /* Remove hover effects on touch devices */
    .sidebar-tool:hover,
    .toolbar-button:hover {
        background-color: rgba(255, 255, 255, 0.1);
        transform: none;
    }
    
    /* Add active states for touch */
    .sidebar-tool:active,
    .toolbar-button:active {
        background-color: rgba(255, 255, 255, 0.3);
        transform: scale(0.95);
    }
    

    /* Improve touch targets for shape handles */
    .editor-canvas {
        touch-action: none; /* Prevent default touch behaviors like scrolling */
    }

    /* Make corner handles larger on touch devices */
    .editor-canvas::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        pointer-events: none;
        z-index: 1;
    }
}

/* Mobile Landscape Orientation - Use fluid sizing; avoid hard pixel overrides */
@media (max-width: 768px) and (orientation: landscape) {
    #launchScreen { padding: 4vh; }
    .logo-container { margin: 4vh 0; }
    .main-navigation { gap: 3vh; margin-bottom: 3vh; }
}

/* Very small screens - keep fluid units; no fixed minimums */
@media (max-width: 600px) and (orientation: landscape) {
    #launchScreen { padding: 3vh; }
    /* Logo and title sizes removed - use default sizes for consistency with rotated portrait */
    .main-navigation { gap: 3vh; margin-bottom: 3vh; }
}

/* Additional touch improvements for all mobile devices */
@media (max-width: 768px) {
    /* Ensure minimum touch targets */
    .sidebar-tool {
        min-width: 44px;
        min-height: 44px;
    }
    
    .toolbar-button {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Mobile portrait: rotate launch screen to look exactly like landscape */
@media (orientation: portrait) and (hover: none) and (pointer: coarse) {
    #launchScreen {
        position: fixed;
        top: 50%;
        left: 50%;
        width: 100vw;
        height: 100vh;
        transform: translate(-50%, -50%) rotate(90deg);
        transform-origin: center center;
    }
}

/* General mobile adjustment: make left toolbar fit on phones (all mobile browsers) */
@media (max-width: 900px) {
    /* move toolbar 10px further from the left edge to avoid notch */
    .editor-sidebar { gap: 2px !important; left: 70px !important; }
    .sidebar-tool { width: 30px !important; height: 30px !important; }
    .sidebar-tool svg,
    .sidebar-tool img { width: 24px !important; height: 24px !important; }
}