/* ------------------------------------------------------------------
   Grants: what the campaign earns, and where the next of it is.
   Loaded after areas.css.
   ------------------------------------------------------------------ */
/*
 * The district-grant screen was styled from here.
 *
 * It is gone: the same ground is covered by grantsSection(), which uses the
 * game screen's own `.g-` blocks, and the Grant tab opens the contests below
 * instead. Keeping five hundred lines describing a screen nothing renders
 * would also have left `.gr-card` meaning two different things.
 */


/* ==========================================================================
   Grant contests — one grant, one track
   --------------------------------------------------------------------------
   A block is a line and a track. The line carries the name, the price of a
   point and the Spend button, and it stays one line at every width. The track
   carries every campaign in the contest as a face at its own position.

   It used to be a chart per campaign: six blocks of up to six bars, which on
   a phone was a page of bars and no answer to the question the page exists to
   answer. A race is one track with the runners on it.
   ========================================================================== */

.gc-list { display: flex; flex-direction: column; gap: 10px; }

.gc-item {
  padding: 9px 11px 7px;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--gold);
  border-radius: 12px;
  background: var(--paper-2);
}
.gc-item.is-owned { border-left-color: var(--navy-3); background: var(--paper); }
.gc-item.is-yours { border-color: var(--gold); border-left-color: var(--gold); }

/*
 * Name, price, button — one line, at every width.
 *
 * The name takes what is left after the two fixed things beside it, and
 * ellipsises rather than wrapping. A Spend button that drops under the name
 * on a phone doubles the height of all six blocks, which is the difference
 * between a page you scroll and a page you read.
 */
.gc-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.gc-name {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gc-cost {
  flex: none;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--navy-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Won, and locked: the tick takes the button’s place rather than sitting beside it. */
.gc-won {
  flex: none;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--paper-3);
  color: var(--navy-2);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.gc-won.is-yours { background: var(--wash-gold); color: var(--gold-deep); }

.gc-spend {
  appearance: none;
  flex: none;
  padding: 6px 14px;
  border: 1px solid var(--warn-good);
  border-radius: 9px;
  background: var(--warn-good);
  color: #fff;
  font-family: var(--font);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.14s ease;
}
.gc-spend:hover:not(:disabled) { filter: brightness(1.08); }
.gc-spend:active:not(:disabled) { filter: brightness(0.94); }
.gc-spend:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
.gc-spend.is-off,
.gc-spend:disabled {
  background: var(--paper-3);
  border-color: var(--rule);
  color: var(--navy-3);
  cursor: default;
}

/* ------------------------------------------------------------- the track */

/*
 * One line, twelve points, every campaign on it.
 *
 * Three layers stacked in a fixed height: the faces above the line, the line
 * with its divisions, and the scale under it. The height is fixed so that six
 * blocks down the page have their lines at even intervals whatever is
 * standing on them — a track that grew when two campaigns tied would make the
 * whole page jump every time somebody spent.
 */
.gt {
  --gt-face: 22px;
  --gt-stack: 13px;
  position: relative;
  margin-top: 4px;
  /*
   * Half a face of room at each end.
   *
   * A campaign on nought stands at the left-hand end of the line and one on
   * twelve at the right, and a marker is centred on its own point — so
   * without this the first and last faces hang half outside the card. The
   * line, the markers and the scale all sit inside the same padded box, so
   * they stay in step with each other.
   */
  padding: calc(var(--gt-face) + var(--gt-stack) * 2 + 4px)
           calc(var(--gt-face) / 2 + 1px) 0;
}

.gt-markers { position: relative; height: 0; }

/*
 * A campaign, standing at its own point.
 *
 * Positioned by the centre of the face, so a campaign on nought sits at the
 * left-hand end of the line and one on twelve at the right rather than either
 * of them hanging off the edge. `--stack` lifts a face clear of any already
 * standing on that point: two level campaigns are one above the other and
 * both are legible, which a pair laid on top of each other is not.
 */
.gt-marker {
  position: absolute;
  bottom: calc(2px + var(--stack) * var(--gt-stack));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: bottom 0.16s ease, left 0.22s ease;
}
.gt-marker .portrait {
  display: block;
  width: var(--gt-face);
  height: var(--gt-face);
  border-radius: 50%;
  border: 2px solid var(--party);
  background: var(--paper);
  box-shadow: 0 1px 3px rgba(18, 32, 54, 0.22);
}

/* A stem down to the line, so a stacked face still points at its own mark. */
.gt-marker-pin {
  width: 2px;
  flex: 1 0 auto;
  min-height: 3px;
  background: var(--party);
  opacity: 0.55;
}

.gt-marker.is-you .portrait { border-color: var(--gold); border-width: 3px; }
.gt-marker.is-lead { z-index: 2; }
.gt-marker.is-lead .portrait { box-shadow: 0 0 0 2px var(--wash-gold), 0 1px 4px rgba(18, 32, 54, 0.3); }

/* The line itself, with the activation mark drawn heavier than the rest. */
.gt-line {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--paper-3);
  box-shadow: inset 0 0 0 1px var(--rule);
  overflow: hidden;
}

/*
 * How far the front of the race has reached, in that campaign’s colour.
 *
 * The bar is the answer to "who is winning this one" from across the page,
 * which a row of faces at different positions is not. The colour is the
 * leader’s and follows the lead: overtake, and the fill changes colour with
 * it, because it is drawn from whoever the engine says is in front.
 *
 * Level at the top fills to that position in the quiet grey instead. Nobody
 * is leading a contest two campaigns are level in, and painting it one of
 * their colours would be picking a winner the rules refuse to pick.
 */
.gt-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 4px;
  background: var(--party, var(--gold));
  transition: width 0.24s cubic-bezier(0.2, 0.9, 0.3, 1),
              background-color 0.24s ease;
}
.gt-fill.is-level { background: var(--navy-3); opacity: 0.5; }

