/*
 * The achievement manager (partials/achievement-manager.php; ruling R25), on the developer's dashboard tab and on
 * the staff record of a game. The list in a card with the form beside it (.with-aside; one column below 1040px):
 * a row per achievement with its order keys, its icon in a keycap tile, the name and key, who earned it and the
 * actions; retired ones fold away below.
 */

/* An achievement's colour (Achievements::COLOURS): the gold badge's tokens with the hue turned (--ach-h, unset =
   gold) and the chroma scaled (--ach-c: 0 = grey), set inline on the badge or an ancestor. The profile pages load
   this file for their badges too (accounts.css draws them). */
.ach-tone,
.ach-icons__pick > input:checked + .ach-icons__tile {
    --ach-bg: var(--warn-bg);
    --ach-line: var(--warn-strong);
    --ach-fg: var(--warn-fg);
}
@supports (color: oklch(from red l c h)) {
    .ach-tone,
    .ach-icons__pick > input:checked + .ach-icons__tile {
        --ach-bg: oklch(from var(--warn-bg) l calc(c * var(--ach-c, 1)) var(--ach-h, h));
        --ach-line: oklch(from var(--warn-strong) l calc(c * var(--ach-c, 1)) var(--ach-h, h));
        --ach-fg: oklch(from var(--warn-fg) l calc(c * var(--ach-c, 1)) var(--ach-h, h));
    }
}


.ach-manager__intro {
    grid-column: 1 / -1;
    margin: 0;
}

.ach-rows {
    display: grid;
    gap: var(--sp-2);
    margin: 0;
    padding: 0;
    list-style: none;
}
.ach-row {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) minmax(110px, 150px);
    grid-template-areas:
        "order icon main earned"
        "order icon actions actions";
    align-items: start;
    gap: var(--sp-1) var(--sp-3);
    margin: 0;
    padding: var(--sp-3);
    border-radius: var(--radius-2);
    background: var(--bg-raised-2);
    box-shadow: inset 0 0 0 1px var(--line);
    scroll-margin-top: var(--sticky-top);
}
/* read-only: no order keys, no actions */
.ach-row:not(:has(> .ach-row__order)) {
    grid-template-columns: auto minmax(0, 1fr) minmax(110px, 150px);
    grid-template-areas: "icon main earned";
    align-items: center;
}
.ach-row__order { grid-area: order; }
.ach-row__icon { grid-area: icon; }
.ach-row__main { grid-area: main; }
.ach-row__earned { grid-area: earned; }
.ach-row__actions { grid-area: actions; }
.ach-row.is-editing {
    box-shadow: inset 0 0 0 2px var(--accent);
}
.ach-row.is-retired > :not(.ach-row__actions) {
    opacity: 0.7;
}
.ach-row:target {
    box-shadow: inset 0 0 0 2px var(--focus-ring);
}

.ach-row__order {
    display: grid;
    gap: 2px;
}
.ach-row__order form,
.ach-row__actions form {
    margin: 0;
}

.ach-row__icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-1);
    background: var(--ach-bg);
    box-shadow: inset 0 0 0 1px var(--ach-line);
    color: var(--ach-fg);
}

.ach-row__main,
.ach-row__earned {
    display: grid;
    gap: 2px;
    min-width: 0;
}
.ach-row__main > p,
.ach-row__earned > p {
    margin: 0;
}
.ach-row__name {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    color: var(--fg-strong);
    font-weight: 600;
}
.ach-row__desc {
    color: var(--fg);
    font-size: var(--text-sm);
}
.ach-row__key {
    display: flex;
    align-items: center;
    gap: 2px;
    min-width: 0;
    font-size: var(--text-xs);
}
.ach-row__key code {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ach-row__count {
    color: var(--fg);
    font-size: var(--text-sm);
}
.ach-row__count strong {
    color: var(--fg-strong);
}
.ach-row__count.is-none,
.ach-row__last {
    color: var(--fg-muted);
    font-size: var(--text-xs);
}
.ach-row__bar {
    display: block;
    height: 4px;
    overflow: hidden;
    border-radius: 2px;
    background: var(--line);
}
.ach-row__bar > span {
    display: block;
    width: var(--share, 0%);
    min-width: 2px;
    height: 100%;
    background: var(--warn-strong);
}

.ach-row__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-1);
    margin-left: calc(var(--sp-2) * -1);
}

