/* Base table styles */
.colour-matrix {
    width: 100%;
    border-collapse: collapse;
    text-align: center;
}

.colour-matrix th,
.colour-matrix td {
    background: var(--bg-colour);
    color: var(--text-colour);
}

.colour-matrix .colour-name {
    text-transform: capitalize;
}

.colour-matrix .colour-value {
    font-size: 0.9rem;
}

.rating-cell {
    padding: 0.5rem;
}

.colour-matrix .rating {
    padding: 0.5rem 1rem;
    border-radius: 100vw;
    font-weight: 700;
    display: none;
}

.colour-matrix .rating-G {
    color: #856404;
    background-color: #fff3cd;
    border-color: #ffeeba;
}

.colour-matrix .rating-AA,
.colour-matrix .rating-AAA {
    color: #155724;
    background-color: #d4edda;
    border-color: #c3e6cb;
}

.colour-matrix .rating-null,
.colour-matrix .rating-cell.not-text {
    background: var(--surface-10);
    color: transparent;
}

.rating-cell .colours {
    font-size: 1.2rem;
}

.rating-cell .colours span {
    font-weight: 700;
}

.toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1rem 0;
}

#toggleRatings {
    display: none;
}

/* Toggle button base styles */
.toggle-button {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
    background-color: #ccc;
    border-radius: 50px;
    transition: background-color 0.3s ease;
    cursor: pointer;
}

.toggle-button::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

/* Visual toggle behavior when checked */
#toggleRatings:checked + .toggle-wrapper .toggle-button {
    background-color: #4caf50;
}

#toggleRatings:checked + .toggle-wrapper .toggle-button::after {
    transform: translateX(24px);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

#toggleRatings:checked ~ * .rating-cell {
    background: unset;
    color: unset;
}

#toggleRatings:checked ~ .matrix-wrapper .rating-cell .rating {
    display: inline-block;
}

#toggleRatings:checked ~ .matrix-wrapper .rating-cell .colours {
    display: none;
}

[data-tooltip] {
    position: relative;
    cursor: pointer;
}

[data-tooltip]:before,
[data-tooltip]:after {
    --scale: 0;
    --arrow-size: 8px;
    --tooltip-color: hsla(191, 0%, 95%, 0.9);
    --tooltip-text-color: #222222;
    position: absolute;
    top: -0.25rem;
    left: 50%;
    transform: translateX(-50%) translateY(var(--translate-y, 0))
        scale(var(--scale));
    transition: 150ms transform;
    transform-origin: bottom center;
}

[data-tooltip]:before {
    --translate-y: calc(-100% - var(--arrow-size));
    content: attr(data-tooltip);
    color: var(--tooltip-text-color);
    font-size: 0.8rem;
    line-height: 1;
    padding: 0.4rem 0.6rem;
    width: max-content;
    background: var(--tooltip-color);
    border-radius: 0.3rem;
    text-align: center;
}

[data-tooltip]:hover:before,
[data-tooltip]:hover:after {
    --scale: 1;
}

[data-tooltip]:after {
    --translate-y: calc(-1 * var(--arrow-size));
    content: "";
    border: var(--arrow-size) solid transparent;
    border-top-color: var(--tooltip-color);
}

/* No-JS fallback warning */
.no-js-warning {
    background: #ffefc5;
    border: 1px solid #ffc107;
    color: #856404;
    padding: 0.5rem;
    margin: 1rem 0;
    font-size: 0.9rem;
}

/* Fade-in animation for ratings */
.colour-matrix .rating {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

#toggleRatings:checked ~ .matrix-wrapper .rating-cell .rating {
    display: inline-block;
    opacity: 1;
}
