/* =====================================================================
   GLOBAL ACHIEVEMENTS - the hall /achievements/, one player
   /achievements/player.html, and the Achievements section on the public
   profile (.pf-achv). Owner: Achievements Page Coder.
   The hall and player pages load after wraith-suite.css and wraith-hall.css
   (body.ws.ah-page) and reuse their tokens, rings, tiles and meters.
   The profile section uses the profile tokens (--pf-*) only.
   Mobile first, dark only, 16 px gutters, no horizontal page scroll.
   Prefixes: ah- (hall and shared), ap- (player page), pf-achv (profile).
   ===================================================================== */

/* ---------- 1. PAGE AND HERO ---------- */
.ah-page [hidden] { display: none !important; }
.ah-hero { --ws-hero-img: url('/images/wraith/achievements-bg.jpg'); --ws-hero-tint: rgba(255, 194, 74, 0.16); min-height: clamp(260px, 34vh, 380px); }
@supports (background-image: image-set(url('/a.webp') type('image/webp'))) {
  /* the Wraith hall art until the Artist ships /images/achievements/hall-bg.webp (swap both urls here then) */
  .ah-hero { --ws-hero-img: image-set(url('/images/wraith/achievements-bg.webp') type('image/webp'), url('/images/wraith/achievements-bg.jpg') type('image/jpeg')); }
}
.ah-hero .ws-hero-inner { max-width: min(640px, 100%); }
.ah-lede { margin: 0.6rem 0 0; color: var(--ws-mute); font-size: var(--ws-fs-base); max-width: 56ch; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8); }
.ah-hidden-note { margin: 0.8rem 0 0; color: var(--ws-faint); font-size: var(--ws-fs-sm); }
.ah-page .ws-figures { gap: 0.9rem 1.8rem; }
@media (max-width: 479px) { .ah-page .ws-figures { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.ah-page .ws-section { margin-top: clamp(1.6rem, 4vw, 2.6rem); }
.ah-page .ws-section:last-of-type { margin-bottom: 2.5rem; }
.ah-foot { margin: 1.4rem 0 2.5rem; color: var(--ws-faint); font-size: var(--ws-fs-sm); }

/* the medallion art sits on the medal disc (.wh-medal is already absolute inside the ring: never override its position,
   that is what stretched the rings 1.6x on the player page). The ring is a fixed square whatever the card row does;
   the sprite icon under the art shows only when the art is missing. */
.ah-page .wh-ring, .ah-dialog .wh-ring { flex: none; width: var(--size); height: var(--size); aspect-ratio: 1 / 1; align-self: center; }
.ah-page .wh-medal img, .ah-dialog .wh-medal img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; border-radius: 50%; }
.ah-page .wh-medal img ~ .wi, .ah-dialog .wh-medal img ~ .wi { visibility: hidden; }
.ah-page .wb-cell > .wh-tier { position: relative; z-index: 1; max-width: 100%; flex-wrap: wrap; justify-content: center; letter-spacing: 0.04em; font-size: var(--ws-fs-xs); }

/* category marks (a sprite icon per catalogue group) */
.ah-grp-mark { display: inline-flex; align-items: center; justify-content: center; width: 1.35rem; height: 1.35rem; flex: none; color: var(--ws-fire); }
.ah-grp-mark .wi { width: 1.1rem; height: 1.1rem; }

/* ---------- 2. RECENT STRIP ---------- */
.ah-recent { display: flex; gap: 0.6rem; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; padding: 0.2rem 0.1rem 0.6rem; scrollbar-width: thin; scrollbar-color: var(--ws-line) transparent; }
.ah-rc { flex: 0 0 min(250px, 78vw); scroll-snap-align: start; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.6rem; align-items: center; padding: 0.65rem 0.8rem; border-radius: 12px; background: var(--ws-panel-2); border: 1px solid var(--ws-line-2); border-left: 3px solid var(--tc, var(--ws-line)); color: inherit; text-decoration: none; min-width: 0; transition: border-color 0.16s ease, transform 0.16s ease; }
.ah-rc:hover { border-color: var(--ws-line); transform: translateY(-2px); color: inherit; }
.ah-rc-body { display: flex; flex-direction: column; min-width: 0; gap: 0.1rem; font-size: 0.86rem; }
.ah-rc-body b, .ah-rc-body > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ah-rc-body > span { color: var(--ws-mute); }
.ah-rc-body small { font-size: var(--ws-fs-xs); color: var(--ws-faint); }
.ah-first { font-family: var(--ws-mono); font-weight: 700; font-size: var(--ws-fs-xs); letter-spacing: 0.1em; color: var(--ws-gold); }

/* ---------- 3. TOOLS ---------- */
.ah-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 0.8rem; margin: 0 0 1.1rem; }
.ah-tools .ws-search { flex: 1 1 220px; max-width: 360px; }
.ah-tools .ws-select { max-width: 100%; flex: 0 1 auto; }
.ah-rar { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.ah-rar .ws-chip { font-size: var(--ws-fs-xs); padding: 0.3rem 0.7rem; --rc: var(--tc, var(--ws-mute)); }
.ah-count { color: var(--ws-faint); font-size: var(--ws-fs-sm); margin-left: auto; }
@media (max-width: 599px) { .ah-tools .ws-search { max-width: none; flex-basis: 100%; } .ah-count { margin-left: 0; flex-basis: 100%; } }

/* ---------- 4. CATALOGUE GROUPS ---------- */
.ah-catalogue { display: flex; flex-direction: column; gap: 1rem; }
.ah-group .wh-group-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.9rem; }
.ah-group .wh-group-meter { margin-left: auto; }
.ah-group.is-collapsed .ah-group-body { display: none; }
.ah-group.is-collapsed .wh-group-head { margin-bottom: 0; }
.ah-gtoggle .wi { transition: transform 0.2s ease; }
.ah-gtoggle[aria-expanded="true"] .wi { transform: rotate(90deg); }
.ah-wlink { white-space: nowrap; }
.ah-wnote { margin: 0.6rem 0 0; color: var(--ws-faint); font-size: var(--ws-fs-sm); }
.ah-sub { margin: 1.1rem 0 0.7rem; font-family: var(--ws-display); font-size: 0.95rem; font-weight: 700; color: var(--ws-ink); letter-spacing: 0.02em; }
.ah-sub small { font-family: var(--ws-body); font-weight: 400; font-size: var(--ws-fs-xs); color: var(--ws-faint); margin-left: 0.4rem; letter-spacing: 0; }
.ah-group-body > .ah-sub:first-child { margin-top: 0.9rem; }
.ah-page .wh-tiles { grid-template-columns: repeat(auto-fill, minmax(min(100%, 100px), 1fr)); gap: 0.6rem; }
@media (min-width: 700px) { .ah-page .wh-tiles { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 0.7rem; } }
.ah-page .wh-tile[role="button"] { cursor: pointer; }
.ah-page .wh-tile:focus-visible, .ah-page .wb-cell:focus-visible { outline: 2px solid var(--ws-fire); outline-offset: 2px; }
.ah-page .wh-tile-meta { overflow-wrap: anywhere; }
.ah-bcell .wb-val { font-size: var(--ws-fs-xs); -webkit-line-clamp: 3; }
.ah-none { color: var(--ws-mute); font-size: 0.9rem; text-align: center; padding: 1.2rem 0; margin: 0; }
.ah-group-hidden { margin: 0.7rem 0 0; font-size: var(--ws-fs-sm); color: var(--ws-faint); }
.ah-rar-txt { color: var(--tc); }

