/* Team balancer tool page — /5v5-team-balancer/ and /es/balanceador-equipos-futbol-5/.
   Styles exactly what assets/js/team-balancer.js emits into [data-tb-stage]; that
   file's header holds the DOM contract. page-team-balancer*.hbs loads it through
   default.hbs "meta", so no other page pays for it.
   The .faq stack is home.css's: never add a second accordion here. */

.tb-page .doc-content p,
.tb-page .doc-content li {
  text-wrap: pretty;
}

/* Reserves its height before js/team-balancer.js renders: the swap causes no
   layout shift. */
.tb {
  margin: 0 0 var(--space-3xl);
  --ring-r: var(--radius-xl);
  --ring-color: var(--color-border);
  --ring-face: var(--color-card);
}

.tb-face {
  padding: var(--space-lg);
}

/* The caption role owns the type; the rules below own the box and the muted ink. */
.tb-noscript {
  margin: 0 0 var(--space-md);
  display: block;
  --ring-r: var(--radius-md);
  --ring-color: var(--color-border);
  --ring-face: var(--surface-soft);
  color: var(--color-heading);
}

.tb-noscript > .ring-face {
  display: block;
  padding: var(--space-sm) var(--space-md);
}

.tb-stage {
  min-height: 28rem;
  --r: var(--radius-lg);
  border-radius: var(--radius-lg);
  background: var(--surface-soft);
}

@media (min-width: 768px) {
  .tb-face {
    padding: 1.75rem;
  }

  .tb-stage {
    min-height: 34rem;
  }
}

/* .doc-content already indents the list and spaces the items; this sets the
   measure only. */
.tb-steps-list {
  max-width: 72ch;
}

.tb-steps-list li::marker {
  color: var(--color-muted);
}

.tb-steps-list strong {
  color: var(--color-heading);
}

/* The 60–75ch prose measure (DESIGN.md → Typography). */
.tb-faq .faq-answer-inner p {
  max-width: 70ch;
}

/* ================================================== interactive tool
   Rendered by assets/js/team-balancer.js into [data-tb-stage]. render() sets
   --team-a-color / --team-b-color on .tb-app, and either can sit against the card
   colour, so anything painted with one carries a --color-heading edge. */
.tb {
  --tb-team-a: #506d59;
  --tb-team-b: #2563eb;
}

:root[data-theme="dark"] .tb {
  --tb-team-a: #90ab8b;
  --tb-team-b: #7ab0ff;
}

/* Rating bands, measured on --color-card: light 4.79 / 3.20 / 3.93 / 3.25:1,
   dark 6.29 / 10.31 / 9.98 / 10.42:1. Ticks are decorative, so the 3:1 non-text
   threshold applies; the readout stays --color-heading for AA. */
.tb {
  --tb-rate-red: #d13b31;
  --tb-rate-orange: #e2701c;
  --tb-rate-green: #3f9142;
  --tb-rate-gold: #b8860b;
}

:root[data-theme="dark"] .tb {
  --tb-rate-red: #f87171;
  --tb-rate-orange: #fdba74;
  --tb-rate-green: #4ade80;
  --tb-rate-gold: #fbbf24;
}

/* JS appends exactly these two children; each claims its area. */
.tb-app {
  display: grid;
  gap: var(--space-sm);
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "squad" "balance";
}

.tb-app > * {
  grid-area: var(--tb-area);
}

.tb-balance {
  --tb-area: balance;
}

.tb-squad {
  --tb-area: squad;
}

