/* Achievements: the page, the card popover and the felt medallions (GPT-embroidered icons on a tier-dyed disk). */

/* ---------- the medallion ---------- */
.ach-medal {
  --s: 64px; --m: var(--hairline); position: relative; display: inline-grid; place-items: center; flex: none;
  width: var(--s); height: var(--s); border-radius: 50%; padding: calc(var(--s) * .13);
  background: var(--m) var(--fibre) 0 0 / 120px; background-blend-mode: soft-light;
  box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--m) 60%, var(--cream)), 0 2px 0 color-mix(in oklab, var(--m) 55%, var(--ink));
}
/* the hand stitch along the rim, a shade lighter than the felt it holds */
.ach-medal::after {
  content: ''; position: absolute; inset: calc(var(--s) * .05); border-radius: 50%; pointer-events: none;
  border: max(1.5px, calc(var(--s) * .025)) dashed color-mix(in oklab, var(--m) 45%, var(--cream));
}
.ach-medal img { width: 100%; height: 100%; border-radius: 50%; display: block; }
.ach-medal.bronze { --m: var(--bronze); }
.ach-medal.silver { --m: var(--silver); }
.ach-medal.gold { --m: var(--gold); }
.ach-medal.rare { --m: var(--lake); }
.ach-medal.going:not(.bronze, .silver, .gold) { --m: var(--sage); }
.ach-medal.going img { filter: saturate(.55); }
/* not begun: only the chalk outline of the patch, as in the badge sheet */
.ach-medal.shut { background: none; box-shadow: none; outline: 2px dashed var(--hairline); outline-offset: -2px; }
.ach-medal.shut::after { display: none; }
.ach-medal.shut img { filter: grayscale(1) opacity(.4); }
.ach-medal.secret { --m: var(--forest); }
/* The dark forest melts into a dark panel; lift it so the rim still reads. */
[data-theme="dark"] .ach-medal.secret { --m: color-mix(in oklab, var(--forest) 65%, var(--on-dark)); }
.ach-medal.secret.shut { background: var(--m) var(--fibre) 0 0 / 120px; background-blend-mode: soft-light; outline: 0; }
.ach-medal.secret.shut img { filter: none; opacity: .9; }

/* ---------- the page ---------- */
#achievements {
  width: min(1040px, calc(100vw - 32px)); height: min(760px, calc(100vh - 32px)); margin: auto; padding: 20px 22px 14px; font-size: 15px;
}
#achievements[open] { display: flex; flex-direction: column; overflow: hidden; animation: enter .28s cubic-bezier(.22,1,.36,1); }
#achievements header { position: relative; isolation: isolate; display: flex; align-items: center; justify-content: space-between; flex: none; gap: 14px; margin-bottom: 14px; min-height: 72px; }
#achievements h2 { margin: 0; font-size: 26px; font-weight: 900; }
#achievements header h2 { position: relative; z-index: 1; }
#achievements .decor.medal { --w: min(300px, 40%); left: 50%; translate: -50% 0; bottom: -6px; opacity: .8; }
#achievements .sum { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 14px; margin: 2px 0 12px; font-weight: 800; }
#achievements .sum .meter { position: relative; height: 16px; }
#achievements .sum .meter b { position: absolute; inset: 0; display: grid; place-items: center; font: 900 13px/1 var(--font); color: var(--ink); }
#achievements .guest { margin: 0 0 10px; padding: 10px 14px; font-weight: 700; }
#achievements .cols { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 196px 1fr; gap: 16px; }
#achCats { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; padding: 2px; }
#achCats .pebble { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; font: 800 14px/1.1 var(--font); text-align: left; }
#achCats .pebble:first-child { grid-template-columns: 1fr auto; padding-left: 14px; }
#achCats img { width: 28px; height: 28px; border-radius: 50%; }
#achCats small { font-weight: 800; opacity: .75; }
#achievements .main { min-height: 0; display: flex; flex-direction: column; gap: 10px; }
#achievements .filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px; }
#achievements .filters .pebble { padding: 6px 14px; font: 800 14px/1 var(--font); }
#achievements .scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin: 0 -10px; padding: 2px 10px 10px; scrollbar-width: thin; scrollbar-color: var(--hairline) transparent; }
#achList { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
#achList .empty { padding: 24px; color: var(--ink-soft); text-align: center; grid-column: 1 / -1; }

