/* Desktop and general styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    width: 100vw;
    height: 100vh;
    min-height: 500px; /* Prevent screen from getting too small */
    overflow: hidden; /* Prevent any scrolling */
    background-color: #1a1a1a;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.clear-all-btn, .export-image-btn, .toggle-notes-btn {
    color: white;
    border: none;
    border-radius: 5px;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    z-index: 1000;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    transition: background-color 0.2s;
    width: 100px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-all-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    background-color: #f44336;
}

.toggle-notes-btn {
    position: fixed;
    top: 70px;
    right: 20px;
    background-color: #2196F3;
}

.button-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    z-index: 1000;
}

.export-image-btn {
    position: fixed;
    top: 120px;
    right: 20px;
    background-color: #4CAF50;
}

.kofi-button {
    display: flex;
    align-items: center;
}

.clear-all-btn:hover {
    background-color: #d32f2f;
}

.toggle-notes-btn:hover {
    background-color: #0b7dda;
}

.export-image-btn:hover {
    background-color: #3e8e41;
}

.container {
    display: flex;
    width: 100%;
    max-width: 100vw;
    height: 100vh;
    min-height: 500px; /* Match body minimum height */
    padding: 20px;
    overflow: hidden; /* Prevent overflow */
    box-sizing: border-box;
}

.sidebar {
    width: 270px; /* Increased from 250px for bigger planets */
    min-width: 270px;
    max-width: 270px;
    height: 100%;
    min-height: 400px; /* Ensure enough space for planets */
    padding: 10px;
    background: white;
    border-radius: 10px;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    gap: 10px; /* Clear separation between sections */
    overflow: hidden; /* Prevent sidebar overflow */
    box-sizing: border-box;
}

.sidebar h2 {
    color: black;
    margin-bottom: 8px;
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.background-selector {
    margin-bottom: 0; /* Remove default margin, use gap instead */
}

#backgroundSelect {
    width: 100%;
    padding: 8px;
    border-radius: 5px;
    background: white;
    border: 1px solid rgba(0, 0, 0, 0.2);
    color: black;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24"><path fill="black" d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px;
}

.planet-selector {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    gap: 4px; /* Slightly increased gap for bigger planets */
    flex: 1;
    overflow: hidden; /* No scrollbar - force everything to fit */
    max-height: calc(100% - 100px); /* Optimized space for headings and background selector */
    align-items: center;
    align-content: flex-start; /* Pack planets to the top */
    padding: 8px 4px;
    width: 100%;
}

.draggable {
    width: 50px; /* Increased from 42px for better visibility */
    height: 50px; /* Increased from 42px for better visibility */
    cursor: grab;
    opacity: 0.85;
    transition: opacity 0.2s ease, background-color 0.2s ease; /* Only transition non-drag properties */
    object-fit: contain;
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.05);
    padding: 2px;
    flex-shrink: 0; /* Prevent shrinking */
}

.draggable:hover {
    opacity: 1;
    transform: scale(1.05);
    background-color: rgba(255, 255, 255, 0.1);
}

/* Disable all transitions during drag operations */
.dragging, .dragging * {
    transition: none !important;
    pointer-events: none !important;
}

/* Override hover effects during drag */
.dragging.draggable:hover {
    transform: none !important;
    opacity: 0.8 !important;
}

.main-content {
    flex: 1;
    position: relative;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    border-radius: 10px;
    overflow: hidden;
    margin-left: 20px;
}

.app-title {
    position: absolute;
    top: 20px;
    left: 0;
    right: 0;
    text-align: center;
    color: black;
    font-size: 28px;
    font-weight: bold;
    z-index: 10;
    font-family: 'Arial', sans-serif;
    letter-spacing: 1px;
    -webkit-text-stroke: 0.5px white;
    text-stroke: 0.5px white;
}

.background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    object-fit: contain;
}

.planet-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
}

.notes-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    z-index: 5;
}

