:root {
    --button-height: 44px;
    --slider-height: 40px;
    --palette-bar-height: 84px;
    --bottom-bar-height: calc(var(--button-height) + var(--slider-height) * 2 + var(--palette-bar-height) + 40px);
}

body {
    margin: 0;
    background: black;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

#canvas-container {
    display: flex;
    position: relative;
    overflow: hidden;
    align-items: flex-start;
    justify-content: center;
    flex-shrink: 0;
}

#out {
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1 / 1;
    width: min(100vw, 70vh);
    height: min(100vw, 70vh);
}

#palettes-container {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    width: 100%;
    gap: 10px;
    height: var(--palette-bar-height);
    align-items: center;
    cursor: grab;
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
    padding: 6px 10px;
    /* Improve touch scrolling on mobile */
    -webkit-overflow-scrolling: touch;
    /* Ensure the container is scrollable on mobile */
    overscroll-behavior-x: contain;
    /* Make it sticky to the top */
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #111;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

#palettes-container::-webkit-scrollbar {
    display: none;
}

#palettes-container.grabbing {
    cursor: grabbing;
}

#palettes-container, #palettes-container * {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Improve touch targets on mobile */
@media (max-width: 768px) {
    #palettes-container {
        padding: 6px 15px;
        /* min-height: 84px; */
    }
    
    #palettes-container img {
        min-width: 64px;
        min-height: 64px;
    }
    
    #bottom-bar {
        padding-bottom: 80px;
    }
}

.selected-palette {
    border: 2px solid #fff;
    box-sizing: border-box;
}

#advanced-controls {
    display: none;
}

#advanced-controls.visible {
    display: block;
}

.slider-with-icon {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.rotation-icon {
    color: #ccc;
    font-size: 18px;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

/* Reset button: inherit kernel-button style but smaller */
#tileParamReset.small-button {
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0; /* keep square within flex row */
    flex-direction: row;
}
#tileParamReset.small-button i {
    font-size: 18px;
}

/* Click feedback when pressed */
#tileParamReset.small-button.flash {
    background-color: #519CFE;
    border-color: #519CFE;
    color: #fff;
}
#tileParamReset.small-button.flash i {
    color: #fff;
}

/* Prevent focus/selection highlight after click */
#tileParamReset.small-button,
#tileParamReset.small-button:focus,
#tileParamReset.small-button:active {
    outline: none;
    background-color: #333;
    border-color: #555;
    user-select: none;
    -webkit-user-select: none;
    /* Remove default iOS/Android tap highlight */
    -webkit-tap-highlight-color: transparent;
}

#bottom-content {
    background-color: #111;
    flex-grow: 1;
    overflow: hidden;
    border-top: 1px solid #333;
    display: flex;
    flex-direction: column;
}

#bottom-bar {
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    overflow-y: auto;
    flex-grow: 1;
    /* Add generous padding at the bottom to prevent cutoff */
    padding-bottom: 60px;
    /* Enable touch scrolling even when touching UI elements */
    -webkit-overflow-scrolling: touch;
    /* Allow vertical scrolling while preserving horizontal interactions */
    touch-action: pan-y;
}

/* Scrollbar styling for the bottom content */
#bottom-content::-webkit-scrollbar {
    width: 8px;
}

#bottom-content::-webkit-scrollbar-track {
    background: #222;
}

#bottom-content::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 4px;
}

#bottom-content::-webkit-scrollbar-thumb:hover {
    background: #777;
}

#button-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    width: 100%;
}

#slider-container {
    width: 100%;
    user-select: none;
    -webkit-user-select: none;
}

.control-slider {
    width: 100%;
    margin: 0;
    height: var(--slider-height);
    transition: background-size 0.1s ease-out;
}

.slider-with-icon .control-slider {
    flex-grow: 1;
}

.control-button {
    background-color: #ccc;
    border: 1px solid #ccc;
    padding: 0;
    cursor: pointer;
    height: var(--button-height);
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: #000;
}

