/*
 * The slip tray (SlipTray.js): the reader's own slip while it is being
 * built — a pill docked above the bottom nav, and the sheet it opens.
 *
 * One fixed root, sized to the shell, that passes every tap through except
 * on the pill and the sheet. It sits at the player page's level and later
 * in the document, so it floats over the two screens picks are collected
 * from and under search, the stories, onboarding and the gate — the pill is a
 * tool of browsing, not of any one screen — a circle in the nav's own row
 * on the fixtures tab, a pill on the fixture page, one box morphing between
 * the two, hidden everywhere else. The sheet is the slip results
 * screen's bookie picker chrome (scrim, stack layer, tall panel, circular X
 * and a title pill) with a pinned footer under a scrolling body.
 */

.slip-tray {
  --slip-scale: 1;

  position: fixed;
  inset: 0;
  z-index: 98;
  max-width: var(--app-max-width);
  margin-inline: auto;
  pointer-events: none;
}

/* --- The pill ------------------------------------------------------------------------- */

/*
 * One box, placed outright: SlipTray.js measures the nav's slip seat and
 * writes --x / --y / --w / --h for wherever the placement says the control
 * goes — over the seat as a circle on the fixtures tab, centred at the
 * seat's height as a pill on the fixture page — and the four transition, so
 * a change of placement is the box travelling and stretching between the
 * two. Stadium-round throughout, so a circle is only the pill at its
 * shortest.
 */
.slip-tray__dock {
  position: absolute;
  top: var(--y, 0px);
  left: var(--x, 0px);
  width: var(--w, var(--nav-height));
  height: var(--h, var(--nav-height));
  opacity: 0;
  transform: scale(0.9);
  transition:
    top var(--spring-duration) var(--spring),
    left var(--spring-duration) var(--spring),
    width var(--spring-duration) var(--spring),
    height var(--spring-duration) var(--spring),
    transform var(--spring-duration) var(--spring),
    opacity var(--duration) var(--easing);
}

.slip-tray[data-shown="true"] .slip-tray__dock:not([data-placement="hidden"]) {
  opacity: 1;
  transform: scale(1);
}

/* The nav's scroll-away, mirrored — the same travel the row makes. */
.slip-tray[data-shown="true"] .slip-tray__dock[data-placement="list"][data-retracted="true"] {
  opacity: 0;
  transform: translateY(calc(100% + var(--space-6))) scale(0.94);
  pointer-events: none;
}

/*
 * The nav's own frosted chrome (bottom-nav.css): surface, hairline, floating
 * shadow, and the blur only once the box has settled — compositing a live
 * backdrop against a moving element is what stutters in Telegram's WebView.
 */
.slip-tray__pill {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  height: 100%;
  padding-inline: var(--space-3);
  background: var(--tg-surface);
  border: 1px solid var(--tg-border);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-floating);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
  overflow: hidden;
  pointer-events: auto;
}

@supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
  .slip-tray__pill {
    background: rgb(var(--tg-surface-rgb) / 0.72);
  }

  .slip-tray__dock--blurred .slip-tray__pill {
    -webkit-backdrop-filter: blur(18px) saturate(180%);
    backdrop-filter: blur(18px) saturate(180%);
  }
}

/* The measuring twin: laid out at its natural width, seen by nobody. */
.slip-tray__pill--ghost {
  position: absolute;
  top: 0;
  left: 0;
  width: auto;
  height: var(--nav-height);
  visibility: hidden;
  pointer-events: none;
}

.slip-tray[data-shown="false"] .slip-tray__pill,
.slip-tray__dock[data-placement="hidden"] .slip-tray__pill {
  pointer-events: none;
}

.slip-tray__pill[data-anim="bump"] {
  animation: slip-tray-bump 260ms var(--spring);
}

@keyframes slip-tray-bump {
  0% {
    transform: scale(calc(1 * var(--press, 1)));
  }
  40% {
    transform: scale(calc(1.06 * var(--press, 1)));
  }
  100% {
    transform: scale(calc(1 * var(--press, 1)));
  }
}

/* As a circle the icon sits centred; the words are folded away. */
.slip-tray__dock:not([data-placement="detail"]) .slip-tray__pill {
  justify-content: center;
  padding-inline: 0;
}

/* The nav's own icon box, so the badge (`.nav-item__badge`, bottom-nav.css)
   lands on the same corner it does on Catch-Up. */
.slip-tray__glyph {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: var(--text);
}

/*
 * The words: present in the pill, folded to nothing in the circle. Width
 * and opacity go together so the box shrinks around what is left rather
 * than clipping the label mid-word.
 */
.slip-tray__label,
.slip-tray__chevron {
  max-width: 120px;
  opacity: 1;
  overflow: hidden;
  transition:
    max-width var(--spring-duration) var(--spring),
    opacity var(--duration) var(--easing);
}

.slip-tray__chevron {
  display: grid;
  place-items: center;
  color: var(--text-muted);
  transform: rotate(180deg);
}