/* ---------- 5. DETAIL DIALOG ---------- */
.ah-dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow-y: auto; margin: auto; padding: 1.2rem; color: var(--ws-ink); background: var(--ws-panel-solid); border: 1px solid var(--ws-line); border-radius: 16px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6); }
.ah-dialog::backdrop { background: rgba(6, 3, 2, 0.72); backdrop-filter: blur(3px); }
.ah-dlg-x { position: absolute; top: 0.5rem; right: 0.5rem; }
.ah-dlg-head { display: flex; gap: 1rem; align-items: flex-start; padding-right: 2rem; }
.ah-dlg-head > div { min-width: 0; }
.ah-dlg-head > .wh-tile { --tsize: 72px; padding: 0; border: 0; background: none; flex: none; }
.ah-dlg-kicker { display: flex; align-items: center; gap: 0.4rem; margin: 0; font-size: var(--ws-fs-xs); text-transform: uppercase; letter-spacing: 0.14em; color: var(--ws-mute); }
.ah-dlg-name { margin: 0.25rem 0 0; font-family: var(--ws-display); font-size: 1.3rem; line-height: 1.2; }
.ah-dlg-desc { margin: 0.4rem 0 0; color: var(--ws-mute); font-size: 0.92rem; }
.ah-dlg-mine { margin: 0.5rem 0 0; font-size: 0.9rem; color: var(--ws-flame); }
.ah-facts { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.5rem; }
.ah-facts li { display: flex; flex-direction: column; gap: 0.1rem; padding: 0.5rem 0.65rem; border-radius: 10px; background: var(--ws-panel-2); border: 1px solid var(--ws-line-2); min-width: 0; }
.ah-facts span { font-size: var(--ws-fs-xs); color: var(--ws-faint); text-transform: uppercase; letter-spacing: 0.1em; }
.ah-facts b { font-size: 0.9rem; overflow-wrap: anywhere; }
.ah-facts a { color: var(--ws-gold); }
.ah-ladder { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: 0.2rem; }
.ah-ladder li { display: grid; grid-template-columns: 8rem 5.5rem minmax(0, 1fr); gap: 0.5rem; align-items: baseline; padding: 0.25rem 0.4rem; border-radius: 6px; font-size: var(--ws-fs-sm); color: var(--ws-faint); }
.ah-ladder li.is-reached { color: var(--ws-mute); }
.ah-ladder li.is-current { background: rgba(255, 106, 26, 0.1); color: var(--ws-ink); }
.ah-lad-tier { font-weight: 600; color: var(--tc, inherit); }
.ah-lad-val { font-family: var(--ws-mono); }
.ah-lad-n { text-align: right; }
@media (max-width: 479px) { .ah-ladder li { grid-template-columns: 6.8rem 4.6rem minmax(0, 1fr); } .ah-dlg-head { flex-direction: column; } }
/* a badge with a tier phrase: "I Ash · level up 10 times" is one cell across the first two columns */
.ah-ladder.has-phrase li { grid-template-columns: minmax(0, 1fr) auto; }
.ah-lad-line { min-width: 0; overflow-wrap: anywhere; }
/* each tier's own rarity (catalogue tiers[].rarity, else the item rarity) */
.ah-lad-n .ah-rar-txt { font-weight: 600; margin-right: 0.3rem; }
.ah-tier-rar { font-size: var(--ws-fs-xs); font-weight: 600; letter-spacing: 0.04em; color: var(--tc, var(--ws-mute)); margin-top: -0.2rem; }
.ah-dlg-foot { margin: 1rem 0 0; font-size: var(--ws-fs-sm); }
.ah-dlg-foot a { color: var(--ws-gold); }

