/*
 * The Slip Splitter (SlipSplitter.js) — one slip broken into several, over the
 * SureTOOLS tab.
 *
 * The shell is the Odds Converter's, which is the Lineup Builder's, which is
 * the player page's: a fixed page that fades while its sheet rises, at
 * z-index 70. Restated here for the reason odds-converter.css gives; there are
 * four copies of it now and they want one `.tool-page` between them.
 *
 * The code field, the platform button and the platform sheet are the shared
 * parts in code-input.css, so this tool's field is literally the Merger's.
 * What is here is what splitting adds: the part-count tiles, and the part cards.
 *
 * Separation is tonal, as everywhere in this corner of the app: white cards on
 * the off-white page, the sunken grey inside them, nothing casts a shadow.
 */

/* --- Shell -------------------------------------------------------------------- */

.slip-splitter {
  --enter-y: 12px;
  --ss-gutter: var(--space-4);

  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  max-width: var(--app-max-width);
  margin-inline: auto;
  background: var(--bg);
  opacity: 0;
  transition: opacity var(--duration) var(--easing);
}

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

.slip-splitter [hidden] {
  display: none !important;
}

.slip-splitter[data-open="true"] {
  --enter-y: 0px;

  opacity: 1;
}

.slip-splitter__sheet {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-top: var(--safe-top);
  transform: translateY(var(--enter-y));
  transition: transform var(--duration) var(--easing);
}

.slip-splitter__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

.ss {
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--space-8) + var(--safe-bottom));
}

.ss-view {
  display: flex;
  flex-direction: column;
}

/* --- Top row and title ----------------------------------------------------------- */

.ss-top {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-3) 0;
}

.ss-top__gap {
  flex: 1;
}

.ss-title {
  margin: var(--space-3) var(--ss-gutter) 0;
  color: var(--text);
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

/* --- Sections ---------------------------------------------------------------------- */

.ss-section {
  display: flex;
  flex-direction: column;
}

.ss-label {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin: var(--space-5) var(--ss-gutter) var(--space-3);
  color: var(--text);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
}

.ss-label__meta {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

.ss-note {
  margin: var(--space-2) var(--ss-gutter) 0;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.4;
}

.ss-card {
  margin: 0 var(--ss-gutter);
  padding: var(--space-3);
  border-radius: var(--radius-xl);
  background: var(--surface);
}

/* The platform button fills its card: there is one selector on this screen and
   nothing to line it up against. */
.ss-card--platform .ci-platform-btn {
  width: 100%;
}

.ss-card--platform .ci-platform-btn__name {
  flex: 1;
  font-size: var(--text-md);
}

/* --- The part-count tiles ------------------------------------------------------------ */

/*
 * Four big squares rather than a stepper. The whole range is four numbers, and
 * which of them this slip can actually take is half the information — a tile
 * that has gone dark has explained itself, where a stepper that refuses to
 * climb has not.
 */
.ss-tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-2);
  margin: 0 var(--ss-gutter);
}

.ss-tile {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: inset 0 0 0 1.5px var(--border);
  color: var(--text);
  overflow: hidden;
  transition:
    background-color var(--sd-fade) var(--se-out),
    box-shadow var(--sd-fade) var(--se-out),
    color var(--sd-fade) var(--se-out),
    transform var(--spring-duration) var(--spring);
}

.ss-tile__num {
  position: relative;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.ss-tile[aria-checked="true"] {
  background: var(--accent);
  box-shadow: none;
  color: var(--accent-text);
}

/*
 * The curved-line watermark inside a chosen tile: two soft arcs of the accent
 * lightened, drawn with repeating conic stops rather than an asset. Decoration,
 * and behind the numeral, so it can never cost legibility.
 */
.ss-tile[aria-checked="true"]::before {
  content: "";
  position: absolute;
  inset: -40% -30% auto -30%;
  aspect-ratio: 1;
  border-radius: var(--radius-full);
  box-shadow:
    inset 0 0 0 8px rgb(var(--text-inverse-rgb) / 0.09),
    inset 0 0 0 22px rgb(var(--text-inverse-rgb) / 0.06);
}

.ss-tile:disabled {
  background: var(--surface-sunken);
  box-shadow: none;
  color: var(--text-disabled);
  cursor: default;
}

/* --- The CTA ---------------------------------------------------------------------------- */

.ss-cta__wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: var(--space-6) var(--ss-gutter) 0;
}

