/* ═══════════════════════════════════════════════════════════════════
   quad.css — THE FOUR-QUADRANT SELECTOR

   The mark is a plate ruled into four with one green quadrant. Read it
   as a control instead of a logo and it is already a complete option
   picker: four cells, one chosen, the chosen one green. The homepage
   mark (`templates/home.html` `#plate`) is this component at rest with
   its top-right option offered — ruled green, going solid on hover.

   That gives the whole product ONE selection grammar:

       surface   the option is there, not chosen
       ruled     you are on it — the offer, mid-reach
       solid     chosen
       pale      locked (a rank or gate you have not reached)
       hairline  unavailable right now

   ORDER RUNS UP AND TO THE RIGHT. Least at bottom-left, most at
   top-right — the same axes the Commission Board already plots
   (`templates/game_launch.html`: spend →, finish ↑). A player learns
   the direction once and it holds everywhere, from a $1 task size to a
   $110 commission.

   MORE THAN FOUR OPTIONS: the top-right cell subdivides into its own
   plate and the remainder goes in there — the mark recursing into its
   own green corner. Rendering is `quad.js`'s job; this file only has to
   make a nested `.quad` look right inside a cell.

   The component is SKIN-AGNOSTIC: every colour is a custom property, so
   the same markup sits on the heritage paper of the game
   (`game_heritage.css`) and the cream/navy of the studio (`style.css`).
   Override the tokens on an ancestor, not the component's rules.
   ═══════════════════════════════════════════════════════════════════ */