@media (min-width: 900px) {
  /* Long rosters scroll inside the card instead of stretching the page. */
  .tb .tb-list {
    max-height: 34rem;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

.tb-h {
  margin: 0 0 var(--space-xs);
  color: var(--color-heading);
  text-wrap: balance;
}

/* balance panel */

.tb-balance {
  --ring-r: var(--radius-lg);
  --ring-color: var(--color-border);
  --ring-face: var(--color-card);
}

.tb-balance-face {
  padding: var(--space-md);
}

/* Title left, the action row right; at 375px the row wraps and the buttons stay
   right-aligned on their own line. */
.tb-balance-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.tb-balance-head .tb-h {
  margin: 0;
}

/* Note + share-link fallback sit under the whole panel as a block. */
.tb-actions-extra {
  display: grid;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
}

.tb-actions-extra .tb-note {
  margin: 0;
}

/* head-to-head strip: it stacks under 600px and reads outward from the VS pill;
   each side is one row that wraps into a column. */

.tb-h2h {
  display: grid;
  gap: 10px var(--space-sm);
  grid-template-columns: minmax(0, 1fr);
}

.tb-h2h-side {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  /* 24px between wrapped lines / 16px inside one: the badge lives in the avs
     padding reserve, the row above still needs air. */
  gap: var(--space-xl) var(--space-md);
  min-width: 0;
}

/* One alias per side; the fallbacks are the JS map's defaults (red / blue) and
   must stay in step with it. */
.tb-h2h-side-a {
  --tb-side-color: var(--team-a-color, #d13b31);
}

.tb-h2h-side-b {
  --tb-side-color: var(--team-b-color, #2563eb);
}

.tb-h2h-line {
  display: flex;
  flex-wrap: wrap; /* the average chip drops to its own row at 375px */
  align-items: center;
  gap: 6px 10px;
  min-width: 0;
}

/* A fixed COLUMN COUNT, never flex-wrap: the line shrink-fits around the average
   chip and a wrapping row then packs against that line (five players silently
   became 3+2). Five columns from 1120px, the width where a side owns the 461px
   five 4rem tiles, their 28px gaps and the chip need. */
.tb-h2h-avs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 4rem));
  justify-content: start;
  gap: var(--space-md) 28px;
  padding: var(--space-xl) 0 0 var(--space-xl);
  margin: -24px 0 0 -24px;
  min-width: 0;
}

@media (min-width: 1120px) {
  .tb-h2h-avs {
    grid-template-columns: repeat(5, minmax(0, 4rem));
  }
}

/* padding 0 so the button is exactly the 44px avatar (the 44px hit floor) in
   both blocks. */
.tb-h2h-avs .tb-pl,
.tb-bench-avs .tb-pl {
  padding: 0;
}

.tb-h2h-pl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2xs);
  /* lets the name clamp inside its fixed column instead of widening it */
  min-width: 0;
}

/* The badge anchor; the badges are siblings of the avatar and of each other —
   buttons never nest. */
.tb-h2h-avawrap {
  position: relative;
  display: block;
}

/* Name under the avatar, aria-hidden in JS: the avatar button — or the swap
   badge — already announces name, rating and destination. */
.tb-h2h-pname {
  max-width: 100%;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
  text-align: center;
  color: var(--color-heading);
}

/* Remove from team: centre on the avatar's outer top-left (top-right is the swap
   badge, bottom-right the rating chip). z-index 2 > the avatar's 1. */
.tb-h2h-rm {
  position: absolute;
  top: -1px;
  left: -1px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  transform: translate(-50%, -50%);
  --ring-color: var(--color-muted);
  --ring-face: var(--color-card);
  color: var(--color-muted);
  font-size: var(--fs-micro);
  line-height: var(--lh-tight);
  cursor: pointer;
  transition: color 0.15s ease-out, background-color 0.15s ease-out,
    border-color 0.15s ease-out;
}

.tb-h2h-rm:focus-visible {
  color: var(--color-error-fg);
  --ring-color: var(--color-error-fg);
  --ring-face: var(--color-error-bg);
}

.tb-h2h-rm::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
}

@media (hover: hover) {
  .tb-h2h-rm:hover {
    color: var(--color-error-fg);
    border-color: var(--color-error-fg);
    background: var(--color-error-bg);
  }
}

/* Swap: the ✕'s top-right twin, neutral accents — it moves a player, it does not
   destroy one. */
.tb-h2h-go {
  position: absolute;
  top: -1px;
  right: -1px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px; /* 32-grid: 24 face around the 16 glyph */
  padding: 0;
  transform: translate(50%, -50%);
  --ring-color: var(--color-muted);
  --ring-face: var(--color-card);
  color: var(--color-muted);
  cursor: pointer;
  transition: color 0.15s ease-out, background-color 0.15s ease-out,
    border-color 0.15s ease-out;
}

/* 44px touch floor: the ::after's box is the 20px content box (22 minus the 1px
   borders), so 20 + 2 × 12 = 44. Its area reaches x≈22 and the ✕ stops at x≈10,
   so the two never overlap. */