.ss-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 54px;
  border-radius: var(--radius-lg);
  background: var(--accent);
  color: var(--accent-text);
  font-size: var(--text-base);
  font-weight: var(--weight-bold);
  transition:
    background-color var(--sd-fade) var(--se-out),
    color var(--sd-fade) var(--se-out),
    transform var(--spring-duration) var(--spring);
}

.ss-cta[data-pressed="true"] {
  background: var(--accent-pressed);
}

/* Grey until a code has actually come back. A CTA that looks alive before it
   can do anything is a promise the screen cannot keep. */
.ss-cta:disabled {
  background: var(--surface-sunken);
  color: var(--text-disabled);
}

.ss-cta__hint {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-align: center;
}

.ss-clear {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  align-self: center;
  min-height: 44px;
  margin-top: var(--space-5);
  padding: 0 var(--space-4);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  transition: transform var(--spring-duration) var(--spring);
}

.ss-clear[data-pressed="true"] {
  background: var(--surface-sunken);
}

/* --- The source, on the result --------------------------------------------------------------- */

/* What the parts came out of, kept at the top of the result: a screen full of
   new slips has to say which slip they were. */
.ss-source {
  margin: var(--space-4) var(--ss-gutter) 0;
  padding: var(--space-3) var(--space-4) var(--space-4);
  border-radius: var(--radius-xl);
  background: var(--surface);
}

