body {
    margin: 0;
    overflow: hidden;
    background-color: #111;
    color: #eee;
    font-family: system-ui, -apple-system, sans-serif;
}

#ui-container {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 280px;
    background: rgba(20, 20, 30, 0.85);
    backdrop-filter: blur(10px);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.back-link {
    position: absolute;
    top: 1rem;
    left: 1rem;
    padding: 0.5rem 1rem;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 0.9rem;
    background: rgba(20, 20, 30, 0.6);
    border-radius: 6px;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: color 0.2s, background 0.2s;
    z-index: 50;
}

.back-link:hover {
    color: #fff;
    background: rgba(20, 20, 30, 0.9);
}

h1 {
    font-size: 1.2rem;
    margin: 0 0 1rem 0;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

.control-group {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

label {
    font-size: 0.85rem;
    color: #aaa;
    display: flex;
    justify-content: space-between;
}

input[type="number"],
select {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
}

input[type="range"] {
    width: 100%;
    accent-color: #ffd700;
}

button {
    width: 100%;
    padding: 10px;
    background: linear-gradient(135deg, #ffd700, #ffaa00);
    border: none;
    border-radius: 6px;
    color: #111;
    font-weight: bold;
    cursor: pointer;
    font-size: 0.95rem;
    text-transform: uppercase;
    transition: filter 0.2s;
    margin-top: 0.5rem;
}

button:hover {
    filter: brightness(1.1);
}

button:active {
    filter: brightness(0.95);
}

.collapsible-header {
    font-size: 0.8rem;
    color: #888;
    cursor: pointer;
    margin: 1rem 0 0.5rem 0;
    user-select: none;
    display: flex;
    align-items: center;
}

.collapsible-header::before {
    content: '▶';
    display: inline-block;
    margin-right: 6px;
    font-size: 0.6rem;
    transition: transform 0.2s;
}

.collapsible-header.active::before {
    transform: rotate(90deg);
}

.collapsible-content {
    display: none;
    padding-left: 5px;
    border-left: 2px solid rgba(255, 255, 255, 0.05);
    margin-left: 3px;
}

.collapsible-content.active {
    display: block;
}

span[id$="-val"] {
    font-family: monospace;
    font-size: 0.8rem;
    color: #ffd700;
}

.mobile-toggle {
    display: none;
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%) rotate(180deg);
    /* Point UP by default (visible state) */
    width: 40px;
    height: 30px;
    background: rgba(20, 20, 30, 0.85);
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    text-align: center;
    line-height: 30px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-top: none;
    color: #ffd700;
    font-size: 0.8rem;
    transition: transform 0.3s;
}

.mobile-toggle.collapsed {
    transform: translateX(-50%) rotate(0deg);
    /* Point DOWN when hidden */
}

@media (max-width: 600px) {
    #ui-container {
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        box-sizing: border-box;
        border-radius: 0 0 12px 12px;
    }

    #ui-container.hidden {
        transform: translateY(-100%);
    }

    .mobile-toggle {
        display: block;
    }

    .ui-content-wrapper {
        max-height: 80vh;
        overflow-y: auto;
    }

}

#legend-container {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.legend-item {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: bold;
    color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
    background-color: #eee;
    text-shadow: 0px 0px 1px rgba(255, 255, 255, 0.8);
}

#mobile-overlay {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 90;
    pointer-events: none;
}

#mobile-n-display {
    font-size: 1.5rem;
    font-weight: bold;
    color: hsl(115, 100%, 48%);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    pointer-events: auto;
}

.mobile-buttons {
    display: flex;
    gap: 15px;
    pointer-events: auto;
}

.mobile-buttons button {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    padding: 0;
    margin: 0;
    font-size: 1rem;
    line-height: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    background: rgba(20, 20, 30, 0.85);
    border: 0px solid rgba(255, 215, 0, 0.3);
    color: hsl(115, 100%, 48%);
    backdrop-filter: blur(4px);
    transition: transform 0.1s, background 0.2s;
}

.mobile-buttons button:active {
    transform: scale(0.95);
    background: rgba(40, 40, 50, 0.95);
}

@media (max-width: 600px) {
    #mobile-overlay {
        display: flex;
    }
}