/* ===========================================================================
   PHASE 7.8 -- FAMILY VOTE AND THE CHALLENGE CARDS.

   Loaded LAST, after phase77a.css, for the same reason each of these follows
   the previous one: where it restyles something an earlier sheet defined, that
   is ordinary cascade order rather than `!important`.

   ---------------------------------------------------------------------------
   NO INLINE STYLES. THE POLICY IS `style-src 'self'`
   ---------------------------------------------------------------------------
   `element.style.*` is blocked, and blocked SILENTLY -- the rule simply never
   applies, and Phase 7 shipped a release where every progress bar rendered
   empty because of it.

   So the progress bars here carry their width as `data-pct`, bucketed to 5%
   by the painter, and the twenty rules at the bottom of this file turn it into
   a width. Twenty buckets is finer than anybody can see on a phone.

   ---------------------------------------------------------------------------
   PHONE FIRST, AND THE BALLOT IS THE POINT
   ---------------------------------------------------------------------------
   The one genuinely new interaction in this phase is choosing somebody to vote
   for, and it happens with a thumb. Each ballot entry is a full-width button
   at `var(--tap)` (48px) with its own vertical gap, so the wrong name is hard
   to hit -- which matters more here than anywhere else in the app, because the
   vote cannot be changed.

   Everything is laid out in a single column with no fixed widths and no
   horizontal scroll: the tally rows are a three-part grid whose middle column
   absorbs the space and truncates a long name rather than pushing the count
   off screen.

   ---------------------------------------------------------------------------
   NO STATE IS CARRIED BY COLOUR ALONE
   ---------------------------------------------------------------------------
   A completed objective has a tick AND the word "(done)" for a screen reader;
   a winning row has an accent AND the winner's prize spelled out underneath.
   =========================================================================== */

/* ---------------------------------------------------------------------------
   THE SHARED CARD SHELL -- used by both Home cards and both screens
   --------------------------------------------------------------------------- */

.p78card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.p78card__eyebrow {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.p78card__prompt,
.p78screen__prompt {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.35;
  color: var(--text);
  /* A long question wraps rather than widening the card. */
  overflow-wrap: anywhere;
}

.p78screen__prompt {
  font-size: 1.15rem;
}

.p78card__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.p78card__icon {
  font-size: 1.25rem;
  line-height: 1;
}

.p78card__objective {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--text-dim);
}

.p78card__note,
.p78screen__hint {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.p78card__label {
  margin: 4px 0 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.p78card__progress {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--metal);
}

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

.p78card__reward,
.p78card__foot,
.p78card__more {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-faint);
}

.p78card__mine {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text);
}