/* a narrow card (a phone): who earned it goes under the name */
@container (max-width: 30rem) {
    .ach-row {
        grid-template-columns: auto auto minmax(0, 1fr);
        grid-template-areas:
            "order icon main"
            "order icon earned"
            "order icon actions";
    }
    .ach-row:not(:has(> .ach-row__order)) {
        grid-template-columns: auto minmax(0, 1fr);
        grid-template-areas: "icon main" "icon earned";
    }
}
.ach-manager > .card {
    container-type: inline-size;
}

.ach-retired > summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: var(--sp-2) 0;
    color: var(--fg-strong);
    font-weight: 600;
    cursor: pointer;
}
.ach-retired > summary .muted {
    font-weight: 400;
    font-size: var(--text-sm);
}

/* ---- the form */

/* the preview, folded under a key until opened; the chevron turns when open */
.ach-preview-box > summary {
    list-style: none;
}
.ach-preview-box > summary::-webkit-details-marker {
    display: none;
}
.ach-preview-box__key {
    width: 100%;
    justify-content: flex-start;
}
.ach-preview-box__what {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    color: var(--fg-muted);
    font-size: var(--text-xs);
    font-weight: 400;
    text-align: end;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ach-preview-box__key > .icon:last-child {
    transition: transform var(--dur-1);
}
.ach-preview-box[open] > .ach-preview-box__key > .icon:last-child {
    transform: rotate(180deg);
}
.ach-preview-box > .ach-preview {
    margin-top: var(--sp-3);
}

/* the preview: captions over the real pieces (the toast, the game panel's rows, the profile's badge and card) */
.ach-preview {
    display: grid;
    gap: var(--sp-2);
    padding: var(--sp-3);
    border-radius: var(--radius-2);
    background: var(--bg-sunken, var(--bg));
    box-shadow: inset 0 0 0 1px var(--line);
}
.ach-preview__label {
    margin: var(--sp-2) 0 0;
    color: var(--fg-muted);
    font-size: var(--text-xs);
    font-weight: 600;
}
.ach-preview__label:first-child {
    margin-top: 0;
}
.ach-preview .toast {
    box-shadow: var(--shadow-1);
    animation: none;
    pointer-events: none;
}
.ach-preview .toast__close {
    display: grid;
    flex: none;
    place-items: center;
    opacity: 0.7;
}
.ach-preview__rows {
    display: grid;
    gap: var(--sp-2);
    margin: 0;
    padding: 0;
    list-style: none;
}
.ach-preview__profile {
    display: flex;
    align-items: center;
    gap: 10px;
}
.ach-preview__badge {
    display: grid;
    flex: none;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-1);
    background: var(--ach-bg);
    box-shadow: inset 0 0 0 1px var(--ach-line);
    color: var(--ach-fg);
}
/* the profile's hover card (accounts.css .ach-tip), its arrow pointing at the badge */
.ach-preview__tip {
    position: relative;
    display: grid;
    gap: 2px;
    min-width: 0;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--bg-inverse);
    color: var(--fg-inverse);
    font-size: var(--text-xs);
    line-height: 1.35;
    overflow-wrap: anywhere;
}
.ach-preview__tip::before {
    content: "";
    position: absolute;
    top: 50%;
    left: -5px;
    width: 10px;
    height: 10px;
    background: inherit;
    transform: translateY(-50%) rotate(45deg);
}
.ach-preview__tip-game,
.ach-preview__tip-when {
    opacity: 0.8;
}
.ach-preview__tip-name {
    font-size: var(--text-sm);
    font-weight: 600;
}