/*
 * A contest nobody has entered is an empty line.
 *
 * No faces, no fill — the drawing of a race that has not started. The track
 * keeps its full height so six blocks down the page stay evenly spaced
 * whether anybody has spent in them or not.
 */
.gt.is-empty .gt-line { background: var(--paper-3); }
/*
 * The divisions sit over the fill, so the scale reads through it.
 *
 * A bar that swallowed its own gradations would be a bar you cannot count
 * along, which is most of what the chart is for.
 */
.gt-notch {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--rule);
  mix-blend-mode: multiply;
}
.gt-notch.is-mark {
  width: 2px;
  background: var(--gold-deep);
  opacity: 0.6;
}

/*
 * The scale, so a position is a number.
 *
 * Every second division, because twelve numbers under a phone-width track is
 * a grey smear. The activation mark is picked out in gold: passing it is the
 * only threshold on the line that changes what happens.
 */
.gt-scale {
  position: relative;
  height: 12px;
  margin-top: 2px;
}
.gt-tick {
  position: absolute;
  transform: translateX(-50%);
  font-size: 0.55rem;
  font-weight: 600;
  color: var(--navy-3);
  font-variant-numeric: tabular-nums;
}
.gt-tick.is-mark { color: var(--gold-deep); font-weight: 700; }

.gc-flash {
  margin: 6px 0 0;
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 0.72rem;
  font-weight: 600;
}
.gc-flash.is-good { background: var(--wash-gold); color: var(--gold-deep); }
.gc-flash.is-bad {
  background: color-mix(in srgb, var(--warn-bad) 10%, transparent);
  color: var(--warn-bad);
}

/* --------------------------------------------------------------- narrow */

/*
 * On a phone the type and the padding give, and the layout does not.
 *
 * Name, price and button stay on one line at 320px because all three shrink
 * together — this is the rule that keeps them there, so it is the one to be
 * careful with.
 */
@media (max-width: 390px) {
  .gc-item { padding: 8px 9px 6px; }
  .gc-head { gap: 6px; }
  .gc-name { font-size: 0.92rem; }
  .gc-cost { font-size: 0.7rem; }
  .gc-spend { padding: 6px 11px; font-size: 0.58rem; letter-spacing: 0.06em; }
  .gt { --gt-face: 20px; --gt-stack: 12px; }
}

@media (max-width: 340px) {
  .gc-name { font-size: 0.86rem; }
  .gc-cost { font-size: 0.65rem; }
  .gc-spend { padding: 5px 9px; font-size: 0.55rem; letter-spacing: 0.03em; }
  .gt { --gt-face: 18px; --gt-stack: 11px; }
  .gt-tick { font-size: 0.5rem; }
}

/*
 * A marker slides to its new point; it does not jump. And where somebody has
 * asked for less movement, nothing slides at all.
 */
@media (prefers-reduced-motion: reduce) {
  .gt-fill, .gt-marker { transition: none; }
}