.tb-h2h-go::after {
  content: "";
  position: absolute;
  inset: -12px;
}

.tb-h2h-go:focus-visible {
  color: var(--color-heading);
  --ring-color: var(--color-heading);
  --ring-face: var(--surface-soft);
}

@media (hover: hover) {
  .tb-h2h-go:hover {
    color: var(--color-heading);
    border-color: var(--color-heading);
    background: var(--surface-soft);
  }
}

.tb-h2h-go svg {
  display: block;
  width: 16px;
  height: 16px; /* 32-grid: 16 tier */
}

/* The average chip (markup: <b>value</b> + sr-only "average"). */
.tb-h2h-avg {
  --ring-color: var(--color-border);
  --ring-face: var(--surface-soft);
  line-height: var(--lh-ui);
  white-space: nowrap;
}

.tb-h2h-avg > .ring-face {
  display: inline-flex;
  align-items: baseline;
  padding: 2px 10px;
}

.tb-h2h-avg b {
  font-size: var(--fs-lead);
  font-weight: var(--fw-bold);
  color: var(--color-heading);
  font-variant-numeric: tabular-nums;
}

/* Decorative VS pill (aria-hidden): presence, not weight. --color-muted on
   --surface-soft is 4.5:1 light / 5.5:1 dark. */
.tb-h2h-vs {
  justify-self: center;
  --ring-color: var(--color-border);
  --ring-face: var(--surface-soft);
  color: var(--color-muted);
  white-space: nowrap;
}

.tb-h2h-vs > .ring-face {
  display: inline-flex;
  padding: 5px var(--space-sm);
}

/* Bench: the players with no team, only rendered while someone IS off the pitch. A
   wrapping row, not a grid: the count runs 1..50 and a fixed column count strands a
   lone tile; the pip is the team pip in grey. */
.tb-bench {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: var(--space-sm); /* .tb-balance is a plain block: children carry their own */
}

.tb-bench-h {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--color-heading);
}

.tb-bench-h::before {
  content: "";
  width: 10px;
  height: 10px;
  flex: none;
  border: 1px solid var(--color-heading);
  --r: var(--radius-circle);
  border-radius: var(--radius-circle);
  background: var(--color-muted);
}

.tb-bench-avs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md) 18px; /* the team rows' rhythm */
  min-width: 0;
}

.tb-bench-avs .tb-h2h-pl {
  flex: 0 0 4rem; /* the same tile width the team rows use */
}

@media (min-width: 600px) {
  .tb-h2h {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
  }

  /* Side B mirrors side A: its line packs to the END (already in the DOM), so
     the two rows read outward from the VS pill. */
  .tb-h2h-side-b {
    justify-content: flex-end;
  }

  .tb-h2h-side-b .tb-h2h-line {
    justify-content: flex-end;
  }
}

/* The pop-up's anchor and the class the outside-pointerdown closer looks for, so
   the pointerdown that opens it is never swallowed. */
.tb-color-wrap {
  position: relative;
  display: inline-flex;
}

/* The B half takes what the A half's share leaves. */
.tb-color-wrap-b {
  flex: 1;
}

/* One bar half: a full-height button painted with the team colour (inline --sw).
   The rounding lives here, not on the bar — the pop-ups must escape it. */