.p78card__winner {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.p78card__prize,
.p78card__earned {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
}

.p78card__item {
  margin: 0;
  font-size: 0.9rem;
  color: var(--metal);
}

/* The action sits at the bottom and spans the card: one obvious tap target. */
.p78card__go {
  margin-top: 4px;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* ---------------------------------------------------------------------------
   THE TALLY -- top five on Home, the full ranking on the screen
   --------------------------------------------------------------------------- */

.p78tally {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.p78tally__row {
  /*
   * rank | name | votes. The NAME column absorbs the slack, so a long display
   * name truncates instead of pushing the count off the side of a phone.
   */
  display: grid;
  grid-template-columns: 1.75rem 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  font-size: 0.95rem;
}

.p78tally__rank {
  font-family: var(--mono);
  color: var(--text-faint);
}

.p78tally__name {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.p78tally__votes {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--metal);
}

/* A winner is accented AND is named again in the prize line below. */
.p78tally__row.is-winner {
  background: var(--accent-dim);
}

.p78tally__row.is-winner .p78tally__name,
.p78tally__row.is-winner .p78tally__votes,
.p78tally__row.is-winner .p78tally__rank {
  color: #04120e;
}

.p78tally--full {
  gap: 3px;
}

/* ---------------------------------------------------------------------------
   OBJECTIVE TICKS
   --------------------------------------------------------------------------- */

.p78objs {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.p78obj {
  display: grid;
  grid-template-columns: 1.1rem 1fr;
  align-items: start;
  gap: 8px;
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--text-dim);
}

.p78obj__mark {
  font-family: var(--mono);
  color: var(--text-faint);
}

.p78obj.is-done {
  color: var(--text);
}

.p78obj.is-done .p78obj__mark {
  color: var(--accent);
}

.p78obj__label {
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------------------
   THE PROGRESS BAR
   --------------------------------------------------------------------------- */

.p78bar {
  height: 10px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  overflow: hidden;
}

.p78bar__fill {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  /* Width comes from the data-pct rules at the bottom of this file. */
  width: 0;
}

/* ---------------------------------------------------------------------------
   THE FAMILY VOTE SCREEN
   --------------------------------------------------------------------------- */

[data-familyvote="root"],
[data-challenges="root"] {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.p78screen__locked {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--text);
}

.p78screen__lock {
  font-size: 1rem;
  line-height: 1;
}

.p78screen__total {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-faint);
}

.p78screen__cancelled {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--warn);
}

/* ---- THE BALLOT ------------------------------------------------------- */

.p78ballot {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  /*
   * A generous gap, on purpose. This is the one irreversible tap in the
   * application, and the cost of hitting the wrong name is somebody else's
   * day. 10px between 48px targets is comfortable for a thumb.
   */
  gap: 10px;
}

.p78ballot__btn {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-elev-2);
  color: var(--text);
  font: inherit;
  font-size: 1.02rem;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}

.p78ballot__btn:hover {
  border-color: var(--accent-dim);
}

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

.p78ballot__btn[disabled] {
  opacity: 0.6;
  cursor: progress;
}

/* ---- THE WINNER PANEL ------------------------------------------------- */

.p78winner {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  border: 1px solid var(--accent-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.p78winner__names {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  overflow-wrap: anywhere;
}

.p78winner__prize {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent);
}

/* ---- SEE ALL VOTES --------------------------------------------------- */

.p78screen__all {
  min-height: var(--tap);
  align-self: flex-start;
}

.p78ballots {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.p78ballots__row {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  font-size: 0.9rem;
  color: var(--text-dim);
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------------------
   THE CHALLENGE SCREEN
   --------------------------------------------------------------------------- */

.p78panel,
.p78next {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.p78done {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  border: 1px solid var(--accent-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.p78done__head {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.p78done__fp {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.p78done__item {
  margin: 0;
  font-size: 0.9rem;
  color: var(--metal);
}

.p78recent {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.p78recent__row {
  display: grid;
  grid-template-columns: 1.4rem 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  font-size: 0.9rem;
}

.p78recent__icon {
  line-height: 1;
}

.p78recent__name {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.p78recent__row.is-done .p78recent__name {
  color: var(--text);
}

.p78recent__status {
  font-size: 0.78rem;
  color: var(--text-faint);
  white-space: nowrap;
}

.p78recent__row.is-done .p78recent__status {
  color: var(--accent);
}

/* ---------------------------------------------------------------------------
   THE TWENTY WIDTH BUCKETS
   ---------------------------------------------------------------------------
   This is what replaces `element.style.width`. The painter rounds to the
   nearest 5% and writes it to `data-pct`; these rules do the rest, so the bars
   work under `style-src 'self'` with no nonce and no exception.
   --------------------------------------------------------------------------- */

.p78bar__fill[data-pct="0"]   { width: 0; }
.p78bar__fill[data-pct="5"]   { width: 5%; }
.p78bar__fill[data-pct="10"]  { width: 10%; }
.p78bar__fill[data-pct="15"]  { width: 15%; }
.p78bar__fill[data-pct="20"]  { width: 20%; }
.p78bar__fill[data-pct="25"]  { width: 25%; }
.p78bar__fill[data-pct="30"]  { width: 30%; }
.p78bar__fill[data-pct="35"]  { width: 35%; }
.p78bar__fill[data-pct="40"]  { width: 40%; }
.p78bar__fill[data-pct="45"]  { width: 45%; }
.p78bar__fill[data-pct="50"]  { width: 50%; }
.p78bar__fill[data-pct="55"]  { width: 55%; }
.p78bar__fill[data-pct="60"]  { width: 60%; }
.p78bar__fill[data-pct="65"]  { width: 65%; }
.p78bar__fill[data-pct="70"]  { width: 70%; }
.p78bar__fill[data-pct="75"]  { width: 75%; }
.p78bar__fill[data-pct="80"]  { width: 80%; }
.p78bar__fill[data-pct="85"]  { width: 85%; }
.p78bar__fill[data-pct="90"]  { width: 90%; }
.p78bar__fill[data-pct="95"]  { width: 95%; }
.p78bar__fill[data-pct="100"] { width: 100%; }

/* ---------------------------------------------------------------------------
   VERY NARROW PHONES (the 320px class)
   ---------------------------------------------------------------------------
   The tally's rank column and the recent list's icon column are the first
   things to cost more than they are worth below 360px.
   --------------------------------------------------------------------------- */

@media (max-width: 359px) {
  .p78tally__row {
    grid-template-columns: 1.4rem 1fr auto;
    padding: 6px 8px;
    font-size: 0.9rem;
  }

  .p78recent__row {
    grid-template-columns: 1.2rem 1fr auto;
  }

  .p78recent__status {
    font-size: 0.72rem;
  }
}

/* Respect a reduced-motion preference: nothing here animates, and the bar's
   width changes between polls rather than transitioning, so there is nothing
   to disable -- stated so a future edit does not add one silently. */
