/*
 * The Code Converter (CodeConverter.js) — one slip rebuilt at another
 * bookmaker, over the SureTOOLS tab.
 *
 * **A sheet rather than a page**, and deliberately: this is a thing you open,
 * do and close, not a place you go. The chrome is the Advanced Markets sheet's
 * — scrim, the grey stack layer peeking above the white panel, a large top
 * radius — restated here because those rules are named for that sheet and
 * scaled to the Slip Builder's 0.75; this one runs at full size.
 *
 * The exchange card is the currency-converter arrangement on purpose: source
 * above, target below, a circular swap overlapping the hairline between them.
 * It is the layout everybody already reads as "this, expressed as that".
 *
 * The code field, the platform buttons and the platform sheet are the shared
 * parts in code-input.css.
 */

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

.code-converter {
  --cc-gutter: var(--space-4);
  /* The entrance is the app's spring; the exit reverses it a shade quicker. */
  --cc-enter: var(--spring-duration);
  --cc-exit: 320ms;
  /* The stack layer settles this much behind the panel. */
  --cc-lag: 40ms;

  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  max-width: var(--app-max-width);
  margin-inline: auto;
}

.code-converter[hidden] {
  display: none;
}

.code-converter [hidden] {
  display: none !important;
}

/* --- Scrim and stack layer ---------------------------------------------------------- */

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

.code-converter[data-open="true"] .cc-scrim {
  opacity: 0.55;
}

/* The card peeking out above the panel, for the stacked look the reference
   shows. Decoration: nothing sits on it, which is why it takes the `--slip-stack`
   value rather than a surface token. */
.cc-stack {
  position: absolute;
  right: 16px;
  bottom: 0;
  left: 16px;
  height: calc(90dvh + 12px);
  border-radius: 26px 26px 0 0;
  background: var(--slip-stack);
  transform: translateY(var(--rest-y, 100%));
  transition: transform var(--cc-exit) var(--se-out);
}

.code-converter[data-open="true"] .cc-stack {
  --rest-y: 0px;

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

.cc-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 90dvh;
  border-radius: 26px 26px 0 0;
  background: var(--bg);
  overflow: hidden;
  transform: translateY(var(--rest-y, 100%));
  transition: transform var(--cc-exit) var(--se-out);
}

.code-converter[data-open="true"] .cc-panel {
  --rest-y: 0px;

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

/* --- Header ------------------------------------------------------------------------------ */

.cc-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-2);
}

/* The title as a pill rather than a heading: this is a sheet's own name, not a
   page's, and it sits between two round buttons that would otherwise leave it
   floating. */
.cc-head__pill {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  height: 36px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  white-space: nowrap;
}

.cc-head__glyph {
  display: grid;
  place-items: center;
  color: var(--accent);
}

.cc-body {
  flex: 1;
  min-height: 0;
  padding: 0 0 calc(var(--space-8) + var(--safe-bottom));
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

/* --- The banner ------------------------------------------------------------------------------ */

/* Promotional, not a control: it says what the tool is for and nothing on it
   does anything. The CTA that converts is under the card. */
.cc-banner {
  position: relative;
  margin: var(--space-2) var(--cc-gutter) 0;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-xl);
  background: var(--accent);
  color: var(--accent-text);
  overflow: hidden;
}

/* The decorative circle pattern, drawn rather than fetched. */
.cc-banner__rings {
  position: absolute;
  top: -60px;
  right: -50px;
  width: 190px;
  height: 190px;
  border-radius: var(--radius-full);
  box-shadow:
    inset 0 0 0 14px rgb(var(--text-inverse-rgb) / 0.1),
    inset 0 0 0 34px rgb(var(--text-inverse-rgb) / 0.07),
    inset 0 0 0 56px rgb(var(--text-inverse-rgb) / 0.05);
}

.cc-banner__text {
  position: relative;
  max-width: 22ch;
}

.cc-banner__title {
  font-size: var(--text-lg);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.cc-banner__sub {
  margin-top: 2px;
  color: rgb(var(--text-inverse-rgb) / 0.82);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1.35;
}

/* --- The exchange card --------------------------------------------------------------------------- */

/*
 * Two rows split by a hairline with the swap overlapping it — the currency
 * converter's arrangement, and the resemblance is the point. Outlined rather
 * than filled so the two rows read as one exchange instead of two cards.
 */
.cc-card {
  position: relative;
  margin: var(--space-4) var(--cc-gutter) 0;
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: inset 0 0 0 1.5px var(--border);
}

.cc-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3);
}

/* Room on the right of both rows for the swap button that straddles them. */
.cc-row--source {
  padding-right: 62px;
}

.cc-row--target {
  min-height: 76px;
  padding-right: 62px;
  align-items: center;
}

.cc-row--source .ci {
  flex: 1;
  min-width: 0;
}

.cc-row--target .ci-platform-btn {
  flex: 1;
}

.cc-divider {
  height: 0;
  margin: 0 var(--space-3);
  border-top: 1px solid var(--border);
}

/* Overlapping the divider, which is what makes the two rows one exchange. */
.cc-swap {
  position: absolute;
  top: 50%;
  right: var(--space-3);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-top: -22px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 0 0 4px var(--surface);
  transition:
    background-color var(--sd-fade) var(--se-out),
    opacity var(--sd-fade) var(--se-out),
    transform var(--spring-duration) var(--spring);
}

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

.cc-swap:disabled {
  background: var(--surface-sunken);
  color: var(--text-disabled);
}

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

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

.cc-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);
}

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

.cc-cta:disabled {
  background: var(--surface-sunken);
  color: var(--text-disabled);
}

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