.tb-bar-half {
  width: 100%;
  height: 100%;
  padding: 0 10px;
  overflow: hidden; /* the name ellipsizes; a lopsided share cannot crush it */
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: var(--sw, #808080);
  cursor: pointer;
}

/* Keep the raw 999px, never minus the ring width: squircle-fallback.js spots a
   pill by that value and measures the half-height per corner, which is what keeps
   these corners concentric with the bar's frame. */
.tb-color-wrap-a .tb-bar-half {
  border-radius: var(--radius-pill) 0 0 var(--radius-pill);
}

.tb-color-wrap-b .tb-bar-half {
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
}

/* Card face + heading ink and hairline: reads on all five team colours, both
   themes. */
.tb-bar-name {
  max-width: 100%;
  --ring-color: var(--color-heading);
  --ring-face: var(--color-card);
  color: var(--color-heading);
}

.tb-bar-name > .ring-face {
  display: block;
  max-width: 100%;
  padding: 1px var(--space-xs);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Swatch pop-up under a bar half. width: max-content keeps one row — the panel
   escapes its half, so shrink-to-fit would wrap it chip per line. The 8px padding
   swallows a selected chip's 4px outline; the 1px --color-muted edge keeps white
   and black visible. */
.tb-swatches {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 5;
  width: max-content;
  --ring-r: var(--radius-md);
  --ring-color: var(--color-border);
  --ring-face: var(--color-card);
}

.tb-swatches-face {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: var(--space-xs);
}

/* B's pop-up anchors right so it always opens inward */
.tb-color-wrap-b .tb-swatches {
  left: auto;
  right: 0;
}

/* Author display: flex would beat the UA [hidden] rule. */
.tb-swatches[hidden] {
  display: none;
}

.tb-swatch > .ring-face {
  display: block; /* the colour is the face; an empty inline span paints nothing */
  height: 100%;
}

.tb-swatch {
  min-width: 44px; /* the bar half's 44px touch floor */
  min-height: 44px;
  --ring-r: var(--radius-xs);
  --ring-color: var(--color-muted);
  --ring-face: var(--sw, #808080);
  cursor: pointer;
  transition: background-color 0.15s ease-out;
}

.tb-swatch:hover {
  --ring-color: var(--color-heading);
}

/* Selected: an offset ring, so selection is a shape and never colour alone
   (aria-pressed carries it to AT). The 4px extension fits the panel's 8px padding. */
.tb-swatch.is-on {
  outline: 2px solid var(--color-heading);
  outline-offset: 2px;
}

/* two-colour balance bar — also the colour selector

   Two clickable halves (shareA% from JS), name chip centred in each, midpoint
   tick. 44px tall: the touch floor. Each half carries its own rounding — the bar
   must not clip the pop-ups. */
/* 48, not 44: each half is a control, and the frame's 2px ring sits inside the
   box, so a 44 bar left the halves at 40 — under the floor. */
.tb-bar {
  position: relative;
  display: flex;
  height: 48px;
  margin-top: var(--space-sm);
  --ring-color: var(--color-heading);
  --ring-face: var(--surface-soft);
}

.tb-bar-face {
  display: flex;
  width: 100%;
}

/* Midpoint tick: heading core + card halo — one of the two always contrasts the
   team colour under it. */
.tb-bar-tick {
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 2px;
  transform: translateX(-50%);
  background: var(--color-heading);
  box-shadow: 0 0 0 1px var(--color-card);
}

.tb-level {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-top: 10px;
  color: var(--color-heading);
  text-wrap: balance;
}

.tb-level-dot {
  width: 8px;
  height: 8px;
  flex: none;
  --r: var(--radius-circle);
  border-radius: var(--radius-circle);
  background: var(--color-muted);
}

.tb-level.is-even .tb-level-dot,
.tb-level.is-fair .tb-level-dot {
  background: var(--tb-team-a);
}

.tb-level.is-uneven .tb-level-dot,
.tb-level.is-lopsided .tb-level-dot {
  background: var(--color-error-fg);
}

/* avatars

   --pitch is the class the JS emits for on-line avatars, --bench the squad card.
   One tap moves a player — no drag — and on a team line the tap is the swap badge,
   so that avatar is a decorative div (cursor: default below). */
.tb-pl {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2xs);
  min-width: 44px;
  min-height: 44px;
  padding: var(--space-2xs);
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: pan-y; /* no drag: taps fire, vertical page scroll still works */
}

/* decorative on a team line, so the pointer stops here; bench and squad-card
   avatars keep it. */
.tb-h2h-avs .tb-pl {
  cursor: default;
}

.tb-pl--bench {
  flex-direction: row;
  flex: none;
}

.tb-ava {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  /* No radius and no clip: the .tb-rate chip hangs off right/bottom: -5px and a
     clip would cut it. Face and rings are the pseudos below, each with its own --r
     marker, so they stay squircles without clipping the chip. */
  background: transparent;
  /* Fixed ink, never a theme token: the faces are hsl literals at one lightness
     in both themes, and white bottomed at 2.94:1 on the lightest hue — this ink
     reads 5.1–5.9:1 across every hue (measured, audit 2026-10-30). */
  color: #101312;
}

/* The face: the colour under the image (and behind the initials).
   Lightness is 30%, not the 44% a tint alone would suggest, because the
   initials sit on it at caption size: at 44% no single ink clears 4.5:1 for
   all 360 hues (dark ink bottoms at 3.43:1 on red, white at 2.8:1 on yellow).
   At 30% cream ink holds ≥5.5:1 on the brightest hue, so one rule serves the
   whole wheel and both themes. */
.tb-ava::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  --r: var(--radius-md);
  border-radius: var(--radius-md);
  background: hsl(var(--h, 0) 42% 30%);
}

/* Rings outside the face: a surface gap (2px), the team colour (2px), the
   --color-heading hairline (1px) that saves a white ring on a light card. Three
   layers clipped to border-box / padding-box / content-box: one squircle covers
   the stack. */
.tb-ava::after {
  content: "";
  position: absolute;
  inset: -5px;
  z-index: 0;
  --r: calc(var(--radius-md) + 5px);
  border: 1px solid transparent;
  padding: 2px;
  border-radius: calc(var(--radius-md) + 5px);
  background:
    linear-gradient(var(--ring-outer, var(--color-card)), var(--ring-outer, var(--color-card))) border-box,
    linear-gradient(var(--ring-team, var(--color-card)), var(--ring-team, var(--color-card))) padding-box,
    linear-gradient(var(--ring-gap, var(--color-card)), var(--ring-gap, var(--color-card))) content-box;
  pointer-events: none;
}

/* Image over the initials fallback. Empty alt: the context already names the
   player. */
.tb-ava-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 2;
  /* Replaced element: it paints its own corners, so it carries the radius and the
     fallback marker itself (the element has neither). */
  --r: var(--radius-md);
  border-radius: var(--radius-md);
  display: block;
}