.slip-tray__dock:not([data-placement="detail"]) .slip-tray__label,
.slip-tray__dock:not([data-placement="detail"]) .slip-tray__chevron {
  max-width: 0;
  opacity: 0;
  margin-left: calc(var(--space-2) * -1);
}

/* The tray's toasts — a pick replaced, a full slip — stack over the pill,
   inside this fixed root so they float over whatever page is open. */
.slip-tray .slip-toasts {
  position: absolute;
  bottom: calc(var(--space-5) + max(var(--safe-bottom), var(--tg-chrome-inset, 0px)) + var(--nav-height) + var(--space-3));
  z-index: 1;
}


/* --- The sheet ------------------------------------------------------------------------- */

/*
 * The slip results screen's bookie picker chrome, restated (`.sr-platforms`
 * in slip-results.css — itself the Advanced Markets / Code Converter
 * sheet): a darker scrim, the stack layer peeking above the panel, a tall
 * panel with a large top radius, and a head with a circular X on the left
 * and the title as a pill in the centre. Its sizes are in that screen's
 * frame, so the sheet takes its scale to come out the same size.
 */
.slip-tray__sheet {
  --slip-scale: 0.75;
  --st-enter: var(--spring-duration);
  --st-exit: 320ms;
  --st-lag: 40ms;

  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  pointer-events: auto;
}

.slip-tray__sheet[hidden] {
  display: none;
}

.slip-tray__scrim {
  position: absolute;
  inset: 0;
  background: var(--text);
  opacity: 0;
  transition: opacity var(--sd-fade) var(--se-out);
}

.slip-tray__sheet[data-open="true"] .slip-tray__scrim {
  opacity: 0.55;
}

.slip-tray__stack {
  position: absolute;
  right: calc(16px * var(--slip-scale));
  bottom: 0;
  left: calc(16px * var(--slip-scale));
  height: calc(84dvh + 12px * var(--slip-scale));
  border-radius: calc(24px * var(--slip-scale)) calc(24px * var(--slip-scale)) 0 0;
  background: var(--slip-stack);
  transform: translateY(var(--rest-y, 100%));
  transition: transform var(--st-exit) var(--se-out);
}

.slip-tray__sheet[data-open="true"] .slip-tray__stack {
  --rest-y: 0px;

  transition: transform var(--st-enter) var(--spring) var(--st-lag);
}

.slip-tray__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 84dvh;
  background: var(--surface);
  border-radius: calc(28px * var(--slip-scale)) calc(28px * var(--slip-scale)) 0 0;
  overflow: hidden;
  transform: translateY(var(--rest-y, 100%));
  transition: transform var(--st-exit) var(--se-out);
}

.slip-tray__sheet[data-open="true"] .slip-tray__panel {
  --rest-y: 0px;

  transition: transform var(--st-enter) var(--spring);
}

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

.slip-tray__head {
  flex: none;
  display: flex;
  align-items: center;
  height: calc(80px * var(--slip-scale));
  padding: 0 calc(20px * var(--slip-scale));
  border-bottom: 1px solid var(--border);
}

/* 56pt visual, 44pt hit whatever the scale — the picker's close. */
.slip-tray__close {
  --press-scale: 0.94;

  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: calc(56px * var(--slip-scale));
  height: calc(56px * var(--slip-scale));
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.slip-tray__close::before {
  content: "";
  position: absolute;
  inset: min(0px, calc((56px * var(--slip-scale) - 44px) / 2));
  border-radius: inherit;
}

.slip-tray__close[data-pressed="true"] {
  box-shadow: inset 0 0 0 999px rgb(var(--text-rgb) / 0.04);
}

.slip-tray__title {
  flex: none;
  display: inline-flex;
  align-items: center;
  height: calc(48px * var(--slip-scale));
  margin-inline: auto;
  padding: 0 calc(22px * var(--slip-scale));
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text);
  font-size: calc(16px * var(--slip-scale));
  font-weight: var(--weight-bold);
  white-space: nowrap;
}

/* Balances the close button so the title pill sits centred. */
.slip-tray__spacer {
  flex: none;
  width: calc(56px * var(--slip-scale));
}

/* The count and the rules on the left, Clear on the right — the body's first row. */
.slip-tray__meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: calc(36px * var(--slip-scale));
}

.slip-tray__subtitle {
  color: var(--text-muted);
  font-size: calc(var(--text-sm) * var(--slip-scale));
  font-weight: var(--weight-medium);
}

.slip-tray__clear {
  height: calc(36px * var(--slip-scale));
  padding-inline: calc(14px * var(--slip-scale));
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  font-size: calc(var(--text-sm) * var(--slip-scale));
  font-weight: var(--weight-semibold);
}

.slip-tray__clear[hidden] {
  display: none;
}

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

