/*
 * The bet builder (BetBuilder.js): a bottom sheet over the fixture page
 * holding every line the feed priced, the model's picks, and the legs the
 * reader is building.
 *
 * The shell is the filter sheet's — scrim, rounded panel on --rest-y /
 * --drag-y, the same dragging states — and the footer is pinned under a
 * scrolling body so the legs and Enter never leave the thumb. The picks and
 * the legs are the filter sheet's `.filter-chip`; the market cards are the
 * Statistics tab's `.stat-card`; the scope switch is `Segmented`. What is new
 * is the rung — a line, its split bar, and an Over and an Under cell.
 */

.bet-builder {
  --rest-y: 100%;
  --slip-scale: 1;

  position: fixed;
  inset: 0;
  /* The band the filter sheet and the slip sheets occupy, above the fixture
     page it opens from and below search and stories. */
  z-index: 96;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  max-width: var(--app-max-width);
  margin-inline: auto;
}

.bet-builder[hidden] {
  display: none;
}

.bet-builder__scrim {
  position: absolute;
  inset: 0;
  background: var(--text);
  opacity: 0;
  transition: opacity var(--duration) var(--easing);
  transition-delay: var(--stagger-step);
}

.bet-builder[data-open="true"] .bet-builder__scrim {
  opacity: 0.4;
  transition-delay: 0ms;
}

.bet-builder__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: min(88dvh, 760px);
  background: var(--surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-floating);
  transform: translateY(calc(var(--rest-y) + var(--drag-y, 0px)));
  transition: transform var(--exit-duration, var(--duration)) var(--easing);
}

.bet-builder[data-open="true"] .bet-builder__panel {
  --rest-y: 0%;

  transition: transform var(--spring-duration) var(--spring) var(--stagger-step);
}

.bet-builder[data-dragging="true"] .bet-builder__panel {
  transition: none;
}

.bet-builder[data-dragging="released"] .bet-builder__panel {
  transition: transform var(--spring-duration) var(--spring);
}

/* --- Head ------------------------------------------------------------------------ */

.bet-builder__grabber {
  display: grid;
  place-items: center;
  padding: var(--space-2) 0 var(--space-1);
  cursor: grab;
  touch-action: none;
}

.bet-builder__bar {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-full);
}

.bet-builder__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-3) var(--space-3) var(--space-5);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.bet-builder__heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.bet-builder__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
}