.ach-card {
  width: 100%; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 10px 12px;
  border: 0; text-align: left; color: var(--ink); font: inherit; cursor: pointer; transition: filter 150ms, transform 150ms;
}
.ach-card:hover { filter: brightness(1.03); }
.ach-card:active { transform: translateY(1px); }
.ach-card:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.ach-card .txt { display: grid; gap: 3px; min-width: 0; }
.ach-card b { font-size: 15px; font-weight: 900; line-height: 1.15; }
.ach-card p { margin: 0; font: 600 13px/1.25 var(--font-read, var(--font)); color: var(--ink-soft); }
.ach-card small { font-size: 13px; font-weight: 800; color: var(--ink-soft); }
.ach-card .prog { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; margin-top: 2px; }
.ach-card .prog .meter { height: 10px; }
.ach-card .side { display: grid; justify-items: end; gap: 8px; }
.ach-card.shut { --c: color-mix(in oklab, var(--row) 80%, var(--hairline)); }
.ach-card.shut b { color: var(--ink-soft); }
.ach-card.secret { --c: color-mix(in oklab, var(--row) 70%, var(--hairline)); }

/* flat felt tags, not pressable pebbles: they only name the tier */
.chip { --c: var(--hairline); display: inline-block; padding: 4px 10px; border-radius: var(--r-sm); background: var(--c) var(--fibre) 0 0 / 120px; background-blend-mode: soft-light; font: 800 13px/1 var(--font); white-space: nowrap; }
.chip.bronze { --c: var(--bronze); color: var(--on-dark); }
.chip.silver { --c: var(--silver); color: var(--ink); }
.chip.gold { --c: var(--gold); color: var(--ink); }
.chip.rare { --c: var(--lake); color: var(--on-dark); }
.ach-card .dots, .ach-dots { display: flex; gap: 4px; }
.ach-card .dots i { width: 9px; height: 9px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--hairline); }
.ach-card .dots i.bronze { background: var(--bronze); }
.ach-card .dots i.silver { background: var(--silver); }
.ach-card .dots i.gold { background: var(--gold); }

/* ---------- one achievement, close up ---------- */
#achCard { width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 32px); margin: auto; padding: 18px 22px 22px; overflow: auto; text-align: center; font-size: 15px; }
#achCard[open] { animation: enter .24s cubic-bezier(.22,1,.36,1); }
#achCard > form { display: flex; justify-content: flex-end; margin: 0 0 14px; }
#achCard .big { position: relative; isolation: isolate; display: grid; justify-items: center; margin: 6px auto 34px; width: max-content; }
/* GPT's grey felt tails, dyed by the tier: multiply keeps their stitches and fibre */
#achCard .big .ribbon {
  --m: var(--gold); position: absolute; z-index: -1; bottom: -30px; left: 50%; translate: -50% 0; width: 150px; aspect-ratio: 189 / 120;
  background: url(img/ach/ribbon.webp) center / contain no-repeat, color-mix(in oklab, var(--m) 80%, var(--cream));
  background-blend-mode: multiply; mask: url(img/ach/ribbon.webp) center / contain no-repeat;
}
#achCard .big .ribbon.bronze { --m: var(--bronze); }
#achCard .big .ribbon.silver { --m: var(--silver); }
#achCard .big .ribbon.rare { --m: var(--lake); }
#achCard .big .chip { position: absolute; bottom: -26px; left: 50%; translate: -50% 0; z-index: 1; }
#achCard h3 { margin: 6px 0 4px; font-size: 22px; font-weight: 900; }
#achCard > div > p { margin: 0 0 8px; font: 600 15px/1.3 var(--font-read, var(--font)); color: var(--ink-soft); }
#achCard .when { font-size: 13px; font-weight: 700; }
#achCard .tiers { list-style: none; margin: 8px 0 12px; padding: 0; display: grid; gap: 6px; text-align: left; }
#achCard .tiers li { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
#achCard .tiers li.got { color: var(--ink); }
#achCard .tiers .dot { width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--hairline); }
#achCard .tiers li.got .dot.bronze { background: var(--bronze); }
#achCard .tiers li.got .dot.silver { background: var(--silver); }
#achCard .tiers li.got .dot.gold { background: var(--gold); }
#achCard .chips { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
#achCard .chips .chip { padding: 6px 12px; }
#achCard .chips .pts { --c: var(--sage); color: var(--ink); }
#achCard .chips .ttl { --c: var(--moss); color: var(--on-dark); }
#achCard .acts { display: grid; gap: 8px; }
#achCard .acts .err { margin: 0; color: var(--berry); font-weight: 800; font-size: 13px; }