/* --- The result ------------------------------------------------------------------------------------------- */

.cc-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: var(--space-4) var(--cc-gutter) 0;
  padding: var(--space-4);
  border-radius: var(--radius-xl);
  background: var(--surface);
  text-align: center;
}

.cc-result__route {
  color: var(--text-muted);
  font-size: var(--text-2xs);
  font-weight: var(--weight-bold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.cc-result__codeRow {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.cc-result__code {
  color: var(--text);
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.cc-result__copy {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  transition: transform var(--spring-duration) var(--spring);
}

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

.cc-result__meta {
  margin-top: var(--space-1);
  color: var(--text);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
}

/* Whole conversions read calm; partial ones do not get to. */
.cc-result__note {
  margin-top: var(--space-2);
  color: var(--success-strong);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.cc-result__note[data-partial="true"] {
  color: var(--warning-strong);
}

.cc-result__priced {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

/* --- What did not cross ------------------------------------------------------------------------------------ */

.cc-lost__block {
  width: 100%;
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--border);
  text-align: left;
}

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

.cc-lost {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
  list-style: none;
}

.cc-lost__row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--warning-soft);
}

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

.cc-lost__match {
  color: var(--text-muted);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Struck through, because it is not on the slip you are being handed. */
.cc-lost__sel {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  text-decoration: line-through;
  text-decoration-color: var(--text-disabled);
}

.cc-lost__why {
  flex: none;
  max-width: 42%;
  color: var(--warning-strong);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  line-height: 1.3;
  text-align: right;
}

.cc-result__actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
  width: 100%;
  margin-top: var(--space-4);
}

.cc-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 44px;
  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);
}

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

.cc-action--share {
  background: var(--accent);
  color: var(--accent-text);
}

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

/* --- The confirmation ---------------------------------------------------------------------------------------- */

.cc-confirm {
  display: flex;
  flex-direction: column;
}

.cc-confirm__body {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1.45;
}

.cc-confirm .cc-lost {
  margin-top: var(--space-3);
}

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

/* Nothing crossed: there is no partial conversion to offer, so the one button
   left is the way out. */
.cc-confirm__actions[data-only="true"] {
  grid-template-columns: minmax(0, 1fr);
}

.cc-confirm__back {
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  transition: transform var(--spring-duration) var(--spring);
}

.cc-confirm__go {
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-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);
}

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

/* --- The history ------------------------------------------------------------------------------------------------ */

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

.cc-label {
  margin: var(--space-6) var(--cc-gutter) var(--space-2);
  color: var(--text);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
}

.cc-history {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0 var(--cc-gutter);
}

.cc-entry__wrap {
  position: relative;
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}

.cc-entry {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 62px;
  padding: var(--space-2) 38px var(--space-2) var(--space-3);
  text-align: left;
  transition: transform var(--spring-duration) var(--spring);
}

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

.cc-entry__route {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.cc-entry__arrow {
  display: grid;
  place-items: center;
  color: var(--text-disabled);
}

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

.cc-entry__code {
  color: var(--text);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  letter-spacing: 0.06em;
}

.cc-entry__meta {
  color: var(--text-muted);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cc-entry__side {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

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

.cc-entry__when {
  color: var(--text-disabled);
  font-size: 10px;
  font-weight: var(--weight-medium);
}

.cc-entry__forget {
  position: absolute;
  top: 50%;
  right: 6px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  margin-top: -13px;
  border-radius: var(--radius-full);
  color: var(--text-disabled);
  transition:
    background-color var(--sd-fade) var(--se-out),
    transform var(--spring-duration) var(--spring);
}

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

/* The count carries the news, so it carries the colour. */
.cc-entry__count[data-partial="true"] {
  color: var(--warning-strong);
  font-weight: var(--weight-bold);
}

.cc-entry__wrap[data-partial="true"] {
  box-shadow: inset 2.5px 0 0 var(--warning);
}

/* --- The quiet list --------------------------------------------------------------------------------------------- */

.cc-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 0 var(--cc-gutter);
  padding: var(--space-6) var(--space-5) var(--space-7);
  border-radius: var(--radius-xl);
  background: var(--surface);
  text-align: center;
}

.cc-empty__mark {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-disabled);
}

.cc-empty__title {
  color: var(--text);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}

.cc-empty__sub {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

/* --- The sheets ----------------------------------------------------------------------------------------------------- */

/* The Slip Builder's sheet at this tool's full size, not its 0.75 — and above
   this sheet, which is itself at z-index 70. */
.code-converter .slip-sheet {
  z-index: 96;
}

.code-converter .slip-sheet__panel {
  max-height: min(84dvh, 760px);
}

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

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

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

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

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

.cc-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) {
  .cc-result__code {
    font-size: 26px;
  }

  .cc-banner {
    padding: var(--space-3) var(--space-4);
  }
}

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

/* The swap turning over. The one beat this sheet has, and it fires on the one
   control whose whole meaning is a half turn. */
.cc-swap[data-anim="spin"] {
  animation: cc-spin var(--sd-spring) var(--se-out);
}

@keyframes cc-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(180deg);
  }
}

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

@media (prefers-reduced-motion: reduce) {
  .code-converter {
    --sd-fade: 100ms;
    --sd-pop: 0ms;
    --sd-spring: 0ms;
    --se-spring: ease-out;
    --cc-enter: 0ms;
    --cc-exit: 0ms;
  }

  .code-converter [data-anim] {
    animation: none !important;
  }
}

/* Convert is a round trip to two bookmakers now; the button says so. */
.cc-cta[data-busy="true"] {
  opacity: 0.7;
}