.tb-ini {
  position: relative;
  z-index: 2;
  /* Fixed cream, never the theme ink: the face is dark in BOTH themes, so the
     initials must not flip with it (DESIGN.md → Typography). */
  color: #f7faf0;
}

.tb-rate {
  position: absolute;
  right: -5px;
  bottom: -5px;
  z-index: 3; /* above the ring and the face, so the overhang stays whole */
  --ring-color: rgba(247, 250, 240, 0.9);
  --ring-face: var(--color-heading);
  color: var(--color-on-accent);
  font-size: var(--fs-micro);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
}

.tb-rate > .ring-face {
  display: block;
  padding: 1px 5px;
}

/* gap = the surface the avatar sits on, team = its colour, outer = the hairline;
   bench rows are tinted, so their gap follows the card. */
.tb-pl--pitch.tb-on-a .tb-ava {
  --ring-team: var(--team-a-color, #d13b31);
  --ring-outer: var(--color-heading);
}

.tb-pl--pitch.tb-on-b .tb-ava {
  --ring-team: var(--team-b-color, #2563eb);
  --ring-outer: var(--color-heading);
}

.tb-pl--bench.tb-on-a .tb-ava {
  --ring-gap: var(--tb-card-bg, var(--color-bg));
  --ring-team: var(--team-a-color, #d13b31);
  --ring-outer: var(--color-heading);
}

.tb-pl--bench.tb-on-b .tb-ava {
  --ring-gap: var(--tb-card-bg, var(--color-bg));
  --ring-team: var(--team-b-color, #2563eb);
  --ring-outer: var(--color-heading);
}

/* actions */

.tb-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin-left: auto; /* right-align the row in .tb-balance-head */
  justify-content: flex-end; /* and keep it packed right when it wraps */
}

.tb-clear {
  color: var(--color-heading);
}

.tb-clear.is-armed {
  background: var(--color-error-bg);
  color: var(--color-error-fg);
}

.tb-note {
  margin: 0;
  color: var(--color-muted);
  text-wrap: pretty;
}

/* A grid child of .tb-actions-extra, so it stacks label + field at full width. */
.tb-fallback {
  width: 100%;
}

.tb-fallback:not([hidden]) {
  display: grid;
  gap: 6px;
}

.tb-fallback[hidden] {
  display: none;
}

/* squad panel */

.tb-squad {
  --ring-r: var(--radius-lg);
  --ring-color: var(--color-border);
  --ring-face: var(--color-card);
}

.tb-squad-face {
  padding: var(--space-md);
}

.tb-squad-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.tb-squad-head .tb-h {
  margin: 0;
}

/* First paint only: the demo-squad chip and the button that makes it the
   visitor's own. Typography comes from typography.css (`.t-chip`); this rule owns
   the pill's box and colour. */
.tb-example {
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-soft);
  color: var(--color-muted);
  white-space: nowrap;
}

.tb-start {
  min-height: 44px;
  --ring-color: var(--color-border-strong);
  --ring-face: var(--color-card);
  color: var(--color-heading);
  font: inherit;
  font-size: var(--fs-caption);
  font-weight: var(--fw-bold);
  cursor: pointer;
  transition: background-color 0.15s ease-out;
}

.tb-start > .ring-face {
  display: inline-flex;
  align-items: center;
  padding: var(--space-xs) 0.9rem;
}

.tb-start:hover {
  --ring-color: var(--color-heading);
}

.tb-add {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

/* 48 = 44 of input + the ring's 2px on each side, so the <input> itself (the
   control the audit measures) clears the floor. */
.tb-field {
  display: flex;
  min-height: 48px;
  --ring-r: var(--radius-sm);
  --ring-color: var(--color-border-strong);
  --ring-face: var(--color-bg);
}

.tb-field:has(.is-invalid) {
  --ring-color: var(--color-error-fg);
}

.tb-input {
  /* Face rule (DESIGN.md → Shapes · the ring surface): an <input> face drops its
     UA border, or a second, pinched frame draws inside the ring. */
  border: 0;
  appearance: none;
  width: 100%;
  min-height: 44px;
  box-sizing: border-box;
  padding: var(--space-xs) var(--space-sm);
  color: var(--color-heading);
  font: inherit;
  font-size: var(--fs-caption);
}

/* The ring wrapper is the flex child; .tb-add-name survives as the JS/focus hook */
.tb-field--name {
  flex: 1 1 8rem;
  min-width: 0;
}

.tb-field--rate {
  flex: 0 0 5.5rem;
}

/* Inline form error (role="alert"), same pairing as .tb-clear.is-armed:
   #991b1b on #fef2f2 (7.6:1) light, #fca5a5 on #2a1512 (9.1:1) dark. */
.tb-add-err {
  margin: var(--space-2xs) 0 var(--space-sm);
  --ring-r: var(--radius-xs);
  --ring-color: var(--color-error-fg);
  --ring-face: var(--color-error-bg);
  color: var(--color-error-fg);
  text-wrap: pretty;
}

.tb-add-err > .ring-face {
  display: block;
  padding: 6px 10px;
}

/* The .tb prefix is load-bearing: support.css `.doc-content ul` (0-1-1) sets margin
   + padding-left and would eat the column; min() lets the floor follow the
   viewport. */
.tb .tb-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(9rem, 100%), 1fr));
  gap: var(--space-xl);
  list-style: none;
  /* 23px of the remove badge's 44px hit area hangs past each card on both axes:
     this padding reserves it and the negative margin pulls the box back, so
     nothing is clipped — from 900px up the list IS a scroll container and would
     eat that corner. 4px right clears the scrollbar. */
  padding: var(--space-xl) var(--space-2xs) 0 var(--space-xl);
  margin: -24px 0 0 -24px;
}