.bet-builder__subtitle {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

/* --- Body --------------------------------------------------------------------------- */

.bet-builder__body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 0;
  padding: 0 var(--space-4) var(--space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.bb-note {
  padding: var(--space-2) var(--space-3);
  background: var(--warning-soft);
  border-radius: var(--radius-md);
  color: var(--warning-strong);
  font-size: var(--text-xs);
  line-height: 1.45;
}

.bb-picks {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.bb-picks__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.bb-picks__all {
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

/* --- Market ----------------------------------------------------------------------------- */

.bb-market {
  gap: var(--space-3);
}

.bb-market__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

/* "Total goals · Over / Under": the name, a dot, the shape of the market. */
.bb-market__title {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
}

.bb-market__unit {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
}

.bb-market__dot {
  width: 6px;
  height: 6px;
  background: var(--border-strong);
  border-radius: 2px;
}

/* The scout glyph: the model calls a line in this market. */
.bb-market__scout {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  background: var(--surface-sunken);
  border-radius: var(--radius-full);
  color: var(--text);
}

.bb-market__scopes .segmented {
  width: 100%;
}

/* The three columns' names over the rows, in the rows' own grid. */
.bb-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-align: center;
}

.bb-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* A rung: the line in its own tile, then Over and Under. */
.bb-row,
.bb-trio {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.bb-value {
  display: grid;
  place-items: center;
  min-height: 64px;
  background: var(--surface-sunken);
  border-radius: var(--radius-md);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/*
 * A tile: the percent, big, over a thin bar. The bar takes the accent on the
 * side that leads and the mid grey on the side that trails, so a rung reads
 * as one comparison; the tile itself takes the accent fill once chosen, and
 * everything in it goes white. The model's call sits as the scout glyph in
 * the corner; a settled goals line wears the success ground or the disabled
 * tone with its mark.
 */
.bb-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 64px;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-sunken);
  border-radius: var(--radius-md);
  color: var(--text);
  transition:
    background-color var(--duration) var(--easing),
    color var(--duration) var(--easing);
}

.bb-tile__label {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.bb-tile__value {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}

.bb-tile__bar {
  display: block;
  width: 100%;
  height: 4px;
  background: var(--surface-pressed);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.bb-tile__fill {
  display: block;
  width: var(--share);
  height: 100%;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  transition: width var(--spring-duration) var(--easing);
}

.bb-tile[data-lead="true"] .bb-tile__fill {
  background: var(--accent);
}

.bb-tile[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

.bb-tile[aria-pressed="true"] .bb-tile__label {
  color: rgb(var(--text-inverse-rgb) / 0.8);
}

.bb-tile[aria-pressed="true"] .bb-tile__bar {
  background: rgb(var(--text-inverse-rgb) / 0.25);
}

.bb-tile[aria-pressed="true"] .bb-tile__fill {
  background: var(--accent-text);
}

.bb-tile__pick {
  position: absolute;
  top: 6px;
  right: 6px;
  color: var(--accent);
}

.bb-tile[aria-pressed="true"] .bb-tile__pick {
  color: var(--accent-text);
}

.bb-tile[data-outcome="won"] {
  background: var(--success-soft);
  color: var(--success-strong);
}

.bb-tile[data-outcome="won"] .bb-tile__fill {
  background: var(--success);
}

.bb-tile[data-outcome="lost"] {
  color: var(--text-disabled);
}

.bb-tile[data-outcome="lost"] .bb-tile__fill {
  background: var(--border);
}

.bb-tile__outcome {
  position: absolute;
  top: 6px;
  left: 6px;
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  background: var(--success);
  border-radius: var(--radius-full);
  color: var(--accent-text);
}

.bb-tile[data-outcome="lost"] .bb-tile__outcome {
  background: var(--text-disabled);
}

.bb-tile[aria-disabled="true"]:not([data-outcome="won"]):not([data-outcome="lost"]) {
  opacity: 0.7;
}

/*
 * The dashed row under a market with something chosen in it. The one place
 * the error band appears on the sheet, because taking a leg back out is
 * the one destructive act on it.
 */
.bb-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  border: 1px dashed var(--error);
  border-radius: var(--radius-md);
  color: var(--error-strong);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

.bb-remove[hidden] {
  display: none;
}

.bb-remove__mark {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  background: var(--error-soft);
  border-radius: var(--radius-full);
  color: var(--error-strong);
}

/* --- Footer --------------------------------------------------------------------------------- */

.bet-builder__footer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4) calc(var(--space-4) + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.bet-builder__summary {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.bet-builder__count {
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

.bet-builder__legs {
  display: flex;
  gap: var(--space-2);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.bet-builder__legs::-webkit-scrollbar {
  display: none;
}

.bet-builder__legs:empty {
  display: none;
}

.bet-builder__leg {
  flex: none;
}

/* A leg already entered wears the tint rather than the fill, so what is new
   in the set reads at a glance. */
.bet-builder__leg[data-entered="true"] {
  background: var(--accent-tint);
  color: var(--accent);
}

.bet-builder__enter {
  width: 100%;
  height: 48px;
  justify-content: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  transition:
    background-color var(--duration) var(--easing),
    color var(--duration) var(--easing),
    box-shadow var(--duration) var(--easing);
}

.bet-builder__enter .slip-ind {
  display: none;
}

.bet-builder__enter[aria-pressed="true"] {
  background: var(--accent-tint);
  box-shadow: none;
  color: var(--accent);
}

.bet-builder__enter[aria-pressed="true"] .slip-ind {
  display: block;
}

.bet-builder__enter[aria-disabled="true"][aria-pressed="false"] {
  background: var(--surface-pressed);
  box-shadow: none;
  color: var(--text-muted);
}