.slip-tray__body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: calc(12px * var(--slip-scale));
  min-height: 0;
  padding: calc(16px * var(--slip-scale)) calc(20px * var(--slip-scale)) calc(24px * var(--slip-scale));
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.slip-tray__full {
  display: flex;
  align-items: center;
  gap: calc(8px * var(--slip-scale));
  padding: calc(10px * var(--slip-scale)) calc(14px * var(--slip-scale));
  background: var(--warning-soft);
  border-radius: var(--radius-md);
  color: var(--warning-strong);
  font-size: calc(var(--text-sm) * var(--slip-scale));
  line-height: 1.45;
}

.slip-tray__full[hidden],
.slip-tray__empty[hidden] {
  display: none;
}

.slip-tray__empty {
  padding: calc(40px * var(--slip-scale)) calc(16px * var(--slip-scale));
  color: var(--text-muted);
  font-size: calc(var(--text-md) * var(--slip-scale));
  text-align: center;
}

.slip-tray__list {
  display: flex;
  flex-direction: column;
  gap: calc(10px * var(--slip-scale));
}

/* One pick: the crests, the words, the remove — the picker's row, with the
   crests where its logo disc sits. Enters and leaves through the keyed
   states, so a removed row folds away rather than vanishing. */
.slip-tray__row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: calc(14px * var(--slip-scale));
  padding: calc(14px * var(--slip-scale)) calc(16px * var(--slip-scale));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(20px * var(--slip-scale));
  transition:
    opacity var(--duration) var(--easing),
    transform var(--duration) var(--easing);
}

.slip-tray__row[data-state="enter"] {
  opacity: 0;
  transform: translateY(6px);
  transition-delay: calc(var(--i, 0) * var(--stagger-step));
}

.slip-tray__row[data-state="leave"] {
  opacity: 0;
  transform: translateX(-8px);
}

.slip-tray__crests {
  display: flex;
  align-items: center;
}

.slip-tray__crests .logo + .logo {
  margin-left: calc(-8px * var(--slip-scale));
}

.slip-tray__text {
  display: flex;
  flex-direction: column;
  gap: calc(4px * var(--slip-scale));
  min-width: 0;
}

.slip-tray__fixture {
  overflow: hidden;
  color: var(--text-secondary);
  font-size: calc(var(--text-xs) * var(--slip-scale));
  font-weight: var(--weight-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slip-tray__pick {
  font-size: calc(var(--text-md) * var(--slip-scale));
  font-weight: var(--weight-bold);
  line-height: 1.3;
}

.slip-tray__market {
  color: var(--text-secondary);
  font-weight: var(--weight-medium);
}

.slip-tray__meta {
  display: flex;
  align-items: center;
  gap: calc(8px * var(--slip-scale));
  margin-top: calc(2px * var(--slip-scale));
}

.slip-tray__when {
  color: var(--text-muted);
  font-size: calc(var(--text-xs) * var(--slip-scale));
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* The remove: the close button's ring, smaller, the error tone on press. */
.slip-tray__remove {
  --press-scale: 0.94;

  display: grid;
  place-items: center;
  width: calc(44px * var(--slip-scale));
  height: calc(44px * var(--slip-scale));
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition:
    color var(--duration) var(--easing),
    background-color var(--duration) var(--easing),
    border-color var(--duration) var(--easing);
}

.slip-tray__remove[data-pressed="true"] {
  background: var(--error-soft);
  border-color: transparent;
  color: var(--error-strong);
}

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

.slip-tray__footer {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: calc(8px * var(--slip-scale));
  padding: calc(12px * var(--slip-scale)) calc(20px * var(--slip-scale)) calc(24px * var(--slip-scale) + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* The results screen's Generate pill, restated: the one action, full width. */
.slip-tray__book {
  width: 100%;
  height: calc(60px * var(--slip-scale));
  justify-content: center;
  gap: calc(10px * var(--slip-scale));
  border-radius: var(--radius-full);
  font-size: calc(16px * var(--slip-scale));
}

.slip-tray__book:disabled {
  opacity: 0.55;
}

.slip-tray__book[data-busy="true"]:disabled {
  opacity: 1;
}

.slip-tray__book-glyph,
.slip-tray__spinner {
  display: grid;
  place-items: center;
}

.slip-tray__spinner {
  display: none;
  width: calc(16px * var(--slip-scale));
  height: calc(16px * var(--slip-scale));
  border: 2px solid rgb(var(--text-inverse-rgb) / 0.35);
  border-top-color: var(--text-inverse);
  border-radius: var(--radius-full);
  animation: ci-spin 700ms linear infinite;
}

.slip-tray__book[data-busy="true"] .slip-tray__spinner {
  display: block;
}

.slip-tray__book[data-busy="true"] .slip-tray__book-glyph {
  display: none;
}

.slip-tray__hint {
  color: var(--text-muted);
  font-size: calc(var(--text-xs) * var(--slip-scale));
  line-height: 1.45;
  text-align: center;
}

/* The Predictions tab's confidence pill, brought into this frame. */
.slip-tray .pred-confidence {
  padding: calc(3px * var(--slip-scale)) calc(8px * var(--slip-scale));
  font-size: calc(var(--text-xs) * var(--slip-scale));
}