/* the count of new ones on the menu button */
#menu button[value="ach"][data-fresh]:not([data-fresh=""])::after {
  content: attr(data-fresh); margin-left: auto; min-width: 22px; padding: 3px 6px; border-radius: var(--r-sm);
  background: var(--berry); color: var(--on-dark); font: 900 12px/1 var(--font); text-align: center;
}

@media (max-width: 720px) {
  #achievements { height: calc(100dvh - 32px); padding: 14px 14px 10px; }
  #achievements .filters { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  #achievements .filters .pebble { flex: none; }
  #achCats { mask: linear-gradient(90deg, #000 85%, #0000); }
  #achievements .decor.medal { display: none; }
  #achievements .sum { grid-template-columns: 1fr; gap: 6px; font-size: 14px; }
  #achievements .cols { grid-template-columns: 1fr; grid-template-rows: auto 1fr; gap: 10px; }
  #achCats { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding-bottom: 4px; scrollbar-width: none; }
  #achCats .pebble { flex: none; }
  #achList { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  #achievements[open], #achCard[open] { animation: none; }
  .ach-card { transition: none; }
}

/* Over the animal (achpop.js): the medallion sprouts, opens with felt scraps, hangs, then leaves. */
.ach-pop {
  position: absolute; left: 50%; bottom: calc(100% + 14px); translate: -50% 0; z-index: 2;
  display: grid; justify-items: center; width: max-content; pointer-events: none;
  animation: ach-sprout .25s cubic-bezier(.22,1,.36,1) both;
}
.tag.titled .ach-pop { bottom: calc(100% + 30px); }
.tag.cam .ach-pop { bottom: calc(100% + 92px); }
.ach-pop.wait { visibility: hidden; animation: none; }
.ach-pop .ach-medal { z-index: 1; }
.ach-pop .ribbon {
  --m: var(--gold); position: absolute; top: 50px; width: 108px; aspect-ratio: 189 / 120;
  background: url(img/ach/ribbon.webp) center / contain no-repeat, color-mix(in oklab, var(--m) 80%, var(--cream));
  background-blend-mode: multiply; mask: url(img/ach/ribbon.webp) center / contain no-repeat;
  animation: ach-open .35s .25s cubic-bezier(.22,1,.36,1) both;
}
.ach-pop.bronze .ribbon { --m: var(--bronze); }
.ach-pop.silver .ribbon { --m: var(--silver); }
.ach-pop.rare .ribbon { --m: var(--lake); }
.ach-pop .banner {
  z-index: 1; margin-top: 30px; max-width: 220px; padding: 7px 20px 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: url(img/ach/banner.webp) center / 100% 100% no-repeat; color: var(--tag-ink); font: 900 14px/1 var(--font);
  animation: ach-open .35s .25s cubic-bezier(.22,1,.36,1) both;
}
.ach-pop .bit {
  position: absolute; top: 32px; width: 18px; height: 18px;
  background: url(img/ach/confetti.webp) calc(var(--cx) * -18px) calc(var(--cy) * -18px) / 72px 72px;
  animation: ach-bit .9s .25s cubic-bezier(.2,.8,.3,1) both;
}
.ach-pop.melt { animation: ach-melt .6s ease-in forwards; }
.ach-pop.fly { animation: ach-fly .6s cubic-bezier(.5,0,.75,0) forwards; }
@keyframes ach-sprout { from { opacity: 0; scale: .25; translate: -50% 24px; } }
@keyframes ach-open { from { opacity: 0; scale: .2 1; } }
@keyframes ach-bit {
  from { opacity: 0; transform: none; }
  15% { opacity: 1; }
  75% { opacity: 1; }
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); }
}
@keyframes ach-melt { to { opacity: 0; translate: -50% -14px; } }
@keyframes ach-fly { to { opacity: .2; scale: .3; translate: calc(-50% + var(--fx, 0px)) var(--fy, -200px); } }