.quad-field {
  /* ── tokens: override these on an ancestor to reskin ── */
  --quad-size: 244px;         /* plate width (height = width / aspect)      */
  --quad-aspect: 1.3;         /* labels are words: wider than tall reads     */
  --quad-rule: 3px;           /* the rule IS the grid gap, as on /home      */
  --quad-radius: 2px;
  --quad-green: var(--sp-brand, #00d98e);       /* StaffParty green, brand.css */
  --quad-green-deep: var(--sp-brand-text, #0f7b53);
  --quad-surface: #fff;
  --quad-rule-color: rgba(28, 26, 22, .16);
  --quad-ink: #1c1a16;
  --quad-ink-soft: #4c463c;
  --quad-ink-faint: #7d7466;
  --quad-focus: #1c1a16;
  --quad-font: inherit;       /* a skin sets the face here, not on a cell   */
  --quad-pitch: 7px;          /* band pitch of the ruled (hover) state       */
  --quad-bar: 2px;

  /* ── the tint ramp ──────────────────────────────────────────────
     The mark's green belongs to the TOP-RIGHT. If every cell filled
     with #00d98e on hover, the corner would stop meaning anything —
     so the fill is a ramp: the lowest option gets `tint-min` percent
     of the green over the cell surface, the corner gets `tint-max`.
     Feedback everywhere, full brand colour in exactly one place, and
     the intensity now encodes the ladder (palest = least committed).

     quad.js sets `--quad-tint` per cell from the option's RANK, not
     its grid area, so the ramp is right for 2-, 3- and 4-cell plates
     and continues into the nested corner past four options.

     The non-corner rungs are NOT a tint of the green — they are GREY.
     Green anywhere but the corner, however pale, still reads as "a bit
     of the brand colour"; grey reads as "not the corner", which is the
     thing that needs saying. So the plate carries exactly one hue: the
     corner. Everything else is a neutral ramp from `tint-min` to
     `tint-soft`, faint at the bottom and merely present at the top.

     `--quad-soft` is that neutral — a grey with the faintest cool cast
     rather than a dead 50% grey, because a pure neutral goes muddy
     beside #00d98e while a whisper of the green's own hue sits with it.
     It still reads as grey; it just doesn't fight.

     To flatten the ramp to a single tone, set --quad-tint-min equal to
     --quad-tint-soft. */
  --quad-soft: #8b9490;       /* the neutral every non-corner rung mixes to */
  --quad-tint-min: 16;        /* % of that neutral in the LOWEST rung       */
  --quad-tint-soft: 40;       /* ceiling for every NON-corner rung          */
  --quad-tint-max: 100;       /* the corner alone — the mark's green, full  */
  --quad-ring: rgba(28, 26, 22, .34);   /* the chosen-cell ring (neutral)   */

  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 18px;
}

/* ── the plate ───────────────────────────────────────────────────── */
.quad {
  display: grid;
  /* minmax(0,1fr), not 1fr: a bare `1fr` track has an AUTO minimum, so one
     cell whose note wraps to two lines grows its row and squashes the
     other — the plate stops being four equal quadrants. Pinning the
     minimum to 0 keeps the quarters equal and lets long text clip
     (each cell already has overflow:hidden) instead of deforming the mark. */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas: "c d" "a b";
  gap: var(--quad-rule);
  background: var(--quad-rule-color);
  width: var(--quad-size);
  aspect-ratio: var(--quad-aspect);
  flex: none;
  padding: 0;
  border: 0;
  margin: 0;
}
/* Fewer than four options: the plate still reads as the mark, but the
   cells that would be empty are absorbed by their neighbours rather
   than left as holes. Least stays bottom-left, most stays top-right. */
.quad[data-n="1"] { grid-template-areas: "a a" "a a"; }
.quad[data-n="2"] { grid-template-areas: "b b" "a a"; }
.quad[data-n="3"] { grid-template-areas: "a c" "a b"; }

.quad__cell {
  grid-area: var(--area);
  /* The ramp, computed here rather than in JS so a skin overriding the
     tint tokens on any ancestor still governs. quad.js supplies
     --quad-rank and --quad-soft-max (the number of steps across the
     non-corner rungs, floored at 1 so a 2-cell plate cannot divide by
     zero). Every rung lands between tint-min and tint-soft. */
  --quad-tint: calc((var(--quad-tint-min) +
    (var(--quad-tint-soft) - var(--quad-tint-min))
    * var(--quad-rank, 0) / var(--quad-soft-max, 1)) * 1%);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 9px 10px 8px;
  background: var(--quad-surface);
  border: 0;
  border-radius: 0;
  font: inherit;
  font-family: var(--quad-font);
  color: var(--quad-ink);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: background .18s ease, color .18s ease;
}
.quad__cell:first-child { border-top-left-radius: var(--quad-radius); }
.quad__cell:last-child  { border-bottom-right-radius: var(--quad-radius); }

/* Every cell reads from its top edge. The first version split this by row —
   top row down from the top, bottom row up from the bottom — which looked
   tidy on short labels but made the NOTE the clipped element on the bottom
   row, since it is the last child. Aligning every cell the same way costs
   one aesthetic nicety and buys a plate where the label and its note are
   always both visible. A cell spanning both rows still centres. */
.quad__cell { justify-content: flex-start; }
.quad[data-n="1"] .quad__cell,
.quad[data-n="3"] .quad__cell[data-area="a"] { justify-content: center; }

/* The ruled state. Painted the way /home paints it and for the same
   reason: SOLID GREEN underneath with white bands laid over, so hover
   only has to fade the bands off. Stripes-at-rest → colour-on-hover
   cannot transition at all, because a gradient does not interpolate to
   a flat background. */
/* The fill. Non-corner rungs mix toward the NEUTRAL; only the corner mixes
   toward the brand green — so a plate carries one hue, in one square. */
.quad__cell::before {
  content: "";
  position: absolute;
  inset: 0;
  /* Flat neutral first: where color-mix is unsupported the cell still
     answers, it just loses the ramp. */
  background: var(--quad-soft);
  background: color-mix(in srgb,
    var(--quad-soft) var(--quad-tint, 40%), var(--quad-surface));
  opacity: 0;
  transition: opacity .18s ease;
  pointer-events: none;
}
.quad__cell[data-corner="1"]::before {
  background: var(--quad-green);
  background: color-mix(in srgb,
    var(--quad-green) calc(var(--quad-tint-max) * 1%), var(--quad-surface));
}
.quad__cell::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to right,
    #fff 0 calc(var(--quad-pitch) - var(--quad-bar)),
    rgba(255, 255, 255, .62) calc(var(--quad-pitch) - var(--quad-bar)) var(--quad-pitch));
  opacity: 0;
  transition: opacity .18s ease;
  pointer-events: none;
}
.quad__cell > * { position: relative; z-index: 1; }

/* reaching for it — ruled green */
.quad__cell:hover::before,
.quad__cell:focus-visible::before { opacity: 1; }
.quad__cell:hover::after,
.quad__cell:focus-visible::after  { opacity: 1; }

/* chosen — the fill goes solid, the bands go. On a pale low-rank cell the
   fill alone is a quiet difference from hover, so the chosen cell also
   takes a neutral ink ring: selection stays unmistakable at every rung
   without spending brand green outside the corner. */
.quad__cell[aria-checked="true"]::before { opacity: 1; }
.quad__cell[aria-checked="true"]::after  { opacity: 0; }
.quad__cell[aria-checked="true"] {
  box-shadow: inset 0 0 0 1.5px var(--quad-ring);
}
/* The deep-green text belongs on the green square only; on a grey rung the
   ordinary ink is what reads, and a green word there would put a second
   trace of the brand colour outside the corner. */