/* Identity stack left, rating rail full height right, ✕ on the outer top-left
   corner. */
.tb-card {
  --tb-card-bg: var(--color-bg);
  /* The card is the relative box so the corner badge can hang past the frame; the
     grid lives on the face. */
  position: relative;
  display: flex;
  flex-direction: column;
  --ring-r: var(--radius-md);
  --ring-color: var(--color-border);
  --ring-face: var(--tb-card-bg);
}

.tb-card-face {
  flex: 1 1 auto; /* fill the card: the frame must never show at the bottom */
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: center;
  gap: 0 var(--space-2xs);
  padding: var(--space-2xs) var(--space-xs) var(--space-xs);
}

/* 15% tint, 30% border; the vars come from .tb-app (interactive-tool block) */
.tb-card.tb-card--on-a {
  --tb-card-bg: color-mix(in srgb, var(--team-a-color, #d13b31) 15%, var(--color-bg));
  --ring-color: color-mix(in srgb, var(--team-a-color, #d13b31) 30%, var(--color-border));
}

.tb-card.tb-card--on-b {
  --tb-card-bg: color-mix(in srgb, var(--team-b-color, #2563eb) 15%, var(--color-bg));
  --ring-color: color-mix(in srgb, var(--team-b-color, #2563eb) 30%, var(--color-border));
}

/* Dark surfaces sit closer together, so 15% over #101312 reads as a raised slab
   next to the #171b19 panel (worst case: the white swatch) — 10% keeps a tint. */
:root[data-theme="dark"] .tb-card.tb-card--on-a {
  --tb-card-bg: color-mix(in srgb, var(--team-a-color, #d13b31) 10%, var(--color-bg));
}

:root[data-theme="dark"] .tb-card.tb-card--on-b {
  --tb-card-bg: color-mix(in srgb, var(--team-b-color, #2563eb) 10%, var(--color-bg));
}

.tb-who   { grid-column: 1; }
/* The rail owns the whole right column, so it is exactly as tall as the card. */
.tb-scale { grid-column: 2; align-self: stretch; min-width: 0; }

/* Avatar, name chip and team chip, stacked and centred. */
.tb-who {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2xs);
}

/* Name chip inside .tb-who, aria-hidden in JS like .tb-h2h-pname; ellipsized. */
.tb-cname {
  min-width: 0;
  max-width: 100%;
  padding: 1px var(--space-xs);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  border-radius: var(--radius-pill);
  background: var(--surface-soft);
  color: var(--color-heading);
}

/* Team chip: a stronger mix of the card's own colour (30% vs 15% light, 20% vs 10%
   dark) so it sits ON the tint, closed by a team-tinted border for the near-card
   colours. The label stays --color-heading: a team-coloured label on its own
   pastel cannot hold AA on all five swatches. */.tb-ctag {
  min-width: 0;
  max-width: 100%;
  --ring-color: var(--tb-ctag-line, var(--color-border));
  --ring-face: var(--tb-ctag-bg, var(--surface-soft));
  color: var(--color-heading);
}

.tb-ctag > .ring-face {
  display: block;
  min-width: 0;
  max-width: 100%;
  padding: 1px var(--space-xs);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tb-ctag-a {
  --tb-ctag-bg: color-mix(in srgb, var(--team-a-color, #d13b31) 30%, var(--color-card));
  --tb-ctag-line: color-mix(in srgb, var(--team-a-color, #d13b31) 55%, var(--color-border));
}

.tb-ctag-b {
  --tb-ctag-bg: color-mix(in srgb, var(--team-b-color, #2563eb) 30%, var(--color-card));
  --tb-ctag-line: color-mix(in srgb, var(--team-b-color, #2563eb) 55%, var(--color-border));
}

:root[data-theme="dark"] .tb-ctag-a {
  --tb-ctag-bg: color-mix(in srgb, var(--team-a-color, #d13b31) 20%, var(--color-card));
}

:root[data-theme="dark"] .tb-ctag-b {
  --tb-ctag-bg: color-mix(in srgb, var(--team-b-color, #2563eb) 20%, var(--color-card));
}

/* Rating scale: a vertical rail of ticks with a real <input type="range"> laid
 * invisibly over it. Its thumb is 16px × --tb-scale-thumb-size, so the browser's
 * value mapping lands exactly under the drawn thumb, inset half a thumb at each
 * end; the grid stretches it over the whole card. */
.tb-scale {
  --tb-scale-inset: 14px;
  --tb-scale-thumb-size: 28px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 32px;
}

.tb-scale-rail {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  width: 100%;
}

/* One row of ticks, two states, zero JS per tick: the hard mask stop at --pos
 * leaves the passed ticks opaque and quiets the rest to 22%. */
.tb-scale-ticks {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: var(--tb-scale-inset) 0;
  -webkit-mask-image: linear-gradient(0deg, #000 var(--pos, 0), rgba(0, 0, 0, 0.22) var(--pos, 0));
  mask-image: linear-gradient(0deg, #000 var(--pos, 0), rgba(0, 0, 0, 0.22) var(--pos, 0));
}

.tb-scale-tick {
  width: 8px;
  height: 2px;
  border-radius: var(--radius-pill);
  background: currentColor;
}

/* Major ticks (0/25/50/75/100) are the quarter marks; both widths stay under the
 * thumb's 16px so the thumb always reads as on top. */
.tb-scale-tick.is-major {
  width: 14px;
}

.tb-scale-tick[data-band="red"] { color: var(--tb-rate-red); }
.tb-scale-tick[data-band="orange"] { color: var(--tb-rate-orange); }
.tb-scale-tick[data-band="green"] { color: var(--tb-rate-green); }
.tb-scale-tick[data-band="gold"] { color: var(--tb-rate-gold); }

.tb-scale-rail[data-band="red"] { --tb-rate-band: var(--tb-rate-red); }
.tb-scale-rail[data-band="orange"] { --tb-rate-band: var(--tb-rate-orange); }
.tb-scale-rail[data-band="green"] { --tb-rate-band: var(--tb-rate-green); }
.tb-scale-rail[data-band="gold"] { --tb-rate-band: var(--tb-rate-gold); }

.tb-scale-thumb > .ring-face {
  display: block;
  height: 100%;
}

.tb-scale-thumb {
  position: absolute;
  top: calc(100% - var(--pos, 0));
  left: 50%;
  width: 16px;
  height: var(--tb-scale-thumb-size);
  transform: translate(-50%, -50%);
  --ring-r: var(--radius-pill);
  --ring-color: var(--tb-rate-band, var(--color-heading));
  --ring-face: var(--color-card);
  /* left, not transform: this position is one calc string shared with the tick
     mask and the range input's mapping (team-balancer.js), so the travel has to
     stay on left until that calc is reworked. Tokens in place; the transform
     path is tracked as audit 2026-10-30 §3.5 pending. */
  transition: left var(--dur-fast) var(--ease-out);
  pointer-events: none;
}

.tb-scale-in {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 100%;
  margin: 0;
  transform: translate(-50%, -50%);
  writing-mode: vertical-lr;
  direction: rtl;
  appearance: none;
  background: transparent;
  opacity: 0;
  cursor: pointer;
}

.tb-scale-in::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: var(--tb-scale-thumb-size);
  border: 0;
  background: transparent;
}

.tb-scale-in::-moz-range-thumb {
  width: 16px;
  height: var(--tb-scale-thumb-size);
  border: 0;
  background: transparent;
}

/* opacity: 0 hides the input's own outline, so the rail carries the ring. */
.tb-scale-rail:has(.tb-scale-in:focus-visible) {
  outline: var(--focus-w) solid var(--focus-color);
  outline-offset: 2px;
}

.tb-scale-rail:focus-within {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

/* Compact badge, 44px target from the pseudo-element; the list above reserves the
   overhang. */
.tb-rm {
  position: absolute;
  top: -1px;
  left: -1px;
  z-index: 2; /* above the rail's invisible range input */
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  transform: translate(-50%, -50%);
  --ring-color: var(--color-muted);
  --ring-face: var(--color-card);
  color: var(--color-muted);
  font-size: var(--fs-label);
  line-height: var(--lh-tight);
  cursor: pointer;
  transition: color 0.15s ease-out, background-color 0.15s ease-out,
    border-color 0.15s ease-out;
}

.tb-rm:focus-visible {
  color: var(--color-error-fg);
  --ring-color: var(--color-error-fg);
  --ring-face: var(--color-error-bg);
}

.tb-rm::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
}

/* reicon trash3 glyph mounted by team-balancer.js: `color` drives it
   (fill="currentColor"), so it follows the badge's muted / hover / focus / error
   ramp; without the module the ✕ text node stays and takes its font-size. */
.tb-rm .tb-rm-ico {
  display: block;
  width: 16px;
  height: 16px;
  pointer-events: none;
}

@media (hover: hover) {
  .tb-rm:hover {
    color: var(--color-error-fg);
    border-color: var(--color-error-fg);
    background: var(--color-error-bg);
  }
}

/* --- feedback --- */

.tb-toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  z-index: 950;
  max-width: calc(100% - 2rem);
  padding: 0.6rem var(--space-md);
  --r: var(--radius-md);
  border-radius: var(--radius-md);
  background: var(--color-heading);
  color: var(--color-on-accent);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 0.15s ease-out;
}

.tb-toast.is-show {
  opacity: 1;
}

/* focus + motion */

.tb button:focus-visible,
.tb a:focus-visible,
.tb input:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .tb *,
  .tb-toast {
    transition: none !important;
  }
}