.control-button i {
    color: #000;
}

#menu-toggle {
    flex-shrink: 0;
    margin-left: 10px;
    width: 80px;
}

#palettes-toggle {
    flex-shrink: 0;
    margin-left: 10px;
    width: 80px;
}

#kernel-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 4px;
    width: 100%;
    margin: 8px 0;
}

.kernel-button {
    background-color: #333;
    border: 1px solid #555;
    color: #ccc;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: all 0.2s ease;
    min-height: 44px;
    min-width: 80px;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    #kernel-container {
        grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
        gap: 6px;
    }
    
    .kernel-button {
        min-width: 90px;
        padding: 8px 4px;
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    #kernel-container {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
    
    .kernel-button {
        min-width: 0;
        padding: 10px 4px;
        font-size: 12px;
    }
    
    #bottom-bar {
        padding-bottom: 100px;
    }
}

.kernel-button:hover {
    background-color: #444;
    border-color: #777;
}

.kernel-button.active {
    background-color: #519CFE;
    border-color: #519CFE;
    color: white;
}

.kernel-button i {
    font-size: 14px;
}

.kernel-button span {
    font-size: 8px;
    font-weight: 500;
    text-align: center;
    line-height: 1;
}

/* Generic small square kernel-style button (used for action buttons & reset) */
.kernel-button.small-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    flex-direction: row; /* horizontal layout so single icon is centered */
}
.kernel-button.small-button i {
    font-size: 18px;
}

/* Flash feedback on click */
.kernel-button.small-button.flash {
    background-color: #519CFE;
    border-color: #519CFE;
    color: #fff;
}
.kernel-button.small-button.flash i {
    color: #fff;
}

/* Prevent focus/selection highlight after click */
.kernel-button.small-button,
.kernel-button.small-button:focus,
.kernel-button.small-button:active {
    outline: none;
    background-color: #333;
    border-color: #555;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Wide bar-style kernel button (used for capture/upload/download/advanced) */
.kernel-button.bar-button {
    width: 100%;
    height: var(--button-height);
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: row;
    gap: 0;
}
.kernel-button.bar-button i {
    font-size: 24px; /* restore larger icon size */
}

.kernel-button.bar-button.flash {
    background-color: #519CFE;
    border-color: #519CFE;
    color: #fff;
}
.kernel-button.bar-button.flash i {
    color: #fff;
}

.kernel-button.bar-button,
.kernel-button.bar-button:focus,
.kernel-button.bar-button:active {
    outline: none;
    background-color: #333;
    border-color: #555;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#notes {
    grid-column: 1 / -1;
    color: #ccc;
    font-size: 12px;
    text-align: center;
    padding-top: 10px;
}

input[type="file"] {
    display: none;
}

input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* Prevent blue highlight on iOS/Android when touching slider */
    -webkit-tap-highlight-color: transparent;
    /* Disable default touch handling so our JS can determine intent */
    touch-action: pan-y;
    /* Remove default outline when focussed */
    outline: none;
}

input[type=range]::-webkit-slider-runnable-track {
    background: linear-gradient(#519CFE, #519CFE) 0/var(--p, 0%) 100% no-repeat #333;
    height: 16px;
    border-radius: 8px;
}

input[type=range]::-moz-range-track {
    background: linear-gradient(#519CFE, #519CFE) 0/var(--p, 0%) 100% no-repeat #333;
    height: 16px;
    border-radius: 8px;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    margin-top: -8px;
    width: 32px;
    height: 32px;
    background: #519CFE;
    cursor: pointer;
    border-radius: 50%;
    /* Prevent thumb from receiving tap highlight */
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-y;
}

input[type=range]::-moz-range-thumb {
    border: none;
    width: 32px;
    height: 32px;
    background: #519CFE;
    cursor: pointer;
    border-radius: 50%;
} 