.quad__cell[data-corner="1"][aria-checked="true"] { color: var(--sp-on-brand, #1c1a16); }
.quad__cell[data-corner="1"][aria-checked="true"] .quad__note { color: rgba(8, 50, 31, .74); }

.quad__cell:focus-visible {
  outline: 2px solid var(--quad-focus);
  outline-offset: -2px;
  z-index: 2;
}

/* locked — the cell is there, the tier is not yours yet. No green at
   all: green means available, and a locked option is not. */
.quad__cell[data-state="locked"] {
  background: #ece7db;   /* fallback where color-mix is unsupported */
  background: color-mix(in srgb, var(--quad-surface) 78%, var(--quad-rule-color));
  color: var(--quad-ink-faint);
  cursor: not-allowed;
}
.quad__cell[data-state="locked"]::before,
.quad__cell[data-state="locked"]::after { opacity: 0 !important; }

/* spent — used up for now (a daily allowance, a claimed task). The
   shape stays so the layout does not jump; the offer does not. */
.quad__cell[data-state="spent"] {
  background: var(--quad-surface);
  color: var(--quad-ink-faint);
  cursor: default;
  box-shadow: inset 0 0 0 1.5px rgba(0, 217, 142, .4);
}
.quad__cell[data-state="spent"]::before { opacity: 0 !important; }
.quad__cell[data-state="spent"]::after {
  opacity: 1;
  background: repeating-linear-gradient(135deg,
    transparent 0 5px, rgba(0, 217, 142, .18) 5px 6.5px);
}

/* ── cell contents ───────────────────────────────────────────────── */
.quad__label {
  font-weight: 600;
  font-size: 13.5px;
  line-height: 1.15;
  letter-spacing: -.005em;
  overflow-wrap: break-word;
  hyphens: auto;
}
.quad__note {
  font-size: 10.5px;
  letter-spacing: .06em;
  color: var(--quad-ink-faint);
  font-variant-numeric: tabular-nums;
  transition: color .18s ease;
}
/* a meter drawn inside a cell — an outcome band, a close rate, a share */
.quad__meter {
  position: relative;
  height: 5px;
  margin-top: 3px;
  border-radius: 3px;
  background: rgba(28, 26, 22, .1);
  overflow: hidden;
}
.quad__meter i {
  position: absolute;
  top: 0;
  bottom: 0;
  background: currentColor;
  opacity: .38;
  border-radius: 3px;
}

/* Compact: the plate shrinks to a glyph beside a control and the labels
   move out to the readout. Used where a form row cannot spare 216px. */
.quad--compact { --quad-size: 74px; }
.quad--compact .quad__cell { padding: 0; }
.quad--compact .quad__label,
.quad--compact .quad__note,
.quad--compact .quad__meter { display: none; }

/* Nested plate: the top-right cell holding options five and up. It
   fills its cell edge to edge and keeps ruling itself. Type steps down a
   notch, because a cell inside a cell has half the room. */
.quad__cell > .quad {
  position: absolute;
  inset: 0;
  width: auto;
  aspect-ratio: auto;
  --quad-rule: 2px;
}
.quad__cell > .quad .quad__cell { padding: 6px 8px 6px; }
.quad__cell > .quad .quad__label { font-size: 12px; }
.quad__cell > .quad .quad__note { font-size: 9.5px; letter-spacing: .04em; }
.quad__cell > .quad .quad__meter { display: none; }
.quad__cell:has(> .quad) { padding: 0; cursor: default; }
.quad__cell:has(> .quad)::before,
.quad__cell:has(> .quad)::after { display: none; }
.quad--compact .quad__cell > .quad .quad__label,
.quad--compact .quad__cell > .quad .quad__note { display: none; }

/* ── the readout: what the chosen option actually means ──────────── */
.quad__readout {
  flex: 1 1 260px;
  min-width: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.quad__readout-eyebrow {
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--quad-ink-faint);
}
.quad__readout-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  text-wrap: balance;
}
.quad__readout-title .quad__price {
  font-variant-numeric: tabular-nums;
  color: var(--quad-green-deep);
  margin-left: 6px;
}
.quad__readout-desc {
  font-size: 14px;
  color: var(--quad-ink-soft);
  line-height: 1.35;
  max-width: 52ch;
}
.quad__readout-locked {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--quad-ink-faint);
}

/* The original control stays in the DOM and keeps carrying the value —
   every existing form post and change handler goes on working. It is
   hidden from sight but not from assistive tech's label association,
   which the plate mirrors with aria-labelledby. */
.quad-field select.quad-source,
.quad-field input.quad-source {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .quad__cell,
  .quad__cell::before,
  .quad__cell::after,
  .quad__note { transition: none; }
}

/* Narrow screens: a 216px plate beside 260px of readout does not fit on
   a phone, so the readout drops under the plate and the plate grows to
   the column width (capped, or it becomes a billboard). */
@media (max-width: 560px) {
  .quad-field { gap: 14px; }
  .quad:not(.quad--compact .quad) { --quad-size: min(100%, 280px); }
}
