/* =================================================================
   ACHIEVEMENTS PANEL
   The player's record: what they have done, what is nearly in reach,
   and what has not been paid out yet.
   See frontend/game/js/achievementsPanel.js for the information design.

   Everything here is prefixed .ach- and lives inside .hud-panel's
   .hp-body, so it inherits the shell's scrolling, its 44px header
   controls and its region-D geometry (docs/HUD-LAYOUT.md §1) and only
   has to describe its own content.

   ## The three states, and why none of them is `opacity`

   A row is locked, ready to claim, or done. The obvious way to say
   "locked" is to fade the row, and it is the wrong one twice over: it
   drags the progress line — the single thing a locked row exists to
   show — under 4.5:1, and it takes the rarity colour down with it, so
   the collection loses its shape exactly where it is longest.

   ## Size

   That argument was right and the file still failed the 2026-09-09 type
   audit eleven times over, because the states were separated correctly and
   then every label on them was set at 8.8px: COMMON, UNLOCKED, LOCKED, the
   padlock, the rarity run. Contrast maths cannot see that (they measured
   6.5-17:1). Nothing here renders below --text-xs / 12px now, and the room
   came out of letter-spacing — see docs/TYPE-LEGIBILITY.md rule 5, which
   this panel's 1.4px-tracked 8.8px caps were the worked example of.

   So the states are separated by SURFACE, not by alpha. Locked rows go
   flat and unlit with a padlocked medallion; ready rows are lifted with
   a gold field and a filled button; done rows keep a coloured rim and a
   tick but give up the field. Text stays at full strength in all three.

   ## Rarity

   One custom property, --ach-rarity, set by the .ach-r-* class on the
   row and read by the medallion rim, the pips and the label. Colour is
   never alone: the pip block always draws four slots and fills one per
   tier, so the tier survives colour blindness, a greyscale screenshot,
   and the flattened locked surface.
   ================================================================= */

/* --- Rarity tiers ---------------------------------------------------- */

/* Slate reads as "no tier" against three saturated ones without needing a
   fifth hue, and it is the same grey the rest of the HUD uses for secondary
   text — so common achievements sit quietly rather than looking broken. */
.ach-r-common   { --ach-rarity: var(--color-text-secondary); }
.ach-r-uncommon { --ach-rarity: var(--color-accent-green-light); }
.ach-r-rare     { --ach-rarity: var(--color-accent-cyan-light); }
/* Gold is this game's prize colour everywhere else in the HUD; the top tier
   is the one place it should mean exactly that. */
.ach-r-epic     { --ach-rarity: var(--color-accent-gold); }

/* --- Summary --------------------------------------------------------- */

.ach-summary {
    padding: 12px;
    margin-bottom: 10px;
    background: rgba(26, 39, 68, 0.5);
    border: 1px solid var(--color-primary-700);
    border-left-width: 3px;
    border-left-color: var(--color-accent-gold);
    border-radius: var(--radius-sm);
}

.ach-stats {
    display: flex;
    align-items: flex-start;
    gap: 8px 20px;
    flex-wrap: wrap;
}

.ach-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ach-stat-value {
    font-family: var(--font-display);
    font-size: 1.6rem;
    line-height: 1.1;
    /* Both figures move when a claim lands; tabular digits stop the pair
       shuffling sideways as they do. */
    font-variant-numeric: tabular-nums;
    color: var(--color-accent-gold);
}

/* The denominator is context, not the achievement — it gets the smaller,
   quieter treatment so "7" is what the eye lands on. */
.ach-stat-of {
    font-size: 0.95rem;
    color: var(--color-text-secondary);
}

.ach-stat-label {
    font-family: var(--font-display);
    font-size: var(--text-xs);
    letter-spacing: 1px;
    color: var(--color-text-secondary);
}

/* --- Bars ------------------------------------------------------------ */

.ach-track {
    display: block;
    position: relative;
    height: 5px;
    background: rgba(10, 15, 26, 0.9);
    border: 1px solid var(--color-primary-700);
    border-radius: 4px;
    overflow: hidden;
}