.ss-source__row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.ss-source__text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.ss-source__label {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: var(--weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ss-source__code {
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ss-source__meta {
  flex: none;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

/* The invariant, printed. The parts are the slip you started with, and a tool
   that rearranges somebody's position owes them that in writing. */
.ss-recombined {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border);
  color: var(--success-strong);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.4;
}

/* --- Strategy ------------------------------------------------------------------------------- */

.ss-strategies {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
  margin: 0 var(--ss-gutter);
}

.ss-strategy {
  height: 42px;
  padding: 0 var(--space-1);
  border-radius: 13px;
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition:
    background-color var(--sd-fade) var(--se-out),
    color var(--sd-fade) var(--se-out),
    transform var(--spring-duration) var(--spring);
}

.ss-strategy[aria-checked="true"] {
  background: var(--accent-tint);
  color: var(--accent);
}

/* --- The parts ---------------------------------------------------------------------------------- */

.ss-parts {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: 0 var(--ss-gutter);
}

.ss-part {
  padding: var(--space-3) var(--space-4) var(--space-4);
  border-radius: var(--radius-xl);
  background: var(--surface);
}

.ss-part__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-bottom: var(--space-2);
}

.ss-part__letter {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--accent-tint);
  color: var(--accent);
  font-size: var(--text-md);
  font-weight: 800;
  line-height: 1;
}

.ss-part__text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.ss-part__title {
  color: var(--text);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
}

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

.ss-part__odds {
  flex: none;
  color: var(--text);
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.ss-legs {
  display: flex;
  flex-direction: column;
  list-style: none;
}

.ss-leg {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}

.ss-leg__text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ss-leg__match {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
}

.ss-leg__teams {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ss-leg__when {
  flex: none;
  color: var(--text-disabled);
  font-variant-numeric: tabular-nums;
}

.ss-leg__sel {
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: 1.25;
}

.ss-leg__odds {
  flex: none;
  color: var(--text);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

/* A part of one is a single, and saying so beats letting the punter work out
   why this card has one line on it. */
.ss-part__single {
  padding-top: var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.ss-part__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
}

.ss-part__eyebrow {
  color: var(--text-muted);
  font-size: var(--text-2xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ss-part__code {
  color: var(--text);
  font-size: var(--text-lg);
  font-weight: 800;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}

.ss-part__actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.ss-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  transition:
    background-color var(--sd-fade) var(--se-out),
    transform var(--spring-duration) var(--spring);
}

.ss-action[data-pressed="true"] {
  background: var(--surface-pressed);
}

/* Share is the one thing on this page that leaves it. */
.ss-action--share {
  background: var(--accent);
  color: var(--accent-text);
}

.ss-action--share[data-pressed="true"] {
  background: var(--accent-pressed);
}

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

/* The Slip Builder's sheet at this page's full size, not its 0.75 — the same
   three overrides every tool page makes. */
.slip-splitter .slip-sheet__panel {
  max-height: min(84dvh, 760px);
}

.slip-splitter .slip-sheet__title {
  padding: var(--space-1) var(--space-4) var(--space-3);
  font-size: var(--text-lg);
}

.slip-splitter .slip-sheet__body {
  padding: 0 var(--space-4) var(--space-4);
}

.ss-about {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.ss-about__row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ss-about__term {
  color: var(--text);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
}

.ss-about__text {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1.45;
}

/* --- Short screens --------------------------------------------------------------------------------- */

@media (max-height: 700px) {
  .ss-title {
    font-size: var(--text-xl);
  }

  .ss-tile__num {
    font-size: 22px;
  }
}

/* --- Motion ----------------------------------------------------------------------------------------- */

/*
 * The parts dealt out. One beat, on the list as a whole rather than per card,
 * and only when the split is genuinely a different split — a re-render for the
 * same parts would be motion for nothing.
 */
.ss-parts[data-anim="deal"] > * {
  animation: ss-deal var(--sd-spring) var(--se-out) backwards;
}

.ss-parts[data-anim="deal"] > *:nth-child(2) {
  animation-delay: 50ms;
}

.ss-parts[data-anim="deal"] > *:nth-child(3) {
  animation-delay: 100ms;
}

.ss-parts[data-anim="deal"] > *:nth-child(4) {
  animation-delay: 150ms;
}

.ss-parts[data-anim="deal"] > *:nth-child(5) {
  animation-delay: 200ms;
}

@keyframes ss-deal {
  0% {
    transform: translateY(10px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

/* --- Reduced motion ----------------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .slip-splitter {
    --sd-fade: 100ms;
    --sd-pop: 0ms;
    --sd-spring: 0ms;
    --se-spring: ease-out;
  }

  .slip-splitter__sheet {
    transform: none;
  }

  .slip-splitter [data-anim] > *,
  .slip-splitter [data-anim] {
    animation: none !important;
  }
}

/* --- The wait, and what was left off ------------------------------------------------------------- */

/* Split is a round trip to the bookmaker now; the button says so and the
   parts dim while a re-split is on its way. */
.ss-cta[data-busy="true"] {
  opacity: 0.7;
}

.ss-parts[data-busy="true"] {
  opacity: 0.5;
  pointer-events: none;
  transition: opacity var(--duration) ease;
}

/* A part the bookmaker refused to book still lists its legs; the code slot
   says there is none and the reason sits under it. */
.ss-part__code[data-missing="true"] {
  color: var(--text-disabled);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  letter-spacing: 0;
}

.ss-part__error {
  margin: var(--space-2) 0 0;
  color: var(--error);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.4;
}

.ss-skipped {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: var(--space-2) var(--ss-gutter) 0;
  padding: 0;
  list-style: none;
}

.ss-skipped__row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
}

.ss-skipped__teams {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: line-through;
}

.ss-skipped__sel {
  color: var(--text-disabled);
  font-size: var(--text-xs);
}