/* ---------- 6. PLAYER PAGE ---------- */
.ap-hero { min-height: clamp(240px, 30vh, 340px); }
.ap-who { display: flex; align-items: center; gap: 0.9rem; min-width: 0; }
.ap-who > div { min-width: 0; }
.ap-who .ws-avatar { --av: 64px; width: 64px; height: 64px; flex: none; }
.ap-name { overflow-wrap: anywhere; }
.ap-lede { margin: 0.6rem 0 0; color: var(--ws-mute); max-width: 52ch; }
.ap-links { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin: 0.4rem 0 0; font-size: var(--ws-fs-sm); }
.ap-links a { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--ws-gold); text-decoration: none; }
.ap-links a:hover { color: var(--ws-flame); }
.ap-picker { position: relative; max-width: 420px; margin-top: 1.2rem; }
.ap-results { position: absolute; z-index: 40; left: 0; right: 0; top: 100%; margin: 0.25rem 0 0; padding: 0.3rem; list-style: none; max-height: 320px; overflow-y: auto; background: var(--ws-panel-solid); border: 1px solid var(--ws-line); border-radius: 12px; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55); }
.ap-results a { display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.55rem; border-radius: 8px; color: var(--ws-ink); text-decoration: none; font-size: 0.88rem; }
.ap-results a:hover, .ap-results a:focus-visible { background: rgba(255, 106, 26, 0.12); }
.ap-results small { margin-left: auto; font-family: var(--ws-mono); color: var(--ws-faint); }
.ap-noresult { padding: 0.5rem; color: var(--ws-mute); font-size: 0.86rem; }
.ap-sub { margin: 0 0 1rem; }
.ap-next { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.45rem; }
.ap-next-row { appearance: none; width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "mark name val" "meter meter meter"; gap: 0.35rem 0.6rem; align-items: center; padding: 0.55rem 0.7rem; border-radius: 10px; background: var(--ws-panel-2); border: 1px solid var(--ws-line-2); }
.ap-next-row:hover { border-color: var(--ws-line); }
.ap-next-row:focus-visible { outline: 2px solid var(--ws-fire); outline-offset: 2px; }
.ap-next-row .ah-grp-mark { grid-area: mark; }
.ap-next-name { grid-area: name; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
.ap-next-name small { color: var(--ws-faint); }
.ap-next-row .ws-meter { grid-area: meter; }
.ap-next-val { grid-area: val; font-family: var(--ws-mono); font-size: var(--ws-fs-xs); color: var(--ws-mute); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ap-next-row { grid-template-columns: 1.75rem minmax(0, 1fr) auto; }
@media (min-width: 700px) { .ap-next-row { grid-template-columns: 1.75rem minmax(0, 1fr) 38% 13ch; grid-template-areas: "mark name meter val"; } .ap-next-val { overflow: hidden; text-overflow: ellipsis; } }
.ap-bgrid .wb-cell { position: relative; }
.ap-bgrid .ah-first { position: absolute; top: 0.4rem; right: 0.5rem; }
.ap-collapsible.is-collapsed .ap-locked-tiles { display: none; }
.ap-toggle { margin-bottom: 0.8rem; }

/* ---------- 7. PROFILE SECTION (.pf-achv on /profile/<id>/) ---------- */
.pf-achv {
  --pa-t0: #3a2e27; --pa-t1: #8a7f78; --pa-t2: #7d8791; --pa-t3: #d68a4b; --pa-t4: #c9d1d9; --pa-t5: #ffc24a;
  --pa-t6: #e4ecf2; --pa-t7: #2aa85a; --pa-t8: #9fe6ff; --pa-t9: #ff3b1e; --pa-t10: #ff6a1a;
}
.pf-achv [data-tier="0"] { --pa-c: var(--pa-t0); } .pf-achv [data-tier="1"], .pf-achv [data-rarity="C"] { --pa-c: var(--pa-t1); }
.pf-achv [data-tier="2"], .pf-achv [data-rarity="U"] { --pa-c: var(--pa-t2); } .pf-achv [data-tier="3"], .pf-achv [data-rarity="R"] { --pa-c: var(--pa-t3); }
.pf-achv [data-tier="4"] { --pa-c: var(--pa-t4); } .pf-achv [data-tier="5"], .pf-achv [data-rarity="E"] { --pa-c: var(--pa-t5); }
.pf-achv [data-tier="6"] { --pa-c: var(--pa-t6); } .pf-achv [data-tier="7"] { --pa-c: var(--pa-t7); } .pf-achv [data-tier="8"] { --pa-c: var(--pa-t8); }
.pf-achv [data-tier="9"], .pf-achv [data-rarity="L"] { --pa-c: var(--pa-t9); } .pf-achv [data-tier="10"], .pf-achv [data-rarity="M"] { --pa-c: var(--pa-t10); }
.pf-achv-figs { display: flex; flex-wrap: wrap; gap: 0.3rem 1.4rem; margin: 0 0 1rem; font-size: var(--pf-fs-sm); color: var(--pf-mute); }
.pf-achv-figs b { font-family: var(--pf-mono); color: var(--pf-ink); margin-right: 0.3rem; }
.pf-medals { list-style: none; margin: 0; padding: 0 0 0.3rem; display: flex; gap: 0.7rem; overflow-x: auto; scrollbar-width: thin; }
.pf-medal { flex: 0 0 92px; display: flex; flex-direction: column; align-items: center; gap: 0.3rem; text-align: center; min-width: 0; }
.pf-medal-disc { position: relative; flex: none; width: 64px; height: 64px; aspect-ratio: 1 / 1; border-radius: 50%; border: 3px solid var(--pa-c); background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--pa-c) 26%, #1a1512), #0d0f16 75%); box-shadow: 0 0 14px color-mix(in srgb, var(--pa-c) 35%, transparent); display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--pa-c); }
.pf-medal-disc img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.pf-medal-disc .wi { width: 26px; height: 26px; }
.pf-medal-disc img ~ .wi { visibility: hidden; }
.pf-medal[data-tier="10"] .pf-medal-disc { border-color: transparent; background-image: radial-gradient(circle at 50% 35%, #3a1a0c, #0d0f16 75%), conic-gradient(from 0deg, #ff3b1e, #ff6a1a, #ffc24a, #ff6a1a, #ff3b1e); background-origin: border-box; background-clip: padding-box, border-box; }
.pf-medal b { font-size: var(--pf-fs-xs); line-height: 1.2; color: var(--pf-ink); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pf-medal small { white-space: nowrap; font-size: var(--pf-fs-xs); color: var(--pa-c); font-weight: 600; }
.pf-achv-cols { display: grid; gap: 1rem; margin-top: 1.1rem; grid-template-columns: minmax(0, 1fr); }
@container pf (min-width: 720px) { .pf-achv-cols { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); } }
.pf-achv-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.pf-achv-list li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.1rem 0.6rem; align-items: center; padding: 0.5rem 0.65rem; border-radius: 10px; background: var(--pf-panel-2); border: 1px solid var(--pf-line); border-left: 3px solid var(--pa-c, var(--pf-line)); }
.pf-achv-list .pf-achv-ico { grid-row: span 2; color: var(--pa-c); display: inline-flex; }
.pf-achv-list .pf-achv-ico .wi { width: 20px; height: 20px; }
.pf-achv-list b { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-achv-list small { font-size: var(--pf-fs-xs); color: var(--pf-faint); }
.pf-achv-list small em { font-style: normal; color: var(--pa-c); font-weight: 600; }
.pf-achv-first { font-family: var(--pf-mono); font-size: var(--pf-fs-xs); color: var(--pf-gold); letter-spacing: 0.08em; }
.pf-achv-foot { margin: 1rem 0 0; }

/* ---------- 8. MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
  .ah-rc, .ah-gtoggle .wi { transition: none; }
  .ah-rc:hover { transform: none; }
}

/* hidden "?" tile art (images/achievements/hidden.webp); the text "?" shows only when the image is missing */
.ah-page .wh-tile.is-hidden .ah-q { position: absolute; inset: 8%; width: 84%; height: 84%; object-fit: contain; z-index: 1; opacity: 0.92; }
.ah-page .wh-tile.is-hidden .ah-q ~ .wh-q { visibility: hidden; }

/* ---------- 9. HOVER TOOLTIP (.ah-tip on .ws-tip): what a badge or achievement is for ---------- */
.ah-tip { max-width: min(320px, calc(100vw - 16px)); white-space: normal; line-height: 1.4; }
.ah-tip .ws-tip-head { text-transform: uppercase; letter-spacing: 0.1em; }
.ah-tip-name { font-family: var(--ws-display); font-weight: 700; font-size: 1rem; color: var(--ws-ink); margin-bottom: 0.25rem; }
.ah-tip-row { margin: 0.2rem 0 0; font-size: var(--ws-fs-sm); color: var(--ws-mute); }
.ah-tip-row.is-desc { color: var(--ws-ink); }
.ah-tip-row.is-foot { color: var(--ws-faint); font-size: var(--ws-fs-xs); margin-top: 0.4rem; }