.ach-track-summary {
    height: 8px;
    margin-top: 10px;
}

.ach-fill {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--color-accent-gold-dark), var(--color-accent-gold-light));
    transition: width var(--transition-slow);
}

/* A locked row's bar is drawn in its own rarity colour rather than in gold.
   It is the only place on the row where the tier is expressed as a quantity,
   and it makes a long list of half-full bars readable as a spread of tiers
   instead of one repeated stripe. */
.ach-row .ach-fill {
    background: var(--ach-rarity);
}

/* --- Rewards waiting ------------------------------------------------- */

/* The loudest block on the panel, and the only one allowed to be. Claiming
   is where the player gets paid; a reward they scrolled past is a reward the
   game kept. */
.ach-ready {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: rgba(212, 175, 55, 0.1);
    border: 1px solid var(--color-accent-gold);
    border-radius: var(--radius-sm);
}

.ach-ready-count {
    font-family: var(--font-display);
    font-size: 0.85rem;
    letter-spacing: 1px;
    color: var(--color-accent-gold-light);
}

.ach-ready-detail {
    font-family: var(--font-mono, monospace);
    font-size: 0.8rem;
    color: var(--color-text-primary);
}

/* The reason there is no "Claim all" button. Quiet, because it is a rule of
   the economy rather than a warning — but present, because a ceiling a player
   cannot see is indistinguishable from a reward that did not pay. */
.ach-ready-note {
    margin-top: 2px;
    font-size: 0.78rem;
    line-height: 1.4;
    color: var(--color-text-secondary);
}

/* --- Categories ------------------------------------------------------ */

.ach-cat {
    margin-bottom: 6px;
}

.ach-cat-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin: 14px 2px 6px;
}

.ach-cat-title {
    font-family: var(--font-display);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    letter-spacing: 1.1px;
    color: var(--color-text-secondary);
    min-width: 0;
    overflow-wrap: anywhere;
}

.ach-cat-count {
    flex-shrink: 0;
    font-family: var(--font-mono, monospace);
    font-size: var(--text-xs);
    font-variant-numeric: tabular-nums;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* --- Rows ------------------------------------------------------------ */

.ach-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 6px;
    background: rgba(17, 24, 39, 0.6);
    border: 1px solid var(--color-primary-700);
    border-left: 3px solid var(--ach-rarity);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

/* Focusable only so a claim has somewhere to hand keyboard focus back to
   after it replaces the row (see restoreFocus in the JS) — never a tab stop. */
.ach-row:focus { outline: none; }
.ach-row:focus-visible {
    outline: 2px solid var(--color-accent-gold);
    outline-offset: 2px;
}

/* Locked: flat and unlit, with the rarity rim dimmed to a hairline. The
   dimming is on the SURFACE only — every piece of text on the row keeps its
   own colour, and the progress line keeps its full weight. */
.ach-locked {
    background: rgba(10, 15, 26, 0.55);
    border-color: var(--color-primary-700);
    border-left-color: var(--ach-rarity);
}

/* Claimable: lifted onto a gold field with a live border. Paired with the
   filled button in the action column, so the state is legible from the row
   shape alone before any text is read. */
.ach-row.ach-claimable {
    background: rgba(212, 175, 55, 0.09);
    border-color: var(--color-accent-gold);
    box-shadow: 0 0 0 1px rgba(212, 175, 55, 0.25);
    animation: achBreathe 2.6s ease-in-out infinite;
}

/* Done: the rim and the tick stay, the field goes. A finished row should be
   visibly finished without becoming unreadable — it is the part of this
   screen the player opened it to look at. */
.ach-done {
    background: rgba(26, 39, 68, 0.4);
}

/* --- Medallion ------------------------------------------------------- */

.ach-medal {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: rgba(10, 15, 26, 0.85);
    border: 2px solid var(--ach-rarity);
    border-radius: 50%;
}

.ach-glyph {
    font-size: 1.15rem;
    line-height: 1;
    color: var(--color-text-primary);
}

/* Locked medallions lose their fill, not their rim: the tier stays readable
   while the glyph reads as "not yours yet". A dashed rim says the same thing
   a second way, for anyone the colour is lost on. */
.ach-locked .ach-medal {
    background: rgba(10, 15, 26, 0.9);
    border-style: dashed;
}

.ach-locked .ach-glyph {
    color: var(--color-text-secondary);
}

/* The padlock and the tick were 8.8px and 9.9px glyphs in a 17px disc — the
   two smallest things on the panel and the two that state a row's outcome.
   Both are at the 12px floor now and the disc grew to 21px to hold them. */
.ach-lock,
.ach-tick {
    position: absolute;
    right: -4px;
    bottom: -4px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 21px;
    height: 21px;
    border-radius: 50%;
    font-size: var(--text-xs);
    line-height: 1;
    background: var(--color-primary-800);
    border: 1px solid var(--color-primary-600);
}

.ach-tick {
    background: var(--color-accent-green);
    border-color: var(--color-accent-green-light);
    color: var(--color-text-primary);
}

/* --- Row content ----------------------------------------------------- */

.ach-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    /* Without this a long achievement name refuses to shrink and pushes the
       Claim button off the right edge of a 390px sheet. */
    min-width: 0;
}