#notesArea {
    width: 100%;
    height: 150px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background-color: rgba(200, 200, 200, 0.7);
    color: black;
    font-family: Arial, sans-serif;
    resize: none;
    font-size: 14px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.footer-credit {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    text-align: center;
    color: #666666;
    font-size: 14px;
    z-index: 10;
    font-family: 'Arial', sans-serif;
}

.footer-credit a {
    color: #4CAF50;
    text-decoration: none;
    transition: color 0.2s;
}

.footer-credit a:hover {
    color: #8bc34a;
    text-decoration: underline;
}

.dragged-planet {
    position: absolute;
    cursor: move;
    transition: none; /* Remove transform transition to prevent drag lag */
    width: 50px; /* Match increased desktop planet size */
    height: 50px;
    object-fit: contain;
}

/* Mobile touch optimization - no scrollbars */
@media (max-width: 768px) {
    body {
        width: 100vw;
        height: 100vh;
        min-height: 350px; /* Reduced minimum for more compact mobile layout */
        overflow-y: auto !important; /* Allow vertical scrolling */
        overflow-x: hidden !important; /* Prevent horizontal scrolling */
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
    
    .container {
        flex-direction: column;
        width: 100vw;
        height: auto !important; /* Let container size based on content */
        min-height: 100vh !important; /* Minimum full height */
        padding: 0;
        overflow-y: auto !important; /* Allow scrolling if needed */
        overflow-x: hidden !important;
        box-sizing: border-box;
        display: flex;
        justify-content: flex-start;
        gap: 0;
    }
    
    .main-content {
        order: 1;
        flex: 0 0 auto; /* Use content size */
        width: 100%;
        height: 65vh !important; /* Reduced from 75vh to leave more room for planets */
        margin-bottom: 0;
        overflow: hidden;
        margin-left: 0;
        min-height: 0;
        padding-bottom: 0;
        position: relative !important;
    }
    
    .sidebar {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        height: auto !important; /* Let it size based on content */
        min-height: 120px !important; /* Minimum space for planets */
        max-height: none !important; /* Remove height restriction - allow full expansion */
        order: 2;
        padding: 5px !important; /* Slightly more padding for better spacing */
        background: white;
        border-radius: 8px;
        backdrop-filter: blur(10px);
        flex-shrink: 0;
        overflow-y: auto !important; /* Allow vertical scrolling within sidebar */
        overflow-x: hidden !important; /* Prevent horizontal overflow */
        display: flex !important;
        flex-direction: column !important;
        gap: 2px !important; /* Slightly more gap for better readability */
        box-sizing: border-box;
        margin-top: 0 !important;
        position: relative !important;
    }
    
    .sidebar h2 {
        font-size: 11px !important; /* Smaller font */
        margin-bottom: 2px !important; /* Reduced margin */
        text-align: center;
        color: black;
        line-height: 1 !important; /* Tighter line height */
    }
    
    .sidebar h2:first-child {
        order: 1;
    }
    
    .sidebar h2:nth-child(3) {
        order: 3;
    }
    
    .sidebar .background-selector {
        order: 2;
        display: flex !important;
        justify-content: center !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .sidebar .background-selector #backgroundSelect {
        width: 80px !important; /* Smaller dropdown */
        height: 22px !important; /* Smaller height */
        padding: 1px !important;
        font-size: 9px !important; /* Smaller font */
        border-radius: 4px !important;
        background-color: #2196F3 !important;
        color: white !important;
        border: none !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3) !important; /* Smaller shadow */
        -webkit-appearance: none !important;
        -moz-appearance: none !important;
        appearance: none !important;
    }
    
    .sidebar .planet-selector {
        order: 4;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 4px !important; /* Increased gap for better spacing */
        justify-content: center !important;
        align-items: flex-start !important; /* Align to top for better wrapping */
        overflow-y: auto !important; /* Allow vertical scrolling if planets overflow */
        overflow-x: hidden !important; /* Prevent horizontal overflow */
        padding: 4px !important; /* More padding for better touch targets */
        width: 100% !important;
        height: auto !important; /* Let it grow to fit multiple rows */
        max-height: 250px !important; /* Set a reasonable max but allow scrolling */
        flex: 1 !important; /* Take available space */
        min-height: 80px !important; /* Ensure minimum space for planets */
        /* Add scrollbar styling for mobile */
        -webkit-overflow-scrolling: touch !important; /* Smooth scrolling on iOS */
    }
    
    /* Style scrollbars for mobile planet selector */
    .sidebar .planet-selector::-webkit-scrollbar {
        width: 4px !important;
    }
    
    .sidebar .planet-selector::-webkit-scrollbar-track {
        background: rgba(0,0,0,0.1) !important;
        border-radius: 2px !important;
    }
    
    .sidebar .planet-selector::-webkit-scrollbar-thumb {
        background: rgba(0,0,0,0.3) !important;
        border-radius: 2px !important;
    }
    
    .sidebar .planet-selector::-webkit-scrollbar-thumb:hover {
        background: rgba(0,0,0,0.5) !important;
    }
    
    /* Style scrollbars for main sidebar */
    .sidebar::-webkit-scrollbar {
        width: 4px !important;
    }
    
    .sidebar::-webkit-scrollbar-track {
        background: rgba(0,0,0,0.1) !important;
        border-radius: 2px !important;
    }
    
    .sidebar::-webkit-scrollbar-thumb {
        background: rgba(0,0,0,0.3) !important;
        border-radius: 2px !important;
    }
    
    .sidebar::-webkit-scrollbar-thumb:hover {
        background: rgba(0,0,0,0.5) !important;
    }
    
    .sidebar .planet-selector .draggable {
        width: 32px !important; /* Much bigger than previous 18-24px */
        height: 32px !important; /* Much bigger than previous 20px */
        min-width: 32px !important;
        max-width: 32px !important;
        min-height: 32px !important;
        max-height: 32px !important;
        flex-shrink: 0 !important;
        opacity: 0.9 !important;
        cursor: grab !important;
        margin: 0 !important;
        object-fit: contain !important;
    }
    
    .sidebar .planet-selector .draggable:active {
        transform: scale(1.05) !important;
        opacity: 1 !important;
    }
    
    .dragged-planet {
        width: 32px !important; /* Match bigger mobile planet size */
        height: 32px !important;
    }
    
    /* Compact button layout for mobile */
    .clear-all-btn, .export-image-btn, .toggle-notes-btn {
        width: 45px !important; /* Smaller buttons */
        height: 26px !important;
        font-size: 10px !important;
        padding: 1px !important;
    }
    
    .clear-all-btn {
        top: 3px !important;
        right: 3px !important;
    }
    
    .toggle-notes-btn {
        top: 32px !important;
        right: 3px !important;
    }
    
    .export-image-btn {
        top: 61px !important;
        right: 3px !important;
    }
    
    .notes-container {
        width: 200px !important; /* Smaller notes */
        max-width: 80vw !important;
    }
    
    #notesArea {
        height: 70px !important; /* Smaller notes area */
        font-size: 10px !important;
    }
    
    .app-title {
        font-size: 16px !important; /* Smaller title */
        top: 5px !important;
        font-weight: bold !important;
        -webkit-text-stroke: 0.5px white !important;
        text-stroke: 0.5px white !important;
    }
    
    .footer-credit {
        font-size: 9px !important; /* Smaller footer */
        bottom: 5px !important;
        color: #666666 !important;
    }
    
    .button-container {
        position: fixed !important;
        top: 90px !important; /* Adjusted position */
        right: 3px !important;
        bottom: auto !important;
        z-index: 1000 !important;
        gap: 3px !important;
    }
    
    .kofi-button {
        display: flex !important;
        align-items: center !important;
    }
    
    .kofi-button img {
        height: 20px !important; /* Smaller coffee button */
        width: auto !important;
    }
}

/* Prevent default touch behaviors and drag artifacts */
*:focus {
    outline: none !important;
}

.draggable, .dragged-planet, .planet-container, .main-content {
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.dragged-planet {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

