/* ===========================================================================
   PHASE 7.5 -- BADGES, REWARDS AND PROGRESSION.

   Loaded LAST, after phase74.css, for the same reason that one is loaded after
   phase7.css: the Badges screen extends the `.achievement` cards phase6.css
   defines, and extending them from a later stylesheet means doing it with
   ordinary specificity instead of `!important`.

   ---------------------------------------------------------------------------
   PHONE FIRST, AND SIX TABS
   ---------------------------------------------------------------------------
   The tab bar went from five items to six. At 320px that is 53px each, which is
   still above the 44px minimum touch target, but the labels no longer have room
   to breathe -- so below 360px they shrink by a point and the icon tightens up.
   Nothing is hidden: a tab with no label is a tab nobody learns.

   ---------------------------------------------------------------------------
   NO INLINE STYLES, ANYWHERE
   ---------------------------------------------------------------------------
   The Content Security Policy is `style-src 'self'`, so a progress bar cannot be
   filled with `element.style.width`. Every meter in this application is filled by
   adding one of the `.is-pN` classes phase6.css already defines, quantised to 5%.
   Phase 7 found this out when every bar in the app rendered empty.
   =========================================================================== */

/* ---------------------------------------------------------------------------
   THE UNREAD DOT (Part H)

   A dot, not a push notification -- H is explicit that badges must never use
   ordinary phone push. Positioned against the tab rather than the icon so it does
   not move when a label wraps.
   --------------------------------------------------------------------------- */

.tab {
  position: relative;
}

.tab__dot {
  position: absolute;
  top: 0.35rem;
  right: 50%;
  margin-right: -1.05rem;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--accent);
  /* A ring in the bar's own colour, so the dot reads as separate from the icon
     rather than as part of it on a busy background. */
  box-shadow: 0 0 0 2px var(--bg-elev);
}

@media (prefers-reduced-motion: no-preference) {
  .tab__dot {
    animation: badge-dot-in 220ms ease-out;
  }
}

@keyframes badge-dot-in {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/*
 * Only the DOT is adjusted here for a small phone. The label and icon sizes live
 * in app.css beside the six-column grid they belong to, because splitting one
 * layout decision across two stylesheets is how a layout decision gets half
 * changed.
 */
@media (max-width: 360px) {
  .tab__dot {
    margin-right: -0.85rem;
  }
}

/* ---------------------------------------------------------------------------
   THE CATEGORY CHIPS (A2)

   One horizontally scrolling row. A2 asks for filtering "without cluttering
   mobile UI", and a row that scrolls is the only control that stays one line tall
   however many categories there are.

   `scrollbar-width: none` hides the bar on desktop; the row is still scrollable
   by wheel, drag and keyboard, and on a phone there was never a visible bar.
   --------------------------------------------------------------------------- */

.chiprow {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding: 0.15rem 0 0.55rem;
  margin: 0 0 0.25rem;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.chiprow::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 2rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

.chip:hover {
  color: var(--text);
}

.chip--on {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
   BADGE CARDS

   The reward line is the new part. It is deliberately quiet: a badge is about
   the thing you did, and the number is the footnote.
   --------------------------------------------------------------------------- */

.achievement__reward {
  margin: 0.3rem 0 0;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.achievement__reward--got {
  /* `--metal` rather than `--accent`: accent is the colour of an ACTION in this
     palette, and a reward already received is a fact rather than an invitation. */
  color: var(--metal);
}

/*
   A SECRET BADGE LOOKS LIKE A SECRET.

   Dashed rather than solid, and the icon dimmed, so the "???" cards read as a
   deliberate row of unknowns rather than as badges that failed to load. A4 asks
   for exactly that impression.
*/
.achievement--secret.achievement--locked {
  border-style: dashed;
}

.achievement--secret.achievement--locked .achievement__icon {
  opacity: 0.55;
}

.achievement--secret.achievement--locked .achievement__name {
  letter-spacing: 0.08em;
}

/* An earned secret is an ordinary earned badge again -- nothing left to hide. */
.achievement--secret.achievement--earned {
  border-style: solid;
}

/* ---------------------------------------------------------------------------
   THE HOME BADGE PROGRESS CARD (A1)
   --------------------------------------------------------------------------- */

.badgecard {
  display: grid;
  gap: 0.55rem;
}

.badgecard__count {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}

.badgecard__empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.badgecard__row {
  display: grid;
  /* The name takes what is left; the figures take only what they need, so a long
     badge name truncates instead of pushing the numbers off the card. */
  grid-template-columns: 1fr auto;
  gap: 0.15rem 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--line);
}

.badgecard__row:first-of-type {
  padding-top: 0;
  border-top: 0;
}

.badgecard__name {
  margin: 0;
  font-weight: 600;
  font-size: 0.92rem;
  /* A single line, ellipsised. Two lines here would make every row a different
     height and the card would never look settled. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badgecard__figures {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.badgecard__bar {
  grid-column: 1 / -1;
  position: relative;
  height: 0.4rem;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

/*
   Filled by a width class, never by an inline style.

   `.is-pN` is defined in phase6.css for `.meter` and `.achievement__progress`;
   those selectors do not reach this element, so the fill is declared here against
   the same class names. The two have to agree about the step size, which is 5%.
*/
.badgecard__bar::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
}

.badgecard__bar.is-p0::after { width: 0; }
.badgecard__bar.is-p5::after { width: 5%; }
.badgecard__bar.is-p10::after { width: 10%; }
.badgecard__bar.is-p15::after { width: 15%; }
.badgecard__bar.is-p20::after { width: 20%; }
.badgecard__bar.is-p25::after { width: 25%; }
.badgecard__bar.is-p30::after { width: 30%; }
.badgecard__bar.is-p35::after { width: 35%; }
.badgecard__bar.is-p40::after { width: 40%; }
.badgecard__bar.is-p45::after { width: 45%; }
.badgecard__bar.is-p50::after { width: 50%; }
.badgecard__bar.is-p55::after { width: 55%; }
.badgecard__bar.is-p60::after { width: 60%; }
.badgecard__bar.is-p65::after { width: 65%; }
.badgecard__bar.is-p70::after { width: 70%; }
.badgecard__bar.is-p75::after { width: 75%; }
.badgecard__bar.is-p80::after { width: 80%; }
.badgecard__bar.is-p85::after { width: 85%; }
.badgecard__bar.is-p90::after { width: 90%; }
.badgecard__bar.is-p95::after { width: 95%; }
.badgecard__bar.is-p100::after { width: 100%; }

.badgecard__reward {
  grid-column: 1 / -1;
  margin: 0.1rem 0 0;
  font-size: 0.76rem;
  color: var(--text-dim);
}

/* ---------------------------------------------------------------------------
   THE UNLOCK CELEBRATION (Part G)

   Extends the Phase 6 badge toast with the reward lines. Still a toast and still
   non-blocking: G asks for "a polished in-app celebration", and somebody halfway
   through answering a question should not have to dismiss a modal because they
   earned a badge.
   --------------------------------------------------------------------------- */

.toast__reward {
  margin: 0.1rem 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent);
}

.toast__reward--note {
  font-weight: 400;
  color: var(--text-dim);
}

/* ---------------------------------------------------------------------------
   ADMIN: THE BADGE CONFIGURATION TABLE (Part I)
   --------------------------------------------------------------------------- */

.badgeadmin__row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.2rem 0.6rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
}

.badgeadmin__meta {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.76rem;
  color: var(--text-dim);
}

.badgeadmin__warn {
  color: var(--warn);
}