.ach-head {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 2px 8px;
    min-width: 0;
}

.ach-name {
    flex: 1 1 auto;
    min-width: 0;
    font-family: var(--font-heading);
    font-weight: var(--font-semibold);
    font-size: 0.92rem;
    letter-spacing: 0.3px;
    color: var(--color-text-primary);
    /* Names are player-facing prose of unknown length; wrapping is always
       better than a truncated title on the row it belongs to. */
    overflow-wrap: anywhere;
}

.ach-desc {
    /* base.css gives every <p> a 16px bottom margin; inside a 3px-gap flex
       column that is a hole, not spacing. */
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.4;
    /* Secondary, not muted: --color-text-muted lands under 4.5:1 on this
       panel's background, and a description a player cannot read is the same
       as no description. */
    color: var(--color-text-secondary);
    overflow-wrap: anywhere;
}

/* --- Rarity chip ----------------------------------------------------- */

.ach-rarity {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* Four slots, always. The count of filled ones is the tier, which is what
   makes rarity legible without colour — and it stays legible on a locked row,
   because nothing here is faded. */
.ach-pips {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.ach-pips i {
    display: block;
    width: 5px;
    height: 5px;
    border: 1px solid var(--ach-rarity);
    /* Rotated squares, so the tier reads as a shape run and not as a row of
       identical dots at a glance. */
    transform: rotate(45deg);
    opacity: 0.4;
}

.ach-pips i.is-on {
    background: var(--ach-rarity);
    opacity: 1;
}

.ach-rarity-label {
    font-family: var(--font-display);
    /* Pinned to .ach-state, the other small caps label on the row — the two
       sit on the same eye-line across a list and any drift between them reads
       as a mistake. */
    font-size: var(--text-xs);
    letter-spacing: 0.8px;
    color: var(--ach-rarity);
    white-space: nowrap;
}

/* --- Progress -------------------------------------------------------- */

.ach-progress {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 3px;
    min-width: 0;
}

.ach-progress-text {
    font-family: var(--font-mono, monospace);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    /* The most important line on a locked row, so it is the one place a
       progress readout is NOT muted. */
    color: var(--color-text-secondary);
    overflow-wrap: anywhere;
}

.ach-progress-text strong {
    font-weight: var(--font-bold);
    color: var(--color-text-primary);
}

.ach-earned {
    color: var(--color-accent-green-light);
}

.ach-reward {
    margin-top: 2px;
    font-size: 0.78rem;
    color: var(--color-accent-gold);
    overflow-wrap: anywhere;
}

/* On a finished row the reward is history, not an offer — it stays on the
   row (the collection should record what each one was worth) but stops
   competing with the rows that still pay. */
.ach-done .ach-reward {
    color: var(--color-text-secondary);
}

/* --- Action column --------------------------------------------------- */

.ach-action {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    /* Matches the button, so LOCKED / CLAIMED / Claim all line up down the
       right edge and the list reads as a column of states. */
    min-width: 88px;
    min-height: var(--touch-target);
}

.ach-state {
    font-family: var(--font-display);
    font-size: var(--text-xs);
    letter-spacing: 0.8px;
    white-space: nowrap;
}

.ach-state-locked { color: var(--color-text-secondary); }
.ach-state-done   { color: var(--color-accent-green-light); }

.ach-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* WCAG 2.5.5: claiming is the one thing this panel exists to let a player
       do, and it is pressed on a phone. */
    min-height: var(--touch-target);
    min-width: 88px;
    padding: 0 14px;
    background: rgba(26, 39, 68, 0.9);
    border: 1px solid var(--color-primary-600);
    border-radius: 3px;
    color: var(--color-text-secondary);
    font-family: var(--font-heading);
    font-size: 0.82rem;
    font-weight: var(--font-semibold);
    cursor: pointer;
    transition: color var(--transition-fast), border-color var(--transition-fast),
                background var(--transition-fast);
}

.ach-btn-primary {
    background: var(--color-accent-gold);
    border-color: var(--color-accent-gold);
    color: var(--color-primary-900);
}

.ach-btn-primary:hover:not(:disabled) {
    background: var(--color-accent-gold-light);
    color: var(--color-primary-900);
}

.ach-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* base.css clears button outlines globally; keyboard users still need one. */
.ach-btn:focus-visible {
    outline: 2px solid var(--color-accent-gold);
    outline-offset: 2px;
}

/* --- Motion ---------------------------------------------------------- */

/* A slow rim breath on rows that owe the player something. Big enough to
   catch peripheral vision on a scrolling list, small enough that a panel left
   open does not become a strobe. Nothing moves, resizes or reflows — only the
   ring — so it cannot shift a button under a thumb mid-press. */
@keyframes achBreathe {
    0%, 100% { box-shadow: 0 0 0 1px rgba(212, 175, 55, 0.2); }
    50%      { box-shadow: 0 0 12px 1px rgba(212, 175, 55, 0.35); }
}

/* The payout. Fires once on the row that was just claimed, after it has
   already rendered its final state — so it is decoration over a correct
   result, never the thing that communicates the result. */
@keyframes achFlourish {
    0%   { background: rgba(212, 175, 55, 0.35); }
    100% { background: rgba(26, 39, 68, 0.4); }
}

.ach-flourish {
    animation: achFlourish 1.2s ease-out;
}

/* --- Narrow widths --------------------------------------------------- */

/* Below ~420px an 88px action column beside a wrapped name, a description and
   a progress line leaves the text three or four words wide and the row reads
   as broken. Dropped to its own line — indented to the text column, not the
   medallion — it reads as the row's action, and a full-width Claim button is
   the easiest thing on the panel to hit one-handed. */
@media (max-width: 420px) {
    .ach-row {
        flex-wrap: wrap;
    }

    .ach-action {
        flex: 1 1 100%;
        justify-content: flex-start;
        /* 44px medallion + the row's 10px gap. */
        padding-left: 54px;
        min-width: 0;
    }

    .ach-btn {
        width: 100%;
    }

    .ach-stat-value {
        font-size: 1.4rem;
    }
}

/* --- Reduced motion (HUD-LAYOUT §7) ---------------------------------- */

/* The breathing ring becomes a static one at its brightest point, so a
   claimable row is no less findable without the animation — the motion was
   always an amplifier for a signal that is already carried by the gold field,
   the filled button and the banner at the top of the panel. */
@media (prefers-reduced-motion: reduce) {
    .ach-row.ach-claimable {
        animation: none;
        box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.35);
    }

    .ach-flourish {
        animation: none;
    }

    .ach-fill,
    .ach-row,
    .ach-btn {
        transition: none;
    }
}