/* One's own news, top right: a sage felt strip with the medallion; a click opens its card. */
#achToast { position: fixed; z-index: 21; top: 16px; right: 16px; display: grid; gap: 8px; justify-items: end; pointer-events: none; }
#achToast .row {
  --c: var(--toast); pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 6px 16px 6px 6px;
  max-width: min(340px, calc(100vw - 32px)); color: var(--on-dark); text-align: left; cursor: pointer;
  animation: ach-in .3s cubic-bezier(.22,1,.36,1);
}
#achToast .row:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
#achToast small { display: block; font: 800 11px/1.2 var(--font); letter-spacing: .06em; text-transform: uppercase; opacity: .85; }
#achToast b { display: block; font: 900 15px/1.25 var(--font); overflow-wrap: anywhere; }
@keyframes ach-in { from { opacity: 0; translate: 16px 0; } }
@media (max-width: 720px) { #achToast { left: 16px; justify-items: stretch; } }
@media (prefers-reduced-motion: reduce) {
  .ach-pop, .ach-pop .ribbon, .ach-pop .banner, #achToast .row { animation: none; }
  .ach-pop.melt, .ach-pop.fly { animation: ach-melt .3s linear forwards; }
}

/* ---------- someone's card (from the chat) ---------- */
#achPlayer { width: min(380px, calc(100vw - 32px)); padding: 18px 20px 20px; }
#achPlayer > form { display: flex; justify-content: flex-end; margin: 0 0 14px; }
#achPlayerBody { display: grid; justify-items: center; gap: 12px; text-align: center; }
#achPlayerBody header { display: grid; justify-items: center; gap: 4px; padding: 0 36px; }
#achPlayerBody .ava { width: 96px; height: 96px; flex: none; border-radius: 50%; object-fit: cover; display: grid; place-items: center;
  background: var(--sage) var(--fibre) 0 0 / 120px; background-blend-mode: soft-light; font: 900 38px/1 var(--font); color: var(--ink);
  outline: 2px dashed var(--stitch-on-dark); outline-offset: -7px; box-shadow: 0 2px 0 color-mix(in oklab, var(--ink) 30%, transparent); }
#achPlayerBody h3 { margin: 6px 0 0; font: 900 24px/1.2 var(--font); overflow-wrap: anywhere; }
#achPlayerBody .login { margin: 0 0 6px; color: var(--ink-soft); font-size: 13px; }
#achPlayerBody .chip.ttl { --c: var(--moss); color: var(--on-dark); padding: 7px 22px; font-size: 14px; }
#achPlayerBody .all { display: grid; justify-items: stretch; width: 100%; }
#achPlayerBody .all li { display: flex; align-items: center; gap: 10px; text-align: left; font-weight: 700; font-size: 14px; }
#achPlayerBody ul { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 0; padding: 0; list-style: none; }
#achPlayerBody .all { max-height: 220px; overflow-y: auto; gap: 8px; padding: 4px; }
#achPlayerBody .all[hidden] { display: none; }
#achPlayerBody .sum { margin: 0; font-weight: 800; }
#setAchBox .btn { justify-self: start; }
