:root {
    --chart-control-h: 1.75rem;
    --chart-output-w: 7ch; /* width of a slider's value; set per control for longer values */
    --chart-field: color-mix(in oklab, var(--secondary-color) 6%, var(--primary-color));
}

.chart-container {
    min-width: 0;
    margin: 1rem 0;
}

.chart-button {
    font: inherit;
    color: var(--secondary-color);
    background: transparent;
    border: none;
    border-radius: 0.25rem;
    padding: 0.15rem 0.6rem;
    cursor: pointer;
    transition: color 0.5s ease-in-out;
}

.chart-button:hover {
    color: color-mix(in srgb, var(--secondary-color) 60%, transparent);
}

.chart-button.is-on {
    background: var(--accent-color);
}

.chart-button:disabled {
    opacity: 0.35;
    cursor: default;
}

.chart-button.is-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--chart-control-h);
    aspect-ratio: 1;
    padding: 0;
}

.chart-button.is-icon svg {
    width: 1.25rem;
    height: 1.25rem;
}

.chart-select {
    height: var(--chart-control-h);
    appearance: none;
    font: inherit;
    color: var(--secondary-color);
    /* The chevron's stroke is --secondary-color, written out: a data URI cannot read a CSS variable */
    background: var(--chart-field)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23060606' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9L12 15L18 9'/%3E%3C/svg%3E")
        no-repeat right 0.4rem center / 1rem;
    border: none;
    border-radius: 0.25rem;
    padding: 0 1.75rem 0 0.5rem;
    cursor: pointer;
}

.chart-select:focus-visible,
.chart-slider:focus-visible {
    outline: 1px solid var(--secondary-color);
    outline-offset: 2px;
}

.chart-slider {
    --track: color-mix(in oklab, var(--secondary-color) 15%, var(--primary-color));
    --fill: 50%;
    appearance: none;
    width: 100%;
    height: var(--chart-control-h);
    background: transparent;
    cursor: pointer;
}

.chart-slider::-webkit-slider-runnable-track {
    height: 4px;
    border-radius: 999px;
    background: linear-gradient(to right, var(--secondary-color) var(--fill), var(--track) var(--fill));
}

.chart-slider::-moz-range-track {
    height: 4px;
    border-radius: 999px;
    background: var(--track);
}

.chart-slider::-moz-range-progress {
    height: 4px;
    border-radius: 999px;
    background: var(--secondary-color);
}

.chart-slider::-webkit-slider-thumb {
    appearance: none;
    width: 12px;
    height: 12px;
    margin-top: -4px;
    border: none;
    border-radius: 50%;
    background: var(--secondary-color);
}

.chart-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border: none;
    border-radius: 50%;
    background: var(--secondary-color);
}

.chart-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem 1rem;
    margin-top: 1rem;
    font-size: 0.875rem;

    input {
        font: inherit;
    }
}

.chart-control {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chart-control-name {
    font-weight: 500;
}

/* A colour legend field: min label, colour bar, max label, on one row as tall as a control */
.chart-legend {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: var(--chart-control-h);
    font-variant-numeric: tabular-nums;
}

.chart-legend-bar {
    flex: 1;
    height: 0.625rem;
    border-radius: 0.25rem;
}

/* A slider field: name on top, then the slider with its value to the right in a fixed-width box */
.chart-control:has(> .chart-slider) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--chart-output-w);
    align-items: center;
    column-gap: 0.5rem;

    > .chart-control-name {
        grid-column: 1 / -1;
    }

    > output {
        text-align: right;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }
}