/* an achievement's row in the game's Achievements panel (play/_achievements.php) and in the preview above:
   earned ones lit in their colour, the others dim and grey until earned */
.play-ach {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: var(--sp-3);
    margin: 0;
    padding: var(--sp-3);
    border-radius: var(--radius-2);
    background: var(--bg-raised-2);
    box-shadow: inset 0 0 0 1px var(--line);
}
.play-ach__icon {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-1);
    background: var(--ach-bg);
    box-shadow: inset 0 0 0 1px var(--ach-line);
    color: var(--ach-fg);
}
.play-ach:not(.is-earned) .play-ach__icon {
    background: var(--bg-raised);
    box-shadow: inset 0 0 0 1px var(--line-strong);
    color: var(--fg-muted);
}
.play-ach__text {
    display: grid;
    gap: 2px;
    min-width: 0;
    overflow-wrap: anywhere;
}
.play-ach__name {
    color: var(--fg-strong);
    font-weight: 600;
}
.play-ach:not(.is-earned) .play-ach__name {
    color: var(--fg);
}
.play-ach__desc {
    color: var(--fg);
    font-size: var(--text-sm);
}
.play-ach__desc[hidden] {
    display: none;
}
.play-ach__when {
    color: var(--fg-muted);
    font-size: var(--text-xs);
}
.ach-icons {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}
/* half a line between a picker's title and its tiles */
.ach-icons > legend {
    margin-bottom: var(--sp-4);
}

.ach-colours {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.ach-colours__pick {
    position: relative;
    display: block;
    cursor: pointer;
}
.ach-colours__pick > input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}
.ach-colours__swatch {
    display: block;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--ach-bg);
    box-shadow: inset 0 0 0 8px var(--ach-line);
}
.ach-colours__pick > input:checked + .ach-colours__swatch {
    box-shadow: inset 0 0 0 8px var(--ach-line), 0 0 0 2px var(--bg-raised), 0 0 0 4px var(--fg-strong);
}
.ach-colours__pick > input:focus-visible + .ach-colours__swatch {
    outline: 2px solid var(--focus-ring);
    outline-offset: 6px;
}
.ach-icons__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
    gap: 4px;
}
/* collapsed (achievements.js): the first 16, and the chosen one wherever it is */
.ach-icons__grid.is-collapsed > .ach-icons__pick:nth-child(n + 17):not(:has(> input:checked)) {
    display: none;
}
.ach-icons__more {
    justify-self: start;
    margin-top: var(--sp-2);
}
.ach-icons__more > .icon {
    transition: transform var(--dur-1);
}
.ach-icons__more[aria-expanded="true"] > .icon {
    transform: rotate(180deg);
}
.ach-icons__pick {
    position: relative;
    display: block;
    cursor: pointer;
}
.ach-icons__pick > input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}
.ach-icons__tile {
    display: grid;
    place-items: center;
    height: 34px;
    border-radius: var(--radius-1);
    background: var(--bg-raised-2);
    box-shadow: inset 0 0 0 1px var(--line);
    color: var(--fg);
}
.ach-icons__pick:hover > .ach-icons__tile {
    box-shadow: inset 0 0 0 1px var(--line-strong, var(--fg-muted));
}
.ach-icons__pick > input:checked + .ach-icons__tile {
    background: var(--ach-bg);
    box-shadow: inset 0 0 0 2px var(--ach-line);
    color: var(--ach-fg);
}
.ach-icons__pick > input:focus-visible + .ach-icons__tile {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

.ach-snippet {
    margin: 0;
    padding: var(--sp-2) var(--sp-3);
    overflow-x: auto;
    border-radius: var(--radius-1);
    background: var(--bg-raised-2);
    box-shadow: inset 0 0 0 1px var(--line);
    font-size: var(--text-sm);
}

@media (forced-colors: active) {
    .ach-icons__pick > input:checked + .ach-icons__tile,
    .ach-colours__pick > input:checked + .ach-colours__swatch {
        outline: 2px solid Highlight;
    }
}
